+TempoSection*
+TempoMap::previous_tempo_section (TempoSection* ts) const
+{
+ Glib::Threads::RWLock::ReaderLock lm (lock);
+
+ return previous_tempo_section_locked (_metrics, ts);
+
+}
+
+TempoSection*
+TempoMap::previous_tempo_section_locked (const Metrics& metrics, TempoSection* ts) const
+{
+ if (!ts) {
+ return 0;
+ }
+
+ TempoSection* prev = 0;
+
+ for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
+
+ if ((*i)->is_tempo()) {
+ TempoSection* t = static_cast<TempoSection*> (*i);
+
+ if (!t->active()) {
+ continue;
+ }
+
+ if (prev && t == ts) {
+
+ return prev;
+ }
+
+ prev = t;
+ }
+ }
+
+ if (prev == 0) {
+ fatal << endmsg;
+ abort(); /*NOTREACHED*/
+ }
+
+ return 0;
+}
+
+TempoSection*
+TempoMap::next_tempo_section (TempoSection* ts) const
+{
+ Glib::Threads::RWLock::ReaderLock lm (lock);
+
+ return next_tempo_section_locked (_metrics, ts);
+}
+
+TempoSection*
+TempoMap::next_tempo_section_locked (const Metrics& metrics, TempoSection* ts) const
+{
+ if (!ts) {
+ return 0;
+ }
+
+ TempoSection* prev = 0;
+
+ for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
+
+ if ((*i)->is_tempo()) {
+ TempoSection* t = static_cast<TempoSection*> (*i);
+
+ if (!t->active()) {
+ continue;
+ }
+
+ if (prev && prev == ts) {
+
+ return t;
+ }
+
+ prev = t;
+ }
+ }
+
+ if (prev == 0) {
+ fatal << endmsg;
+ abort(); /*NOTREACHED*/
+ }
+
+ return 0;
+}