def test_perform():
    provider = Provider.realtime()
    spy = Mock(wraps=provider)
    proxy_mapping = {}
    notes_mapping = {}
    # Allocate
    event = SynthAllocateEvent(id_)
    with provider.at():
        event.perform(
            spy,
            proxy_mapping,
            current_offset=0.0,
            notes_mapping=notes_mapping,
            priority=Priority.START,
        )
    assert proxy_mapping == {
        id_:
        SynthProxy(provider=provider,
                   identifier=1000,
                   synthdef=default,
                   settings={})
    }
    assert notes_mapping == {}
    assert spy.mock_calls == [
        call.add_synth(add_action=AddAction.ADD_TO_HEAD,
                       synthdef=None,
                       target_node=None)
    ]
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]]],
    ]
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]]],
    ]
Esempio n. 4
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
        """)
Esempio n. 5
0
def test_RealtimeProvider_add_synth_2(server):
    provider = Provider.from_context(server)
    seconds = time.time()
    with server.osc_protocol.capture() as transcript:
        with provider.at(None):
            group_proxy = provider.add_group()
        with provider.at(seconds + 0.01) as provider_moment:
            synth_proxy = provider.add_synth(target_node=group_proxy,
                                             amplitude=0.5,
                                             frequency=666)
    assert synth_proxy == SynthProxy(
        identifier=1001,
        provider=provider,
        synthdef=default,
        settings=dict(amplitude=0.5, frequency=666),
    )
    assert provider_moment == ProviderMoment(
        provider=provider,
        seconds=seconds + 0.01,
        bus_settings=[],
        node_additions=[(synth_proxy, AddAction.ADD_TO_HEAD, group_proxy)],
        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,
            [[
                "/s_new", "default", 1001, 0, 1000, "amplitude", 0.5,
                "frequency", 666
            ]],
        ],
    ]
    time.sleep(0.1)
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 group
                    1001 default
                        out: 0.0, amplitude: 0.5, frequency: 666.0, gate: 1.0, pan: 0.5
        """)
Esempio n. 6
0
def test_RealtimeProvider_add_synth_3(server):
    provider = Provider.from_context(server)
    with server.osc_protocol.capture() as transcript:
        with provider.at(None):
            audio_bus_proxy = provider.add_bus("audio")
            control_bus_proxy = provider.add_bus("control")
            synth_proxy = provider.add_synth(amplitude=control_bus_proxy,
                                             out=audio_bus_proxy)
    assert synth_proxy == SynthProxy(
        identifier=1000,
        provider=provider,
        synthdef=default,
        settings=dict(amplitude=control_bus_proxy, out=audio_bus_proxy),
    )
    assert [entry.message.to_list() for entry in transcript] == [[
        None,
        [["/s_new", "default", 1000, 0, 1, "amplitude", "c0", "out", 16.0]]
    ]]
    assert str(server.query()) == normalize("""
        NODE TREE 0 group
            1 group
                1000 default
                    out: 16.0, amplitude: c0, frequency: 440.0, gate: 1.0, pan: 0.5
        """)
def test_perform():
    provider = Provider.realtime()
    proxy_mapping = {}
    notes_mapping = {}
    # 0: Allocate a bus for later
    bus_event = BusAllocateEvent(bus_id, calculation_rate="control")
    with provider.at():
        bus_event.perform(
            provider,
            proxy_mapping,
            current_offset=0.0,
            notes_mapping=notes_mapping,
            priority=Priority.START,
        )
    # A: Allocate
    event_one = NoteEvent(id_)
    spy = Mock(wraps=provider)
    with provider.at():
        event_one.perform(
            spy,
            proxy_mapping,
            current_offset=0.0,
            notes_mapping=notes_mapping,
            priority=Priority.START,
        )
    assert proxy_mapping == {
        id_:
        SynthProxy(provider=provider,
                   identifier=1000,
                   synthdef=default,
                   settings={}),
        bus_id:
        BusGroupProxy(
            calculation_rate=CalculationRate.CONTROL,
            channel_count=1,
            identifier=0,
            provider=provider,
        ),
    }
    assert notes_mapping == {id_: 1.0}
    assert spy.mock_calls == [
        call.add_synth(add_action=AddAction.ADD_TO_HEAD,
                       synthdef=None,
                       target_node=None)
    ]
    # Wait
    provider.server.sync()
    # B: Already allocated, so update settings
    event_two = NoteEvent(id_, amplitude=bus_id, frequency=550)
    spy = Mock(wraps=provider)
    with provider.at():
        event_two.perform(
            spy,
            proxy_mapping,
            current_offset=1.0,
            notes_mapping=notes_mapping,
            priority=Priority.START,
        )
    assert proxy_mapping == {
        id_:
        SynthProxy(provider=provider,
                   identifier=1000,
                   synthdef=default,
                   settings={}),
        bus_id:
        BusGroupProxy(
            calculation_rate=CalculationRate.CONTROL,
            channel_count=1,
            identifier=0,
            provider=provider,
        ),
    }
    assert notes_mapping == {id_: 2.0}
    assert spy.mock_calls == [
        call.set_node(
            SynthProxy(provider=provider,
                       identifier=1000,
                       synthdef=default,
                       settings={}),
            amplitude=proxy_mapping[bus_id],
            frequency=550,
        )
    ]
    # C: Free, but stop time doesn't match: no-op
    spy = Mock(wraps=provider)
    with provider.at():
        event_one.perform(
            spy,
            proxy_mapping,
            current_offset=1.0,
            notes_mapping=notes_mapping,
            priority=Priority.STOP,
        )
    assert proxy_mapping == {
        id_:
        SynthProxy(provider=provider,
                   identifier=1000,
                   synthdef=default,
                   settings={}),
        bus_id:
        BusGroupProxy(
            calculation_rate=CalculationRate.CONTROL,
            channel_count=1,
            identifier=0,
            provider=provider,
        ),
    }
    assert notes_mapping == {id_: 2.0}
    assert spy.mock_calls == []
    # D: Free, and stop time does match
    spy = Mock(wraps=provider)
    with provider.at():
        event_one.perform(
            spy,
            proxy_mapping,
            current_offset=2.0,
            notes_mapping=notes_mapping,
            priority=Priority.STOP,
        )
    assert proxy_mapping == {
        bus_id:
        BusGroupProxy(
            calculation_rate=CalculationRate.CONTROL,
            channel_count=1,
            identifier=0,
            provider=provider,
        )
    }
    assert notes_mapping == {}
    assert spy.mock_calls == [
        call.free_node(
            SynthProxy(provider=provider,
                       identifier=1000,
                       synthdef=default,
                       settings={}))
    ]
Esempio n. 8
0
     add_action=AddAction.ADD_TO_HEAD,
     synthdef=None,
     target_node=None,
     frequency=440,
 ),
 call.at(2.0),
 call.add_synth(
     add_action=AddAction.ADD_TO_HEAD,
     synthdef=None,
     target_node=None,
     frequency=550,
 ),
 call.free_node(
     SynthProxy(
         provider=provider,
         identifier=1000,
         synthdef=default,
         settings={"frequency": 440},
     )),
 call.at(4.0),
 call.add_synth(
     add_action=AddAction.ADD_TO_HEAD,
     synthdef=None,
     target_node=None,
     frequency=660,
 ),
 call.free_node(
     SynthProxy(
         provider=provider,
         identifier=1001,
         synthdef=default,
         settings={"frequency": 550},