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());
341 Selection::add (RegionView* r)
343 if (find (regions.begin(), regions.end(), r) == regions.end()) {
345 if (Config->get_link_region_and_track_selection()) {
346 add (&r->get_trackview());
353 Selection::add (nframes_t start, nframes_t end)
355 AudioRangeComparator cmp;
357 /* XXX this implementation is incorrect */
359 time.push_back (AudioRange (start, end, next_time_id++));
365 return next_time_id - 1;
369 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
371 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
372 if ((*i).id == sid) {
374 time.push_back (AudioRange(start,end, sid));
376 /* don't consolidate here */
379 AudioRangeComparator cmp;
389 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
391 boost::shared_ptr<ARDOUR::AutomationList> al
392 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
394 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
398 if (find (lines.begin(), lines.end(), al) == lines.end()) {
399 lines.push_back (al);
405 Selection::remove (TimeAxisView* track)
407 list<TimeAxisView*>::iterator i;
408 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
415 Selection::remove (const list<TimeAxisView*>& track_list)
417 bool changed = false;
419 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
421 list<TimeAxisView*>::iterator x;
423 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
435 Selection::remove (boost::shared_ptr<Playlist> track)
437 list<boost::shared_ptr<Playlist> >::iterator i;
438 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
445 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
447 bool changed = false;
449 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
451 list<boost::shared_ptr<Playlist> >::iterator x;
453 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
465 Selection::remove (RegionView* r)
467 if (regions.remove (r)) {
471 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
472 remove (&r->get_trackview());
478 Selection::remove (uint32_t selection_id)
484 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
485 if ((*i).id == selection_id) {
495 Selection::remove (nframes_t /*start*/, nframes_t /*end*/)
500 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
502 AutomationSelection::iterator i;
503 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
510 Selection::set (TimeAxisView* track)
517 Selection::set (const list<TimeAxisView*>& track_list)
524 Selection::set (boost::shared_ptr<Playlist> playlist)
531 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
538 Selection::set (const RegionSelection& rs)
542 RegionsChanged(); /* EMIT SIGNAL */
546 Selection::set (RegionView* r, bool also_clear_tracks)
549 if (also_clear_tracks) {
556 Selection::set (vector<RegionView*>& v)
559 if (Config->get_link_region_and_track_selection()) {
561 // make sure to deselect any automation selections
568 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
570 if ((start == 0 && end == 0) || end < start) {
575 time.push_back (AudioRange (start, end, next_time_id++));
577 /* reuse the first entry, and remove all the rest */
579 while (time.size() > 1) {
582 time.front().start = start;
583 time.front().end = end;
588 time.group = track->route_group();
598 return time.front().id;
602 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
609 Selection::selected (Marker* m)
611 return find (markers.begin(), markers.end(), m) != markers.end();
615 Selection::selected (TimeAxisView* tv)
617 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
621 Selection::selected (RegionView* rv)
623 return find (regions.begin(), regions.end(), rv) != regions.end();
629 return regions.empty () &&
632 playlists.empty () &&
635 playlists.empty () &&
641 Selection::toggle (const vector<AutomationSelectable*>& autos)
643 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
644 if ((*x)->get_selected()) {
647 points.push_back (**x);
653 PointsChanged (); /* EMIT SIGNAL */
657 Selection::toggle (list<Selectable*>& selectables)
660 AutomationSelectable* as;
661 vector<RegionView*> rvs;
662 vector<AutomationSelectable*> autos;
664 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
665 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
667 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
668 autos.push_back (as);
670 fatal << _("programming error: ")
671 << X_("unknown selectable type passed to Selection::toggle()")
681 if (!autos.empty()) {
687 Selection::set (list<Selectable*>& selectables)
696 Selection::add (list<Selectable*>& selectables)
699 AutomationSelectable* as;
700 vector<RegionView*> rvs;
701 vector<AutomationSelectable*> autos;
703 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
704 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
706 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
707 autos.push_back (as);
709 fatal << _("programming error: ")
710 << X_("unknown selectable type passed to Selection::add()")
720 if (!autos.empty()) {
726 Selection::clear_points ()
728 if (!points.empty()) {
735 Selection::add (vector<AutomationSelectable*>& autos)
737 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
738 points.push_back (**i);
745 Selection::set (Marker* m)
752 Selection::toggle (Marker* m)
754 MarkerSelection::iterator i;
756 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
764 Selection::remove (Marker* m)
766 MarkerSelection::iterator i;
768 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
775 Selection::add (Marker* m)
777 if (find (markers.begin(), markers.end(), m) == markers.end()) {
779 /* disambiguate which remove() for the compiler */
781 void (Selection::*pmf)(Marker*) = &Selection::remove;
783 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
785 markers.push_back (m);
791 Selection::add (const list<Marker*>& m)
793 markers.insert (markers.end(), m.begin(), m.end());
798 MarkerSelection::range (nframes64_t& s, nframes64_t& e)
803 for (MarkerSelection::iterator i = begin(); i != end(); ++i) {
805 if ((*i)->position() < s) {
806 s = (*i)->position();
809 if ((*i)->position() > e) {
810 e = (*i)->position();