2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <sigc++/bind.h>
23 #include "pbd/error.h"
24 #include "pbd/stacktrace.h"
25 #include "pbd/types_convert.h"
27 #include "ardour/evoral_types_convert.h"
28 #include "ardour/playlist.h"
29 #include "ardour/rc_configuration.h"
30 #include "ardour/selection.h"
32 #include "control_protocol/control_protocol.h"
34 #include "audio_region_view.h"
36 #include "gui_thread.h"
37 #include "midi_cut_buffer.h"
38 #include "region_gain_line.h"
39 #include "region_view.h"
40 #include "selection.h"
41 #include "selection_templates.h"
42 #include "time_axis_view.h"
43 #include "automation_time_axis.h"
44 #include "public_editor.h"
45 #include "control_point.h"
46 #include "vca_time_axis.h"
51 using namespace ARDOUR;
54 struct AudioRangeComparator {
55 bool operator()(AudioRange a, AudioRange b) {
56 return a.start < b.start;
60 Selection::Selection (const PublicEditor* e, bool mls)
64 , manage_libardour_selection (mls)
68 /* we have disambiguate which remove() for the compiler */
70 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
71 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
73 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
74 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
79 Selection::operator= (const Selection& other)
82 regions = other.regions;
83 tracks = other.tracks;
86 midi_regions = other.midi_regions;
87 midi_notes = other.midi_notes;
94 operator== (const Selection& a, const Selection& b)
96 return a.regions == b.regions &&
97 a.tracks == b.tracks &&
100 a.playlists == b.playlists &&
101 a.midi_notes == b.midi_notes &&
102 a.midi_regions == b.midi_regions;
105 /** Clear everything from the Selection */
116 clear_midi_regions ();
118 pending_midi_note_selection.clear();
122 Selection::clear_objects (bool with_signal)
124 clear_regions (with_signal);
125 clear_points (with_signal);
126 clear_lines(with_signal);
127 clear_playlists (with_signal);
128 clear_midi_notes (with_signal);
129 clear_midi_regions (with_signal);
133 Selection::clear_time (bool with_signal)
142 Selection::dump_region_layers()
144 cerr << "region selection layer dump" << endl;
145 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
146 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
152 Selection::clear_regions (bool with_signal)
154 if (!regions.empty()) {
155 regions.clear_all ();
163 Selection::clear_midi_notes (bool with_signal)
165 if (!midi_notes.empty()) {
166 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
175 // clear note selections for MRV's that have note selections
176 // this will cause the MRV to be removed from the list
177 for (MidiRegionSelection::iterator i = midi_regions.begin();
178 i != midi_regions.end();) {
179 MidiRegionSelection::iterator tmp = i;
181 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
183 mrv->clear_selection();
190 Selection::clear_midi_regions (bool with_signal)
192 if (!midi_regions.empty()) {
193 midi_regions.clear ();
195 MidiRegionsChanged ();
201 Selection::clear_playlists (bool with_signal)
203 /* Selections own their playlists */
205 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
206 /* selections own their own regions, which are copies of the "originals". make them go away */
207 (*i)->drop_regions ();
211 if (!playlists.empty()) {
220 Selection::clear_lines (bool with_signal)
222 if (!lines.empty()) {
231 Selection::clear_markers (bool with_signal)
233 if (!markers.empty()) {
242 Selection::toggle (boost::shared_ptr<Playlist> pl)
244 clear_time(); //enforce object/range exclusivity
245 clear_tracks(); //enforce object/track exclusivity
247 PlaylistSelection::iterator i;
249 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
251 playlists.push_back(pl);
260 Selection::toggle (const MidiNoteSelection& midi_note_list)
262 clear_time(); //enforce object/range exclusivity
263 clear_tracks(); //enforce object/track exclusivity
265 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
271 Selection::toggle (MidiCutBuffer* midi)
273 MidiNoteSelection::iterator i;
275 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
276 midi_notes.push_back (midi);
278 /* remember that we own the MCB */
280 midi_notes.erase (i);
288 Selection::toggle (RegionView* r)
290 clear_time(); //enforce object/range exclusivity
291 clear_tracks(); //enforce object/track exclusivity
293 RegionSelection::iterator i;
295 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
305 Selection::toggle (MidiRegionView* mrv)
307 clear_time(); //enforce object/range exclusivity
308 clear_tracks(); //enforce object/track exclusivity
310 MidiRegionSelection::iterator i;
312 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
315 midi_regions.erase (i);
318 MidiRegionsChanged ();
322 Selection::toggle (vector<RegionView*>& r)
324 clear_time(); //enforce object/range exclusivity
325 clear_tracks(); //enforce object/track exclusivity
327 RegionSelection::iterator i;
329 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
330 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
341 Selection::toggle (framepos_t start, framepos_t end)
343 clear_objects(); //enforce object/range exclusivity
345 AudioRangeComparator cmp;
347 /* XXX this implementation is incorrect */
349 time.push_back (AudioRange (start, end, ++next_time_id));
359 Selection::add (boost::shared_ptr<Playlist> pl)
362 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
363 clear_time(); //enforce object/range exclusivity
364 clear_tracks(); //enforce object/track exclusivity
366 playlists.push_back(pl);
372 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
374 bool changed = false;
376 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
377 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
379 playlists.push_back (*i);
385 clear_time(); //enforce object/range exclusivity
386 clear_tracks(); //enforce object/track exclusivity
392 Selection::add (const MidiNoteSelection& midi_list)
394 const MidiNoteSelection::const_iterator b = midi_list.begin();
395 const MidiNoteSelection::const_iterator e = midi_list.end();
397 if (!midi_list.empty()) {
398 clear_time(); //enforce object/range exclusivity
399 clear_tracks(); //enforce object/track exclusivity
400 midi_notes.insert (midi_notes.end(), b, e);
406 Selection::add (MidiCutBuffer* midi)
408 /* we take ownership of the MCB */
410 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
411 midi_notes.push_back (midi);
417 Selection::add (vector<RegionView*>& v)
419 /* XXX This method or the add (const RegionSelection&) needs to go
422 bool changed = false;
424 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
425 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
426 changed = regions.add ((*i));
431 clear_time(); //enforce object/range exclusivity
432 clear_tracks(); //enforce object/track exclusivity
438 Selection::add (const RegionSelection& rs)
440 /* XXX This method or the add (const vector<RegionView*>&) needs to go
443 bool changed = false;
445 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
446 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
447 changed = regions.add ((*i));
452 clear_time(); //enforce object/range exclusivity
453 clear_tracks(); //enforce object/track exclusivity
459 Selection::add (RegionView* r)
461 if (find (regions.begin(), regions.end(), r) == regions.end()) {
462 bool changed = regions.add (r);
464 clear_time(); //enforce object/range exclusivity
465 clear_tracks(); //enforce object/track exclusivity
472 Selection::add (MidiRegionView* mrv)
474 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
476 clear_time(); //enforce object/range exclusivity
477 clear_tracks(); //enforce object/track exclusivity
479 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
480 midi_regions.push_back (mrv);
481 /* XXX should we do this? */
482 MidiRegionsChanged ();
487 Selection::add (framepos_t start, framepos_t end)
489 clear_objects(); //enforce object/range exclusivity
491 AudioRangeComparator cmp;
493 /* XXX this implementation is incorrect */
495 time.push_back (AudioRange (start, end, ++next_time_id));
505 Selection::move_time (framecnt_t distance)
511 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
512 (*i).start += distance;
513 (*i).end += distance;
520 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
522 clear_objects(); //enforce object/range exclusivity
524 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
525 if ((*i).id == sid) {
527 time.push_back (AudioRange(start,end, sid));
529 /* don't consolidate here */
532 AudioRangeComparator cmp;
542 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
544 boost::shared_ptr<ARDOUR::AutomationList> al = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
547 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
552 clear_time(); //enforce object/range exclusivity
553 clear_tracks(); //enforce object/track exclusivity
556 /* The original may change so we must store a copy (not a pointer) here.
557 * e.g AutomationLine rewrites the list with gain mapping.
558 * the downside is that we can't perfom duplicate checks.
559 * This code was changed in response to #6842
561 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
566 Selection::remove (ControlPoint* p)
568 PointSelection::iterator i = find (points.begin(), points.end(), p);
569 if (i != points.end ()) {
575 Selection::remove (const MidiNoteSelection& midi_list)
577 bool changed = false;
579 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
581 MidiNoteSelection::iterator x;
583 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
584 midi_notes.erase (x);
595 Selection::remove (MidiCutBuffer* midi)
597 MidiNoteSelection::iterator x;
599 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
600 /* remember that we own the MCB */
602 midi_notes.erase (x);
608 Selection::remove (boost::shared_ptr<Playlist> track)
610 list<boost::shared_ptr<Playlist> >::iterator i;
611 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
618 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
620 bool changed = false;
622 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
624 list<boost::shared_ptr<Playlist> >::iterator x;
626 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
638 Selection::remove (RegionView* r)
640 if (regions.remove (r)) {
646 Selection::remove (MidiRegionView* mrv)
648 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
650 MidiRegionSelection::iterator x;
652 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
653 midi_regions.erase (x);
654 MidiRegionsChanged ();
659 Selection::remove (uint32_t selection_id)
665 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
666 if ((*i).id == selection_id) {
676 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
681 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
683 AutomationSelection::iterator i;
684 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
691 Selection::set (const MidiNoteSelection& midi_list)
693 if (!midi_list.empty()) {
694 clear_time (); //enforce region/object exclusivity
695 clear_tracks(); //enforce object/track exclusivity
702 Selection::set (boost::shared_ptr<Playlist> playlist)
705 clear_time (); //enforce region/object exclusivity
706 clear_tracks(); //enforce object/track exclusivity
713 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
715 if (!pllist.empty()) {
716 clear_time(); //enforce region/object exclusivity
723 Selection::set (const RegionSelection& rs)
726 clear_time(); //enforce region/object exclusivity
727 clear_tracks(); //enforce object/track exclusivity
731 RegionsChanged(); /* EMIT SIGNAL */
735 Selection::set (MidiRegionView* mrv)
738 clear_time(); //enforce region/object exclusivity
739 clear_tracks(); //enforce object/track exclusivity
746 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
749 clear_time(); //enforce region/object exclusivity
750 clear_tracks(); //enforce object/track exclusivity
757 Selection::set (vector<RegionView*>& v)
760 clear_time(); //enforce region/object exclusivity
761 clear_tracks(); //enforce object/track exclusivity
769 /** Set the start and end time of the time selection, without changing
770 * the list of tracks it applies to.
773 Selection::set (framepos_t start, framepos_t end)
775 clear_objects(); //enforce region/object exclusivity
778 if ((start == 0 && end == 0) || end < start) {
783 time.push_back (AudioRange (start, end, ++next_time_id));
785 /* reuse the first entry, and remove all the rest */
787 while (time.size() > 1) {
790 time.front().start = start;
791 time.front().end = end;
798 return time.front().id;
801 /** Set the start and end of the range selection. If more than one range
802 * is currently selected, the start of the earliest range and the end of the
803 * latest range are set. If no range is currently selected, this method
804 * selects a single range from start to end.
806 * @param start New start time.
807 * @param end New end time.
810 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
812 clear_objects(); //enforce region/object exclusivity
814 if ((start == 0 && end == 0) || (end < start)) {
819 time.push_back (AudioRange (start, end, ++next_time_id));
821 time.sort (AudioRangeComparator ());
822 time.front().start = start;
823 time.back().end = end;
832 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
834 clear_time(); //enforce region/object exclusivity
835 clear_tracks(); //enforce object/track exclusivity
842 Selection::selected (ArdourMarker* m) const
844 return find (markers.begin(), markers.end(), m) != markers.end();
848 Selection::selected (RegionView* rv) const
850 return find (regions.begin(), regions.end(), rv) != regions.end();
854 Selection::selected (ControlPoint* cp) const
856 return find (points.begin(), points.end(), cp) != points.end();
860 Selection::empty (bool internal_selection)
862 bool object_level_empty = regions.empty () &&
865 playlists.empty () &&
868 playlists.empty () &&
873 if (!internal_selection) {
874 return object_level_empty;
877 /* this is intended to really only apply when using a Selection
881 return object_level_empty && midi_notes.empty() && points.empty();
885 Selection::toggle (ControlPoint* cp)
887 clear_time(); //enforce region/object exclusivity
888 clear_tracks(); //enforce object/track exclusivity
890 cp->set_selected (!cp->selected ());
891 PointSelection::iterator i = find (points.begin(), points.end(), cp);
892 if (i == points.end()) {
893 points.push_back (cp);
898 PointsChanged (); /* EMIT SIGNAL */
902 Selection::toggle (vector<ControlPoint*> const & cps)
904 clear_time(); //enforce region/object exclusivity
905 clear_tracks(); //enforce object/track exclusivity
907 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
913 Selection::toggle (list<Selectable*> const & selectables)
915 clear_time(); //enforce region/object exclusivity
916 clear_tracks(); //enforce object/track exclusivity
920 vector<RegionView*> rvs;
921 vector<ControlPoint*> cps;
923 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
924 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
926 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
929 fatal << _("programming error: ")
930 << X_("unknown selectable type passed to Selection::toggle()")
932 abort(); /*NOTREACHED*/
946 Selection::set (list<Selectable*> const & selectables)
948 clear_time (); //enforce region/object exclusivity
949 clear_tracks(); //enforce object/track exclusivity
956 Selection::add (PointSelection const & s)
958 clear_time (); //enforce region/object exclusivity
959 clear_tracks(); //enforce object/track exclusivity
961 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
962 points.push_back (*i);
967 Selection::add (list<Selectable*> const & selectables)
969 clear_time (); //enforce region/object exclusivity
970 clear_tracks(); //enforce object/track exclusivity
974 vector<RegionView*> rvs;
975 vector<ControlPoint*> cps;
977 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
978 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
980 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
983 fatal << _("programming error: ")
984 << X_("unknown selectable type passed to Selection::add()")
986 abort(); /*NOTREACHED*/
1000 Selection::clear_points (bool with_signal)
1002 if (!points.empty()) {
1011 Selection::add (ControlPoint* cp)
1013 clear_time (); //enforce region/object exclusivity
1014 clear_tracks(); //enforce object/track exclusivity
1016 cp->set_selected (true);
1017 points.push_back (cp);
1018 PointsChanged (); /* EMIT SIGNAL */
1022 Selection::add (vector<ControlPoint*> const & cps)
1024 clear_time (); //enforce region/object exclusivity
1025 clear_tracks(); //enforce object/track exclusivity
1027 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1028 (*i)->set_selected (true);
1029 points.push_back (*i);
1031 PointsChanged (); /* EMIT SIGNAL */
1035 Selection::set (ControlPoint* cp)
1037 clear_time (); //enforce region/object exclusivity
1038 clear_tracks(); //enforce object/track exclusivity
1040 if (cp->selected () && points.size () == 1) {
1044 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1045 cp->line().nth (i)->set_selected (false);
1053 Selection::set (ArdourMarker* m)
1055 clear_time (); //enforce region/object exclusivity
1056 clear_tracks(); //enforce object/track exclusivity
1063 Selection::toggle (ArdourMarker* m)
1065 MarkerSelection::iterator i;
1067 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1075 Selection::remove (ArdourMarker* m)
1077 MarkerSelection::iterator i;
1079 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1086 Selection::add (ArdourMarker* m)
1088 clear_time (); //enforce region/object exclusivity
1089 clear_tracks(); //enforce object/track exclusivity
1091 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1092 markers.push_back (m);
1098 Selection::add (const list<ArdourMarker*>& m)
1100 clear_time (); //enforce region/object exclusivity
1101 clear_tracks(); //enforce object/track exclusivity
1103 markers.insert (markers.end(), m.begin(), m.end());
1111 MarkerSelection::range (framepos_t& s, framepos_t& e)
1116 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1118 if ((*i)->position() < s) {
1119 s = (*i)->position();
1122 if ((*i)->position() > e) {
1123 e = (*i)->position();
1127 s = std::min (s, e);
1128 e = std::max (s, e);
1132 Selection::get_state () const
1134 /* XXX: not complete; just sufficient to get track selection state
1135 so that re-opening plugin windows for editor mixer strips works
1138 XMLNode* node = new XMLNode (X_("Selection"));
1140 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1141 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1142 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1144 XMLNode* t = node->add_child (X_("RouteView"));
1145 t->set_property (X_("id"), rtv->route()->id ());
1147 XMLNode* t = node->add_child (X_("AutomationView"));
1148 t->set_property (X_("id"), atv->parent_stripable()->id ());
1149 t->set_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1153 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1154 XMLNode* r = node->add_child (X_("Region"));
1155 r->set_property (X_("id"), (*i)->region ()->id ());
1158 /* midi region views have thir own internal selection. */
1159 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1160 editor->get_per_region_note_selection (rid_notes);
1162 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1163 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1164 XMLNode* n = node->add_child (X_("MIDINotes"));
1165 n->set_property (X_("region-id"), (*rn_it).first);
1167 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1168 XMLNode* nc = n->add_child(X_("note"));
1169 nc->set_property(X_("note-id"), (*i)->id());
1173 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1174 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1177 XMLNode* r = node->add_child (X_("ControlPoint"));
1178 r->set_property (X_("type"), "track");
1179 r->set_property (X_("route-id"), atv->parent_stripable()->id ());
1180 r->set_property (X_("automation-list-id"), (*i)->line().the_list()->id ());
1181 r->set_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1182 r->set_property (X_("view-index"), (*i)->view_index());
1186 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1188 XMLNode* r = node->add_child (X_("ControlPoint"));
1189 r->set_property (X_("type"), "region");
1190 r->set_property (X_("region-id"), argl->region_view ().region ()->id ());
1191 r->set_property (X_("view-index"), (*i)->view_index());
1196 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1197 XMLNode* t = node->add_child (X_("AudioRange"));
1198 t->set_property (X_("start"), (*i).start);
1199 t->set_property (X_("end"), (*i).end);
1202 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1203 XMLNode* t = node->add_child (X_("Marker"));
1206 Location* loc = editor->find_location_from_marker (*i, is_start);
1208 t->set_property (X_("id"), loc->id());
1209 t->set_property (X_("start"), is_start);
1216 Selection::set_state (XMLNode const & node, int)
1218 if (node.name() != X_("Selection")) {
1223 clear_midi_notes ();
1228 RegionSelection selected_regions;
1230 /* NOTE: stripable/time-axis-view selection is saved/restored by
1231 * ARDOUR::CoreSelection, not this Selection object
1235 XMLNodeList children = node.children ();
1237 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1238 if ((*i)->name() == X_("Region")) {
1240 if (!(*i)->get_property (X_("id"), id)) {
1245 editor->get_regionviews_by_id (id, rs);
1248 selected_regions.insert (selected_regions.end(), rs.begin(), rs.end());
1251 regionviews haven't been constructed - stash the region IDs
1252 so we can identify them in Editor::region_view_added ()
1254 regions.pending.push_back (id);
1257 } else if ((*i)->name() == X_("MIDINotes")) {
1259 if (!(*i)->get_property (X_("region-id"), id)) {
1265 editor->get_regionviews_by_id (id, rs); // there could be more than one
1267 std::list<Evoral::event_id_t> notes;
1268 XMLNodeList children = (*i)->children ();
1270 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1271 Evoral::event_id_t id;
1272 if ((*ci)->get_property (X_ ("note-id"), id)) {
1273 notes.push_back (id);
1277 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1278 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1280 mrv->select_notes(notes);
1285 /* regionviews containing these notes don't yet exist on the canvas.*/
1286 pending_midi_note_selection.push_back (make_pair (id, notes));
1289 } else if ((*i)->name() == X_("ControlPoint")) {
1290 XMLProperty const * prop_type = (*i)->property (X_("type"));
1294 if (prop_type->value () == "track") {
1299 uint32_t view_index;
1301 if (!(*i)->get_property (X_("route-id"), route_id) ||
1302 !(*i)->get_property (X_("automation-list-id"), alist_id) ||
1303 !(*i)->get_property (X_("parameter"), param) ||
1304 !(*i)->get_property (X_("view-index"), view_index)) {
1308 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id); // XXX may also be VCA
1309 vector <ControlPoint *> cps;
1312 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1314 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1315 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1316 if ((*li)->the_list()->id() == alist_id) {
1317 ControlPoint* cp = (*li)->nth(view_index);
1329 } else if (prop_type->value () == "region") {
1332 uint32_t view_index;
1333 if (!(*i)->get_property (X_("region-id"), region_id) ||
1334 !(*i)->get_property (X_("view-index"), view_index)) {
1339 editor->get_regionviews_by_id (region_id, rs);
1342 vector <ControlPoint *> cps;
1343 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1344 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1346 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1347 ControlPoint* cp = gl->nth(view_index);
1360 } else if ((*i)->name() == X_("AudioRange")) {
1364 if (!(*i)->get_property (X_("start"), start) || !(*i)->get_property (X_("end"), end)) {
1367 set_preserving_all_ranges (start, end);
1369 } else if ((*i)->name() == X_("AutomationView")) {
1373 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("parameter"), param)) {
1377 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1380 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1382 /* the automation could be for an entity that was never saved
1383 in the session file. Don't freak out if we can't find
1392 } else if ((*i)->name() == X_("Marker")) {
1395 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("start"), is_start)) {
1399 ArdourMarker* m = editor->find_marker_from_location_id (id, is_start);
1408 // now add regions to selection at once
1409 add (selected_regions);
1415 Selection::remove_regions (TimeAxisView* t)
1417 RegionSelection::iterator i = regions.begin();
1418 while (i != regions.end ()) {
1419 RegionSelection::iterator tmp = i;
1422 if (&(*i)->get_time_axis_view() == t) {
1430 /* TIME AXIS VIEW ... proxy for Stripable/Controllable
1432 * public methods just modify the CoreSelection; PresentationInfo::Changed will
1433 * trigger Selection::core_selection_changed() and we will update our own data
1438 Selection::toggle (const TrackViewList& track_list)
1440 TrackViewList t = add_grouped_tracks (track_list);
1442 CoreSelection& selection (editor->session()->selection());
1443 PresentationInfo::ChangeSuspender cs;
1445 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1446 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1447 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1448 selection.toggle (s, c);
1453 Selection::toggle (TimeAxisView* track)
1455 if (dynamic_cast<VCATimeAxisView*> (track)) {
1460 tr.push_back (track);
1465 Selection::add (TrackViewList const & track_list)
1467 TrackViewList t = add_grouped_tracks (track_list);
1469 CoreSelection& selection (editor->session()->selection());
1470 PresentationInfo::ChangeSuspender cs;
1472 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1473 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1474 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1475 selection.add (s, c);
1480 Selection::add (TimeAxisView* track)
1482 if (dynamic_cast<VCATimeAxisView*> (track)) {
1487 tr.push_back (track);
1492 Selection::remove (TimeAxisView* track)
1494 if (dynamic_cast<VCATimeAxisView*> (track)) {
1499 tvl.push_back (track);
1504 Selection::remove (const TrackViewList& t)
1506 CoreSelection& selection (editor->session()->selection());
1507 PresentationInfo::ChangeSuspender cs;
1509 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1510 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1511 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1512 selection.remove (s, c);
1517 Selection::set (TimeAxisView* track)
1519 if (dynamic_cast<VCATimeAxisView*> (track)) {
1524 tvl.push_back (track);
1529 Selection::set (const TrackViewList& track_list)
1531 TrackViewList t = add_grouped_tracks (track_list);
1533 CoreSelection& selection (editor->session()->selection());
1535 #if 1 // crazy optmization hack
1536 /* check is the selection actually changed, ignore NO-OPs
1538 * There are excessive calls from EditorRoutes::selection_changed():
1539 * Every click calls selection_changed() even if it doesn't change.
1540 * Also re-ordering tracks calls into this due to gtk's odd DnD signal
1541 * messaging (row removed, re-added).
1543 * Re-ordering a row results in at least 2 calls to selection_changed()
1544 * without actual change. Calling selection.clear_stripables()
1545 * and re-adding the same tracks every time in turn emits changed signals.
1547 bool changed = false;
1548 CoreSelection::StripableAutomationControls sac;
1549 selection.get_stripables (sac);
1550 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1551 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1552 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1554 for (CoreSelection::StripableAutomationControls::iterator j = sac.begin (); j != sac.end (); ++j) {
1555 if (j->stripable == s && j->controllable == c) {
1566 if (!changed && sac.size() == 0) {
1571 PresentationInfo::ChangeSuspender cs;
1573 selection.clear_stripables ();
1575 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1576 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1577 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1578 selection.add (s, c);
1583 Selection::clear_tracks (bool)
1585 if (!manage_libardour_selection) {
1589 Session* s = editor->session();
1591 CoreSelection& selection (s->selection());
1592 selection.clear_stripables ();
1597 Selection::selected (TimeAxisView* tv) const
1599 Session* session = editor->session();
1605 CoreSelection& selection (session->selection());
1606 boost::shared_ptr<Stripable> s = tv->stripable ();
1607 boost::shared_ptr<AutomationControl> c = tv->control ();
1610 return selection.selected (c);
1613 return selection.selected (s);
1617 Selection::add_grouped_tracks (TrackViewList const & t)
1619 TrackViewList added;
1621 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1622 if (dynamic_cast<VCATimeAxisView*> (*i)) {
1626 /* select anything in the same select-enabled route group */
1627 ARDOUR::RouteGroup* rg = (*i)->route_group ();
1629 if (rg && rg->is_active() && rg->is_select ()) {
1631 TrackViewList tr = editor->axis_views_from_routes (rg->route_list ());
1633 for (TrackViewList::iterator j = tr.begin(); j != tr.end(); ++j) {
1635 /* Do not add the trackview passed in as an
1636 * argument, because we want that to be on the
1641 if (!added.contains (*j)) {
1642 added.push_back (*j);
1649 /* now add the the trackview's passed in as actual arguments */
1650 added.insert (added.end(), t.begin(), t.end());
1656 static void dump_tracks (Selection const & s)
1658 cerr << "--TRACKS [" << s.tracks.size() << ']' << ":\n";
1659 for (TrackViewList::const_iterator x = s.tracks.begin(); x != s.tracks.end(); ++x) {
1660 cerr << (*x)->name() << ' ' << (*x)->stripable() << " C = " << (*x)->control() << endl;
1667 Selection::core_selection_changed (PropertyChange const & what_changed)
1671 pc.add (Properties::selected);
1673 if (!what_changed.contains (pc)) {
1677 CoreSelection& selection (editor->session()->selection());
1679 if (selection.selected()) {
1680 clear_objects(); // enforce object/range exclusivity
1683 tracks.clear (); // clear stage for whatever tracks are now selected (maybe none)
1685 CoreSelection::StripableAutomationControls sac;
1686 selection.get_stripables (sac);
1688 for (CoreSelection::StripableAutomationControls::const_iterator i = sac.begin(); i != sac.end(); ++i) {
1691 if ((*i).controllable) {
1692 av = editor->axis_view_by_control ((*i).controllable);
1694 av = editor->axis_view_by_stripable ((*i).stripable);
1697 tav = dynamic_cast<TimeAxisView*>(av);
1699 tracks.push_back (tav);