def test_Provider_from_context(session, server):
    realtime_provider = Provider.from_context(server)
    assert isinstance(realtime_provider, RealtimeProvider)
    assert realtime_provider.server is server
    nonrealtime_provider = Provider.from_context(session)
    assert isinstance(nonrealtime_provider, NonrealtimeProvider)
    assert nonrealtime_provider.session is session
    with pytest.raises(ValueError):
        Provider.from_context(23)
def test_NonrealtimeProvider_add_synth_1(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        synth_proxy = provider.add_synth(amplitude=0.3, frequency=333)
    assert synth_proxy == SynthProxy(
        identifier=session.nodes_by_session_id[1000],
        provider=provider,
        synthdef=default,
        settings=dict(amplitude=0.3, frequency=333),
    )
    assert session.to_lists(10) == [
        [
            1.2345,
            [
                *pytest.helpers.build_d_recv_commands([default]),
                [
                    "/s_new",
                    default.anonymous_name,
                    1000,
                    0,
                    0,
                    "amplitude",
                    0.3,
                    "frequency",
                    333,
                ],
            ],
        ],
        [10.0, [["/n_set", 1000, "gate", 0], [0]]],
    ]
def test_NonrealtimeProvider_add_synth_error(session):
    """
    Requires moment.
    """
    provider = Provider.from_context(session)
    with pytest.raises(ValueError):
        provider.add_synth()
Пример #4
0
def test_RealtimeProvider_set_node_3(server):
    provider = Provider.from_context(server)
    with provider.at(None):
        synth_proxy = provider.add_synth()
        bus_proxy = provider.add_bus()
    time.sleep(0.01)
    with server.osc_protocol.capture() as transcript:
        with provider.at(None):
            synth_proxy["frequency"] = bus_proxy
    assert [
        entry.message.to_list() for entry in transcript if not (
            entry.label == "R" and entry.message.address == "/status.reply")
    ] == [[None, [["/n_set", 1000, "frequency", "c0"]]]]
    time.sleep(0.01)
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 default
                    out: 0.0, amplitude: 0.1, frequency: c0, gate: 1.0, pan: 0.5
        """)
    time.sleep(0.01)
    with server.osc_protocol.capture() as transcript:
        with provider.at(None):
            synth_proxy["frequency"] = 443
    assert [
        entry.message.to_list() for entry in transcript if not (
            entry.label == "R" and entry.message.address == "/status.reply")
    ] == [[None, [["/n_set", 1000, "frequency", 443.0]]]]
    time.sleep(0.01)
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 default
                    out: 0.0, amplitude: 0.1, frequency: 443.0, gate: 1.0, pan: 0.5
        """)
Пример #5
0
def test_RealtimeProvider_add_group_error(server):
    """
    Requires moment.
    """
    provider = Provider.from_context(server)
    with pytest.raises(ValueError):
        provider.add_group()
