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)) {
462 clear_objects(); //enforce object/range exclusivity
465 track->set_selected (true);
466 tr.push_back (track);
471 Selection::add (const MidiNoteSelection& midi_list)
473 clear_time(); //enforce object/range exclusivity
474 clear_tracks(); //enforce object/track exclusivity
476 const MidiNoteSelection::const_iterator b = midi_list.begin();
477 const MidiNoteSelection::const_iterator e = midi_list.end();
479 if (!midi_list.empty()) {
480 midi_notes.insert (midi_notes.end(), b, e);
486 Selection::add (MidiCutBuffer* midi)
488 /* we take ownership of the MCB */
490 if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
491 midi_notes.push_back (midi);
497 Selection::add (vector<RegionView*>& v)
499 clear_time(); //enforce object/range exclusivity
500 clear_tracks(); //enforce object/track exclusivity
502 /* XXX This method or the add (const RegionSelection&) needs to go
505 bool changed = false;
507 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
508 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
509 changed = regions.add ((*i));
519 Selection::add (const RegionSelection& rs)
521 clear_time(); //enforce object/range exclusivity
522 clear_tracks(); //enforce object/track exclusivity
524 /* XXX This method or the add (const vector<RegionView*>&) needs to go
527 bool changed = false;
529 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
530 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
531 changed = regions.add ((*i));
541 Selection::add (RegionView* r)
543 clear_time(); //enforce object/range exclusivity
544 clear_tracks(); //enforce object/track exclusivity
546 if (find (regions.begin(), regions.end(), r) == regions.end()) {
547 bool changed = regions.add (r);
555 Selection::add (MidiRegionView* mrv)
557 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
559 clear_time(); //enforce object/range exclusivity
560 clear_tracks(); //enforce object/track exclusivity
562 if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
563 midi_regions.push_back (mrv);
564 /* XXX should we do this? */
565 MidiRegionsChanged ();
570 Selection::add (framepos_t start, framepos_t end)
572 clear_objects(); //enforce object/range exclusivity
574 AudioRangeComparator cmp;
576 /* XXX this implementation is incorrect */
578 time.push_back (AudioRange (start, end, ++next_time_id));
588 Selection::move_time (framecnt_t distance)
594 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
595 (*i).start += distance;
596 (*i).end += distance;
603 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
605 clear_objects(); //enforce object/range exclusivity
607 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
608 if ((*i).id == sid) {
610 time.push_back (AudioRange(start,end, sid));
612 /* don't consolidate here */
615 AudioRangeComparator cmp;
625 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
627 clear_time(); //enforce object/range exclusivity
628 clear_tracks(); //enforce object/track exclusivity
630 boost::shared_ptr<ARDOUR::AutomationList> al
631 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
633 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
637 /* The original may change so we must store a copy (not a pointer) here.
638 * e.g AutomationLine rewrites the list with gain mapping.
639 * the downside is that we can't perfom duplicate checks.
640 * This code was changed in response to #6842
642 lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
647 Selection::remove (TimeAxisView* track)
649 list<TimeAxisView*>::iterator i;
650 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
651 track->set_selected (false);
657 Selection::remove (const TrackViewList& track_list)
659 PresentationInfo::ChangeSuspender cs;
661 for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
663 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
665 if (x != tracks.end()) {
667 (*i)->set_selected (false);
673 Selection::remove (ControlPoint* p)
675 PointSelection::iterator i = find (points.begin(), points.end(), p);
676 if (i != points.end ()) {
682 Selection::remove (const MidiNoteSelection& midi_list)
684 bool changed = false;
686 for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
688 MidiNoteSelection::iterator x;
690 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
691 midi_notes.erase (x);
702 Selection::remove (MidiCutBuffer* midi)
704 MidiNoteSelection::iterator x;
706 if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
707 /* remember that we own the MCB */
709 midi_notes.erase (x);
715 Selection::remove (boost::shared_ptr<Playlist> track)
717 list<boost::shared_ptr<Playlist> >::iterator i;
718 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
725 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
727 bool changed = false;
729 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
731 list<boost::shared_ptr<Playlist> >::iterator x;
733 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
745 Selection::remove (RegionView* r)
747 if (regions.remove (r)) {
753 Selection::remove (MidiRegionView* mrv)
755 DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
757 MidiRegionSelection::iterator x;
759 if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
760 midi_regions.erase (x);
761 MidiRegionsChanged ();
766 Selection::remove (uint32_t selection_id)
772 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
773 if ((*i).id == selection_id) {
783 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
788 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
790 AutomationSelection::iterator i;
791 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
798 Selection::set (TimeAxisView* track)
800 if (dynamic_cast<VCATimeAxisView*> (track)) {
803 clear_objects (); //enforce object/range exclusivity
805 PresentationInfo::ChangeSuspender cs;
807 if (!tracks.empty()) {
809 if (tracks.size() == 1 && tracks.front() == track) {
810 /* already single selection: nothing to do */
814 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
815 (*x)->set_selected (false);
825 Selection::set (const TrackViewList& track_list)
827 clear_objects(); //enforce object/range exclusivity
829 PresentationInfo::ChangeSuspender cs;
831 if (!tracks.empty()) {
833 /* cannot use set<T>::operator== (set<T> const &) here, because
834 * apparently the ordering used within 2 sets is not
835 * necessarily the same.
838 if (tracks.size() == track_list.size()) {
839 bool missing = false;
841 for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
842 if (dynamic_cast<VCATimeAxisView*> (*x)) {
845 if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) {
851 /* already same selection: nothing to do */
856 /* argument is different from existing selection */
858 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
859 if (dynamic_cast<VCATimeAxisView*> (*x)) {
862 (*x)->set_selected (false);
872 Selection::set (const MidiNoteSelection& midi_list)
874 clear_time (); //enforce region/object exclusivity
875 clear_tracks(); //enforce object/track exclusivity
881 Selection::set (boost::shared_ptr<Playlist> playlist)
883 clear_time (); //enforce region/object exclusivity
884 clear_tracks(); //enforce object/track exclusivity
890 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
892 clear_time(); //enforce region/object exclusivity
898 Selection::set (const RegionSelection& rs)
900 clear_time(); //enforce region/object exclusivity
901 clear_tracks(); //enforce object/track exclusivity
904 RegionsChanged(); /* EMIT SIGNAL */
908 Selection::set (MidiRegionView* mrv)
910 clear_time(); //enforce region/object exclusivity
911 clear_tracks(); //enforce object/track exclusivity
917 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
919 clear_time(); //enforce region/object exclusivity
920 clear_tracks(); //enforce object/track exclusivity
926 Selection::set (vector<RegionView*>& v)
928 clear_time(); //enforce region/object exclusivity
929 clear_tracks(); //enforce object/track exclusivity
935 /** Set the start and end time of the time selection, without changing
936 * the list of tracks it applies to.
939 Selection::set (framepos_t start, framepos_t end)
941 clear_objects(); //enforce region/object exclusivity
944 if ((start == 0 && end == 0) || end < start) {
949 time.push_back (AudioRange (start, end, ++next_time_id));
951 /* reuse the first entry, and remove all the rest */
953 while (time.size() > 1) {
956 time.front().start = start;
957 time.front().end = end;
964 return time.front().id;
967 /** Set the start and end of the range selection. If more than one range
968 * is currently selected, the start of the earliest range and the end of the
969 * latest range are set. If no range is currently selected, this method
970 * selects a single range from start to end.
972 * @param start New start time.
973 * @param end New end time.
976 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
978 clear_objects(); //enforce region/object exclusivity
980 if ((start == 0 && end == 0) || (end < start)) {
985 time.push_back (AudioRange (start, end, ++next_time_id));
987 time.sort (AudioRangeComparator ());
988 time.front().start = start;
989 time.back().end = end;
998 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
1000 clear_time(); //enforce region/object exclusivity
1001 clear_tracks(); //enforce object/track exclusivity
1008 Selection::selected (ArdourMarker* m)
1010 return find (markers.begin(), markers.end(), m) != markers.end();
1014 Selection::selected (TimeAxisView* tv)
1016 return tv->selected ();
1020 Selection::selected (RegionView* rv)
1022 return find (regions.begin(), regions.end(), rv) != regions.end();
1026 Selection::selected (ControlPoint* cp)
1028 return find (points.begin(), points.end(), cp) != points.end();
1032 Selection::empty (bool internal_selection)
1034 bool object_level_empty = regions.empty () &&
1037 playlists.empty () &&
1040 playlists.empty () &&
1042 midi_regions.empty()
1045 if (!internal_selection) {
1046 return object_level_empty;
1049 /* this is intended to really only apply when using a Selection
1053 return object_level_empty && midi_notes.empty() && points.empty();
1057 Selection::toggle (ControlPoint* cp)
1059 clear_time(); //enforce region/object exclusivity
1060 clear_tracks(); //enforce object/track exclusivity
1062 cp->set_selected (!cp->selected ());
1063 PointSelection::iterator i = find (points.begin(), points.end(), cp);
1064 if (i == points.end()) {
1065 points.push_back (cp);
1070 PointsChanged (); /* EMIT SIGNAL */
1074 Selection::toggle (vector<ControlPoint*> const & cps)
1076 clear_time(); //enforce region/object exclusivity
1077 clear_tracks(); //enforce object/track exclusivity
1079 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1085 Selection::toggle (list<Selectable*> const & selectables)
1087 clear_time(); //enforce region/object exclusivity
1088 clear_tracks(); //enforce object/track exclusivity
1092 vector<RegionView*> rvs;
1093 vector<ControlPoint*> cps;
1095 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1096 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1098 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1101 fatal << _("programming error: ")
1102 << X_("unknown selectable type passed to Selection::toggle()")
1104 abort(); /*NOTREACHED*/
1118 Selection::set (list<Selectable*> const & selectables)
1120 clear_time (); //enforce region/object exclusivity
1121 clear_tracks(); //enforce object/track exclusivity
1128 Selection::add (PointSelection const & s)
1130 clear_time (); //enforce region/object exclusivity
1131 clear_tracks(); //enforce object/track exclusivity
1133 for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1134 points.push_back (*i);
1139 Selection::add (list<Selectable*> const & selectables)
1141 clear_time (); //enforce region/object exclusivity
1142 clear_tracks(); //enforce object/track exclusivity
1146 vector<RegionView*> rvs;
1147 vector<ControlPoint*> cps;
1149 for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1150 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1152 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1155 fatal << _("programming error: ")
1156 << X_("unknown selectable type passed to Selection::add()")
1158 abort(); /*NOTREACHED*/
1172 Selection::clear_points (bool with_signal)
1174 if (!points.empty()) {
1183 Selection::add (ControlPoint* cp)
1185 clear_time (); //enforce region/object exclusivity
1186 clear_tracks(); //enforce object/track exclusivity
1188 cp->set_selected (true);
1189 points.push_back (cp);
1190 PointsChanged (); /* EMIT SIGNAL */
1194 Selection::add (vector<ControlPoint*> const & cps)
1196 clear_time (); //enforce region/object exclusivity
1197 clear_tracks(); //enforce object/track exclusivity
1199 for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1200 (*i)->set_selected (true);
1201 points.push_back (*i);
1203 PointsChanged (); /* EMIT SIGNAL */
1207 Selection::set (ControlPoint* cp)
1209 clear_time (); //enforce region/object exclusivity
1210 clear_tracks(); //enforce object/track exclusivity
1212 if (cp->selected () && points.size () == 1) {
1216 for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1217 cp->line().nth (i)->set_selected (false);
1225 Selection::set (ArdourMarker* m)
1227 clear_time (); //enforce region/object exclusivity
1228 clear_tracks(); //enforce object/track exclusivity
1235 Selection::toggle (ArdourMarker* m)
1237 MarkerSelection::iterator i;
1239 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1247 Selection::remove (ArdourMarker* m)
1249 MarkerSelection::iterator i;
1251 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1258 Selection::add (ArdourMarker* m)
1260 clear_time (); //enforce region/object exclusivity
1261 clear_tracks(); //enforce object/track exclusivity
1263 if (find (markers.begin(), markers.end(), m) == markers.end()) {
1264 markers.push_back (m);
1270 Selection::add (const list<ArdourMarker*>& m)
1272 clear_time (); //enforce region/object exclusivity
1273 clear_tracks(); //enforce object/track exclusivity
1275 markers.insert (markers.end(), m.begin(), m.end());
1283 MarkerSelection::range (framepos_t& s, framepos_t& e)
1288 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1290 if ((*i)->position() < s) {
1291 s = (*i)->position();
1294 if ((*i)->position() > e) {
1295 e = (*i)->position();
1299 s = std::min (s, e);
1300 e = std::max (s, e);
1304 Selection::get_state () const
1306 /* XXX: not complete; just sufficient to get track selection state
1307 so that re-opening plugin windows for editor mixer strips works
1311 XMLNode* node = new XMLNode (X_("Selection"));
1313 for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1314 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1315 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1317 XMLNode* t = node->add_child (X_("RouteView"));
1318 t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1320 XMLNode* t = node->add_child (X_("AutomationView"));
1321 t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1322 t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1326 for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1327 XMLNode* r = node->add_child (X_("Region"));
1328 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1331 /* midi region views have thir own internal selection. */
1332 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1333 editor->get_per_region_note_selection (rid_notes);
1335 list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1336 for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1337 XMLNode* n = node->add_child (X_("MIDINotes"));
1338 n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
1340 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1341 XMLNode* nc = n->add_child(X_("note"));
1343 snprintf(buf, sizeof(buf), "%d", (*i)->id());
1344 nc->add_property (X_("note-id"), string(buf));
1348 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1349 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1352 XMLNode* r = node->add_child (X_("ControlPoint"));
1353 r->add_property (X_("type"), "track");
1354 r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1355 r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1356 r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1358 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1359 r->add_property (X_("view-index"), string(buf));
1363 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1365 XMLNode* r = node->add_child (X_("ControlPoint"));
1366 r->add_property (X_("type"), "region");
1367 r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1368 snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1369 r->add_property (X_("view-index"), string(buf));
1374 for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1375 XMLNode* t = node->add_child (X_("AudioRange"));
1376 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1377 t->add_property (X_("start"), string(buf));
1378 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1379 t->add_property (X_("end"), string(buf));
1382 for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1383 XMLNode* t = node->add_child (X_("Marker"));
1386 Location* loc = editor->find_location_from_marker (*i, is_start);
1388 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1389 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1396 Selection::set_state (XMLNode const & node, int)
1398 if (node.name() != X_("Selection")) {
1403 clear_midi_notes ();
1409 XMLNodeList children = node.children ();
1410 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1411 if ((*i)->name() == X_("RouteView")) {
1413 XMLProperty const * prop_id = (*i)->property (X_("id"));
1415 PBD::ID id (prop_id->value ());
1416 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1421 } else if ((*i)->name() == X_("Region")) {
1422 XMLProperty const * prop_id = (*i)->property (X_("id"));
1424 PBD::ID id (prop_id->value ());
1427 editor->get_regionviews_by_id (id, rs);
1433 regionviews haven't been constructed - stash the region IDs
1434 so we can identify them in Editor::region_view_added ()
1436 regions.pending.push_back (id);
1439 } else if ((*i)->name() == X_("MIDINotes")) {
1440 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1442 assert (prop_region_id);
1444 PBD::ID const id (prop_region_id->value ());
1447 editor->get_regionviews_by_id (id, rs); // there could be more than one
1449 std::list<Evoral::event_id_t> notes;
1450 XMLNodeList children = (*i)->children ();
1452 for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1453 XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
1455 Evoral::event_id_t id = atoi(prop_id->value());
1456 notes.push_back (id);
1460 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1461 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1463 mrv->select_notes(notes);
1468 /* regionviews containing these notes don't yet exist on the canvas.*/
1469 pending_midi_note_selection.push_back (make_pair (id, notes));
1472 } else if ((*i)->name() == X_("ControlPoint")) {
1473 XMLProperty const * prop_type = (*i)->property (X_("type"));
1477 if (prop_type->value () == "track") {
1479 XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
1480 XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
1481 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1482 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1484 assert (prop_route_id);
1485 assert (prop_alist_id);
1486 assert (prop_parameter);
1487 assert (prop_view_index);
1489 PBD::ID route_id (prop_route_id->value ());
1490 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1491 vector <ControlPoint *> cps;
1494 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1496 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1497 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1498 if ((*li)->the_list()->id() == prop_alist_id->value()) {
1499 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1511 } else if (prop_type->value () == "region") {
1512 XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
1513 XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
1515 if (!prop_region_id || !prop_view_index) {
1519 PBD::ID region_id (prop_region_id->value ());
1521 editor->get_regionviews_by_id (region_id, rs);
1524 vector <ControlPoint *> cps;
1525 for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1526 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1528 boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1529 ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1542 } else if ((*i)->name() == X_("AudioRange")) {
1543 XMLProperty const * prop_start = (*i)->property (X_("start"));
1544 XMLProperty const * prop_end = (*i)->property (X_("end"));
1546 assert (prop_start);
1549 framepos_t s (atol (prop_start->value ().c_str()));
1550 framepos_t e (atol (prop_end->value ().c_str()));
1552 set_preserving_all_ranges (s, e);
1554 } else if ((*i)->name() == X_("AutomationView")) {
1556 XMLProperty const * prop_id = (*i)->property (X_("id"));
1557 XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
1560 assert (prop_parameter);
1562 PBD::ID id (prop_id->value ());
1563 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1566 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1568 /* the automation could be for an entity that was never saved
1569 in the session file. Don't freak out if we can't find
1578 } else if ((*i)->name() == X_("Marker")) {
1580 XMLProperty const * prop_id = (*i)->property (X_("id"));
1581 XMLProperty const * prop_start = (*i)->property (X_("start"));
1583 assert (prop_start);
1585 PBD::ID id (prop_id->value ());
1586 ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1599 Selection::remove_regions (TimeAxisView* t)
1601 RegionSelection::iterator i = regions.begin();
1602 while (i != regions.end ()) {
1603 RegionSelection::iterator tmp = i;
1606 if (&(*i)->get_time_axis_view() == t) {