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>
27 #include "region_view.h"
28 #include "selection.h"
29 #include "selection_templates.h"
30 #include "time_axis_view.h"
31 #include "automation_time_axis.h"
32 #include "public_editor.h"
36 using namespace ARDOUR;
40 struct AudioRangeComparator {
41 bool operator()(AudioRange a, AudioRange b) {
42 return a.start < b.start;
47 Selection::operator= (const Selection& other)
50 regions = other.regions;
51 tracks = other.tracks;
59 operator== (const Selection& a, const Selection& b)
61 return a.regions == b.regions &&
62 a.tracks == b.tracks &&
63 a.time.track == b.time.track &&
64 a.time.group == b.time.group &&
67 a.playlists == b.playlists;
70 /** Clear everything from the Selection */
83 Selection::dump_region_layers()
85 cerr << "region selection layer dump" << endl;
86 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
87 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
93 Selection::clear_regions ()
95 if (!regions.empty()) {
102 Selection::clear_tracks ()
104 if (!tracks.empty()) {
111 Selection::clear_time ()
121 Selection::clear_playlists ()
123 /* Selections own their playlists */
125 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
126 /* selections own their own regions, which are copies of the "originals". make them go away */
127 (*i)->drop_regions ();
131 if (!playlists.empty()) {
138 Selection::clear_lines ()
140 if (!lines.empty()) {
147 Selection::clear_markers ()
149 if (!markers.empty()) {
156 Selection::toggle (boost::shared_ptr<Playlist> pl)
158 PlaylistSelection::iterator i;
160 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
162 playlists.push_back(pl);
171 Selection::toggle (const list<TimeAxisView*>& track_list)
173 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
179 Selection::toggle (TimeAxisView* track)
181 TrackSelection::iterator i;
183 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
184 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
185 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
186 tracks.push_back (track);
195 Selection::toggle (RegionView* r)
197 RegionSelection::iterator i;
199 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
209 Selection::toggle (vector<RegionView*>& r)
211 RegionSelection::iterator i;
213 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
214 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
225 Selection::toggle (nframes_t start, nframes_t end)
227 AudioRangeComparator cmp;
229 /* XXX this implementation is incorrect */
231 time.push_back (AudioRange (start, end, next_time_id++));
237 return next_time_id - 1;
241 Selection::add (boost::shared_ptr<Playlist> pl)
243 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
245 playlists.push_back(pl);
251 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
253 bool changed = false;
255 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
256 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
258 playlists.push_back (*i);
269 Selection::add (const list<TimeAxisView*>& track_list)
271 bool changed = false;
273 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
274 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
275 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
276 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
277 tracks.push_back (*i);
288 Selection::add (TimeAxisView* track)
290 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
291 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
292 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
293 tracks.push_back (track);
299 Selection::add (vector<RegionView*>& v)
301 /* XXX This method or the add (const RegionSelection&) needs to go
304 bool changed = false;
306 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
307 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
308 changed = regions.add ((*i));
309 if (Config->get_link_region_and_track_selection() && changed) {
310 add (&(*i)->get_trackview());
321 Selection::add (const RegionSelection& rs)
323 /* XXX This method or the add (const vector<RegionView*>&) needs to go
326 bool changed = false;
328 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
329 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
330 changed = regions.add ((*i));
331 if (Config->get_link_region_and_track_selection() && changed) {
332 add (&(*i)->get_trackview());
338 select_edit_group_regions ();
344 Selection::add (RegionView* r)
346 if (find (regions.begin(), regions.end(), r) == regions.end()) {
348 if (Config->get_link_region_and_track_selection()) {
349 add (&r->get_trackview());
356 Selection::add (nframes_t start, nframes_t end)
358 AudioRangeComparator cmp;
360 /* XXX this implementation is incorrect */
362 time.push_back (AudioRange (start, end, next_time_id++));
368 return next_time_id - 1;
372 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
374 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
375 if ((*i).id == sid) {
377 time.push_back (AudioRange(start,end, sid));
379 /* don't consolidate here */
382 AudioRangeComparator cmp;
392 Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
394 boost::shared_ptr<ARDOUR::AutomationList> al
395 = boost::dynamic_pointer_cast<ARDOUR::AutomationList>(cl);
397 warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
401 if (find (lines.begin(), lines.end(), al) == lines.end()) {
402 lines.push_back (al);
408 Selection::remove (TimeAxisView* track)
410 list<TimeAxisView*>::iterator i;
411 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
418 Selection::remove (const list<TimeAxisView*>& track_list)
420 bool changed = false;
422 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
424 list<TimeAxisView*>::iterator x;
426 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
438 Selection::remove (boost::shared_ptr<Playlist> track)
440 list<boost::shared_ptr<Playlist> >::iterator i;
441 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
448 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
450 bool changed = false;
452 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
454 list<boost::shared_ptr<Playlist> >::iterator x;
456 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
468 Selection::remove (RegionView* r)
470 if (regions.remove (r)) {
474 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
475 remove (&r->get_trackview());
481 Selection::remove (uint32_t selection_id)
487 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
488 if ((*i).id == selection_id) {
498 Selection::remove (nframes_t start, nframes_t end)
503 Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
505 AutomationSelection::iterator i;
506 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
513 Selection::set (TimeAxisView* track)
520 Selection::set (const list<TimeAxisView*>& track_list)
527 Selection::set (boost::shared_ptr<Playlist> playlist)
534 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
541 Selection::set (const RegionSelection& rs)
545 RegionsChanged(); /* EMIT SIGNAL */
549 Selection::set (RegionView* r, bool also_clear_tracks)
552 if (also_clear_tracks) {
559 Selection::set (vector<RegionView*>& v)
562 if (Config->get_link_region_and_track_selection()) {
564 // make sure to deselect any automation selections
571 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
573 if ((start == 0 && end == 0) || end < start) {
578 time.push_back (AudioRange (start, end, next_time_id++));
580 /* reuse the first entry, and remove all the rest */
582 while (time.size() > 1) {
585 time.front().start = start;
586 time.front().end = end;
591 time.group = track->edit_group();
601 return time.front().id;
605 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
612 Selection::selected (TimeAxisView* tv)
614 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
618 Selection::selected (RegionView* rv)
620 return find (regions.begin(), regions.end(), rv) != regions.end();
626 return regions.empty () &&
629 playlists.empty () &&
632 playlists.empty () &&
638 Selection::toggle (const vector<AutomationSelectable*>& autos)
640 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
641 if ((*x)->get_selected()) {
644 points.push_back (**x);
650 PointsChanged (); /* EMIT SIGNAL */
654 Selection::toggle (list<Selectable*>& selectables)
657 AutomationSelectable* as;
658 vector<RegionView*> rvs;
659 vector<AutomationSelectable*> autos;
661 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
662 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
664 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
665 autos.push_back (as);
667 fatal << _("programming error: ")
668 << X_("unknown selectable type passed to Selection::toggle()")
678 if (!autos.empty()) {
684 Selection::set (list<Selectable*>& selectables)
693 Selection::add (list<Selectable*>& selectables)
696 AutomationSelectable* as;
697 vector<RegionView*> rvs;
698 vector<AutomationSelectable*> autos;
700 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
701 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
703 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
704 autos.push_back (as);
706 fatal << _("programming error: ")
707 << X_("unknown selectable type passed to Selection::add()")
717 if (!autos.empty()) {
723 Selection::clear_points ()
725 if (!points.empty()) {
732 Selection::add (vector<AutomationSelectable*>& autos)
734 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
735 points.push_back (**i);
742 Selection::select_edit_group_regions ()
744 std::set<RegionView*> regions_to_add;
746 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
747 vector<RegionView*> e;
748 editor->get_equivalent_regions (*i, e);
749 for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
750 regions_to_add.insert(*j);
754 for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
760 Selection::set (Marker* m)
767 Selection::toggle (Marker* m)
769 MarkerSelection::iterator i;
771 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
779 Selection::remove (Marker* m)
781 MarkerSelection::iterator i;
783 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
790 Selection::add (Marker* m)
792 if (find (markers.begin(), markers.end(), m) == markers.end()) {
794 /* disambiguate which remove() for the compiler */
796 void (Selection::*pmf)(Marker*) = &Selection::remove;
798 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
800 markers.push_back (m);