BPM is calculated inaccurately
Opened this issue · 0 comments
Boscop commented
When I save a midi file from Reaper with BPM 127 it gets saved with 472441 ms per quarter note (beat).
When I open this file in MidiEditor.exe, it shows BPM 126.
The calculation it seems to do is:
int bpm = 1000000.0 * 60.0 / ms_per_beat;
But 60000000.0 / 472441
is 126.99998518333506194424277317168
, so it's shown as 126 because of truncation.
It should either show a fractional BPM or be a little more accurate by doing:
int bpm = 1000000.0 * 60.0 / ms_per_beat + 0.5;
instead :)
Similar care should be taken when saving the BPM.
E.g. in Reaper when I saved with BPM 127:
60000000.0 / 127 == 472440.94488188976377952755905512
And it stored 472441 (rounded up, probably with + 0.5
) instead of truncating!