+ TrackViewList tr;
+ tr.push_back (track);
+ add (tr);
+}
+
+void
+Selection::remove (TimeAxisView* track)
+{
+ TrackViewList tvl;
+ tvl.push_back (track);
+ remove (tvl);
+}
+
+void
+Selection::remove (const TrackViewList& t)
+{
+ CoreSelection& selection (editor->session()->selection());
+ PresentationInfo::ChangeSuspender cs;
+
+ for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
+ boost::shared_ptr<Stripable> s = (*i)->stripable ();
+ boost::shared_ptr<AutomationControl> c = (*i)->control ();
+ selection.remove (s, c);
+ }
+}
+
+void
+Selection::set (TimeAxisView* track)
+{
+ TrackViewList tvl;
+ tvl.push_back (track);
+ set (tvl);
+}
+
+void
+Selection::set (const TrackViewList& track_list)
+{
+ TrackViewList t = add_grouped_tracks (track_list);
+
+ CoreSelection& selection (editor->session()->selection());
+
+#if 1 // crazy optmization hack
+ /* check is the selection actually changed, ignore NO-OPs
+ *
+ * There are excessive calls from EditorRoutes::selection_changed():
+ * Every click calls selection_changed() even if it doesn't change.
+ * Also re-ordering tracks calls into this due to gtk's odd DnD signal
+ * messaging (row removed, re-added).
+ *
+ * Re-ordering a row results in at least 2 calls to selection_changed()
+ * without actual change. Calling selection.clear_stripables()
+ * and re-adding the same tracks every time in turn emits changed signals.
+ */
+ bool changed = false;
+ CoreSelection::StripableAutomationControls sac;
+ selection.get_stripables (sac);
+ for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
+ boost::shared_ptr<Stripable> s = (*i)->stripable ();
+ boost::shared_ptr<AutomationControl> c = (*i)->control ();
+ bool found = false;
+ for (CoreSelection::StripableAutomationControls::iterator j = sac.begin (); j != sac.end (); ++j) {
+ if (j->stripable == s && j->controllable == c) {
+ found = true;
+ sac.erase (j);
+ break;
+ }
+ }
+ if (!found) {
+ changed = true;
+ break;
+ }
+ }
+ if (!changed && sac.size() == 0) {
+ return;
+ }
+#endif
+
+ PresentationInfo::ChangeSuspender cs;
+
+ selection.clear_stripables ();
+
+ for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
+ boost::shared_ptr<Stripable> s = (*i)->stripable ();
+ boost::shared_ptr<AutomationControl> c = (*i)->control ();
+ selection.add (s, c);
+ }
+}
+
+void
+Selection::clear_tracks (bool)
+{
+ if (!manage_libardour_selection) {
+ return;
+ }
+
+ Session* s = editor->session();
+ if (s) {
+ CoreSelection& selection (s->selection());
+ selection.clear_stripables ();
+ }
+}
+
+bool
+Selection::selected (TimeAxisView* tv) const
+{
+ Session* session = editor->session();
+
+ if (!session) {
+ return false;
+ }
+
+ CoreSelection& selection (session->selection());
+ boost::shared_ptr<Stripable> s = tv->stripable ();
+ boost::shared_ptr<AutomationControl> c = tv->control ();
+
+ if (c) {
+ return selection.selected (c);
+ }
+
+ return selection.selected (s);
+}
+
+TrackViewList
+Selection::add_grouped_tracks (TrackViewList const & t)
+{
+ TrackViewList added;
+
+ for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
+ if (dynamic_cast<VCATimeAxisView*> (*i)) {
+ continue;
+ }
+
+ /* select anything in the same select-enabled route group */
+ ARDOUR::RouteGroup* rg = (*i)->route_group ();
+
+ if (rg && rg->is_active() && rg->is_select ()) {
+
+ TrackViewList tr = editor->axis_views_from_routes (rg->route_list ());
+
+ for (TrackViewList::iterator j = tr.begin(); j != tr.end(); ++j) {
+
+ /* Do not add the trackview passed in as an
+ * argument, because we want that to be on the
+ * end of the list.
+ */
+
+ if (*j != *i) {
+ if (!added.contains (*j)) {
+ added.push_back (*j);
+ }
+ }
+ }
+ }
+ }
+
+ /* now add the the trackview's passed in as actual arguments */
+ added.insert (added.end(), t.begin(), t.end());
+
+ return added;
+}
+
+#if 0
+static void dump_tracks (Selection const & s)
+{
+ cerr << "--TRACKS [" << s.tracks.size() << ']' << ":\n";
+ for (TrackViewList::const_iterator x = s.tracks.begin(); x != s.tracks.end(); ++x) {
+ cerr << (*x)->name() << ' ' << (*x)->stripable() << " C = " << (*x)->control() << endl;
+ }
+ cerr << "///\n";
+}
+#endif
+
+void
+Selection::core_selection_changed (PropertyChange const & what_changed)
+{
+ PropertyChange pc;
+
+ pc.add (Properties::selected);
+
+ if (!what_changed.contains (pc)) {
+ return;
+ }
+
+ CoreSelection& selection (editor->session()->selection());
+
+ if (selection.selected()) {
+ clear_objects(); // enforce object/range exclusivity
+ }
+
+ tracks.clear (); // clear stage for whatever tracks are now selected (maybe none)
+
+ CoreSelection::StripableAutomationControls sac;
+ selection.get_stripables (sac);
+
+ for (CoreSelection::StripableAutomationControls::const_iterator i = sac.begin(); i != sac.end(); ++i) {
+ AxisView* av;
+ TimeAxisView* tav;
+ if ((*i).controllable) {
+ av = editor->axis_view_by_control ((*i).controllable);
+ } else {
+ av = editor->axis_view_by_stripable ((*i).stripable);
+ }
+
+ tav = dynamic_cast<TimeAxisView*>(av);
+ if (tav) {
+ tracks.push_back (tav);
+ }
+ }
+
+ TracksChanged();