diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index a285810883..e0c3295dfc 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -3503,7 +3503,12 @@ TempoMap::metric_at (BBT_Argument const & bbt, bool can_match) const TempoPoint const * tp = 0; MeterPoint const * mp = 0; - (void) get_tempo_and_meter (tp, mp, bbt, can_match, false); + /* Since the reference time of a BBT_Argument is the time of the + * latest tempo/meter marker before or at BBT, we can use the reference + * time to get the metric. + */ + + (void) get_tempo_and_meter (tp, mp, bbt.reference(), can_match, false); return TempoMetric (*tp, *mp); } diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 83fa1df75c..672fb73046 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -1052,43 +1052,19 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible * other similar call sites where we do not modify the map */ - 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 { - - /* because `this` is const (because the method is marked - * const), the following: - - _points.begin() - _points.end() - _tempos.front() - _meters.front() - - will all be the const versions of these methods. - */ - - /* Use the reference time of the BBT_Argument to determine - * where to start iterating. - */ - - Points::const_iterator pi = _points.begin(); - Tempos::const_iterator ti = _tempos.begin(); - Meters::const_iterator mi = _meters.begin(); - - while (pi != _points.end() && pi->sclock() < bbt.reference().superclocks()) ++pi; - while (ti != _tempos.end() && ti->sclock() < bbt.reference().superclocks()) ++ti; - while (mi != _meters.end() && mi->sclock() < bbt.reference().superclocks()) ++mi; - - if (pi == _points.end()) { --pi; } - if (ti == _tempos.end()) { --ti; } - if (mi == _meters.end()) { --mi; } - - return _get_tempo_and_meter > (t, m, &Point::bbt, bbt, pi, _points.end(), &*ti, &*mi, can_match, ret_iterator_after_not_at); - } Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, superclock_t sc, bool can_match, bool ret_iterator_after_not_at) const { return _get_tempo_and_meter > (t, m, &Point::sclock, sc, _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, Beats const & b, bool can_match, bool ret_iterator_after_not_at) const { return _get_tempo_and_meter > (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, timepos_t const & pos, bool can_match, bool ret_iterator_after_not_at) const { + if (pos.time_domain() == BeatTime) { + return get_tempo_and_meter (t, m, pos.beats(), can_match, ret_iterator_after_not_at); + } else { + return get_tempo_and_meter (t, m, pos.superclocks(), can_match, ret_iterator_after_not_at); + } + } /* This is private, and should not be callable from outside the map because of potential confusion between samplepos_t and