def test_no_reallocate_synthdef(server): synthdef = supriya.assets.synthdefs.test supriya.realtime.Synth(synthdef=synthdef).allocate(server) # SynthDef won't be allocated again synth_b = supriya.realtime.Synth(synthdef=synthdef) assert not synth_b.is_allocated assert synth_b.node_id is None assert synth_b not in server with server.osc_protocol.capture() as transcript: synth_b.allocate(server) assert [(_.label, _.message) for _ in transcript if _.message.address != "/status.reply"] == [ ("S", OscMessage("/s_new", "test", 1001, 0, 1)), ("R", OscMessage("/n_go", 1001, 1, -1, 1000, 0)), ] assert synthdef in server assert synth_b.node_id == 1001 assert server[1001] is synth_b assert synth_b in server server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1001 test amplitude: 1.0, frequency: 440.0 1000 test amplitude: 1.0, frequency: 440.0 """) assert str(server.root_node) == server_state
def test_allocate_synthdef(server): synthdef = supriya.assets.synthdefs.test synth_a = supriya.realtime.Synth(synthdef=synthdef) assert synthdef not in server assert not synth_a.is_allocated assert synth_a.node_id is None assert synth_a not in server with server.osc_protocol.capture() as transcript: synth_a.allocate(server) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscMessage( "/d_recv", bytearray(synthdef.compile()), OscMessage("/s_new", "test", 1000, 0, 1), ), ), ("R", OscMessage("/n_go", 1000, 1, -1, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] assert synthdef in server assert synth_a.node_id == 1000 assert server[1000] is synth_a assert synth_a in server server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1000 test amplitude: 1.0, frequency: 440.0 """) assert str(server.root_node) == server_state
def test_shared_resources(): server_a, server_b = Server(), Server() server_a.boot(maximum_logins=2) server_b.connect() with supriya.SynthDefBuilder(frequency=440) as builder: _ = supriya.ugens.Out.ar( bus=0, source=supriya.ugens.SinOsc.ar(frequency=builder["frequency"]) ) synthdef = builder.build(name="foo") synth = supriya.Synth(synthdef=synthdef) transcript_a = server_a.osc_protocol.capture() transcript_b = server_b.osc_protocol.capture() with transcript_a, transcript_b: synth.allocate(target_node=server_b) time.sleep(0.1) # Wait for all clients to receive /n_go assert synth not in server_a assert synth in server_b assert [ (label, osc_message) for _, label, osc_message in transcript_a if osc_message.address not in ["/status", "/status.reply"] ] == [("R", OscMessage("/n_go", 67109864, 2, -1, -1, 0))] assert [ (label, osc_message) for _, label, osc_message in transcript_b if osc_message.address not in ["/status", "/status.reply"] ] == [ ( "S", OscMessage( "/d_recv", synthdef.compile(), OscMessage("/s_new", "foo", 67109864, 0, 2), ), ), ("R", OscMessage("/n_go", 67109864, 2, -1, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] # TODO: Server A doesn't actually know what this SynthDef should be. assert str(server_a.root_node) == normalize( """ NODE TREE 0 group 1 group 2 group 67109864 default out: 0.0, amplitude: 0.1, frequency: 440.0, gate: 1.0, pan: 0.5 """ ) assert str(server_b.root_node) == normalize( """ NODE TREE 0 group 1 group 2 group 67109864 foo frequency: 440.0 """ )
def test_replace(server): synthdef = supriya.assets.synthdefs.test synth_a = supriya.realtime.Synth() synth_b = supriya.realtime.Synth(synthdef=synthdef) synth_a.allocate(server) assert synth_a.node_id == 1000 assert server[1000] is synth_a assert synth_a in server assert synth_a.is_allocated assert synthdef not in server assert not synth_b.is_allocated assert synth_b.node_id is None assert synth_b not in server server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1000 default out: 0.0, amplitude: 0.1, frequency: 440.0, gate: 1.0, pan: 0.5 """) with server.osc_protocol.capture() as transcript: synth_b.allocate(add_action="replace", target_node=synth_a) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscMessage( "/d_recv", bytearray(synthdef.compile()), OscMessage("/s_new", "test", 1001, 4, 1000), ), ), ("R", OscMessage("/n_go", 1001, 1, -1, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1001 test amplitude: 1.0, frequency: 440.0 """) assert synth_a.node_id is None assert synth_a not in server assert not synth_a.is_allocated assert server[1000] is None assert synth_b.node_id == 1001 assert server[1001] is synth_b assert synth_b in server assert synth_b.is_allocated
def test_group_allocate_paused(server): group = supriya.realtime.Group() group.pause() assert group.is_paused with server.osc_protocol.capture() as transcript: group.allocate(server) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscBundle(contents=( OscMessage("/g_new", 1000, 0, 1), OscMessage("/n_run", 1000, 0), OscMessage("/sync", 0), )), ), ("R", OscMessage("/n_go", 1000, 1, -1, -1, 1, -1, -1)), ("R", OscMessage("/n_off", 1000, 1, -1, -1, 1, -1, -1)), ("R", OscMessage("/synced", 0)), ] assert group.is_paused with server.osc_protocol.capture() as transcript: group.free() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_free", 1000))] assert group.is_paused group.unpause() assert not group.is_paused
def test_synth_allocate_free_paused(server): synth = supriya.realtime.Synth(synthdef=supriya.assets.synthdefs.test) synth.pause() assert synth.is_paused with server.osc_protocol.capture() as transcript: synth.allocate(server) bundle = OscBundle(contents=( OscMessage("/s_new", "test", 1000, 0, 1), OscMessage("/n_run", 1000, 0), )) assert [(_.label, _.message) for _ in transcript] == [ ("S", OscMessage("/d_recv", supriya.assets.synthdefs.test.compile(), bundle)), ("R", OscMessage("/n_go", 1000, 1, -1, -1, 0)), ("R", OscMessage("/n_off", 1000, 1, -1, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] assert synth.is_paused with server.osc_protocol.capture() as transcript: synth.free() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_free", 1000))] assert synth.is_paused synth.unpause() assert not synth.is_paused
def test_shared_resources(): server_a, server_b = Server(), Server() server_a.boot(maximum_logins=2) server_b.connect() with supriya.SynthDefBuilder(frequency=440) as builder: _ = supriya.ugens.Out.ar( bus=0, source=supriya.ugens.SinOsc.ar(frequency=builder["frequency"])) synthdef = builder.build(name="foo") synth = supriya.Synth(synthdef=synthdef) transcript_a = server_a.osc_io.capture() transcript_b = server_b.osc_io.capture() with transcript_a, transcript_b: synth.allocate(target_node=server_b) assert synth not in server_a assert synth in server_b assert [(label, osc_message) for _, label, osc_message, _ in transcript_a ] == [("R", OscMessage("/n_go", 67109864, 2, -1, -1, 0))] assert [(label, osc_message) for _, label, osc_message, _ in transcript_b] == [ ("S", OscMessage(5, synthdef.compile(), OscMessage(9, "foo", 67109864, 0, 2))), ("R", OscMessage("/n_go", 67109864, 2, -1, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] # TODO: Server A doesn't actually know what this SynthDef should be. assert str(server_a.query_local_nodes(True)) == normalize(""" NODE TREE 0 group 1 group 2 group 67109864 default amplitude: 0.1, frequency: 440.0, gate: 1.0, out: 0.0, pan: 0.5 """) assert str(server_b.query_local_nodes(True)) == normalize(""" NODE TREE 0 group 1 group 2 group 67109864 foo frequency: 440.0 """)
def test_synth_pause_unpause(server): synth = supriya.realtime.Synth().allocate(server) assert not synth.is_paused with server.osc_protocol.capture() as transcript: synth.pause() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_run", 1000, 0))] assert synth.is_paused with server.osc_protocol.capture() as transcript: synth.pause() assert list(transcript) == [] assert synth.is_paused with server.osc_protocol.capture() as transcript: synth.unpause() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_run", 1000, 1))] assert not synth.is_paused with server.osc_protocol.capture() as transcript: synth.unpause() assert list(transcript) == [] assert not synth.is_paused
def test_group_pause_unpause(server): group = supriya.realtime.Group().allocate() assert not group.is_paused with server.osc_protocol.capture() as transcript: group.pause() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_run", 1000, 0))] assert group.is_paused with server.osc_protocol.capture() as transcript: group.pause() assert list(transcript) == [] assert group.is_paused with server.osc_protocol.capture() as transcript: group.unpause() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_run", 1000, 1))] assert not group.is_paused with server.osc_protocol.capture() as transcript: group.unpause() assert list(transcript) == [] assert not group.is_paused
def test_extend_unallocated(server): group = supriya.realtime.Group() group.allocate() synth_a = supriya.realtime.Synth(supriya.assets.synthdefs.test) synth_b = supriya.realtime.Synth(supriya.assets.synthdefs.test, amplitude=0.0) with server.osc_protocol.capture() as transcript: group.extend([synth_a, synth_b]) server_state = str(server.query_remote_nodes(True)) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1000 group 1001 test amplitude: 1.0, frequency: 440.0 1002 test amplitude: 0.0, frequency: 440.0 """) assert str(server.query_local_nodes(include_controls=True)) == server_state bundle = OscBundle(contents=( OscMessage("/s_new", "test", 1001, 0, 1000), OscMessage("/s_new", "test", 1002, 3, 1001, "amplitude", 0.0), )) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscMessage("/d_recv", supriya.assets.synthdefs.test.compile(), bundle), ), ("R", OscMessage("/n_go", 1001, 1000, -1, -1, 0)), ("R", OscMessage("/n_go", 1002, 1000, 1001, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ]
def test_group_allocate_nested_paused(server): group = supriya.realtime.Group([ supriya.realtime.Synth(), supriya.realtime.Group([supriya.realtime.Synth()]) ]) group[0].pause() group[1][0].pause() assert not group.is_paused assert group[0].is_paused assert not group[1].is_paused assert group[1][0].is_paused with server.osc_protocol.capture() as transcript: group.allocate(server) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscBundle(contents=( OscMessage("/g_new", 1000, 0, 1), OscMessage("/s_new", "default", 1001, 0, 1000), OscMessage("/g_new", 1002, 3, 1001), OscMessage("/s_new", "default", 1003, 0, 1002), OscMessage("/n_run", 1001, 0, 1003, 0), OscMessage("/sync", 0), )), ), ("R", OscMessage("/n_go", 1000, 1, -1, -1, 1, -1, -1)), ("R", OscMessage("/n_go", 1001, 1000, -1, -1, 0)), ("R", OscMessage("/n_go", 1002, 1000, 1001, -1, 1, -1, -1)), ("R", OscMessage("/n_go", 1003, 1002, -1, -1, 0)), ("R", OscMessage("/n_off", 1001, 1000, -1, 1002, 0)), ("R", OscMessage("/n_off", 1003, 1002, -1, -1, 0)), ("R", OscMessage("/synced", 0)), ] assert not group.is_paused assert group[0].is_paused assert not group[1].is_paused assert group[1][0].is_paused with server.osc_protocol.capture() as transcript: group.free() assert [(_.label, _.message) for _ in transcript] == [("S", OscMessage("/n_free", 1000))] assert not group.is_paused assert group[0].is_paused assert not group[1].is_paused assert group[1][0].is_paused
def test_mapping(server): synthdef = supriya.assets.synthdefs.test.allocate(server) synth = supriya.realtime.Synth(synthdef=synthdef) synth["frequency"] = 443 synth["amplitude"] = 0.5 assert synth["frequency"] == 443 assert synth["amplitude"] == 0.5 # Allocate and verify messaging and server state with server.osc_protocol.capture() as transcript: synth.allocate(server) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscMessage("/s_new", "test", 1000, 0, 1, "amplitude", 0.5, "frequency", 443.0), ), ("R", OscMessage("/n_go", 1000, 1, -1, -1, 0)), ] server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1000 test amplitude: 0.5, frequency: 443.0 """) # Free and verify post-free state synth.free() assert synth["frequency"] == 443 assert synth["amplitude"] == 0.5 # Map controls to buses control_bus = supriya.realtime.Bus( 0, calculation_rate="control").allocate(server) audio_bus = supriya.realtime.Bus(0, calculation_rate="audio").allocate(server) synth["frequency"] = control_bus synth["amplitude"] = audio_bus assert synth["frequency"] == control_bus assert synth["amplitude"] == audio_bus # Allocate and verify messaging and server state with server.osc_protocol.capture() as transcript: synth.allocate(server) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscBundle(contents=( OscMessage("/s_new", "test", 1001, 0, 1), OscMessage("/n_mapa", 1001, "amplitude", 0), OscMessage("/n_map", 1001, "frequency", 0), OscMessage("/sync", 0), )), ), ("R", OscMessage("/n_end", 1000, 1, -1, -1, 0)), ("R", OscMessage("/n_go", 1001, 1, -1, -1, 0)), ("R", OscMessage("/synced", 0)), ] server_state = str(server.query()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1001 test amplitude: a0, frequency: c0 """) # Free and verify post-free state synth.free() assert synth["frequency"] == control_bus assert synth["amplitude"] == audio_bus
def test_extend_allocate_nested_and_move(server): synth = supriya.realtime.Synth().allocate() synthdef = supriya.assets.synthdefs.test group_a = supriya.realtime.Group().allocate() group_b = supriya.realtime.Group([ supriya.realtime.Synth(synthdef=synthdef), supriya.realtime.Group([supriya.realtime.Synth(synthdef=synthdef)]), ]) server_state = str(server.query_remote_nodes()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1001 group 1000 default """) assert str(server.query_local_nodes()) == server_state with server.osc_protocol.capture() as transcript: group_a.extend([group_b, synth]) bundle = OscBundle(contents=( OscMessage("/g_new", 1002, 0, 1001), OscMessage("/s_new", "test", 1003, 0, 1002), OscMessage("/g_new", 1004, 3, 1003), OscMessage("/s_new", "test", 1005, 0, 1004), OscMessage("/n_after", 1000, 1002), )) assert [(_.label, _.message) for _ in transcript] == [ ( "S", OscMessage("/d_recv", supriya.assets.synthdefs.test.compile(), bundle), ), ("R", OscMessage("/n_go", 1002, 1001, -1, -1, 1, -1, -1)), ("R", OscMessage("/n_go", 1003, 1002, -1, -1, 0)), ("R", OscMessage("/n_go", 1004, 1002, 1003, -1, 1, -1, -1)), ("R", OscMessage("/n_go", 1005, 1004, -1, -1, 0)), ("R", OscMessage("/n_move", 1000, 1001, 1002, -1, 0)), ("R", OscMessage("/done", "/d_recv")), ] server_state = str(server.query_remote_nodes()) assert server_state == uqbar.strings.normalize(""" NODE TREE 0 group 1 group 1001 group 1002 group 1003 test 1004 group 1005 test 1000 default """) assert str(server.query_local_nodes()) == server_state