Fix tempo rounding issue in MusicXML export #7309
Merged
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.
This is a long PR description for a seemingly simple issue :)
Since MuseScore internally stores tempo in units of 'beats per seconds' and truncates it to a fixed precision, the exported MusicXML tempo was sometimes incorrectly rounded. For example, 92 BPM in MuseScore was exported as 91.9998 and 88 BPM was exported as 88.0002.
To eliminate this error, tempo is now rounded to up to 2 decimal places when exporting (that is, up to 2 digits to the right of the decimal separator). Since the MuseScore interface itself only allows up to 2 decimal places anyway (in the Inspector), this is not expected to limit users.
Disclaimer: if files with fractional tempos are imported (with more than 2 decimal places), their tempo will be rounded to 2 decimal places on export, but this is presumably very rare (compared to the very common integer tempi which this PR fixes).
To reproduce the bug: Open MuseScore 3.6 and create a new score. Drag a 'quarter = 80' tempo marking to the score. Export the score to MusicXML – see the tempo is exported incorrectly (
sound tempo="79.9998"
). After applying this PR, it would be exported correctly.Note: the underlying cause to this bug is actually not related to MusicXML export, it is due to the fact that tempo is stored imprecisely in mscx/mscz files. To illustrate this, try the following: Open MuseScore 3.6 and create a new score. Drag a 'quarter = 80' tempo marking to the score. In the Inspector, untick 'Follow text', and then re-tick it (this causes re-computation of the tempo internally). Export the score to MusicXML – see the tempo is exported correctly (
sound tempo="80"
). Save the score to mscx/mscz, close the score, and re-open the mscx/mscz. Export again to MusicXML – now the tempo is exported incorrectly (sound tempo="79.9998"
).However, this PR doesn't fix the underlying issue because I'm not sure that this fix would be desirable to you. I submitted that change in #7310. In any case, even if the other PR is applied, the current PR is still needed, because of two reasons: 1) old mscx/mscz files that users have lying around, 2) the user's stored palette configurations will already have the tempo imprecisely stored.