From bf87916fb1978348cf3f146bb2d4cef055279e23 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 28 Jun 2022 10:16:31 -0600 Subject: [PATCH] tempo display: further simplifications to handling map changes When a tempo map change originates from a drag, we know the required redraws have already been done. Use a new bool member, ignore_map_change, to tell the Editor to ignore the map change signal. For all other map changes, do the full reset. --- gtk2_ardour/editor.cc | 1 + gtk2_ardour/editor.h | 3 ++- gtk2_ardour/editor_drag.cc | 12 +++++------ gtk2_ardour/editor_tempodisplay.cc | 34 +++++++++++++----------------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 6b1ff8087d..5599f2fd5b 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -388,6 +388,7 @@ Editor::Editor () , lock_dialog (0) /* , last_event_time { 0, 0 } */ /* this initialization style requires C++11 */ , _dragging_playhead (false) + , ignore_map_change (false) , _follow_playhead (true) , _stationary_playhead (false) , _maximised (false) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index d1cb61517a..10cc564558 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1729,6 +1729,8 @@ private: Temporal::TempoMap::WritableSharedPtr begin_tempo_map_edit (); void abort_tempo_map_edit (); + void commit_tempo_map_edit (Temporal::TempoMap::WritableSharedPtr&); + bool ignore_map_change; enum MidTempoChanges { TempoChanged = 0x1, @@ -1875,7 +1877,6 @@ private: void update_tempo_curves (double min_tempo, double max_tempo, samplecnt_t sr); void tempo_map_changed (); - void tempo_map_model_update (); void redisplay_grid (bool immediate_redraw); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 6b472d75e2..b177846032 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3145,7 +3145,7 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred) _editor->set_grid_to (_old_grid_type); _editor->set_snap_mode (_old_snap_mode); - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); XMLNode &after = map->get_state(); _editor->session()->add_command (new Temporal::TempoCommand (_("move time signature"), before_state, &after)); @@ -3237,7 +3237,7 @@ TempoCurveDrag::finished (GdkEvent* event, bool movement_occurred) /* push the current state of our writable map copy */ - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); XMLNode &after = map->get_state(); _editor->session()->add_command (new Temporal::TempoCommand (_("change tempo"), _before_state, &after)); @@ -3346,7 +3346,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred) /* push the current state of our writable map copy */ - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); XMLNode &after = map->get_state(); _editor->session()->add_command (new Temporal::TempoCommand (_("move tempo"), _before_state, &after)); @@ -3518,7 +3518,7 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred) } } - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); XMLNode &after = map->get_state(); @@ -3628,7 +3628,7 @@ TempoTwistDrag::finished (GdkEvent* event, bool movement_occurred) _editor->session()->add_command (new Temporal::TempoCommand (_("twist tempo"), _before_state, &after)); _editor->commit_reversible_command (); - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); } void @@ -3734,7 +3734,7 @@ TempoEndDrag::finished (GdkEvent* event, bool movement_occurred) return; } - TempoMap::update (map); + _editor->commit_tempo_map_edit (map); XMLNode &after = map->get_state(); _editor->session()->add_command (new Temporal::TempoCommand (_("move tempo end"), _before_state, &after)); diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 500765313f..f9ec4fe9ff 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -36,6 +36,7 @@ #include "pbd/error.h" #include "pbd/memento_command.h" +#include "pbd/unwind.h" #include #include @@ -327,6 +328,10 @@ Editor::update_tempo_curves (double min_tempo, double max_tempo, samplecnt_t sr) void Editor::tempo_map_changed () { + if (ignore_map_change) { + return; + } + TempoMap::SharedPtr current_map = TempoMap::fetch (); /* If the tempo map was changed by something other than the Editor, we @@ -334,25 +339,9 @@ Editor::tempo_map_changed () * with the new map. */ - if (!tempo_marks.empty()) { - /* a little awkward using shared_ptr::get() but better than every - * point in the map holding a shared_ptr ref to the map that owns it. - */ - - if (&tempo_marks.front()->point().map() != current_map.get()) { - reassociate_metric_markers (current_map); - } - } - - tempo_map_model_update (); -} - -void -Editor::tempo_map_model_update () -{ - reset_metric_marks (); - update_tempo_based_rulers (); - maybe_draw_grid_lines (); + reset_metric_marks (); + update_tempo_based_rulers (); + maybe_draw_grid_lines (); } void @@ -730,6 +719,13 @@ Editor::abort_tempo_map_edit () reassociate_metric_markers (tmap); } +void +Editor::commit_tempo_map_edit (TempoMap::WritableSharedPtr& new_map) +{ + PBD::Unwinder uw (ignore_map_change, true); + TempoMap::update (new_map); +} + void Editor::mid_tempo_change (MidTempoChanges what_changed) {