From f7a2df1c9a8c540f7e5778561c8527c525874b84 Mon Sep 17 00:00:00 2001 From: Colin Fletcher Date: Sun, 8 Mar 2015 15:48:27 +0000 Subject: [PATCH] Make editing of meter work at the current position 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 | 3 +-- libs/ardour/ardour/tempo.h | 1 + libs/ardour/tempo.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/main_clock.cc b/gtk2_ardour/main_clock.cc index f90599de13..26d780ea8a 100644 --- a/gtk2_ardour/main_clock.cc +++ b/gtk2_ardour/main_clock.cc @@ -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); } diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index f2d314651d..29f1f25643 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -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); diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index ff6553e820..8c4011cefd 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -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 (*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