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 list<TimeAxisView*> added = tracks.add (track_list);
275 for (list<TimeAxisView*>::const_iterator i = added.begin(); i != added.end(); ++i) {
276 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
277 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
280 if (!added.empty()) {
286 Selection::add (TimeAxisView* track)
288 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
289 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
290 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
291 tracks.push_back (track);
297 Selection::add (vector<RegionView*>& v)
299 /* XXX This method or the add (const RegionSelection&) needs to go
302 bool changed = false;
304 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
305 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
306 changed = regions.add ((*i));
307 if (Config->get_link_region_and_track_selection() && changed) {
308 add (&(*i)->get_trackview());
319 Selection::add (const RegionSelection& rs)
321 /* XXX This method or the add (const vector<RegionView*>&) needs to go
324 bool changed = false;
326 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
327 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
328 changed = regions.add ((*i));
329 if (Config->get_link_region_and_track_selection() && changed) {
330 add (&(*i)->get_trackview());
336 select_edit_group_regions ();
342 Selection::add (RegionView* r)
344 if (find (regions.begin(), regions.end(), r) == regions.end()) {
346 if (Config->get_link_region_and_track_selection()) {
347 add (&r->get_trackview());
354 Selection::add (nframes_t start, nframes_t end)
356 AudioRangeComparator cmp;
358 /* XXX this implementation is incorrect */
360 time.push_back (AudioRange (start, end, next_time_id++));
366 return next_time_id - 1;
370 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
372 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
373 if ((*i).id == sid) {
375 time.push_back (AudioRange(start,end, sid));
377 /* don't consolidate here */
380 AudioRangeComparator cmp;
390 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
392 boost::shared_ptr<ARDOUR::AutomationList> al
393 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
395 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
399 if (find (lines.begin(), lines.end(), al) == lines.end()) {
400 lines.push_back (al);
406 Selection::remove (TimeAxisView* track)
408 list<TimeAxisView*>::iterator i;
409 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
416 Selection::remove (const list<TimeAxisView*>& track_list)
418 bool changed = false;
420 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
422 list<TimeAxisView*>::iterator x;
424 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
436 Selection::remove (boost::shared_ptr<Playlist> track)
438 list<boost::shared_ptr<Playlist> >::iterator i;
439 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
446 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
448 bool changed = false;
450 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
452 list<boost::shared_ptr<Playlist> >::iterator x;
454 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
466 Selection::remove (RegionView* r)
468 if (regions.remove (r)) {
472 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
473 remove (&r->get_trackview());
479 Selection::remove (uint32_t selection_id)
485 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
486 if ((*i).id == selection_id) {
496 Selection::remove (nframes_t start, nframes_t end)
501 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
503 AutomationSelection::iterator i;
504 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
511 Selection::set (TimeAxisView* track)
518 Selection::set (const list<TimeAxisView*>& track_list)
525 Selection::set (boost::shared_ptr<Playlist> playlist)
532 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
539 Selection::set (const RegionSelection& rs)
543 RegionsChanged(); /* EMIT SIGNAL */
547 Selection::set (RegionView* r, bool also_clear_tracks)
550 if (also_clear_tracks) {
557 Selection::set (vector<RegionView*>& v)
560 if (Config->get_link_region_and_track_selection()) {
562 // make sure to deselect any automation selections
569 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
571 if ((start == 0 && end == 0) || end < start) {
576 time.push_back (AudioRange (start, end, next_time_id++));
578 /* reuse the first entry, and remove all the rest */
580 while (time.size() > 1) {
583 time.front().start = start;
584 time.front().end = end;
589 time.group = track->route_group();
599 return time.front().id;
603 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
610 Selection::selected (Marker* m)
612 return find (markers.begin(), markers.end(), m) != markers.end();
616 Selection::selected (TimeAxisView* tv)
618 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
622 Selection::selected (RegionView* rv)
624 return find (regions.begin(), regions.end(), rv) != regions.end();
630 return regions.empty () &&
633 playlists.empty () &&
636 playlists.empty () &&
642 Selection::toggle (const vector<AutomationSelectable*>& autos)
644 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
645 if ((*x)->get_selected()) {
648 points.push_back (**x);
654 PointsChanged (); /* EMIT SIGNAL */
658 Selection::toggle (list<Selectable*>& selectables)
661 AutomationSelectable* as;
662 vector<RegionView*> rvs;
663 vector<AutomationSelectable*> autos;
665 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
666 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
668 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
669 autos.push_back (as);
671 fatal << _("programming error: ")
672 << X_("unknown selectable type passed to Selection::toggle()")
682 if (!autos.empty()) {
688 Selection::set (list<Selectable*>& selectables)
697 Selection::add (list<Selectable*>& selectables)
700 AutomationSelectable* as;
701 vector<RegionView*> rvs;
702 vector<AutomationSelectable*> autos;
704 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
705 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
707 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
708 autos.push_back (as);
710 fatal << _("programming error: ")
711 << X_("unknown selectable type passed to Selection::add()")
721 if (!autos.empty()) {
727 Selection::clear_points ()
729 if (!points.empty()) {
736 Selection::add (vector<AutomationSelectable*>& autos)
738 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
739 points.push_back (**i);
746 Selection::select_edit_group_regions ()
748 std::set<RegionView*> regions_to_add;
750 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
751 vector<RegionView*> e;
752 editor->get_equivalent_regions (*i, e);
753 for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
754 regions_to_add.insert(*j);
758 for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
764 Selection::set (Marker* m)
771 Selection::toggle (Marker* m)
773 MarkerSelection::iterator i;
775 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
783 Selection::remove (Marker* m)
785 MarkerSelection::iterator i;
787 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
794 Selection::add (Marker* m)
796 if (find (markers.begin(), markers.end(), m) == markers.end()) {
798 /* disambiguate which remove() for the compiler */
800 void (Selection::*pmf)(Marker*) = &Selection::remove;
802 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
804 markers.push_back (m);
810 Selection::add (const list<Marker*>& m)
812 markers.insert (markers.end(), m.begin(), m.end());
817 MarkerSelection::range (nframes64_t& s, nframes64_t& e)
822 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
824 if ((*i)->position() < s) {
825 s = (*i)->position();
828 if ((*i)->position() > e) {
829 e = (*i)->position();