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_perform(): provider = Provider.realtime() spy = Mock(wraps=provider) proxy_mapping = {} notes_mapping = {} # Allocate event = BusAllocateEvent(id_, calculation_rate="audio", channel_count=8) with provider.at(): event.perform( spy, proxy_mapping, current_offset=0.0, notes_mapping=notes_mapping, priority=Priority.START, ) assert proxy_mapping == { id_: BusGroupProxy( calculation_rate=CalculationRate.AUDIO, channel_count=8, identifier=16, provider=provider, ) } assert notes_mapping == {} assert spy.mock_calls == [ call.add_bus_group(calculation_rate=CalculationRate.AUDIO, channel_count=8) ]
def test_perform(): provider = Provider.realtime() proxy_mapping = {} notes_mapping = {} # Allocate allocate_event = GroupAllocateEvent(id_) with provider.at(): allocate_event.perform( provider, proxy_mapping, current_offset=0.0, notes_mapping=notes_mapping, priority=Priority.START, ) proxy = proxy_mapping[id_] # Wait provider.server.sync() # Free free_event = NodeFreeEvent(id_) spy = Mock(wraps=provider) with provider.at(): free_event.perform( spy, proxy_mapping, current_offset=0.0, notes_mapping=notes_mapping, priority=Priority.START, ) assert proxy_mapping == {} assert notes_mapping == {} assert spy.mock_calls == [call.free_node(proxy)]
def test(pattern, until, expected): clock = OfflineClock() provider = Provider.realtime() spy = Mock(spec=Provider, wraps=provider) pattern.play(provider=spy, clock=clock, until=until) expected_mock_calls = expected(provider) assert spy.mock_calls == expected_mock_calls
def play( self, provider=None, *, at=None, clock=None, quantization=None, tempo=None, until=None, ): if provider is None: provider = Provider.realtime() elif not isinstance(provider, Provider): provider = Provider.from_context(provider) if isinstance(provider, NonrealtimeProvider): clock = OfflineClock() at = at or 0.0 elif not clock: clock = Clock.default() player = PatternPlayer(pattern=self, provider=provider, clock=clock) player.play(quantization=quantization, at=at, until=until) return player
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={})) ]