temporal: TempoMap::tempo_at() ... templates FTW

This commit is contained in:
Paul Davis 2021-11-13 10:00:25 -07:00
parent fb2281129a
commit 4128088b70
2 changed files with 8 additions and 54 deletions

View File

@ -2855,63 +2855,15 @@ TempoMap::tempo_at (timepos_t const & pos) const
return pos.is_beats() ? tempo_at (pos.beats()) : tempo_at (pos.superclocks());
}
template<typename TimeType, typename Comparator>
TempoPoint const &
TempoMap::tempo_at (superclock_t sc) const
TempoMap::_tempo_at (TimeType when, Comparator cmp) const
{
assert (!_tempos.empty());
Point::sclock_comparator cmp;
Tempos::const_iterator prev = _tempos.end();
for (Tempos::const_iterator t = _tempos.begin(); t != _tempos.end(); ++t) {
if (cmp (*t, sc)) {
prev = t;
} else {
break;
}
}
if (prev == _tempos.end()) {
return _tempos.front();
}
return *prev;
}
TempoPoint const &
TempoMap::tempo_at (Beats const & b) const
{
assert (!_tempos.empty());
Point::beat_comparator cmp;
Tempos::const_iterator prev = _tempos.end();
for (Tempos::const_iterator t = _tempos.begin(); t != _tempos.end(); ++t) {
if (cmp (*t, b)) {
prev = t;
} else {
break;
}
}
if (prev == _tempos.end()) {
return _tempos.front();
}
return *prev;
Tempos::const_iterator t = std::lower_bound (_tempos.begin(), _tempos.end(), b, cmp);
if (t == _tempos.end()) {
return _tempos.front();
}
return *t;
}
TempoPoint const &
TempoMap::tempo_at (BBT_Time const & bbt) const
{
assert (!_tempos.empty());
Point::bbt_comparator cmp;
Tempos::const_iterator prev = _tempos.end();
for (Tempos::const_iterator t = _tempos.begin(); t != _tempos.end(); ++t) {
if (cmp (*t, bbt)) {
if (cmp (*t, when)) {
prev = t;
} else {
break;

View File

@ -763,9 +763,9 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
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;
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& tempo_at (superclock_t sc) const { return _tempo_at (sc, Point::sclock_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const { return _tempo_at (b, Point::beat_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Time const & bbt) const { return _tempo_at (bbt, Point::bbt_comparator()); }
LIBTEMPORAL_API TempoPoint const* previous_tempo (TempoPoint const &) const;
@ -868,6 +868,8 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
BBT_Time bbt_at (Beats const &) const;
BBT_Time bbt_at (superclock_t sc) const;
template<typename TimeType, typename Comparator> TempoPoint const & _tempo_at (TimeType when, Comparator cmp) const;
template<typename T, typename T1> struct const_traits {
typedef Points::const_iterator iterator_type;
typedef TempoPoint const * tempo_point_type;