def tempo_clock(mocker): tempo_clock = TempoClock() tempo_clock.slop = 0.001 mock = mocker.patch.object(TempoClock, "get_current_time") mock.return_value = 0.0 yield tempo_clock tempo_clock.stop()
def test_clock_skew(): tempo_clock = TempoClock() tempo_clock.slop = 0.0001 all_stats = [] for _ in range(5): store = [] for _ in range(20): delta = random.random() / 100 tempo_clock.schedule( callback, schedule_at=random.random(), args=[store], kwargs={ "limit": 100, "delta": delta, "time_unit": TimeUnit.SECONDS }, ) tempo_clock.start() time.sleep(5.0) tempo_clock.stop() stats = calculate_skew(store) print(" ".join(f"{key}: {value:f}" for key, value in stats.items())) all_stats.append(stats) threshold = tempo_clock.slop * 1.5 assert all(stats["median"] < threshold for stats in all_stats)
def test_realtime_02(limit, bpm_schedule, expected): store = [] tempo_clock = TempoClock() tempo_clock.cue(callback, quantization="1/4", args=[store], kwargs=dict(limit=limit)) for schedule_at, beats_per_minute in bpm_schedule: tempo_clock.schedule_change( beats_per_minute=beats_per_minute, schedule_at=schedule_at, time_unit=TimeUnit.SECONDS, ) tempo_clock.start() time.sleep(2) tempo_clock.stop() actual = [( desired_moment.offset, desired_moment.seconds - tempo_clock._state.initial_seconds, ) for current_moment, desired_moment, event in store] assert actual == expected
def __init__(self, pattern, server=None, event_template=None, clock=None): import supriya.patterns clock = clock or TempoClock.default() if event_template is None: event_template = supriya.patterns.NoteEvent() elif issubclass(event_template, supriya.patterns.Event): event_template = event_template() self._clock = clock self._cumulative_time = 0 self._event_template = event_template self._iterator = None self._pattern = pattern self._server = server or supriya.realtime.Server.default() self._uuids = {} self._event_id = None
def test_realtime_01(): store = [] tempo_clock = TempoClock() assert not tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 tempo_clock.start() assert tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 tempo_clock.schedule(callback, schedule_at=0.0, args=[store]) time.sleep(4) tempo_clock.stop() assert not tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 assert len(store) == 5 assert [ desired_moment.offset for current_moment, desired_moment, event in store ] == [0.0, 0.25, 0.5, 0.75, 1.0]
def test_realtime_01(schedule, start_clock_first, expected): """ Start clock, then schedule """ store = [] tempo_clock = TempoClock() assert not tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 if start_clock_first: tempo_clock.start() assert tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 if schedule: tempo_clock.schedule(callback, schedule_at=0.0, args=[store]) else: tempo_clock.cue(callback, quantization="1/4", args=[store]) if not start_clock_first: tempo_clock.start() assert tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 time.sleep(4) tempo_clock.stop() assert not tempo_clock.is_running assert tempo_clock.beats_per_minute == 120 assert len(store) == 5 actual = [ desired_moment.offset for current_moment, desired_moment, event in store ] assert actual == expected
def __init__(self): DawNode.__init__(self) self._clock = TempoClock() self._node = Synth(synthdef=self._build_synthdef(), name="transport")