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"
26 #include "ardour/playlist.h"
27 #include "ardour/rc_configuration.h"
29 #include "control_protocol/control_protocol.h"
31 #include "audio_region_view.h"
33 #include "gui_thread.h"
34 #include "midi_cut_buffer.h"
35 #include "region_gain_line.h"
36 #include "region_view.h"
37 #include "selection.h"
38 #include "selection_templates.h"
39 #include "time_axis_view.h"
40 #include "automation_time_axis.h"
41 #include "public_editor.h"
42 #include "control_point.h"
43 #include "vca_time_axis.h"
48 using namespace ARDOUR;
51 struct AudioRangeComparator {
52 bool operator()(AudioRange a, AudioRange b) {
53 return a.start < b.start;
57 Selection::Selection (const PublicEditor* e)
64 /* we have disambiguate which remove() for the compiler */
66 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
67 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
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_tracks (bool with_signal)
134 if (!tracks.empty()) {
135 PresentationInfo::ChangeSuspender cs;
137 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
138 (*x)->set_selected (false);
146 Selection::clear_time (bool with_signal)
155 Selection::dump_region_layers()
157 cerr << "region selection layer dump" << endl;
158 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
159 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
165 Selection::clear_regions (bool with_signal)
167 if (!regions.empty()) {
168 regions.clear_all ();
176 Selection::clear_midi_notes (bool with_signal)
178 if (!midi_notes.empty()) {
179 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
188 // clear note selections for MRV's that have note selections
189 // this will cause the MRV to be removed from the list
190 for (MidiRegionSelection::iterator i = midi_regions.begin();
191 i != midi_regions.end();) {
192 MidiRegionSelection::iterator tmp = i;
194 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
196 mrv->clear_selection();
203 Selection::clear_midi_regions (bool with_signal)
205 if (!midi_regions.empty()) {
206 midi_regions.clear ();
208 MidiRegionsChanged ();
214 Selection::clear_playlists (bool with_signal)
216 /* Selections own their playlists */
218 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
219 /* selections own their own regions, which are copies of the "originals". make them go away */
220 (*i)->drop_regions ();
224 if (!playlists.empty()) {
233 Selection::clear_lines (bool with_signal)
235 if (!lines.empty()) {
244 Selection::clear_markers (bool with_signal)
246 if (!markers.empty()) {
255 Selection::toggle (boost::shared_ptr<Playlist> pl)
257 clear_time(); //enforce object/range exclusivity
258 clear_tracks(); //enforce object/track exclusivity
260 PlaylistSelection::iterator i;
262 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
264 playlists.push_back(pl);
273 Selection::toggle (const TrackViewList& track_list)
275 PresentationInfo::ChangeSuspender cs;
277 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
278 if (dynamic_cast<VCATimeAxisView*> (*i)) {
286 Selection::toggle (TimeAxisView* track)
288 if (dynamic_cast<VCATimeAxisView*> (track)) {
292 TrackSelection::iterator i;
294 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
295 tracks.push_back (track);
296 track->set_selected (true);
299 track->set_selected (false);
305 Selection::toggle (const MidiNoteSelection& midi_note_list)
307 clear_time(); //enforce object/range exclusivity
308 clear_tracks(); //enforce object/track exclusivity
310 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
316 Selection::toggle (MidiCutBuffer* midi)
318 MidiNoteSelection::iterator i;
320 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
321 midi_notes.push_back (midi);
323 /* remember that we own the MCB */
325 midi_notes.erase (i);
333 Selection::toggle (RegionView* r)
335 clear_time(); //enforce object/range exclusivity
336 clear_tracks(); //enforce object/track exclusivity
338 RegionSelection::iterator i;
340 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
350 Selection::toggle (MidiRegionView* mrv)
352 clear_time(); //enforce object/range exclusivity
353 clear_tracks(); //enforce object/track exclusivity
355 MidiRegionSelection::iterator i;
357 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
360 midi_regions.erase (i);
363 MidiRegionsChanged ();
367 Selection::toggle (vector<RegionView*>& r)
369 clear_time(); //enforce object/range exclusivity
370 clear_tracks(); //enforce object/track exclusivity
372 RegionSelection::iterator i;
374 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
375 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
386 Selection::toggle (framepos_t start, framepos_t end)
388 clear_objects(); //enforce object/range exclusivity
390 AudioRangeComparator cmp;
392 /* XXX this implementation is incorrect */
394 time.push_back (AudioRange (start, end, ++next_time_id));
404 Selection::add (boost::shared_ptr<Playlist> pl)
406 clear_time(); //enforce object/range exclusivity
407 clear_tracks(); //enforce object/track exclusivity
409 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
411 playlists.push_back(pl);
417 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
419 clear_time(); //enforce object/range exclusivity
420 clear_tracks(); //enforce object/track exclusivity
422 bool changed = false;
424 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
425 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
427 playlists.push_back (*i);
438 Selection::add (TrackViewList const & track_list)
440 clear_objects(); //enforce object/range exclusivity
442 PresentationInfo::ChangeSuspender cs;
444 TrackViewList added = tracks.add (track_list);
446 if (!added.empty()) {
447 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
448 if (dynamic_cast<VCATimeAxisView*> (*x)) {
451 (*x)->set_selected (true);
457 Selection::add (TimeAxisView* track)
459 if (dynamic_cast<VCATimeAxisView*> (track)) {
464 tr.push_back (track);
469 Selection::add (const MidiNoteSelection& midi_list)
471 clear_time(); //enforce object/range exclusivity
472 clear_tracks(); //enforce object/track exclusivity
474 const MidiNoteSelection::const_iterator b = midi_list.begin();
475 const MidiNoteSelection::const_iterator e = midi_list.end();
477 if (!midi_list.empty()) {
478 midi_notes.insert (midi_notes.end(), b, e);
484 Selection::add (MidiCutBuffer* midi)
486 /* we take ownership of the MCB */
488 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
489 midi_notes.push_back (midi);
495 Selection::add (vector<RegionView*>& v)
497 clear_time(); //enforce object/range exclusivity
498 clear_tracks(); //enforce object/track exclusivity
500 /* XXX This method or the add (const RegionSelection&) needs to go
503 bool changed = false;
505 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
506 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
507 changed = regions.add ((*i));
517 Selection::add (const RegionSelection& rs)
519 clear_time(); //enforce object/range exclusivity
520 clear_tracks(); //enforce object/track exclusivity
522 /* XXX This method or the add (const vector<RegionView*>&) needs to go
525 bool changed = false;
527 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
528 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
529 changed = regions.add ((*i));
539 Selection::add (RegionView* r)
541 clear_time(); //enforce object/range exclusivity
542 clear_tracks(); //enforce object/track exclusivity
544 if (find (regions.begin(), regions.end(), r) == regions.end()) {
545 bool changed = regions.add (r);
553 Selection::add (MidiRegionView* mrv)
555 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
557 clear_time(); //enforce object/range exclusivity
558 clear_tracks(); //enforce object/track exclusivity
560 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
561 midi_regions.push_back (mrv);
562 /* XXX should we do this? */
563 MidiRegionsChanged ();
568 Selection::add (framepos_t start, framepos_t end)
570 clear_objects(); //enforce object/range exclusivity
572 AudioRangeComparator cmp;
574 /* XXX this implementation is incorrect */
576 time.push_back (AudioRange (start, end, ++next_time_id));
586 Selection::move_time (framecnt_t distance)
592 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
593 (*i).start += distance;
594 (*i).end += distance;
601 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
603 clear_objects(); //enforce object/range exclusivity
605 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
606 if ((*i).id == sid) {
608 time.push_back (AudioRange(start,end, sid));
610 /* don't consolidate here */
613 AudioRangeComparator cmp;
623 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
625 clear_time(); //enforce object/range exclusivity
626 clear_tracks(); //enforce object/track exclusivity
628 boost::shared_ptr<ARDOUR::AutomationList> al
629 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
631 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
635 /* The original may change so we must store a copy (not a pointer) here.
636 * e.g AutomationLine rewrites the list with gain mapping.
637 * the downside is that we can't perfom duplicate checks.
638 * This code was changed in response to #6842
640 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
645 Selection::remove (TimeAxisView* track)
647 list<TimeAxisView*>::iterator i;
648 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
649 /* erase first, because set_selected() will remove the track
650 from the selection, invalidating the iterator.
652 In fact, we don't really even need to do the erase, but this is
653 a hangover of axis view selection being in the GUI.
656 track->set_selected (false);
661 Selection::remove (const TrackViewList& track_list)
663 PresentationInfo::ChangeSuspender cs;
665 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
667 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
669 if (x != tracks.end()) {
671 (*i)->set_selected (false);
677 Selection::remove (ControlPoint* p)
679 PointSelection::iterator i = find (points.begin(), points.end(), p);
680 if (i != points.end ()) {
686 Selection::remove (const MidiNoteSelection& midi_list)
688 bool changed = false;
690 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
692 MidiNoteSelection::iterator x;
694 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
695 midi_notes.erase (x);
706 Selection::remove (MidiCutBuffer* midi)
708 MidiNoteSelection::iterator x;
710 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
711 /* remember that we own the MCB */
713 midi_notes.erase (x);
719 Selection::remove (boost::shared_ptr<Playlist> track)
721 list<boost::shared_ptr<Playlist> >::iterator i;
722 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
729 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
731 bool changed = false;
733 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
735 list<boost::shared_ptr<Playlist> >::iterator x;
737 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
749 Selection::remove (RegionView* r)
751 if (regions.remove (r)) {
757 Selection::remove (MidiRegionView* mrv)
759 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
761 MidiRegionSelection::iterator x;
763 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
764 midi_regions.erase (x);
765 MidiRegionsChanged ();
770 Selection::remove (uint32_t selection_id)
776 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
777 if ((*i).id == selection_id) {
787 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
792 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
794 AutomationSelection::iterator i;
795 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
802 Selection::set (TimeAxisView* track)
804 if (dynamic_cast<VCATimeAxisView*> (track)) {
807 clear_objects (); //enforce object/range exclusivity
809 PresentationInfo::ChangeSuspender cs;
811 if (!tracks.empty()) {
813 if (tracks.size() == 1 && tracks.front() == track) {
814 /* already single selection: nothing to do */
818 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
819 (*x)->set_selected (false);
829 Selection::set (const TrackViewList& track_list)
831 clear_objects(); //enforce object/range exclusivity
833 PresentationInfo::ChangeSuspender cs;
835 if (!tracks.empty()) {
837 /* cannot use set<T>::operator== (set<T> const &) here, because
838 * apparently the ordering used within 2 sets is not
839 * necessarily the same.
842 if (tracks.size() == track_list.size()) {
843 bool missing = false;
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()) {
855 /* already same selection: nothing to do */
860 /* argument is different from existing selection */
862 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
863 if (dynamic_cast<VCATimeAxisView*> (*x)) {
866 (*x)->set_selected (false);
876 Selection::set (const MidiNoteSelection& midi_list)
878 clear_time (); //enforce region/object exclusivity
879 clear_tracks(); //enforce object/track exclusivity
885 Selection::set (boost::shared_ptr<Playlist> playlist)
887 clear_time (); //enforce region/object exclusivity
888 clear_tracks(); //enforce object/track exclusivity
894 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
896 clear_time(); //enforce region/object exclusivity
902 Selection::set (const RegionSelection& rs)
904 clear_time(); //enforce region/object exclusivity
905 clear_tracks(); //enforce object/track exclusivity
908 RegionsChanged(); /* EMIT SIGNAL */
912 Selection::set (MidiRegionView* mrv)
914 clear_time(); //enforce region/object exclusivity
915 clear_tracks(); //enforce object/track exclusivity
921 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
923 clear_time(); //enforce region/object exclusivity
924 clear_tracks(); //enforce object/track exclusivity
930 Selection::set (vector<RegionView*>& v)
932 clear_time(); //enforce region/object exclusivity
933 clear_tracks(); //enforce object/track exclusivity
939 /** Set the start and end time of the time selection, without changing
940 * the list of tracks it applies to.
943 Selection::set (framepos_t start, framepos_t end)
945 clear_objects(); //enforce region/object exclusivity
948 if ((start == 0 && end == 0) || end < start) {
953 time.push_back (AudioRange (start, end, ++next_time_id));
955 /* reuse the first entry, and remove all the rest */
957 while (time.size() > 1) {
960 time.front().start = start;
961 time.front().end = end;
968 return time.front().id;
971 /** Set the start and end of the range selection. If more than one range
972 * is currently selected, the start of the earliest range and the end of the
973 * latest range are set. If no range is currently selected, this method
974 * selects a single range from start to end.
976 * @param start New start time.
977 * @param end New end time.
980 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
982 clear_objects(); //enforce region/object exclusivity
984 if ((start == 0 && end == 0) || (end < start)) {
989 time.push_back (AudioRange (start, end, ++next_time_id));
991 time.sort (AudioRangeComparator ());
992 time.front().start = start;
993 time.back().end = end;
1002 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
1004 clear_time(); //enforce region/object exclusivity
1005 clear_tracks(); //enforce object/track exclusivity
1012 Selection::selected (ArdourMarker* m) const
1014 return find (markers.begin(), markers.end(), m) != markers.end();
1018 Selection::selected (TimeAxisView* tv) const
1020 return tv->selected ();
1024 Selection::selected (RegionView* rv) const
1026 return find (regions.begin(), regions.end(), rv) != regions.end();
1030 Selection::selected (ControlPoint* cp) const
1032 return find (points.begin(), points.end(), cp) != points.end();
1036 Selection::empty (bool internal_selection)
1038 bool object_level_empty = regions.empty () &&
1041 playlists.empty () &&
1044 playlists.empty () &&
1046 midi_regions.empty()
1049 if (!internal_selection) {
1050 return object_level_empty;
1053 /* this is intended to really only apply when using a Selection
1057 return object_level_empty && midi_notes.empty() && points.empty();
1061 Selection::toggle (ControlPoint* cp)
1063 clear_time(); //enforce region/object exclusivity
1064 clear_tracks(); //enforce object/track exclusivity
1066 cp->set_selected (!cp->selected ());
1067 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1068 if (i == points.end()) {
1069 points.push_back (cp);
1074 PointsChanged (); /* EMIT SIGNAL */
1078 Selection::toggle (vector<ControlPoint*> const & cps)
1080 clear_time(); //enforce region/object exclusivity
1081 clear_tracks(); //enforce object/track exclusivity
1083 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1089 Selection::toggle (list<Selectable*> const & selectables)
1091 clear_time(); //enforce region/object exclusivity
1092 clear_tracks(); //enforce object/track exclusivity
1096 vector<RegionView*> rvs;
1097 vector<ControlPoint*> cps;
1099 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1100 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1102 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1105 fatal << _("programming error: ")
1106 << X_("unknown selectable type passed to Selection::toggle()")
1108 abort(); /*NOTREACHED*/
1122 Selection::set (list<Selectable*> const & selectables)
1124 clear_time (); //enforce region/object exclusivity
1125 clear_tracks(); //enforce object/track exclusivity
1132 Selection::add (PointSelection const & s)
1134 clear_time (); //enforce region/object exclusivity
1135 clear_tracks(); //enforce object/track exclusivity
1137 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1138 points.push_back (*i);
1143 Selection::add (list<Selectable*> const & selectables)
1145 clear_time (); //enforce region/object exclusivity
1146 clear_tracks(); //enforce object/track exclusivity
1150 vector<RegionView*> rvs;
1151 vector<ControlPoint*> cps;
1153 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1154 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1156 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1159 fatal << _("programming error: ")
1160 << X_("unknown selectable type passed to Selection::add()")
1162 abort(); /*NOTREACHED*/
1176 Selection::clear_points (bool with_signal)
1178 if (!points.empty()) {
1187 Selection::add (ControlPoint* cp)
1189 clear_time (); //enforce region/object exclusivity
1190 clear_tracks(); //enforce object/track exclusivity
1192 cp->set_selected (true);
1193 points.push_back (cp);
1194 PointsChanged (); /* EMIT SIGNAL */
1198 Selection::add (vector<ControlPoint*> const & cps)
1200 clear_time (); //enforce region/object exclusivity
1201 clear_tracks(); //enforce object/track exclusivity
1203 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1204 (*i)->set_selected (true);
1205 points.push_back (*i);
1207 PointsChanged (); /* EMIT SIGNAL */
1211 Selection::set (ControlPoint* cp)
1213 clear_time (); //enforce region/object exclusivity
1214 clear_tracks(); //enforce object/track exclusivity
1216 if (cp->selected () && points.size () == 1) {
1220 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1221 cp->line().nth (i)->set_selected (false);
1229 Selection::set (ArdourMarker* m)
1231 clear_time (); //enforce region/object exclusivity
1232 clear_tracks(); //enforce object/track exclusivity
1239 Selection::toggle (ArdourMarker* m)
1241 MarkerSelection::iterator i;
1243 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1251 Selection::remove (ArdourMarker* m)
1253 MarkerSelection::iterator i;
1255 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1262 Selection::add (ArdourMarker* m)
1264 clear_time (); //enforce region/object exclusivity
1265 clear_tracks(); //enforce object/track exclusivity
1267 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1268 markers.push_back (m);
1274 Selection::add (const list<ArdourMarker*>& m)
1276 clear_time (); //enforce region/object exclusivity
1277 clear_tracks(); //enforce object/track exclusivity
1279 markers.insert (markers.end(), m.begin(), m.end());
1287 MarkerSelection::range (framepos_t& s, framepos_t& e)
1292 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1294 if ((*i)->position() < s) {
1295 s = (*i)->position();
1298 if ((*i)->position() > e) {
1299 e = (*i)->position();
1303 s = std::min (s, e);
1304 e = std::max (s, e);
1308 Selection::get_state () const
1310 /* XXX: not complete; just sufficient to get track selection state
1311 so that re-opening plugin windows for editor mixer strips works
1315 XMLNode* node = new XMLNode (X_("Selection"));
1317 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1318 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1319 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1321 XMLNode* t = node->add_child (X_("RouteView"));
1322 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1324 XMLNode* t = node->add_child (X_("AutomationView"));
1325 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1326 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1330 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1331 XMLNode* r = node->add_child (X_("Region"));
1332 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1335 /* midi region views have thir own internal selection. */
1336 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1337 editor->get_per_region_note_selection (rid_notes);
1339 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1340 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1341 XMLNode* n = node->add_child (X_("MIDINotes"));
1342 n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
1344 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1345 XMLNode* nc = n->add_child(X_("note"));
1347 snprintf(buf, sizeof(buf), "%d", (*i)->id());
1348 nc->add_property (X_("note-id"), string(buf));
1352 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1353 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1356 XMLNode* r = node->add_child (X_("ControlPoint"));
1357 r->add_property (X_("type"), "track");
1358 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1359 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1360 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1362 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1363 r->add_property (X_("view-index"), string(buf));
1367 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1369 XMLNode* r = node->add_child (X_("ControlPoint"));
1370 r->add_property (X_("type"), "region");
1371 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1372 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1373 r->add_property (X_("view-index"), string(buf));
1378 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1379 XMLNode* t = node->add_child (X_("AudioRange"));
1380 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1381 t->add_property (X_("start"), string(buf));
1382 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1383 t->add_property (X_("end"), string(buf));
1386 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1387 XMLNode* t = node->add_child (X_("Marker"));
1390 Location* loc = editor->find_location_from_marker (*i, is_start);
1392 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1393 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1400 Selection::set_state (XMLNode const & node, int)
1402 if (node.name() != X_("Selection")) {
1407 clear_midi_notes ();
1413 XMLNodeList children = node.children ();
1414 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1415 if ((*i)->name() == X_("RouteView")) {
1417 XMLProperty const * prop_id = (*i)->property (X_("id"));
1419 PBD::ID id (prop_id->value ());
1420 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1425 } else if ((*i)->name() == X_("Region")) {
1426 XMLProperty const * prop_id = (*i)->property (X_("id"));
1428 PBD::ID id (prop_id->value ());
1431 editor->get_regionviews_by_id (id, rs);
1437 regionviews haven't been constructed - stash the region IDs
1438 so we can identify them in Editor::region_view_added ()
1440 regions.pending.push_back (id);
1443 } else if ((*i)->name() == X_("MIDINotes")) {
1444 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1446 assert (prop_region_id);
1448 PBD::ID const id (prop_region_id->value ());
1451 editor->get_regionviews_by_id (id, rs); // there could be more than one
1453 std::list<Evoral::event_id_t> notes;
1454 XMLNodeList children = (*i)->children ();
1456 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1457 XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
1459 Evoral::event_id_t id = atoi(prop_id->value());
1460 notes.push_back (id);
1464 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1465 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1467 mrv->select_notes(notes);
1472 /* regionviews containing these notes don't yet exist on the canvas.*/
1473 pending_midi_note_selection.push_back (make_pair (id, notes));
1476 } else if ((*i)->name() == X_("ControlPoint")) {
1477 XMLProperty const * prop_type = (*i)->property (X_("type"));
1481 if (prop_type->value () == "track") {
1483 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1484 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1485 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1486 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1488 assert (prop_route_id);
1489 assert (prop_alist_id);
1490 assert (prop_parameter);
1491 assert (prop_view_index);
1493 PBD::ID route_id (prop_route_id->value ());
1494 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1495 vector <ControlPoint *> cps;
1498 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1500 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1501 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1502 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1503 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1515 } else if (prop_type->value () == "region") {
1516 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1517 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1519 if (!prop_region_id || !prop_view_index) {
1523 PBD::ID region_id (prop_region_id->value ());
1525 editor->get_regionviews_by_id (region_id, rs);
1528 vector <ControlPoint *> cps;
1529 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1530 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1532 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1533 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1546 } else if ((*i)->name() == X_("AudioRange")) {
1547 XMLProperty const * prop_start = (*i)->property (X_("start"));
1548 XMLProperty const * prop_end = (*i)->property (X_("end"));
1550 assert (prop_start);
1553 framepos_t s (atol (prop_start->value ().c_str()));
1554 framepos_t e (atol (prop_end->value ().c_str()));
1556 set_preserving_all_ranges (s, e);
1558 } else if ((*i)->name() == X_("AutomationView")) {
1560 XMLProperty const * prop_id = (*i)->property (X_("id"));
1561 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1564 assert (prop_parameter);
1566 PBD::ID id (prop_id->value ());
1567 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1570 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1572 /* the automation could be for an entity that was never saved
1573 in the session file. Don't freak out if we can't find
1582 } else if ((*i)->name() == X_("Marker")) {
1584 XMLProperty const * prop_id = (*i)->property (X_("id"));
1585 XMLProperty const * prop_start = (*i)->property (X_("start"));
1587 assert (prop_start);
1589 PBD::ID id (prop_id->value ());
1590 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1603 Selection::remove_regions (TimeAxisView* t)
1605 RegionSelection::iterator i = regions.begin();
1606 while (i != regions.end ()) {
1607 RegionSelection::iterator tmp = i;
1610 if (&(*i)->get_time_axis_view() == t) {