Make editing of meter work at the current position
authorColin Fletcher <colin.m.fletcher@googlemail.com>
Sun, 8 Mar 2015 15:48:27 +0000 (15:48 +0000)
committerColin Fletcher <colin.m.fletcher@googlemail.com>
Mon, 9 Mar 2015 19:17:53 +0000 (19:17 +0000)
Add a function TempoMap::meter_section_at(), similar to
TempoMap::tempo_section_at() but returning the meter section at the given
position, and use this to make editing meter changes from the main clock
work on the meter that's in effect at the current position.

gtk2_ardour/main_clock.cc
libs/ardour/ardour/tempo.h
libs/ardour/tempo.cc

index f90599de1374e6675a636e0188305e2ccefc4850..26d780ea8a1655ebaac2cfd53490ef5e815ac0b3 100644 (file)
@@ -99,8 +99,7 @@ MainClock::edit_current_tempo ()
 void
 MainClock::edit_current_meter ()
 {
-       ARDOUR::Meter m = PublicEditor::instance().session()->tempo_map().meter_at (absolute_time());
-       ARDOUR::MeterSection ms (absolute_time(), m.divisions_per_bar(), m.note_divisor());
+       ARDOUR::MeterSection ms = PublicEditor::instance().session()->tempo_map().meter_section_at (absolute_time());
        PublicEditor::instance().edit_meter_section (&ms);
 }
 
index f2d314651dee52686b1e49e1e9e8852a5aa0c20b..29f1f256438069e1c75ed6b2ea8221f0833cbf9b 100644 (file)
@@ -287,6 +287,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
        const Meter& meter_at (framepos_t) const;
 
        const TempoSection& tempo_section_at (framepos_t) const;
+       const MeterSection& meter_section_at (framepos_t) const;
 
        void add_tempo (const Tempo&, Timecode::BBT_Time where);
        void add_meter (const Meter&, Timecode::BBT_Time where);
index ff6553e82048feb42388b7ec0c6016503322c233..8c4011cefd89471f2dd68f73d16ea5b8140d3762 100644 (file)
@@ -1583,6 +1583,33 @@ TempoMap::tempo_at (framepos_t frame) const
        return m.tempo();
 }
 
+const MeterSection&
+TempoMap::meter_section_at (framepos_t frame) const
+{
+       Glib::Threads::RWLock::ReaderLock lm (lock);
+       Metrics::const_iterator i;
+       MeterSection* prev = 0;
+
+       for (i = metrics.begin(); i != metrics.end(); ++i) {
+               MeterSection* t;
+
+               if ((t = dynamic_cast<MeterSection*> (*i)) != 0) {
+
+                       if ((*i)->frame() > frame) {
+                               break;
+                       }
+
+                       prev = t;
+               }
+       }
+
+       if (prev == 0) {
+               fatal << endmsg;
+               abort(); /*NOTREACHED*/
+       }
+
+       return *prev;
+}
 
 const Meter&
 TempoMap::meter_at (framepos_t frame) const