From 68f6bff2581a3be506a68f8667edfc6404b85a30 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 4 Jan 2021 21:55:14 -0700 Subject: [PATCH] libtemporal: improve implementation/accuracy of Meter::round_to_bar() --- libs/temporal/tempo.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index a64bdd1caa..d346a6836e 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -343,12 +343,14 @@ Meter::bbt_subtract (Temporal::BBT_Time const & bbt, Temporal::BBT_Offset const Temporal::BBT_Time Meter::round_to_bar (Temporal::BBT_Time const & bbt) const { - Temporal::BBT_Time b = bbt.round_to_beat (); - if (b.beats > _divisions_per_bar/2) { - b.bars++; + Beats b (bbt.beats, bbt.ticks); + Beats half (Beats::ticks (Beats::PPQN + ((_divisions_per_bar * Beats::PPQN / 2)))); + + 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