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>
22 #include "pbd/error.h"
23 #include "pbd/stacktrace.h"
25 #include "ardour/playlist.h"
26 #include "ardour/rc_configuration.h"
28 #include "region_view.h"
29 #include "selection.h"
30 #include "selection_templates.h"
31 #include "time_axis_view.h"
32 #include "automation_time_axis.h"
33 #include "public_editor.h"
38 using namespace ARDOUR;
42 struct AudioRangeComparator {
43 bool operator()(AudioRange a, AudioRange b) {
44 return a.start < b.start;
49 Selection::operator= (const Selection& other)
52 regions = other.regions;
53 tracks = other.tracks;
61 operator== (const Selection& a, const Selection& b)
63 return a.regions == b.regions &&
64 a.tracks == b.tracks &&
65 a.time.track == b.time.track &&
66 a.time.group == b.time.group &&
69 a.playlists == b.playlists;
72 /** Clear everything from the Selection */
85 Selection::dump_region_layers()
87 cerr << "region selection layer dump" << endl;
88 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
89 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
95 Selection::clear_regions ()
97 if (!regions.empty()) {
104 Selection::clear_tracks ()
106 if (!tracks.empty()) {
113 Selection::clear_time ()
123 Selection::clear_playlists ()
125 /* Selections own their playlists */
127 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
128 /* selections own their own regions, which are copies of the "originals". make them go away */
129 (*i)->drop_regions ();
133 if (!playlists.empty()) {
140 Selection::clear_lines ()
142 if (!lines.empty()) {
149 Selection::clear_markers ()
151 if (!markers.empty()) {
158 Selection::toggle (boost::shared_ptr<Playlist> pl)
160 PlaylistSelection::iterator i;
162 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
164 playlists.push_back(pl);
173 Selection::toggle (const list<TimeAxisView*>& track_list)
175 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
181 Selection::toggle (TimeAxisView* track)
183 TrackSelection::iterator i;
185 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
186 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
187 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
188 tracks.push_back (track);
197 Selection::toggle (RegionView* r)
199 RegionSelection::iterator i;
201 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
211 Selection::toggle (vector<RegionView*>& r)
213 RegionSelection::iterator i;
215 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
216 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
227 Selection::toggle (nframes_t start, nframes_t end)
229 AudioRangeComparator cmp;
231 /* XXX this implementation is incorrect */
233 time.push_back (AudioRange (start, end, next_time_id++));
239 return next_time_id - 1;
243 Selection::add (boost::shared_ptr<Playlist> pl)
245 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
247 playlists.push_back(pl);
253 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
255 bool changed = false;
257 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
258 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
260 playlists.push_back (*i);
271 Selection::add (const list<TimeAxisView*>& track_list)
273 bool changed = false;
275 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
276 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
277 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
278 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
279 tracks.push_back (*i);
290 Selection::add (TimeAxisView* track)
292 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
293 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
294 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
295 tracks.push_back (track);
301 Selection::add (vector<RegionView*>& v)
303 /* XXX This method or the add (const RegionSelection&) needs to go
306 bool changed = false;
308 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
309 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
310 changed = regions.add ((*i));
311 if (Config->get_link_region_and_track_selection() && changed) {
312 add (&(*i)->get_trackview());
323 Selection::add (const RegionSelection& rs)
325 /* XXX This method or the add (const vector<RegionView*>&) needs to go
328 bool changed = false;
330 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
331 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
332 changed = regions.add ((*i));
333 if (Config->get_link_region_and_track_selection() && changed) {
334 add (&(*i)->get_trackview());
340 select_edit_group_regions ();
346 Selection::add (RegionView* r)
348 if (find (regions.begin(), regions.end(), r) == regions.end()) {
350 if (Config->get_link_region_and_track_selection()) {
351 add (&r->get_trackview());
358 Selection::add (nframes_t start, nframes_t end)
360 AudioRangeComparator cmp;
362 /* XXX this implementation is incorrect */
364 time.push_back (AudioRange (start, end, next_time_id++));
370 return next_time_id - 1;
374 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
376 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
377 if ((*i).id == sid) {
379 time.push_back (AudioRange(start,end, sid));
381 /* don't consolidate here */
384 AudioRangeComparator cmp;
394 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
396 boost::shared_ptr<ARDOUR::AutomationList> al
397 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
399 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
403 if (find (lines.begin(), lines.end(), al) == lines.end()) {
404 lines.push_back (al);
410 Selection::remove (TimeAxisView* track)
412 list<TimeAxisView*>::iterator i;
413 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
420 Selection::remove (const list<TimeAxisView*>& track_list)
422 bool changed = false;
424 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
426 list<TimeAxisView*>::iterator x;
428 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
440 Selection::remove (boost::shared_ptr<Playlist> track)
442 list<boost::shared_ptr<Playlist> >::iterator i;
443 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
450 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
452 bool changed = false;
454 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
456 list<boost::shared_ptr<Playlist> >::iterator x;
458 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
470 Selection::remove (RegionView* r)
472 if (regions.remove (r)) {
476 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
477 remove (&r->get_trackview());
483 Selection::remove (uint32_t selection_id)
489 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
490 if ((*i).id == selection_id) {
500 Selection::remove (nframes_t start, nframes_t end)
505 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
507 AutomationSelection::iterator i;
508 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
515 Selection::set (TimeAxisView* track)
522 Selection::set (const list<TimeAxisView*>& track_list)
529 Selection::set (boost::shared_ptr<Playlist> playlist)
536 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
543 Selection::set (const RegionSelection& rs)
547 RegionsChanged(); /* EMIT SIGNAL */
551 Selection::set (RegionView* r, bool also_clear_tracks)
554 if (also_clear_tracks) {
561 Selection::set (vector<RegionView*>& v)
564 if (Config->get_link_region_and_track_selection()) {
566 // make sure to deselect any automation selections
573 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
575 if ((start == 0 && end == 0) || end < start) {
580 time.push_back (AudioRange (start, end, next_time_id++));
582 /* reuse the first entry, and remove all the rest */
584 while (time.size() > 1) {
587 time.front().start = start;
588 time.front().end = end;
593 time.group = track->edit_group();
603 return time.front().id;
607 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
614 Selection::selected (Marker* m)
616 return find (markers.begin(), markers.end(), m) != markers.end();
620 Selection::selected (TimeAxisView* tv)
622 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
626 Selection::selected (RegionView* rv)
628 return find (regions.begin(), regions.end(), rv) != regions.end();
634 return regions.empty () &&
637 playlists.empty () &&
640 playlists.empty () &&
646 Selection::toggle (const vector<AutomationSelectable*>& autos)
648 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
649 if ((*x)->get_selected()) {
652 points.push_back (**x);
658 PointsChanged (); /* EMIT SIGNAL */
662 Selection::toggle (list<Selectable*>& selectables)
665 AutomationSelectable* as;
666 vector<RegionView*> rvs;
667 vector<AutomationSelectable*> autos;
669 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
670 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
672 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
673 autos.push_back (as);
675 fatal << _("programming error: ")
676 << X_("unknown selectable type passed to Selection::toggle()")
686 if (!autos.empty()) {
692 Selection::set (list<Selectable*>& selectables)
701 Selection::add (list<Selectable*>& selectables)
704 AutomationSelectable* as;
705 vector<RegionView*> rvs;
706 vector<AutomationSelectable*> autos;
708 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
709 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
711 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
712 autos.push_back (as);
714 fatal << _("programming error: ")
715 << X_("unknown selectable type passed to Selection::add()")
725 if (!autos.empty()) {
731 Selection::clear_points ()
733 if (!points.empty()) {
740 Selection::add (vector<AutomationSelectable*>& autos)
742 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
743 points.push_back (**i);
750 Selection::select_edit_group_regions ()
752 std::set<RegionView*> regions_to_add;
754 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
755 vector<RegionView*> e;
756 editor->get_equivalent_regions (*i, e);
757 for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
758 regions_to_add.insert(*j);
762 for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
768 Selection::set (Marker* m)
775 Selection::toggle (Marker* m)
777 MarkerSelection::iterator i;
779 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
787 Selection::remove (Marker* m)
789 MarkerSelection::iterator i;
791 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
798 Selection::add (Marker* m)
800 if (find (markers.begin(), markers.end(), m) == markers.end()) {
802 /* disambiguate which remove() for the compiler */
804 void (Selection::*pmf)(Marker*) = &Selection::remove;
806 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
808 markers.push_back (m);
814 Selection::add (const list<Marker*>& m)
816 markers.insert (markers.end(), m.begin(), m.end());
821 MarkerSelection::range (nframes64_t& s, nframes64_t& e)
826 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
828 if ((*i)->position() < s) {
829 s = (*i)->position();
832 if ((*i)->position() > e) {
833 e = (*i)->position();