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 "control_protocol/control_protocol.h"
31 #include "audio_region_view.h"
33 #include "gui_thread.h"
34 #include "midi_cut_buffer.h"
35 #include "region_gain_line.h"
36 #include "region_view.h"
37 #include "selection.h"
38 #include "selection_templates.h"
39 #include "time_axis_view.h"
40 #include "automation_time_axis.h"
41 #include "public_editor.h"
42 #include "control_point.h"
43 #include "vca_time_axis.h"
48 using namespace ARDOUR;
51 struct AudioRangeComparator {
52 bool operator()(AudioRange a, AudioRange b) {
53 return a.start < b.start;
57 Selection::Selection (const PublicEditor* e)
64 /* we have disambiguate which remove() for the compiler */
66 void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
67 TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
69 void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
70 ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
72 void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
73 ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
78 Selection::operator= (const Selection& other)
81 regions = other.regions;
82 tracks = other.tracks;
85 midi_regions = other.midi_regions;
86 midi_notes = other.midi_notes;
93 operator== (const Selection& a, const Selection& b)
95 return a.regions == b.regions &&
96 a.tracks == b.tracks &&
99 a.playlists == b.playlists &&
100 a.midi_notes == b.midi_notes &&
101 a.midi_regions == b.midi_regions;
104 /** Clear everything from the Selection */
115 clear_midi_regions ();
117 pending_midi_note_selection.clear();
121 Selection::clear_objects (bool with_signal)
123 clear_regions (with_signal);
124 clear_points (with_signal);
125 clear_lines(with_signal);
126 clear_playlists (with_signal);
127 clear_midi_notes (with_signal);
128 clear_midi_regions (with_signal);
132 Selection::clear_tracks (bool with_signal)
134 if (!tracks.empty()) {
135 PresentationInfo::ChangeSuspender cs;
137 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
138 (*x)->set_selected (false);
146 Selection::clear_time (bool with_signal)
155 Selection::dump_region_layers()
157 cerr << "region selection layer dump" << endl;
158 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
159 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
165 Selection::clear_regions (bool with_signal)
167 if (!regions.empty()) {
168 regions.clear_all ();
176 Selection::clear_midi_notes (bool with_signal)
178 if (!midi_notes.empty()) {
179 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
188 // clear note selections for MRV's that have note selections
189 // this will cause the MRV to be removed from the list
190 for (MidiRegionSelection::iterator i = midi_regions.begin();
191 i != midi_regions.end();) {
192 MidiRegionSelection::iterator tmp = i;
194 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
196 mrv->clear_selection();
203 Selection::clear_midi_regions (bool with_signal)
205 if (!midi_regions.empty()) {
206 midi_regions.clear ();
208 MidiRegionsChanged ();
214 Selection::clear_playlists (bool with_signal)
216 /* Selections own their playlists */
218 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
219 /* selections own their own regions, which are copies of the "originals". make them go away */
220 (*i)->drop_regions ();
224 if (!playlists.empty()) {
233 Selection::clear_lines (bool with_signal)
235 if (!lines.empty()) {
244 Selection::clear_markers (bool with_signal)
246 if (!markers.empty()) {
255 Selection::toggle (boost::shared_ptr<Playlist> pl)
257 clear_time(); //enforce object/range exclusivity
258 clear_tracks(); //enforce object/track exclusivity
260 PlaylistSelection::iterator i;
262 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
264 playlists.push_back(pl);
273 Selection::toggle (const TrackViewList& track_list)
275 PresentationInfo::ChangeSuspender cs;
277 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
278 if (dynamic_cast<VCATimeAxisView*> (*i)) {
286 Selection::toggle (TimeAxisView* track)
288 if (dynamic_cast<VCATimeAxisView*> (track)) {
292 TrackSelection::iterator i;
294 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
295 tracks.push_back (track);
296 track->set_selected (true);
299 track->set_selected (false);
305 Selection::toggle (const MidiNoteSelection& midi_note_list)
307 clear_time(); //enforce object/range exclusivity
308 clear_tracks(); //enforce object/track exclusivity
310 for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
316 Selection::toggle (MidiCutBuffer* midi)
318 MidiNoteSelection::iterator i;
320 if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
321 midi_notes.push_back (midi);
323 /* remember that we own the MCB */
325 midi_notes.erase (i);
333 Selection::toggle (RegionView* r)
335 clear_time(); //enforce object/range exclusivity
336 clear_tracks(); //enforce object/track exclusivity
338 RegionSelection::iterator i;
340 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
350 Selection::toggle (MidiRegionView* mrv)
352 clear_time(); //enforce object/range exclusivity
353 clear_tracks(); //enforce object/track exclusivity
355 MidiRegionSelection::iterator i;
357 if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
360 midi_regions.erase (i);
363 MidiRegionsChanged ();
367 Selection::toggle (vector<RegionView*>& r)
369 clear_time(); //enforce object/range exclusivity
370 clear_tracks(); //enforce object/track exclusivity
372 RegionSelection::iterator i;
374 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
375 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
386 Selection::toggle (framepos_t start, framepos_t end)
388 clear_objects(); //enforce object/range exclusivity
390 AudioRangeComparator cmp;
392 /* XXX this implementation is incorrect */
394 time.push_back (AudioRange (start, end, ++next_time_id));
404 Selection::add (boost::shared_ptr<Playlist> pl)
406 clear_time(); //enforce object/range exclusivity
407 clear_tracks(); //enforce object/track exclusivity
409 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
411 playlists.push_back(pl);
417 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
419 clear_time(); //enforce object/range exclusivity
420 clear_tracks(); //enforce object/track exclusivity
422 bool changed = false;
424 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
425 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
427 playlists.push_back (*i);
438 Selection::add (TrackViewList const & track_list)
440 clear_objects(); //enforce object/range exclusivity
442 PresentationInfo::ChangeSuspender cs;
444 TrackViewList added = tracks.add (track_list);
446 if (!added.empty()) {
447 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
448 if (dynamic_cast<VCATimeAxisView*> (*x)) {
451 (*x)->set_selected (true);
457 Selection::add (TimeAxisView* track)
459 if (dynamic_cast<VCATimeAxisView*> (track)) {
464 tr.push_back (track);
469 Selection::add (const MidiNoteSelection& midi_list)
471 clear_time(); //enforce object/range exclusivity
472 clear_tracks(); //enforce object/track exclusivity
474 const MidiNoteSelection::const_iterator b = midi_list.begin();
475 const MidiNoteSelection::const_iterator e = midi_list.end();
477 if (!midi_list.empty()) {
478 midi_notes.insert (midi_notes.end(), b, e);
484 Selection::add (MidiCutBuffer* midi)
486 /* we take ownership of the MCB */
488 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
489 midi_notes.push_back (midi);
495 Selection::add (vector<RegionView*>& v)
497 clear_time(); //enforce object/range exclusivity
498 clear_tracks(); //enforce object/track exclusivity
500 /* XXX This method or the add (const RegionSelection&) needs to go
503 bool changed = false;
505 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
506 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
507 changed = regions.add ((*i));
517 Selection::add (const RegionSelection& rs)
519 clear_time(); //enforce object/range exclusivity
520 clear_tracks(); //enforce object/track exclusivity
522 /* XXX This method or the add (const vector<RegionView*>&) needs to go
525 bool changed = false;
527 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
528 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
529 changed = regions.add ((*i));
539 Selection::add (RegionView* r)
541 clear_time(); //enforce object/range exclusivity
542 clear_tracks(); //enforce object/track exclusivity
544 if (find (regions.begin(), regions.end(), r) == regions.end()) {
545 bool changed = regions.add (r);
553 Selection::add (MidiRegionView* mrv)
555 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
557 clear_time(); //enforce object/range exclusivity
558 clear_tracks(); //enforce object/track exclusivity
560 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
561 midi_regions.push_back (mrv);
562 /* XXX should we do this? */
563 MidiRegionsChanged ();
568 Selection::add (framepos_t start, framepos_t end)
570 clear_objects(); //enforce object/range exclusivity
572 AudioRangeComparator cmp;
574 /* XXX this implementation is incorrect */
576 time.push_back (AudioRange (start, end, ++next_time_id));
586 Selection::move_time (framecnt_t distance)
592 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
593 (*i).start += distance;
594 (*i).end += distance;
601 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
603 clear_objects(); //enforce object/range exclusivity
605 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
606 if ((*i).id == sid) {
608 time.push_back (AudioRange(start,end, sid));
610 /* don't consolidate here */
613 AudioRangeComparator cmp;
623 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
625 clear_time(); //enforce object/range exclusivity
626 clear_tracks(); //enforce object/track exclusivity
628 boost::shared_ptr<ARDOUR::AutomationList> al
629 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
631 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
635 /* The original may change so we must store a copy (not a pointer) here.
636 * e.g AutomationLine rewrites the list with gain mapping.
637 * the downside is that we can't perfom duplicate checks.
638 * This code was changed in response to #6842
640 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
645 Selection::remove (TimeAxisView* track)
647 list<TimeAxisView*>::iterator i;
648 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
649 /* erase first, because set_selected() will remove the track
650 from the selection, invalidating the iterator.
652 In fact, we don't really even need to do the erase, but this is
653 a hangover of axis view selection being in the GUI.
656 track->set_selected (false);
661 Selection::remove (const TrackViewList& track_list)
663 PresentationInfo::ChangeSuspender cs;
665 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
667 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
669 if (x != tracks.end()) {
671 (*i)->set_selected (false);
677 Selection::remove (ControlPoint* p)
679 PointSelection::iterator i = find (points.begin(), points.end(), p);
680 if (i != points.end ()) {
686 Selection::remove (const MidiNoteSelection& midi_list)
688 bool changed = false;
690 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
692 MidiNoteSelection::iterator x;
694 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
695 midi_notes.erase (x);
706 Selection::remove (MidiCutBuffer* midi)
708 MidiNoteSelection::iterator x;
710 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
711 /* remember that we own the MCB */
713 midi_notes.erase (x);
719 Selection::remove (boost::shared_ptr<Playlist> track)
721 list<boost::shared_ptr<Playlist> >::iterator i;
722 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
729 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
731 bool changed = false;
733 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
735 list<boost::shared_ptr<Playlist> >::iterator x;
737 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
749 Selection::remove (RegionView* r)
751 if (regions.remove (r)) {
757 Selection::remove (MidiRegionView* mrv)
759 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
761 MidiRegionSelection::iterator x;
763 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
764 midi_regions.erase (x);
765 MidiRegionsChanged ();
770 Selection::remove (uint32_t selection_id)
776 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
777 if ((*i).id == selection_id) {
787 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
792 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
794 AutomationSelection::iterator i;
795 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
802 Selection::set (TimeAxisView* track)
804 if (dynamic_cast<VCATimeAxisView*> (track)) {
807 clear_objects (); //enforce object/range exclusivity
809 PresentationInfo::ChangeSuspender cs;
811 if (!tracks.empty()) {
813 if (tracks.size() == 1 && tracks.front() == track) {
814 /* already single selection: nothing to do */
818 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
819 (*x)->set_selected (false);
829 Selection::set (const TrackViewList& track_list)
831 clear_objects(); //enforce object/range exclusivity
834 TrackViewList to_be_added;
835 TrackViewList to_be_removed;
837 for (TrackViewList::const_iterator x = tracks.begin(); x != tracks.end(); ++x) {
838 if (find (track_list.begin(), track_list.end(), *x) == track_list.end()) {
839 to_be_removed.push_back (*x);
843 for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
844 if (dynamic_cast<VCATimeAxisView*> (*x)) {
847 if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) {
848 to_be_added.push_back (*x);
852 PresentationInfo::ChangeSuspender cs;
853 remove (to_be_removed);
859 Selection::set (const MidiNoteSelection& midi_list)
861 clear_time (); //enforce region/object exclusivity
862 clear_tracks(); //enforce object/track exclusivity
868 Selection::set (boost::shared_ptr<Playlist> playlist)
870 clear_time (); //enforce region/object exclusivity
871 clear_tracks(); //enforce object/track exclusivity
877 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
879 clear_time(); //enforce region/object exclusivity
885 Selection::set (const RegionSelection& rs)
887 clear_time(); //enforce region/object exclusivity
888 clear_tracks(); //enforce object/track exclusivity
891 RegionsChanged(); /* EMIT SIGNAL */
895 Selection::set (MidiRegionView* mrv)
897 clear_time(); //enforce region/object exclusivity
898 clear_tracks(); //enforce object/track exclusivity
904 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
906 clear_time(); //enforce region/object exclusivity
907 clear_tracks(); //enforce object/track exclusivity
913 Selection::set (vector<RegionView*>& v)
915 clear_time(); //enforce region/object exclusivity
916 clear_tracks(); //enforce object/track exclusivity
922 /** Set the start and end time of the time selection, without changing
923 * the list of tracks it applies to.
926 Selection::set (framepos_t start, framepos_t end)
928 clear_objects(); //enforce region/object exclusivity
931 if ((start == 0 && end == 0) || end < start) {
936 time.push_back (AudioRange (start, end, ++next_time_id));
938 /* reuse the first entry, and remove all the rest */
940 while (time.size() > 1) {
943 time.front().start = start;
944 time.front().end = end;
951 return time.front().id;
954 /** Set the start and end of the range selection. If more than one range
955 * is currently selected, the start of the earliest range and the end of the
956 * latest range are set. If no range is currently selected, this method
957 * selects a single range from start to end.
959 * @param start New start time.
960 * @param end New end time.
963 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
965 clear_objects(); //enforce region/object exclusivity
967 if ((start == 0 && end == 0) || (end < start)) {
972 time.push_back (AudioRange (start, end, ++next_time_id));
974 time.sort (AudioRangeComparator ());
975 time.front().start = start;
976 time.back().end = end;
985 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
987 clear_time(); //enforce region/object exclusivity
988 clear_tracks(); //enforce object/track exclusivity
995 Selection::selected (ArdourMarker* m) const
997 return find (markers.begin(), markers.end(), m) != markers.end();
1001 Selection::selected (TimeAxisView* tv) const
1003 return tv->selected ();
1007 Selection::selected (RegionView* rv) const
1009 return find (regions.begin(), regions.end(), rv) != regions.end();
1013 Selection::selected (ControlPoint* cp) const
1015 return find (points.begin(), points.end(), cp) != points.end();
1019 Selection::empty (bool internal_selection)
1021 bool object_level_empty = regions.empty () &&
1024 playlists.empty () &&
1027 playlists.empty () &&
1029 midi_regions.empty()
1032 if (!internal_selection) {
1033 return object_level_empty;
1036 /* this is intended to really only apply when using a Selection
1040 return object_level_empty && midi_notes.empty() && points.empty();
1044 Selection::toggle (ControlPoint* cp)
1046 clear_time(); //enforce region/object exclusivity
1047 clear_tracks(); //enforce object/track exclusivity
1049 cp->set_selected (!cp->selected ());
1050 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1051 if (i == points.end()) {
1052 points.push_back (cp);
1057 PointsChanged (); /* EMIT SIGNAL */
1061 Selection::toggle (vector<ControlPoint*> const & cps)
1063 clear_time(); //enforce region/object exclusivity
1064 clear_tracks(); //enforce object/track exclusivity
1066 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1072 Selection::toggle (list<Selectable*> const & selectables)
1074 clear_time(); //enforce region/object exclusivity
1075 clear_tracks(); //enforce object/track exclusivity
1079 vector<RegionView*> rvs;
1080 vector<ControlPoint*> cps;
1082 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1083 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1085 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1088 fatal << _("programming error: ")
1089 << X_("unknown selectable type passed to Selection::toggle()")
1091 abort(); /*NOTREACHED*/
1105 Selection::set (list<Selectable*> const & selectables)
1107 clear_time (); //enforce region/object exclusivity
1108 clear_tracks(); //enforce object/track exclusivity
1115 Selection::add (PointSelection const & s)
1117 clear_time (); //enforce region/object exclusivity
1118 clear_tracks(); //enforce object/track exclusivity
1120 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1121 points.push_back (*i);
1126 Selection::add (list<Selectable*> const & selectables)
1128 clear_time (); //enforce region/object exclusivity
1129 clear_tracks(); //enforce object/track exclusivity
1133 vector<RegionView*> rvs;
1134 vector<ControlPoint*> cps;
1136 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1137 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1139 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1142 fatal << _("programming error: ")
1143 << X_("unknown selectable type passed to Selection::add()")
1145 abort(); /*NOTREACHED*/
1159 Selection::clear_points (bool with_signal)
1161 if (!points.empty()) {
1170 Selection::add (ControlPoint* cp)
1172 clear_time (); //enforce region/object exclusivity
1173 clear_tracks(); //enforce object/track exclusivity
1175 cp->set_selected (true);
1176 points.push_back (cp);
1177 PointsChanged (); /* EMIT SIGNAL */
1181 Selection::add (vector<ControlPoint*> const & cps)
1183 clear_time (); //enforce region/object exclusivity
1184 clear_tracks(); //enforce object/track exclusivity
1186 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1187 (*i)->set_selected (true);
1188 points.push_back (*i);
1190 PointsChanged (); /* EMIT SIGNAL */
1194 Selection::set (ControlPoint* cp)
1196 clear_time (); //enforce region/object exclusivity
1197 clear_tracks(); //enforce object/track exclusivity
1199 if (cp->selected () && points.size () == 1) {
1203 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1204 cp->line().nth (i)->set_selected (false);
1212 Selection::set (ArdourMarker* m)
1214 clear_time (); //enforce region/object exclusivity
1215 clear_tracks(); //enforce object/track exclusivity
1222 Selection::toggle (ArdourMarker* m)
1224 MarkerSelection::iterator i;
1226 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1234 Selection::remove (ArdourMarker* m)
1236 MarkerSelection::iterator i;
1238 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1245 Selection::add (ArdourMarker* m)
1247 clear_time (); //enforce region/object exclusivity
1248 clear_tracks(); //enforce object/track exclusivity
1250 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1251 markers.push_back (m);
1257 Selection::add (const list<ArdourMarker*>& m)
1259 clear_time (); //enforce region/object exclusivity
1260 clear_tracks(); //enforce object/track exclusivity
1262 markers.insert (markers.end(), m.begin(), m.end());
1270 MarkerSelection::range (framepos_t& s, framepos_t& e)
1275 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1277 if ((*i)->position() < s) {
1278 s = (*i)->position();
1281 if ((*i)->position() > e) {
1282 e = (*i)->position();
1286 s = std::min (s, e);
1287 e = std::max (s, e);
1291 Selection::get_state () const
1293 /* XXX: not complete; just sufficient to get track selection state
1294 so that re-opening plugin windows for editor mixer strips works
1298 XMLNode* node = new XMLNode (X_("Selection"));
1300 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1301 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1302 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1304 XMLNode* t = node->add_child (X_("RouteView"));
1305 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1307 XMLNode* t = node->add_child (X_("AutomationView"));
1308 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1309 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1313 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1314 XMLNode* r = node->add_child (X_("Region"));
1315 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1318 /* midi region views have thir own internal selection. */
1319 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1320 editor->get_per_region_note_selection (rid_notes);
1322 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1323 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1324 XMLNode* n = node->add_child (X_("MIDINotes"));
1325 n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
1327 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1328 XMLNode* nc = n->add_child(X_("note"));
1330 snprintf(buf, sizeof(buf), "%d", (*i)->id());
1331 nc->add_property (X_("note-id"), string(buf));
1335 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1336 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1339 XMLNode* r = node->add_child (X_("ControlPoint"));
1340 r->add_property (X_("type"), "track");
1341 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1342 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1343 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1345 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1346 r->add_property (X_("view-index"), string(buf));
1350 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1352 XMLNode* r = node->add_child (X_("ControlPoint"));
1353 r->add_property (X_("type"), "region");
1354 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1355 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1356 r->add_property (X_("view-index"), string(buf));
1361 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1362 XMLNode* t = node->add_child (X_("AudioRange"));
1363 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1364 t->add_property (X_("start"), string(buf));
1365 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1366 t->add_property (X_("end"), string(buf));
1369 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1370 XMLNode* t = node->add_child (X_("Marker"));
1373 Location* loc = editor->find_location_from_marker (*i, is_start);
1375 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1376 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1383 Selection::set_state (XMLNode const & node, int)
1385 if (node.name() != X_("Selection")) {
1390 clear_midi_notes ();
1396 XMLNodeList children = node.children ();
1397 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1398 if ((*i)->name() == X_("RouteView")) {
1400 XMLProperty const * prop_id = (*i)->property (X_("id"));
1402 PBD::ID id (prop_id->value ());
1403 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1408 } else if ((*i)->name() == X_("Region")) {
1409 XMLProperty const * prop_id = (*i)->property (X_("id"));
1411 PBD::ID id (prop_id->value ());
1414 editor->get_regionviews_by_id (id, rs);
1420 regionviews haven't been constructed - stash the region IDs
1421 so we can identify them in Editor::region_view_added ()
1423 regions.pending.push_back (id);
1426 } else if ((*i)->name() == X_("MIDINotes")) {
1427 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1429 assert (prop_region_id);
1431 PBD::ID const id (prop_region_id->value ());
1434 editor->get_regionviews_by_id (id, rs); // there could be more than one
1436 std::list<Evoral::event_id_t> notes;
1437 XMLNodeList children = (*i)->children ();
1439 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1440 XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
1442 Evoral::event_id_t id = atoi(prop_id->value());
1443 notes.push_back (id);
1447 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1448 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1450 mrv->select_notes(notes);
1455 /* regionviews containing these notes don't yet exist on the canvas.*/
1456 pending_midi_note_selection.push_back (make_pair (id, notes));
1459 } else if ((*i)->name() == X_("ControlPoint")) {
1460 XMLProperty const * prop_type = (*i)->property (X_("type"));
1464 if (prop_type->value () == "track") {
1466 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1467 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1468 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1469 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1471 assert (prop_route_id);
1472 assert (prop_alist_id);
1473 assert (prop_parameter);
1474 assert (prop_view_index);
1476 PBD::ID route_id (prop_route_id->value ());
1477 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1478 vector <ControlPoint *> cps;
1481 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1483 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1484 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1485 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1486 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1498 } else if (prop_type->value () == "region") {
1499 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1500 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1502 if (!prop_region_id || !prop_view_index) {
1506 PBD::ID region_id (prop_region_id->value ());
1508 editor->get_regionviews_by_id (region_id, rs);
1511 vector <ControlPoint *> cps;
1512 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1513 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1515 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1516 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1529 } else if ((*i)->name() == X_("AudioRange")) {
1530 XMLProperty const * prop_start = (*i)->property (X_("start"));
1531 XMLProperty const * prop_end = (*i)->property (X_("end"));
1533 assert (prop_start);
1536 framepos_t s (atol (prop_start->value ().c_str()));
1537 framepos_t e (atol (prop_end->value ().c_str()));
1539 set_preserving_all_ranges (s, e);
1541 } else if ((*i)->name() == X_("AutomationView")) {
1543 XMLProperty const * prop_id = (*i)->property (X_("id"));
1544 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1547 assert (prop_parameter);
1549 PBD::ID id (prop_id->value ());
1550 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1553 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1555 /* the automation could be for an entity that was never saved
1556 in the session file. Don't freak out if we can't find
1565 } else if ((*i)->name() == X_("Marker")) {
1567 XMLProperty const * prop_id = (*i)->property (X_("id"));
1568 XMLProperty const * prop_start = (*i)->property (X_("start"));
1570 assert (prop_start);
1572 PBD::ID id (prop_id->value ());
1573 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1586 Selection::remove_regions (TimeAxisView* t)
1588 RegionSelection::iterator i = regions.begin();
1589 while (i != regions.end ()) {
1590 RegionSelection::iterator tmp = i;
1593 if (&(*i)->get_time_axis_view() == t) {