From 991a7bf8a7461da748e31b571d2bcfb2006b874d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 19 Mar 2021 14:17:29 -0600 Subject: [PATCH] add TempoMap::count_bars() to allow bar counting even with position (BBT) markers in the tempo map This just reuses the algorithm in TempoMap::get_grid() by asking for just the bar grid, and counting the size of the result --- libs/temporal/tempo.cc | 10 ++++++++++ libs/temporal/temporal/tempo.h | 1 + 2 files changed, 11 insertions(+) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index ae3726c96c..e85b18886c 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -1971,6 +1971,16 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u DEBUG_TRACE (DEBUG::Grid, "<<< GRID DONE\n"); } +uint32_t +TempoMap::count_bars (Beats const & start, Beats const & end) +{ + TempoMapPoints bar_grid; + superclock_t s (superclock_at (start)); + superclock_t e (superclock_at (end)); + get_grid (bar_grid, s, e, 1); + return bar_grid.size(); +} + std::ostream& std::operator<<(std::ostream& str, Meter const & m) { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 8f379c48fb..4f8cfe2572 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -787,6 +787,7 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible BBT_Time bbt_walk (BBT_Time const &, BBT_Offset const &) const; void get_grid (TempoMapPoints& points, superclock_t start, superclock_t end, uint32_t bar_mod = 0); + uint32_t count_bars (Beats const & start, Beats const & end); struct EmptyTempoMapException : public std::exception { virtual const char* what() const throw() { return "TempoMap is empty"; }