From 883527ba3e8ade52a0a9c948d02231d09e7ca89c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 29 Nov 2022 09:34:28 -0700 Subject: [PATCH] temporal: add Meter::round_to_beat() --- libs/temporal/tempo.cc | 11 +++++++++++ libs/temporal/temporal/tempo.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 5503c022b7..46ab09b260 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -366,6 +366,17 @@ Meter::round_up_to_beat (Temporal::BBT_Time const & bbt) const return b; } +Temporal::BBT_Time +Meter::round_to_beat (Temporal::BBT_Time const & bbt) const +{ + Temporal::BBT_Time b = bbt.round_to_beat (); + if (b.beats > _divisions_per_bar) { + b.bars++; + b.beats = 1; + } + return b; +} + Temporal::Beats Meter::to_quarters (Temporal::BBT_Offset const & offset) const { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index e20979a9a7..65bb96289f 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -336,6 +336,7 @@ class LIBTEMPORAL_API Meter { 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_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;