Repository navigation
Conversation
MidiTrack played at one fixed rate for the whole track, so a file that changes tempo, or that simply does not use the 120 BPM default, played at the wrong speed throughout. The Set Tempo meta event was skipped. Act on Set Tempo. Its value is in microseconds per quarter note, which can only be converted to the ticks per second MidiTrack works in if the ticks per quarter note is known, so take that as a new optional ticks_per_beat argument. from_file() reads it from the file header; it is left at 0 for SMPTE timing, where the rate is already absolute and Set Tempo does not apply, and for callers that pass raw track bytes without it. The tempo is rewound along with the track when the sample restarts, so a looping track does not inherit the rate its last loop ended on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tyeth
added this pull request to stack #11668
October 23, 2026 22:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last of five stacked PRs; targets the branch of the previous one. This one is a feature rather than a bug fix, so it is deliberately last and can be dropped independently of the four below it.
MidiTrackplayed at one fixed rate for the whole track, so a file that changes tempo, or that simply does not use the 120 BPM default, played at the wrong speed throughout. The Set Tempo meta event was skipped.Act on Set Tempo. Its value is in microseconds per quarter note, which can only be converted to the ticks per second
MidiTrackworks in if the ticks per quarter note is known, so that becomes a new optionalticks_per_beatargument.from_file()reads it from the file header. It stays 0 for SMPTE timing, where the rate is already absolute and Set Tempo does not apply, and for callers passing raw track bytes without it — so existing code is unaffected.The tempo is rewound along with the track when the sample restarts, so a looping track does not inherit the rate its last loop ended on.
Verification
Cross-checked against
adafruit_midi_parseron a file with a mid-track tempo change: the new decoder reproduces its timings exactly (0.50s then 0.25s). A 30-second format-0 excerpt of the Bach Toccata carrying ten Set Tempo events decodes to 114 note events and follows the ritardando from 512 down to 93 ticks/sec; on the old decoder the same file is silent. Builds clean on arm and xtensa.Size
About +144 bytes of flash on nrf52840, plus six bytes per
MidiTrackobject.🤖 Generated with Claude Code