diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 34f950061a..31f361850b 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -1785,6 +1785,32 @@ TempoMap::set_bartime (BBT_Time const & bbt, timepos_t const & pos, std::string add_or_replace_bartime (tp); } +superclock_t +TempoMap::previous_bbt_reference_at_superclock (superclock_t sc) const +{ + if (_bartimes.empty()) { + return 0; + } + + if (_bartimes.size() == 1) { + if (_bartimes.front().sclock() > sc) { + return 0; + } + return _bartimes.front().sclock(); + } + + MusicTimes::const_iterator m; + + for (m = _bartimes.begin(); m != _bartimes.end() && (*m).sclock() < sc; ++m); + + if (m == _bartimes.end()) { + return _bartimes.back().sclock(); + } + + --m; + return (*m).sclock(); +} + void TempoMap::replace_bartime (MusicTimePoint & mtp, bool with_reset) { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 85ff033693..703f91d1b7 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -825,6 +825,8 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API void remove_bartime (MusicTimePoint const & tp, bool with_reset = true); LIBTEMPORAL_API void replace_bartime (MusicTimePoint & tp, bool with_reset = true); + LIBTEMPORAL_API superclock_t previous_bbt_reference_at_superclock (superclock_t) const; +U LIBTEMPORAL_API TempoPoint& set_tempo (Tempo const &, BBT_Argument const &); LIBTEMPORAL_API TempoPoint& set_tempo (Tempo const &, timepos_t const &);