diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2018-08-24 14:03:04 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2018-08-24 14:04:18 -0400 |
commit | 2d0416a0169e0c2e13f61fd353775826072ba147 (patch) | |
tree | cd81ff0b5c0654ddd8138bc637b73dea438004bd /libs/ardour/selection.cc | |
parent | 3136b20847ea2e2e12f707bdc82fa336f85f4801 (diff) |
add new methods to ARDOUR::CoreSelection to centralize selecting next/prev stripables
Diffstat (limited to 'libs/ardour/selection.cc')
-rw-r--r-- | libs/ardour/selection.cc | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/libs/ardour/selection.cc b/libs/ardour/selection.cc index 5bd05b99f7..a2c2d16735 100644 --- a/libs/ardour/selection.cc +++ b/libs/ardour/selection.cc @@ -24,6 +24,8 @@ #include "ardour/automation_control.h" #include "ardour/debug.h" +#include "ardour/route.h" +#include "ardour/route_group.h" #include "ardour/selection.h" #include "ardour/session.h" #include "ardour/stripable.h" @@ -49,6 +51,146 @@ CoreSelection::~CoreSelection () { } +template<typename IterTypeForward, typename IterTypeCore> +void +CoreSelection::select_adjacent_stripable (bool mixer_order, bool routes_only, + IterTypeCore (StripableList::*begin_method)(), + IterTypeCore (StripableList::*end_method)()) +{ + if (_stripables.empty()) { + + /* Pick first acceptable */ + + StripableList stripables; + session.get_stripables (stripables); + stripables.sort (ARDOUR::Stripable::Sorter (mixer_order)); + + for (IterTypeForward s = (stripables.*begin_method)(); s != (stripables.*end_method)(); ++s) { + if (select_stripable_and_maybe_group (*s, true, routes_only, 0)) { + break; + } + } + + return; + } + + /* fetch the current selection so that we can get the most recently selected */ + StripableAutomationControls selected; + get_stripables (selected); + boost::shared_ptr<Stripable> last_selected = selected.back().stripable; + + /* Get all stripables and sort into the appropriate ordering */ + StripableList stripables; + session.get_stripables (stripables); + stripables.sort (ARDOUR::Stripable::Sorter (mixer_order)); + + + /* Check for a possible selection-affecting route group */ + + RouteGroup* group = 0; + boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (last_selected); + + if (r && r->route_group() && r->route_group()->is_select()) { + group = r->route_group(); + } + + bool select_me = false; + + for (IterTypeCore i = (stripables.*begin_method)(); i != (stripables.*end_method)(); ++i) { + + if (select_me) { + + if (!this->selected (*i)) { /* not currently selected */ + if (select_stripable_and_maybe_group (*i, true, routes_only, group)) { + return; + } + } + } + + if ((*i) == last_selected) { + select_me = true; + } + } + + /* no previous, wrap around ... find first usable stripable from the back + */ + + for (IterTypeCore s = (stripables.*begin_method)(); s != (stripables.*end_method)(); ++s) { + + r = boost::dynamic_pointer_cast<Route> (*s); + + if ((!routes_only || r) && !(*s)->is_monitor()) { + if (select_stripable_and_maybe_group (*s, true, routes_only, 0)) { + return; + } + } + } +} + +void +CoreSelection::select_next_stripable (bool mixer_order, bool routes_only) +{ + select_adjacent_stripable<StripableList::iterator> (mixer_order, routes_only, &StripableList::begin, &StripableList::end); +} + +void +CoreSelection::select_prev_stripable (bool mixer_order, bool routes_only) +{ + select_adjacent_stripable<StripableList::reverse_iterator> (mixer_order, routes_only, &StripableList::rbegin, &StripableList::rend); +} + + +bool +CoreSelection::select_stripable_and_maybe_group (boost::shared_ptr<Stripable> s, bool with_group, bool routes_only, RouteGroup* group) +{ + boost::shared_ptr<Route> r; + StripableList sl; + + if (s->is_hidden()) { + return false; + } + + if ((r = boost::dynamic_pointer_cast<Route> (s))) { + + if (!r->active()) { + return false; + } + + if (with_group) { + + if (!group || !r->route_group() || r->route_group() != group) { + + if (r->route_group() && r->route_group()->is_select()) { + boost::shared_ptr<RouteList> rl = r->route_group()->route_list (); + for (RouteList::iterator ri = rl->begin(); ri != rl->end(); ++ri) { + if (*ri != r) { + sl.push_back (*ri); + } + } + } + + /* it is important to make the "primary" stripable being selected the last in this + * list + */ + + sl.push_back (s); + set (sl); + return true; + } + + } else { + set (s, boost::shared_ptr<AutomationControl>()); + return true; + } + + } else if (!routes_only) { + set (s, boost::shared_ptr<AutomationControl>()); + return true; + } + + return false; +} + void CoreSelection::toggle (boost::shared_ptr<Stripable> s, boost::shared_ptr<AutomationControl> c) { @@ -62,6 +204,63 @@ CoreSelection::toggle (boost::shared_ptr<Stripable> s, boost::shared_ptr<Automat } void +CoreSelection::set (StripableList& sl) +{ + bool send = false; + boost::shared_ptr<AutomationControl> no_control; + + std::vector<boost::shared_ptr<Stripable> > removed; + + { + Glib::Threads::RWLock::WriterLock lm (_lock); + + removed.reserve (_stripables.size()); + + for (SelectedStripables::const_iterator x = _stripables.begin(); x != _stripables.end(); ++x) { + boost::shared_ptr<Stripable> sp = session.stripable_by_id ((*x).stripable); + if (sp) { + removed.push_back (sp); + } + } + + _stripables.clear (); + + for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) { + + SelectedStripable ss (*s, no_control, g_atomic_int_add (&selection_order, 1)); + + if (_stripables.insert (ss).second) { + DEBUG_TRACE (DEBUG::Selection, string_compose ("set:added %1 to s/c selection\n", (*s)->name())); + send = true; + } else { + DEBUG_TRACE (DEBUG::Selection, string_compose ("%1 already in s/c selection\n", (*s)->name())); + } + } + } + + if (send || !removed.empty()) { + + send_selection_change (); + + /* send per-object signal to notify interested parties + the selection status has changed + */ + + PropertyChange pc (Properties::selected); + + for (std::vector<boost::shared_ptr<Stripable> >::iterator s = removed.begin(); s != removed.end(); ++s) { + (*s)->presentation_info().PropertyChanged (pc); + } + + for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) { + (*s)->presentation_info().PropertyChanged (pc); + } + + } + +} + +void CoreSelection::add (boost::shared_ptr<Stripable> s, boost::shared_ptr<AutomationControl> c) { bool send = false; |