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 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
647 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
648 if (x != tracks.end()) {
649 (*i)->set_selected (false);
656 Selection::remove (ControlPoint* p)
658 PointSelection::iterator i = find (points.begin(), points.end(), p);
659 if (i != points.end ()) {
665 Selection::remove (const MidiNoteSelection& midi_list)
667 bool changed = false;
669 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
671 MidiNoteSelection::iterator x;
673 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
674 midi_notes.erase (x);
685 Selection::remove (MidiCutBuffer* midi)
687 MidiNoteSelection::iterator x;
689 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
690 /* remember that we own the MCB */
692 midi_notes.erase (x);
698 Selection::remove (boost::shared_ptr<Playlist> track)
700 list<boost::shared_ptr<Playlist> >::iterator i;
701 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
708 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
710 bool changed = false;
712 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
714 list<boost::shared_ptr<Playlist> >::iterator x;
716 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
728 Selection::remove (RegionView* r)
730 if (regions.remove (r)) {
736 Selection::remove (MidiRegionView* mrv)
738 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
740 MidiRegionSelection::iterator x;
742 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
743 midi_regions.erase (x);
744 MidiRegionsChanged ();
749 Selection::remove (uint32_t selection_id)
755 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
756 if ((*i).id == selection_id) {
766 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
771 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
773 AutomationSelection::iterator i;
774 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
781 Selection::set (TimeAxisView* track)
783 clear_objects (); //enforce object/range exclusivity
785 PresentationInfo::ChangeSuspender cs;
787 if (!tracks.empty()) {
789 if (tracks.size() == 1 && tracks.front() == track) {
790 /* already single selection: nothing to do */
794 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
795 (*x)->set_selected (false);
805 Selection::set (const TrackViewList& track_list)
807 clear_objects(); //enforce object/range exclusivity
809 PresentationInfo::ChangeSuspender cs;
811 if (!tracks.empty()) {
813 /* cannot use set<T>::operator== (set<T> const &) here, because
814 * apparently the ordering used within 2 sets is not
815 * necessarily the same.
818 if (tracks.size() == track_list.size()) {
819 bool missing = false;
821 for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
822 if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) {
828 /* already same selection: nothing to do */
833 /* argument is different from existing selection */
835 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
836 (*x)->set_selected (false);
846 Selection::set (const MidiNoteSelection& midi_list)
848 clear_time (); //enforce region/object exclusivity
849 clear_tracks(); //enforce object/track exclusivity
855 Selection::set (boost::shared_ptr<Playlist> playlist)
857 clear_time (); //enforce region/object exclusivity
858 clear_tracks(); //enforce object/track exclusivity
864 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
866 clear_time(); //enforce region/object exclusivity
872 Selection::set (const RegionSelection& rs)
874 clear_time(); //enforce region/object exclusivity
875 clear_tracks(); //enforce object/track exclusivity
878 RegionsChanged(); /* EMIT SIGNAL */
882 Selection::set (MidiRegionView* mrv)
884 clear_time(); //enforce region/object exclusivity
885 clear_tracks(); //enforce object/track exclusivity
891 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
893 clear_time(); //enforce region/object exclusivity
894 clear_tracks(); //enforce object/track exclusivity
900 Selection::set (vector<RegionView*>& v)
902 clear_time(); //enforce region/object exclusivity
903 clear_tracks(); //enforce object/track exclusivity
909 /** Set the start and end time of the time selection, without changing
910 * the list of tracks it applies to.
913 Selection::set (framepos_t start, framepos_t end)
915 clear_objects(); //enforce region/object exclusivity
918 if ((start == 0 && end == 0) || end < start) {
923 time.push_back (AudioRange (start, end, ++next_time_id));
925 /* reuse the first entry, and remove all the rest */
927 while (time.size() > 1) {
930 time.front().start = start;
931 time.front().end = end;
938 return time.front().id;
941 /** Set the start and end of the range selection. If more than one range
942 * is currently selected, the start of the earliest range and the end of the
943 * latest range are set. If no range is currently selected, this method
944 * selects a single range from start to end.
946 * @param start New start time.
947 * @param end New end time.
950 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
952 clear_objects(); //enforce region/object exclusivity
954 if ((start == 0 && end == 0) || (end < start)) {
959 time.push_back (AudioRange (start, end, ++next_time_id));
961 time.sort (AudioRangeComparator ());
962 time.front().start = start;
963 time.back().end = end;
972 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
974 clear_time(); //enforce region/object exclusivity
975 clear_tracks(); //enforce object/track exclusivity
982 Selection::selected (ArdourMarker* m)
984 return find (markers.begin(), markers.end(), m) != markers.end();
988 Selection::selected (TimeAxisView* tv)
990 return tv->selected ();
994 Selection::selected (RegionView* rv)
996 return find (regions.begin(), regions.end(), rv) != regions.end();
1000 Selection::selected (ControlPoint* cp)
1002 return find (points.begin(), points.end(), cp) != points.end();
1006 Selection::empty (bool internal_selection)
1008 bool object_level_empty = regions.empty () &&
1011 playlists.empty () &&
1014 playlists.empty () &&
1016 midi_regions.empty()
1019 if (!internal_selection) {
1020 return object_level_empty;
1023 /* this is intended to really only apply when using a Selection
1027 return object_level_empty && midi_notes.empty() && points.empty();
1031 Selection::toggle (ControlPoint* cp)
1033 clear_time(); //enforce region/object exclusivity
1034 clear_tracks(); //enforce object/track exclusivity
1036 cp->set_selected (!cp->selected ());
1037 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1038 if (i == points.end()) {
1039 points.push_back (cp);
1044 PointsChanged (); /* EMIT SIGNAL */
1048 Selection::toggle (vector<ControlPoint*> const & cps)
1050 clear_time(); //enforce region/object exclusivity
1051 clear_tracks(); //enforce object/track exclusivity
1053 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1059 Selection::toggle (list<Selectable*> const & selectables)
1061 clear_time(); //enforce region/object exclusivity
1062 clear_tracks(); //enforce object/track exclusivity
1066 vector<RegionView*> rvs;
1067 vector<ControlPoint*> cps;
1069 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1070 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1072 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1075 fatal << _("programming error: ")
1076 << X_("unknown selectable type passed to Selection::toggle()")
1078 abort(); /*NOTREACHED*/
1092 Selection::set (list<Selectable*> const & selectables)
1094 clear_time (); //enforce region/object exclusivity
1095 clear_tracks(); //enforce object/track exclusivity
1102 Selection::add (PointSelection const & s)
1104 clear_time (); //enforce region/object exclusivity
1105 clear_tracks(); //enforce object/track exclusivity
1107 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1108 points.push_back (*i);
1113 Selection::add (list<Selectable*> const & selectables)
1115 clear_time (); //enforce region/object exclusivity
1116 clear_tracks(); //enforce object/track exclusivity
1120 vector<RegionView*> rvs;
1121 vector<ControlPoint*> cps;
1123 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1124 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1126 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1129 fatal << _("programming error: ")
1130 << X_("unknown selectable type passed to Selection::add()")
1132 abort(); /*NOTREACHED*/
1146 Selection::clear_points (bool with_signal)
1148 if (!points.empty()) {
1157 Selection::add (ControlPoint* cp)
1159 clear_time (); //enforce region/object exclusivity
1160 clear_tracks(); //enforce object/track exclusivity
1162 cp->set_selected (true);
1163 points.push_back (cp);
1164 PointsChanged (); /* EMIT SIGNAL */
1168 Selection::add (vector<ControlPoint*> const & cps)
1170 clear_time (); //enforce region/object exclusivity
1171 clear_tracks(); //enforce object/track exclusivity
1173 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1174 (*i)->set_selected (true);
1175 points.push_back (*i);
1177 PointsChanged (); /* EMIT SIGNAL */
1181 Selection::set (ControlPoint* cp)
1183 clear_time (); //enforce region/object exclusivity
1184 clear_tracks(); //enforce object/track exclusivity
1186 if (cp->selected () && points.size () == 1) {
1190 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1191 cp->line().nth (i)->set_selected (false);
1199 Selection::set (ArdourMarker* m)
1201 clear_time (); //enforce region/object exclusivity
1202 clear_tracks(); //enforce object/track exclusivity
1209 Selection::toggle (ArdourMarker* m)
1211 MarkerSelection::iterator i;
1213 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1221 Selection::remove (ArdourMarker* m)
1223 MarkerSelection::iterator i;
1225 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1232 Selection::add (ArdourMarker* m)
1234 clear_time (); //enforce region/object exclusivity
1235 clear_tracks(); //enforce object/track exclusivity
1237 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1238 markers.push_back (m);
1244 Selection::add (const list<ArdourMarker*>& m)
1246 clear_time (); //enforce region/object exclusivity
1247 clear_tracks(); //enforce object/track exclusivity
1249 markers.insert (markers.end(), m.begin(), m.end());
1257 MarkerSelection::range (framepos_t& s, framepos_t& e)
1262 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1264 if ((*i)->position() < s) {
1265 s = (*i)->position();
1268 if ((*i)->position() > e) {
1269 e = (*i)->position();
1273 s = std::min (s, e);
1274 e = std::max (s, e);
1278 Selection::get_state () const
1280 /* XXX: not complete; just sufficient to get track selection state
1281 so that re-opening plugin windows for editor mixer strips works
1285 XMLNode* node = new XMLNode (X_("Selection"));
1287 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1288 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1289 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1291 XMLNode* t = node->add_child (X_("RouteView"));
1292 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1294 XMLNode* t = node->add_child (X_("AutomationView"));
1295 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1296 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1300 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1301 XMLNode* r = node->add_child (X_("Region"));
1302 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1305 /* midi region views have thir own internal selection. */
1306 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1307 editor->get_per_region_note_selection (rid_notes);
1309 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1310 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1311 XMLNode* n = node->add_child (X_("MIDINotes"));
1312 n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
1314 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1315 XMLNode* nc = n->add_child(X_("note"));
1317 snprintf(buf, sizeof(buf), "%d", (*i)->id());
1318 nc->add_property (X_("note-id"), string(buf));
1322 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1323 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1326 XMLNode* r = node->add_child (X_("ControlPoint"));
1327 r->add_property (X_("type"), "track");
1328 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1329 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1330 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1332 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1333 r->add_property (X_("view-index"), string(buf));
1337 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1339 XMLNode* r = node->add_child (X_("ControlPoint"));
1340 r->add_property (X_("type"), "region");
1341 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1342 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1343 r->add_property (X_("view-index"), string(buf));
1348 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1349 XMLNode* t = node->add_child (X_("AudioRange"));
1350 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1351 t->add_property (X_("start"), string(buf));
1352 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1353 t->add_property (X_("end"), string(buf));
1356 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1357 XMLNode* t = node->add_child (X_("Marker"));
1360 Location* loc = editor->find_location_from_marker (*i, is_start);
1362 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1363 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1370 Selection::set_state (XMLNode const & node, int)
1372 if (node.name() != X_("Selection")) {
1377 clear_midi_notes ();
1383 XMLNodeList children = node.children ();
1384 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1385 if ((*i)->name() == X_("RouteView")) {
1387 XMLProperty const * prop_id = (*i)->property (X_("id"));
1389 PBD::ID id (prop_id->value ());
1390 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1395 } else if ((*i)->name() == X_("Region")) {
1396 XMLProperty const * prop_id = (*i)->property (X_("id"));
1398 PBD::ID id (prop_id->value ());
1401 editor->get_regionviews_by_id (id, rs);
1407 regionviews haven't been constructed - stash the region IDs
1408 so we can identify them in Editor::region_view_added ()
1410 regions.pending.push_back (id);
1413 } else if ((*i)->name() == X_("MIDINotes")) {
1414 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1416 assert (prop_region_id);
1418 PBD::ID const id (prop_region_id->value ());
1421 editor->get_regionviews_by_id (id, rs); // there could be more than one
1423 std::list<Evoral::event_id_t> notes;
1424 XMLNodeList children = (*i)->children ();
1426 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1427 XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
1429 Evoral::event_id_t id = atoi(prop_id->value());
1430 notes.push_back (id);
1434 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1435 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1437 mrv->select_notes(notes);
1442 /* regionviews containing these notes don't yet exist on the canvas.*/
1443 pending_midi_note_selection.push_back (make_pair (id, notes));
1446 } else if ((*i)->name() == X_("ControlPoint")) {
1447 XMLProperty const * prop_type = (*i)->property (X_("type"));
1451 if (prop_type->value () == "track") {
1453 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1454 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1455 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1456 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1458 assert (prop_route_id);
1459 assert (prop_alist_id);
1460 assert (prop_parameter);
1461 assert (prop_view_index);
1463 PBD::ID route_id (prop_route_id->value ());
1464 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1465 vector <ControlPoint *> cps;
1468 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1470 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1471 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1472 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1473 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1485 } else if (prop_type->value () == "region") {
1486 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1487 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1489 if (!prop_region_id || !prop_view_index) {
1493 PBD::ID region_id (prop_region_id->value ());
1495 editor->get_regionviews_by_id (region_id, rs);
1498 vector <ControlPoint *> cps;
1499 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1500 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1502 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1503 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1516 } else if ((*i)->name() == X_("AudioRange")) {
1517 XMLProperty const * prop_start = (*i)->property (X_("start"));
1518 XMLProperty const * prop_end = (*i)->property (X_("end"));
1520 assert (prop_start);
1523 framepos_t s (atol (prop_start->value ().c_str()));
1524 framepos_t e (atol (prop_end->value ().c_str()));
1526 set_preserving_all_ranges (s, e);
1528 } else if ((*i)->name() == X_("AutomationView")) {
1530 XMLProperty const * prop_id = (*i)->property (X_("id"));
1531 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1534 assert (prop_parameter);
1536 PBD::ID id (prop_id->value ());
1537 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1540 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1542 /* the automation could be for an entity that was never saved
1543 in the session file. Don't freak out if we can't find
1552 } else if ((*i)->name() == X_("Marker")) {
1554 XMLProperty const * prop_id = (*i)->property (X_("id"));
1555 XMLProperty const * prop_start = (*i)->property (X_("start"));
1557 assert (prop_start);
1559 PBD::ID id (prop_id->value ());
1560 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1573 Selection::remove_regions (TimeAxisView* t)
1575 RegionSelection::iterator i = regions.begin();
1576 while (i != regions.end ()) {
1577 RegionSelection::iterator tmp = i;
1580 if (&(*i)->get_time_axis_view() == t) {