X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_selection.cc;h=b5a0be1c7869aa3e19c71a5a83c8ef282ac08bdb;hb=08e564dc2e65e3c80b362024ffe5ca89962dc00f;hp=4386b228776808919a8e83a975efea1d48aeb3df;hpb=c9d6d9ed85b2a2cc56e45d170dceb5a42c2d6a01;p=ardour.git diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index 4386b22877..b5a0be1c78 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -21,17 +21,20 @@ #include #include "pbd/stacktrace.h" +#include "pbd/unwind.h" +#include "ardour/control_protocol_manager.h" #include "ardour/midi_region.h" #include "ardour/playlist.h" #include "ardour/profile.h" #include "ardour/route_group.h" +#include "ardour/selection.h" #include "ardour/session.h" +#include "ardour/vca.h" -#include "control_protocol/control_protocol.h" - -#include "editor_drag.h" #include "editor.h" +#include "editor_drag.h" +#include "editor_routes.h" #include "actions.h" #include "audio_time_axis.h" #include "audio_region_view.h" @@ -43,7 +46,7 @@ #include "midi_region_view.h" #include "sfdb_ui.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -88,10 +91,6 @@ Editor::extend_selection_to_track (TimeAxisView& view) sorted.sort (cmp); - if (!selection->selected (&view)) { - to_be_added.push_back (&view); - } - /* figure out if we should go forward or backwards */ for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) { @@ -157,6 +156,10 @@ Editor::extend_selection_to_track (TimeAxisView& view) } } + if (!selection->selected (&view)) { + to_be_added.push_back (&view); + } + if (!to_be_added.empty()) { selection->add (to_be_added); return true; @@ -174,6 +177,7 @@ Editor::select_all_tracks () visible_views.push_back (*i); } } + PBD::Unwinder uw (_track_selection_change_without_scroll, true); selection->set (visible_views); } @@ -265,9 +269,7 @@ Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no break; case Selection::Add: - if (!selection->selected (&view)) { - selection->add (&view); - } + selection->add (&view); break; case Selection::Set: @@ -621,7 +623,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) if (press) { if (selection->selected (clicked_routeview)) { - get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::select.property_id); + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); } else { all_equivalent_regions.push_back (clicked_regionview); } @@ -639,7 +641,7 @@ 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::select.property_id); + get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); selection->set (all_equivalent_regions); commit = true; } else { @@ -649,7 +651,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) 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::select.property_id); + get_equivalent_regions(clicked_regionview, all_equivalent_regions, ARDOUR::Properties::group_select.property_id); selection->set(all_equivalent_regions); commit = true; } @@ -791,7 +793,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) RouteTimeAxisView* closest = 0; int distance = INT_MAX; - int key = rtv->route()->order_key (); + int key = rtv->route()->presentation_info().order (); for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) { @@ -806,7 +808,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) if (result.second) { /* newly added to already_in_selection */ - int d = artv->route()->order_key (); + int d = artv->route()->presentation_info().order (); d -= key; @@ -822,7 +824,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) /* now add all tracks between that one and this one */ - int okey = closest->route()->order_key (); + int okey = closest->route()->presentation_info().order (); if (okey > key) { swap (okey, key); @@ -832,7 +834,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) RouteTimeAxisView* artv = dynamic_cast(*x); if (artv && artv != rtv) { - int k = artv->route()->order_key (); + int k = artv->route()->presentation_info().order (); if (k >= okey && k <= key) { @@ -879,13 +881,42 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op) if (!regions.empty()) { selection->add (regions); commit = true; + } else if (selection->regions.empty() && !selection->selected (clicked_regionview)) { + /* ensure that at least the clicked regionview is selected. */ + selection->set (clicked_regionview); + commit = true; } + } out: return commit; } +void +Editor::set_selection (std::list s, Selection::Operation op) +{ + if (s.empty()) { + return; + } + begin_reversible_selection_op (X_("set selection")); + switch (op) { + case Selection::Toggle: + selection->toggle (s); + break; + case Selection::Set: + selection->set (s); + break; + case Selection::Extend: + selection->add (s); + break; + case Selection::Add: + selection->add (s); + break; + } + + commit_reversible_selection_op () ; +} void Editor::set_selected_regionview_from_region_list (boost::shared_ptr region, Selection::Operation op) @@ -950,75 +981,175 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* /*ev*/, StreamView* return true; } +struct SelectionOrderSorter { + bool operator() (TimeAxisView const * const a, TimeAxisView const * const b) const { + boost::shared_ptr sa = a->stripable (); + boost::shared_ptr sb = b->stripable (); + if (!sa && !sb) { + return a < b; + } + if (!sa) { + return false; + } + if (!sb) { + return true; + } + return sa->presentation_info().selection_cnt() < sb->presentation_info().selection_cnt(); + } +}; + void -Editor::track_selection_changed () +Editor::presentation_info_changed (PropertyChange const & what_changed) { - switch (selection->tracks.size()) { - case 0: - break; - default: - set_selected_mixer_strip (*(selection->tracks.front())); - break; + uint32_t n_tracks = 0; + uint32_t n_busses = 0; + uint32_t n_vcas = 0; + uint32_t n_routes = 0; + uint32_t n_stripables = 0; + + /* We cannot ensure ordering of the handlers for + * PresentationInfo::Changed, so we have to do everything in order + * here, as a single handler. + */ + + if (what_changed.contains (Properties::selected)) { + for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + (*i)->set_selected (false); + (*i)->hide_selection (); + } } - RouteNotificationListPtr routes (new RouteNotificationList); + /* STEP 1: set the GUI selection state (in which TimeAxisViews for the + * currently selected stripable/controllable duples are found and added + */ - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + selection->core_selection_changed (what_changed); - bool yn = (find (selection->tracks.begin(), selection->tracks.end(), *i) != selection->tracks.end()); + /* STEP 2: update TimeAxisView's knowledge of their selected state + */ - (*i)->set_selected (yn); + if (what_changed.contains (Properties::selected)) { - TimeAxisView::Children c = (*i)->get_child_list (); - for (TimeAxisView::Children::iterator j = c.begin(); j != c.end(); ++j) { - (*j)->set_selected (find (selection->tracks.begin(), selection->tracks.end(), j->get()) != selection->tracks.end()); - } + StripableNotificationListPtr stripables (new StripableNotificationList); - if (yn) { - (*i)->reshow_selection (selection->time); - } else { - (*i)->hide_selection (); + switch (selection->tracks.size()) { + case 0: + break; + default: + set_selected_mixer_strip (*(selection->tracks.back())); + if (!_track_selection_change_without_scroll) { + ensure_time_axis_view_is_visible (*(selection->tracks.back()), false); + } + break; } + CoreSelection::StripableAutomationControls sc; + _session->selection().get_stripables (sc); + + for (CoreSelection::StripableAutomationControls::const_iterator i = sc.begin(); i != sc.end(); ++i) { - if (yn) { - RouteTimeAxisView* rtav = dynamic_cast (*i); - if (rtav) { - routes->push_back (rtav->route()); + AxisView* av = axis_view_by_stripable ((*i).stripable); + + if (!av) { + continue; } - } - } - ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, !selection->tracks.empty()); + n_stripables++; - /* notify control protocols */ + if (boost::dynamic_pointer_cast ((*i).stripable)) { + n_tracks++; + n_routes++; + } else if (boost::dynamic_pointer_cast ((*i).stripable)) { + n_busses++; + n_routes++; + } else if (boost::dynamic_pointer_cast ((*i).stripable)) { + n_vcas++; + } - ControlProtocol::TrackSelectionChanged (routes); + TimeAxisView* tav = dynamic_cast (av); - if (sfbrowser && _session && !_session->deletion_in_progress()) { - uint32_t audio_track_cnt = 0; - uint32_t midi_track_cnt = 0; + if (!tav) { + assert (0); + continue; /* impossible */ + } - for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) { - AudioTimeAxisView* atv = dynamic_cast(*x); + if (!(*i).controllable) { - if (atv) { - if (atv->is_audio_track()) { - audio_track_cnt++; - } + /* "parent" track selected */ + tav->set_selected (true); + tav->reshow_selection (selection->time); } else { - MidiTimeAxisView* mtv = dynamic_cast(*x); - if (mtv) { - if (mtv->is_midi_track()) { - midi_track_cnt++; + /* possibly a child */ + + TimeAxisView::Children c = tav->get_child_list (); + + for (TimeAxisView::Children::iterator j = c.begin(); j != c.end(); ++j) { + + boost::shared_ptr control = (*j)->control (); + + if (control != (*i).controllable) { + continue; } + + (*j)->set_selected (true); + (*j)->reshow_selection (selection->time); } } + + stripables->push_back ((*i).stripable); + } + + ActionManager::set_sensitive (ActionManager::stripable_selection_sensitive_actions, (n_stripables > 0)); + ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, (n_tracks > 0)); + ActionManager::set_sensitive (ActionManager::bus_selection_sensitive_actions, (n_busses > 0)); + ActionManager::set_sensitive (ActionManager::route_selection_sensitive_actions, (n_routes > 0)); + ActionManager::set_sensitive (ActionManager::vca_selection_sensitive_actions, (n_vcas > 0)); + + sensitize_the_right_region_actions (false); + + /* STEP 4: notify control protocols */ + + ControlProtocolManager::instance().stripable_selection_changed (stripables); + + if (sfbrowser && _session && !_session->deletion_in_progress()) { + uint32_t audio_track_cnt = 0; + uint32_t midi_track_cnt = 0; + + for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) { + AudioTimeAxisView* atv = dynamic_cast(*x); + + if (atv) { + if (atv->is_audio_track()) { + audio_track_cnt++; + } + + } else { + MidiTimeAxisView* mtv = dynamic_cast(*x); + + if (mtv) { + if (mtv->is_midi_track()) { + midi_track_cnt++; + } + } + } + } + + sfbrowser->reset (audio_track_cnt, midi_track_cnt); } + } + + /* STEP 4: update EditorRoutes treeview */ + + PropertyChange soh; + + soh.add (Properties::selected); + soh.add (Properties::order); + soh.add (Properties::hidden); - sfbrowser->reset (audio_track_cnt, midi_track_cnt); + if (what_changed.contains (soh)) { + _routes->sync_treeview_from_presentation_info (what_changed); } } @@ -1075,23 +1206,87 @@ Editor::sensitize_all_region_actions (bool s) _all_region_actions_sensitized = s; } -/** Sensitize region-based actions based on the selection ONLY, ignoring the entered_regionview. - * This method should be called just before displaying a Region menu. When a Region menu is not - * currently being shown, all region actions are sensitized so that hotkey-triggered actions - * on entered_regionviews work without having to check sensitivity every time the selection or - * entered_regionview changes. +/** Sensitize region-based actions. * - * This method also sets up toggle action state as appropriate. + * This method is called from whenever we leave the canvas, either by moving + * the pointer out of it, or by popping up a context menu. See + * Editor::{entered,left}_track_canvas() for details there. */ void -Editor::sensitize_the_right_region_actions () +Editor::sensitize_the_right_region_actions (bool because_canvas_crossing) { + bool have_selection = false; + bool have_entered = false; + bool have_edit_point = false; + RegionSelection rs; - RegionSelection rs = get_regions_from_selection_and_entered (); - sensitize_all_region_actions (!rs.empty ()); + // std::cerr << "STRRA: crossing ? " << because_canvas_crossing << " within ? " << within_track_canvas + // << std::endl; + + if (!selection->regions.empty()) { + have_selection = true; + rs = selection->regions; + } + + if (entered_regionview) { + have_entered = true; + rs.add (entered_regionview); + } + + if (rs.empty() && !selection->tracks.empty()) { + + /* no selected regions, but some selected tracks. + */ + + if (_edit_point == EditAtMouse) { + if (!within_track_canvas) { + /* pointer is not in canvas, so edit point is meaningless */ + have_edit_point = false; + } else { + /* inside canvas. we don't know where the edit + point will be when an action is invoked, but + assume it could intersect with a region. + */ + have_edit_point = true; + } + } else { + RegionSelection at_edit_point; + framepos_t const where = get_preferred_edit_position (Editing::EDIT_IGNORE_NONE, false, !within_track_canvas); + get_regions_at (at_edit_point, where, selection->tracks); + if (!at_edit_point.empty()) { + have_edit_point = true; + } + if (rs.empty()) { + rs.insert (rs.end(), at_edit_point.begin(), at_edit_point.end()); + } + } + } + + //std::cerr << "\tfinal have selection: " << have_selection + // << " have entered " << have_entered + // << " have edit point " << have_edit_point + // << " EP = " << enum_2_string (_edit_point) + // << std::endl; + + typedef std::map RegionActionMap; _ignore_region_action = true; + for (RegionActionMap::iterator x = region_action_map.begin(); x != region_action_map.end(); ++x) { + RegionActionTarget tgt = x->second.target; + bool sensitive = false; + + if ((tgt & SelectedRegions) && have_selection) { + sensitive = true; + } else if ((tgt & EnteredRegions) && have_entered) { + sensitive = true; + } else if ((tgt & EditPointRegions) && have_edit_point) { + sensitive = true; + } + + x->second.action->set_sensitive (sensitive); + } + /* Look through the regions that are selected and make notes about what we have got */ bool have_audio = false; @@ -1116,6 +1311,7 @@ Editor::sensitize_the_right_region_actions () bool have_inactive_fade_out = false; bool have_active_fade_in = false; bool have_active_fade_out = false; + bool have_transients = false; for (list::const_iterator i = rs.begin(); i != rs.end(); ++i) { @@ -1171,6 +1367,10 @@ Editor::sensitize_the_right_region_actions () have_not_at_natural_position = true; } + if (r->has_transients ()){ + have_transients = true; + } + if (ar) { if (ar->envelope_active()) { have_envelope_active = true; @@ -1196,6 +1396,8 @@ Editor::sensitize_the_right_region_actions () } } + _region_actions->get_action("split-region-at-transients")->set_sensitive (have_transients); + if (rs.size() > 1) { _region_actions->get_action("show-region-list-editor")->set_sensitive (false); _region_actions->get_action("show-region-properties")->set_sensitive (false); @@ -1234,13 +1436,7 @@ Editor::sensitize_the_right_region_actions () /* others were already marked sensitive */ } - if (_edit_point == EditAtMouse) { - _region_actions->get_action("set-region-sync-position")->set_sensitive (false); - _region_actions->get_action("trim-front")->set_sensitive (false); - _region_actions->get_action("trim-back")->set_sensitive (false); - _region_actions->get_action("split-region")->set_sensitive (false); - _region_actions->get_action("place-transient")->set_sensitive (false); - } + /* ok, moving along... */ if (have_compound_regions) { _region_actions->get_action("uncombine-regions")->set_sensitive (true); @@ -1287,8 +1483,12 @@ Editor::sensitize_the_right_region_actions () a = Glib::RefPtr::cast_dynamic (_region_actions->get_action("toggle-region-lock-style")); a->set_active (have_position_lock_style_music && !have_position_lock_style_audio); - if (have_position_lock_style_music && have_position_lock_style_audio) { - // a->set_inconsistent (); + vector proxies = a->get_proxies(); + for (vector::iterator p = proxies.begin(); p != proxies.end(); ++p) { + Gtk::CheckMenuItem* cmi = dynamic_cast (*p); + if (cmi) { + cmi->set_inconsistent (have_position_lock_style_music && have_position_lock_style_audio); + } } a = Glib::RefPtr::cast_dynamic (_region_actions->get_action("toggle-region-mute")); @@ -1342,7 +1542,6 @@ Editor::sensitize_the_right_region_actions () _all_region_actions_sensitized = false; } - void Editor::region_selection_changed () { @@ -1364,16 +1563,7 @@ Editor::region_selection_changed () _regions->block_change_connection (false); editor_regions_selection_changed_connection.block(false); - if (!_all_region_actions_sensitized) { - /* This selection change might have changed what region actions - are allowed, so sensitize them all in case a key is pressed. - */ - sensitize_all_region_actions (true); - } - - if (_session && !_session->transport_rolling() && !selection->regions.empty()) { - maybe_locate_with_edit_preroll (selection->regions.start()); - } + sensitize_the_right_region_actions (false); /* propagate into backend */ @@ -1453,28 +1643,32 @@ Editor::select_all_objects (Selection::Operation op) { list touched; - TrackViewList ts = track_views; - if (internal_editing() && select_all_internal_edit(op)) { return; // Selected notes } + TrackViewList ts; + + if (selection->tracks.empty()) { + ts = track_views; + } else { + ts = selection->tracks; + } + for (TrackViewList::iterator iter = ts.begin(); iter != ts.end(); ++iter) { if ((*iter)->hidden()) { continue; } (*iter)->get_selectables (0, max_framepos, 0, DBL_MAX, touched); - selection->add (*iter); } - begin_reversible_selection_op (X_("select all")); switch (op) { case Selection::Add: selection->add (touched); break; case Selection::Toggle: - selection->add (touched); + selection->toggle (touched); break; case Selection::Set: selection->set (touched); @@ -1557,7 +1751,7 @@ Editor::select_all_within (framepos_t start, framepos_t end, double top, double if (preserve_if_selected && op != Selection::Toggle) { list::iterator i = found.begin(); - while (i != found.end() && (*i)->get_selected()) { + while (i != found.end() && (*i)->selected()) { ++i; } @@ -1611,7 +1805,9 @@ Editor::set_selection_from_region () selection->set (tvl); - set_mouse_mode (Editing::MouseRange, false); + if (!get_smart_mode () || !mouse_mode == Editing::MouseObject) { + set_mouse_mode (Editing::MouseRange, false); + } } void @@ -1644,7 +1840,9 @@ Editor::set_selection_from_range (Location& loc) selection->set (loc.start(), loc.end()); commit_reversible_selection_op (); - set_mouse_mode (Editing::MouseRange, false); + if (!get_smart_mode () || mouse_mode != Editing::MouseObject) { + set_mouse_mode (MouseRange, false); + } } void @@ -1903,8 +2101,11 @@ Editor::select_range_between () return; } + if (!get_smart_mode () || mouse_mode != Editing::MouseObject) { + set_mouse_mode (MouseRange, false); + } + begin_reversible_selection_op (X_("Select Range Between")); - set_mouse_mode (MouseRange); selection->set (start, end); commit_reversible_selection_op (); }