diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 856e527a9a..155024f720 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2158,7 +2158,10 @@ Editor::snap_musical() const case SnapToBeatDiv3: case SnapToBeatDiv2: return true; + default: + break; } + return false; } diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index 676980714b..2a28a65f5b 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -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); diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 0d933cbed0..72a1f2fea6 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -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 (*i)) != 0) { + if (prev_ms && m->beat() > beat) { + break; + } + prev_ms = m; + } + + } + return *prev_ms; +} + XMLNode& TempoMap::get_state () {