def _build_synthdef(): with supriya.SynthDefBuilder(amplitude=0, bus=0, frequency=440) as builder: supriya.ugens.Out.ar( bus=builder["bus"], source=supriya.ugens.SinOsc.ar(frequency=builder["frequency"]) * builder["amplitude"], ) return builder.build(name="simple_sine")
def test_aggregated_anonymous(server): with supriya.SynthDefBuilder(frequency=440) as builder: source = supriya.ugens.SinOsc.ar(frequency=builder["frequency"]) supriya.ugens.Out.ar(bus=0, source=source) synthdef = builder.build() assert synthdef.server is None assert synthdef not in server synth_a = supriya.Synth(synthdef=synthdef, frequency=666) synth_b = supriya.Synth(synthdef=synthdef, frequency=777) synth_c = supriya.Synth(synthdef=synthdef, frequency=888) # allocate synthdef on node allocation with server.osc_io.capture() as transcript: synth_a.allocate(server=server) assert synthdef.server is server assert synthdef in server assert [message for timestamp, message in transcript.sent_messages] == [ supriya.osc.OscMessage( 5, synthdef.compile(), supriya.osc.OscMessage(9, synthdef.anonymous_name, 1000, 0, 1, "frequency", 666.0), ) ] # don't need to re-allocate with server.osc_io.capture() as transcript: synth_b.allocate(server=server) assert synthdef.server is server assert synthdef in server assert [message for timestamp, message in transcript.sent_messages] == [ supriya.osc.OscMessage(9, synthdef.anonymous_name, 1001, 0, 1, "frequency", 777.0) ] # just free the synthdef with server.osc_io.capture() as transcript: synthdef.free() assert synthdef.server is None assert synthdef not in server assert [message for timestamp, message in transcript.sent_messages ] == [supriya.osc.OscMessage(53, synthdef.anonymous_name)] # allocate synthdef (again)n on node allocation with server.osc_io.capture() as transcript: synth_c.allocate(server=server) assert synthdef.server is server assert synthdef in server assert [message for timestamp, message in transcript.sent_messages] == [ supriya.osc.OscMessage( 5, synthdef.compile(), supriya.osc.OscMessage(9, synthdef.anonymous_name, 1002, 0, 1, "frequency", 888.0), ) ]
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_unaggregated_anonymous(server): with supriya.SynthDefBuilder(frequency=440) as builder: source = supriya.ugens.SinOsc.ar(frequency=builder["frequency"]) supriya.ugens.Out.ar(bus=0, source=source) synthdef = builder.build() assert synthdef not in server with server.osc_io.capture() as transcript: synthdef.allocate(server=server) assert synthdef in server assert [message for timestamp, message in transcript.sent_messages ] == [supriya.osc.OscMessage(5, synthdef.compile())] with server.osc_io.capture() as transcript: synthdef.free() assert synthdef not in server assert [message for timestamp, message in transcript.sent_messages ] == [supriya.osc.OscMessage(53, synthdef.anonymous_name)]
def test_unaggregated_named(server): with supriya.SynthDefBuilder(frequency=440) as builder: source = supriya.ugens.SinOsc.ar(frequency=builder["frequency"]) supriya.ugens.Out.ar(bus=0, source=source) synthdef = builder.build(name="test-synthdef") assert synthdef not in server with server.osc_protocol.capture() as transcript: synthdef.allocate(server=server) assert synthdef in server assert [message for timestamp, message in transcript.sent_messages ] == [supriya.osc.OscMessage("/d_recv", synthdef.compile())] with server.osc_protocol.capture() as transcript: synthdef.free(server) assert synthdef not in server assert [message for timestamp, message in transcript.sent_messages ] == [supriya.osc.OscMessage("/d_free", synthdef.name)]
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_01(): with supriya.SynthDefBuilder(out=0, value=0.5) as builder: supriya.ugens.Out.ar(bus=builder["out"], source=supriya.ugens.DC.ar(builder["value"])) synthdef_A = builder.build(name="synthdef_A") with supriya.SynthDefBuilder(out=0, value=-0.3) as builder: supriya.ugens.Out.ar(bus=builder["out"], source=supriya.ugens.DC.ar(builder["value"])) synthdef_B = builder.build(name="synthdef_B") request = supriya.commands.SynthDefReceiveRequest( synthdefs=[synthdef_A], callback=supriya.commands.RequestBundle(contents=[ supriya.commands.GroupNewRequest(items=[ supriya.commands.GroupNewRequest.Item(node_id=1000, target_node_id=1) ]), supriya.commands.SynthNewRequest( node_id=1001, synthdef=synthdef_A, target_node_id=1000), supriya.commands.SynthDefReceiveRequest( synthdefs=[synthdef_B], callback=supriya.commands.RequestBundle(contents=[ supriya.commands.SynthNewRequest( add_action=supriya.AddAction.ADD_BEFORE, node_id=1002, synthdef=synthdef_B, target_node_id=1001, ), supriya.commands.NodeRunRequest( node_id_run_flag_pairs=[(1002, False)]), ]), ), ]), ) assert list(request._linearize()) == [ supriya.commands.SynthDefReceiveRequest(synthdefs=(synthdef_A, )), supriya.commands.GroupNewRequest(items=[ supriya.commands.GroupNewRequest.Item( add_action=supriya.AddAction.ADD_TO_HEAD, node_id=1000, target_node_id=1, ) ]), supriya.commands.SynthNewRequest( add_action=supriya.AddAction.ADD_TO_HEAD, node_id=1001, synthdef=synthdef_A, target_node_id=1000, ), supriya.commands.SynthDefReceiveRequest(synthdefs=(synthdef_B, )), supriya.commands.SynthNewRequest( add_action=supriya.AddAction.ADD_BEFORE, node_id=1002, synthdef=synthdef_B, target_node_id=1001, ), supriya.commands.NodeRunRequest(node_id_run_flag_pairs=((1002, False), )), ]
import supriya from used_light.session_setup import channel_count ### BUF NOISE ### with supriya.SynthDefBuilder( name="bufnoise", amp=1, out=0, buffer_id=0, start=0, end=1, freq=1, atk=0, sus=0, rel=3, c1=1.0, c2=-1.0, pan=0, ) as builder: env = supriya.ugens.EnvGen.kr(envelope=supriya.synthdefs.Envelope( amplitudes=(0, 1, 1, 0), durations=( builder['atk'], builder['sus'], builder['rel'], ), curves=( builder['c1'], 0, builder['c2'],