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"
30 #include "gui_thread.h"
31 #include "midi_cut_buffer.h"
32 #include "region_gain_line.h"
33 #include "region_view.h"
34 #include "selection.h"
35 #include "selection_templates.h"
36 #include "time_axis_view.h"
37 #include "automation_time_axis.h"
38 #include "public_editor.h"
39 #include "control_point.h"
44 using namespace ARDOUR;
47 struct AudioRangeComparator {
48 bool operator()(AudioRange a, AudioRange b) {
49 return a.start < b.start;
53 Selection::Selection (const PublicEditor* e)
57 , _no_tracks_changed (false)
61 /* we have disambiguate which remove() for the compiler */
63 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
64 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
66 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
67 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
69 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
70 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
75 Selection::operator= (const Selection& other)
78 regions = other.regions;
79 tracks = other.tracks;
82 midi_regions = other.midi_regions;
83 midi_notes = other.midi_notes;
90 operator== (const Selection& a, const Selection& b)
92 return a.regions == b.regions &&
93 a.tracks == b.tracks &&
96 a.playlists == b.playlists &&
97 a.midi_notes == b.midi_notes &&
98 a.midi_regions == b.midi_regions;
101 /** Clear everything from the Selection */
112 clear_midi_regions ();
114 pending_midi_note_selection.clear();
118 Selection::clear_objects ()
125 clear_midi_regions ();
129 Selection::clear_tracks ()
131 if (!tracks.empty()) {
132 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
133 (*x)->set_selected (false);
136 if (!_no_tracks_changed) {
143 Selection::clear_time ()
151 Selection::dump_region_layers()
153 cerr << "region selection layer dump" << endl;
154 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
155 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
161 Selection::clear_regions ()
163 if (!regions.empty()) {
164 regions.clear_all ();
170 Selection::clear_midi_notes ()
172 if (!midi_notes.empty()) {
173 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
180 /* The note selection is actually stored in MidiRegionView, emit signal to
181 tell them to clear their selection. */
182 ClearMidiNoteSelection(); /* EMIT SIGNAL */
186 Selection::clear_midi_regions ()
188 if (!midi_regions.empty()) {
189 midi_regions.clear ();
190 MidiRegionsChanged ();
195 Selection::clear_playlists ()
197 /* Selections own their playlists */
199 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
200 /* selections own their own regions, which are copies of the "originals". make them go away */
201 (*i)->drop_regions ();
205 if (!playlists.empty()) {
212 Selection::clear_lines ()
214 if (!lines.empty()) {
221 Selection::clear_markers ()
223 if (!markers.empty()) {
230 Selection::toggle (boost::shared_ptr<Playlist> pl)
232 clear_time(); //enforce object/range exclusivity
233 clear_tracks(); //enforce object/track exclusivity
235 PlaylistSelection::iterator i;
237 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
239 playlists.push_back(pl);
248 Selection::toggle (const TrackViewList& track_list)
250 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
256 Selection::toggle (TimeAxisView* track)
258 TrackSelection::iterator i;
260 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
261 track->set_selected (true);
262 tracks.push_back (track);
264 track->set_selected (false);
268 if (!_no_tracks_changed) {
274 Selection::toggle (const MidiNoteSelection& midi_note_list)
276 clear_time(); //enforce object/range exclusivity
277 clear_tracks(); //enforce object/track exclusivity
279 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
285 Selection::toggle (MidiCutBuffer* midi)
287 MidiNoteSelection::iterator i;
289 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
290 midi_notes.push_back (midi);
292 /* remember that we own the MCB */
294 midi_notes.erase (i);
302 Selection::toggle (RegionView* r)
304 clear_time(); //enforce object/range exclusivity
305 clear_tracks(); //enforce object/track exclusivity
307 RegionSelection::iterator i;
309 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
319 Selection::toggle (MidiRegionView* mrv)
321 clear_time(); //enforce object/range exclusivity
322 clear_tracks(); //enforce object/track exclusivity
324 MidiRegionSelection::iterator i;
326 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
329 midi_regions.erase (i);
332 MidiRegionsChanged ();
336 Selection::toggle (vector<RegionView*>& r)
338 clear_time(); //enforce object/range exclusivity
339 clear_tracks(); //enforce object/track exclusivity
341 RegionSelection::iterator i;
343 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
344 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
355 Selection::toggle (framepos_t start, framepos_t end)
357 clear_objects(); //enforce object/range exclusivity
359 AudioRangeComparator cmp;
361 /* XXX this implementation is incorrect */
363 time.push_back (AudioRange (start, end, ++next_time_id));
373 Selection::add (boost::shared_ptr<Playlist> pl)
375 clear_time(); //enforce object/range exclusivity
376 clear_tracks(); //enforce object/track exclusivity
378 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
380 playlists.push_back(pl);
386 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
388 clear_time(); //enforce object/range exclusivity
389 clear_tracks(); //enforce object/track exclusivity
391 bool changed = false;
393 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
394 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
396 playlists.push_back (*i);
407 Selection::add (const TrackViewList& track_list)
409 clear_objects(); //enforce object/range exclusivity
411 TrackViewList added = tracks.add (track_list);
413 if (!added.empty()) {
414 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
415 (*x)->set_selected (true);
417 if (!_no_tracks_changed) {
424 Selection::add (TimeAxisView* track)
426 clear_objects(); //enforce object/range exclusivity
429 track->set_selected (true);
430 tr.push_back (track);
435 Selection::add (const MidiNoteSelection& midi_list)
437 clear_time(); //enforce object/range exclusivity
438 clear_tracks(); //enforce object/track exclusivity
440 const MidiNoteSelection::const_iterator b = midi_list.begin();
441 const MidiNoteSelection::const_iterator e = midi_list.end();
443 if (!midi_list.empty()) {
444 midi_notes.insert (midi_notes.end(), b, e);
450 Selection::add (MidiCutBuffer* midi)
452 /* we take ownership of the MCB */
454 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
455 midi_notes.push_back (midi);
461 Selection::add (vector<RegionView*>& v)
463 clear_time(); //enforce object/range exclusivity
464 clear_tracks(); //enforce object/track exclusivity
466 /* XXX This method or the add (const RegionSelection&) needs to go
469 bool changed = false;
471 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
472 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
473 changed = regions.add ((*i));
483 Selection::add (const RegionSelection& rs)
485 clear_time(); //enforce object/range exclusivity
486 clear_tracks(); //enforce object/track exclusivity
488 /* XXX This method or the add (const vector<RegionView*>&) needs to go
491 bool changed = false;
493 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
494 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
495 changed = regions.add ((*i));
505 Selection::add (RegionView* r)
507 clear_time(); //enforce object/range exclusivity
508 clear_tracks(); //enforce object/track exclusivity
510 if (find (regions.begin(), regions.end(), r) == regions.end()) {
511 bool changed = regions.add (r);
519 Selection::add (MidiRegionView* mrv)
521 clear_time(); //enforce object/range exclusivity
522 clear_tracks(); //enforce object/track exclusivity
524 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
525 midi_regions.push_back (mrv);
526 /* XXX should we do this? */
527 MidiRegionsChanged ();
532 Selection::add (framepos_t start, framepos_t end)
534 clear_objects(); //enforce object/range exclusivity
536 AudioRangeComparator cmp;
538 /* XXX this implementation is incorrect */
540 time.push_back (AudioRange (start, end, ++next_time_id));
550 Selection::move_time (framecnt_t distance)
556 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
557 (*i).start += distance;
558 (*i).end += distance;
565 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
567 clear_objects(); //enforce object/range exclusivity
569 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
570 if ((*i).id == sid) {
572 time.push_back (AudioRange(start,end, sid));
574 /* don't consolidate here */
577 AudioRangeComparator cmp;
587 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
589 clear_time(); //enforce object/range exclusivity
590 clear_tracks(); //enforce object/track exclusivity
592 boost::shared_ptr<ARDOUR::AutomationList> al
593 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
595 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
598 if (find (lines.begin(), lines.end(), al) == lines.end()) {
599 lines.push_back (al);
605 Selection::remove (TimeAxisView* track)
607 list<TimeAxisView*>::iterator i;
608 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
609 track->set_selected (false);
611 if (!_no_tracks_changed) {
618 Selection::remove (const TrackViewList& track_list)
620 bool changed = false;
622 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
624 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
625 if (x != tracks.end()) {
626 (*i)->set_selected (false);
633 if (!_no_tracks_changed) {
640 Selection::remove (ControlPoint* p)
642 PointSelection::iterator i = find (points.begin(), points.end(), p);
643 if (i != points.end ()) {
649 Selection::remove (const MidiNoteSelection& midi_list)
651 bool changed = false;
653 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
655 MidiNoteSelection::iterator x;
657 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
658 midi_notes.erase (x);
669 Selection::remove (MidiCutBuffer* midi)
671 MidiNoteSelection::iterator x;
673 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
674 /* remember that we own the MCB */
676 midi_notes.erase (x);
682 Selection::remove (boost::shared_ptr<Playlist> track)
684 list<boost::shared_ptr<Playlist> >::iterator i;
685 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
692 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
694 bool changed = false;
696 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
698 list<boost::shared_ptr<Playlist> >::iterator x;
700 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
712 Selection::remove (RegionView* r)
714 if (regions.remove (r)) {
720 Selection::remove (MidiRegionView* mrv)
722 MidiRegionSelection::iterator x;
724 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
725 midi_regions.erase (x);
726 MidiRegionsChanged ();
732 Selection::remove (uint32_t selection_id)
738 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
739 if ((*i).id == selection_id) {
749 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
754 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
756 AutomationSelection::iterator i;
757 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
764 Selection::set (TimeAxisView* track)
766 clear_objects(); //enforce object/range exclusivity
772 Selection::set (const TrackViewList& track_list)
774 clear_objects(); //enforce object/range exclusivity
780 Selection::set (const MidiNoteSelection& midi_list)
782 clear_time (); //enforce region/object exclusivity
783 clear_tracks(); //enforce object/track exclusivity
789 Selection::set (boost::shared_ptr<Playlist> playlist)
791 clear_time (); //enforce region/object exclusivity
792 clear_tracks(); //enforce object/track exclusivity
798 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
800 clear_time(); //enforce region/object exclusivity
806 Selection::set (const RegionSelection& rs)
808 clear_time(); //enforce region/object exclusivity
809 clear_tracks(); //enforce object/track exclusivity
812 RegionsChanged(); /* EMIT SIGNAL */
816 Selection::set (MidiRegionView* mrv)
818 clear_time(); //enforce region/object exclusivity
819 clear_tracks(); //enforce object/track exclusivity
825 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
827 clear_time(); //enforce region/object exclusivity
828 clear_tracks(); //enforce object/track exclusivity
834 Selection::set (vector<RegionView*>& v)
836 clear_time(); //enforce region/object exclusivity
837 clear_tracks(); //enforce object/track exclusivity
843 /** Set the start and end time of the time selection, without changing
844 * the list of tracks it applies to.
847 Selection::set (framepos_t start, framepos_t end)
849 clear_objects(); //enforce region/object exclusivity
852 if ((start == 0 && end == 0) || end < start) {
857 time.push_back (AudioRange (start, end, ++next_time_id));
859 /* reuse the first entry, and remove all the rest */
861 while (time.size() > 1) {
864 time.front().start = start;
865 time.front().end = end;
872 return time.front().id;
875 /** Set the start and end of the range selection. If more than one range
876 * is currently selected, the start of the earliest range and the end of the
877 * latest range are set. If no range is currently selected, this method
878 * selects a single range from start to end.
880 * @param start New start time.
881 * @param end New end time.
884 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
886 clear_objects(); //enforce region/object exclusivity
888 if ((start == 0 && end == 0) || (end < start)) {
893 time.push_back (AudioRange (start, end, ++next_time_id));
895 time.sort (AudioRangeComparator ());
896 time.front().start = start;
897 time.back().end = end;
906 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
908 clear_time(); //enforce region/object exclusivity
909 clear_tracks(); //enforce object/track exclusivity
916 Selection::selected (ArdourMarker* m)
918 return find (markers.begin(), markers.end(), m) != markers.end();
922 Selection::selected (TimeAxisView* tv)
924 return tv->get_selected ();
928 Selection::selected (RegionView* rv)
930 return find (regions.begin(), regions.end(), rv) != regions.end();
934 Selection::selected (ControlPoint* cp)
936 return find (points.begin(), points.end(), cp) != points.end();
940 Selection::empty (bool internal_selection)
942 bool object_level_empty = regions.empty () &&
945 playlists.empty () &&
948 playlists.empty () &&
953 if (!internal_selection) {
954 return object_level_empty;
957 /* this is intended to really only apply when using a Selection
961 return object_level_empty && midi_notes.empty() && points.empty();
965 Selection::toggle (ControlPoint* cp)
967 clear_time(); //enforce region/object exclusivity
968 clear_tracks(); //enforce object/track exclusivity
970 cp->set_selected (!cp->get_selected ());
971 PointSelection::iterator i = find (points.begin(), points.end(), cp);
972 if (i == points.end()) {
973 points.push_back (cp);
978 PointsChanged (); /* EMIT SIGNAL */
982 Selection::toggle (vector<ControlPoint*> const & cps)
984 clear_time(); //enforce region/object exclusivity
985 clear_tracks(); //enforce object/track exclusivity
987 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
993 Selection::toggle (list<Selectable*> const & selectables)
995 clear_time(); //enforce region/object exclusivity
996 clear_tracks(); //enforce object/track exclusivity
1000 vector<RegionView*> rvs;
1001 vector<ControlPoint*> cps;
1003 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1004 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1006 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1009 fatal << _("programming error: ")
1010 << X_("unknown selectable type passed to Selection::toggle()")
1012 abort(); /*NOTREACHED*/
1026 Selection::set (list<Selectable*> const & selectables)
1028 clear_time (); //enforce region/object exclusivity
1029 clear_tracks(); //enforce object/track exclusivity
1036 Selection::add (PointSelection const & s)
1038 clear_time (); //enforce region/object exclusivity
1039 clear_tracks(); //enforce object/track exclusivity
1041 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1042 points.push_back (*i);
1047 Selection::add (list<Selectable*> const & selectables)
1049 clear_time (); //enforce region/object exclusivity
1050 clear_tracks(); //enforce object/track exclusivity
1054 vector<RegionView*> rvs;
1055 vector<ControlPoint*> cps;
1057 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1058 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1060 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1063 fatal << _("programming error: ")
1064 << X_("unknown selectable type passed to Selection::add()")
1066 abort(); /*NOTREACHED*/
1080 Selection::clear_points ()
1082 if (!points.empty()) {
1089 Selection::add (ControlPoint* cp)
1091 clear_time (); //enforce region/object exclusivity
1092 clear_tracks(); //enforce object/track exclusivity
1094 cp->set_selected (true);
1095 points.push_back (cp);
1096 PointsChanged (); /* EMIT SIGNAL */
1100 Selection::add (vector<ControlPoint*> const & cps)
1102 clear_time (); //enforce region/object exclusivity
1103 clear_tracks(); //enforce object/track exclusivity
1105 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1106 (*i)->set_selected (true);
1107 points.push_back (*i);
1109 PointsChanged (); /* EMIT SIGNAL */
1113 Selection::set (ControlPoint* cp)
1115 clear_time (); //enforce region/object exclusivity
1116 clear_tracks(); //enforce object/track exclusivity
1118 if (cp->get_selected () && points.size () == 1) {
1122 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1123 cp->line().nth (i)->set_selected (false);
1131 Selection::set (ArdourMarker* m)
1133 clear_time (); //enforce region/object exclusivity
1134 clear_tracks(); //enforce object/track exclusivity
1141 Selection::toggle (ArdourMarker* m)
1143 MarkerSelection::iterator i;
1145 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1153 Selection::remove (ArdourMarker* m)
1155 MarkerSelection::iterator i;
1157 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1164 Selection::add (ArdourMarker* m)
1166 clear_time (); //enforce region/object exclusivity
1167 clear_tracks(); //enforce object/track exclusivity
1169 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1170 markers.push_back (m);
1176 Selection::add (const list<ArdourMarker*>& m)
1178 clear_time (); //enforce region/object exclusivity
1179 clear_tracks(); //enforce object/track exclusivity
1181 markers.insert (markers.end(), m.begin(), m.end());
1189 MarkerSelection::range (framepos_t& s, framepos_t& e)
1194 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1196 if ((*i)->position() < s) {
1197 s = (*i)->position();
1200 if ((*i)->position() > e) {
1201 e = (*i)->position();
1205 s = std::min (s, e);
1206 e = std::max (s, e);
1210 Selection::get_state () const
1212 /* XXX: not complete; just sufficient to get track selection state
1213 so that re-opening plugin windows for editor mixer strips works
1217 XMLNode* node = new XMLNode (X_("Selection"));
1219 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1220 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1221 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1223 XMLNode* t = node->add_child (X_("RouteView"));
1224 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1226 XMLNode* t = node->add_child (X_("AutomationView"));
1227 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1228 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1232 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1233 XMLNode* r = node->add_child (X_("Region"));
1234 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1237 /* midi region views have thir own internal selection. */
1239 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1240 editor->get_per_region_note_selection (rid_notes);
1241 if (!rid_notes.empty()) {
1242 n = node->add_child (X_("MIDINote"));
1244 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1245 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1246 assert(n); // hint for clang static analysis
1247 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1249 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1250 XMLNode* nc = n->add_child(X_("note"));
1251 snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1252 nc->add_property(X_("channel"), string(buf));
1254 snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1255 nc->add_property(X_("time"), string(buf));
1257 snprintf(buf, sizeof(buf), "%d", (*i)->note());
1258 nc->add_property(X_("note"), string(buf));
1260 snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1261 nc->add_property(X_("length"), string(buf));
1263 snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1264 nc->add_property(X_("velocity"), string(buf));
1266 snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1267 nc->add_property(X_("off-velocity"), string(buf));
1271 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1272 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1275 XMLNode* r = node->add_child (X_("ControlPoint"));
1276 r->add_property (X_("type"), "track");
1277 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1278 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1279 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1281 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1282 r->add_property (X_("view-index"), string(buf));
1286 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1288 XMLNode* r = node->add_child (X_("ControlPoint"));
1289 r->add_property (X_("type"), "region");
1290 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1291 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1292 r->add_property (X_("view-index"), string(buf));
1297 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1298 XMLNode* t = node->add_child (X_("AudioRange"));
1299 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1300 t->add_property (X_("start"), string(buf));
1301 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1302 t->add_property (X_("end"), string(buf));
1305 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1306 XMLNode* t = node->add_child (X_("Marker"));
1309 Location* loc = editor->find_location_from_marker (*i, is_start);
1311 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1312 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1319 Selection::set_state (XMLNode const & node, int)
1321 if (node.name() != X_("Selection")) {
1326 clear_midi_notes ();
1332 XMLNodeList children = node.children ();
1333 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1334 if ((*i)->name() == X_("RouteView")) {
1336 XMLProperty* prop_id = (*i)->property (X_("id"));
1338 PBD::ID id (prop_id->value ());
1339 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1344 } else if ((*i)->name() == X_("Region")) {
1345 XMLProperty* prop_id = (*i)->property (X_("id"));
1347 PBD::ID id (prop_id->value ());
1350 editor->get_regionviews_by_id (id, rs);
1356 regionviews haven't been constructed - stash the region IDs
1357 so we can identify them in Editor::region_view_added ()
1359 regions.pending.push_back (id);
1362 } else if ((*i)->name() == X_("MIDINote")) {
1363 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1365 assert (prop_region_id);
1367 PBD::ID const id (prop_region_id->value ());
1370 editor->get_regionviews_by_id (id, rs); // there could be more than one
1372 std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1373 XMLNodeList children = (*i)->children ();
1375 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1376 XMLProperty* prop_channel = (*ci)->property (X_("channel"));
1377 XMLProperty* prop_time = (*ci)->property (X_("time"));
1378 XMLProperty* prop_note = (*ci)->property (X_("note"));
1379 XMLProperty* prop_length = (*ci)->property (X_("length"));
1380 XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
1381 XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
1383 assert (prop_channel);
1386 assert (prop_length);
1387 assert (prop_velocity);
1388 assert (prop_off_velocity);
1390 uint8_t channel = atoi(prop_channel->value());
1391 Evoral::Beats time (atof(prop_time->value()));
1392 Evoral::Beats length (atof(prop_length->value()));
1393 uint8_t note = atoi(prop_note->value());
1394 uint8_t velocity = atoi(prop_velocity->value());
1395 uint8_t off_velocity = atoi(prop_off_velocity->value());
1396 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1397 (new Evoral::Note<Evoral::Beats> (channel, time, length, note, velocity));
1398 the_note->set_off_velocity (off_velocity);
1400 notes.push_back (the_note);
1403 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1404 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1406 mrv->select_notes(notes);
1411 /* regionviews containing these notes don't yet exist on the canvas.*/
1412 pending_midi_note_selection.push_back (make_pair (id, notes));
1415 } else if ((*i)->name() == X_("ControlPoint")) {
1416 XMLProperty* prop_type = (*i)->property (X_("type"));
1420 if (prop_type->value () == "track") {
1422 XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
1423 XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
1424 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1425 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1427 assert (prop_route_id);
1428 assert (prop_alist_id);
1429 assert (prop_parameter);
1430 assert (prop_view_index);
1432 PBD::ID route_id (prop_route_id->value ());
1433 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1434 vector <ControlPoint *> cps;
1437 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1439 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1440 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1441 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1442 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1454 } else if (prop_type->value () == "region") {
1455 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1456 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1458 if (!prop_region_id || !prop_view_index) {
1462 PBD::ID region_id (prop_region_id->value ());
1464 editor->get_regionviews_by_id (region_id, rs);
1467 vector <ControlPoint *> cps;
1468 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1469 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1471 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1472 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1485 } else if ((*i)->name() == X_("AudioRange")) {
1486 XMLProperty* prop_start = (*i)->property (X_("start"));
1487 XMLProperty* prop_end = (*i)->property (X_("end"));
1489 assert (prop_start);
1492 framepos_t s (atol (prop_start->value ().c_str()));
1493 framepos_t e (atol (prop_end->value ().c_str()));
1495 set_preserving_all_ranges (s, e);
1497 } else if ((*i)->name() == X_("AutomationView")) {
1499 XMLProperty* prop_id = (*i)->property (X_("id"));
1500 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1503 assert (prop_parameter);
1505 PBD::ID id (prop_id->value ());
1506 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1509 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1511 /* the automation could be for an entity that was never saved
1512 in the session file. Don't freak out if we can't find
1521 } else if ((*i)->name() == X_("Marker")) {
1523 XMLProperty* prop_id = (*i)->property (X_("id"));
1524 XMLProperty* prop_start = (*i)->property (X_("start"));
1526 assert (prop_start);
1528 PBD::ID id (prop_id->value ());
1529 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1542 Selection::remove_regions (TimeAxisView* t)
1544 RegionSelection::iterator i = regions.begin();
1545 while (i != regions.end ()) {
1546 RegionSelection::iterator tmp = i;
1549 if (&(*i)->get_time_axis_view() == t) {
1558 Selection::block_tracks_changed (bool yn)
1560 _no_tracks_changed = yn;