Change handling of Midi note selection to eliminate signal emission/delays.
[ardour.git] / gtk2_ardour / selection.cc
1 /*
2     Copyright (C) 2002 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <algorithm>
21 #include <sigc++/bind.h>
22
23 #include "pbd/error.h"
24 #include "pbd/stacktrace.h"
25
26 #include "ardour/playlist.h"
27 #include "ardour/rc_configuration.h"
28
29 #include "audio_region_view.h"
30 #include "debug.h"
31 #include "gui_thread.h"
32 #include "midi_cut_buffer.h"
33 #include "region_gain_line.h"
34 #include "region_view.h"
35 #include "selection.h"
36 #include "selection_templates.h"
37 #include "time_axis_view.h"
38 #include "automation_time_axis.h"
39 #include "public_editor.h"
40 #include "control_point.h"
41
42 #include "i18n.h"
43
44 using namespace std;
45 using namespace ARDOUR;
46 using namespace PBD;
47
48 struct AudioRangeComparator {
49         bool operator()(AudioRange a, AudioRange b) {
50                 return a.start < b.start;
51         }
52 };
53
54 Selection::Selection (const PublicEditor* e)
55         : tracks (e)
56         , editor (e)
57         , next_time_id (0)
58         , _no_tracks_changed (false)
59 {
60         clear ();
61
62         /* we have disambiguate which remove() for the compiler */
63
64         void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
65         TimeAxisView::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (track_remove, this, _1), gui_context());
66
67         void (Selection::*marker_remove)(ArdourMarker*) = &Selection::remove;
68         ArdourMarker::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (marker_remove, this, _1), gui_context());
69
70         void (Selection::*point_remove)(ControlPoint*) = &Selection::remove;
71         ControlPoint::CatchDeletion.connect (*this, MISSING_INVALIDATOR, boost::bind (point_remove, this, _1), gui_context());
72 }
73
74 #if 0
75 Selection&
76 Selection::operator= (const Selection& other)
77 {
78         if (&other != this) {
79                 regions = other.regions;
80                 tracks = other.tracks;
81                 time = other.time;
82                 lines = other.lines;
83                 midi_regions = other.midi_regions;
84                 midi_notes = other.midi_notes;
85         }
86         return *this;
87 }
88 #endif
89
90 bool
91 operator== (const Selection& a, const Selection& b)
92 {
93         return a.regions == b.regions &&
94                 a.tracks == b.tracks &&
95                 a.time == b.time &&
96                 a.lines == b.lines &&
97                 a.playlists == b.playlists &&
98                 a.midi_notes == b.midi_notes &&
99                 a.midi_regions == b.midi_regions;
100 }
101
102 /** Clear everything from the Selection */
103 void
104 Selection::clear ()
105 {
106         clear_tracks ();
107         clear_regions ();
108         clear_points ();
109         clear_lines();
110         clear_time ();
111         clear_playlists ();
112         clear_midi_notes ();
113         clear_midi_regions ();
114         clear_markers ();
115         pending_midi_note_selection.clear();
116 }
117
118 void
119 Selection::clear_objects ()
120 {
121         clear_regions ();
122         clear_points ();
123         clear_lines();
124         clear_playlists ();
125         clear_midi_notes ();
126         clear_midi_regions ();
127 }
128
129 void
130 Selection::clear_tracks ()
131 {
132         if (!tracks.empty()) {
133                 for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
134                         (*x)->set_selected (false);
135                 }
136                 tracks.clear ();
137                 if (!_no_tracks_changed) {
138                         TracksChanged();
139                 }
140         }
141 }
142
143 void
144 Selection::clear_time ()
145 {
146         time.clear();
147
148         TimeChanged ();
149 }
150
151 void
152 Selection::dump_region_layers()
153 {
154         cerr << "region selection layer dump" << endl;
155         for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
156                 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
157         }
158 }
159
160
161 void
162 Selection::clear_regions ()
163 {
164         if (!regions.empty()) {
165                 regions.clear_all ();
166                 RegionsChanged();
167         }
168 }
169
170 void
171 Selection::clear_midi_notes ()
172 {
173         if (!midi_notes.empty()) {
174                 for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
175                         delete *x;
176                 }
177                 midi_notes.clear ();
178                 MidiNotesChanged ();
179         }
180
181         // clear note selections for MRV's that have note selections
182         // this will cause the MRV to be removed from the list
183         for (MidiRegionSelection::iterator i = midi_regions.begin();
184              i != midi_regions.end();) {
185                 MidiRegionSelection::iterator tmp = i;
186                 ++tmp;
187                 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
188                 if (mrv) {
189                         mrv->clear_selection();
190                 }
191                 i = tmp;
192         }
193 }
194
195 void
196 Selection::clear_midi_regions ()
197 {
198         if (!midi_regions.empty()) {
199                 midi_regions.clear ();
200                 MidiRegionsChanged ();
201         }
202 }
203
204 void
205 Selection::clear_playlists ()
206 {
207         /* Selections own their playlists */
208
209         for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
210                 /* selections own their own regions, which are copies of the "originals". make them go away */
211                 (*i)->drop_regions ();
212                 (*i)->release ();
213         }
214
215         if (!playlists.empty()) {
216                 playlists.clear ();
217                 PlaylistsChanged();
218         }
219 }
220
221 void
222 Selection::clear_lines ()
223 {
224         if (!lines.empty()) {
225                 lines.clear ();
226                 LinesChanged();
227         }
228 }
229
230 void
231 Selection::clear_markers ()
232 {
233         if (!markers.empty()) {
234                 markers.clear ();
235                 MarkersChanged();
236         }
237 }
238
239 void
240 Selection::toggle (boost::shared_ptr<Playlist> pl)
241 {
242         clear_time();  //enforce object/range exclusivity
243         clear_tracks();  //enforce object/track exclusivity
244
245         PlaylistSelection::iterator i;
246
247         if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
248                 pl->use ();
249                 playlists.push_back(pl);
250         } else {
251                 playlists.erase (i);
252         }
253
254         PlaylistsChanged ();
255 }
256
257 void
258 Selection::toggle (const TrackViewList& track_list)
259 {
260         for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
261                 toggle ((*i));
262         }
263 }
264
265 void
266 Selection::toggle (TimeAxisView* track)
267 {
268         TrackSelection::iterator i;
269
270         if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
271                 track->set_selected (true);
272                 tracks.push_back (track);
273         } else {
274                 track->set_selected (false);
275                 tracks.erase (i);
276         }
277
278         if (!_no_tracks_changed) {
279                 TracksChanged();
280         }
281 }
282
283 void
284 Selection::toggle (const MidiNoteSelection& midi_note_list)
285 {
286         clear_time();  //enforce object/range exclusivity
287         clear_tracks();  //enforce object/track exclusivity
288
289         for (MidiNoteSelection::const_iterator i = midi_note_list.begin(); i != midi_note_list.end(); ++i) {
290                 toggle ((*i));
291         }
292 }
293
294 void
295 Selection::toggle (MidiCutBuffer* midi)
296 {
297         MidiNoteSelection::iterator i;
298
299         if ((i = find (midi_notes.begin(), midi_notes.end(), midi)) == midi_notes.end()) {
300                 midi_notes.push_back (midi);
301         } else {
302                 /* remember that we own the MCB */
303                 delete *i;
304                 midi_notes.erase (i);
305         }
306
307         MidiNotesChanged();
308 }
309
310
311 void
312 Selection::toggle (RegionView* r)
313 {
314         clear_time();  //enforce object/range exclusivity
315         clear_tracks();  //enforce object/track exclusivity
316
317         RegionSelection::iterator i;
318
319         if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
320                 add (r);
321         } else {
322                 remove (*i);
323         }
324
325         RegionsChanged ();
326 }
327
328 void
329 Selection::toggle (MidiRegionView* mrv)
330 {
331         clear_time();   //enforce object/range exclusivity
332         clear_tracks();  //enforce object/track exclusivity
333
334         MidiRegionSelection::iterator i;
335
336         if ((i = find (midi_regions.begin(), midi_regions.end(), mrv)) == midi_regions.end()) {
337                 add (mrv);
338         } else {
339                 midi_regions.erase (i);
340         }
341
342         MidiRegionsChanged ();
343 }
344
345 void
346 Selection::toggle (vector<RegionView*>& r)
347 {
348         clear_time();  //enforce object/range exclusivity
349         clear_tracks();  //enforce object/track exclusivity
350
351         RegionSelection::iterator i;
352
353         for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
354                 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
355                         add ((*x));
356                 } else {
357                         remove (*x);
358                 }
359         }
360
361         RegionsChanged ();
362 }
363
364 long
365 Selection::toggle (framepos_t start, framepos_t end)
366 {
367         clear_objects();  //enforce object/range exclusivity
368
369         AudioRangeComparator cmp;
370
371         /* XXX this implementation is incorrect */
372
373         time.push_back (AudioRange (start, end, ++next_time_id));
374         time.consolidate ();
375         time.sort (cmp);
376
377         TimeChanged ();
378
379         return next_time_id;
380 }
381
382 void
383 Selection::add (boost::shared_ptr<Playlist> pl)
384 {
385         clear_time();  //enforce object/range exclusivity
386         clear_tracks();  //enforce object/track exclusivity
387
388         if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
389                 pl->use ();
390                 playlists.push_back(pl);
391                 PlaylistsChanged ();
392         }
393 }
394
395 void
396 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
397 {
398         clear_time();  //enforce object/range exclusivity
399         clear_tracks();  //enforce object/track exclusivity
400
401         bool changed = false;
402
403         for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
404                 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
405                         (*i)->use ();
406                         playlists.push_back (*i);
407                         changed = true;
408                 }
409         }
410
411         if (changed) {
412                 PlaylistsChanged ();
413         }
414 }
415
416 void
417 Selection::add (const TrackViewList& track_list)
418 {
419         clear_objects();  //enforce object/range exclusivity
420
421         TrackViewList added = tracks.add (track_list);
422
423         if (!added.empty()) {
424                 for (TrackViewList::iterator x = added.begin(); x != added.end(); ++x) {
425                         (*x)->set_selected (true);
426                 }
427                 if (!_no_tracks_changed) {
428                         TracksChanged ();
429                 }
430         }
431 }
432
433 void
434 Selection::add (TimeAxisView* track)
435 {
436         clear_objects();  //enforce object/range exclusivity
437
438         TrackViewList tr;
439         track->set_selected (true);
440         tr.push_back (track);
441         add (tr);
442 }
443
444 void
445 Selection::add (const MidiNoteSelection& midi_list)
446 {
447         clear_time();  //enforce object/range exclusivity
448         clear_tracks();  //enforce object/track exclusivity
449
450         const MidiNoteSelection::const_iterator b = midi_list.begin();
451         const MidiNoteSelection::const_iterator e = midi_list.end();
452
453         if (!midi_list.empty()) {
454                 midi_notes.insert (midi_notes.end(), b, e);
455                 MidiNotesChanged ();
456         }
457 }
458
459 void
460 Selection::add (MidiCutBuffer* midi)
461 {
462         /* we take ownership of the MCB */
463
464         if (find (midi_notes.begin(), midi_notes.end(), midi) == midi_notes.end()) {
465                 midi_notes.push_back (midi);
466                 MidiNotesChanged ();
467         }
468 }
469
470 void
471 Selection::add (vector<RegionView*>& v)
472 {
473         clear_time();  //enforce object/range exclusivity
474         clear_tracks();  //enforce object/track exclusivity
475
476         /* XXX This method or the add (const RegionSelection&) needs to go
477          */
478
479         bool changed = false;
480
481         for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
482                 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
483                         changed = regions.add ((*i));
484                 }
485         }
486
487         if (changed) {
488                 RegionsChanged ();
489         }
490 }
491
492 void
493 Selection::add (const RegionSelection& rs)
494 {
495         clear_time();  //enforce object/range exclusivity
496         clear_tracks();  //enforce object/track exclusivity
497
498         /* XXX This method or the add (const vector<RegionView*>&) needs to go
499          */
500
501         bool changed = false;
502
503         for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
504                 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
505                         changed = regions.add ((*i));
506                 }
507         }
508
509         if (changed) {
510                 RegionsChanged ();
511         }
512 }
513
514 void
515 Selection::add (RegionView* r)
516 {
517         clear_time();  //enforce object/range exclusivity
518         clear_tracks();  //enforce object/track exclusivity
519
520         if (find (regions.begin(), regions.end(), r) == regions.end()) {
521                 bool changed = regions.add (r);
522                 if (changed) {
523                         RegionsChanged ();
524                 }
525         }
526 }
527
528 void
529 Selection::add (MidiRegionView* mrv)
530 {
531         DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::add MRV %1\n", mrv));
532
533         clear_time();  //enforce object/range exclusivity
534         clear_tracks();  //enforce object/track exclusivity
535
536         if (find (midi_regions.begin(), midi_regions.end(), mrv) == midi_regions.end()) {
537                 midi_regions.push_back (mrv);
538                 /* XXX should we do this? */
539                 MidiRegionsChanged ();
540         }
541 }
542
543 long
544 Selection::add (framepos_t start, framepos_t end)
545 {
546         clear_objects();  //enforce object/range exclusivity
547
548         AudioRangeComparator cmp;
549
550         /* XXX this implementation is incorrect */
551
552         time.push_back (AudioRange (start, end, ++next_time_id));
553         time.consolidate ();
554         time.sort (cmp);
555
556         TimeChanged ();
557
558         return next_time_id;
559 }
560
561 void
562 Selection::move_time (framecnt_t distance)
563 {
564         if (distance == 0) {
565                 return;
566         }
567
568         for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
569                 (*i).start += distance;
570                 (*i).end += distance;
571         }
572
573         TimeChanged ();
574 }
575
576 void
577 Selection::replace (uint32_t sid, framepos_t start, framepos_t end)
578 {
579         clear_objects();  //enforce object/range exclusivity
580
581         for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
582                 if ((*i).id == sid) {
583                         time.erase (i);
584                         time.push_back (AudioRange(start,end, sid));
585
586                         /* don't consolidate here */
587
588
589                         AudioRangeComparator cmp;
590                         time.sort (cmp);
591
592                         TimeChanged ();
593                         break;
594                 }
595         }
596 }
597
598 void
599 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
600 {
601         clear_time();  //enforce object/range exclusivity
602         clear_tracks();  //enforce object/track exclusivity
603
604         boost::shared_ptr<ARDOUR::AutomationList> al
605                 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
606         if (!al) {
607                 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
608                 return;
609         }
610         if (find (lines.begin(), lines.end(), al) == lines.end()) {
611                 lines.push_back (al);
612                 LinesChanged();
613         }
614 }
615
616 void
617 Selection::remove (TimeAxisView* track)
618 {
619         list<TimeAxisView*>::iterator i;
620         if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
621                 track->set_selected (false);
622                 tracks.erase (i);
623                 if (!_no_tracks_changed) {
624                         TracksChanged();
625                 }
626         }
627 }
628
629 void
630 Selection::remove (const TrackViewList& track_list)
631 {
632         bool changed = false;
633
634         for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
635
636                 TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
637                 if (x != tracks.end()) {
638                         (*i)->set_selected (false);
639                         tracks.erase (x);
640                         changed = true;
641                 }
642         }
643
644         if (changed) {
645                 if (!_no_tracks_changed) {
646                         TracksChanged();
647                 }
648         }
649 }
650
651 void
652 Selection::remove (ControlPoint* p)
653 {
654         PointSelection::iterator i = find (points.begin(), points.end(), p);
655         if (i != points.end ()) {
656                 points.erase (i);
657         }
658 }
659
660 void
661 Selection::remove (const MidiNoteSelection& midi_list)
662 {
663         bool changed = false;
664
665         for (MidiNoteSelection::const_iterator i = midi_list.begin(); i != midi_list.end(); ++i) {
666
667                 MidiNoteSelection::iterator x;
668
669                 if ((x = find (midi_notes.begin(), midi_notes.end(), (*i))) != midi_notes.end()) {
670                         midi_notes.erase (x);
671                         changed = true;
672                 }
673         }
674
675         if (changed) {
676                 MidiNotesChanged();
677         }
678 }
679
680 void
681 Selection::remove (MidiCutBuffer* midi)
682 {
683         MidiNoteSelection::iterator x;
684
685         if ((x = find (midi_notes.begin(), midi_notes.end(), midi)) != midi_notes.end()) {
686                 /* remember that we own the MCB */
687                 delete *x;
688                 midi_notes.erase (x);
689                 MidiNotesChanged ();
690         }
691 }
692
693 void
694 Selection::remove (boost::shared_ptr<Playlist> track)
695 {
696         list<boost::shared_ptr<Playlist> >::iterator i;
697         if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
698                 playlists.erase (i);
699                 PlaylistsChanged();
700         }
701 }
702
703 void
704 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
705 {
706         bool changed = false;
707
708         for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
709
710                 list<boost::shared_ptr<Playlist> >::iterator x;
711
712                 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
713                         playlists.erase (x);
714                         changed = true;
715                 }
716         }
717
718         if (changed) {
719                 PlaylistsChanged();
720         }
721 }
722
723 void
724 Selection::remove (RegionView* r)
725 {
726         if (regions.remove (r)) {
727                 RegionsChanged ();
728         }
729 }
730
731 void
732 Selection::remove (MidiRegionView* mrv)
733 {
734         DEBUG_TRACE(DEBUG::Selection, string_compose("Selection::remove MRV %1\n", mrv));
735
736         MidiRegionSelection::iterator x;
737
738         if ((x = find (midi_regions.begin(), midi_regions.end(), mrv)) != midi_regions.end()) {
739                 midi_regions.erase (x);
740                 MidiRegionsChanged ();
741         }
742 }
743
744 void
745 Selection::remove (uint32_t selection_id)
746 {
747         if (time.empty()) {
748                 return;
749         }
750
751         for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
752                 if ((*i).id == selection_id) {
753                         time.erase (i);
754
755                         TimeChanged ();
756                         break;
757                 }
758         }
759 }
760
761 void
762 Selection::remove (framepos_t /*start*/, framepos_t /*end*/)
763 {
764 }
765
766 void
767 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
768 {
769         AutomationSelection::iterator i;
770         if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
771                 lines.erase (i);
772                 LinesChanged();
773         }
774 }
775
776 void
777 Selection::set (TimeAxisView* track)
778 {
779         clear_objects();  //enforce object/range exclusivity
780         clear_tracks ();
781         add (track);
782 }
783
784 void
785 Selection::set (const TrackViewList& track_list)
786 {
787         clear_objects();  //enforce object/range exclusivity
788         clear_tracks ();
789         add (track_list);
790 }
791
792 void
793 Selection::set (const MidiNoteSelection& midi_list)
794 {
795         clear_time ();  //enforce region/object exclusivity
796         clear_tracks();  //enforce object/track exclusivity
797         clear_objects ();
798         add (midi_list);
799 }
800
801 void
802 Selection::set (boost::shared_ptr<Playlist> playlist)
803 {
804         clear_time ();  //enforce region/object exclusivity
805         clear_tracks();  //enforce object/track exclusivity
806         clear_objects ();
807         add (playlist);
808 }
809
810 void
811 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
812 {
813         clear_time();  //enforce region/object exclusivity
814         clear_objects ();
815         add (pllist);
816 }
817
818 void
819 Selection::set (const RegionSelection& rs)
820 {
821         clear_time();  //enforce region/object exclusivity
822         clear_tracks();  //enforce object/track exclusivity
823         clear_objects();
824         regions = rs;
825         RegionsChanged(); /* EMIT SIGNAL */
826 }
827
828 void
829 Selection::set (MidiRegionView* mrv)
830 {
831         clear_time();  //enforce region/object exclusivity
832         clear_tracks();  //enforce object/track exclusivity
833         clear_objects ();
834         add (mrv);
835 }
836
837 void
838 Selection::set (RegionView* r, bool /*also_clear_tracks*/)
839 {
840         clear_time();  //enforce region/object exclusivity
841         clear_tracks();  //enforce object/track exclusivity
842         clear_objects ();
843         add (r);
844 }
845
846 void
847 Selection::set (vector<RegionView*>& v)
848 {
849         clear_time();  //enforce region/object exclusivity
850         clear_tracks();  //enforce object/track exclusivity
851         clear_objects();
852
853         add (v);
854 }
855
856 /** Set the start and end time of the time selection, without changing
857  *  the list of tracks it applies to.
858  */
859 long
860 Selection::set (framepos_t start, framepos_t end)
861 {
862         clear_objects();  //enforce region/object exclusivity
863         clear_time();
864
865         if ((start == 0 && end == 0) || end < start) {
866                 return 0;
867         }
868
869         if (time.empty()) {
870                 time.push_back (AudioRange (start, end, ++next_time_id));
871         } else {
872                 /* reuse the first entry, and remove all the rest */
873
874                 while (time.size() > 1) {
875                         time.pop_front();
876                 }
877                 time.front().start = start;
878                 time.front().end = end;
879         }
880
881         time.consolidate ();
882
883         TimeChanged ();
884
885         return time.front().id;
886 }
887
888 /** Set the start and end of the range selection.  If more than one range
889  *  is currently selected, the start of the earliest range and the end of the
890  *  latest range are set.  If no range is currently selected, this method
891  *  selects a single range from start to end.
892  *
893  *  @param start New start time.
894  *  @param end New end time.
895  */
896 void
897 Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
898 {
899         clear_objects();  //enforce region/object exclusivity
900
901         if ((start == 0 && end == 0) || (end < start)) {
902                 return;
903         }
904
905         if (time.empty ()) {
906                 time.push_back (AudioRange (start, end, ++next_time_id));
907         } else {
908                 time.sort (AudioRangeComparator ());
909                 time.front().start = start;
910                 time.back().end = end;
911         }
912
913         time.consolidate ();
914
915         TimeChanged ();
916 }
917
918 void
919 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
920 {
921         clear_time();  //enforce region/object exclusivity
922         clear_tracks();  //enforce object/track exclusivity
923         clear_objects();
924
925         add (ac);
926 }
927
928 bool
929 Selection::selected (ArdourMarker* m)
930 {
931         return find (markers.begin(), markers.end(), m) != markers.end();
932 }
933
934 bool
935 Selection::selected (TimeAxisView* tv)
936 {
937         return tv->get_selected ();
938 }
939
940 bool
941 Selection::selected (RegionView* rv)
942 {
943         return find (regions.begin(), regions.end(), rv) != regions.end();
944 }
945
946 bool
947 Selection::selected (ControlPoint* cp)
948 {
949         return find (points.begin(), points.end(), cp) != points.end();
950 }
951
952 bool
953 Selection::empty (bool internal_selection)
954 {
955         bool object_level_empty =  regions.empty () &&
956                 tracks.empty () &&
957                 points.empty () &&
958                 playlists.empty () &&
959                 lines.empty () &&
960                 time.empty () &&
961                 playlists.empty () &&
962                 markers.empty() &&
963                 midi_regions.empty()
964                 ;
965
966         if (!internal_selection) {
967                 return object_level_empty;
968         }
969
970         /* this is intended to really only apply when using a Selection
971            as a cut buffer.
972         */
973
974         return object_level_empty && midi_notes.empty() && points.empty();
975 }
976
977 void
978 Selection::toggle (ControlPoint* cp)
979 {
980         clear_time();  //enforce region/object exclusivity
981         clear_tracks();  //enforce object/track exclusivity
982
983         cp->set_selected (!cp->get_selected ());
984         PointSelection::iterator i = find (points.begin(), points.end(), cp);
985         if (i == points.end()) {
986                 points.push_back (cp);
987         } else {
988                 points.erase (i);
989         }
990
991         PointsChanged (); /* EMIT SIGNAL */
992 }
993
994 void
995 Selection::toggle (vector<ControlPoint*> const & cps)
996 {
997         clear_time();  //enforce region/object exclusivity
998         clear_tracks();  //enforce object/track exclusivity
999
1000         for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1001                 toggle (*i);
1002         }
1003 }
1004
1005 void
1006 Selection::toggle (list<Selectable*> const & selectables)
1007 {
1008         clear_time();  //enforce region/object exclusivity
1009         clear_tracks();  //enforce object/track exclusivity
1010
1011         RegionView* rv;
1012         ControlPoint* cp;
1013         vector<RegionView*> rvs;
1014         vector<ControlPoint*> cps;
1015
1016         for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1017                 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1018                         rvs.push_back (rv);
1019                 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1020                         cps.push_back (cp);
1021                 } else {
1022                         fatal << _("programming error: ")
1023                               << X_("unknown selectable type passed to Selection::toggle()")
1024                               << endmsg;
1025                         abort(); /*NOTREACHED*/
1026                 }
1027         }
1028
1029         if (!rvs.empty()) {
1030                 toggle (rvs);
1031         }
1032
1033         if (!cps.empty()) {
1034                 toggle (cps);
1035         }
1036 }
1037
1038 void
1039 Selection::set (list<Selectable*> const & selectables)
1040 {
1041         clear_time ();  //enforce region/object exclusivity
1042         clear_tracks();  //enforce object/track exclusivity
1043         clear_objects ();
1044
1045         add (selectables);
1046 }
1047
1048 void
1049 Selection::add (PointSelection const & s)
1050 {
1051         clear_time ();  //enforce region/object exclusivity
1052         clear_tracks();  //enforce object/track exclusivity
1053
1054         for (PointSelection::const_iterator i = s.begin(); i != s.end(); ++i) {
1055                 points.push_back (*i);
1056         }
1057 }
1058
1059 void
1060 Selection::add (list<Selectable*> const & selectables)
1061 {
1062         clear_time ();  //enforce region/object exclusivity
1063         clear_tracks();  //enforce object/track exclusivity
1064
1065         RegionView* rv;
1066         ControlPoint* cp;
1067         vector<RegionView*> rvs;
1068         vector<ControlPoint*> cps;
1069
1070         for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
1071                 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
1072                         rvs.push_back (rv);
1073                 } else if ((cp = dynamic_cast<ControlPoint*> (*i)) != 0) {
1074                         cps.push_back (cp);
1075                 } else {
1076                         fatal << _("programming error: ")
1077                               << X_("unknown selectable type passed to Selection::add()")
1078                               << endmsg;
1079                         abort(); /*NOTREACHED*/
1080                 }
1081         }
1082
1083         if (!rvs.empty()) {
1084                 add (rvs);
1085         }
1086
1087         if (!cps.empty()) {
1088                 add (cps);
1089         }
1090 }
1091
1092 void
1093 Selection::clear_points ()
1094 {
1095         if (!points.empty()) {
1096                 points.clear ();
1097                 PointsChanged ();
1098         }
1099 }
1100
1101 void
1102 Selection::add (ControlPoint* cp)
1103 {
1104         clear_time ();  //enforce region/object exclusivity
1105         clear_tracks();  //enforce object/track exclusivity
1106
1107         cp->set_selected (true);
1108         points.push_back (cp);
1109         PointsChanged (); /* EMIT SIGNAL */
1110 }
1111
1112 void
1113 Selection::add (vector<ControlPoint*> const & cps)
1114 {
1115         clear_time ();  //enforce region/object exclusivity
1116         clear_tracks();  //enforce object/track exclusivity
1117
1118         for (vector<ControlPoint*>::const_iterator i = cps.begin(); i != cps.end(); ++i) {
1119                 (*i)->set_selected (true);
1120                 points.push_back (*i);
1121         }
1122         PointsChanged (); /* EMIT SIGNAL */
1123 }
1124
1125 void
1126 Selection::set (ControlPoint* cp)
1127 {
1128         clear_time ();  //enforce region/object exclusivity
1129         clear_tracks();  //enforce object/track exclusivity
1130
1131         if (cp->get_selected () && points.size () == 1) {
1132                 return;
1133         }
1134
1135         for (uint32_t i = 0; i < cp->line().npoints(); ++i) {
1136                 cp->line().nth (i)->set_selected (false);
1137         }
1138
1139         clear_objects ();
1140         add (cp);
1141 }
1142
1143 void
1144 Selection::set (ArdourMarker* m)
1145 {
1146         clear_time ();  //enforce region/object exclusivity
1147         clear_tracks();  //enforce object/track exclusivity
1148         markers.clear ();
1149
1150         add (m);
1151 }
1152
1153 void
1154 Selection::toggle (ArdourMarker* m)
1155 {
1156         MarkerSelection::iterator i;
1157
1158         if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
1159                 add (m);
1160         } else {
1161                 remove (m);
1162         }
1163 }
1164
1165 void
1166 Selection::remove (ArdourMarker* m)
1167 {
1168         MarkerSelection::iterator i;
1169
1170         if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
1171                 markers.erase (i);
1172                 MarkersChanged();
1173         }
1174 }
1175
1176 void
1177 Selection::add (ArdourMarker* m)
1178 {
1179         clear_time ();  //enforce region/object exclusivity
1180         clear_tracks();  //enforce object/track exclusivity
1181
1182         if (find (markers.begin(), markers.end(), m) == markers.end()) {
1183                 markers.push_back (m);
1184                 MarkersChanged();
1185         }
1186 }
1187
1188 void
1189 Selection::add (const list<ArdourMarker*>& m)
1190 {
1191         clear_time ();  //enforce region/object exclusivity
1192         clear_tracks();  //enforce object/track exclusivity
1193
1194         markers.insert (markers.end(), m.begin(), m.end());
1195         markers.sort ();
1196         markers.unique ();
1197
1198         MarkersChanged ();
1199 }
1200
1201 void
1202 MarkerSelection::range (framepos_t& s, framepos_t& e)
1203 {
1204         s = max_framepos;
1205         e = 0;
1206
1207         for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
1208
1209                 if ((*i)->position() < s) {
1210                         s = (*i)->position();
1211                 }
1212
1213                 if ((*i)->position() > e) {
1214                         e = (*i)->position();
1215                 }
1216         }
1217
1218         s = std::min (s, e);
1219         e = std::max (s, e);
1220 }
1221
1222 XMLNode&
1223 Selection::get_state () const
1224 {
1225         /* XXX: not complete; just sufficient to get track selection state
1226            so that re-opening plugin windows for editor mixer strips works
1227         */
1228
1229         char buf[32];
1230         XMLNode* node = new XMLNode (X_("Selection"));
1231
1232         for (TrackSelection::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
1233                 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
1234                 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (*i);
1235                 if (rtv) {
1236                         XMLNode* t = node->add_child (X_("RouteView"));
1237                         t->add_property (X_("id"), atoi (rtv->route()->id().to_s().c_str()));
1238                 } else if (atv) {
1239                         XMLNode* t = node->add_child (X_("AutomationView"));
1240                         t->add_property (X_("id"), atoi (atv->parent_route()->id().to_s().c_str()));
1241                         t->add_property (X_("parameter"), EventTypeMap::instance().to_symbol (atv->parameter ()));
1242                 }
1243         }
1244
1245         for (RegionSelection::const_iterator i = regions.begin(); i != regions.end(); ++i) {
1246                 XMLNode* r = node->add_child (X_("Region"));
1247                 r->add_property (X_("id"), atoi ((*i)->region ()->id ().to_s ().c_str()));
1248         }
1249
1250         /* midi region views have thir own internal selection. */
1251         XMLNode* n = NULL;
1252         list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
1253         editor->get_per_region_note_selection (rid_notes);
1254         if (!rid_notes.empty()) {
1255                 n = node->add_child (X_("MIDINote"));
1256         }
1257         list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
1258         for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
1259                 assert(n); // hint for clang static analysis
1260                 n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
1261
1262                 for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
1263                         XMLNode* nc = n->add_child(X_("note"));
1264                         snprintf(buf, sizeof(buf), "%d", (*i)->channel());
1265                         nc->add_property(X_("channel"), string(buf));
1266
1267                         snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
1268                         nc->add_property(X_("time"), string(buf));
1269
1270                         snprintf(buf, sizeof(buf), "%d", (*i)->note());
1271                         nc->add_property(X_("note"), string(buf));
1272
1273                         snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
1274                         nc->add_property(X_("length"), string(buf));
1275
1276                         snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
1277                         nc->add_property(X_("velocity"), string(buf));
1278
1279                         snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
1280                         nc->add_property(X_("off-velocity"), string(buf));
1281                 }
1282         }
1283
1284         for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
1285                 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (&(*i)->line().trackview);
1286                 if (atv) {
1287
1288                         XMLNode* r = node->add_child (X_("ControlPoint"));
1289                         r->add_property (X_("type"), "track");
1290                         r->add_property (X_("route-id"), atoi (atv->parent_route()->id ().to_s ().c_str()));
1291                         r->add_property (X_("automation-list-id"), atoi ((*i)->line().the_list()->id ().to_s ().c_str()));
1292                         r->add_property (X_("parameter"), EventTypeMap::instance().to_symbol ((*i)->line().the_list()->parameter ()));
1293
1294                         snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1295                         r->add_property (X_("view-index"), string(buf));
1296                         continue;
1297                 }
1298
1299                 AudioRegionGainLine* argl = dynamic_cast<AudioRegionGainLine*> (&(*i)->line());
1300                 if (argl) {
1301                         XMLNode* r = node->add_child (X_("ControlPoint"));
1302                         r->add_property (X_("type"), "region");
1303                         r->add_property (X_("region-id"), atoi (argl->region_view ().region ()->id ().to_s ().c_str()));
1304                         snprintf(buf, sizeof(buf), "%d", (*i)->view_index());
1305                         r->add_property (X_("view-index"), string(buf));
1306                 }
1307
1308         }
1309
1310         for (TimeSelection::const_iterator i = time.begin(); i != time.end(); ++i) {
1311                 XMLNode* t = node->add_child (X_("AudioRange"));
1312                 snprintf(buf, sizeof(buf), "%" PRId64, (*i).start);
1313                 t->add_property (X_("start"), string(buf));
1314                 snprintf(buf, sizeof(buf), "%" PRId64, (*i).end);
1315                 t->add_property (X_("end"), string(buf));
1316         }
1317
1318         for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
1319                 XMLNode* t = node->add_child (X_("Marker"));
1320
1321                 bool is_start;
1322                 Location* loc = editor->find_location_from_marker (*i, is_start);
1323
1324                 t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
1325                 t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
1326         }
1327
1328         return *node;
1329 }
1330
1331 int
1332 Selection::set_state (XMLNode const & node, int)
1333 {
1334         if (node.name() != X_("Selection")) {
1335                 return -1;
1336         }
1337
1338         clear_regions ();
1339         clear_midi_notes ();
1340         clear_points ();
1341         clear_time ();
1342         clear_tracks ();
1343         clear_markers ();
1344
1345         XMLNodeList children = node.children ();
1346         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
1347                 if ((*i)->name() == X_("RouteView")) {
1348
1349                         XMLProperty* prop_id = (*i)->property (X_("id"));
1350                         assert (prop_id);
1351                         PBD::ID id (prop_id->value ());
1352                         RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1353                         if (rtv) {
1354                                 add (rtv);
1355                         }
1356
1357                 } else if ((*i)->name() == X_("Region")) {
1358                         XMLProperty* prop_id = (*i)->property (X_("id"));
1359                         assert (prop_id);
1360                         PBD::ID id (prop_id->value ());
1361
1362                         RegionSelection rs;
1363                         editor->get_regionviews_by_id (id, rs);
1364
1365                         if (!rs.empty ()) {
1366                                 add (rs);
1367                         } else {
1368                                 /*
1369                                   regionviews haven't been constructed - stash the region IDs
1370                                   so we can identify them in Editor::region_view_added ()
1371                                 */
1372                                 regions.pending.push_back (id);
1373                         }
1374
1375                 } else if ((*i)->name() == X_("MIDINote")) {
1376                         XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1377
1378                         assert (prop_region_id);
1379
1380                         PBD::ID const id (prop_region_id->value ());
1381                         RegionSelection rs;
1382
1383                         editor->get_regionviews_by_id (id, rs); // there could be more than one
1384
1385                         std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
1386                         XMLNodeList children = (*i)->children ();
1387
1388                         for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
1389                                 XMLProperty* prop_channel = (*ci)->property (X_("channel"));
1390                                 XMLProperty* prop_time = (*ci)->property (X_("time"));
1391                                 XMLProperty* prop_note = (*ci)->property (X_("note"));
1392                                 XMLProperty* prop_length = (*ci)->property (X_("length"));
1393                                 XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
1394                                 XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
1395
1396                                 assert (prop_channel);
1397                                 assert (prop_time);
1398                                 assert (prop_note);
1399                                 assert (prop_length);
1400                                 assert (prop_velocity);
1401                                 assert (prop_off_velocity);
1402
1403                                 uint8_t channel = atoi(prop_channel->value());
1404                                 Evoral::Beats time (atof(prop_time->value()));
1405                                 Evoral::Beats length (atof(prop_length->value()));
1406                                 uint8_t note = atoi(prop_note->value());
1407                                 uint8_t velocity = atoi(prop_velocity->value());
1408                                 uint8_t off_velocity = atoi(prop_off_velocity->value());
1409                                 boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
1410                                         (new Evoral::Note<Evoral::Beats>  (channel, time, length, note, velocity));
1411                                 the_note->set_off_velocity (off_velocity);
1412
1413                                 notes.push_back (the_note);
1414                         }
1415
1416                         for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1417                                 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*rsi);
1418                                 if (mrv) {
1419                                         mrv->select_notes(notes);
1420                                 }
1421                         }
1422
1423                         if (rs.empty()) {
1424                                 /* regionviews containing these notes don't yet exist on the canvas.*/
1425                                 pending_midi_note_selection.push_back (make_pair (id, notes));
1426                         }
1427
1428                 } else if  ((*i)->name() == X_("ControlPoint")) {
1429                         XMLProperty* prop_type = (*i)->property (X_("type"));
1430
1431                         assert(prop_type);
1432
1433                         if (prop_type->value () == "track") {
1434
1435                                 XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
1436                                 XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
1437                                 XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1438                                 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1439
1440                                 assert (prop_route_id);
1441                                 assert (prop_alist_id);
1442                                 assert (prop_parameter);
1443                                 assert (prop_view_index);
1444
1445                                 PBD::ID route_id (prop_route_id->value ());
1446                                 RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (route_id);
1447                                 vector <ControlPoint *> cps;
1448
1449                                 if (rtv) {
1450                                         boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1451                                         if (atv) {
1452                                                 list<boost::shared_ptr<AutomationLine> > lines = atv->lines();
1453                                                 for (list<boost::shared_ptr<AutomationLine> > ::iterator li = lines.begin(); li != lines.end(); ++li) {
1454                                                         if ((*li)->the_list()->id() == prop_alist_id->value()) {
1455                                                                 ControlPoint* cp = (*li)->nth(atol(prop_view_index->value().c_str()));
1456                                                                 if (cp) {
1457                                                                         cps.push_back (cp);
1458                                                                         cp->show();
1459                                                                 }
1460                                                         }
1461                                                 }
1462                                         }
1463                                 }
1464                                 if (!cps.empty()) {
1465                                         add (cps);
1466                                 }
1467                         } else if (prop_type->value () == "region") {
1468                                 XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
1469                                 XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
1470
1471                                 if (!prop_region_id || !prop_view_index) {
1472                                         continue;
1473                                 }
1474
1475                                 PBD::ID region_id (prop_region_id->value ());
1476                                 RegionSelection rs;
1477                                 editor->get_regionviews_by_id (region_id, rs);
1478
1479                                 if (!rs.empty ()) {
1480                                         vector <ControlPoint *> cps;
1481                                         for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
1482                                                 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*rsi);
1483                                                 if (arv) {
1484                                                         boost::shared_ptr<AudioRegionGainLine> gl = arv->get_gain_line ();
1485                                                         ControlPoint* cp = gl->nth(atol(prop_view_index->value().c_str()));
1486                                                         if (cp) {
1487                                                                 cps.push_back (cp);
1488                                                                 cp->show();
1489                                                         }
1490                                                 }
1491                                         }
1492                                         if (!cps.empty()) {
1493                                                 add (cps);
1494                                         }
1495                                 }
1496                         }
1497
1498                 } else if  ((*i)->name() == X_("AudioRange")) {
1499                         XMLProperty* prop_start = (*i)->property (X_("start"));
1500                         XMLProperty* prop_end = (*i)->property (X_("end"));
1501
1502                         assert (prop_start);
1503                         assert (prop_end);
1504
1505                         framepos_t s (atol (prop_start->value ().c_str()));
1506                         framepos_t e (atol (prop_end->value ().c_str()));
1507
1508                         set_preserving_all_ranges (s, e);
1509
1510                 } else if ((*i)->name() == X_("AutomationView")) {
1511
1512                         XMLProperty* prop_id = (*i)->property (X_("id"));
1513                         XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
1514
1515                         assert (prop_id);
1516                         assert (prop_parameter);
1517
1518                         PBD::ID id (prop_id->value ());
1519                         RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
1520
1521                         if (rtv) {
1522                                 boost::shared_ptr<AutomationTimeAxisView> atv = rtv->automation_child (EventTypeMap::instance().from_symbol (prop_parameter->value ()));
1523
1524                                 /* the automation could be for an entity that was never saved
1525                                    in the session file. Don't freak out if we can't find
1526                                    it.
1527                                 */
1528
1529                                 if (atv) {
1530                                         add (atv.get());
1531                                 }
1532                         }
1533
1534                 } else if ((*i)->name() == X_("Marker")) {
1535
1536                         XMLProperty* prop_id = (*i)->property (X_("id"));
1537                         XMLProperty* prop_start = (*i)->property (X_("start"));
1538                         assert (prop_id);
1539                         assert (prop_start);
1540
1541                         PBD::ID id (prop_id->value ());
1542                         ArdourMarker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
1543                         if (m) {
1544                                 add (m);
1545                         }
1546
1547                 }
1548
1549         }
1550
1551         return 0;
1552 }
1553
1554 void
1555 Selection::remove_regions (TimeAxisView* t)
1556 {
1557         RegionSelection::iterator i = regions.begin();
1558         while (i != regions.end ()) {
1559                 RegionSelection::iterator tmp = i;
1560                 ++tmp;
1561
1562                 if (&(*i)->get_time_axis_view() == t) {
1563                         remove (*i);
1564                 }
1565
1566                 i = tmp;
1567         }
1568 }
1569
1570 void
1571 Selection::block_tracks_changed (bool yn)
1572 {
1573         _no_tracks_changed = yn;
1574 }