def test_NonrealtimeProvider_free_bus_group(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        bus_group_proxy = provider.add_bus_group(channel_count=2)
    with provider.at(2.3456):
        bus_group_proxy.free()
    assert session.to_lists(10) == [[10.0, [[0]]]]
def test_NonrealtimeProvider_free_bus(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        bus_proxy = provider.add_bus()
    with provider.at(2.3456):
        provider.free_bus(bus_proxy)
    assert session.to_lists(10) == [[10.0, [[0]]]]
Пример #8
0
def test_RealtimeProvider_add_synth_1(server):
    provider = Provider.from_context(server)
    seconds = time.time()
    with server.osc_protocol.capture() as transcript:
        with provider.at(seconds) as provider_moment:
            synth_proxy = provider.add_synth(amplitude=0.3, frequency=333)
    assert synth_proxy == SynthProxy(
        identifier=1000,
        provider=provider,
        synthdef=default,
        settings=dict(amplitude=0.3, frequency=333),
    )
    assert provider_moment == ProviderMoment(
        provider=provider,
        seconds=seconds,
        bus_settings=[],
        node_additions=[(synth_proxy, AddAction.ADD_TO_HEAD,
                         server.default_group)],
        node_removals=[],
        node_reorderings=[],
        node_settings=[],
    )
    assert [entry.message.to_list() for entry in transcript] == [[
        seconds + provider.latency,
        [["/s_new", "default", 1000, 0, 1, "amplitude", 0.3, "frequency",
          333]],
    ]]
    time.sleep(0.1)
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 default
                    out: 0.0, amplitude: 0.3, frequency: 333.0, gate: 1.0, pan: 0.5
        """)
def test_NonrealtimeProvider_add_synth_2(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        group_proxy = provider.add_group()
    with provider.at(2.3456):
        synth_proxy = provider.add_synth(target_node=group_proxy,
                                         amplitude=0.5,
                                         frequency=666)
    assert synth_proxy == SynthProxy(
        identifier=session.nodes_by_session_id[1001],
        provider=provider,
        synthdef=default,
        settings=dict(amplitude=0.5, frequency=666),
    )
    assert session.to_lists(10) == [
        [1.2345, [["/g_new", 1000, 0, 0]]],
        [
            2.3456,
            [
                *pytest.helpers.build_d_recv_commands([default]),
                [
                    "/s_new",
                    default.anonymous_name,
                    1001,
                    0,
                    1000,
                    "amplitude",
                    0.5,
                    "frequency",
                    666,
                ],
            ],
        ],
        [10.0, [["/n_free", 1000], ["/n_set", 1001, "gate", 0], [0]]],
    ]
Пример #10
0
def test_RealtimeProvider_add_group_2(server):
    provider = Provider.from_context(server)
    seconds = time.time()
    with server.osc_protocol.capture() as transcript:
        with provider.at(None):
            group_proxy_one = provider.add_group()
        with provider.at(seconds + 0.01) as provider_moment:
            group_proxy_two = provider.add_group(target_node=group_proxy_one)
    assert group_proxy_two == GroupProxy(identifier=1001, provider=provider)
    assert provider_moment == ProviderMoment(
        provider=provider,
        seconds=seconds + 0.01,
        bus_settings=[],
        node_additions=[(group_proxy_two, AddAction.ADD_TO_HEAD,
                         group_proxy_one)],
        node_removals=[],
        node_reorderings=[],
        node_settings=[],
    )
    assert [entry.message.to_list() for entry in transcript] == [
        [None, [["/g_new", 1000, 0, 1]]],
        [seconds + 0.01 + provider.latency, [["/g_new", 1001, 0, 1000]]],
    ]
    time.sleep(0.1)
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 group
                    1001 group
        """)
Пример #11
0
def test_RealtimeProvider_set_node_error(server):
    provider = Provider.from_context(server)
    with provider.at(None):
        group_proxy = provider.add_group()
        synth_proxy = provider.add_synth()
    with pytest.raises(ValueError):
        group_proxy["foo"] = 23
    with pytest.raises(ValueError):
        synth_proxy["foo"] = 23
def test_NonrealtimeProvider_free_node_error(session):
    """
    Requires moment.
    """
    provider = Provider.from_context(session)
    with provider.at(0):
        group_proxy = provider.add_group()
    with pytest.raises(ValueError):
        provider.free_node(group_proxy)
def test_NonrealtimeProvider_set_node_error(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        group_proxy = provider.add_group()
        synth_proxy = provider.add_synth()
    with pytest.raises(ValueError):
        group_proxy["foo"] = 23
    with pytest.raises(ValueError):
        synth_proxy["foo"] = 23
def test_NonrealtimeProvider_add_buffer_1(session):
    provider = Provider.from_context(session)
    file_path = locate("supriya.assets:audio/pulse_44100sr_16bit_octo.wav")
    with provider.at(1.2345):
        proxy = provider.add_buffer(file_path=file_path)
    assert isinstance(proxy, BufferProxy)
    assert session.to_lists(10) == [
        [1.2345, [["/b_allocRead", 0, str(file_path), 0, -1]]],
        [10.0, [["/b_free", 0], [0]]],
    ]
def test_NonrealtimeProvider_add_bus_error(session):
    """
    Must be control or audio rate.
    """
    provider = Provider.from_context(session)
    with pytest.raises(ValueError):
        provider.add_bus()
    with provider.at(0):
        with pytest.raises(ValueError):
            provider.add_bus(calculation_rate="scalar")
def test_NonrealtimeProvider_set_bus_1(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        bus_group_proxy = provider.add_bus_group(channel_count=4)
        for i, bus_proxy in enumerate(bus_group_proxy):
            bus_proxy.set_(pow(2, i))
    assert session.to_lists(10) == [
        [1.2345, [["/c_set", 0, 1.0, 1, 2.0, 2, 4.0, 3, 8.0]]],
        [10.0, [[0]]],
    ]
def test_NonrealtimeProvider_set_bus_error(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        audio_bus_proxy = provider.add_bus(
            calculation_rate=CalculationRate.AUDIO)
        control_bus_proxy = provider.add_bus()
        with pytest.raises(ValueError):
            audio_bus_proxy.set_(0.1234)
    with pytest.raises(ValueError):
        control_bus_proxy.set_(0.1234)
def test_NonrealtimeProvider_move_node_error(session):
    """
    Requires moment.
    """
    provider = Provider.from_context(session)
    with provider.at(0):
        group_proxy_one = provider.add_group()
        group_proxy_two = provider.add_group()
    with pytest.raises(ValueError):
        group_proxy_one.move(AddAction.ADD_TO_HEAD, group_proxy_two)
def test_NonrealtimeProvider_add_group_1(session):
    provider = Provider.from_context(session)
    seconds = 1.2345
    with provider.at(seconds):
        group_proxy = provider.add_group()
    assert group_proxy == GroupProxy(
        identifier=session.nodes_by_session_id[1000], provider=provider)
    assert session.to_lists(10) == [
        [1.2345, [["/g_new", 1000, 0, 0]]],
        [10.0, [["/n_free", 1000], [0]]],
    ]
Пример #20
0
def test_RealtimeProvider_free_buffer(server):
    provider = Provider.from_context(server)
    file_path = locate("supriya.assets:audio/pulse_44100sr_16bit_octo.wav")
    with provider.at(1.2345):
        proxy = provider.add_buffer(file_path=file_path)
    time.sleep(0.1)
    with server.osc_protocol.capture() as transcript:
        with provider.at(2.3456):
            proxy.free()
    assert [entry.message.to_list()
            for entry in transcript] == [[2.4456, [["/b_free", 0]]]]
def test_NonrealtimeProvider_set_node_1(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        group_proxy = provider.add_group()
    with provider.at(2.3456):
        group_proxy["foo"] = 23
    assert session.to_lists(10) == [
        [1.2345, [["/g_new", 1000, 0, 0]]],
        [2.3456, [["/n_set", 1000, "foo", 23]]],
        [10.0, [["/n_free", 1000], [0]]],
    ]
Пример #22
0
def test_RealtimeProvider_set_node_1(server):
    provider = Provider.from_context(server)
    seconds = time.time()
    with provider.at(seconds):
        group_proxy = provider.add_group()
    with server.osc_protocol.capture() as transcript:
        with provider.at(seconds + 0.01):
            group_proxy["foo"] = 23
    assert [entry.message.to_list() for entry in transcript] == [[
        seconds + 0.01 + provider.latency, [["/n_set", 1000, "foo", 23]]
    ]]
Пример #23
0
def test_RealtimeProvider_add_bus_1(server):
    provider = Provider.from_context(server)
    with provider.at(1.2345):
        bus_proxy_one = provider.add_bus(calculation_rate="audio")
        bus_proxy_two = provider.add_bus()
    assert bus_proxy_one == BusProxy(calculation_rate=CalculationRate.AUDIO,
                                     identifier=16,
                                     provider=provider)
    assert bus_proxy_two == BusProxy(calculation_rate=CalculationRate.CONTROL,
                                     identifier=0,
                                     provider=provider)
def test_NonrealtimeProvider_add_bus_group_error(session):
    """
    Must be 1 or more channels and control or audio rate.
    """
    provider = Provider.from_context(session)
    with pytest.raises(ValueError):
        provider.add_bus_group()
    with provider.at(0):
        with pytest.raises(ValueError):
            provider.add_bus_group(channel_count=0)
        with pytest.raises(ValueError):
            provider.add_bus_group(calculation_rate="scalar")
Пример #25
0
def test_RealtimeProvider_add_buffer_1(server):
    provider = Provider.from_context(server)
    file_path = locate("supriya.assets:audio/pulse_44100sr_16bit_octo.wav")
    with server.osc_protocol.capture() as transcript:
        with provider.at(1.2345):
            proxy = provider.add_buffer(file_path=file_path)
        time.sleep(0.1)
    assert isinstance(proxy, BufferProxy)
    assert [entry.message.to_list() for entry in transcript] == [
        [1.3345, [["/b_allocRead", 0, str(file_path), 0, -1]]],
        ["/done", "/b_allocRead", 0],
    ]
Пример #26
0
def test_RealtimeProvider_set_bus_1(server):
    provider = Provider.from_context(server)
    seconds = time.time()
    with server.osc_protocol.capture() as transcript:
        with provider.at(seconds):
            bus_group_proxy = provider.add_bus_group(channel_count=4)
            for i, bus_proxy in enumerate(bus_group_proxy):
                bus_proxy.set_(pow(2, i))
    assert [entry.message.to_list() for entry in transcript] == [[
        seconds + provider.latency,
        [["/c_set", 0, 1.0, 1, 2.0, 2, 4.0, 3, 8.0]]
    ]]
def test_NonrealtimeProvider_move_node_1(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        group_proxy_one = provider.add_group()
        group_proxy_two = provider.add_group()
    with provider.at(2.3456):
        provider.move_node(group_proxy_one, AddAction.ADD_TO_TAIL,
                           group_proxy_two)
    assert session.to_lists(10) == [
        [1.2345, [["/g_new", 1000, 0, 0], ["/g_new", 1001, 0, 0]]],
        [2.3456, [["/g_tail", 1001, 1000]]],
        [10.0, [["/n_free", 1000, 1001], [0]]],
    ]
def test_NonrealtimeProvider_add_group_2(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        group_proxy_one = provider.add_group()
    with provider.at(2.3456):
        group_proxy_two = provider.add_group(target_node=group_proxy_one)
    assert session.to_lists(10) == [
        [1.2345, [["/g_new", 1000, 0, 0]]],
        [2.3456, [["/g_new", 1001, 0, 1000]]],
        [10.0, [["/n_free", 1000, 1001], [0]]],
    ]
    assert group_proxy_one == GroupProxy(
        identifier=session.nodes_by_session_id[1000], provider=provider)
    assert group_proxy_two == GroupProxy(
        identifier=session.nodes_by_session_id[1001], provider=provider)
def test_NonrealtimeProvider_add_bus_1(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        bus_proxy_one = provider.add_bus(calculation_rate="audio")
        bus_proxy_two = provider.add_bus()
    assert bus_proxy_one == BusProxy(
        calculation_rate=CalculationRate.AUDIO,
        identifier=session.buses_by_session_id[0],
        provider=provider,
    )
    assert bus_proxy_two == BusProxy(
        calculation_rate=CalculationRate.CONTROL,
        identifier=session.buses_by_session_id[1],
        provider=provider,
    )
    assert session.to_lists(10) == [[10.0, [[0]]]]
def test_NonrealtimeProvider_set_node_2(session):
    provider = Provider.from_context(session)
    with provider.at(1.2345):
        synth_proxy = provider.add_synth()
    with provider.at(2.3456):
        synth_proxy["frequency"] = 666.666
    assert session.to_lists(10) == [
        [
            1.2345,
            [
                *pytest.helpers.build_d_recv_commands([default]),
                ["/s_new", default.anonymous_name, 1000, 0, 0],
            ],
        ],
        [2.3456, [["/n_set", 1000, "frequency", 666.666]]],
        [10.0, [["/n_set", 1000, "gate", 0], [0]]],
    ]