Skip to content

Read-only tempo map (0x2028): get_tempo_map() + beats/samples conversion - #7

Open
katzzero wants to merge 1 commit into
sebedard-creator:masterfrom
katzzero:fix/tempo-map
Open

katzzero wants to merge 1 commit into
sebedard-creator:masterfrom
katzzero:fix/tempo-map

Conversation

@katzzero

Copy link
Copy Markdown

Fixes #6.

Adds read-only access to the session tempo map and musical-position conversion:

  • get_tempo_map() returns the ordered tempo changes — {position_ticks, beats, bpm} — read from the 0x2028 block under the unique 0x2718 container. A constant tempo yields one entry; tempo automation yields one entry per change (beat 0 = session start).
  • beats_to_samples() / samples_to_beats() convert a musical position using the session's own tempo map (not a fixed 120 BPM).
  • 0x2028 is added to FLAT_PTX_CONTENT_TYPES: its payload is a flat "Tempo" header plus 61-byte records, and scanning it for children produced false sub-blocks from incidental 0x5A bytes in the record timestamps.

Validation:

  • New unit tests in tests/test_tempo_map.py (constant tempo, ordered automation, session without a tempo container, unsupported header). Unknown geometry is refused, never guessed.
  • Full suite green on this branch base: 693 tests, OK (skipped=145) (the skips are the usual absent native fixtures).
  • Cross-checked on controlled fixtures: constant-tempo sessions yield one change; a 90→120 BPM ramp yields all 276 changes (monotonic, 90.0 → 119.0). Conversions validated at 48 kHz.

Everything here is offered under the MIT license, which is compatible with this project's LGPL-2.1-or-later.

- Parse the 0x2028 tempo block under the unique 0x2718 container (flat
  "Tempo" header + 61-byte records) and add 0x2028 to
  FLAT_PTX_CONTENT_TYPES so incidental 0x5A bytes in timestamps no longer
  form false sub-blocks.
- get_tempo_map() returns ordered {position_ticks, beats, bpm}; beat 0 is
  the session start.
- beats_to_samples() / samples_to_beats() convert musical positions via the
  session tempo map (no fixed 120 BPM).
- tests/test_tempo_map.py: constant tempo, automation, no-map and bad-header.

Refs sebedard-creator#6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tempo map (0x2028) decode: musical position (bar|beat ↔ samples) from the session

1 participant