13
0

fix BBT_Time::round_up_to_beat_div() (partially)

Math is now correct for cases where "beats" in BBT are quarters.
Incorrect for others
This commit is contained in:
Paul Davis 2023-09-22 22:54:37 -06:00
parent 44d32d6325
commit 14e7f62891

View File

@ -59,14 +59,14 @@ BBT_Time::round_up_to_bar() const
BBT_Time BBT_Time
BBT_Time::round_up_to_beat_div (int beat_div) const BBT_Time::round_up_to_beat_div (int beat_div) const
{ {
/* XXX this doesn't work where "beats" are not quarters, because /* XXX this doesn't work where "beats" are not quarters, because
we could have B|b|0 and this is not on a beat_div, even though it is we could have B|b|0 and this is not on a beat_div, even though it is
an integer beat position (think triplets. an integer beat position (think triplets.
*/ */
int32_t div_ticks = ticks_per_beat / beat_div; const int32_t div_ticks = ticks_per_beat / beat_div;
int32_t ticks_remainder = ticks % div_ticks; int32_t rounded_up = ticks + div_ticks - 1;
int32_t rounded_up = ticks + div_ticks - ticks_remainder; rounded_up -= rounded_up % div_ticks;
if (rounded_up == ticks_per_beat) { if (rounded_up == ticks_per_beat) {
return BBT_Time (bars, beats+1, 0); return BBT_Time (bars, beats+1, 0);