diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index a447646b9d..0d0a3ed887 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -636,6 +636,36 @@ MeterPoint::get_state () const return base; } +timepos_t +TempoMetric::reftime() const +{ + TempoMap::SharedPtr tmap (TempoMap::use ()); + return tmap->reftime (*this); +} + +timepos_t +TempoMap::reftime (TempoMetric const &tm) const +{ + Points::const_iterator pi; + + if (tm.meter().sclock() < tm.tempo().sclock()) { + pi = _points.s_iterator_to (*(static_cast (&tm.meter()))); + } else { + pi = _points.s_iterator_to (*(static_cast (&tm.tempo()))); + } + + /* Walk backwards through points to find a BBT markers, or the start */ + + while (pi != _points.begin()) { + if (dynamic_cast (&*pi)) { + break; + } + --pi; + } + + return timepos_t (pi->sclock()); +} + Temporal::BBT_Argument TempoMetric::bbt_at (timepos_t const & pos) const { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index db132e9089..cf73c8a9ba 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -470,7 +470,7 @@ class LIBTEMPORAL_API TempoMetric TempoMetric (TempoPoint const & t, MeterPoint const & m) : _tempo (&t), _meter (&m) {} virtual ~TempoMetric () {} - timepos_t reftime() const { return timepos_t (std::min (_tempo->sclock(), _meter->sclock())); } + timepos_t reftime() const; TempoPoint const & tempo() const { return *_tempo; } MeterPoint const & meter() const { return *_meter; } @@ -711,6 +711,9 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API static WritableSharedPtr fetch_writable() { _tempo_map_p = write_copy(); return _tempo_map_p; } + /* not part of public API */ + timepos_t reftime(TempoMetric const &) const; + /* and now on with the rest of the show ... */ public: