From e682e1fde4e86b8691bc523b5669314597f00e1e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 8 Aug 2025 14:20:04 -0600 Subject: [PATCH] refinements to infrastructure for an EditingContext's locally scoped tempo map --- gtk2_ardour/editing_context.cc | 14 ++++++++++---- gtk2_ardour/editing_context.h | 23 +++++++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/gtk2_ardour/editing_context.cc b/gtk2_ardour/editing_context.cc index 3b23559397..925ec6d29c 100644 --- a/gtk2_ardour/editing_context.cc +++ b/gtk2_ardour/editing_context.cc @@ -1629,11 +1629,17 @@ EditingContext::snap_relative_time_to_relative_time (timepos_t const & origin, t return origin.distance (snapped); } -std::shared_ptr -EditingContext::start_local_tempo_map (std::shared_ptr) +void +EditingContext::start_local_tempo_map (std::shared_ptr map) { - /* default is a no-op */ - return Temporal::TempoMap::use (); + _local_tempo_map = map; +} + +void +EditingContext::end_local_tempo_map () +{ + _local_tempo_map.reset (); + Temporal::TempoMap::fetch (); } bool diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index 08caf25ff1..a59bfeb677 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -87,18 +87,17 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider, Temporal::TimeDomain time_domain () const; - struct TempoMapScope { TempoMapScope (EditingContext& context, std::shared_ptr map) : ec (context) { - old_map = ec.start_local_tempo_map (map); + ec.start_local_tempo_map (map); + ec.ensure_local_tempo_scope (); } ~TempoMapScope () { - ec.end_local_tempo_map (old_map); + ec.end_local_tempo_map (); } EditingContext& ec; - std::shared_ptr old_map; }; DragManager* drags () const { @@ -666,8 +665,9 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider, QuantizeDialog* quantize_dialog; friend struct TempoMapScope; - virtual std::shared_ptr start_local_tempo_map (std::shared_ptr); - virtual void end_local_tempo_map (std::shared_ptr) { /* no-op by default */ } + void set_local_tempo_map (std::shared_ptr); + void start_local_tempo_map (std::shared_ptr); + void end_local_tempo_map (); virtual bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType) = 0; virtual bool button_press_handler_1 (ArdourCanvas::Item*, GdkEvent*, ItemType) = 0; @@ -832,4 +832,15 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider, bool temporary_zoom_focus_change; bool _dragging_playhead; + + std::shared_ptr _local_tempo_map; + void ensure_local_tempo_scope () { + if (_local_tempo_map) { + Temporal::TempoMap::set (_local_tempo_map); + _local_tempo_map.reset (); + } + } }; + +#define EC_LOCAL_TEMPO_SCOPE ensure_local_tempo_scope () +#define EC_GIVEN_LOCAL_TEMPO_SCOPE(ec) ec.ensure_local_tempo_scope ()