Clock
MIDI Clock — source and sink, platform-agnostic.
Uses only sequencer.event_write(event, tick=True) for output. Works identically on CoreMIDI (macOS) and ALSA (Linux).
- class midi.clock.ClockSource(bpm=120.0, sequencer=None)
Bases:
objectClock source: schedules clock pulses via OS sequencer timestamps.
Call schedule_ahead() from your run loop to keep the buffer full. The OS delivers each pulse at the exact kernel-scheduled time.
- tick_for_pulse(pulse)
Return the sequencer tick value for a given pulse number.
- class midi.clock.ClockSink(sequencer_resolution)
Bases:
objectClock sink: processes incoming clock events.
Uses wall-clock time between ClockEvents for BPM estimation (exponential moving average). Feed events from event_read() into process().
- Parameters:
sequencer_resolution (int)
- tick_for_next_pulse(offset=0)
Predict tick for the next clock pulse (or +offset pulses ahead).
- process(event)
Feed events from event_read(). Recognizes Clock/Start/Stop/Continue/SPP.
- Return type:
- Parameters:
event (AbstractEvent)