diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index e91af44587..5d19053160 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -2774,6 +2774,47 @@ TempoMap::previous_tempo (TempoPoint const & point) const return 0; } +TempoPoint const & +TempoMap::tempo_at (timepos_t const & pos) const +{ + if (pos.is_beats()) { + return tempo_at (pos.beats()); + } + + return tempo_at (pos.superclocks()); +} + +TempoPoint const & +TempoMap::tempo_at (superclock_t sc) const +{ + assert (!_tempos.empty()); + Point::sclock_comparator cmp; + Tempos::const_iterator t = std::lower_bound (_tempos.begin(), _tempos.end(), sc, cmp); + assert (t != _tempos.end()); + return *t; +} + + +TempoPoint const & +TempoMap::tempo_at (Beats const & b) const +{ + assert (!_tempos.empty()); + Point::beat_comparator cmp; + Tempos::const_iterator t = std::lower_bound (_tempos.begin(), _tempos.end(), b, cmp); + assert (t != _tempos.end()); + return *t; +} + +TempoPoint const & +TempoMap::tempo_at (BBT_Time const & bbt) const +{ + assert (!_tempos.empty()); + Point::bbt_comparator cmp; + Tempos::const_iterator t = std::lower_bound (_tempos.begin(), _tempos.end(), bbt, cmp); + assert (t != _tempos.end()); + return *t; +} + TempoMetric TempoMap::metric_at (timepos_t const & pos) const { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 1707f67e1f..7075807309 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -91,6 +91,9 @@ class /*LIBTEMPORAL_API*/ Point : public point_hook { bool operator() (Point const & a, Point const & b) const { return a.sclock() < b.sclock(); } + bool operator() (Point const & a, superclock_t sc) const { + return a.sclock() < sc; + } }; struct LIBTEMPORAL_API ptr_sclock_comparator { @@ -103,12 +106,18 @@ class /*LIBTEMPORAL_API*/ Point : public point_hook { bool operator() (Point const & a, Point const & b) const { return a.beats() < b.beats(); } + bool operator() (Point const & a, Beats const & beats) const { + return a.beats() < beats; + } }; struct LIBTEMPORAL_API bbt_comparator { bool operator() (Point const & a, Point const & b) const { return a.bbt() < b.bbt(); } + bool operator() (Point const & a, BBT_Time const & bbt) const { + return a.bbt() < bbt; + } }; /* all time members are supposed to be synced at all times, so we need @@ -752,10 +761,10 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API MeterPoint const& meter_at (Beats const & b) const { return metric_at (b).meter(); } LIBTEMPORAL_API MeterPoint const& meter_at (BBT_Time const & bbt) const { return metric_at (bbt).meter(); } - LIBTEMPORAL_API TempoPoint const& tempo_at (timepos_t const & p) const { return metric_at (p).tempo(); } - LIBTEMPORAL_API TempoPoint const& tempo_at (superclock_t sc) const { return metric_at (sc).tempo(); } - LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const { return metric_at (b).tempo(); } - LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Time const & bbt) const { return metric_at (bbt).tempo(); } + LIBTEMPORAL_API TempoPoint const& tempo_at (timepos_t const & p) const; + LIBTEMPORAL_API TempoPoint const& tempo_at (superclock_t sc) const; + LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const; + LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Time const & bbt) const; LIBTEMPORAL_API TempoPoint const* previous_tempo (TempoPoint const &) const;