From d25a615e20e6a65926de29cb57040f6dfa335354 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 23 Feb 2023 23:01:09 -0700 Subject: [PATCH] API development for time domain flipping (GUI edition) --- gtk2_ardour/editor.h | 4 ++++ gtk2_ardour/editor_drag.cc | 7 ++++--- gtk2_ardour/editor_tempodisplay.cc | 28 ++++++++++++++++++++++++++++ gtk2_ardour/public_editor.h | 7 +++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 127c1b3595..363a050973 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1742,6 +1742,9 @@ private: void mid_tempo_per_region_update (RegionView*); bool ignore_map_change; + Temporal::TempoMap::WritableSharedPtr begin_tempo_mapping (); + void abort_tempo_mapping (); + enum MidTempoChanges { TempoChanged = 0x1, MeterChanged = 0x2, @@ -1752,6 +1755,7 @@ private: protected: void _commit_tempo_map_edit (Temporal::TempoMap::WritableSharedPtr&, bool with_update = false); + void _commit_tempo_mapping (Temporal::TempoMap::WritableSharedPtr&); private: friend class DragManager; diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index c3da90b8e7..5a10ee7d18 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3633,7 +3633,8 @@ TempoTwistDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); - map = _editor->begin_tempo_map_edit (); + map = _editor->begin_tempo_mapping (); + /* Get the tempo point that starts this section */ _tempo = const_cast (&map->tempo_at (raw_grab_time())); @@ -3714,13 +3715,13 @@ TempoTwistDrag::finished (GdkEvent* event, bool movement_occurred) _editor->session()->add_command (new Temporal::TempoCommand (_("twist tempo"), _before_state, &after)); _editor->commit_reversible_command (); - _editor->commit_tempo_map_edit (map); + _editor->commit_tempo_mapping (map); } void TempoTwistDrag::aborted (bool moved) { - _editor->abort_tempo_map_edit (); + _editor->abort_tempo_mapping (); } TempoEndDrag::TempoEndDrag (Editor* e, ArdourCanvas::Item* i) diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index dce2dd8cb8..953634f824 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -754,6 +754,34 @@ Editor::real_remove_meter_marker (Temporal::MeterPoint const * section) return FALSE; } + +Temporal::TempoMap::WritableSharedPtr +Editor::begin_tempo_mapping () +{ + TempoMap::WritableSharedPtr wmap = TempoMap::fetch_writable (); + reassociate_metric_markers (wmap); + (void) Temporal::DomainSwapInformation::start (Temporal::BeatTime); + _session->globally_change_time_domain (Temporal::BeatTime, Temporal::AudioTime); + return wmap; +} + +void +Editor::abort_tempo_mapping () +{ + delete domain_swap; /* undo the domain swap */ + domain_swap = 0; + + TempoMap::SharedPtr tmap (TempoMap::fetch()); + reassociate_metric_markers (tmap); +} + +void +Editor::_commit_tempo_mapping (TempoMap::WritableSharedPtr& new_map) +{ + TempoMap::update (new_map); + abort_tempo_mapping (); +} + Temporal::TempoMap::WritableSharedPtr Editor::begin_tempo_map_edit () { diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index a833e3566d..da6ac30c5e 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -520,6 +520,12 @@ public: _commit_tempo_map_edit (map, with_update); } + virtual Temporal::TempoMap::WritableSharedPtr begin_tempo_mapping () = 0; + virtual void abort_tempo_mapping () = 0; + void commit_tempo_mapping (Temporal::TempoMap::WritableSharedPtr& map) { + _commit_tempo_mapping (map); + } + virtual void access_action (const std::string&, const std::string&) = 0; virtual void set_toggleaction (const std::string&, const std::string&, bool) = 0; @@ -584,6 +590,7 @@ protected: virtual void suspend_route_redisplay () = 0; virtual void resume_route_redisplay () = 0; virtual void _commit_tempo_map_edit (Temporal::TempoMap::WritableSharedPtr&, bool with_update) = 0; + virtual void _commit_tempo_mapping (Temporal::TempoMap::WritableSharedPtr&) = 0; std::atomic _suspend_route_redisplay_counter; };