From 0aea2a2ef8e2bd1109ce1aca26155f535cf62ac3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 17 Mar 2023 18:30:39 -0600 Subject: [PATCH] tempo twisting: GUI improvements, including undo/redo logic --- gtk2_ardour/editor_drag.cc | 43 ++++++------------------------------- gtk2_ardour/editor_drag.h | 3 ++- gtk2_ardour/editor_mouse.cc | 14 ++++++------ 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 9894844dcf..d70f2f068a 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3712,7 +3712,8 @@ MappingStretchDrag::aborted (bool moved) MappingTwistDrag::MappingTwistDrag (Editor* e, ArdourCanvas::Item* i, Temporal::TempoMap::WritableSharedPtr& wmap, TempoPoint& prv, TempoPoint& fcus, - TempoPoint& nxt) + TempoPoint& nxt, + XMLNode& before) : Drag (e, i, Temporal::BeatTime) , prev (prv) , focus (fcus) @@ -3720,7 +3721,7 @@ MappingTwistDrag::MappingTwistDrag (Editor* e, ArdourCanvas::Item* i, Temporal:: , map (wmap) , direction (0.) , delta (0.) - , _before_state (0) + , _before_state (&before) , _drag_valid (true) { DEBUG_TRACE (DEBUG::Drags, "New MappingTwistDrag\n"); @@ -3736,9 +3737,6 @@ MappingTwistDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) void MappingTwistDrag::setup_pointer_offset () { - /* get current state */ - _before_state = &map->get_state(); - Beats grab_qn = max (Beats(), raw_grab_time().beats()); uint32_t divisions = _editor->get_grid_beat_divisions (_editor->grid_type()); @@ -3754,20 +3752,6 @@ MappingTwistDrag::setup_pointer_offset () void MappingTwistDrag::motion (GdkEvent* event, bool first_move) { - if (first_move) { - _editor->begin_reversible_command (_("map tempo w/twist")); - } - - samplepos_t mouse_pos; - - if (_editor->grid_musical()) { - mouse_pos = adjusted_current_time (event, false).samples(); - } else { - mouse_pos = adjusted_current_time (event).samples(); - } - - double pixels_moved = _drags->current_pointer_x() - last_pointer_x(); - if (_drags->current_pointer_x() < last_pointer_x()) { if (direction < 0.) { direction = 1.; @@ -3795,7 +3779,7 @@ MappingTwistDrag::motion (GdkEvent* event, bool first_move) map->twist_tempi (prev, focus, next, initial_npm + delta); - // _editor->mapping_cursor->set_position (Duple (_editor->sample_to_pixel_unrounded (mouse_pos), _editor->mapping_cursor->position().y)); + _editor->mapping_cursor->set_position (Duple (_editor->sample_to_pixel_unrounded (superclock_to_samples (focus.sclock(), TEMPORAL_SAMPLE_RATE)), _editor->mapping_cursor->position().y)); _editor->mid_tempo_change (Editor::MappingChanged); } @@ -3807,26 +3791,21 @@ MappingTwistDrag::finished (GdkEvent* event, bool movement_occurred) /* click, no drag */ _editor->abort_tempo_mapping (); + _editor->abort_reversible_command (); _editor->session()->request_locate (grab_sample(), false, _was_rolling ? MustRoll : RollIfAppropriate); return; } if (!_drag_valid) { _editor->abort_tempo_mapping (); + _editor->abort_reversible_command (); return; } XMLNode &after = map->get_state(); - _editor->session()->add_command (new Temporal::TempoCommand (_("move BBT point"), _before_state, &after)); + _editor->session()->add_command (new Temporal::TempoCommand (_("twist tempo"), _before_state, &after)); _editor->commit_reversible_command (); - - /* 2nd argument means "update tempo map display after the new map is - * installed. We need to do this because the code above has not - * actually changed anything about how tempo is displayed, it simply - * modified the map. - */ - _editor->commit_tempo_mapping (map); } @@ -3893,14 +3872,6 @@ TempoTwistDrag::motion (GdkEvent* event, bool first_move) } } - samplepos_t mouse_pos; - - if (_editor->grid_musical()) { - mouse_pos = adjusted_current_time (event, false).samples(); - } else { - mouse_pos = adjusted_current_time (event).samples(); - } - /* adjust this and the next tempi to match pointer sample */ // map->twist_tempi (_tempo, adjusted_time (grab_time(), 0, false).samples(), mouse_pos); diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index b3cb0950e4..ef546da9e8 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -977,7 +977,8 @@ public: MappingTwistDrag (Editor *, ArdourCanvas::Item *, Temporal::TempoMap::WritableSharedPtr&, Temporal::TempoPoint& prev, Temporal::TempoPoint& focus, - Temporal::TempoPoint& next); + Temporal::TempoPoint& next, + XMLNode&); void start_grab (GdkEvent *, Gdk::Cursor* c = 0); void motion (GdkEvent *, bool); diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 63a639c3e4..72f8173616 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2993,6 +2993,11 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event) TempoPoint* before; TempoPoint* focus; + /* Reversible command starts here, must be ended/aborted in drag */ + + begin_reversible_command (_("map tempo/twist")); + XMLNode* before_state = &map->get_state(); + if (tempo.bbt() < bbt) { /* Add a new tempo marker at the nearest beat point @@ -3005,7 +3010,6 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event) Tempo copied_no_ramp (map->tempo_at (bbt)); TempoPoint& added = const_cast (map->set_tempo (copied_no_ramp, bbt)); focus = &added; - std::cerr << "Focus will be " << *focus << std::endl; reset_tempo_marks (); } else { @@ -3019,12 +3023,6 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event) focus = &tempo; } - std::cerr << "Prev: " << *before << std::endl; - std::cerr << "Focus: " << *focus << std::endl; - std::cerr << "Next: " << *after << std::endl; + _drags->set (new MappingTwistDrag (this, item, map, *before, *focus, *after, *before_state), event); - std::cerr << "focus says next at " << focus->superclock_at (after->beats()) << " vs. " << after->sclock() << std::endl; - - _drags->set (new MappingTwistDrag (this, item, map, *before, *focus, *after), event); - std::cerr << ":Twist\n"; }