From 364598e94f3d0e93aeb481599cf49a8bd822d3b9 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 28 Oct 2024 14:01:43 -0600 Subject: [PATCH] temporal: add round_up_to_bar() methods to Meter, Metric and TempoMap --- libs/temporal/tempo.cc | 11 +++++++++++ libs/temporal/temporal/tempo.h | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index e607a27ed7..29c372db6d 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -359,6 +359,17 @@ 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.beats == 1 && bbt.ticks == 0) { + /* on bar, do not round up */ + return bbt; + } + + return BBT_Time (bbt.bars+1, 1, 0); +} + Temporal::BBT_Time Meter::round_up_to_beat_div (Temporal::BBT_Time const & bbt, int beat_div) const { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index d28066484a..d1405b710b 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -304,6 +304,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_up_to_bar (BBT_Time const &) const; BBT_Time round_up_to_beat_div (BBT_Time const &, int beat_div) const; BBT_Time round_up_to_beat (BBT_Time const & bbt) const { return round_up_to_beat_div (bbt, 1); } BBT_Time round_to_beat (BBT_Time const &) const; @@ -470,6 +471,7 @@ class LIBTEMPORAL_API TempoMetric BBT_Argument bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const { return BBT_Argument (reftime(), _meter->bbt_add (bbt, add)); } BBT_Argument bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const { return BBT_Argument (reftime(), _meter->bbt_subtract (bbt, sub)); } BBT_Argument round_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_to_bar (bbt)); } + BBT_Argument round_up_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_up_to_bar (bbt)); } Beats to_quarters (BBT_Offset const & bbo) const { return _meter->to_quarters (bbo); } /* combination methods that require both tempo and meter information */ @@ -929,10 +931,13 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible */ LIBTEMPORAL_API double quarters_per_minute_at (timepos_t const & pos) const; - /* convenience function */ + /* convenience functions */ LIBTEMPORAL_API BBT_Argument round_to_bar (BBT_Argument const & bbt) const { return metric_at (bbt).round_to_bar (bbt); } + LIBTEMPORAL_API BBT_Argument round_up_to_bar (BBT_Argument const & bbt) const { + return metric_at (bbt).round_up_to_bar (bbt); + } LIBTEMPORAL_API BBT_Argument bbt_at (timepos_t const &) const; LIBTEMPORAL_API BBT_Argument bbt_at (Beats const &) const;