From e6883e4c97f59b164f9e0e22cd276d72c699d984 Mon Sep 17 00:00:00 2001 From: houston Date: Thu, 23 Nov 2017 11:28:30 +0100 Subject: [PATCH 1/2] change behaviour of equivalent regions selection with modifier key --- gtk2_ardour/editor.h | 1 + gtk2_ardour/editor_selection.cc | 73 ++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 07dc11aedb7..2287ee95219 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -763,6 +763,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList bool set_selected_control_point_from_click (bool press, Selection::Operation op = Selection::Set); void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false); void set_selected_track_as_side_effect (Selection::Operation op); + bool selection_contains_isolated_equivalent_region (); bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set); bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr); diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index 79cda34f155..c66adf1409a 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -577,6 +577,32 @@ Editor::get_regionview_count_from_region_list (boost::shared_ptr region) } +bool +Editor::selection_contains_isolated_equivalent_region () +{ + vector already_seen; + + for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) { + if (std::find(already_seen.begin(), already_seen.end(), (*r)) != already_seen.end()){ + continue; + } + + vector equivalent_regions; + get_equivalent_regions ((*r), equivalent_regions, ARDOUR::Properties::group_select.property_id); + + for (vector::iterator er = equivalent_regions.begin() ; er != equivalent_regions.end(); ++er){ + already_seen.push_back((*er)); + + if (!selection->selected((*er))) { + return true; + } + } + } + return false; +} + + + bool Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) { @@ -592,9 +618,12 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) } if (op == Selection::Toggle || op == Selection::Set) { - +// bool isolate_region = (selection->regions.empty() || selection_contains_isolated_equivalent_region()); + switch (op) { case Selection::Toggle: + + if (selection->selected (clicked_regionview)) { if (press) { @@ -606,10 +635,20 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) } else { if (button_release_can_deselect) { - - /* just remove this one region, but only on a permitted button release */ - - selection->remove (clicked_regionview); + + if (selection->regions.empty() || selection_contains_isolated_equivalent_region()) { + /* just remove this one region, but only on a permitted button release */ + selection->remove (clicked_regionview); + + } else { + /* remove all equivalents regions, but only on a permitted button release */ + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); + + for (vector::iterator r = all_equivalent_regions.begin(); r != all_equivalent_regions.end(); ++r ){ + selection->remove((*r)); + } + } + commit = true; /* no more deselect action on button release till a new press @@ -623,11 +662,15 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) } else { if (press) { - - if (selection->selected (clicked_routeview)) { - get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); - } else { + + if (selection->regions.empty() || selection_contains_isolated_equivalent_region()) { + all_equivalent_regions.push_back (clicked_regionview); + + } else { + + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); + } /* add all the equivalent regions, but only on button press */ @@ -876,7 +919,17 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) RegionView* arv; if ((arv = dynamic_cast(*x)) != 0) { - regions.push_back (arv); + if (selection_contains_isolated_equivalent_region()) { + regions.push_back (arv); + } else { + get_equivalent_regions(arv, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); + for (vector::iterator i=all_equivalent_regions.begin(); i != all_equivalent_regions.end(); ++i){ + if ( !(std::find(regions.begin(), regions.end(), (*i)) != regions.end()) ) { + regions.push_back (*i); + } + } + } + } } From 28e20294da8dab101c3c6213fe1d7df2b3a6c80c Mon Sep 17 00:00:00 2001 From: houston Date: Mon, 1 Feb 2021 00:03:19 +0100 Subject: [PATCH 2/2] little code clean --- gtk2_ardour/editor_selection.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index 5f1a0730e2b..1ddcb0947ba 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -639,13 +639,10 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) } if (op == Selection::Toggle || op == Selection::Set) { -// bool isolate_region = (selection->regions.empty() || selection_contains_isolated_equivalent_region()); - switch (op) { case Selection::Toggle: - - if (selection->selected (clicked_regionview)) { + if (press) { /* whatever was clicked was selected already; do nothing here but allow @@ -655,12 +652,13 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) button_release_can_deselect = true; } else { + if (button_release_can_deselect) { - + if (selection->regions.empty() || selection_contains_isolated_equivalent_region()) { /* just remove this one region, but only on a permitted button release */ selection->remove (clicked_regionview); - + } else { /* remove all equivalents regions, but only on a permitted button release */ get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); @@ -669,7 +667,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) selection->remove((*r)); } } - + commit = true; /* no more deselect action on button release till a new press @@ -683,15 +681,15 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) } else { if (press) { - + if (selection->regions.empty() || selection_contains_isolated_equivalent_region()) { - + all_equivalent_regions.push_back (clicked_regionview); - + } else { get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); - + } /* add all the equivalent regions, but only on button press */ @@ -707,14 +705,20 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) case Selection::Set: if (!selection->selected (clicked_regionview)) { + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); selection->set (all_equivalent_regions); commit = true; + } else { /* clicked on an already selected region */ + if (press) + goto out; + else { + if (selection->regions.size() > 1) { /* collapse region selection down to just this one region (and its equivalents) */ get_equivalent_regions(clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id);