libtemporal: improve implementation/accuracy of Meter::round_to_bar()

This commit is contained in:
Paul Davis 2021-01-04 21:55:14 -07:00
parent e393c5efcf
commit 68f6bff258

View file

@ -343,12 +343,14 @@ Meter::bbt_subtract (Temporal::BBT_Time const & bbt, Temporal::BBT_Offset const
Temporal::BBT_Time Temporal::BBT_Time
Meter::round_to_bar (Temporal::BBT_Time const & bbt) const Meter::round_to_bar (Temporal::BBT_Time const & bbt) const
{ {
Temporal::BBT_Time b = bbt.round_to_beat (); Beats b (bbt.beats, bbt.ticks);
if (b.beats > _divisions_per_bar/2) { Beats half (Beats::ticks (Beats::PPQN + ((_divisions_per_bar * Beats::PPQN / 2))));
b.bars++;
if (b >= half) {
return BBT_Time (bbt.bars+1, 1, 0);
} }
b.beats = 1;
return b; return BBT_Time (bbt.bars, 1, 0);
} }
Temporal::BBT_Time Temporal::BBT_Time