X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_selection.cc;h=b5a0be1c7869aa3e19c71a5a83c8ef282ac08bdb;hb=9bc8b32b8eaf8304d0c51c3340e15345b7300988;hp=1c065289c620347f66ea72127ea6c909bade5fae;hpb=437ec10b318fb44a24c2cadb82da30cfb2a563bf;p=ardour.git diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index 1c065289c6..b5a0be1c78 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -23,16 +23,18 @@ #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" @@ -89,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) { @@ -158,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; @@ -267,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: @@ -981,88 +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: - /* last element in selection list is the most recently - * selected, because we always append to that list. - */ - cerr << "setting selected mixer strip to " - << selection->tracks.back()->name() - << endl; - set_selected_mixer_strip (*(selection->tracks.back())); - if (!_track_selection_change_without_scroll) { - ensure_time_axis_view_is_visible (*(selection->tracks.back()), false); + 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 (); } - break; } - RouteNotificationListPtr routes (new RouteNotificationList); - StripableNotificationListPtr stripables (new StripableNotificationList); + /* 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); - if (yn) { - RouteTimeAxisView* rtav = dynamic_cast (*i); - if (rtav) { - routes->push_back (rtav->route()); - stripables->push_back (rtav->route()); + for (CoreSelection::StripableAutomationControls::const_iterator i = sc.begin(); i != sc.end(); ++i) { + + AxisView* av = axis_view_by_stripable ((*i).stripable); + + if (!av) { + continue; } - } - } - ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, !selection->tracks.empty()); + n_stripables++; - sensitize_the_right_region_actions (false); + 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++; + } + + TimeAxisView* tav = dynamic_cast (av); - /* notify control protocols */ + if (!tav) { + assert (0); + continue; /* impossible */ + } + + if (!(*i).controllable) { - ControlProtocol::StripableSelectionChanged (stripables); + /* "parent" track selected */ + tav->set_selected (true); + tav->reshow_selection (selection->time); - if (sfbrowser && _session && !_session->deletion_in_progress()) { - uint32_t audio_track_cnt = 0; - uint32_t midi_track_cnt = 0; + } else { - for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) { - AudioTimeAxisView* atv = dynamic_cast(*x); + /* 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; + } - if (atv) { - if (atv->is_audio_track()) { - audio_track_cnt++; + (*j)->set_selected (true); + (*j)->reshow_selection (selection->time); } + } - } else { - MidiTimeAxisView* mtv = dynamic_cast(*x); + 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++; + if (mtv) { + if (mtv->is_midi_track()) { + midi_track_cnt++; + } } } } + + sfbrowser->reset (audio_track_cnt, 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); + + if (what_changed.contains (soh)) { + _routes->sync_treeview_from_presentation_info (what_changed); } } @@ -1556,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); @@ -1714,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 @@ -1747,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 @@ -2006,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 (); }