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/playlist.h"
28 #include "ardour/rc_configuration.h"
29 #include "ardour/evoral_types_convert.h"
31 #include "control_protocol/control_protocol.h"
33 #include "audio_region_view.h"
35 #include "gui_thread.h"
36 #include "midi_cut_buffer.h"
37 #include "region_gain_line.h"
38 #include "region_view.h"
39 #include "selection.h"
40 #include "selection_templates.h"
41 #include "time_axis_view.h"
42 #include "automation_time_axis.h"
43 #include "public_editor.h"
44 #include "control_point.h"
45 #include "vca_time_axis.h"
50 using namespace ARDOUR;
53 struct AudioRangeComparator {
54 bool operator()(AudioRange a, AudioRange b) {
55 return a.start < b.start;
59 Selection::Selection (const PublicEditor* e)
66 /* we have disambiguate which remove() for the compiler */
68 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
69 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
71 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
72 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
74 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
75 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
80 Selection::operator= (const Selection& other)
83 regions = other.regions;
84 tracks = other.tracks;
87 midi_regions = other.midi_regions;
88 midi_notes = other.midi_notes;
95 operator== (const Selection& a, const Selection& b)
97 return a.regions == b.regions &&
98 a.tracks == b.tracks &&
100 a.lines == b.lines &&
101 a.playlists == b.playlists &&
102 a.midi_notes == b.midi_notes &&
103 a.midi_regions == b.midi_regions;
106 /** Clear everything from the Selection */
117 clear_midi_regions ();
119 pending_midi_note_selection.clear();
123 Selection::clear_objects (bool with_signal)
125 clear_regions (with_signal);
126 clear_points (with_signal);
127 clear_lines(with_signal);
128 clear_playlists (with_signal);
129 clear_midi_notes (with_signal);
130 clear_midi_regions (with_signal);
134 Selection::clear_tracks (bool with_signal)
136 if (!tracks.empty()) {
137 PresentationInfo::ChangeSuspender cs;
139 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
140 (*x)->set_selected (false);
148 Selection::clear_time (bool with_signal)
157 Selection::dump_region_layers()
159 cerr << "region selection layer dump" << endl;
160 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
161 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
167 Selection::clear_regions (bool with_signal)
169 if (!regions.empty()) {
170 regions.clear_all ();
178 Selection::clear_midi_notes (bool with_signal)
180 if (!midi_notes.empty()) {
181 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
190 // clear note selections for MRV's that have note selections
191 // this will cause the MRV to be removed from the list
192 for (MidiRegionSelection::iterator i = midi_regions.begin();
193 i != midi_regions.end();) {
194 MidiRegionSelection::iterator tmp = i;
196 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
198 mrv->clear_selection();
205 Selection::clear_midi_regions (bool with_signal)
207 if (!midi_regions.empty()) {
208 midi_regions.clear ();
210 MidiRegionsChanged ();
216 Selection::clear_playlists (bool with_signal)
218 /* Selections own their playlists */
220 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
221 /* selections own their own regions, which are copies of the "originals". make them go away */
222 (*i)->drop_regions ();
226 if (!playlists.empty()) {
235 Selection::clear_lines (bool with_signal)
237 if (!lines.empty()) {
246 Selection::clear_markers (bool with_signal)
248 if (!markers.empty()) {
257 Selection::toggle (boost::shared_ptr<Playlist> pl)
259 clear_time(); //enforce object/range exclusivity
260 clear_tracks(); //enforce object/track exclusivity
262 PlaylistSelection::iterator i;
264 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
266 playlists.push_back(pl);
275 Selection::toggle (const TrackViewList& track_list)
277 PresentationInfo::ChangeSuspender cs;
279 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
280 if (dynamic_cast<VCATimeAxisView*> (*i)) {
288 Selection::toggle (TimeAxisView* track)
290 if (dynamic_cast<VCATimeAxisView*> (track)) {
294 TrackSelection::iterator i;
296 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
297 tracks.push_back (track);
298 track->set_selected (true);
301 track->set_selected (false);
307 Selection::toggle (const MidiNoteSelection& midi_note_list)
309 clear_time(); //enforce object/range exclusivity
310 clear_tracks(); //enforce object/track exclusivity
312 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
318 Selection::toggle (MidiCutBuffer* midi)
320 MidiNoteSelection::iterator i;
322 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
323 midi_notes.push_back (midi);
325 /* remember that we own the MCB */
327 midi_notes.erase (i);
335 Selection::toggle (RegionView* r)
337 clear_time(); //enforce object/range exclusivity
338 clear_tracks(); //enforce object/track exclusivity
340 RegionSelection::iterator i;
342 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
352 Selection::toggle (MidiRegionView* mrv)
354 clear_time(); //enforce object/range exclusivity
355 clear_tracks(); //enforce object/track exclusivity
357 MidiRegionSelection::iterator i;
359 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
362 midi_regions.erase (i);
365 MidiRegionsChanged ();
369 Selection::toggle (vector<RegionView*>& r)
371 clear_time(); //enforce object/range exclusivity
372 clear_tracks(); //enforce object/track exclusivity
374 RegionSelection::iterator i;
376 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
377 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
388 Selection::toggle (framepos_t start, framepos_t end)
390 clear_objects(); //enforce object/range exclusivity
392 AudioRangeComparator cmp;
394 /* XXX this implementation is incorrect */
396 time.push_back (AudioRange (start, end, ++next_time_id));
406 Selection::add (boost::shared_ptr<Playlist> pl)
408 clear_time(); //enforce object/range exclusivity
409 clear_tracks(); //enforce object/track exclusivity
411 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
413 playlists.push_back(pl);
419 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
421 clear_time(); //enforce object/range exclusivity
422 clear_tracks(); //enforce object/track exclusivity
424 bool changed = false;
426 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
427 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
429 playlists.push_back (*i);
440 Selection::add (TrackViewList const & track_list)
442 clear_objects(); //enforce object/range exclusivity
444 PresentationInfo::ChangeSuspender cs;
446 TrackViewList added = tracks.add (track_list);
448 if (!added.empty()) {
449 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
450 if (dynamic_cast<VCATimeAxisView*> (*x)) {
453 (*x)->set_selected (true);
459 Selection::add (TimeAxisView* track)
461 if (dynamic_cast<VCATimeAxisView*> (track)) {
466 tr.push_back (track);
471 Selection::add (const MidiNoteSelection& midi_list)
473 clear_time(); //enforce object/range exclusivity
474 clear_tracks(); //enforce object/track exclusivity
476 const MidiNoteSelection::const_iterator b = midi_list.begin();
477 const MidiNoteSelection::const_iterator e = midi_list.end();
479 if (!midi_list.empty()) {
480 midi_notes.insert (midi_notes.end(), b, e);
486 Selection::add (MidiCutBuffer* midi)
488 /* we take ownership of the MCB */
490 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
491 midi_notes.push_back (midi);
497 Selection::add (vector<RegionView*>& v)
499 clear_time(); //enforce object/range exclusivity
500 clear_tracks(); //enforce object/track exclusivity
502 /* XXX This method or the add (const RegionSelection&) needs to go
505 bool changed = false;
507 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
508 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
509 changed = regions.add ((*i));
519 Selection::add (const RegionSelection& rs)
521 clear_time(); //enforce object/range exclusivity
522 clear_tracks(); //enforce object/track exclusivity
524 /* XXX This method or the add (const vector<RegionView*>&) needs to go
527 bool changed = false;
529 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
530 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
531 changed = regions.add ((*i));
541 Selection::add (RegionView* r)
543 clear_time(); //enforce object/range exclusivity
544 clear_tracks(); //enforce object/track exclusivity
546 if (find (regions.begin(), regions.end(), r) == regions.end()) {
547 bool changed = regions.add (r);
555 Selection::add (MidiRegionView* mrv)
557 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
559 clear_time(); //enforce object/range exclusivity
560 clear_tracks(); //enforce object/track exclusivity
562 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
563 midi_regions.push_back (mrv);
564 /* XXX should we do this? */
565 MidiRegionsChanged ();
570 Selection::add (framepos_t start, framepos_t end)
572 clear_objects(); //enforce object/range exclusivity
574 AudioRangeComparator cmp;
576 /* XXX this implementation is incorrect */
578 time.push_back (AudioRange (start, end, ++next_time_id));
588 Selection::move_time (framecnt_t distance)
594 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
595 (*i).start += distance;
596 (*i).end += distance;
603 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
605 clear_objects(); //enforce object/range exclusivity
607 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
608 if ((*i).id == sid) {
610 time.push_back (AudioRange(start,end, sid));
612 /* don't consolidate here */
615 AudioRangeComparator cmp;
625 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
627 clear_time(); //enforce object/range exclusivity
628 clear_tracks(); //enforce object/track exclusivity
630 boost::shared_ptr<ARDOUR::AutomationList> al
631 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
633 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
637 /* The original may change so we must store a copy (not a pointer) here.
638 * e.g AutomationLine rewrites the list with gain mapping.
639 * the downside is that we can't perfom duplicate checks.
640 * This code was changed in response to #6842
642 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
647 Selection::remove (TimeAxisView* track)
649 list<TimeAxisView*>::iterator i;
650 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
651 /* erase first, because set_selected() will remove the track
652 from the selection, invalidating the iterator.
654 In fact, we don't really even need to do the erase, but this is
655 a hangover of axis view selection being in the GUI.
658 track->set_selected (false);
663 Selection::remove (const TrackViewList& track_list)
665 PresentationInfo::ChangeSuspender cs;
667 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
669 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
671 if (x != tracks.end()) {
673 (*i)->set_selected (false);
679 Selection::remove (ControlPoint* p)
681 PointSelection::iterator i = find (points.begin(), points.end(), p);
682 if (i != points.end ()) {
688 Selection::remove (const MidiNoteSelection& midi_list)
690 bool changed = false;
692 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
694 MidiNoteSelection::iterator x;
696 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
697 midi_notes.erase (x);
708 Selection::remove (MidiCutBuffer* midi)
710 MidiNoteSelection::iterator x;
712 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
713 /* remember that we own the MCB */
715 midi_notes.erase (x);
721 Selection::remove (boost::shared_ptr<Playlist> track)
723 list<boost::shared_ptr<Playlist> >::iterator i;
724 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
731 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
733 bool changed = false;
735 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
737 list<boost::shared_ptr<Playlist> >::iterator x;
739 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
751 Selection::remove (RegionView* r)
753 if (regions.remove (r)) {
759 Selection::remove (MidiRegionView* mrv)
761 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
763 MidiRegionSelection::iterator x;
765 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
766 midi_regions.erase (x);
767 MidiRegionsChanged ();
772 Selection::remove (uint32_t selection_id)
778 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
779 if ((*i).id == selection_id) {
789 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
794 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
796 AutomationSelection::iterator i;
797 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
804 Selection::set (TimeAxisView* track)
806 if (dynamic_cast<VCATimeAxisView*> (track)) {
809 clear_objects (); //enforce object/range exclusivity
811 PresentationInfo::ChangeSuspender cs;
813 if (!tracks.empty()) {
815 if (tracks.size() == 1 && tracks.front() == track) {
816 /* already single selection: nothing to do */
820 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
821 (*x)->set_selected (false);
831 Selection::set (const TrackViewList& track_list)
833 clear_objects(); //enforce object/range exclusivity
836 TrackViewList to_be_added;
837 TrackViewList to_be_removed;
839 for (TrackViewList::const_iterator x = tracks.begin(); x != tracks.end(); ++x) {
840 if (find (track_list.begin(), track_list.end(), *x) == track_list.end()) {
841 to_be_removed.push_back (*x);
845 for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
846 if (dynamic_cast<VCATimeAxisView*> (*x)) {
849 if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) {
850 to_be_added.push_back (*x);
854 PresentationInfo::ChangeSuspender cs;
855 remove (to_be_removed);
861 Selection::set (const MidiNoteSelection& midi_list)
863 clear_time (); //enforce region/object exclusivity
864 clear_tracks(); //enforce object/track exclusivity
870 Selection::set (boost::shared_ptr<Playlist> playlist)
872 clear_time (); //enforce region/object exclusivity
873 clear_tracks(); //enforce object/track exclusivity
879 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
881 clear_time(); //enforce region/object exclusivity
887 Selection::set (const RegionSelection& rs)
889 clear_time(); //enforce region/object exclusivity
890 clear_tracks(); //enforce object/track exclusivity
893 RegionsChanged(); /* EMIT SIGNAL */
897 Selection::set (MidiRegionView* mrv)
899 clear_time(); //enforce region/object exclusivity
900 clear_tracks(); //enforce object/track exclusivity
906 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
908 clear_time(); //enforce region/object exclusivity
909 clear_tracks(); //enforce object/track exclusivity
915 Selection::set (vector<RegionView*>& v)
917 clear_time(); //enforce region/object exclusivity
918 clear_tracks(); //enforce object/track exclusivity
924 /** Set the start and end time of the time selection, without changing
925 * the list of tracks it applies to.
928 Selection::set (framepos_t start, framepos_t end)
930 clear_objects(); //enforce region/object exclusivity
933 if ((start == 0 && end == 0) || end < start) {
938 time.push_back (AudioRange (start, end, ++next_time_id));
940 /* reuse the first entry, and remove all the rest */
942 while (time.size() > 1) {
945 time.front().start = start;
946 time.front().end = end;
953 return time.front().id;
956 /** Set the start and end of the range selection. If more than one range
957 * is currently selected, the start of the earliest range and the end of the
958 * latest range are set. If no range is currently selected, this method
959 * selects a single range from start to end.
961 * @param start New start time.
962 * @param end New end time.
965 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
967 clear_objects(); //enforce region/object exclusivity
969 if ((start == 0 && end == 0) || (end < start)) {
974 time.push_back (AudioRange (start, end, ++next_time_id));
976 time.sort (AudioRangeComparator ());
977 time.front().start = start;
978 time.back().end = end;
987 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
989 clear_time(); //enforce region/object exclusivity
990 clear_tracks(); //enforce object/track exclusivity
997 Selection::selected (ArdourMarker* m) const
999 return find (markers.begin(), markers.end(), m) != markers.end();
1003 Selection::selected (TimeAxisView* tv) const
1005 return tv->selected ();
1009 Selection::selected (RegionView* rv) const
1011 return find (regions.begin(), regions.end(), rv) != regions.end();
1015 Selection::selected (ControlPoint* cp) const
1017 return find (points.begin(), points.end(), cp) != points.end();
1021 Selection::empty (bool internal_selection)
1023 bool object_level_empty = regions.empty () &&
1026 playlists.empty () &&
1029 playlists.empty () &&
1031 midi_regions.empty()
1034 if (!internal_selection) {
1035 return object_level_empty;
1038 /* this is intended to really only apply when using a Selection
1042 return object_level_empty && midi_notes.empty() && points.empty();
1046 Selection::toggle (ControlPoint* cp)
1048 clear_time(); //enforce region/object exclusivity
1049 clear_tracks(); //enforce object/track exclusivity
1051 cp->set_selected (!cp->selected ());
1052 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1053 if (i == points.end()) {
1054 points.push_back (cp);
1059 PointsChanged (); /* EMIT SIGNAL */
1063 Selection::toggle (vector<ControlPoint*> const & cps)
1065 clear_time(); //enforce region/object exclusivity
1066 clear_tracks(); //enforce object/track exclusivity
1068 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1074 Selection::toggle (list<Selectable*> const & selectables)
1076 clear_time(); //enforce region/object exclusivity
1077 clear_tracks(); //enforce object/track exclusivity
1081 vector<RegionView*> rvs;
1082 vector<ControlPoint*> cps;
1084 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1085 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1087 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1090 fatal << _("programming error: ")
1091 << X_("unknown selectable type passed to Selection::toggle()")
1093 abort(); /*NOTREACHED*/
1107 Selection::set (list<Selectable*> const & selectables)
1109 clear_time (); //enforce region/object exclusivity
1110 clear_tracks(); //enforce object/track exclusivity
1117 Selection::add (PointSelection const & s)
1119 clear_time (); //enforce region/object exclusivity
1120 clear_tracks(); //enforce object/track exclusivity
1122 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1123 points.push_back (*i);
1128 Selection::add (list<Selectable*> const & selectables)
1130 clear_time (); //enforce region/object exclusivity
1131 clear_tracks(); //enforce object/track exclusivity
1135 vector<RegionView*> rvs;
1136 vector<ControlPoint*> cps;
1138 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1139 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1141 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1144 fatal << _("programming error: ")
1145 << X_("unknown selectable type passed to Selection::add()")
1147 abort(); /*NOTREACHED*/
1161 Selection::clear_points (bool with_signal)
1163 if (!points.empty()) {
1172 Selection::add (ControlPoint* cp)
1174 clear_time (); //enforce region/object exclusivity
1175 clear_tracks(); //enforce object/track exclusivity
1177 cp->set_selected (true);
1178 points.push_back (cp);
1179 PointsChanged (); /* EMIT SIGNAL */
1183 Selection::add (vector<ControlPoint*> const & cps)
1185 clear_time (); //enforce region/object exclusivity
1186 clear_tracks(); //enforce object/track exclusivity
1188 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1189 (*i)->set_selected (true);
1190 points.push_back (*i);
1192 PointsChanged (); /* EMIT SIGNAL */
1196 Selection::set (ControlPoint* cp)
1198 clear_time (); //enforce region/object exclusivity
1199 clear_tracks(); //enforce object/track exclusivity
1201 if (cp->selected () && points.size () == 1) {
1205 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1206 cp->line().nth (i)->set_selected (false);
1214 Selection::set (ArdourMarker* m)
1216 clear_time (); //enforce region/object exclusivity
1217 clear_tracks(); //enforce object/track exclusivity
1224 Selection::toggle (ArdourMarker* m)
1226 MarkerSelection::iterator i;
1228 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1236 Selection::remove (ArdourMarker* m)
1238 MarkerSelection::iterator i;
1240 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1247 Selection::add (ArdourMarker* m)
1249 clear_time (); //enforce region/object exclusivity
1250 clear_tracks(); //enforce object/track exclusivity
1252 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1253 markers.push_back (m);
1259 Selection::add (const list<ArdourMarker*>& m)
1261 clear_time (); //enforce region/object exclusivity
1262 clear_tracks(); //enforce object/track exclusivity
1264 markers.insert (markers.end(), m.begin(), m.end());
1272 MarkerSelection::range (framepos_t& s, framepos_t& e)
1277 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1279 if ((*i)->position() < s) {
1280 s = (*i)->position();
1283 if ((*i)->position() > e) {
1284 e = (*i)->position();
1288 s = std::min (s, e);
1289 e = std::max (s, e);
1293 Selection::get_state () const
1295 /* XXX: not complete; just sufficient to get track selection state
1296 so that re-opening plugin windows for editor mixer strips works
1299 XMLNode* node = new XMLNode (X_("Selection"));
1301 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1302 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1303 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1305 XMLNode* t = node->add_child (X_("RouteView"));
1306 t->set_property (X_("id"), rtv->route()->id ());
1308 XMLNode* t = node->add_child (X_("AutomationView"));
1309 t->set_property (X_("id"), atv->parent_route()->id ());
1310 t->set_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1314 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1315 XMLNode* r = node->add_child (X_("Region"));
1316 r->set_property (X_("id"), (*i)->region ()->id ());
1319 /* midi region views have thir own internal selection. */
1320 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1321 editor->get_per_region_note_selection (rid_notes);
1323 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1324 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1325 XMLNode* n = node->add_child (X_("MIDINotes"));
1326 n->set_property (X_("region-id"), (*rn_it).first);
1328 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1329 XMLNode* nc = n->add_child(X_("note"));
1330 nc->set_property(X_("note-id"), (*i)->id());
1334 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1335 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1338 XMLNode* r = node->add_child (X_("ControlPoint"));
1339 r->set_property (X_("type"), "track");
1340 r->set_property (X_("route-id"), atv->parent_route()->id ());
1341 r->set_property (X_("automation-list-id"), (*i)->line().the_list()->id ());
1342 r->set_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1343 r->set_property (X_("view-index"), (*i)->view_index());
1347 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1349 XMLNode* r = node->add_child (X_("ControlPoint"));
1350 r->set_property (X_("type"), "region");
1351 r->set_property (X_("region-id"), argl->region_view ().region ()->id ());
1352 r->set_property (X_("view-index"), (*i)->view_index());
1357 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1358 XMLNode* t = node->add_child (X_("AudioRange"));
1359 t->set_property (X_("start"), (*i).start);
1360 t->set_property (X_("end"), (*i).end);
1363 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1364 XMLNode* t = node->add_child (X_("Marker"));
1367 Location* loc = editor->find_location_from_marker (*i, is_start);
1369 t->set_property (X_("id"), loc->id());
1370 t->set_property (X_("start"), is_start);
1377 Selection::set_state (XMLNode const & node, int)
1379 if (node.name() != X_("Selection")) {
1384 clear_midi_notes ();
1391 XMLNodeList children = node.children ();
1392 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1393 if ((*i)->name() == X_("RouteView")) {
1395 if (!(*i)->get_property (X_("id"), id)) {
1396 assert(false); // handle this more gracefully?
1399 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1404 } else if ((*i)->name() == X_("Region")) {
1406 if (!(*i)->get_property (X_("id"), id)) {
1411 editor->get_regionviews_by_id (id, rs);
1417 regionviews haven't been constructed - stash the region IDs
1418 so we can identify them in Editor::region_view_added ()
1420 regions.pending.push_back (id);
1423 } else if ((*i)->name() == X_("MIDINotes")) {
1425 if (!(*i)->get_property (X_("region-id"), id)) {
1431 editor->get_regionviews_by_id (id, rs); // there could be more than one
1433 std::list<Evoral::event_id_t> notes;
1434 XMLNodeList children = (*i)->children ();
1436 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1437 Evoral::event_id_t id;
1438 if ((*ci)->get_property (X_ ("note-id"), id)) {
1439 notes.push_back (id);
1443 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1444 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1446 mrv->select_notes(notes);
1451 /* regionviews containing these notes don't yet exist on the canvas.*/
1452 pending_midi_note_selection.push_back (make_pair (id, notes));
1455 } else if ((*i)->name() == X_("ControlPoint")) {
1456 XMLProperty const * prop_type = (*i)->property (X_("type"));
1460 if (prop_type->value () == "track") {
1465 uint32_t view_index;
1467 if (!(*i)->get_property (X_("route-id"), route_id) ||
1468 !(*i)->get_property (X_("automation-list-id"), alist_id) ||
1469 !(*i)->get_property (X_("parameter"), param) ||
1470 !(*i)->get_property (X_("view-index"), view_index)) {
1474 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1475 vector <ControlPoint *> cps;
1478 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1480 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1481 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1482 if ((*li)->the_list()->id() == alist_id) {
1483 ControlPoint* cp = (*li)->nth(view_index);
1495 } else if (prop_type->value () == "region") {
1498 uint32_t view_index;
1499 if (!(*i)->get_property (X_("region-id"), region_id) ||
1500 !(*i)->get_property (X_("view-index"), view_index)) {
1505 editor->get_regionviews_by_id (region_id, rs);
1508 vector <ControlPoint *> cps;
1509 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1510 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1512 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1513 ControlPoint* cp = gl->nth(view_index);
1526 } else if ((*i)->name() == X_("AudioRange")) {
1530 if (!(*i)->get_property (X_("start"), start) || !(*i)->get_property (X_("end"), end)) {
1533 set_preserving_all_ranges (start, end);
1535 } else if ((*i)->name() == X_("AutomationView")) {
1539 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("parameter"), param)) {
1543 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1546 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (param));
1548 /* the automation could be for an entity that was never saved
1549 in the session file. Don't freak out if we can't find
1558 } else if ((*i)->name() == X_("Marker")) {
1561 if (!(*i)->get_property (X_("id"), id) || !(*i)->get_property (X_("start"), is_start)) {
1565 ArdourMarker* m = editor->find_marker_from_location_id (id, is_start);
1578 Selection::remove_regions (TimeAxisView* t)
1580 RegionSelection::iterator i = regions.begin();
1581 while (i != regions.end ()) {
1582 RegionSelection::iterator tmp = i;
1585 if (&(*i)->get_time_axis_view() == t) {