From d06e7104026140f5921f03d640afec80f84f1e7d Mon Sep 17 00:00:00 2001 From: nick_m Date: Mon, 27 Feb 2017 02:21:05 +1100 Subject: [PATCH] add TempoMap::next_tempo_section() --- libs/ardour/ardour/tempo.h | 2 ++ libs/ardour/tempo.cc | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index 4f44ac5455..1426801f24 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -367,6 +367,8 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible const MeterSection& meter_section_at_frame (framepos_t frame) const; const MeterSection& meter_section_at_beat (double beat) const; + TempoSection* next_tempo_section (TempoSection*) const; + /** add a tempo section locked to pls. ignored values will be set in recompute_tempi() * @param pulse pulse position of new section. ignored if pls == AudioTime * @param frame frame position of new section. ignored if pls == MusicTime diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index dbc0457f8a..c3ae1533dc 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -1816,9 +1816,9 @@ TempoMap::minute_at_tempo_locked (const Metrics& metrics, const Tempo& tempo) co if (prev_t) { const double prev_t_bpm = prev_t->note_types_per_minute(); const double prev_t_end_bpm = prev_t->end_note_types_per_minute(); - if (prev_t_bpm > tempo_bpm && prev_t_end_bpm < tempo_bpm - || prev_t_bpm < tempo_bpm && prev_t_end_bpm > tempo_bpm - || prev_t_end_bpm == tempo_bpm) { + if ((prev_t_bpm > tempo_bpm && prev_t_end_bpm < tempo_bpm) + || (prev_t_bpm < tempo_bpm && prev_t_end_bpm > tempo_bpm) + || (prev_t_end_bpm == tempo_bpm)) { return prev_t->minute_at_ntpm (tempo_bpm, t->pulse()); } @@ -4274,6 +4274,38 @@ TempoMap::tempo_section_at_beat_locked (const Metrics& metrics, const double& be return *prev_t; } +TempoSection* +TempoMap::next_tempo_section (TempoSection* ts) const +{ + Glib::Threads::RWLock::ReaderLock lm (lock); + + TempoSection* prev = 0; + + for (Metrics::const_iterator i = _metrics.begin(); i != _metrics.end(); ++i) { + + if ((*i)->is_tempo()) { + TempoSection* t = static_cast (*i); + + if (!t->active()) { + continue; + } + + if (prev && prev == ts) { + + return t; + } + + prev = t; + } + } + + if (prev == 0) { + fatal << endmsg; + abort(); /*NOTREACHED*/ + } + + return 0; +} /* don't use this to calculate length (the tempo is only correct for this frame). do that stuff based on the beat_at_frame and frame_at_beat api */