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
This commit is contained in:
Paul Davis 2021-03-19 14:17:29 -06:00
parent f05b2ed93b
commit 991a7bf8a7
2 changed files with 11 additions and 0 deletions

View File

@ -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)
{

View File

@ -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"; }