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"
47 using namespace ARDOUR;
50 struct AudioRangeComparator {
51 bool operator()(AudioRange a, AudioRange b) {
52 return a.start < b.start;
56 Selection::Selection (const PublicEditor* e)
63 /* we have disambiguate which remove() for the compiler */
65 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
66 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
68 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
69 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
71 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
72 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
77 Selection::operator= (const Selection& other)
80 regions = other.regions;
81 tracks = other.tracks;
84 midi_regions = other.midi_regions;
85 midi_notes = other.midi_notes;
92 operator== (const Selection& a, const Selection& b)
94 return a.regions == b.regions &&
95 a.tracks == b.tracks &&
98 a.playlists == b.playlists &&
99 a.midi_notes == b.midi_notes &&
100 a.midi_regions == b.midi_regions;
103 /** Clear everything from the Selection */
114 clear_midi_regions ();
116 pending_midi_note_selection.clear();
120 Selection::clear_objects (bool with_signal)
122 clear_regions (with_signal);
123 clear_points (with_signal);
124 clear_lines(with_signal);
125 clear_playlists (with_signal);
126 clear_midi_notes (with_signal);
127 clear_midi_regions (with_signal);
131 Selection::clear_tracks (bool with_signal)
133 if (!tracks.empty()) {
134 PresentationInfo::ChangeSuspender cs;
136 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
137 (*x)->set_selected (false);
145 Selection::clear_time (bool with_signal)
154 Selection::dump_region_layers()
156 cerr << "region selection layer dump" << endl;
157 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
158 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
164 Selection::clear_regions (bool with_signal)
166 if (!regions.empty()) {
167 regions.clear_all ();
175 Selection::clear_midi_notes (bool with_signal)
177 if (!midi_notes.empty()) {
178 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
187 // clear note selections for MRV's that have note selections
188 // this will cause the MRV to be removed from the list
189 for (MidiRegionSelection::iterator i = midi_regions.begin();
190 i != midi_regions.end();) {
191 MidiRegionSelection::iterator tmp = i;
193 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
195 mrv->clear_selection();
202 Selection::clear_midi_regions (bool with_signal)
204 if (!midi_regions.empty()) {
205 midi_regions.clear ();
207 MidiRegionsChanged ();
213 Selection::clear_playlists (bool with_signal)
215 /* Selections own their playlists */
217 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
218 /* selections own their own regions, which are copies of the "originals". make them go away */
219 (*i)->drop_regions ();
223 if (!playlists.empty()) {
232 Selection::clear_lines (bool with_signal)
234 if (!lines.empty()) {
243 Selection::clear_markers (bool with_signal)
245 if (!markers.empty()) {
254 Selection::toggle (boost::shared_ptr<Playlist> pl)
256 clear_time(); //enforce object/range exclusivity
257 clear_tracks(); //enforce object/track exclusivity
259 PlaylistSelection::iterator i;
261 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
263 playlists.push_back(pl);
272 Selection::toggle (const TrackViewList& track_list)
274 PresentationInfo::ChangeSuspender cs;
276 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
282 Selection::toggle (TimeAxisView* track)
284 TrackSelection::iterator i;
286 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
287 tracks.push_back (track);
288 track->set_selected (true);
291 track->set_selected (false);
297 Selection::toggle (const MidiNoteSelection& midi_note_list)
299 clear_time(); //enforce object/range exclusivity
300 clear_tracks(); //enforce object/track exclusivity
302 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
308 Selection::toggle (MidiCutBuffer* midi)
310 MidiNoteSelection::iterator i;
312 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
313 midi_notes.push_back (midi);
315 /* remember that we own the MCB */
317 midi_notes.erase (i);
325 Selection::toggle (RegionView* r)
327 clear_time(); //enforce object/range exclusivity
328 clear_tracks(); //enforce object/track exclusivity
330 RegionSelection::iterator i;
332 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
342 Selection::toggle (MidiRegionView* mrv)
344 clear_time(); //enforce object/range exclusivity
345 clear_tracks(); //enforce object/track exclusivity
347 MidiRegionSelection::iterator i;
349 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
352 midi_regions.erase (i);
355 MidiRegionsChanged ();
359 Selection::toggle (vector<RegionView*>& r)
361 clear_time(); //enforce object/range exclusivity
362 clear_tracks(); //enforce object/track exclusivity
364 RegionSelection::iterator i;
366 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
367 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
378 Selection::toggle (framepos_t start, framepos_t end)
380 clear_objects(); //enforce object/range exclusivity
382 AudioRangeComparator cmp;
384 /* XXX this implementation is incorrect */
386 time.push_back (AudioRange (start, end, ++next_time_id));
396 Selection::add (boost::shared_ptr<Playlist> pl)
398 clear_time(); //enforce object/range exclusivity
399 clear_tracks(); //enforce object/track exclusivity
401 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
403 playlists.push_back(pl);
409 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
411 clear_time(); //enforce object/range exclusivity
412 clear_tracks(); //enforce object/track exclusivity
414 bool changed = false;
416 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
417 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
419 playlists.push_back (*i);
430 Selection::add (TrackViewList const & track_list)
432 clear_objects(); //enforce object/range exclusivity
434 PresentationInfo::ChangeSuspender cs;
436 TrackViewList added = tracks.add (track_list);
438 if (!added.empty()) {
439 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
440 (*x)->set_selected (true);
446 Selection::add (TimeAxisView* track)
448 clear_objects(); //enforce object/range exclusivity
451 track->set_selected (true);
452 tr.push_back (track);
457 Selection::add (const MidiNoteSelection& midi_list)
459 clear_time(); //enforce object/range exclusivity
460 clear_tracks(); //enforce object/track exclusivity
462 const MidiNoteSelection::const_iterator b = midi_list.begin();
463 const MidiNoteSelection::const_iterator e = midi_list.end();
465 if (!midi_list.empty()) {
466 midi_notes.insert (midi_notes.end(), b, e);
472 Selection::add (MidiCutBuffer* midi)
474 /* we take ownership of the MCB */
476 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
477 midi_notes.push_back (midi);
483 Selection::add (vector<RegionView*>& v)
485 clear_time(); //enforce object/range exclusivity
486 clear_tracks(); //enforce object/track exclusivity
488 /* XXX This method or the add (const RegionSelection&) needs to go
491 bool changed = false;
493 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
494 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
495 changed = regions.add ((*i));
505 Selection::add (const RegionSelection& rs)
507 clear_time(); //enforce object/range exclusivity
508 clear_tracks(); //enforce object/track exclusivity
510 /* XXX This method or the add (const vector<RegionView*>&) needs to go
513 bool changed = false;
515 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
516 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
517 changed = regions.add ((*i));
527 Selection::add (RegionView* r)
529 clear_time(); //enforce object/range exclusivity
530 clear_tracks(); //enforce object/track exclusivity
532 if (find (regions.begin(), regions.end(), r) == regions.end()) {
533 bool changed = regions.add (r);
541 Selection::add (MidiRegionView* mrv)
543 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
545 clear_time(); //enforce object/range exclusivity
546 clear_tracks(); //enforce object/track exclusivity
548 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
549 midi_regions.push_back (mrv);
550 /* XXX should we do this? */
551 MidiRegionsChanged ();
556 Selection::add (framepos_t start, framepos_t end)
558 clear_objects(); //enforce object/range exclusivity
560 AudioRangeComparator cmp;
562 /* XXX this implementation is incorrect */
564 time.push_back (AudioRange (start, end, ++next_time_id));
574 Selection::move_time (framecnt_t distance)
580 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
581 (*i).start += distance;
582 (*i).end += distance;
589 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
591 clear_objects(); //enforce object/range exclusivity
593 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
594 if ((*i).id == sid) {
596 time.push_back (AudioRange(start,end, sid));
598 /* don't consolidate here */
601 AudioRangeComparator cmp;
611 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
613 clear_time(); //enforce object/range exclusivity
614 clear_tracks(); //enforce object/track exclusivity
616 boost::shared_ptr<ARDOUR::AutomationList> al
617 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
619 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
623 /* The original may change so we must store a copy (not a pointer) here.
624 * e.g AutomationLine rewrites the list with gain mapping.
625 * the downside is that we can't perfom duplicate checks.
626 * This code was changed in response to #6842
628 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
633 Selection::remove (TimeAxisView* track)
635 list<TimeAxisView*>::iterator i;
636 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
637 track->set_selected (false);
643 Selection::remove (const TrackViewList& track_list)
645 PresentationInfo::ChangeSuspender cs;
647 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
649 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
651 if (x != tracks.end()) {
653 (*i)->set_selected (false);
659 Selection::remove (ControlPoint* p)
661 PointSelection::iterator i = find (points.begin(), points.end(), p);
662 if (i != points.end ()) {
668 Selection::remove (const MidiNoteSelection& midi_list)
670 bool changed = false;
672 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
674 MidiNoteSelection::iterator x;
676 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
677 midi_notes.erase (x);
688 Selection::remove (MidiCutBuffer* midi)
690 MidiNoteSelection::iterator x;
692 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
693 /* remember that we own the MCB */
695 midi_notes.erase (x);
701 Selection::remove (boost::shared_ptr<Playlist> track)
703 list<boost::shared_ptr<Playlist> >::iterator i;
704 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
711 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
713 bool changed = false;
715 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
717 list<boost::shared_ptr<Playlist> >::iterator x;
719 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
731 Selection::remove (RegionView* r)
733 if (regions.remove (r)) {
739 Selection::remove (MidiRegionView* mrv)
741 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
743 MidiRegionSelection::iterator x;
745 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
746 midi_regions.erase (x);
747 MidiRegionsChanged ();
752 Selection::remove (uint32_t selection_id)
758 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
759 if ((*i).id == selection_id) {
769 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
774 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
776 AutomationSelection::iterator i;
777 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
784 Selection::set (TimeAxisView* track)
786 clear_objects (); //enforce object/range exclusivity
788 PresentationInfo::ChangeSuspender cs;
790 if (!tracks.empty()) {
792 if (tracks.size() == 1 && tracks.front() == track) {
793 /* already single selection: nothing to do */
797 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
798 (*x)->set_selected (false);
808 Selection::set (const TrackViewList& track_list)
810 clear_objects(); //enforce object/range exclusivity
812 PresentationInfo::ChangeSuspender cs;
814 if (!tracks.empty()) {
816 /* cannot use set<T>::operator== (set<T> const &) here, because
817 * apparently the ordering used within 2 sets is not
818 * necessarily the same.
821 if (tracks.size() == track_list.size()) {
822 bool missing = false;
824 for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
825 if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) {
831 /* already same selection: nothing to do */
836 /* argument is different from existing selection */
838 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
839 (*x)->set_selected (false);
849 Selection::set (const MidiNoteSelection& midi_list)
851 clear_time (); //enforce region/object exclusivity
852 clear_tracks(); //enforce object/track exclusivity
858 Selection::set (boost::shared_ptr<Playlist> playlist)
860 clear_time (); //enforce region/object exclusivity
861 clear_tracks(); //enforce object/track exclusivity
867 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
869 clear_time(); //enforce region/object exclusivity
875 Selection::set (const RegionSelection& rs)
877 clear_time(); //enforce region/object exclusivity
878 clear_tracks(); //enforce object/track exclusivity
881 RegionsChanged(); /* EMIT SIGNAL */
885 Selection::set (MidiRegionView* mrv)
887 clear_time(); //enforce region/object exclusivity
888 clear_tracks(); //enforce object/track exclusivity
894 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
896 clear_time(); //enforce region/object exclusivity
897 clear_tracks(); //enforce object/track exclusivity
903 Selection::set (vector<RegionView*>& v)
905 clear_time(); //enforce region/object exclusivity
906 clear_tracks(); //enforce object/track exclusivity
912 /** Set the start and end time of the time selection, without changing
913 * the list of tracks it applies to.
916 Selection::set (framepos_t start, framepos_t end)
918 clear_objects(); //enforce region/object exclusivity
921 if ((start == 0 && end == 0) || end < start) {
926 time.push_back (AudioRange (start, end, ++next_time_id));
928 /* reuse the first entry, and remove all the rest */
930 while (time.size() > 1) {
933 time.front().start = start;
934 time.front().end = end;
941 return time.front().id;
944 /** Set the start and end of the range selection. If more than one range
945 * is currently selected, the start of the earliest range and the end of the
946 * latest range are set. If no range is currently selected, this method
947 * selects a single range from start to end.
949 * @param start New start time.
950 * @param end New end time.
953 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
955 clear_objects(); //enforce region/object exclusivity
957 if ((start == 0 && end == 0) || (end < start)) {
962 time.push_back (AudioRange (start, end, ++next_time_id));
964 time.sort (AudioRangeComparator ());
965 time.front().start = start;
966 time.back().end = end;
975 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
977 clear_time(); //enforce region/object exclusivity
978 clear_tracks(); //enforce object/track exclusivity
985 Selection::selected (ArdourMarker* m)
987 return find (markers.begin(), markers.end(), m) != markers.end();
991 Selection::selected (TimeAxisView* tv)
993 return tv->selected ();
997 Selection::selected (RegionView* rv)
999 return find (regions.begin(), regions.end(), rv) != regions.end();
1003 Selection::selected (ControlPoint* cp)
1005 return find (points.begin(), points.end(), cp) != points.end();
1009 Selection::empty (bool internal_selection)
1011 bool object_level_empty = regions.empty () &&
1014 playlists.empty () &&
1017 playlists.empty () &&
1019 midi_regions.empty()
1022 if (!internal_selection) {
1023 return object_level_empty;
1026 /* this is intended to really only apply when using a Selection
1030 return object_level_empty && midi_notes.empty() && points.empty();
1034 Selection::toggle (ControlPoint* cp)
1036 clear_time(); //enforce region/object exclusivity
1037 clear_tracks(); //enforce object/track exclusivity
1039 cp->set_selected (!cp->selected ());
1040 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1041 if (i == points.end()) {
1042 points.push_back (cp);
1047 PointsChanged (); /* EMIT SIGNAL */
1051 Selection::toggle (vector<ControlPoint*> const & cps)
1053 clear_time(); //enforce region/object exclusivity
1054 clear_tracks(); //enforce object/track exclusivity
1056 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1062 Selection::toggle (list<Selectable*> const & selectables)
1064 clear_time(); //enforce region/object exclusivity
1065 clear_tracks(); //enforce object/track exclusivity
1069 vector<RegionView*> rvs;
1070 vector<ControlPoint*> cps;
1072 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1073 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1075 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1078 fatal << _("programming error: ")
1079 << X_("unknown selectable type passed to Selection::toggle()")
1081 abort(); /*NOTREACHED*/
1095 Selection::set (list<Selectable*> const & selectables)
1097 clear_time (); //enforce region/object exclusivity
1098 clear_tracks(); //enforce object/track exclusivity
1105 Selection::add (PointSelection const & s)
1107 clear_time (); //enforce region/object exclusivity
1108 clear_tracks(); //enforce object/track exclusivity
1110 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1111 points.push_back (*i);
1116 Selection::add (list<Selectable*> const & selectables)
1118 clear_time (); //enforce region/object exclusivity
1119 clear_tracks(); //enforce object/track exclusivity
1123 vector<RegionView*> rvs;
1124 vector<ControlPoint*> cps;
1126 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1127 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1129 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1132 fatal << _("programming error: ")
1133 << X_("unknown selectable type passed to Selection::add()")
1135 abort(); /*NOTREACHED*/
1149 Selection::clear_points (bool with_signal)
1151 if (!points.empty()) {
1160 Selection::add (ControlPoint* cp)
1162 clear_time (); //enforce region/object exclusivity
1163 clear_tracks(); //enforce object/track exclusivity
1165 cp->set_selected (true);
1166 points.push_back (cp);
1167 PointsChanged (); /* EMIT SIGNAL */
1171 Selection::add (vector<ControlPoint*> const & cps)
1173 clear_time (); //enforce region/object exclusivity
1174 clear_tracks(); //enforce object/track exclusivity
1176 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1177 (*i)->set_selected (true);
1178 points.push_back (*i);
1180 PointsChanged (); /* EMIT SIGNAL */
1184 Selection::set (ControlPoint* cp)
1186 clear_time (); //enforce region/object exclusivity
1187 clear_tracks(); //enforce object/track exclusivity
1189 if (cp->selected () && points.size () == 1) {
1193 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1194 cp->line().nth (i)->set_selected (false);
1202 Selection::set (ArdourMarker* m)
1204 clear_time (); //enforce region/object exclusivity
1205 clear_tracks(); //enforce object/track exclusivity
1212 Selection::toggle (ArdourMarker* m)
1214 MarkerSelection::iterator i;
1216 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1224 Selection::remove (ArdourMarker* m)
1226 MarkerSelection::iterator i;
1228 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1235 Selection::add (ArdourMarker* m)
1237 clear_time (); //enforce region/object exclusivity
1238 clear_tracks(); //enforce object/track exclusivity
1240 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1241 markers.push_back (m);
1247 Selection::add (const list<ArdourMarker*>& m)
1249 clear_time (); //enforce region/object exclusivity
1250 clear_tracks(); //enforce object/track exclusivity
1252 markers.insert (markers.end(), m.begin(), m.end());
1260 MarkerSelection::range (framepos_t& s, framepos_t& e)
1265 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1267 if ((*i)->position() < s) {
1268 s = (*i)->position();
1271 if ((*i)->position() > e) {
1272 e = (*i)->position();
1276 s = std::min (s, e);
1277 e = std::max (s, e);
1281 Selection::get_state () const
1283 /* XXX: not complete; just sufficient to get track selection state
1284 so that re-opening plugin windows for editor mixer strips works
1288 XMLNode* node = new XMLNode (X_("Selection"));
1290 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1291 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1292 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1294 XMLNode* t = node->add_child (X_("RouteView"));
1295 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1297 XMLNode* t = node->add_child (X_("AutomationView"));
1298 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1299 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1303 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1304 XMLNode* r = node->add_child (X_("Region"));
1305 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1308 /* midi region views have thir own internal selection. */
1309 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1310 editor->get_per_region_note_selection (rid_notes);
1312 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1313 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1314 XMLNode* n = node->add_child (X_("MIDINotes"));
1315 n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
1317 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1318 XMLNode* nc = n->add_child(X_("note"));
1320 snprintf(buf, sizeof(buf), "%d", (*i)->id());
1321 nc->add_property (X_("note-id"), string(buf));
1325 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1326 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1329 XMLNode* r = node->add_child (X_("ControlPoint"));
1330 r->add_property (X_("type"), "track");
1331 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1332 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1333 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1335 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1336 r->add_property (X_("view-index"), string(buf));
1340 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1342 XMLNode* r = node->add_child (X_("ControlPoint"));
1343 r->add_property (X_("type"), "region");
1344 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1345 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1346 r->add_property (X_("view-index"), string(buf));
1351 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1352 XMLNode* t = node->add_child (X_("AudioRange"));
1353 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1354 t->add_property (X_("start"), string(buf));
1355 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1356 t->add_property (X_("end"), string(buf));
1359 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1360 XMLNode* t = node->add_child (X_("Marker"));
1363 Location* loc = editor->find_location_from_marker (*i, is_start);
1365 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1366 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1373 Selection::set_state (XMLNode const & node, int)
1375 if (node.name() != X_("Selection")) {
1380 clear_midi_notes ();
1386 XMLNodeList children = node.children ();
1387 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1388 if ((*i)->name() == X_("RouteView")) {
1390 XMLProperty const * prop_id = (*i)->property (X_("id"));
1392 PBD::ID id (prop_id->value ());
1393 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1398 } else if ((*i)->name() == X_("Region")) {
1399 XMLProperty const * prop_id = (*i)->property (X_("id"));
1401 PBD::ID id (prop_id->value ());
1404 editor->get_regionviews_by_id (id, rs);
1410 regionviews haven't been constructed - stash the region IDs
1411 so we can identify them in Editor::region_view_added ()
1413 regions.pending.push_back (id);
1416 } else if ((*i)->name() == X_("MIDINotes")) {
1417 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1419 assert (prop_region_id);
1421 PBD::ID const id (prop_region_id->value ());
1424 editor->get_regionviews_by_id (id, rs); // there could be more than one
1426 std::list<Evoral::event_id_t> notes;
1427 XMLNodeList children = (*i)->children ();
1429 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1430 XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
1432 Evoral::event_id_t id = atoi(prop_id->value());
1433 notes.push_back (id);
1437 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1438 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1440 mrv->select_notes(notes);
1445 /* regionviews containing these notes don't yet exist on the canvas.*/
1446 pending_midi_note_selection.push_back (make_pair (id, notes));
1449 } else if ((*i)->name() == X_("ControlPoint")) {
1450 XMLProperty const * prop_type = (*i)->property (X_("type"));
1454 if (prop_type->value () == "track") {
1456 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1457 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1458 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1459 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1461 assert (prop_route_id);
1462 assert (prop_alist_id);
1463 assert (prop_parameter);
1464 assert (prop_view_index);
1466 PBD::ID route_id (prop_route_id->value ());
1467 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1468 vector <ControlPoint *> cps;
1471 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1473 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1474 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1475 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1476 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1488 } else if (prop_type->value () == "region") {
1489 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1490 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1492 if (!prop_region_id || !prop_view_index) {
1496 PBD::ID region_id (prop_region_id->value ());
1498 editor->get_regionviews_by_id (region_id, rs);
1501 vector <ControlPoint *> cps;
1502 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1503 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1505 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1506 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1519 } else if ((*i)->name() == X_("AudioRange")) {
1520 XMLProperty const * prop_start = (*i)->property (X_("start"));
1521 XMLProperty const * prop_end = (*i)->property (X_("end"));
1523 assert (prop_start);
1526 framepos_t s (atol (prop_start->value ().c_str()));
1527 framepos_t e (atol (prop_end->value ().c_str()));
1529 set_preserving_all_ranges (s, e);
1531 } else if ((*i)->name() == X_("AutomationView")) {
1533 XMLProperty const * prop_id = (*i)->property (X_("id"));
1534 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1537 assert (prop_parameter);
1539 PBD::ID id (prop_id->value ());
1540 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1543 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1545 /* the automation could be for an entity that was never saved
1546 in the session file. Don't freak out if we can't find
1555 } else if ((*i)->name() == X_("Marker")) {
1557 XMLProperty const * prop_id = (*i)->property (X_("id"));
1558 XMLProperty const * prop_start = (*i)->property (X_("start"));
1560 assert (prop_start);
1562 PBD::ID id (prop_id->value ());
1563 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1576 Selection::remove_regions (TimeAxisView* t)
1578 RegionSelection::iterator i = regions.begin();
1579 while (i != regions.end ()) {
1580 RegionSelection::iterator tmp = i;
1583 if (&(*i)->get_time_axis_view() == t) {