13
0

temporal: provide a new variant of ::get_tempo_and_meter() for BBT time

This one is more complex than the Beats or superclock variants, because
we cannot just start from the front of the map. Instead, we have to
first iterate through the map so that we start the code in
_get_tempo_and_meter<...> from the TempoPoint and MeterPoint
in effect at the BBT_Argument's reference time.
This commit is contained in:
Paul Davis 2023-09-22 15:09:11 -06:00
parent 3aacbc453e
commit 374283cc3f

View File

@ -1108,7 +1108,37 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
return _get_tempo_and_meter<const_traits<Beats const &, Beats> > (t, m, &Point::beats, b, _points.begin(), _points.end(), &_tempos.front(), &_meters.front(), can_match, ret_iterator_after_not_at);
}
Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, BBT_Argument const & bbt, bool can_match, bool ret_iterator_after_not_at) const {
if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
/* Skip through the tempo map to find the tempo and meter in
* effect at the bbt's "reference" time, and use them as the
* starting point for the normal operation of
* _get_tempo_and_meter ()
*/
Tempos::const_iterator tp = _tempos.begin();
Meters::const_iterator mp = _meters.begin();
superclock_t ref = bbt.reference();
if (ref != 0) {
while (tp != _tempos.end()) {
Tempos::const_iterator nxt = tp; ++nxt;
if (nxt == _tempos.end() || nxt->sclock() > ref) {
break;
}
tp = nxt;
}
while (mp != _meters.end()) {
Meters::const_iterator nxt = mp; ++nxt;
if (nxt == _meters.end() || mp->sclock() > ref) {
break;
}
}
}
return _get_tempo_and_meter<const_traits<BBT_Time const &, BBT_Time> > (t, m, &Point::bbt, bbt, _points.begin(), _points.end(), &(*tp), &(*mp), can_match, ret_iterator_after_not_at);
}
/* This is private, and should not be callable from outside the map