tempomap: provide improved reftime() method for TempoMetric

This now looks backwards in time for a BBT_Marker or the start of the
tempo map, whichever comes first.
This commit is contained in:
Paul Davis 2023-02-13 16:49:58 -07:00
parent 6cde958480
commit 92bd8461ca
2 changed files with 34 additions and 1 deletions

View file

@ -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<const Point*> (&tm.meter())));
} else {
pi = _points.s_iterator_to (*(static_cast<const Point*> (&tm.tempo())));
}
/* Walk backwards through points to find a BBT markers, or the start */
while (pi != _points.begin()) {
if (dynamic_cast<const MusicTimePoint*> (&*pi)) {
break;
}
--pi;
}
return timepos_t (pi->sclock());
}
Temporal::BBT_Argument
TempoMetric::bbt_at (timepos_t const & pos) const
{

View file

@ -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: