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

Increase default MIDI ticksPerQuarter #1577

Merged
merged 3 commits into from
May 17, 2023

Conversation

TimFelixBeyer
Copy link
Contributor

According to comments in the code, the default MIDI ticksPerQuarter is set to 1024 to avoid a limitation in midi.py, which is no longer used.
Therefore, I propose to set the ticksPerQuarter to 10080 which is the same value used for MusicXML divisions. This would allow exported MIDI to represent more durations exactly without quantization errors and without significant risk/downsides.
I have also updated all relevant tests.
Let me know what you think!

@coveralls
Copy link

coveralls commented May 17, 2023

Coverage Status

Coverage: 93.104% (+8.0e-05%) from 93.104% when pulling 05548b0 on TimFelixBeyer:patch-6 into c20a4cd on cuthbertLab:master.

just a semantic change in case things change and ticksPerQuarter is no longer tied to divisionsPerQuarter later.
@mscuthbert
Copy link
Member

Good idea. Compatibility with buggy versions of midi.py is no longer a consideration, agreed.

Can you explain why the note was changed from 128th note to double the duration? Is there a bug that emerged?

@TimFelixBeyer
Copy link
Contributor Author

Sure, 1024 = 2^10, so we can represent even a 1/4096th note using integer ticks.
10080 = 2^5 * 3^2 * 5 * 7, so the smallest standard (1/2^n) note it can represent exactly is a 1/128th note.
The example effectively implemented a 3/256th note (dotted 128th), which would have required a non-integer tick.

I‘d advise against increasing the default ticksPerQuarter over 10080, as it is already on the high side for MIDI (typical range 120-960), and very high ticks may lead to compatibility problems with other libraries (craffel/pretty-midi#175)
Users can always override the default if they want more precision and want to represent tiny notes (3/256th) exactly.

@mscuthbert
Copy link
Member

Thanks! Got it!

@mscuthbert mscuthbert merged commit 6201cf0 into cuthbertLab:master May 17, 2023
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.

3 participants