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 "audio_region_view.h"
31 #include "gui_thread.h"
32 #include "midi_cut_buffer.h"
33 #include "region_gain_line.h"
34 #include "region_view.h"
35 #include "selection.h"
36 #include "selection_templates.h"
37 #include "time_axis_view.h"
38 #include "automation_time_axis.h"
39 #include "public_editor.h"
40 #include "control_point.h"
45 using namespace ARDOUR;
48 struct AudioRangeComparator {
49 bool operator()(AudioRange a, AudioRange b) {
50 return a.start < b.start;
54 Selection::Selection (const PublicEditor* e)
58 , _no_tracks_changed (false)
62 /* we have disambiguate which remove() for the compiler */
64 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
65 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
67 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
68 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
70 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
71 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
76 Selection::operator= (const Selection& other)
79 regions = other.regions;
80 tracks = other.tracks;
83 midi_regions = other.midi_regions;
84 midi_notes = other.midi_notes;
91 operator== (const Selection& a, const Selection& b)
93 return a.regions == b.regions &&
94 a.tracks == b.tracks &&
97 a.playlists == b.playlists &&
98 a.midi_notes == b.midi_notes &&
99 a.midi_regions == b.midi_regions;
102 /** Clear everything from the Selection */
113 clear_midi_regions ();
115 pending_midi_note_selection.clear();
119 Selection::clear_objects (bool with_signal)
121 clear_regions (with_signal);
122 clear_points (with_signal);
123 clear_lines(with_signal);
124 clear_playlists (with_signal);
125 clear_midi_notes (with_signal);
126 clear_midi_regions (with_signal);
130 Selection::clear_tracks (bool with_signal)
132 if (!tracks.empty()) {
133 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
134 (*x)->set_selected (false);
137 if (!_no_tracks_changed && with_signal) {
144 Selection::clear_time (bool with_signal)
153 Selection::dump_region_layers()
155 cerr << "region selection layer dump" << endl;
156 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
157 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
163 Selection::clear_regions (bool with_signal)
165 if (!regions.empty()) {
166 regions.clear_all ();
174 Selection::clear_midi_notes (bool with_signal)
176 if (!midi_notes.empty()) {
177 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
186 // clear note selections for MRV's that have note selections
187 // this will cause the MRV to be removed from the list
188 for (MidiRegionSelection::iterator i = midi_regions.begin();
189 i != midi_regions.end();) {
190 MidiRegionSelection::iterator tmp = i;
192 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
194 mrv->clear_selection();
201 Selection::clear_midi_regions (bool with_signal)
203 if (!midi_regions.empty()) {
204 midi_regions.clear ();
206 MidiRegionsChanged ();
212 Selection::clear_playlists (bool with_signal)
214 /* Selections own their playlists */
216 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
217 /* selections own their own regions, which are copies of the "originals". make them go away */
218 (*i)->drop_regions ();
222 if (!playlists.empty()) {
231 Selection::clear_lines (bool with_signal)
233 if (!lines.empty()) {
242 Selection::clear_markers (bool with_signal)
244 if (!markers.empty()) {
253 Selection::toggle (boost::shared_ptr<Playlist> pl)
255 clear_time(); //enforce object/range exclusivity
256 clear_tracks(); //enforce object/track exclusivity
258 PlaylistSelection::iterator i;
260 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
262 playlists.push_back(pl);
271 Selection::toggle (const TrackViewList& track_list)
273 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
279 Selection::toggle (TimeAxisView* track)
281 TrackSelection::iterator i;
283 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
284 track->set_selected (true);
285 tracks.push_back (track);
287 track->set_selected (false);
291 if (!_no_tracks_changed) {
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 (const TrackViewList& track_list)
432 clear_objects(); //enforce object/range exclusivity
434 TrackViewList added = tracks.add (track_list);
436 if (!added.empty()) {
437 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
438 (*x)->set_selected (true);
440 if (!_no_tracks_changed) {
447 Selection::add (TimeAxisView* track)
449 clear_objects(); //enforce object/range exclusivity
452 track->set_selected (true);
453 tr.push_back (track);
458 Selection::add (const MidiNoteSelection& midi_list)
460 clear_time(); //enforce object/range exclusivity
461 clear_tracks(); //enforce object/track exclusivity
463 const MidiNoteSelection::const_iterator b = midi_list.begin();
464 const MidiNoteSelection::const_iterator e = midi_list.end();
466 if (!midi_list.empty()) {
467 midi_notes.insert (midi_notes.end(), b, e);
473 Selection::add (MidiCutBuffer* midi)
475 /* we take ownership of the MCB */
477 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
478 midi_notes.push_back (midi);
484 Selection::add (vector<RegionView*>& v)
486 clear_time(); //enforce object/range exclusivity
487 clear_tracks(); //enforce object/track exclusivity
489 /* XXX This method or the add (const RegionSelection&) needs to go
492 bool changed = false;
494 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
495 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
496 changed = regions.add ((*i));
506 Selection::add (const RegionSelection& rs)
508 clear_time(); //enforce object/range exclusivity
509 clear_tracks(); //enforce object/track exclusivity
511 /* XXX This method or the add (const vector<RegionView*>&) needs to go
514 bool changed = false;
516 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
517 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
518 changed = regions.add ((*i));
528 Selection::add (RegionView* r)
530 clear_time(); //enforce object/range exclusivity
531 clear_tracks(); //enforce object/track exclusivity
533 if (find (regions.begin(), regions.end(), r) == regions.end()) {
534 bool changed = regions.add (r);
542 Selection::add (MidiRegionView* mrv)
544 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
546 clear_time(); //enforce object/range exclusivity
547 clear_tracks(); //enforce object/track exclusivity
549 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
550 midi_regions.push_back (mrv);
551 /* XXX should we do this? */
552 MidiRegionsChanged ();
557 Selection::add (framepos_t start, framepos_t end)
559 clear_objects(); //enforce object/range exclusivity
561 AudioRangeComparator cmp;
563 /* XXX this implementation is incorrect */
565 time.push_back (AudioRange (start, end, ++next_time_id));
575 Selection::move_time (framecnt_t distance)
581 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
582 (*i).start += distance;
583 (*i).end += distance;
590 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
592 clear_objects(); //enforce object/range exclusivity
594 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
595 if ((*i).id == sid) {
597 time.push_back (AudioRange(start,end, sid));
599 /* don't consolidate here */
602 AudioRangeComparator cmp;
612 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
614 clear_time(); //enforce object/range exclusivity
615 clear_tracks(); //enforce object/track exclusivity
617 boost::shared_ptr<ARDOUR::AutomationList> al
618 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
620 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
624 /* The original may change so we must store a copy (not a pointer) here.
625 * e.g AutomationLine rewrites the list with gain mapping.
626 * the downside is that we can't perfom duplicate checks.
627 * This code was changed in response to #6842
629 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
634 Selection::remove (TimeAxisView* track)
636 list<TimeAxisView*>::iterator i;
637 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
638 track->set_selected (false);
640 if (!_no_tracks_changed) {
647 Selection::remove (const TrackViewList& track_list)
649 bool changed = false;
651 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
653 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
654 if (x != tracks.end()) {
655 (*i)->set_selected (false);
662 if (!_no_tracks_changed) {
669 Selection::remove (ControlPoint* p)
671 PointSelection::iterator i = find (points.begin(), points.end(), p);
672 if (i != points.end ()) {
678 Selection::remove (const MidiNoteSelection& midi_list)
680 bool changed = false;
682 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
684 MidiNoteSelection::iterator x;
686 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
687 midi_notes.erase (x);
698 Selection::remove (MidiCutBuffer* midi)
700 MidiNoteSelection::iterator x;
702 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
703 /* remember that we own the MCB */
705 midi_notes.erase (x);
711 Selection::remove (boost::shared_ptr<Playlist> track)
713 list<boost::shared_ptr<Playlist> >::iterator i;
714 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
721 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
723 bool changed = false;
725 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
727 list<boost::shared_ptr<Playlist> >::iterator x;
729 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
741 Selection::remove (RegionView* r)
743 if (regions.remove (r)) {
749 Selection::remove (MidiRegionView* mrv)
751 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
753 MidiRegionSelection::iterator x;
755 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
756 midi_regions.erase (x);
757 MidiRegionsChanged ();
762 Selection::remove (uint32_t selection_id)
768 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
769 if ((*i).id == selection_id) {
779 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
784 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
786 AutomationSelection::iterator i;
787 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
794 Selection::set (TimeAxisView* track)
796 clear_objects (); //enforce object/range exclusivity
797 clear_tracks (false);
802 Selection::set (const TrackViewList& track_list)
804 clear_objects(); //enforce object/range exclusivity
805 clear_tracks (false);
810 Selection::set (const MidiNoteSelection& midi_list)
812 clear_time (); //enforce region/object exclusivity
813 clear_tracks(); //enforce object/track exclusivity
819 Selection::set (boost::shared_ptr<Playlist> playlist)
821 clear_time (); //enforce region/object exclusivity
822 clear_tracks(); //enforce object/track exclusivity
828 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
830 clear_time(); //enforce region/object exclusivity
836 Selection::set (const RegionSelection& rs)
838 clear_time(); //enforce region/object exclusivity
839 clear_tracks(); //enforce object/track exclusivity
842 RegionsChanged(); /* EMIT SIGNAL */
846 Selection::set (MidiRegionView* mrv)
848 clear_time(); //enforce region/object exclusivity
849 clear_tracks(); //enforce object/track exclusivity
855 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
857 clear_time(); //enforce region/object exclusivity
858 clear_tracks(); //enforce object/track exclusivity
864 Selection::set (vector<RegionView*>& v)
866 clear_time(); //enforce region/object exclusivity
867 clear_tracks(); //enforce object/track exclusivity
873 /** Set the start and end time of the time selection, without changing
874 * the list of tracks it applies to.
877 Selection::set (framepos_t start, framepos_t end)
879 clear_objects(); //enforce region/object exclusivity
882 if ((start == 0 && end == 0) || end < start) {
887 time.push_back (AudioRange (start, end, ++next_time_id));
889 /* reuse the first entry, and remove all the rest */
891 while (time.size() > 1) {
894 time.front().start = start;
895 time.front().end = end;
902 return time.front().id;
905 /** Set the start and end of the range selection. If more than one range
906 * is currently selected, the start of the earliest range and the end of the
907 * latest range are set. If no range is currently selected, this method
908 * selects a single range from start to end.
910 * @param start New start time.
911 * @param end New end time.
914 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
916 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 time.sort (AudioRangeComparator ());
926 time.front().start = start;
927 time.back().end = end;
936 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
938 clear_time(); //enforce region/object exclusivity
939 clear_tracks(); //enforce object/track exclusivity
946 Selection::selected (ArdourMarker* m)
948 return find (markers.begin(), markers.end(), m) != markers.end();
952 Selection::selected (TimeAxisView* tv)
954 return tv->selected ();
958 Selection::selected (RegionView* rv)
960 return find (regions.begin(), regions.end(), rv) != regions.end();
964 Selection::selected (ControlPoint* cp)
966 return find (points.begin(), points.end(), cp) != points.end();
970 Selection::empty (bool internal_selection)
972 bool object_level_empty = regions.empty () &&
975 playlists.empty () &&
978 playlists.empty () &&
983 if (!internal_selection) {
984 return object_level_empty;
987 /* this is intended to really only apply when using a Selection
991 return object_level_empty && midi_notes.empty() && points.empty();
995 Selection::toggle (ControlPoint* cp)
997 clear_time(); //enforce region/object exclusivity
998 clear_tracks(); //enforce object/track exclusivity
1000 cp->set_selected (!cp->selected ());
1001 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1002 if (i == points.end()) {
1003 points.push_back (cp);
1008 PointsChanged (); /* EMIT SIGNAL */
1012 Selection::toggle (vector<ControlPoint*> const & cps)
1014 clear_time(); //enforce region/object exclusivity
1015 clear_tracks(); //enforce object/track exclusivity
1017 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1023 Selection::toggle (list<Selectable*> const & selectables)
1025 clear_time(); //enforce region/object exclusivity
1026 clear_tracks(); //enforce object/track exclusivity
1030 vector<RegionView*> rvs;
1031 vector<ControlPoint*> cps;
1033 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1034 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1036 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1039 fatal << _("programming error: ")
1040 << X_("unknown selectable type passed to Selection::toggle()")
1042 abort(); /*NOTREACHED*/
1056 Selection::set (list<Selectable*> const & selectables)
1058 clear_time (); //enforce region/object exclusivity
1059 clear_tracks(); //enforce object/track exclusivity
1066 Selection::add (PointSelection const & s)
1068 clear_time (); //enforce region/object exclusivity
1069 clear_tracks(); //enforce object/track exclusivity
1071 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1072 points.push_back (*i);
1077 Selection::add (list<Selectable*> const & selectables)
1079 clear_time (); //enforce region/object exclusivity
1080 clear_tracks(); //enforce object/track exclusivity
1084 vector<RegionView*> rvs;
1085 vector<ControlPoint*> cps;
1087 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1088 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1090 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1093 fatal << _("programming error: ")
1094 << X_("unknown selectable type passed to Selection::add()")
1096 abort(); /*NOTREACHED*/
1110 Selection::clear_points (bool with_signal)
1112 if (!points.empty()) {
1121 Selection::add (ControlPoint* cp)
1123 clear_time (); //enforce region/object exclusivity
1124 clear_tracks(); //enforce object/track exclusivity
1126 cp->set_selected (true);
1127 points.push_back (cp);
1128 PointsChanged (); /* EMIT SIGNAL */
1132 Selection::add (vector<ControlPoint*> const & cps)
1134 clear_time (); //enforce region/object exclusivity
1135 clear_tracks(); //enforce object/track exclusivity
1137 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1138 (*i)->set_selected (true);
1139 points.push_back (*i);
1141 PointsChanged (); /* EMIT SIGNAL */
1145 Selection::set (ControlPoint* cp)
1147 clear_time (); //enforce region/object exclusivity
1148 clear_tracks(); //enforce object/track exclusivity
1150 if (cp->selected () && points.size () == 1) {
1154 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1155 cp->line().nth (i)->set_selected (false);
1163 Selection::set (ArdourMarker* m)
1165 clear_time (); //enforce region/object exclusivity
1166 clear_tracks(); //enforce object/track exclusivity
1173 Selection::toggle (ArdourMarker* m)
1175 MarkerSelection::iterator i;
1177 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1185 Selection::remove (ArdourMarker* m)
1187 MarkerSelection::iterator i;
1189 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1196 Selection::add (ArdourMarker* m)
1198 clear_time (); //enforce region/object exclusivity
1199 clear_tracks(); //enforce object/track exclusivity
1201 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1202 markers.push_back (m);
1208 Selection::add (const list<ArdourMarker*>& m)
1210 clear_time (); //enforce region/object exclusivity
1211 clear_tracks(); //enforce object/track exclusivity
1213 markers.insert (markers.end(), m.begin(), m.end());
1221 MarkerSelection::range (framepos_t& s, framepos_t& e)
1226 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1228 if ((*i)->position() < s) {
1229 s = (*i)->position();
1232 if ((*i)->position() > e) {
1233 e = (*i)->position();
1237 s = std::min (s, e);
1238 e = std::max (s, e);
1242 Selection::get_state () const
1244 /* XXX: not complete; just sufficient to get track selection state
1245 so that re-opening plugin windows for editor mixer strips works
1249 XMLNode* node = new XMLNode (X_("Selection"));
1251 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1252 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1253 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1255 XMLNode* t = node->add_child (X_("RouteView"));
1256 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1258 XMLNode* t = node->add_child (X_("AutomationView"));
1259 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1260 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1264 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1265 XMLNode* r = node->add_child (X_("Region"));
1266 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1269 /* midi region views have thir own internal selection. */
1271 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1272 editor->get_per_region_note_selection (rid_notes);
1273 if (!rid_notes.empty()) {
1274 n = node->add_child (X_("MIDINote"));
1276 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1277 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1278 assert(n); // hint for clang static analysis
1279 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1281 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1282 XMLNode* nc = n->add_child(X_("note"));
1283 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1284 nc->add_property(X_("channel"), string(buf));
1286 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1287 nc->add_property(X_("time"), string(buf));
1289 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1290 nc->add_property(X_("note"), string(buf));
1292 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1293 nc->add_property(X_("length"), string(buf));
1295 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1296 nc->add_property(X_("velocity"), string(buf));
1298 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1299 nc->add_property(X_("off-velocity"), string(buf));
1303 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1304 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1307 XMLNode* r = node->add_child (X_("ControlPoint"));
1308 r->add_property (X_("type"), "track");
1309 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1310 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1311 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1313 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1314 r->add_property (X_("view-index"), string(buf));
1318 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1320 XMLNode* r = node->add_child (X_("ControlPoint"));
1321 r->add_property (X_("type"), "region");
1322 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1323 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1324 r->add_property (X_("view-index"), string(buf));
1329 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1330 XMLNode* t = node->add_child (X_("AudioRange"));
1331 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1332 t->add_property (X_("start"), string(buf));
1333 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1334 t->add_property (X_("end"), string(buf));
1337 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1338 XMLNode* t = node->add_child (X_("Marker"));
1341 Location* loc = editor->find_location_from_marker (*i, is_start);
1343 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1344 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1351 Selection::set_state (XMLNode const & node, int)
1353 if (node.name() != X_("Selection")) {
1358 clear_midi_notes ();
1364 XMLNodeList children = node.children ();
1365 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1366 if ((*i)->name() == X_("RouteView")) {
1368 XMLProperty const * prop_id = (*i)->property (X_("id"));
1370 PBD::ID id (prop_id->value ());
1371 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1376 } else if ((*i)->name() == X_("Region")) {
1377 XMLProperty const * prop_id = (*i)->property (X_("id"));
1379 PBD::ID id (prop_id->value ());
1382 editor->get_regionviews_by_id (id, rs);
1388 regionviews haven't been constructed - stash the region IDs
1389 so we can identify them in Editor::region_view_added ()
1391 regions.pending.push_back (id);
1394 } else if ((*i)->name() == X_("MIDINote")) {
1395 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1397 assert (prop_region_id);
1399 PBD::ID const id (prop_region_id->value ());
1402 editor->get_regionviews_by_id (id, rs); // there could be more than one
1404 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1405 XMLNodeList children = (*i)->children ();
1407 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1408 XMLProperty const * prop_channel = (*ci)->property (X_("channel"));
1409 XMLProperty const * prop_time = (*ci)->property (X_("time"));
1410 XMLProperty const * prop_note = (*ci)->property (X_("note"));
1411 XMLProperty const * prop_length = (*ci)->property (X_("length"));
1412 XMLProperty const * prop_velocity = (*ci)->property (X_("velocity"));
1413 XMLProperty const * prop_off_velocity = (*ci)->property (X_("off-velocity"));
1415 assert (prop_channel);
1418 assert (prop_length);
1419 assert (prop_velocity);
1420 assert (prop_off_velocity);
1422 uint8_t channel = atoi(prop_channel->value());
1423 Evoral::Beats time (atof(prop_time->value()));
1424 Evoral::Beats length (atof(prop_length->value()));
1425 uint8_t note = atoi(prop_note->value());
1426 uint8_t velocity = atoi(prop_velocity->value());
1427 uint8_t off_velocity = atoi(prop_off_velocity->value());
1428 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1429 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1430 the_note->set_off_velocity (off_velocity);
1432 notes.push_back (the_note);
1435 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1436 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1438 mrv->select_notes(notes);
1443 /* regionviews containing these notes don't yet exist on the canvas.*/
1444 pending_midi_note_selection.push_back (make_pair (id, notes));
1447 } else if ((*i)->name() == X_("ControlPoint")) {
1448 XMLProperty const * prop_type = (*i)->property (X_("type"));
1452 if (prop_type->value () == "track") {
1454 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1455 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1456 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1457 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1459 assert (prop_route_id);
1460 assert (prop_alist_id);
1461 assert (prop_parameter);
1462 assert (prop_view_index);
1464 PBD::ID route_id (prop_route_id->value ());
1465 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1466 vector <ControlPoint *> cps;
1469 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1471 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1472 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1473 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1474 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1486 } else if (prop_type->value () == "region") {
1487 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1488 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1490 if (!prop_region_id || !prop_view_index) {
1494 PBD::ID region_id (prop_region_id->value ());
1496 editor->get_regionviews_by_id (region_id, rs);
1499 vector <ControlPoint *> cps;
1500 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1501 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1503 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1504 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1517 } else if ((*i)->name() == X_("AudioRange")) {
1518 XMLProperty const * prop_start = (*i)->property (X_("start"));
1519 XMLProperty const * prop_end = (*i)->property (X_("end"));
1521 assert (prop_start);
1524 framepos_t s (atol (prop_start->value ().c_str()));
1525 framepos_t e (atol (prop_end->value ().c_str()));
1527 set_preserving_all_ranges (s, e);
1529 } else if ((*i)->name() == X_("AutomationView")) {
1531 XMLProperty const * prop_id = (*i)->property (X_("id"));
1532 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1535 assert (prop_parameter);
1537 PBD::ID id (prop_id->value ());
1538 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1541 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1543 /* the automation could be for an entity that was never saved
1544 in the session file. Don't freak out if we can't find
1553 } else if ((*i)->name() == X_("Marker")) {
1555 XMLProperty const * prop_id = (*i)->property (X_("id"));
1556 XMLProperty const * prop_start = (*i)->property (X_("start"));
1558 assert (prop_start);
1560 PBD::ID id (prop_id->value ());
1561 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1574 Selection::remove_regions (TimeAxisView* t)
1576 RegionSelection::iterator i = regions.begin();
1577 while (i != regions.end ()) {
1578 RegionSelection::iterator tmp = i;
1581 if (&(*i)->get_time_axis_view() == t) {
1590 Selection::block_tracks_changed (bool yn)
1592 _no_tracks_changed = yn;