From bccdc95f32bc1e1edb8415dbc07e77bc52c98d9e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 27 Mar 2021 09:11:10 -0600 Subject: [PATCH] libtemporal: fix logic for ::get_tempo_and_meter() if starting point is the timeline start --- libs/temporal/tempo.cc | 13 ++++++++++++- libs/temporal/temporal/tempo.h | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 855e233cd5..670c703b18 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -1642,7 +1642,7 @@ TempoMap::dump (std::ostream& ostr) const ostr << "------------\n\n\n"; } -template TempoMap::Points::const_iterator +template TempoMap::Points::const_iterator TempoMap::_get_tempo_and_meter (TempoPoint const *& tp, MeterPoint const *& mp, T (Point::*method)() const, T arg, bool can_match) const { Points::const_iterator p; @@ -1656,6 +1656,17 @@ TempoMap::_get_tempo_and_meter (TempoPoint const *& tp, MeterPoint const *& mp, tp = 0; mp = 0; + /* if the starting position is the beginning of the timeline (indicated + * by the default constructor value for T1, then we are always allowed + * to use the tempo & meter at that position. Without this, it would be + * necessary to special case "can_match" in the caller if the start is + * "zero". Instead we do that here, since common cases + * (e.g. ::get_grid()) will use can_match = false, but may pass in a + * zero start point. + */ + + can_match = (can_match || arg == T1()); + for (tp = &_tempos.front(), mp = &_meters.front(), p = _points.begin(); p != _points.end(); ++p) { TempoPoint const * tpp; diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index b55ce6227a..af68e96da8 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -854,11 +854,11 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible BBT_Time bbt_at (Beats const &) const; BBT_Time bbt_at (superclock_t sc) const; - template Points::const_iterator _get_tempo_and_meter (TempoPoint const *& tp, MeterPoint const *& mp, T (Point::*method)() const, T arg, bool can_match) const; + template Points::const_iterator _get_tempo_and_meter (TempoPoint const *& tp, MeterPoint const *& mp, T (Point::*method)() const, T arg, bool can_match) const; - Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, BBT_Time const & bbt, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::bbt, bbt, can_match); } - Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, superclock_t sc, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::sclock, sc, can_match); } - Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, Beats const & b, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::beats, b, can_match); } + Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, BBT_Time const & bbt, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::bbt, bbt, can_match); } + Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, superclock_t sc, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::sclock, sc, can_match); } + Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, Beats const & b, bool can_match = true) const { return _get_tempo_and_meter (t, m, &Point::beats, b, can_match); } /* parsing legacy tempo maps */