From cc6a437faf836f1e6f542da09c5de2c17bf59147 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 3 Aug 2022 10:59:29 -0600 Subject: [PATCH] temporal: fix a bug in BBT_Time::round_up_to_bar() Also remove Meter:: versions of related methods, because they are not necessary. We only need metrical information for operations like ::round_to_bar() --- libs/temporal/bbt_time.cc | 14 ++++++++++++++ libs/temporal/beats.cc | 4 ++-- libs/temporal/tempo.cc | 31 ++----------------------------- libs/temporal/temporal/bbt_time.h | 2 +- libs/temporal/temporal/tempo.h | 3 --- 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/libs/temporal/bbt_time.cc b/libs/temporal/bbt_time.cc index fe5e249b71..5c876b0a38 100644 --- a/libs/temporal/bbt_time.cc +++ b/libs/temporal/bbt_time.cc @@ -23,6 +23,20 @@ using namespace Temporal; +BBT_Time +BBT_Time::round_up_to_bar() const +{ + if (ticks == 0 && beats == 1) { + return *this; + } + BBT_Time b = round_up_to_beat (); + if (b.beats > 1) { + b.bars += 1; + b.beats = 1; + } + return b; +} + BBT_Offset::BBT_Offset (double dbeats) { /* NOTE: this does not construct a BBT time in a canonical form, diff --git a/libs/temporal/beats.cc b/libs/temporal/beats.cc index b8d2ddfc77..fb3d594e80 100644 --- a/libs/temporal/beats.cc +++ b/libs/temporal/beats.cc @@ -49,12 +49,12 @@ Beats::round_to_subdivision (int subdivision, RoundMode dir) const { if (dir == RoundDownAlways && bbt.ticks == 0) { bbt = metric.bbt_subtract (bbt, Temporal::BBT_Offset (0, 0, 1)); } - bbt = metric.meter().round_down_to_bar (bbt); + bbt = bbt.round_down_to_bar (); } if (dir > 0) { if (dir == RoundUpAlways && bbt.ticks == 0) { bbt.ticks += 1; } - bbt = metric.meter().round_up_to_bar (bbt); + bbt = bbt.round_up_to_bar (); } else { bbt = metric.meter().round_to_bar (bbt); } diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index c0a8f05cb5..e044c7dee9 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -355,33 +355,6 @@ Meter::round_to_bar (Temporal::BBT_Time const & bbt) const return BBT_Time (bbt.bars, 1, 0); } -Temporal::BBT_Time -Meter::round_up_to_bar (Temporal::BBT_Time const & bbt) const -{ - if (bbt.ticks == 0 && bbt.beats == 1) { - return bbt; - } - BBT_Time b = bbt.round_up_to_beat (); - if (b.beats > 1) { - b.bars += 1; - b.beats = 1; - } - return b; -} - -Temporal::BBT_Time -Meter::round_down_to_bar (Temporal::BBT_Time const & bbt) const -{ - if (bbt.ticks == 0 && bbt.beats == 1) { - return bbt; - } - BBT_Time b = bbt.round_down_to_beat (); - if (b.beats > 1) { - b.beats = 1; - } - return b; -} - Temporal::BBT_Time Meter::round_up_to_beat (Temporal::BBT_Time const & bbt) const { @@ -1322,9 +1295,9 @@ TempoMap::move_meter (MeterPoint const & mp, timepos_t const & when, bool earlie bbt = metric.bbt_at (beats); if (round_up) { - bbt = metric.meter().round_up_to_bar (bbt); + bbt = bbt.round_up_to_bar (); } else { - bbt = metric.meter().round_down_to_bar (bbt); + bbt = bbt.round_down_to_bar (); } for (t = _tempos.begin(), prev_t = _tempos.end(); t != _tempos.end() && t->bbt() < bbt; ++t) { prev_t = t; } diff --git a/libs/temporal/temporal/bbt_time.h b/libs/temporal/temporal/bbt_time.h index 364371edfa..508ceb27b8 100644 --- a/libs/temporal/temporal/bbt_time.h +++ b/libs/temporal/temporal/bbt_time.h @@ -119,7 +119,7 @@ struct LIBTEMPORAL_API BBT_Time * next bar time. */ - BBT_Time round_up_to_bar () const { return beats > 1 ? BBT_Time (bars+1, 1, 0) : BBT_Time (bars, 1, 0); } + BBT_Time round_up_to_bar () const; BBT_Time round_down_to_bar () const { return BBT_Time (bars, 1, 0); } BBT_Time next_bar () const { return (bars == -1) ? BBT_Time (1, 1, 0) : BBT_Time (bars+1, 1, 0); } BBT_Time prev_bar () const { return (bars == 1) ? BBT_Time (-1, 1, 0) : BBT_Time (bars-1, 1, 0); } diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 787dd84f2d..8dd28c58f2 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -332,10 +332,7 @@ class LIBTEMPORAL_API Meter { BBT_Time bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const; BBT_Time bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const; BBT_Time round_to_bar (BBT_Time const &) const; - BBT_Time round_down_to_bar (BBT_Time const &) const; - BBT_Time round_up_to_bar (BBT_Time const &) const; BBT_Time round_up_to_beat (BBT_Time const &) const; - BBT_Time round_to_beat (BBT_Time const &) const; Beats to_quarters (BBT_Offset const &) const; XMLNode& get_state () const;