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),
        )
    ]
Beispiel #2
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 setup_nodes(server):
    microphone_synth = supriya.Synth(
        synthdef=supriya.synthdefs.system_link_audio_2,
        in_=int(server.audio_input_bus_group),
        out=int(server.audio_output_bus_group),
        name='mic_input',
    )
    source_group = supriya.Group(name='source_group')
    source_compressor = supriya.Synth(
        synthdef=synthdefs.multiband_compressor,
        name='source_compressor',
    )
    effect_group = supriya.Group(name='effect_group')
    grain_synthdef = build_grain_synthdef()
    grain_synth = supriya.Synth(
        synthdef=grain_synthdef,
        name='grain_synth',
    )
    pitch_shift_synthdef = build_pitch_shift_synthdef()
    pitch_shift_synth = supriya.Synth(
        synthdef=pitch_shift_synthdef,
        name='pitch_shift_synth',
    )
    delay_synthdef = build_delay_synthdef()
    delay_synth = supriya.Synth(
        synthdef=delay_synthdef,
        name='delay_synth',
    )
    freeverb_synthdef = build_freeverb_synthdef()
    freeverb_synth = supriya.Synth(
        synthdef=freeverb_synthdef,
        name='freeverb_synth',
    )
    effect_group.extend([
        grain_synth,
        pitch_shift_synth,
        delay_synth,
        freeverb_synth,
    ])
    effect_compressor = supriya.Synth(
        synthdef=synthdefs.multiband_compressor,
        name='effect_compressor',
    )
    server.default_group.extend([
        microphone_synth,
        source_group,
        source_compressor,
        effect_group,
        effect_compressor,
    ])
Beispiel #4
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_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(server):
    outer_group = supriya.Group()
    inner_group = supriya.Group()
    synth_a = supriya.Synth()
    synth_b = supriya.Synth()
    synth_c = supriya.Synth()
    outer_group.extend([synth_a, inner_group, synth_c])
    inner_group.append(synth_b)
    assert format(outer_group.__graph__(),
                  "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            group [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 0 }"];
            "synth-0" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-0 }"];
            "group-1" [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 0-1 }"];
            "synth-1-0" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-1-0 }"];
            "synth-2" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-2 }"];
            group -> "synth-0";
            group -> "group-1";
            group -> "synth-2";
            "group-1" -> "synth-1-0";
        }
        """)
    outer_group.allocate()
    assert format(outer_group.__graph__(),
                  "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            "group-1000" [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 1000 }"];
            "synth-1001" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 1001 }"];
            "group-1002" [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 1002 }"];
            "synth-1003" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 1003 }"];
            "synth-1004" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 1004 }"];
            "group-1000" -> "synth-1001";
            "group-1000" -> "group-1002";
            "group-1000" -> "synth-1004";
            "group-1002" -> "synth-1003";
        }
        """)
    outer_group.free()
    assert format(outer_group.__graph__(),
                  "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            group [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 0 }"];
            "synth-0" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-0 }"];
            "group-1" [fillcolor=lightsteelblue2,
                label="{ <f_0_0> Group | <f_0_1> id: 0-1 }"];
            "synth-1-0" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-1-0 }"];
            "synth-2" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0-2 }"];
            group -> "synth-0";
            group -> "group-1";
            group -> "synth-2";
            "group-1" -> "synth-1-0";
        }
        """)
Beispiel #6
0
def test_01(server):
    synth = supriya.Synth()
    assert format(synth.__graph__(), "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            synth [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0 }"];
        }
        """)
    synth.allocate()
    assert format(synth.__graph__(), "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            "synth-1000" [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 1000 }"];
        }
        """)
    synth.free()
    assert format(synth.__graph__(), "graphviz") == uqbar.strings.normalize("""
        digraph G {
            graph [bgcolor=transparent,
                color=lightslategrey,
                dpi=72,
                fontname=Arial,
                outputorder=edgesfirst,
                overlap=prism,
                penwidth=2,
                rankdir=TB,
                ranksep=0.5,
                splines=spline,
                style="dotted, rounded"];
            node [fontname=Arial,
                fontsize=12,
                penwidth=2,
                shape=Mrecord,
                style="filled, rounded"];
            edge [penwidth=2];
            synth [fillcolor=lightgoldenrod2,
                label="{ <f_0_0> Synth | <f_0_1> id: 0 }"];
        }
        """)