Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SMPTE based SMF division #457

Open
1 of 5 tasks
rdoursenaud opened this issue Jan 31, 2023 · 0 comments · May be fixed by #456
Open
1 of 5 tasks

Add support for SMPTE based SMF division #457

rdoursenaud opened this issue Jan 31, 2023 · 0 comments · May be fixed by #456
Assignees
Labels
bug enhancement feature:midifile Standard MIDI File (SMF) implementation
Milestone

Comments

@rdoursenaud
Copy link
Member

rdoursenaud commented Jan 31, 2023

Standard MIDI Files (SMF) can specify their time base division in two formats:

  • ticks per quarter-note (aka notation-based)
  • negative SMPTE format + ticks per frame (aka time-based)

Currently, mido only supports the first format and creates invalid data when the second is present.

Spec

This information is stored in the Header Chunk of the SMF in the division field:

b'MThd'    # Header chunk magic (4 bytes)
<length>   # Length of the following data. At least 6 bytes. (1 byte)
<ff>       # Format type (2 bytes representing a 16-bit word MSB first aka big-endian)
<ntrks>    # Number of tracks (2 bytes representing a 16-bit word MSB first aka big-endian)
<division> # Time base division (2 bytes representing a 16-bit word MSB first aka big-endian)

The data is a 16-bit word (2 bytes big-endian).
The most significat bit represents the time base division format:

  • 0: ticks-per quarter note.
    The value is stored in the 15 other bits in big-endian form.
  • 1: SMPTE.
    Negative SMPTE format encodes the framerate onto the remaining 7 bits of the most significant byte.
    The least significant byte encodes the tick per frames.

Challenges

mido always expects ticks_per_beat (sic) for the moment.
A thorough review of the implications is required before implementation.
Including, but not limited to:

  • Tempo determination
  • Time units conversions
  • Message time property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement feature:midifile Standard MIDI File (SMF) implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant