From 2c3f54250df53d474e67b507d282e0783ce8eef4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 9 Jan 2008 21:07:18 +0000 Subject: [PATCH] clever fixes to make keyboard-driven trimming work nicely git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2856 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour.bindings.in | 4 +-- gtk2_ardour/editor.h | 12 ++++++++ gtk2_ardour/editor_ops.cc | 51 +++++++++++++++++++-------------- gtk2_ardour/editor_selection.cc | 25 ++++++++++++++++ 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/gtk2_ardour/ardour.bindings.in b/gtk2_ardour/ardour.bindings.in index a171e90349..f8c1b2d278 100644 --- a/gtk2_ardour/ardour.bindings.in +++ b/gtk2_ardour/ardour.bindings.in @@ -317,8 +317,8 @@ (gtk_accel_path "/Editor/set-fade-out-length" "backslash") (gtk_accel_path "/Editor/trim-from-start" "<%TERTIARY%>braceleft") (gtk_accel_path "/Editor/trim-to-end" "<%TERTIARY%>braceright") -;(gtk_accel_path "/Editor/trim-front" "a") -;(gtk_accel_path "/Editor/trim-back" "s") +(gtk_accel_path "/Editor/trim-front" "j") +(gtk_accel_path "/Editor/trim-back" "k") (gtk_accel_path "/Editor/goto-mark-1" "KP_1") (gtk_accel_path "/Editor/goto-mark-2" "KP_2") (gtk_accel_path "/Editor/goto-mark-3" "KP_3") diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 599b7d5815..25883dbcf8 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1966,6 +1966,18 @@ class Editor : public PublicEditor TimeAxisView* entered_track; RegionView* entered_regionview; + + class ExclusiveRegionSelection { + public: + ExclusiveRegionSelection (Editor&, RegionView*); + ~ExclusiveRegionSelection (); + + private: + Editor& editor; + RegionView* regionview; + bool remove; + }; + void ensure_entered_region_selected (bool op_acts_on_objects = false); void ensure_entered_track_selected (bool op_acts_on_objects = false); bool clear_entered_track; diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 59e3e39cdd..45bf4c60d1 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -3171,7 +3171,7 @@ Editor::trim_region_to_punch () void Editor::trim_region_to_location (const Location& loc, const char* str) { - ensure_entered_region_selected (); + ExclusiveRegionSelection ers (*this, entered_regionview); RegionSelection& rs (get_regions_for_action ()); @@ -3222,6 +3222,8 @@ Editor::trim_region_to_location (const Location& loc, const char* str) void Editor::trim_region_to_edit_point () { + ExclusiveRegionSelection ers (*this, entered_regionview); + RegionSelection& rs (get_regions_for_action ()); nframes64_t where = get_preferred_edit_position(); @@ -3264,6 +3266,8 @@ Editor::trim_region_to_edit_point () void Editor::trim_region_from_edit_point () { + ExclusiveRegionSelection ers (*this, entered_regionview); + RegionSelection& rs (get_regions_for_action ()); nframes64_t where = get_preferred_edit_position(); @@ -4609,27 +4613,29 @@ Editor::ensure_entered_track_selected (bool op_really_wants_one_track_if_none_ar void Editor::ensure_entered_region_selected (bool op_really_wants_one_region_if_none_are_selected) { - if (entered_regionview && mouse_mode == MouseObject) { + if (!entered_regionview || mouse_mode != MouseObject) { + return; + } - /* heuristic: - - - if there is no existing selection, don't change it. the operation will thus apply to "all" - - - if there is an existing selection, but the entered regionview isn't in it, add it. this - avoids key-mouse ops on unselected regions from interfering with an existing selection, - but also means that the operation will apply to the pointed-at region. - */ - - if (!selection->regions.empty()) { - if (find (selection->regions.begin(), selection->regions.end(), entered_regionview) != selection->regions.end()) { - selection->add (entered_regionview); - } - } else { - /* there is no selection, but this operation requires/prefers selected objects */ - - if (op_really_wants_one_region_if_none_are_selected) { - selection->set (entered_regionview, false); - } + + /* heuristic: + + - if there is no existing selection, don't change it. the operation will thus apply to "all" + + - if there is an existing selection, but the entered regionview isn't in it, add it. this + avoids key-mouse ops on unselected regions from interfering with an existing selection, + but also means that the operation will apply to the pointed-at region. + */ + + if (!selection->regions.empty()) { + if (!selection->selected (entered_regionview)) { + selection->add (entered_regionview); + } + } else { + /* there is no selection, but this operation requires/prefers selected objects */ + + if (op_really_wants_one_region_if_none_are_selected) { + selection->set (entered_regionview, false); } } } @@ -4649,6 +4655,8 @@ Editor::trim_region_back () void Editor::trim_region (bool front) { + ExclusiveRegionSelection ers (*this, entered_regionview); + nframes64_t where = get_preferred_edit_position(); RegionSelection& rs = get_regions_for_action (); @@ -4671,6 +4679,7 @@ Editor::trim_region (bool front) session->add_command(new MementoCommand(*pl.get(), &before, &after)); } } + commit_reversible_command (); } diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index f1248fb13a..8e1d35ca69 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -1325,3 +1325,28 @@ Editor::deselect_all () { selection->clear (); } + +Editor::ExclusiveRegionSelection::ExclusiveRegionSelection (Editor& ed, RegionView* rv) + : editor (ed), + regionview (rv) +{ + + if (!rv || ed.current_mouse_mode() != Editing::MouseObject) { + return; + } + + if (ed.get_selection().regions.empty() && !ed.get_selection().selected (rv)) { + ed.get_selection().set (rv, false); + remove = true; + } else { + remove = false; + } +} + +Editor::ExclusiveRegionSelection::~ExclusiveRegionSelection () +{ + if (remove) { + editor.get_selection().remove (regionview); + } +} +