temporal: implement a faster method to lookup TempoPoint

There is no reason to build a TempoMetric if you only need the Tempo
This commit is contained in:
Paul Davis 2021-11-11 16:50:04 -07:00
parent 5105083394
commit 4f3bf37680
2 changed files with 54 additions and 4 deletions

View file

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

View file

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