Skip to main content

Module ppq_clock

Module ppq_clock 

Source
Expand description

PPQ (pulses-per-quarter-note) tick ↔ musical time ↔ wall-clock time.

A MIDI sequence measures time in ticks: there are ppq ticks in one quarter note (a “beat” in 4/4). At a tempo of bpm quarter notes per minute, one quarter note lasts 60 / bpm seconds, so

seconds = (ticks / ppq) * (60 / bpm)
ticks   = seconds * (bpm / 60) * ppq

Both directions are pure functions with no allocation — safe on the hot path. Values are validated: ppq and bpm must be strictly positive.

Functions§

seconds_to_ticks
Convert seconds of wall-clock time to a fractional PPQ tick count.
ticks_to_seconds
Convert a PPQ tick count to seconds of wall-clock time at a given tempo.