Tempo ramps - use correct meter when snapping to the future.
authornick_m <mainsbridge@gmail.com>
Mon, 28 Mar 2016 16:14:23 +0000 (03:14 +1100)
committernick_m <mainsbridge@gmail.com>
Fri, 27 May 2016 13:38:12 +0000 (23:38 +1000)
gtk2_ardour/editor.cc
libs/ardour/ardour/tempo.h
libs/ardour/tempo.cc

index 856e527a9ac28acb6bc97d7c5c9f5d1489b3f87a..155024f7202464b19fd3aeab8ad87ac4526a1df4 100644 (file)
@@ -2158,7 +2158,10 @@ Editor::snap_musical() const
        case SnapToBeatDiv3:
        case SnapToBeatDiv2:
                return true;
+       default:
+               break;
        }
+
        return false;
 }
 
index 676980714b5f135388ebd584e6a76f62f9837aa2..2a28a65f5b4332a3a9d9e38c6a3dea4f61e1085c 100644 (file)
@@ -373,6 +373,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
 
        const TempoSection& tempo_section_at (framepos_t frame) const;
        const MeterSection& meter_section_at (framepos_t frame) const;
+       const MeterSection& meter_section_at (const double& beat) const;
 
        void add_tempo (const Tempo&, const double& pulse, TempoSection::Type type);
        void add_tempo (const Tempo&, const framepos_t& frame, TempoSection::Type type);
index 0d933cbed070fce4c30a1a1683e0ade003b88f3c..72a1f2fea692b4c1fee41e722ef4fb01eb767188 100644 (file)
@@ -2483,7 +2483,7 @@ void
 TempoMap::round_bbt (BBT_Time& when, const int32_t& sub_num)
 {
        if (sub_num == -1) {
-               const double bpb = meter_at (bbt_to_beats_locked (_metrics, when)).note_divisor();
+               const double bpb = meter_section_at (bbt_to_beats_locked (_metrics, when)).divisions_per_bar();
                if ((double) when.beats > bpb / 2.0) {
                        ++when.bars;
                }
@@ -2491,8 +2491,13 @@ TempoMap::round_bbt (BBT_Time& when, const int32_t& sub_num)
                when.ticks = 0;
                return;
        } else if (sub_num == 0) {
+               const double bpb = meter_section_at (bbt_to_beats_locked (_metrics, when)).divisions_per_bar();
                if (when.ticks > BBT_Time::ticks_per_beat / 2) {
                        ++when.beats;
+                       while ((double) when.beats > bpb) {
+                               ++when.bars;
+                               when.beats -= (uint32_t) floor (bpb);
+                       }
                        when.ticks = 0;
                } else {
                        when.ticks = 0;
@@ -2751,6 +2756,25 @@ TempoMap::meter_at (framepos_t frame) const
        return m.meter();
 }
 
+const MeterSection&
+TempoMap::meter_section_at (const double& beat) const
+{
+       MeterSection* prev_ms = 0;
+       Glib::Threads::RWLock::ReaderLock lm (lock);
+
+       for (Metrics::const_iterator i = _metrics.begin(); i != _metrics.end(); ++i) {
+               MeterSection* m;
+               if ((m = dynamic_cast<MeterSection*> (*i)) != 0) {
+                       if (prev_ms && m->beat() > beat) {
+                               break;
+                       }
+                       prev_ms = m;
+               }
+
+       }
+       return *prev_ms;
+}
+
 XMLNode&
 TempoMap::get_state ()
 {