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 ()
126 clear_midi_regions ();
130 Selection::clear_tracks ()
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) {
144 Selection::clear_time ()
152 Selection::dump_region_layers()
154 cerr << "region selection layer dump" << endl;
155 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
156 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
162 Selection::clear_regions ()
164 if (!regions.empty()) {
165 regions.clear_all ();
171 Selection::clear_midi_notes ()
173 if (!midi_notes.empty()) {
174 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
181 // clear note selections for MRV's that have note selections
182 // this will cause the MRV to be removed from the list
183 for (MidiRegionSelection::iterator i = midi_regions.begin();
184 i != midi_regions.end();) {
185 MidiRegionSelection::iterator tmp = i;
187 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
189 mrv->clear_selection();
196 Selection::clear_midi_regions ()
198 if (!midi_regions.empty()) {
199 midi_regions.clear ();
200 MidiRegionsChanged ();
205 Selection::clear_playlists ()
207 /* Selections own their playlists */
209 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
210 /* selections own their own regions, which are copies of the "originals". make them go away */
211 (*i)->drop_regions ();
215 if (!playlists.empty()) {
222 Selection::clear_lines ()
224 if (!lines.empty()) {
231 Selection::clear_markers ()
233 if (!markers.empty()) {
240 Selection::toggle (boost::shared_ptr<Playlist> pl)
242 clear_time(); //enforce object/range exclusivity
243 clear_tracks(); //enforce object/track exclusivity
245 PlaylistSelection::iterator i;
247 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
249 playlists.push_back(pl);
258 Selection::toggle (const TrackViewList& track_list)
260 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
266 Selection::toggle (TimeAxisView* track)
268 TrackSelection::iterator i;
270 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
271 track->set_selected (true);
272 tracks.push_back (track);
274 track->set_selected (false);
278 if (!_no_tracks_changed) {
284 Selection::toggle (const MidiNoteSelection& midi_note_list)
286 clear_time(); //enforce object/range exclusivity
287 clear_tracks(); //enforce object/track exclusivity
289 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
295 Selection::toggle (MidiCutBuffer* midi)
297 MidiNoteSelection::iterator i;
299 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
300 midi_notes.push_back (midi);
302 /* remember that we own the MCB */
304 midi_notes.erase (i);
312 Selection::toggle (RegionView* r)
314 clear_time(); //enforce object/range exclusivity
315 clear_tracks(); //enforce object/track exclusivity
317 RegionSelection::iterator i;
319 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
329 Selection::toggle (MidiRegionView* mrv)
331 clear_time(); //enforce object/range exclusivity
332 clear_tracks(); //enforce object/track exclusivity
334 MidiRegionSelection::iterator i;
336 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
339 midi_regions.erase (i);
342 MidiRegionsChanged ();
346 Selection::toggle (vector<RegionView*>& r)
348 clear_time(); //enforce object/range exclusivity
349 clear_tracks(); //enforce object/track exclusivity
351 RegionSelection::iterator i;
353 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
354 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
365 Selection::toggle (framepos_t start, framepos_t end)
367 clear_objects(); //enforce object/range exclusivity
369 AudioRangeComparator cmp;
371 /* XXX this implementation is incorrect */
373 time.push_back (AudioRange (start, end, ++next_time_id));
383 Selection::add (boost::shared_ptr<Playlist> pl)
385 clear_time(); //enforce object/range exclusivity
386 clear_tracks(); //enforce object/track exclusivity
388 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
390 playlists.push_back(pl);
396 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
398 clear_time(); //enforce object/range exclusivity
399 clear_tracks(); //enforce object/track exclusivity
401 bool changed = false;
403 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
404 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
406 playlists.push_back (*i);
417 Selection::add (const TrackViewList& track_list)
419 clear_objects(); //enforce object/range exclusivity
421 TrackViewList added = tracks.add (track_list);
423 if (!added.empty()) {
424 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
425 (*x)->set_selected (true);
427 if (!_no_tracks_changed) {
434 Selection::add (TimeAxisView* track)
436 clear_objects(); //enforce object/range exclusivity
439 track->set_selected (true);
440 tr.push_back (track);
445 Selection::add (const MidiNoteSelection& midi_list)
447 clear_time(); //enforce object/range exclusivity
448 clear_tracks(); //enforce object/track exclusivity
450 const MidiNoteSelection::const_iterator b = midi_list.begin();
451 const MidiNoteSelection::const_iterator e = midi_list.end();
453 if (!midi_list.empty()) {
454 midi_notes.insert (midi_notes.end(), b, e);
460 Selection::add (MidiCutBuffer* midi)
462 /* we take ownership of the MCB */
464 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
465 midi_notes.push_back (midi);
471 Selection::add (vector<RegionView*>& v)
473 clear_time(); //enforce object/range exclusivity
474 clear_tracks(); //enforce object/track exclusivity
476 /* XXX This method or the add (const RegionSelection&) needs to go
479 bool changed = false;
481 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
482 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
483 changed = regions.add ((*i));
493 Selection::add (const RegionSelection& rs)
495 clear_time(); //enforce object/range exclusivity
496 clear_tracks(); //enforce object/track exclusivity
498 /* XXX This method or the add (const vector<RegionView*>&) needs to go
501 bool changed = false;
503 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
504 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
505 changed = regions.add ((*i));
515 Selection::add (RegionView* r)
517 clear_time(); //enforce object/range exclusivity
518 clear_tracks(); //enforce object/track exclusivity
520 if (find (regions.begin(), regions.end(), r) == regions.end()) {
521 bool changed = regions.add (r);
529 Selection::add (MidiRegionView* mrv)
531 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
533 clear_time(); //enforce object/range exclusivity
534 clear_tracks(); //enforce object/track exclusivity
536 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
537 midi_regions.push_back (mrv);
538 /* XXX should we do this? */
539 MidiRegionsChanged ();
544 Selection::add (framepos_t start, framepos_t end)
546 clear_objects(); //enforce object/range exclusivity
548 AudioRangeComparator cmp;
550 /* XXX this implementation is incorrect */
552 time.push_back (AudioRange (start, end, ++next_time_id));
562 Selection::move_time (framecnt_t distance)
568 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
569 (*i).start += distance;
570 (*i).end += distance;
577 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
579 clear_objects(); //enforce object/range exclusivity
581 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
582 if ((*i).id == sid) {
584 time.push_back (AudioRange(start,end, sid));
586 /* don't consolidate here */
589 AudioRangeComparator cmp;
599 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
601 clear_time(); //enforce object/range exclusivity
602 clear_tracks(); //enforce object/track exclusivity
604 boost::shared_ptr<ARDOUR::AutomationList> al
605 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
607 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
610 if (find (lines.begin(), lines.end(), al) == lines.end()) {
611 lines.push_back (al);
617 Selection::remove (TimeAxisView* track)
619 list<TimeAxisView*>::iterator i;
620 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
621 track->set_selected (false);
623 if (!_no_tracks_changed) {
630 Selection::remove (const TrackViewList& track_list)
632 bool changed = false;
634 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
636 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
637 if (x != tracks.end()) {
638 (*i)->set_selected (false);
645 if (!_no_tracks_changed) {
652 Selection::remove (ControlPoint* p)
654 PointSelection::iterator i = find (points.begin(), points.end(), p);
655 if (i != points.end ()) {
661 Selection::remove (const MidiNoteSelection& midi_list)
663 bool changed = false;
665 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
667 MidiNoteSelection::iterator x;
669 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
670 midi_notes.erase (x);
681 Selection::remove (MidiCutBuffer* midi)
683 MidiNoteSelection::iterator x;
685 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
686 /* remember that we own the MCB */
688 midi_notes.erase (x);
694 Selection::remove (boost::shared_ptr<Playlist> track)
696 list<boost::shared_ptr<Playlist> >::iterator i;
697 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
704 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
706 bool changed = false;
708 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
710 list<boost::shared_ptr<Playlist> >::iterator x;
712 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
724 Selection::remove (RegionView* r)
726 if (regions.remove (r)) {
732 Selection::remove (MidiRegionView* mrv)
734 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
736 MidiRegionSelection::iterator x;
738 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
739 midi_regions.erase (x);
740 MidiRegionsChanged ();
745 Selection::remove (uint32_t selection_id)
751 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
752 if ((*i).id == selection_id) {
762 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
767 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
769 AutomationSelection::iterator i;
770 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
777 Selection::set (TimeAxisView* track)
779 clear_objects(); //enforce object/range exclusivity
785 Selection::set (const TrackViewList& track_list)
787 clear_objects(); //enforce object/range exclusivity
793 Selection::set (const MidiNoteSelection& midi_list)
795 clear_time (); //enforce region/object exclusivity
796 clear_tracks(); //enforce object/track exclusivity
802 Selection::set (boost::shared_ptr<Playlist> playlist)
804 clear_time (); //enforce region/object exclusivity
805 clear_tracks(); //enforce object/track exclusivity
811 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
813 clear_time(); //enforce region/object exclusivity
819 Selection::set (const RegionSelection& rs)
821 clear_time(); //enforce region/object exclusivity
822 clear_tracks(); //enforce object/track exclusivity
825 RegionsChanged(); /* EMIT SIGNAL */
829 Selection::set (MidiRegionView* mrv)
831 clear_time(); //enforce region/object exclusivity
832 clear_tracks(); //enforce object/track exclusivity
838 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
840 clear_time(); //enforce region/object exclusivity
841 clear_tracks(); //enforce object/track exclusivity
847 Selection::set (vector<RegionView*>& v)
849 clear_time(); //enforce region/object exclusivity
850 clear_tracks(); //enforce object/track exclusivity
856 /** Set the start and end time of the time selection, without changing
857 * the list of tracks it applies to.
860 Selection::set (framepos_t start, framepos_t end)
862 clear_objects(); //enforce region/object exclusivity
865 if ((start == 0 && end == 0) || end < start) {
870 time.push_back (AudioRange (start, end, ++next_time_id));
872 /* reuse the first entry, and remove all the rest */
874 while (time.size() > 1) {
877 time.front().start = start;
878 time.front().end = end;
885 return time.front().id;
888 /** Set the start and end of the range selection. If more than one range
889 * is currently selected, the start of the earliest range and the end of the
890 * latest range are set. If no range is currently selected, this method
891 * selects a single range from start to end.
893 * @param start New start time.
894 * @param end New end time.
897 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
899 clear_objects(); //enforce region/object exclusivity
901 if ((start == 0 && end == 0) || (end < start)) {
906 time.push_back (AudioRange (start, end, ++next_time_id));
908 time.sort (AudioRangeComparator ());
909 time.front().start = start;
910 time.back().end = end;
919 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
921 clear_time(); //enforce region/object exclusivity
922 clear_tracks(); //enforce object/track exclusivity
929 Selection::selected (ArdourMarker* m)
931 return find (markers.begin(), markers.end(), m) != markers.end();
935 Selection::selected (TimeAxisView* tv)
937 return tv->get_selected ();
941 Selection::selected (RegionView* rv)
943 return find (regions.begin(), regions.end(), rv) != regions.end();
947 Selection::selected (ControlPoint* cp)
949 return find (points.begin(), points.end(), cp) != points.end();
953 Selection::empty (bool internal_selection)
955 bool object_level_empty = regions.empty () &&
958 playlists.empty () &&
961 playlists.empty () &&
966 if (!internal_selection) {
967 return object_level_empty;
970 /* this is intended to really only apply when using a Selection
974 return object_level_empty && midi_notes.empty() && points.empty();
978 Selection::toggle (ControlPoint* cp)
980 clear_time(); //enforce region/object exclusivity
981 clear_tracks(); //enforce object/track exclusivity
983 cp->set_selected (!cp->get_selected ());
984 PointSelection::iterator i = find (points.begin(), points.end(), cp);
985 if (i == points.end()) {
986 points.push_back (cp);
991 PointsChanged (); /* EMIT SIGNAL */
995 Selection::toggle (vector<ControlPoint*> const & cps)
997 clear_time(); //enforce region/object exclusivity
998 clear_tracks(); //enforce object/track exclusivity
1000 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1006 Selection::toggle (list<Selectable*> const & selectables)
1008 clear_time(); //enforce region/object exclusivity
1009 clear_tracks(); //enforce object/track exclusivity
1013 vector<RegionView*> rvs;
1014 vector<ControlPoint*> cps;
1016 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1017 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1019 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1022 fatal << _("programming error: ")
1023 << X_("unknown selectable type passed to Selection::toggle()")
1025 abort(); /*NOTREACHED*/
1039 Selection::set (list<Selectable*> const & selectables)
1041 clear_time (); //enforce region/object exclusivity
1042 clear_tracks(); //enforce object/track exclusivity
1049 Selection::add (PointSelection const & s)
1051 clear_time (); //enforce region/object exclusivity
1052 clear_tracks(); //enforce object/track exclusivity
1054 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1055 points.push_back (*i);
1060 Selection::add (list<Selectable*> const & selectables)
1062 clear_time (); //enforce region/object exclusivity
1063 clear_tracks(); //enforce object/track exclusivity
1067 vector<RegionView*> rvs;
1068 vector<ControlPoint*> cps;
1070 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1071 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1073 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1076 fatal << _("programming error: ")
1077 << X_("unknown selectable type passed to Selection::add()")
1079 abort(); /*NOTREACHED*/
1093 Selection::clear_points ()
1095 if (!points.empty()) {
1102 Selection::add (ControlPoint* cp)
1104 clear_time (); //enforce region/object exclusivity
1105 clear_tracks(); //enforce object/track exclusivity
1107 cp->set_selected (true);
1108 points.push_back (cp);
1109 PointsChanged (); /* EMIT SIGNAL */
1113 Selection::add (vector<ControlPoint*> const & cps)
1115 clear_time (); //enforce region/object exclusivity
1116 clear_tracks(); //enforce object/track exclusivity
1118 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1119 (*i)->set_selected (true);
1120 points.push_back (*i);
1122 PointsChanged (); /* EMIT SIGNAL */
1126 Selection::set (ControlPoint* cp)
1128 clear_time (); //enforce region/object exclusivity
1129 clear_tracks(); //enforce object/track exclusivity
1131 if (cp->get_selected () && points.size () == 1) {
1135 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1136 cp->line().nth (i)->set_selected (false);
1144 Selection::set (ArdourMarker* m)
1146 clear_time (); //enforce region/object exclusivity
1147 clear_tracks(); //enforce object/track exclusivity
1154 Selection::toggle (ArdourMarker* m)
1156 MarkerSelection::iterator i;
1158 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1166 Selection::remove (ArdourMarker* m)
1168 MarkerSelection::iterator i;
1170 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1177 Selection::add (ArdourMarker* m)
1179 clear_time (); //enforce region/object exclusivity
1180 clear_tracks(); //enforce object/track exclusivity
1182 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1183 markers.push_back (m);
1189 Selection::add (const list<ArdourMarker*>& m)
1191 clear_time (); //enforce region/object exclusivity
1192 clear_tracks(); //enforce object/track exclusivity
1194 markers.insert (markers.end(), m.begin(), m.end());
1202 MarkerSelection::range (framepos_t& s, framepos_t& e)
1207 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1209 if ((*i)->position() < s) {
1210 s = (*i)->position();
1213 if ((*i)->position() > e) {
1214 e = (*i)->position();
1218 s = std::min (s, e);
1219 e = std::max (s, e);
1223 Selection::get_state () const
1225 /* XXX: not complete; just sufficient to get track selection state
1226 so that re-opening plugin windows for editor mixer strips works
1230 XMLNode* node = new XMLNode (X_("Selection"));
1232 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1233 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1234 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1236 XMLNode* t = node->add_child (X_("RouteView"));
1237 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1239 XMLNode* t = node->add_child (X_("AutomationView"));
1240 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1241 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1245 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1246 XMLNode* r = node->add_child (X_("Region"));
1247 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1250 /* midi region views have thir own internal selection. */
1252 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1253 editor->get_per_region_note_selection (rid_notes);
1254 if (!rid_notes.empty()) {
1255 n = node->add_child (X_("MIDINote"));
1257 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1258 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1259 assert(n); // hint for clang static analysis
1260 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1262 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1263 XMLNode* nc = n->add_child(X_("note"));
1264 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1265 nc->add_property(X_("channel"), string(buf));
1267 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1268 nc->add_property(X_("time"), string(buf));
1270 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1271 nc->add_property(X_("note"), string(buf));
1273 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1274 nc->add_property(X_("length"), string(buf));
1276 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1277 nc->add_property(X_("velocity"), string(buf));
1279 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1280 nc->add_property(X_("off-velocity"), string(buf));
1284 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1285 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1288 XMLNode* r = node->add_child (X_("ControlPoint"));
1289 r->add_property (X_("type"), "track");
1290 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1291 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1292 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1294 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1295 r->add_property (X_("view-index"), string(buf));
1299 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1301 XMLNode* r = node->add_child (X_("ControlPoint"));
1302 r->add_property (X_("type"), "region");
1303 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1304 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1305 r->add_property (X_("view-index"), string(buf));
1310 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1311 XMLNode* t = node->add_child (X_("AudioRange"));
1312 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1313 t->add_property (X_("start"), string(buf));
1314 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1315 t->add_property (X_("end"), string(buf));
1318 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1319 XMLNode* t = node->add_child (X_("Marker"));
1322 Location* loc = editor->find_location_from_marker (*i, is_start);
1324 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1325 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1332 Selection::set_state (XMLNode const & node, int)
1334 if (node.name() != X_("Selection")) {
1339 clear_midi_notes ();
1345 XMLNodeList children = node.children ();
1346 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1347 if ((*i)->name() == X_("RouteView")) {
1349 XMLProperty* prop_id = (*i)->property (X_("id"));
1351 PBD::ID id (prop_id->value ());
1352 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1357 } else if ((*i)->name() == X_("Region")) {
1358 XMLProperty* prop_id = (*i)->property (X_("id"));
1360 PBD::ID id (prop_id->value ());
1363 editor->get_regionviews_by_id (id, rs);
1369 regionviews haven't been constructed - stash the region IDs
1370 so we can identify them in Editor::region_view_added ()
1372 regions.pending.push_back (id);
1375 } else if ((*i)->name() == X_("MIDINote")) {
1376 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1378 assert (prop_region_id);
1380 PBD::ID const id (prop_region_id->value ());
1383 editor->get_regionviews_by_id (id, rs); // there could be more than one
1385 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1386 XMLNodeList children = (*i)->children ();
1388 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1389 XMLProperty* prop_channel = (*ci)->property (X_("channel"));
1390 XMLProperty* prop_time = (*ci)->property (X_("time"));
1391 XMLProperty* prop_note = (*ci)->property (X_("note"));
1392 XMLProperty* prop_length = (*ci)->property (X_("length"));
1393 XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
1394 XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
1396 assert (prop_channel);
1399 assert (prop_length);
1400 assert (prop_velocity);
1401 assert (prop_off_velocity);
1403 uint8_t channel = atoi(prop_channel->value());
1404 Evoral::Beats time (atof(prop_time->value()));
1405 Evoral::Beats length (atof(prop_length->value()));
1406 uint8_t note = atoi(prop_note->value());
1407 uint8_t velocity = atoi(prop_velocity->value());
1408 uint8_t off_velocity = atoi(prop_off_velocity->value());
1409 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1410 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1411 the_note->set_off_velocity (off_velocity);
1413 notes.push_back (the_note);
1416 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1417 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1419 mrv->select_notes(notes);
1424 /* regionviews containing these notes don't yet exist on the canvas.*/
1425 pending_midi_note_selection.push_back (make_pair (id, notes));
1428 } else if ((*i)->name() == X_("ControlPoint")) {
1429 XMLProperty* prop_type = (*i)->property (X_("type"));
1433 if (prop_type->value () == "track") {
1435 XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
1436 XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
1437 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1438 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1440 assert (prop_route_id);
1441 assert (prop_alist_id);
1442 assert (prop_parameter);
1443 assert (prop_view_index);
1445 PBD::ID route_id (prop_route_id->value ());
1446 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1447 vector <ControlPoint *> cps;
1450 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1452 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1453 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1454 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1455 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1467 } else if (prop_type->value () == "region") {
1468 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1469 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1471 if (!prop_region_id || !prop_view_index) {
1475 PBD::ID region_id (prop_region_id->value ());
1477 editor->get_regionviews_by_id (region_id, rs);
1480 vector <ControlPoint *> cps;
1481 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1482 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1484 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1485 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1498 } else if ((*i)->name() == X_("AudioRange")) {
1499 XMLProperty* prop_start = (*i)->property (X_("start"));
1500 XMLProperty* prop_end = (*i)->property (X_("end"));
1502 assert (prop_start);
1505 framepos_t s (atol (prop_start->value ().c_str()));
1506 framepos_t e (atol (prop_end->value ().c_str()));
1508 set_preserving_all_ranges (s, e);
1510 } else if ((*i)->name() == X_("AutomationView")) {
1512 XMLProperty* prop_id = (*i)->property (X_("id"));
1513 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1516 assert (prop_parameter);
1518 PBD::ID id (prop_id->value ());
1519 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1522 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1524 /* the automation could be for an entity that was never saved
1525 in the session file. Don't freak out if we can't find
1534 } else if ((*i)->name() == X_("Marker")) {
1536 XMLProperty* prop_id = (*i)->property (X_("id"));
1537 XMLProperty* prop_start = (*i)->property (X_("start"));
1539 assert (prop_start);
1541 PBD::ID id (prop_id->value ());
1542 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1555 Selection::remove_regions (TimeAxisView* t)
1557 RegionSelection::iterator i = regions.begin();
1558 while (i != regions.end ()) {
1559 RegionSelection::iterator tmp = i;
1562 if (&(*i)->get_time_axis_view() == t) {
1571 Selection::block_tracks_changed (bool yn)
1573 _no_tracks_changed = yn;