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)
60 , _no_tracks_changed (false)
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 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
136 (*x)->set_selected (false);
139 if (!_no_tracks_changed && with_signal) {
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 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
281 Selection::toggle (TimeAxisView* track)
283 TrackSelection::iterator i;
285 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
286 track->set_selected (true);
287 tracks.push_back (track);
289 track->set_selected (false);
293 if (!_no_tracks_changed) {
299 Selection::toggle (const MidiNoteSelection& midi_note_list)
301 clear_time(); //enforce object/range exclusivity
302 clear_tracks(); //enforce object/track exclusivity
304 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
310 Selection::toggle (MidiCutBuffer* midi)
312 MidiNoteSelection::iterator i;
314 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
315 midi_notes.push_back (midi);
317 /* remember that we own the MCB */
319 midi_notes.erase (i);
327 Selection::toggle (RegionView* r)
329 clear_time(); //enforce object/range exclusivity
330 clear_tracks(); //enforce object/track exclusivity
332 RegionSelection::iterator i;
334 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
344 Selection::toggle (MidiRegionView* mrv)
346 clear_time(); //enforce object/range exclusivity
347 clear_tracks(); //enforce object/track exclusivity
349 MidiRegionSelection::iterator i;
351 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
354 midi_regions.erase (i);
357 MidiRegionsChanged ();
361 Selection::toggle (vector<RegionView*>& r)
363 clear_time(); //enforce object/range exclusivity
364 clear_tracks(); //enforce object/track exclusivity
366 RegionSelection::iterator i;
368 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
369 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
380 Selection::toggle (framepos_t start, framepos_t end)
382 clear_objects(); //enforce object/range exclusivity
384 AudioRangeComparator cmp;
386 /* XXX this implementation is incorrect */
388 time.push_back (AudioRange (start, end, ++next_time_id));
398 Selection::add (boost::shared_ptr<Playlist> pl)
400 clear_time(); //enforce object/range exclusivity
401 clear_tracks(); //enforce object/track exclusivity
403 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
405 playlists.push_back(pl);
411 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
413 clear_time(); //enforce object/range exclusivity
414 clear_tracks(); //enforce object/track exclusivity
416 bool changed = false;
418 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
419 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
421 playlists.push_back (*i);
432 Selection::add (const TrackViewList& track_list)
434 clear_objects(); //enforce object/range exclusivity
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);
442 if (!_no_tracks_changed) {
449 Selection::add (TimeAxisView* track)
451 clear_objects(); //enforce object/range exclusivity
454 track->set_selected (true);
455 tr.push_back (track);
460 Selection::add (const MidiNoteSelection& midi_list)
462 clear_time(); //enforce object/range exclusivity
463 clear_tracks(); //enforce object/track exclusivity
465 const MidiNoteSelection::const_iterator b = midi_list.begin();
466 const MidiNoteSelection::const_iterator e = midi_list.end();
468 if (!midi_list.empty()) {
469 midi_notes.insert (midi_notes.end(), b, e);
475 Selection::add (MidiCutBuffer* midi)
477 /* we take ownership of the MCB */
479 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
480 midi_notes.push_back (midi);
486 Selection::add (vector<RegionView*>& v)
488 clear_time(); //enforce object/range exclusivity
489 clear_tracks(); //enforce object/track exclusivity
491 /* XXX This method or the add (const RegionSelection&) needs to go
494 bool changed = false;
496 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
497 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
498 changed = regions.add ((*i));
508 Selection::add (const RegionSelection& rs)
510 clear_time(); //enforce object/range exclusivity
511 clear_tracks(); //enforce object/track exclusivity
513 /* XXX This method or the add (const vector<RegionView*>&) needs to go
516 bool changed = false;
518 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
519 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
520 changed = regions.add ((*i));
530 Selection::add (RegionView* r)
532 clear_time(); //enforce object/range exclusivity
533 clear_tracks(); //enforce object/track exclusivity
535 if (find (regions.begin(), regions.end(), r) == regions.end()) {
536 bool changed = regions.add (r);
544 Selection::add (MidiRegionView* mrv)
546 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
548 clear_time(); //enforce object/range exclusivity
549 clear_tracks(); //enforce object/track exclusivity
551 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
552 midi_regions.push_back (mrv);
553 /* XXX should we do this? */
554 MidiRegionsChanged ();
559 Selection::add (framepos_t start, framepos_t end)
561 clear_objects(); //enforce object/range exclusivity
563 AudioRangeComparator cmp;
565 /* XXX this implementation is incorrect */
567 time.push_back (AudioRange (start, end, ++next_time_id));
577 Selection::move_time (framecnt_t distance)
583 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
584 (*i).start += distance;
585 (*i).end += distance;
592 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
594 clear_objects(); //enforce object/range exclusivity
596 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
597 if ((*i).id == sid) {
599 time.push_back (AudioRange(start,end, sid));
601 /* don't consolidate here */
604 AudioRangeComparator cmp;
614 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
616 clear_time(); //enforce object/range exclusivity
617 clear_tracks(); //enforce object/track exclusivity
619 boost::shared_ptr<ARDOUR::AutomationList> al
620 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
622 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
626 /* The original may change so we must store a copy (not a pointer) here.
627 * e.g AutomationLine rewrites the list with gain mapping.
628 * the downside is that we can't perfom duplicate checks.
629 * This code was changed in response to #6842
631 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
636 Selection::remove (TimeAxisView* track)
638 list<TimeAxisView*>::iterator i;
639 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
640 track->set_selected (false);
643 if (!_no_tracks_changed) {
650 Selection::remove (const TrackViewList& track_list)
652 bool changed = false;
654 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
656 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
657 if (x != tracks.end()) {
658 (*i)->set_selected (false);
665 if (!_no_tracks_changed) {
672 Selection::remove (ControlPoint* p)
674 PointSelection::iterator i = find (points.begin(), points.end(), p);
675 if (i != points.end ()) {
681 Selection::remove (const MidiNoteSelection& midi_list)
683 bool changed = false;
685 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
687 MidiNoteSelection::iterator x;
689 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
690 midi_notes.erase (x);
701 Selection::remove (MidiCutBuffer* midi)
703 MidiNoteSelection::iterator x;
705 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
706 /* remember that we own the MCB */
708 midi_notes.erase (x);
714 Selection::remove (boost::shared_ptr<Playlist> track)
716 list<boost::shared_ptr<Playlist> >::iterator i;
717 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
724 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
726 bool changed = false;
728 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
730 list<boost::shared_ptr<Playlist> >::iterator x;
732 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
744 Selection::remove (RegionView* r)
746 if (regions.remove (r)) {
752 Selection::remove (MidiRegionView* mrv)
754 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
756 MidiRegionSelection::iterator x;
758 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
759 midi_regions.erase (x);
760 MidiRegionsChanged ();
765 Selection::remove (uint32_t selection_id)
771 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
772 if ((*i).id == selection_id) {
782 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
787 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
789 AutomationSelection::iterator i;
790 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
797 Selection::set (TimeAxisView* track)
799 clear_objects (); //enforce object/range exclusivity
800 clear_tracks (false);
805 Selection::set (const TrackViewList& track_list)
807 clear_objects(); //enforce object/range exclusivity
808 clear_tracks (false);
813 Selection::set (const MidiNoteSelection& midi_list)
815 clear_time (); //enforce region/object exclusivity
816 clear_tracks(); //enforce object/track exclusivity
822 Selection::set (boost::shared_ptr<Playlist> playlist)
824 clear_time (); //enforce region/object exclusivity
825 clear_tracks(); //enforce object/track exclusivity
831 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
833 clear_time(); //enforce region/object exclusivity
839 Selection::set (const RegionSelection& rs)
841 clear_time(); //enforce region/object exclusivity
842 clear_tracks(); //enforce object/track exclusivity
845 RegionsChanged(); /* EMIT SIGNAL */
849 Selection::set (MidiRegionView* mrv)
851 clear_time(); //enforce region/object exclusivity
852 clear_tracks(); //enforce object/track exclusivity
858 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
860 clear_time(); //enforce region/object exclusivity
861 clear_tracks(); //enforce object/track exclusivity
867 Selection::set (vector<RegionView*>& v)
869 clear_time(); //enforce region/object exclusivity
870 clear_tracks(); //enforce object/track exclusivity
876 /** Set the start and end time of the time selection, without changing
877 * the list of tracks it applies to.
880 Selection::set (framepos_t start, framepos_t end)
882 clear_objects(); //enforce region/object exclusivity
885 if ((start == 0 && end == 0) || end < start) {
890 time.push_back (AudioRange (start, end, ++next_time_id));
892 /* reuse the first entry, and remove all the rest */
894 while (time.size() > 1) {
897 time.front().start = start;
898 time.front().end = end;
905 return time.front().id;
908 /** Set the start and end of the range selection. If more than one range
909 * is currently selected, the start of the earliest range and the end of the
910 * latest range are set. If no range is currently selected, this method
911 * selects a single range from start to end.
913 * @param start New start time.
914 * @param end New end time.
917 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
919 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 time.sort (AudioRangeComparator ());
929 time.front().start = start;
930 time.back().end = end;
939 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
941 clear_time(); //enforce region/object exclusivity
942 clear_tracks(); //enforce object/track exclusivity
949 Selection::selected (ArdourMarker* m)
951 return find (markers.begin(), markers.end(), m) != markers.end();
955 Selection::selected (TimeAxisView* tv)
957 return tv->selected ();
961 Selection::selected (RegionView* rv)
963 return find (regions.begin(), regions.end(), rv) != regions.end();
967 Selection::selected (ControlPoint* cp)
969 return find (points.begin(), points.end(), cp) != points.end();
973 Selection::empty (bool internal_selection)
975 bool object_level_empty = regions.empty () &&
978 playlists.empty () &&
981 playlists.empty () &&
986 if (!internal_selection) {
987 return object_level_empty;
990 /* this is intended to really only apply when using a Selection
994 return object_level_empty && midi_notes.empty() && points.empty();
998 Selection::toggle (ControlPoint* cp)
1000 clear_time(); //enforce region/object exclusivity
1001 clear_tracks(); //enforce object/track exclusivity
1003 cp->set_selected (!cp->selected ());
1004 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1005 if (i == points.end()) {
1006 points.push_back (cp);
1011 PointsChanged (); /* EMIT SIGNAL */
1015 Selection::toggle (vector<ControlPoint*> const & cps)
1017 clear_time(); //enforce region/object exclusivity
1018 clear_tracks(); //enforce object/track exclusivity
1020 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1026 Selection::toggle (list<Selectable*> const & selectables)
1028 clear_time(); //enforce region/object exclusivity
1029 clear_tracks(); //enforce object/track exclusivity
1033 vector<RegionView*> rvs;
1034 vector<ControlPoint*> cps;
1036 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1037 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1039 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1042 fatal << _("programming error: ")
1043 << X_("unknown selectable type passed to Selection::toggle()")
1045 abort(); /*NOTREACHED*/
1059 Selection::set (list<Selectable*> const & selectables)
1061 clear_time (); //enforce region/object exclusivity
1062 clear_tracks(); //enforce object/track exclusivity
1069 Selection::add (PointSelection const & s)
1071 clear_time (); //enforce region/object exclusivity
1072 clear_tracks(); //enforce object/track exclusivity
1074 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1075 points.push_back (*i);
1080 Selection::add (list<Selectable*> const & selectables)
1082 clear_time (); //enforce region/object exclusivity
1083 clear_tracks(); //enforce object/track exclusivity
1087 vector<RegionView*> rvs;
1088 vector<ControlPoint*> cps;
1090 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1091 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1093 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1096 fatal << _("programming error: ")
1097 << X_("unknown selectable type passed to Selection::add()")
1099 abort(); /*NOTREACHED*/
1113 Selection::clear_points (bool with_signal)
1115 if (!points.empty()) {
1124 Selection::add (ControlPoint* cp)
1126 clear_time (); //enforce region/object exclusivity
1127 clear_tracks(); //enforce object/track exclusivity
1129 cp->set_selected (true);
1130 points.push_back (cp);
1131 PointsChanged (); /* EMIT SIGNAL */
1135 Selection::add (vector<ControlPoint*> const & cps)
1137 clear_time (); //enforce region/object exclusivity
1138 clear_tracks(); //enforce object/track exclusivity
1140 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1141 (*i)->set_selected (true);
1142 points.push_back (*i);
1144 PointsChanged (); /* EMIT SIGNAL */
1148 Selection::set (ControlPoint* cp)
1150 clear_time (); //enforce region/object exclusivity
1151 clear_tracks(); //enforce object/track exclusivity
1153 if (cp->selected () && points.size () == 1) {
1157 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1158 cp->line().nth (i)->set_selected (false);
1166 Selection::set (ArdourMarker* m)
1168 clear_time (); //enforce region/object exclusivity
1169 clear_tracks(); //enforce object/track exclusivity
1176 Selection::toggle (ArdourMarker* m)
1178 MarkerSelection::iterator i;
1180 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1188 Selection::remove (ArdourMarker* m)
1190 MarkerSelection::iterator i;
1192 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1199 Selection::add (ArdourMarker* m)
1201 clear_time (); //enforce region/object exclusivity
1202 clear_tracks(); //enforce object/track exclusivity
1204 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1205 markers.push_back (m);
1211 Selection::add (const list<ArdourMarker*>& m)
1213 clear_time (); //enforce region/object exclusivity
1214 clear_tracks(); //enforce object/track exclusivity
1216 markers.insert (markers.end(), m.begin(), m.end());
1224 MarkerSelection::range (framepos_t& s, framepos_t& e)
1229 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1231 if ((*i)->position() < s) {
1232 s = (*i)->position();
1235 if ((*i)->position() > e) {
1236 e = (*i)->position();
1240 s = std::min (s, e);
1241 e = std::max (s, e);
1245 Selection::get_state () const
1247 /* XXX: not complete; just sufficient to get track selection state
1248 so that re-opening plugin windows for editor mixer strips works
1252 XMLNode* node = new XMLNode (X_("Selection"));
1254 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1255 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1256 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1258 XMLNode* t = node->add_child (X_("RouteView"));
1259 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1261 XMLNode* t = node->add_child (X_("AutomationView"));
1262 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1263 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1267 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1268 XMLNode* r = node->add_child (X_("Region"));
1269 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1272 /* midi region views have thir own internal selection. */
1274 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1275 editor->get_per_region_note_selection (rid_notes);
1276 if (!rid_notes.empty()) {
1277 n = node->add_child (X_("MIDINote"));
1279 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1280 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1281 assert(n); // hint for clang static analysis
1282 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1284 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1285 XMLNode* nc = n->add_child(X_("note"));
1286 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1287 nc->add_property(X_("channel"), string(buf));
1289 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1290 nc->add_property(X_("time"), string(buf));
1292 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1293 nc->add_property(X_("note"), string(buf));
1295 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1296 nc->add_property(X_("length"), string(buf));
1298 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1299 nc->add_property(X_("velocity"), string(buf));
1301 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1302 nc->add_property(X_("off-velocity"), string(buf));
1306 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1307 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1310 XMLNode* r = node->add_child (X_("ControlPoint"));
1311 r->add_property (X_("type"), "track");
1312 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1313 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1314 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1316 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1317 r->add_property (X_("view-index"), string(buf));
1321 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1323 XMLNode* r = node->add_child (X_("ControlPoint"));
1324 r->add_property (X_("type"), "region");
1325 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1326 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1327 r->add_property (X_("view-index"), string(buf));
1332 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1333 XMLNode* t = node->add_child (X_("AudioRange"));
1334 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1335 t->add_property (X_("start"), string(buf));
1336 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1337 t->add_property (X_("end"), string(buf));
1340 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1341 XMLNode* t = node->add_child (X_("Marker"));
1344 Location* loc = editor->find_location_from_marker (*i, is_start);
1346 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1347 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1354 Selection::set_state (XMLNode const & node, int)
1356 if (node.name() != X_("Selection")) {
1361 clear_midi_notes ();
1367 XMLNodeList children = node.children ();
1368 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1369 if ((*i)->name() == X_("RouteView")) {
1371 XMLProperty const * prop_id = (*i)->property (X_("id"));
1373 PBD::ID id (prop_id->value ());
1374 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1379 } else if ((*i)->name() == X_("Region")) {
1380 XMLProperty const * prop_id = (*i)->property (X_("id"));
1382 PBD::ID id (prop_id->value ());
1385 editor->get_regionviews_by_id (id, rs);
1391 regionviews haven't been constructed - stash the region IDs
1392 so we can identify them in Editor::region_view_added ()
1394 regions.pending.push_back (id);
1397 } else if ((*i)->name() == X_("MIDINote")) {
1398 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1400 assert (prop_region_id);
1402 PBD::ID const id (prop_region_id->value ());
1405 editor->get_regionviews_by_id (id, rs); // there could be more than one
1407 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1408 XMLNodeList children = (*i)->children ();
1410 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1411 XMLProperty const * prop_channel = (*ci)->property (X_("channel"));
1412 XMLProperty const * prop_time = (*ci)->property (X_("time"));
1413 XMLProperty const * prop_note = (*ci)->property (X_("note"));
1414 XMLProperty const * prop_length = (*ci)->property (X_("length"));
1415 XMLProperty const * prop_velocity = (*ci)->property (X_("velocity"));
1416 XMLProperty const * prop_off_velocity = (*ci)->property (X_("off-velocity"));
1418 assert (prop_channel);
1421 assert (prop_length);
1422 assert (prop_velocity);
1423 assert (prop_off_velocity);
1425 uint8_t channel = atoi(prop_channel->value());
1426 Evoral::Beats time (atof(prop_time->value()));
1427 Evoral::Beats length (atof(prop_length->value()));
1428 uint8_t note = atoi(prop_note->value());
1429 uint8_t velocity = atoi(prop_velocity->value());
1430 uint8_t off_velocity = atoi(prop_off_velocity->value());
1431 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1432 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1433 the_note->set_off_velocity (off_velocity);
1435 notes.push_back (the_note);
1438 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1439 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1441 mrv->select_notes(notes);
1446 /* regionviews containing these notes don't yet exist on the canvas.*/
1447 pending_midi_note_selection.push_back (make_pair (id, notes));
1450 } else if ((*i)->name() == X_("ControlPoint")) {
1451 XMLProperty const * prop_type = (*i)->property (X_("type"));
1455 if (prop_type->value () == "track") {
1457 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1458 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1459 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1460 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1462 assert (prop_route_id);
1463 assert (prop_alist_id);
1464 assert (prop_parameter);
1465 assert (prop_view_index);
1467 PBD::ID route_id (prop_route_id->value ());
1468 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1469 vector <ControlPoint *> cps;
1472 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1474 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1475 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1476 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1477 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1489 } else if (prop_type->value () == "region") {
1490 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1491 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1493 if (!prop_region_id || !prop_view_index) {
1497 PBD::ID region_id (prop_region_id->value ());
1499 editor->get_regionviews_by_id (region_id, rs);
1502 vector <ControlPoint *> cps;
1503 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1504 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1506 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1507 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1520 } else if ((*i)->name() == X_("AudioRange")) {
1521 XMLProperty const * prop_start = (*i)->property (X_("start"));
1522 XMLProperty const * prop_end = (*i)->property (X_("end"));
1524 assert (prop_start);
1527 framepos_t s (atol (prop_start->value ().c_str()));
1528 framepos_t e (atol (prop_end->value ().c_str()));
1530 set_preserving_all_ranges (s, e);
1532 } else if ((*i)->name() == X_("AutomationView")) {
1534 XMLProperty const * prop_id = (*i)->property (X_("id"));
1535 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1538 assert (prop_parameter);
1540 PBD::ID id (prop_id->value ());
1541 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1544 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1546 /* the automation could be for an entity that was never saved
1547 in the session file. Don't freak out if we can't find
1556 } else if ((*i)->name() == X_("Marker")) {
1558 XMLProperty const * prop_id = (*i)->property (X_("id"));
1559 XMLProperty const * prop_start = (*i)->property (X_("start"));
1561 assert (prop_start);
1563 PBD::ID id (prop_id->value ());
1564 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1577 Selection::remove_regions (TimeAxisView* t)
1579 RegionSelection::iterator i = regions.begin();
1580 while (i != regions.end ()) {
1581 RegionSelection::iterator tmp = i;
1584 if (&(*i)->get_time_axis_view() == t) {
1593 Selection::block_tracks_changed (bool yn)
1595 _no_tracks_changed = yn;