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)
67 /* we have disambiguate which remove() for the compiler */
69 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
70 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
72 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
73 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
78 Selection::operator= (const Selection& other)
81 regions = other.regions;
82 tracks = other.tracks;
85 midi_regions = other.midi_regions;
86 midi_notes = other.midi_notes;
93 operator== (const Selection& a, const Selection& b)
95 return a.regions == b.regions &&
96 a.tracks == b.tracks &&
99 a.playlists == b.playlists &&
100 a.midi_notes == b.midi_notes &&
101 a.midi_regions == b.midi_regions;
104 /** Clear everything from the Selection */
115 clear_midi_regions ();
117 pending_midi_note_selection.clear();
121 Selection::clear_objects (bool with_signal)
123 clear_regions (with_signal);
124 clear_points (with_signal);
125 clear_lines(with_signal);
126 clear_playlists (with_signal);
127 clear_midi_notes (with_signal);
128 clear_midi_regions (with_signal);
132 Selection::clear_time (bool with_signal)
141 Selection::dump_region_layers()
143 cerr << "region selection layer dump" << endl;
144 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
145 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
151 Selection::clear_regions (bool with_signal)
153 if (!regions.empty()) {
154 regions.clear_all ();
162 Selection::clear_midi_notes (bool with_signal)
164 if (!midi_notes.empty()) {
165 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
174 // clear note selections for MRV's that have note selections
175 // this will cause the MRV to be removed from the list
176 for (MidiRegionSelection::iterator i = midi_regions.begin();
177 i != midi_regions.end();) {
178 MidiRegionSelection::iterator tmp = i;
180 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
182 mrv->clear_selection();
189 Selection::clear_midi_regions (bool with_signal)
191 if (!midi_regions.empty()) {
192 midi_regions.clear ();
194 MidiRegionsChanged ();
200 Selection::clear_playlists (bool with_signal)
202 /* Selections own their playlists */
204 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
205 /* selections own their own regions, which are copies of the "originals". make them go away */
206 (*i)->drop_regions ();
210 if (!playlists.empty()) {
219 Selection::clear_lines (bool with_signal)
221 if (!lines.empty()) {
230 Selection::clear_markers (bool with_signal)
232 if (!markers.empty()) {
241 Selection::toggle (boost::shared_ptr<Playlist> pl)
243 clear_time(); //enforce object/range exclusivity
244 clear_tracks(); //enforce object/track exclusivity
246 PlaylistSelection::iterator i;
248 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
250 playlists.push_back(pl);
259 Selection::toggle (const MidiNoteSelection& midi_note_list)
261 clear_time(); //enforce object/range exclusivity
262 clear_tracks(); //enforce object/track exclusivity
264 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
270 Selection::toggle (MidiCutBuffer* midi)
272 MidiNoteSelection::iterator i;
274 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
275 midi_notes.push_back (midi);
277 /* remember that we own the MCB */
279 midi_notes.erase (i);
287 Selection::toggle (RegionView* r)
289 clear_time(); //enforce object/range exclusivity
290 clear_tracks(); //enforce object/track exclusivity
292 RegionSelection::iterator i;
294 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
304 Selection::toggle (MidiRegionView* mrv)
306 clear_time(); //enforce object/range exclusivity
307 clear_tracks(); //enforce object/track exclusivity
309 MidiRegionSelection::iterator i;
311 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
314 midi_regions.erase (i);
317 MidiRegionsChanged ();
321 Selection::toggle (vector<RegionView*>& r)
323 clear_time(); //enforce object/range exclusivity
324 clear_tracks(); //enforce object/track exclusivity
326 RegionSelection::iterator i;
328 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
329 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
340 Selection::toggle (framepos_t start, framepos_t end)
342 clear_objects(); //enforce object/range exclusivity
344 AudioRangeComparator cmp;
346 /* XXX this implementation is incorrect */
348 time.push_back (AudioRange (start, end, ++next_time_id));
358 Selection::add (boost::shared_ptr<Playlist> pl)
361 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
362 clear_time(); //enforce object/range exclusivity
363 clear_tracks(); //enforce object/track exclusivity
365 playlists.push_back(pl);
371 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
373 bool changed = false;
375 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
376 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
378 playlists.push_back (*i);
384 clear_time(); //enforce object/range exclusivity
385 clear_tracks(); //enforce object/track exclusivity
391 Selection::add (const MidiNoteSelection& midi_list)
393 const MidiNoteSelection::const_iterator b = midi_list.begin();
394 const MidiNoteSelection::const_iterator e = midi_list.end();
396 if (!midi_list.empty()) {
397 clear_time(); //enforce object/range exclusivity
398 clear_tracks(); //enforce object/track exclusivity
399 midi_notes.insert (midi_notes.end(), b, e);
405 Selection::add (MidiCutBuffer* midi)
407 /* we take ownership of the MCB */
409 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
410 midi_notes.push_back (midi);
416 Selection::add (vector<RegionView*>& v)
418 /* XXX This method or the add (const RegionSelection&) needs to go
421 bool changed = false;
423 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
424 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
425 changed = regions.add ((*i));
430 clear_time(); //enforce object/range exclusivity
431 clear_tracks(); //enforce object/track exclusivity
437 Selection::add (const RegionSelection& rs)
439 /* XXX This method or the add (const vector<RegionView*>&) needs to go
442 bool changed = false;
444 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
445 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
446 changed = regions.add ((*i));
451 clear_time(); //enforce object/range exclusivity
452 clear_tracks(); //enforce object/track exclusivity
458 Selection::add (RegionView* r)
460 if (find (regions.begin(), regions.end(), r) == regions.end()) {
461 bool changed = regions.add (r);
463 clear_time(); //enforce object/range exclusivity
464 clear_tracks(); //enforce object/track exclusivity
471 Selection::add (MidiRegionView* mrv)
473 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
475 clear_time(); //enforce object/range exclusivity
476 clear_tracks(); //enforce object/track exclusivity
478 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
479 midi_regions.push_back (mrv);
480 /* XXX should we do this? */
481 MidiRegionsChanged ();
486 Selection::add (framepos_t start, framepos_t end)
488 clear_objects(); //enforce object/range exclusivity
490 AudioRangeComparator cmp;
492 /* XXX this implementation is incorrect */
494 time.push_back (AudioRange (start, end, ++next_time_id));
504 Selection::move_time (framecnt_t distance)
510 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
511 (*i).start += distance;
512 (*i).end += distance;
519 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
521 clear_objects(); //enforce object/range exclusivity
523 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
524 if ((*i).id == sid) {
526 time.push_back (AudioRange(start,end, sid));
528 /* don't consolidate here */
531 AudioRangeComparator cmp;
541 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
543 boost::shared_ptr<ARDOUR::AutomationList> al = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
546 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
551 clear_time(); //enforce object/range exclusivity
552 clear_tracks(); //enforce object/track exclusivity
555 /* The original may change so we must store a copy (not a pointer) here.
556 * e.g AutomationLine rewrites the list with gain mapping.
557 * the downside is that we can't perfom duplicate checks.
558 * This code was changed in response to #6842
560 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
565 Selection::remove (ControlPoint* p)
567 PointSelection::iterator i = find (points.begin(), points.end(), p);
568 if (i != points.end ()) {
574 Selection::remove (const MidiNoteSelection& midi_list)
576 bool changed = false;
578 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
580 MidiNoteSelection::iterator x;
582 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
583 midi_notes.erase (x);
594 Selection::remove (MidiCutBuffer* midi)
596 MidiNoteSelection::iterator x;
598 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
599 /* remember that we own the MCB */
601 midi_notes.erase (x);
607 Selection::remove (boost::shared_ptr<Playlist> track)
609 list<boost::shared_ptr<Playlist> >::iterator i;
610 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
617 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
619 bool changed = false;
621 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
623 list<boost::shared_ptr<Playlist> >::iterator x;
625 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
637 Selection::remove (RegionView* r)
639 if (regions.remove (r)) {
645 Selection::remove (MidiRegionView* mrv)
647 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
649 MidiRegionSelection::iterator x;
651 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
652 midi_regions.erase (x);
653 MidiRegionsChanged ();
658 Selection::remove (uint32_t selection_id)
664 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
665 if ((*i).id == selection_id) {
675 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
680 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
682 AutomationSelection::iterator i;
683 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
690 Selection::set (const MidiNoteSelection& midi_list)
692 if (!midi_list.empty()) {
693 clear_time (); //enforce region/object exclusivity
694 clear_tracks(); //enforce object/track exclusivity
701 Selection::set (boost::shared_ptr<Playlist> playlist)
704 clear_time (); //enforce region/object exclusivity
705 clear_tracks(); //enforce object/track exclusivity
712 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
714 if (!pllist.empty()) {
715 clear_time(); //enforce region/object exclusivity
722 Selection::set (const RegionSelection& rs)
725 clear_time(); //enforce region/object exclusivity
726 clear_tracks(); //enforce object/track exclusivity
730 RegionsChanged(); /* EMIT SIGNAL */
734 Selection::set (MidiRegionView* mrv)
737 clear_time(); //enforce region/object exclusivity
738 clear_tracks(); //enforce object/track exclusivity
745 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
748 clear_time(); //enforce region/object exclusivity
749 clear_tracks(); //enforce object/track exclusivity
756 Selection::set (vector<RegionView*>& v)
759 clear_time(); //enforce region/object exclusivity
760 clear_tracks(); //enforce object/track exclusivity
768 /** Set the start and end time of the time selection, without changing
769 * the list of tracks it applies to.
772 Selection::set (framepos_t start, framepos_t end)
774 clear_objects(); //enforce region/object exclusivity
777 if ((start == 0 && end == 0) || end < start) {
782 time.push_back (AudioRange (start, end, ++next_time_id));
784 /* reuse the first entry, and remove all the rest */
786 while (time.size() > 1) {
789 time.front().start = start;
790 time.front().end = end;
797 return time.front().id;
800 /** Set the start and end of the range selection. If more than one range
801 * is currently selected, the start of the earliest range and the end of the
802 * latest range are set. If no range is currently selected, this method
803 * selects a single range from start to end.
805 * @param start New start time.
806 * @param end New end time.
809 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
811 clear_objects(); //enforce region/object exclusivity
813 if ((start == 0 && end == 0) || (end < start)) {
818 time.push_back (AudioRange (start, end, ++next_time_id));
820 time.sort (AudioRangeComparator ());
821 time.front().start = start;
822 time.back().end = end;
831 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
833 clear_time(); //enforce region/object exclusivity
834 clear_tracks(); //enforce object/track exclusivity
841 Selection::selected (ArdourMarker* m) const
843 return find (markers.begin(), markers.end(), m) != markers.end();
847 Selection::selected (RegionView* rv) const
849 return find (regions.begin(), regions.end(), rv) != regions.end();
853 Selection::selected (ControlPoint* cp) const
855 return find (points.begin(), points.end(), cp) != points.end();
859 Selection::empty (bool internal_selection)
861 bool object_level_empty = regions.empty () &&
864 playlists.empty () &&
867 playlists.empty () &&
872 if (!internal_selection) {
873 return object_level_empty;
876 /* this is intended to really only apply when using a Selection
880 return object_level_empty && midi_notes.empty() && points.empty();
884 Selection::toggle (ControlPoint* cp)
886 clear_time(); //enforce region/object exclusivity
887 clear_tracks(); //enforce object/track exclusivity
889 cp->set_selected (!cp->selected ());
890 PointSelection::iterator i = find (points.begin(), points.end(), cp);
891 if (i == points.end()) {
892 points.push_back (cp);
897 PointsChanged (); /* EMIT SIGNAL */
901 Selection::toggle (vector<ControlPoint*> const & cps)
903 clear_time(); //enforce region/object exclusivity
904 clear_tracks(); //enforce object/track exclusivity
906 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
912 Selection::toggle (list<Selectable*> const & selectables)
914 clear_time(); //enforce region/object exclusivity
915 clear_tracks(); //enforce object/track exclusivity
919 vector<RegionView*> rvs;
920 vector<ControlPoint*> cps;
922 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
923 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
925 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
928 fatal << _("programming error: ")
929 << X_("unknown selectable type passed to Selection::toggle()")
931 abort(); /*NOTREACHED*/
945 Selection::set (list<Selectable*> const & selectables)
947 clear_time (); //enforce region/object exclusivity
948 clear_tracks(); //enforce object/track exclusivity
955 Selection::add (PointSelection const & s)
957 clear_time (); //enforce region/object exclusivity
958 clear_tracks(); //enforce object/track exclusivity
960 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
961 points.push_back (*i);
966 Selection::add (list<Selectable*> const & selectables)
968 clear_time (); //enforce region/object exclusivity
969 clear_tracks(); //enforce object/track exclusivity
973 vector<RegionView*> rvs;
974 vector<ControlPoint*> cps;
976 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
977 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
979 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
982 fatal << _("programming error: ")
983 << X_("unknown selectable type passed to Selection::add()")
985 abort(); /*NOTREACHED*/
999 Selection::clear_points (bool with_signal)
1001 if (!points.empty()) {
1010 Selection::add (ControlPoint* cp)
1012 clear_time (); //enforce region/object exclusivity
1013 clear_tracks(); //enforce object/track exclusivity
1015 cp->set_selected (true);
1016 points.push_back (cp);
1017 PointsChanged (); /* EMIT SIGNAL */
1021 Selection::add (vector<ControlPoint*> const & cps)
1023 clear_time (); //enforce region/object exclusivity
1024 clear_tracks(); //enforce object/track exclusivity
1026 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1027 (*i)->set_selected (true);
1028 points.push_back (*i);
1030 PointsChanged (); /* EMIT SIGNAL */
1034 Selection::set (ControlPoint* cp)
1036 clear_time (); //enforce region/object exclusivity
1037 clear_tracks(); //enforce object/track exclusivity
1039 if (cp->selected () && points.size () == 1) {
1043 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1044 cp->line().nth (i)->set_selected (false);
1052 Selection::set (ArdourMarker* m)
1054 clear_time (); //enforce region/object exclusivity
1055 clear_tracks(); //enforce object/track exclusivity
1062 Selection::toggle (ArdourMarker* m)
1064 MarkerSelection::iterator i;
1066 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1074 Selection::remove (ArdourMarker* m)
1076 MarkerSelection::iterator i;
1078 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1085 Selection::add (ArdourMarker* m)
1087 clear_time (); //enforce region/object exclusivity
1088 clear_tracks(); //enforce object/track exclusivity
1090 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1091 markers.push_back (m);
1097 Selection::add (const list<ArdourMarker*>& m)
1099 clear_time (); //enforce region/object exclusivity
1100 clear_tracks(); //enforce object/track exclusivity
1102 markers.insert (markers.end(), m.begin(), m.end());
1110 MarkerSelection::range (framepos_t& s, framepos_t& e)
1115 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1117 if ((*i)->position() < s) {
1118 s = (*i)->position();
1121 if ((*i)->position() > e) {
1122 e = (*i)->position();
1126 s = std::min (s, e);
1127 e = std::max (s, e);
1131 Selection::get_state () const
1133 /* XXX: not complete; just sufficient to get track selection state
1134 so that re-opening plugin windows for editor mixer strips works
1137 XMLNode* node = new XMLNode (X_("Selection"));
1139 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1140 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1141 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1143 XMLNode* t = node->add_child (X_("RouteView"));
1144 t->set_property (X_("id"), rtv->route()->id ());
1146 XMLNode* t = node->add_child (X_("AutomationView"));
1147 t->set_property (X_("id"), atv->parent_route()->id ());
1148 t->set_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1152 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1153 XMLNode* r = node->add_child (X_("Region"));
1154 r->set_property (X_("id"), (*i)->region ()->id ());
1157 /* midi region views have thir own internal selection. */
1158 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1159 editor->get_per_region_note_selection (rid_notes);
1161 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1162 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1163 XMLNode* n = node->add_child (X_("MIDINotes"));
1164 n->set_property (X_("region-id"), (*rn_it).first);
1166 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1167 XMLNode* nc = n->add_child(X_("note"));
1168 nc->set_property(X_("note-id"), (*i)->id());
1172 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1173 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1176 XMLNode* r = node->add_child (X_("ControlPoint"));
1177 r->set_property (X_("type"), "track");
1178 r->set_property (X_("route-id"), atv->parent_route()->id ());
1179 r->set_property (X_("automation-list-id"), (*i)->line().the_list()->id ());
1180 r->set_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1181 r->set_property (X_("view-index"), (*i)->view_index());
1185 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1187 XMLNode* r = node->add_child (X_("ControlPoint"));
1188 r->set_property (X_("type"), "region");
1189 r->set_property (X_("region-id"), argl->region_view ().region ()->id ());
1190 r->set_property (X_("view-index"), (*i)->view_index());
1195 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1196 XMLNode* t = node->add_child (X_("AudioRange"));
1197 t->set_property (X_("start"), (*i).start);
1198 t->set_property (X_("end"), (*i).end);
1201 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1202 XMLNode* t = node->add_child (X_("Marker"));
1205 Location* loc = editor->find_location_from_marker (*i, is_start);
1207 t->set_property (X_("id"), loc->id());
1208 t->set_property (X_("start"), is_start);
1215 Selection::set_state (XMLNode const & node, int)
1217 if (node.name() != X_("Selection")) {
1222 clear_midi_notes ();
1227 RegionSelection selected_regions;
1229 /* NOTE: stripable/time-axis-view selection is saved/restored by
1230 * ARDOUR::CoreSelection, not this Selection object
1234 XMLNodeList children = node.children ();
1236 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1237 if ((*i)->name() == X_("Region")) {
1239 if (!(*i)->get_property (X_("id"), id)) {
1244 editor->get_regionviews_by_id (id, rs);
1247 selected_regions.insert (selected_regions.end(), rs.begin(), rs.end());
1250 regionviews haven't been constructed - stash the region IDs
1251 so we can identify them in Editor::region_view_added ()
1253 regions.pending.push_back (id);
1256 } else if ((*i)->name() == X_("MIDINotes")) {
1258 if (!(*i)->get_property (X_("region-id"), id)) {
1264 editor->get_regionviews_by_id (id, rs); // there could be more than one
1266 std::list<Evoral::event_id_t> notes;
1267 XMLNodeList children = (*i)->children ();
1269 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1270 Evoral::event_id_t id;
1271 if ((*ci)->get_property (X_ ("note-id"), id)) {
1272 notes.push_back (id);
1276 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1277 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1279 mrv->select_notes(notes);
1284 /* regionviews containing these notes don't yet exist on the canvas.*/
1285 pending_midi_note_selection.push_back (make_pair (id, notes));
1288 } else if ((*i)->name() == X_("ControlPoint")) {
1289 XMLProperty const * prop_type = (*i)->property (X_("type"));
1293 if (prop_type->value () == "track") {
1298 uint32_t view_index;
1300 if (!(*i)->get_property (X_("route-id"), route_id) ||
1301 !(*i)->get_property (X_("automation-list-id"), alist_id) ||
1302 !(*i)->get_property (X_("parameter"), param) ||
1303 !(*i)->get_property (X_("view-index"), view_index)) {
1307 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1308 vector <ControlPoint *> cps;
1311 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1313 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1314 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1315 if ((*li)->the_list()->id() == alist_id) {
1316 ControlPoint* cp = (*li)->nth(view_index);
1328 } else if (prop_type->value () == "region") {
1331 uint32_t view_index;
1332 if (!(*i)->get_property (X_("region-id"), region_id) ||
1333 !(*i)->get_property (X_("view-index"), view_index)) {
1338 editor->get_regionviews_by_id (region_id, rs);
1341 vector <ControlPoint *> cps;
1342 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1343 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1345 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1346 ControlPoint* cp = gl->nth(view_index);
1359 } else if ((*i)->name() == X_("AudioRange")) {
1363 if (!(*i)->get_property (X_("start"), start) || !(*i)->get_property (X_("end"), end)) {
1366 set_preserving_all_ranges (start, end);
1368 } else if ((*i)->name() == X_("AutomationView")) {
1372 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("parameter"), param)) {
1376 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1379 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1381 /* the automation could be for an entity that was never saved
1382 in the session file. Don't freak out if we can't find
1391 } else if ((*i)->name() == X_("Marker")) {
1394 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("start"), is_start)) {
1398 ArdourMarker* m = editor->find_marker_from_location_id (id, is_start);
1407 // now add regions to selection at once
1408 add (selected_regions);
1414 Selection::remove_regions (TimeAxisView* t)
1416 RegionSelection::iterator i = regions.begin();
1417 while (i != regions.end ()) {
1418 RegionSelection::iterator tmp = i;
1421 if (&(*i)->get_time_axis_view() == t) {
1429 /* TIME AXIS VIEW ... proxy for Stripable/Controllable
1431 * public methods just modify the CoreSelection; PresentationInfo::Changed will
1432 * trigger Selection::core_selection_changed() and we will update our own data
1437 Selection::toggle (const TrackViewList& track_list)
1439 TrackViewList t = add_grouped_tracks (track_list);
1441 CoreSelection& selection (editor->session()->selection());
1442 PresentationInfo::ChangeSuspender cs;
1444 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1445 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1446 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1447 selection.toggle (s, c);
1452 Selection::toggle (TimeAxisView* track)
1454 if (dynamic_cast<VCATimeAxisView*> (track)) {
1459 tr.push_back (track);
1464 Selection::add (TrackViewList const & track_list)
1466 TrackViewList t = add_grouped_tracks (track_list);
1468 CoreSelection& selection (editor->session()->selection());
1469 PresentationInfo::ChangeSuspender cs;
1471 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1472 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1473 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1474 selection.add (s, c);
1479 Selection::add (TimeAxisView* track)
1481 if (dynamic_cast<VCATimeAxisView*> (track)) {
1486 tr.push_back (track);
1491 Selection::remove (TimeAxisView* track)
1493 if (dynamic_cast<VCATimeAxisView*> (track)) {
1498 tvl.push_back (track);
1503 Selection::remove (const TrackViewList& t)
1505 CoreSelection& selection (editor->session()->selection());
1506 PresentationInfo::ChangeSuspender cs;
1508 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1509 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1510 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1511 selection.remove (s, c);
1516 Selection::set (TimeAxisView* track)
1518 if (dynamic_cast<VCATimeAxisView*> (track)) {
1523 tvl.push_back (track);
1528 Selection::set (const TrackViewList& track_list)
1530 TrackViewList t = add_grouped_tracks (track_list);
1532 CoreSelection& selection (editor->session()->selection());
1533 PresentationInfo::ChangeSuspender cs;
1535 selection.clear_stripables ();
1537 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1538 boost::shared_ptr<Stripable> s = (*i)->stripable ();
1539 boost::shared_ptr<AutomationControl> c = (*i)->control ();
1540 selection.add (s, c);
1545 Selection::clear_tracks (bool)
1547 Session* s = editor->session();
1549 CoreSelection& selection (s->selection());
1550 selection.clear_stripables ();
1555 Selection::selected (TimeAxisView* tv) const
1557 Session* session = editor->session();
1563 CoreSelection& selection (session->selection());
1564 boost::shared_ptr<Stripable> s = tv->stripable ();
1565 boost::shared_ptr<AutomationControl> c = tv->control ();
1568 return selection.selected (c);
1571 return selection.selected (s);
1575 Selection::add_grouped_tracks (TrackViewList const & t)
1577 TrackViewList added;
1579 for (TrackSelection::const_iterator i = t.begin(); i != t.end(); ++i) {
1580 if (dynamic_cast<VCATimeAxisView*> (*i)) {
1584 /* select anything in the same select-enabled route group */
1585 ARDOUR::RouteGroup* rg = (*i)->route_group ();
1587 if (rg && rg->is_active() && rg->is_select ()) {
1589 TrackViewList tr = editor->axis_views_from_routes (rg->route_list ());
1591 for (TrackViewList::iterator j = tr.begin(); j != tr.end(); ++j) {
1593 /* Do not add the trackview passed in as an
1594 * argument, because we want that to be on the
1599 if (!added.contains (*j)) {
1600 added.push_back (*j);
1607 /* now add the the trackview's passed in as actual arguments */
1608 added.insert (added.end(), t.begin(), t.end());
1614 static void dump_tracks (Selection const & s)
1616 cerr << "--TRACKS [" << s.tracks.size() << ']' << ":\n";
1617 for (TrackViewList::const_iterator x = s.tracks.begin(); x != s.tracks.end(); ++x) {
1618 cerr << (*x)->name() << ' ' << (*x)->stripable() << " C = " << (*x)->control() << endl;
1625 Selection::core_selection_changed (PropertyChange const & what_changed)
1629 pc.add (Properties::selected);
1631 if (!what_changed.contains (pc)) {
1635 CoreSelection& selection (editor->session()->selection());
1637 if (selection.selected()) {
1638 clear_objects(); // enforce object/range exclusivity
1641 tracks.clear (); // clear stage for whatever tracks are now selected (maybe none)
1643 CoreSelection::StripableAutomationControls sac;
1644 selection.get_stripables (sac);
1646 for (CoreSelection::StripableAutomationControls::const_iterator i = sac.begin(); i != sac.end(); ++i) {
1649 if ((*i).controllable) {
1650 av = editor->axis_view_by_control ((*i).controllable);
1652 av = editor->axis_view_by_stripable ((*i).stripable);
1655 tav = dynamic_cast<TimeAxisView*>(av);
1657 tracks.push_back (tav);