def test_01b(self): session = nonrealtimetools.Session() with session.at(10): synth = session.add_synth( duration=6, synthdef=synthdefs.default, frequency=440, ) with session.at(11): synth['frequency'] = 442 with session.at(13): synth['frequency'] = 443 assert session.to_lists() == [ [ 10.0, [['/d_recv', bytearray(synthdefs.default.compile())], [ '/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1000, 0, 0, 'frequency', 440 ]] ], [11.0, [['/n_set', 1000, 'frequency', 442]]], [13.0, [['/n_set', 1000, 'frequency', 443]]], [16.0, [['/n_set', 1000, 'gate', 0], [0]]], ]
def test_01(self): session = nonrealtimetools.Session() with session.at(0): session.add_synth( duration=4, synthdef=synthdefs.default, ) with session.at(2): session.add_synth( duration=4, synthdef=synthdefs.default, amplitude=0.5, frequency=443, pan=0.75, out=8, ) assert session.to_lists() == [ [ 0.0, [['/d_recv', bytearray(synthdefs.default.compile())], ['/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1000, 0, 0]] ], [ 2.0, [[ '/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1001, 0, 0, 'amplitude', 0.5, 'frequency', 443, 'out', 8, 'pan', 0.75 ]] ], [4.0, [['/n_set', 1000, 'gate', 0]]], [6.0, [['/n_set', 1001, 'gate', 0], [0]]] ]
def test_06(self): """ Exit at midpoint. """ session = nonrealtimetools.Session() with session.at(0): one = session.add_group(duration=10) two = one.add_group(duration=10) with session.at(5): session.move_node(two) with session.at(0): entering, exiting, occupying, starting, stopping = \ one.inspect_children() assert entering == () assert exiting == () assert occupying == () assert starting == (two,) assert stopping == () with session.at(5): entering, exiting, occupying, starting, stopping = \ one.inspect_children() assert entering == () assert exiting == (two,) assert occupying == () assert starting == () assert stopping == () with session.at(10): entering, exiting, occupying, starting, stopping = \ one.inspect_children() assert entering == () assert exiting == () assert occupying == () assert starting == () assert stopping == ()
def test_04(self): session = nonrealtimetools.Session() with session.at(0): session.add_synth( duration=1, synthdef=self.build_gate_synthdef(), ) assert session.to_osc_bundles(duration=2) == [ osctools.OscBundle( timestamp=0.0, contents=( osctools.OscMessage( '/d_recv', bytearray( b'SCgf\x00\x00\x00\x02\x00\x01 fc663c6d1f8badaed1bd3e25cf2220f0\x00\x00\x00\x08?\x80\x00\x00\x00\x00\x00\x00@\x00\x00\x00\xc2\xc6\x00\x00<#\xd7\n@\xa0\x00\x00\xc0\x80\x00\x00C\xdc\x00\x00\x00\x00\x00\x01?\x80\x00\x00\x00\x00\x00\x01\x04gate\x00\x00\x00\x00\x00\x00\x00\x05\x07Control\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x01\x06EnvGen\x02\x00\x00\x00\x11\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x02\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x03\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x04\xff\xff\xff\xff\x00\x00\x00\x05\xff\xff\xff\xff\x00\x00\x00\x06\xff\xff\xff\xff\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x05\xff\xff\xff\xff\x00\x00\x00\x06\x02\x03Saw\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\xff\xff\xff\xff\x00\x00\x00\x07\x02\x0cBinaryOpUGen\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x03Out\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00' )), osctools.OscMessage('/s_new', 'fc663c6d1f8badaed1bd3e25cf2220f0', 1000, 0, 0), )), osctools.OscBundle(timestamp=1.0, contents=(osctools.OscMessage( '/n_set', 1000, 'gate', 0), )), osctools.OscBundle(timestamp=2.0, contents=(osctools.OscMessage(0), )), ]
def test_01(self): session = nonrealtimetools.Session() bus_one = session.add_bus() bus_two = session.add_bus() with session.at(0): bus_one.set_(10) with session.at(2): bus_one.set_(20) bus_two.set_(30) with session.at(3): bus_two.set_(40) assert session.to_osc_bundles() == [ osctools.OscBundle( timestamp=0.0, contents=( osctools.OscMessage('/c_set', 0, 10.0), ) ), osctools.OscBundle( timestamp=2.0, contents=( osctools.OscMessage('/c_set', 0, 20.0, 1, 30.0), ) ), osctools.OscBundle( timestamp=3.0, contents=( osctools.OscMessage('/c_set', 1, 40.0), osctools.OscMessage(0), ) ) ]
def test_basic(self): session = nonrealtimetools.Session() with session.at(0): node = session.add_group(duration=20) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 20.0: NODE TREE 0 group ''') assert session.to_lists() == [[0.0, [['/g_new', 1000, 0, 0]]], [20.0, [['/n_free', 1000], [0]]]] node.set_duration(30) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 30.0: NODE TREE 0 group ''') assert session.to_lists() == [[0.0, [['/g_new', 1000, 0, 0]]], [30.0, [['/n_free', 1000], [0]]]] node.set_duration(10) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 10.0: NODE TREE 0 group ''') assert session.to_lists() == [[0.0, [['/g_new', 1000, 0, 0]]], [10.0, [['/n_free', 1000], [0]]]]
def test_nonrealtime_01a(self): session = nonrealtimetools.Session() with session.at(0): self.pbind_01.inscribe(session) assert session.to_lists() == [ [ 0.0, [['/d_recv', bytearray(synthdefs.default.compile())], [ '/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1000, 0, 0, 'amplitude', 1.0, 'frequency', 440 ]] ], [ 1.0, [[ '/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1001, 0, 0, 'amplitude', 1.0, 'frequency', 660 ], ['/n_set', 1000, 'gate', 0]] ], [ 3.0, [[ '/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1002, 0, 0, 'amplitude', 1.0, 'frequency', 880 ], ['/n_set', 1001, 'gate', 0]] ], [6.0, [['/n_set', 1002, 'gate', 0], [0]]], ]
def test_03(self): session = nonrealtimetools.Session() synthdef = self.build_duration_synthdef() with session.at(0): session.add_synth( duration=1, synthdef=self.build_duration_synthdef(), ) assert session.to_osc_bundles() == [ osctools.OscBundle( timestamp=0.0, contents=( osctools.OscMessage('/d_recv', bytearray(synthdef.compile())), osctools.OscMessage('/s_new', '448a8d487adfc99ec697033edc2a1227', 1000, 0, 0), )), osctools.OscBundle(timestamp=1.0, contents=( osctools.OscMessage('/n_free', 1000), osctools.OscMessage(0), )), ] exit_code, _ = session.render( self.output_file_path, output_bus_channel_count=1, ) self.assert_ok(exit_code, 1., 44100, 1) soundfile = soundfiletools.SoundFile(self.output_file_path) for i in range(1, 100): value = float(i) / 100 assert self.round(soundfile.at_percent(value)[0]) == value
def test_pbus(self): session = nonrealtimetools.Session() with session.at(0): group = session.add_group() synth = group.add_synth(add_action='ADD_AFTER') group.add_synth(duration=10) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 1002 da0982184cc8fa54cf9d288a0fe1f6ca 1001 da0982184cc8fa54cf9d288a0fe1f6ca 10.0: NODE TREE 0 group 1000 group 1001 da0982184cc8fa54cf9d288a0fe1f6ca inf: NODE TREE 0 group ''') synth.set_duration(15) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 1002 da0982184cc8fa54cf9d288a0fe1f6ca 1001 da0982184cc8fa54cf9d288a0fe1f6ca 10.0: NODE TREE 0 group 1000 group 1001 da0982184cc8fa54cf9d288a0fe1f6ca 15.0: NODE TREE 0 group 1000 group inf: NODE TREE 0 group ''') group.set_duration(15) assert session.to_strings() == self.normalize(''' 0.0: NODE TREE 0 group 1000 group 1002 da0982184cc8fa54cf9d288a0fe1f6ca 1001 da0982184cc8fa54cf9d288a0fe1f6ca 10.0: NODE TREE 0 group 1000 group 1001 da0982184cc8fa54cf9d288a0fe1f6ca 15.0: NODE TREE 0 group ''') assert session.to_lists() == [[ 0.0, [['/d_recv', bytearray(synthdefs.default.compile())], ['/g_new', 1000, 0, 0], ['/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1001, 3, 1000], ['/s_new', 'da0982184cc8fa54cf9d288a0fe1f6ca', 1002, 0, 1000]] ], [10.0, [['/n_set', 1002, 'gate', 0]] ], [15.0, [['/n_free', 1000], ['/n_set', 1001, 'gate', 0], [0]]]]
def test_05(self): """ Mismatch. """ session = nonrealtimetools.Session() with session.at(5): node = session.add_group(duration=10, offset=13) with self.assertRaises(ValueError): node.add_group(duration=1)
def test_01(self): session = nonrealtimetools.Session() with session.at(0): session.add_synth( duration=1, synthdef=self.build_basic_synthdef(), ) exit_code, _ = session.render(self.output_filepath) self.assert_ok(exit_code, 1., 44100, 8)
def test_02(self): """ With offset=... keyword. """ session = nonrealtimetools.Session() node = session.add_group(duration=10, offset=5) assert isinstance(node, nonrealtimetools.Group) assert node in session.nodes assert node.start_offset == 5 assert node.stop_offset == 15
def test_06(self): """ Defaults. """ session = nonrealtimetools.Session() with session.at(0): synth = session.add_synth() assert synth.synthdef == synthdefs.default assert synth.duration == float('inf') assert synth.start_offset == 0.
def test_set(self): session = nonrealtimetools.Session() with session.at(0): buffer_ = session.add_buffer(frame_count=512) with session.at(1): buffer_.set([(64, 0.5), (128, 0.75)]) assert session.to_lists(duration=2) == [ [0.0, [['/b_alloc', 0, 512, 1]]], [1.0, [['/b_set', 0, 64, 0.5, 128, 0.75]]], [2.0, [['/b_free', 0], [0]]], ]
def test_fill(self): session = nonrealtimetools.Session() with session.at(0): buffer_ = session.add_buffer(frame_count=512) with session.at(1): buffer_.fill([(0, 64, 0.5), (64, 256, 0.25)]) assert session.to_lists(duration=2) == [ [0.0, [['/b_alloc', 0, 512, 1]]], [1.0, [['/b_fill', 0, 0, 64, 0.5, 64, 256, 0.25]]], [2.0, [['/b_free', 0], [0]]], ]
def test_01(self): """ With Session.at(...) context manager. """ session = nonrealtimetools.Session() with session.at(5): node = session.add_group(duration=10) assert isinstance(node, nonrealtimetools.Group) assert node in session.nodes assert node.start_offset == 5 assert node.stop_offset == 15
def test_04(self): """ With both Session.at(...) context manager and offset keyword. """ session = nonrealtimetools.Session() with session.at(5): node = session.add_group(duration=10, offset=13) assert isinstance(node, nonrealtimetools.Group) assert node in session.nodes assert node.start_offset == 13 assert node.stop_offset == 23
def test_Session(self): session = nonrealtimetools.Session() request = requesttools.BufferAllocateReadRequest( buffer_id=1, file_path=session, frame_count=512, starting_frame=128, ) assert request.file_path is session osc_message = request.to_osc_message(with_textual_osc_command=True) assert osc_message.address == '/b_allocRead' assert osc_message.contents == (1, session, 128, 512)
def test_02(self): """ With offset=... keyword. """ session = nonrealtimetools.Session() with session.at(0): group_one = session.add_group() group_two = session.add_group() node = group_one.add_synth() group_two.move_node(node, offset=5) with session.at(5): assert node.get_parent() is group_two
def test_02(self): session = nonrealtimetools.Session() with session.at(0): session.add_synth( duration=300, synthdef=self.build_basic_synthdef(), ) exit_code, _ = session.render( self.output_filepath, sample_rate=48000, output_bus_channel_count=2, ) self.assert_ok(exit_code, 300., 48000, 2)
def test_05(self): session = nonrealtimetools.Session() synthdef = self.build_basic_synthdef() with session.at(0): session.add_synth( duration=0, synthdef=synthdef, ) assert session.to_lists(duration=1) == [[ 0.0, [['/d_recv', bytearray(synthdef.compile())], ['/s_new', 'd719856d7deff2696a3f807f5dc79809', 1000, 0, 0]] ], [1.0, [[0]]]]
def test_03(self): """ Without Session.at(...) context manager or offset keyword. """ session = nonrealtimetools.Session() with session.at(0): group_one = session.add_group() group_two = session.add_group() node = group_one.add_synth() with session.at(10): group_two.move_node(node) with self.assertRaises(ValueError): group_two.move_node(node)
def test_01(self): """ With Session.at(...) context manager. """ session = nonrealtimetools.Session() with session.at(0): group_one = session.add_group() group_two = session.add_group() node = group_one.add_synth() with session.at(5): group_two.move_node(node) with session.at(5): assert node.get_parent() is group_two
def test_set_contiguous(self): session = nonrealtimetools.Session() with session.at(0): buffer_ = session.add_buffer(frame_count=512) with session.at(1): buffer_.set_contiguous([(0, (1, 2, 3)), (128, (1, 2, 3))]) assert session.to_lists(duration=2) == [ [0.0, [['/b_alloc', 0, 512, 1]]], [ 1.0, [['/b_setn', 0, 0, 3, 1.0, 2.0, 3.0, 128, 3, 1.0, 2.0, 3.0]] ], [2.0, [['/b_free', 0], [0]]], ]
def test_alloc_read(self): session = nonrealtimetools.Session() with session.at(0): session.add_buffer(file_path='foo.aiff', ) with session.at(1): session.add_buffer( file_path='bar.aiff', frame_count=512, starting_frame=53, ) assert session.to_lists(duration=2) == [[ 0.0, [['/b_allocRead', 0, 'foo.aiff', 0, -1]] ], [1.0, [['/b_allocRead', 1, 'bar.aiff', 53, 512]]], [2.0, [['/b_free', 0], ['/b_free', 1], [0]]]]
def test_Session(self): session = nonrealtimetools.Session() request = requesttools.BufferReadRequest( buffer_id=1, file_path=session, frame_count=512, leave_open=True, starting_frame_in_buffer=0, starting_frame_in_file=0, ) assert request.file_path is session osc_message = request.to_osc_message(with_textual_osc_command=True) assert osc_message.address == '/b_read' assert osc_message.contents == (1, session, 0, 512, 0, 1)
def test_04(self): """ With both Session.at(...) context manager and offset keyword. """ session = nonrealtimetools.Session() with session.at(0): group_one = session.add_group() group_two = session.add_group() node = group_one.add_synth() with session.at(10): group_two.move_node(node) with session.at(5): parent = node.get_parent(offset=15) assert parent is group_two
def test_02(self): """ With offset=... keyword. """ session = nonrealtimetools.Session() with session.at(0): group_one = session.add_group() group_two = session.add_group() node = group_one.add_synth() with session.at(10): group_two.move_node(node) parentage = node.get_parentage(offset=5) assert parentage == [node, group_one, session.root_node] parentage = node.get_parentage(offset=15) assert parentage == [node, group_two, session.root_node]
def test_01(self): session = nonrealtimetools.Session() with session.at(0): buffer_group_one = session.add_buffer_group() with session.at(5): buffer_group_two = session.add_buffer_group( buffer_count=2, duration=10, ) # buffer group one assert buffer_group_one.duration == float('inf') assert buffer_group_one.session is session assert buffer_group_one.start_offset == 0 assert buffer_group_one.stop_offset == float('inf') # buffer group one bufferes assert len(buffer_group_one) == 1 buffer_ = buffer_group_one[0] assert buffer_ in buffer_group_one assert buffer_group_one.index(buffer_) == 0 assert buffer_.duration == buffer_group_one.duration assert buffer_.session is buffer_group_one.session assert buffer_.start_offset == buffer_group_one.start_offset assert buffer_.stop_offset == buffer_group_one.stop_offset # buffer group two assert buffer_group_two.duration == 10 assert buffer_group_two.session is session assert buffer_group_two.start_offset == 5 assert buffer_group_two.stop_offset == 15 # buffer group two bufferes assert len(buffer_group_two) == 2 buffer_ = buffer_group_two[0] assert buffer_ in buffer_group_two assert buffer_group_two.index(buffer_) == 0 assert buffer_.duration == buffer_group_two.duration assert buffer_.session is buffer_group_two.session assert buffer_.start_offset == buffer_group_two.start_offset assert buffer_.stop_offset == buffer_group_two.stop_offset buffer_ = buffer_group_two[1] assert buffer_ in buffer_group_two assert buffer_group_two.index(buffer_) == 1 assert buffer_.duration == buffer_group_two.duration assert buffer_.session is buffer_group_two.session assert buffer_.start_offset == buffer_group_two.start_offset assert buffer_.stop_offset == buffer_group_two.stop_offset
def test_05(self): """ Soundfile DiskIn input. """ path_one = os.path.join(self.output_directory, 'output-one.aiff') path_two = os.path.join(self.output_directory, 'output-two.aiff') session_one = self._make_session() exit_code, _ = session_one.render( path_one, render_path=self.output_directory, ) self.assert_ok(exit_code, 10., 44100, 8, file_path=path_one) session_two = nonrealtimetools.Session() synthdef = self._build_diskin_synthdef(channel_count=8) with session_two.at(0): buffer_ = session_two.cue_soundfile( path_one, duration=10, ) session_two.add_synth( synthdef=synthdef, buffer_id=buffer_, duration=10, ) assert session_two.to_lists() == [ [0.0, [ ['/d_recv', bytearray(synthdef.compile())], ['/b_alloc', 0, 32768, 8], ['/b_read', 0, path_one, 0, -1, 0, 1], ['/s_new', '42367b5102dfa250b301ec698b3bd6c4', 1000, 0, 0, 'buffer_id', 0]]], [10.0, [ ['/n_free', 1000], ['/b_close', 0], ['/b_free', 0], [0]]]] exit_code, _ = session_two.render( path_two, render_path=self.output_directory, ) self.assert_ok(exit_code, 10., 44100, 8, file_path=path_two) assert self._sample(path_two) == { 0.0: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0.21: [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], 0.41: [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], 0.61: [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75], 0.81: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 0.99: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], }