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 "gui_thread.h"
30 #include "midi_cut_buffer.h"
31 #include "region_view.h"
32 #include "selection.h"
33 #include "selection_templates.h"
34 #include "time_axis_view.h"
35 #include "automation_time_axis.h"
36 #include "public_editor.h"
37 #include "control_point.h"
42 using namespace ARDOUR;
45 struct AudioRangeComparator {
46 bool operator()(AudioRange a, AudioRange b) {
47 return a.start < b.start;
51 Selection::Selection (const PublicEditor* e)
55 , _no_tracks_changed (false)
59 /* we have disambiguate which remove() for the compiler */
61 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
62 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
64 void (Selection::*marker_remove)(Marker*) = &Selection::remove;
65 Marker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
67 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
68 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
73 Selection::operator= (const Selection& other)
76 regions = other.regions;
77 tracks = other.tracks;
80 midi_regions = other.midi_regions;
81 midi_notes = other.midi_notes;
88 operator== (const Selection& a, const Selection& b)
90 return a.regions == b.regions &&
91 a.tracks == b.tracks &&
94 a.playlists == b.playlists &&
95 a.midi_notes == b.midi_notes &&
96 a.midi_regions == b.midi_regions;
99 /** Clear everything from the Selection */
110 clear_midi_regions ();
112 pending_midi_note_selection.clear();
116 Selection::clear_objects ()
123 clear_midi_regions ();
127 Selection::clear_tracks ()
129 if (!tracks.empty()) {
130 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
131 (*x)->set_selected (false);
134 if (!_no_tracks_changed) {
141 Selection::clear_time ()
149 Selection::dump_region_layers()
151 cerr << "region selection layer dump" << endl;
152 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
153 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
159 Selection::clear_regions ()
161 if (!regions.empty()) {
162 regions.clear_all ();
168 Selection::clear_midi_notes ()
170 if (!midi_notes.empty()) {
171 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
178 /* The note selection is actually stored in MidiRegionView, emit signal to
179 tell them to clear their selection. */
180 ClearMidiNoteSelection(); /* EMIT SIGNAL */
184 Selection::clear_midi_regions ()
186 if (!midi_regions.empty()) {
187 midi_regions.clear ();
188 MidiRegionsChanged ();
193 Selection::clear_playlists ()
195 /* Selections own their playlists */
197 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
198 /* selections own their own regions, which are copies of the "originals". make them go away */
199 (*i)->drop_regions ();
203 if (!playlists.empty()) {
210 Selection::clear_lines ()
212 if (!lines.empty()) {
219 Selection::clear_markers ()
221 if (!markers.empty()) {
228 Selection::toggle (boost::shared_ptr<Playlist> pl)
230 clear_time(); //enforce object/range exclusivity
231 clear_tracks(); //enforce object/track exclusivity
233 PlaylistSelection::iterator i;
235 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
237 playlists.push_back(pl);
246 Selection::toggle (const TrackViewList& track_list)
248 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
254 Selection::toggle (TimeAxisView* track)
256 TrackSelection::iterator i;
258 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
259 track->set_selected (true);
260 tracks.push_back (track);
262 track->set_selected (false);
266 if (!_no_tracks_changed) {
272 Selection::toggle (const MidiNoteSelection& midi_note_list)
274 clear_time(); //enforce object/range exclusivity
275 clear_tracks(); //enforce object/track exclusivity
277 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
283 Selection::toggle (MidiCutBuffer* midi)
285 MidiNoteSelection::iterator i;
287 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
288 midi_notes.push_back (midi);
290 /* remember that we own the MCB */
292 midi_notes.erase (i);
300 Selection::toggle (RegionView* r)
302 clear_time(); //enforce object/range exclusivity
303 clear_tracks(); //enforce object/track exclusivity
305 RegionSelection::iterator i;
307 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
317 Selection::toggle (MidiRegionView* mrv)
319 clear_time(); //enforce object/range exclusivity
320 clear_tracks(); //enforce object/track exclusivity
322 MidiRegionSelection::iterator i;
324 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
327 midi_regions.erase (i);
330 MidiRegionsChanged ();
334 Selection::toggle (vector<RegionView*>& r)
336 clear_time(); //enforce object/range exclusivity
337 clear_tracks(); //enforce object/track exclusivity
339 RegionSelection::iterator i;
341 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
342 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
353 Selection::toggle (framepos_t start, framepos_t end)
355 clear_objects(); //enforce object/range exclusivity
357 AudioRangeComparator cmp;
359 /* XXX this implementation is incorrect */
361 time.push_back (AudioRange (start, end, ++next_time_id));
371 Selection::add (boost::shared_ptr<Playlist> pl)
373 clear_time(); //enforce object/range exclusivity
374 clear_tracks(); //enforce object/track exclusivity
376 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
378 playlists.push_back(pl);
384 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
386 clear_time(); //enforce object/range exclusivity
387 clear_tracks(); //enforce object/track exclusivity
389 bool changed = false;
391 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
392 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
394 playlists.push_back (*i);
405 Selection::add (const TrackViewList& track_list)
407 clear_objects(); //enforce object/range exclusivity
409 TrackViewList added = tracks.add (track_list);
411 if (!added.empty()) {
412 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
413 (*x)->set_selected (true);
415 if (!_no_tracks_changed) {
422 Selection::add (TimeAxisView* track)
424 clear_objects(); //enforce object/range exclusivity
427 track->set_selected (true);
428 tr.push_back (track);
433 Selection::add (const MidiNoteSelection& midi_list)
435 clear_time(); //enforce object/range exclusivity
436 clear_tracks(); //enforce object/track exclusivity
438 const MidiNoteSelection::const_iterator b = midi_list.begin();
439 const MidiNoteSelection::const_iterator e = midi_list.end();
441 if (!midi_list.empty()) {
442 midi_notes.insert (midi_notes.end(), b, e);
448 Selection::add (MidiCutBuffer* midi)
450 /* we take ownership of the MCB */
452 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
453 midi_notes.push_back (midi);
459 Selection::add (vector<RegionView*>& v)
461 clear_time(); //enforce object/range exclusivity
462 clear_tracks(); //enforce object/track exclusivity
464 /* XXX This method or the add (const RegionSelection&) needs to go
467 bool changed = false;
469 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
470 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
471 changed = regions.add ((*i));
481 Selection::add (const RegionSelection& rs)
483 clear_time(); //enforce object/range exclusivity
484 clear_tracks(); //enforce object/track exclusivity
486 /* XXX This method or the add (const vector<RegionView*>&) needs to go
489 bool changed = false;
491 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
492 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
493 changed = regions.add ((*i));
503 Selection::add (RegionView* r)
505 clear_time(); //enforce object/range exclusivity
506 clear_tracks(); //enforce object/track exclusivity
508 if (find (regions.begin(), regions.end(), r) == regions.end()) {
509 bool changed = regions.add (r);
517 Selection::add (MidiRegionView* mrv)
519 clear_time(); //enforce object/range exclusivity
520 clear_tracks(); //enforce object/track exclusivity
522 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
523 midi_regions.push_back (mrv);
524 /* XXX should we do this? */
525 MidiRegionsChanged ();
530 Selection::add (framepos_t start, framepos_t end)
532 clear_objects(); //enforce object/range exclusivity
534 AudioRangeComparator cmp;
536 /* XXX this implementation is incorrect */
538 time.push_back (AudioRange (start, end, ++next_time_id));
548 Selection::move_time (framecnt_t distance)
554 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
555 (*i).start += distance;
556 (*i).end += distance;
563 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
565 clear_objects(); //enforce object/range exclusivity
567 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
568 if ((*i).id == sid) {
570 time.push_back (AudioRange(start,end, sid));
572 /* don't consolidate here */
575 AudioRangeComparator cmp;
585 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
587 clear_time(); //enforce object/range exclusivity
588 clear_tracks(); //enforce object/track exclusivity
590 boost::shared_ptr<ARDOUR::AutomationList> al
591 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
593 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
596 if (find (lines.begin(), lines.end(), al) == lines.end()) {
597 lines.push_back (al);
603 Selection::remove (TimeAxisView* track)
605 list<TimeAxisView*>::iterator i;
606 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
607 track->set_selected (false);
609 if (!_no_tracks_changed) {
616 Selection::remove (const TrackViewList& track_list)
618 bool changed = false;
620 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
622 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
623 if (x != tracks.end()) {
624 (*i)->set_selected (false);
631 if (!_no_tracks_changed) {
638 Selection::remove (ControlPoint* p)
640 PointSelection::iterator i = find (points.begin(), points.end(), p);
641 if (i != points.end ()) {
647 Selection::remove (const MidiNoteSelection& midi_list)
649 bool changed = false;
651 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
653 MidiNoteSelection::iterator x;
655 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
656 midi_notes.erase (x);
667 Selection::remove (MidiCutBuffer* midi)
669 MidiNoteSelection::iterator x;
671 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
672 /* remember that we own the MCB */
674 midi_notes.erase (x);
680 Selection::remove (boost::shared_ptr<Playlist> track)
682 list<boost::shared_ptr<Playlist> >::iterator i;
683 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
690 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
692 bool changed = false;
694 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
696 list<boost::shared_ptr<Playlist> >::iterator x;
698 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
710 Selection::remove (RegionView* r)
712 if (regions.remove (r)) {
718 Selection::remove (MidiRegionView* mrv)
720 MidiRegionSelection::iterator x;
722 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
723 midi_regions.erase (x);
724 MidiRegionsChanged ();
730 Selection::remove (uint32_t selection_id)
736 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
737 if ((*i).id == selection_id) {
747 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
752 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
754 AutomationSelection::iterator i;
755 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
762 Selection::set (TimeAxisView* track)
764 clear_objects(); //enforce object/range exclusivity
770 Selection::set (const TrackViewList& track_list)
772 clear_objects(); //enforce object/range exclusivity
778 Selection::set (const MidiNoteSelection& midi_list)
780 clear_time (); //enforce region/object exclusivity
781 clear_tracks(); //enforce object/track exclusivity
787 Selection::set (boost::shared_ptr<Playlist> playlist)
789 clear_time (); //enforce region/object exclusivity
790 clear_tracks(); //enforce object/track exclusivity
796 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
798 clear_time(); //enforce region/object exclusivity
804 Selection::set (const RegionSelection& rs)
806 clear_time(); //enforce region/object exclusivity
807 clear_tracks(); //enforce object/track exclusivity
810 RegionsChanged(); /* EMIT SIGNAL */
814 Selection::set (MidiRegionView* mrv)
816 clear_time(); //enforce region/object exclusivity
817 clear_tracks(); //enforce object/track exclusivity
823 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
825 clear_time(); //enforce region/object exclusivity
826 clear_tracks(); //enforce object/track exclusivity
832 Selection::set (vector<RegionView*>& v)
834 clear_time(); //enforce region/object exclusivity
835 clear_tracks(); //enforce object/track exclusivity
841 /** Set the start and end time of the time selection, without changing
842 * the list of tracks it applies to.
845 Selection::set (framepos_t start, framepos_t end)
847 clear_objects(); //enforce region/object exclusivity
850 if ((start == 0 && end == 0) || end < start) {
855 time.push_back (AudioRange (start, end, ++next_time_id));
857 /* reuse the first entry, and remove all the rest */
859 while (time.size() > 1) {
862 time.front().start = start;
863 time.front().end = end;
870 return time.front().id;
873 /** Set the start and end of the range selection. If more than one range
874 * is currently selected, the start of the earliest range and the end of the
875 * latest range are set. If no range is currently selected, this method
876 * selects a single range from start to end.
878 * @param start New start time.
879 * @param end New end time.
882 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
884 clear_objects(); //enforce region/object exclusivity
886 if ((start == 0 && end == 0) || (end < start)) {
891 time.push_back (AudioRange (start, end, ++next_time_id));
893 time.sort (AudioRangeComparator ());
894 time.front().start = start;
895 time.back().end = end;
904 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
906 clear_time(); //enforce region/object exclusivity
907 clear_tracks(); //enforce object/track exclusivity
914 Selection::selected (Marker* m)
916 return find (markers.begin(), markers.end(), m) != markers.end();
920 Selection::selected (TimeAxisView* tv)
922 return tv->get_selected ();
926 Selection::selected (RegionView* rv)
928 return find (regions.begin(), regions.end(), rv) != regions.end();
932 Selection::selected (ControlPoint* cp)
934 return find (points.begin(), points.end(), cp) != points.end();
938 Selection::empty (bool internal_selection)
940 bool object_level_empty = regions.empty () &&
943 playlists.empty () &&
946 playlists.empty () &&
951 if (!internal_selection) {
952 return object_level_empty;
955 /* this is intended to really only apply when using a Selection
959 return object_level_empty && midi_notes.empty() && points.empty();
963 Selection::toggle (ControlPoint* cp)
965 clear_time(); //enforce region/object exclusivity
966 clear_tracks(); //enforce object/track exclusivity
968 cp->set_selected (!cp->get_selected ());
969 PointSelection::iterator i = find (points.begin(), points.end(), cp);
970 if (i == points.end()) {
971 points.push_back (cp);
976 PointsChanged (); /* EMIT SIGNAL */
980 Selection::toggle (vector<ControlPoint*> const & cps)
982 clear_time(); //enforce region/object exclusivity
983 clear_tracks(); //enforce object/track exclusivity
985 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
991 Selection::toggle (list<Selectable*> const & selectables)
993 clear_time(); //enforce region/object exclusivity
994 clear_tracks(); //enforce object/track exclusivity
998 vector<RegionView*> rvs;
999 vector<ControlPoint*> cps;
1001 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1002 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1004 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1007 fatal << _("programming error: ")
1008 << X_("unknown selectable type passed to Selection::toggle()")
1010 abort(); /*NOTREACHED*/
1024 Selection::set (list<Selectable*> const & selectables)
1026 clear_time (); //enforce region/object exclusivity
1027 clear_tracks(); //enforce object/track exclusivity
1034 Selection::add (PointSelection const & s)
1036 clear_time (); //enforce region/object exclusivity
1037 clear_tracks(); //enforce object/track exclusivity
1039 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1040 points.push_back (*i);
1045 Selection::add (list<Selectable*> const & selectables)
1047 clear_time (); //enforce region/object exclusivity
1048 clear_tracks(); //enforce object/track exclusivity
1052 vector<RegionView*> rvs;
1053 vector<ControlPoint*> cps;
1055 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1056 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1058 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1061 fatal << _("programming error: ")
1062 << X_("unknown selectable type passed to Selection::add()")
1064 abort(); /*NOTREACHED*/
1078 Selection::clear_points ()
1080 if (!points.empty()) {
1087 Selection::add (ControlPoint* cp)
1089 clear_time (); //enforce region/object exclusivity
1090 clear_tracks(); //enforce object/track exclusivity
1092 cp->set_selected (true);
1093 points.push_back (cp);
1094 PointsChanged (); /* EMIT SIGNAL */
1098 Selection::add (vector<ControlPoint*> const & cps)
1100 clear_time (); //enforce region/object exclusivity
1101 clear_tracks(); //enforce object/track exclusivity
1103 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1104 (*i)->set_selected (true);
1105 points.push_back (*i);
1107 PointsChanged (); /* EMIT SIGNAL */
1111 Selection::set (ControlPoint* cp)
1113 clear_time (); //enforce region/object exclusivity
1114 clear_tracks(); //enforce object/track exclusivity
1116 if (cp->get_selected()) {
1120 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1121 cp->line().nth (i)->set_selected (false);
1129 Selection::set (Marker* m)
1131 clear_time (); //enforce region/object exclusivity
1132 clear_tracks(); //enforce object/track exclusivity
1139 Selection::toggle (Marker* m)
1141 MarkerSelection::iterator i;
1143 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1151 Selection::remove (Marker* m)
1153 MarkerSelection::iterator i;
1155 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1162 Selection::add (Marker* m)
1164 clear_time (); //enforce region/object exclusivity
1165 clear_tracks(); //enforce object/track exclusivity
1167 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1168 markers.push_back (m);
1174 Selection::add (const list<Marker*>& m)
1176 clear_time (); //enforce region/object exclusivity
1177 clear_tracks(); //enforce object/track exclusivity
1179 markers.insert (markers.end(), m.begin(), m.end());
1187 MarkerSelection::range (framepos_t& s, framepos_t& e)
1192 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1194 if ((*i)->position() < s) {
1195 s = (*i)->position();
1198 if ((*i)->position() > e) {
1199 e = (*i)->position();
1203 s = std::min (s, e);
1204 e = std::max (s, e);
1208 Selection::get_state () const
1210 /* XXX: not complete; just sufficient to get track selection state
1211 so that re-opening plugin windows for editor mixer strips works
1215 XMLNode* node = new XMLNode (X_("Selection"));
1217 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1218 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1219 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1221 XMLNode* t = node->add_child (X_("RouteView"));
1222 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1224 XMLNode* t = node->add_child (X_("AutomationView"));
1225 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1226 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1230 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1231 XMLNode* r = node->add_child (X_("Region"));
1232 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1235 /* midi region views have thir own internal selection. */
1237 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1238 editor->get_per_region_note_selection (rid_notes);
1239 if (!rid_notes.empty()) {
1240 n = node->add_child (X_("MIDINote"));
1242 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1243 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1244 assert(n); // hint for clang static analysis
1245 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1247 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1248 XMLNode* nc = n->add_child(X_("note"));
1249 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1250 nc->add_property(X_("channel"), string(buf));
1252 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1253 nc->add_property(X_("time"), string(buf));
1255 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1256 nc->add_property(X_("note"), string(buf));
1258 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1259 nc->add_property(X_("length"), string(buf));
1261 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1262 nc->add_property(X_("velocity"), string(buf));
1264 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1265 nc->add_property(X_("off-velocity"), string(buf));
1269 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1270 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1273 XMLNode* r = node->add_child (X_("ControlPoint"));
1274 r->add_property (X_("type"), "track");
1275 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1276 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1277 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1279 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1280 r->add_property (X_("view-index"), string(buf));
1285 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1286 XMLNode* t = node->add_child (X_("AudioRange"));
1287 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1288 t->add_property (X_("start"), string(buf));
1289 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1290 t->add_property (X_("end"), string(buf));
1293 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1294 XMLNode* t = node->add_child (X_("Marker"));
1297 Location* loc = editor->find_location_from_marker (*i, is_start);
1299 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1300 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1307 Selection::set_state (XMLNode const & node, int)
1309 if (node.name() != X_("Selection")) {
1314 clear_midi_notes ();
1320 XMLNodeList children = node.children ();
1321 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1322 if ((*i)->name() == X_("RouteView")) {
1324 XMLProperty* prop_id = (*i)->property (X_("id"));
1326 PBD::ID id (prop_id->value ());
1327 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1332 } else if ((*i)->name() == X_("Region")) {
1333 XMLProperty* prop_id = (*i)->property (X_("id"));
1335 PBD::ID id (prop_id->value ());
1338 editor->get_regionviews_by_id (id, rs);
1344 regionviews haven't been constructed - stash the region IDs
1345 so we can identify them in Editor::region_view_added ()
1347 regions.pending.push_back (id);
1350 } else if ((*i)->name() == X_("MIDINote")) {
1351 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1353 assert (prop_region_id);
1355 PBD::ID const id (prop_region_id->value ());
1358 editor->get_regionviews_by_id (id, rs); // there could be more than one
1360 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1361 XMLNodeList children = (*i)->children ();
1363 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1364 XMLProperty* prop_channel = (*ci)->property (X_("channel"));
1365 XMLProperty* prop_time = (*ci)->property (X_("time"));
1366 XMLProperty* prop_note = (*ci)->property (X_("note"));
1367 XMLProperty* prop_length = (*ci)->property (X_("length"));
1368 XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
1369 XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
1371 assert (prop_channel);
1374 assert (prop_length);
1375 assert (prop_velocity);
1376 assert (prop_off_velocity);
1378 uint8_t channel = atoi(prop_channel->value());
1379 Evoral::Beats time (atof(prop_time->value()));
1380 Evoral::Beats length (atof(prop_length->value()));
1381 uint8_t note = atoi(prop_note->value());
1382 uint8_t velocity = atoi(prop_velocity->value());
1383 uint8_t off_velocity = atoi(prop_off_velocity->value());
1384 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1385 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1386 the_note->set_off_velocity (off_velocity);
1388 notes.push_back (the_note);
1391 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1392 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1394 mrv->select_notes(notes);
1399 /* regionviews containing these notes don't yet exist on the canvas.*/
1400 pending_midi_note_selection.push_back (make_pair (id, notes));
1403 } else if ((*i)->name() == X_("ControlPoint")) {
1404 XMLProperty* prop_type = (*i)->property (X_("type"));
1408 if (prop_type->value () == "track") {
1410 XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
1411 XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
1412 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1413 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1416 assert (prop_route_id);
1417 assert (prop_alist_id);
1418 assert (prop_parameter);
1419 assert (prop_view_index);
1421 PBD::ID route_id (prop_route_id->value ());
1422 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1423 vector <ControlPoint *> cps;
1426 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1428 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1429 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1430 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1431 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1445 } else if ((*i)->name() == X_("AudioRange")) {
1446 XMLProperty* prop_start = (*i)->property (X_("start"));
1447 XMLProperty* prop_end = (*i)->property (X_("end"));
1449 assert (prop_start);
1452 framepos_t s (atol (prop_start->value ().c_str()));
1453 framepos_t e (atol (prop_end->value ().c_str()));
1455 set_preserving_all_ranges (s, e);
1457 } else if ((*i)->name() == X_("AutomationView")) {
1459 XMLProperty* prop_id = (*i)->property (X_("id"));
1460 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1463 assert (prop_parameter);
1465 PBD::ID id (prop_id->value ());
1466 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1469 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1471 /* the automation could be for an entity that was never saved
1472 in the session file. Don't freak out if we can't find
1481 } else if ((*i)->name() == X_("Marker")) {
1483 XMLProperty* prop_id = (*i)->property (X_("id"));
1484 XMLProperty* prop_start = (*i)->property (X_("start"));
1486 assert (prop_start);
1488 PBD::ID id (prop_id->value ());
1489 Marker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1502 Selection::remove_regions (TimeAxisView* t)
1504 RegionSelection::iterator i = regions.begin();
1505 while (i != regions.end ()) {
1506 RegionSelection::iterator tmp = i;
1509 if (&(*i)->get_time_axis_view() == t) {
1518 Selection::block_tracks_changed (bool yn)
1520 _no_tracks_changed = yn;