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;
623 if (find (lines.begin(), lines.end(), al) == lines.end()) {
624 lines.push_back (al);
630 Selection::remove (TimeAxisView* track)
632 list<TimeAxisView*>::iterator i;
633 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
634 track->set_selected (false);
636 if (!_no_tracks_changed) {
643 Selection::remove (const TrackViewList& track_list)
645 bool changed = false;
647 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
649 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
650 if (x != tracks.end()) {
651 (*i)->set_selected (false);
658 if (!_no_tracks_changed) {
665 Selection::remove (ControlPoint* p)
667 PointSelection::iterator i = find (points.begin(), points.end(), p);
668 if (i != points.end ()) {
674 Selection::remove (const MidiNoteSelection& midi_list)
676 bool changed = false;
678 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
680 MidiNoteSelection::iterator x;
682 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
683 midi_notes.erase (x);
694 Selection::remove (MidiCutBuffer* midi)
696 MidiNoteSelection::iterator x;
698 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
699 /* remember that we own the MCB */
701 midi_notes.erase (x);
707 Selection::remove (boost::shared_ptr<Playlist> track)
709 list<boost::shared_ptr<Playlist> >::iterator i;
710 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
717 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
719 bool changed = false;
721 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
723 list<boost::shared_ptr<Playlist> >::iterator x;
725 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
737 Selection::remove (RegionView* r)
739 if (regions.remove (r)) {
745 Selection::remove (MidiRegionView* mrv)
747 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
749 MidiRegionSelection::iterator x;
751 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
752 midi_regions.erase (x);
753 MidiRegionsChanged ();
758 Selection::remove (uint32_t selection_id)
764 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
765 if ((*i).id == selection_id) {
775 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
780 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
782 AutomationSelection::iterator i;
783 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
790 Selection::set (TimeAxisView* track)
792 clear_objects (); //enforce object/range exclusivity
793 clear_tracks (false);
798 Selection::set (const TrackViewList& track_list)
800 clear_objects(); //enforce object/range exclusivity
801 clear_tracks (false);
806 Selection::set (const MidiNoteSelection& midi_list)
808 clear_time (); //enforce region/object exclusivity
809 clear_tracks(); //enforce object/track exclusivity
815 Selection::set (boost::shared_ptr<Playlist> playlist)
817 clear_time (); //enforce region/object exclusivity
818 clear_tracks(); //enforce object/track exclusivity
824 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
826 clear_time(); //enforce region/object exclusivity
832 Selection::set (const RegionSelection& rs)
834 clear_time(); //enforce region/object exclusivity
835 clear_tracks(); //enforce object/track exclusivity
838 RegionsChanged(); /* EMIT SIGNAL */
842 Selection::set (MidiRegionView* mrv)
844 clear_time(); //enforce region/object exclusivity
845 clear_tracks(); //enforce object/track exclusivity
851 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
853 clear_time(); //enforce region/object exclusivity
854 clear_tracks(); //enforce object/track exclusivity
860 Selection::set (vector<RegionView*>& v)
862 clear_time(); //enforce region/object exclusivity
863 clear_tracks(); //enforce object/track exclusivity
869 /** Set the start and end time of the time selection, without changing
870 * the list of tracks it applies to.
873 Selection::set (framepos_t start, framepos_t end)
875 clear_objects(); //enforce region/object exclusivity
878 if ((start == 0 && end == 0) || end < start) {
883 time.push_back (AudioRange (start, end, ++next_time_id));
885 /* reuse the first entry, and remove all the rest */
887 while (time.size() > 1) {
890 time.front().start = start;
891 time.front().end = end;
898 return time.front().id;
901 /** Set the start and end of the range selection. If more than one range
902 * is currently selected, the start of the earliest range and the end of the
903 * latest range are set. If no range is currently selected, this method
904 * selects a single range from start to end.
906 * @param start New start time.
907 * @param end New end time.
910 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
912 clear_objects(); //enforce region/object exclusivity
914 if ((start == 0 && end == 0) || (end < start)) {
919 time.push_back (AudioRange (start, end, ++next_time_id));
921 time.sort (AudioRangeComparator ());
922 time.front().start = start;
923 time.back().end = end;
932 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
934 clear_time(); //enforce region/object exclusivity
935 clear_tracks(); //enforce object/track exclusivity
942 Selection::selected (ArdourMarker* m)
944 return find (markers.begin(), markers.end(), m) != markers.end();
948 Selection::selected (TimeAxisView* tv)
950 return tv->get_selected ();
954 Selection::selected (RegionView* rv)
956 return find (regions.begin(), regions.end(), rv) != regions.end();
960 Selection::selected (ControlPoint* cp)
962 return find (points.begin(), points.end(), cp) != points.end();
966 Selection::empty (bool internal_selection)
968 bool object_level_empty = regions.empty () &&
971 playlists.empty () &&
974 playlists.empty () &&
979 if (!internal_selection) {
980 return object_level_empty;
983 /* this is intended to really only apply when using a Selection
987 return object_level_empty && midi_notes.empty() && points.empty();
991 Selection::toggle (ControlPoint* cp)
993 clear_time(); //enforce region/object exclusivity
994 clear_tracks(); //enforce object/track exclusivity
996 cp->set_selected (!cp->get_selected ());
997 PointSelection::iterator i = find (points.begin(), points.end(), cp);
998 if (i == points.end()) {
999 points.push_back (cp);
1004 PointsChanged (); /* EMIT SIGNAL */
1008 Selection::toggle (vector<ControlPoint*> const & cps)
1010 clear_time(); //enforce region/object exclusivity
1011 clear_tracks(); //enforce object/track exclusivity
1013 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1019 Selection::toggle (list<Selectable*> const & selectables)
1021 clear_time(); //enforce region/object exclusivity
1022 clear_tracks(); //enforce object/track exclusivity
1026 vector<RegionView*> rvs;
1027 vector<ControlPoint*> cps;
1029 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1030 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1032 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1035 fatal << _("programming error: ")
1036 << X_("unknown selectable type passed to Selection::toggle()")
1038 abort(); /*NOTREACHED*/
1052 Selection::set (list<Selectable*> const & selectables)
1054 clear_time (); //enforce region/object exclusivity
1055 clear_tracks(); //enforce object/track exclusivity
1062 Selection::add (PointSelection const & s)
1064 clear_time (); //enforce region/object exclusivity
1065 clear_tracks(); //enforce object/track exclusivity
1067 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1068 points.push_back (*i);
1073 Selection::add (list<Selectable*> const & selectables)
1075 clear_time (); //enforce region/object exclusivity
1076 clear_tracks(); //enforce object/track exclusivity
1080 vector<RegionView*> rvs;
1081 vector<ControlPoint*> cps;
1083 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1084 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1086 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1089 fatal << _("programming error: ")
1090 << X_("unknown selectable type passed to Selection::add()")
1092 abort(); /*NOTREACHED*/
1106 Selection::clear_points (bool with_signal)
1108 if (!points.empty()) {
1117 Selection::add (ControlPoint* cp)
1119 clear_time (); //enforce region/object exclusivity
1120 clear_tracks(); //enforce object/track exclusivity
1122 cp->set_selected (true);
1123 points.push_back (cp);
1124 PointsChanged (); /* EMIT SIGNAL */
1128 Selection::add (vector<ControlPoint*> const & cps)
1130 clear_time (); //enforce region/object exclusivity
1131 clear_tracks(); //enforce object/track exclusivity
1133 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1134 (*i)->set_selected (true);
1135 points.push_back (*i);
1137 PointsChanged (); /* EMIT SIGNAL */
1141 Selection::set (ControlPoint* cp)
1143 clear_time (); //enforce region/object exclusivity
1144 clear_tracks(); //enforce object/track exclusivity
1146 if (cp->get_selected () && points.size () == 1) {
1150 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1151 cp->line().nth (i)->set_selected (false);
1159 Selection::set (ArdourMarker* m)
1161 clear_time (); //enforce region/object exclusivity
1162 clear_tracks(); //enforce object/track exclusivity
1169 Selection::toggle (ArdourMarker* m)
1171 MarkerSelection::iterator i;
1173 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1181 Selection::remove (ArdourMarker* m)
1183 MarkerSelection::iterator i;
1185 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1192 Selection::add (ArdourMarker* m)
1194 clear_time (); //enforce region/object exclusivity
1195 clear_tracks(); //enforce object/track exclusivity
1197 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1198 markers.push_back (m);
1204 Selection::add (const list<ArdourMarker*>& m)
1206 clear_time (); //enforce region/object exclusivity
1207 clear_tracks(); //enforce object/track exclusivity
1209 markers.insert (markers.end(), m.begin(), m.end());
1217 MarkerSelection::range (framepos_t& s, framepos_t& e)
1222 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1224 if ((*i)->position() < s) {
1225 s = (*i)->position();
1228 if ((*i)->position() > e) {
1229 e = (*i)->position();
1233 s = std::min (s, e);
1234 e = std::max (s, e);
1238 Selection::get_state () const
1240 /* XXX: not complete; just sufficient to get track selection state
1241 so that re-opening plugin windows for editor mixer strips works
1245 XMLNode* node = new XMLNode (X_("Selection"));
1247 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1248 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1249 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1251 XMLNode* t = node->add_child (X_("RouteView"));
1252 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1254 XMLNode* t = node->add_child (X_("AutomationView"));
1255 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1256 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1260 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1261 XMLNode* r = node->add_child (X_("Region"));
1262 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1265 /* midi region views have thir own internal selection. */
1267 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1268 editor->get_per_region_note_selection (rid_notes);
1269 if (!rid_notes.empty()) {
1270 n = node->add_child (X_("MIDINote"));
1272 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1273 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1274 assert(n); // hint for clang static analysis
1275 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1277 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1278 XMLNode* nc = n->add_child(X_("note"));
1279 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1280 nc->add_property(X_("channel"), string(buf));
1282 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1283 nc->add_property(X_("time"), string(buf));
1285 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1286 nc->add_property(X_("note"), string(buf));
1288 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1289 nc->add_property(X_("length"), string(buf));
1291 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1292 nc->add_property(X_("velocity"), string(buf));
1294 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1295 nc->add_property(X_("off-velocity"), string(buf));
1299 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1300 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1303 XMLNode* r = node->add_child (X_("ControlPoint"));
1304 r->add_property (X_("type"), "track");
1305 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1306 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1307 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1309 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1310 r->add_property (X_("view-index"), string(buf));
1314 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1316 XMLNode* r = node->add_child (X_("ControlPoint"));
1317 r->add_property (X_("type"), "region");
1318 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1319 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1320 r->add_property (X_("view-index"), string(buf));
1325 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1326 XMLNode* t = node->add_child (X_("AudioRange"));
1327 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1328 t->add_property (X_("start"), string(buf));
1329 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1330 t->add_property (X_("end"), string(buf));
1333 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1334 XMLNode* t = node->add_child (X_("Marker"));
1337 Location* loc = editor->find_location_from_marker (*i, is_start);
1339 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1340 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1347 Selection::set_state (XMLNode const & node, int)
1349 if (node.name() != X_("Selection")) {
1354 clear_midi_notes ();
1360 XMLNodeList children = node.children ();
1361 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1362 if ((*i)->name() == X_("RouteView")) {
1364 XMLProperty* prop_id = (*i)->property (X_("id"));
1366 PBD::ID id (prop_id->value ());
1367 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1372 } else if ((*i)->name() == X_("Region")) {
1373 XMLProperty* prop_id = (*i)->property (X_("id"));
1375 PBD::ID id (prop_id->value ());
1378 editor->get_regionviews_by_id (id, rs);
1384 regionviews haven't been constructed - stash the region IDs
1385 so we can identify them in Editor::region_view_added ()
1387 regions.pending.push_back (id);
1390 } else if ((*i)->name() == X_("MIDINote")) {
1391 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1393 assert (prop_region_id);
1395 PBD::ID const id (prop_region_id->value ());
1398 editor->get_regionviews_by_id (id, rs); // there could be more than one
1400 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1401 XMLNodeList children = (*i)->children ();
1403 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1404 XMLProperty* prop_channel = (*ci)->property (X_("channel"));
1405 XMLProperty* prop_time = (*ci)->property (X_("time"));
1406 XMLProperty* prop_note = (*ci)->property (X_("note"));
1407 XMLProperty* prop_length = (*ci)->property (X_("length"));
1408 XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
1409 XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
1411 assert (prop_channel);
1414 assert (prop_length);
1415 assert (prop_velocity);
1416 assert (prop_off_velocity);
1418 uint8_t channel = atoi(prop_channel->value());
1419 Evoral::Beats time (atof(prop_time->value()));
1420 Evoral::Beats length (atof(prop_length->value()));
1421 uint8_t note = atoi(prop_note->value());
1422 uint8_t velocity = atoi(prop_velocity->value());
1423 uint8_t off_velocity = atoi(prop_off_velocity->value());
1424 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1425 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1426 the_note->set_off_velocity (off_velocity);
1428 notes.push_back (the_note);
1431 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1432 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1434 mrv->select_notes(notes);
1439 /* regionviews containing these notes don't yet exist on the canvas.*/
1440 pending_midi_note_selection.push_back (make_pair (id, notes));
1443 } else if ((*i)->name() == X_("ControlPoint")) {
1444 XMLProperty* prop_type = (*i)->property (X_("type"));
1448 if (prop_type->value () == "track") {
1450 XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
1451 XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
1452 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1453 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1455 assert (prop_route_id);
1456 assert (prop_alist_id);
1457 assert (prop_parameter);
1458 assert (prop_view_index);
1460 PBD::ID route_id (prop_route_id->value ());
1461 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1462 vector <ControlPoint *> cps;
1465 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1467 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1468 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1469 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1470 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1482 } else if (prop_type->value () == "region") {
1483 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1484 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1486 if (!prop_region_id || !prop_view_index) {
1490 PBD::ID region_id (prop_region_id->value ());
1492 editor->get_regionviews_by_id (region_id, rs);
1495 vector <ControlPoint *> cps;
1496 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1497 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1499 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1500 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1513 } else if ((*i)->name() == X_("AudioRange")) {
1514 XMLProperty* prop_start = (*i)->property (X_("start"));
1515 XMLProperty* prop_end = (*i)->property (X_("end"));
1517 assert (prop_start);
1520 framepos_t s (atol (prop_start->value ().c_str()));
1521 framepos_t e (atol (prop_end->value ().c_str()));
1523 set_preserving_all_ranges (s, e);
1525 } else if ((*i)->name() == X_("AutomationView")) {
1527 XMLProperty* prop_id = (*i)->property (X_("id"));
1528 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1531 assert (prop_parameter);
1533 PBD::ID id (prop_id->value ());
1534 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1537 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1539 /* the automation could be for an entity that was never saved
1540 in the session file. Don't freak out if we can't find
1549 } else if ((*i)->name() == X_("Marker")) {
1551 XMLProperty* prop_id = (*i)->property (X_("id"));
1552 XMLProperty* prop_start = (*i)->property (X_("start"));
1554 assert (prop_start);
1556 PBD::ID id (prop_id->value ());
1557 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1570 Selection::remove_regions (TimeAxisView* t)
1572 RegionSelection::iterator i = regions.begin();
1573 while (i != regions.end ()) {
1574 RegionSelection::iterator tmp = i;
1577 if (&(*i)->get_time_axis_view() == t) {
1586 Selection::block_tracks_changed (bool yn)
1588 _no_tracks_changed = yn;