Musical subdivision constants and clock/timing helpers.
More...
|
| uint32_t | beats_to_ticks (float beats, uint32_t bpm) |
| | Convert musical beats at a given tempo into microseconds.
|
| uint32_t | subdivision_us (uint8_t subdiv, uint32_t bpm) |
| | Microseconds per single subdivision at the given tempo.
|
| uint32_t | quantize_to_grid (uint32_t tick_us, uint32_t subdiv_us) |
| | Round a tick value down to the nearest grid boundary.
|
| int32_t | swing_offset (uint32_t tick_us, uint8_t swing_percent, uint32_t subdiv_us) |
| | Microsecond offset to apply to "every other" subdivision to create swing feel.
|
|
|
constexpr uint8_t | kSubdiv1 = 0 |
| | Whole note subdivision (4 beats in 4/4).
|
|
constexpr uint8_t | kSubdiv_2 = 1 |
| | Half note subdivision.
|
|
constexpr uint8_t | kSubdiv_4 = 2 |
| | Quarter note subdivision (one beat).
|
|
constexpr uint8_t | kSubdiv_8 = 3 |
| | Eighth note subdivision.
|
|
constexpr uint8_t | kSubdiv_16 = 4 |
| | Sixteenth note subdivision.
|
|
constexpr uint8_t | kSubdiv_32 = 5 |
| | Thirty-second note subdivision.
|
|
constexpr uint8_t | kSubdivTripletQuarter = 6 |
| | Quarter-note triplet (three notes per half-note).
|
|
constexpr uint8_t | kSubdivTripletEighth = 7 |
| | Eighth-note triplet (three notes per quarter-note).
|
|
constexpr uint8_t | kSubdivTripletSixteenth = 8 |
| | Sixteenth-note triplet (three notes per eighth-note).
|
Musical subdivision constants and clock/timing helpers.
◆ beats_to_ticks()
| uint32_t op::sdk::timing::beats_to_ticks |
( |
float | beats, |
|
|
uint32_t | bpm ) |
|
inline |
Convert musical beats at a given tempo into microseconds.
- Parameters
-
| beats | Fractional beat count. |
| bpm | Tempo in beats per minute (must be non-zero). |
- Returns
- Duration in microseconds, or 0 if bpm == 0.
◆ quantize_to_grid()
| uint32_t op::sdk::timing::quantize_to_grid |
( |
uint32_t | tick_us, |
|
|
uint32_t | subdiv_us ) |
|
inline |
Round a tick value down to the nearest grid boundary.
- Parameters
-
| tick_us | Microsecond timestamp. |
| subdiv_us | Grid step in microseconds (typically from subdivision_us). |
- Returns
- Largest multiple of subdiv_us that is <= tick_us.
-
tick_us unchanged when subdiv_us == 0.
◆ subdivision_us()
| uint32_t op::sdk::timing::subdivision_us |
( |
uint8_t | subdiv, |
|
|
uint32_t | bpm ) |
|
inline |
Microseconds per single subdivision at the given tempo.
- Parameters
-
| subdiv | One of the kSubdiv* constants. |
| bpm | Tempo in beats per minute (must be non-zero). |
- Returns
- Duration of one step of that subdivision, or 0 for unknown input.
Reference (120 BPM): quarter = 500'000us, eighth = 250'000us, triplet eighth = 166'666us.
Safe for bpm in [1, ...]. The result fits uint32_t for all bpm >= 1 (the worst case, kSubdiv1 at bpm == 1, is 240'000'000us, well within the uint32_t range).
◆ swing_offset()
| int32_t op::sdk::timing::swing_offset |
( |
uint32_t | tick_us, |
|
|
uint8_t | swing_percent, |
|
|
uint32_t | subdiv_us ) |
|
inline |
Microsecond offset to apply to "every other" subdivision to create swing feel.
- Parameters
-
| tick_us | Target tick (used to decide whether we are on an even or odd subdivision). |
| swing_percent | 0..100. 50 is "no swing" (straight feel). Higher values delay the off-beat subdivision proportionally. |
| subdiv_us | Duration of one grid step (see subdivision_us). |
- Returns
- Signed microsecond offset to add to the off-beat's nominal time, 0 on the on-beat or when subdiv_us == 0.
Pass a grid-quantized tick_us (see quantize_to_grid) so the even/odd subdivision classification lands on true grid-step boundaries. An unquantized tick_us near a boundary can flip parity under integer truncation.