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.
22 #include <sigc++/bind.h>
23 #include <pbd/error.h>
25 #include <ardour/playlist.h>
27 #include "regionview.h"
28 #include "selection.h"
29 #include "selection_templates.h"
30 #include "time_axis_view.h"
31 #include "automation_time_axis.h"
35 using namespace ARDOUR;
38 struct AudioRangeComparator {
39 bool operator()(AudioRange a, AudioRange b) {
40 return a.start < b.start;
45 Selection::operator= (const Selection& other)
48 audio_regions = other.audio_regions;
49 tracks = other.tracks;
57 operator== (const Selection& a, const Selection& b)
59 return a.audio_regions == b.audio_regions &&
60 a.tracks == b.tracks &&
61 a.time.track == b.time.track &&
62 a.time.group == b.time.group &&
65 a.playlists == b.playlists &&
66 a.redirects == b.redirects;
73 clear_audio_regions ();
82 Selection::dump_region_layers()
84 cerr << "region selection layer dump" << endl;
85 for (AudioRegionSelection::iterator i = audio_regions.begin(); i != audio_regions.end(); ++i) {
86 cerr << "layer: " << (int)(*i)->region.layer() << endl;
92 Selection::clear_redirects ()
94 if (!redirects.empty()) {
101 Selection::clear_audio_regions ()
103 if (!audio_regions.empty()) {
104 audio_regions.clear_all ();
110 Selection::clear_tracks ()
112 if (!tracks.empty()) {
119 Selection::clear_time ()
129 Selection::clear_playlists ()
131 /* Selections own their playlists */
133 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
137 if (!playlists.empty()) {
144 Selection::clear_lines ()
146 if (!lines.empty()) {
153 Selection::toggle (Redirect* r)
155 RedirectSelection::iterator i;
157 if ((i = find (redirects.begin(), redirects.end(), r)) == redirects.end()) {
158 redirects.push_back (r);
167 Selection::toggle (Playlist* pl)
169 PlaylistSelection::iterator i;
171 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
173 playlists.push_back(pl);
182 Selection::toggle (TimeAxisView* track)
184 TrackSelection::iterator i;
186 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
187 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
188 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
189 tracks.push_back (track);
198 Selection::toggle (AudioRegionView* r)
200 AudioRegionSelection::iterator i;
202 if ((i = find (audio_regions.begin(), audio_regions.end(), r)) == audio_regions.end()) {
203 audio_regions.add (r);
205 audio_regions.erase (i);
212 Selection::toggle (vector<AudioRegionView*>& r)
214 AudioRegionSelection::iterator i;
216 for (vector<AudioRegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
217 if ((i = find (audio_regions.begin(), audio_regions.end(), (*x))) == audio_regions.end()) {
218 audio_regions.add ((*x));
220 audio_regions.erase (i);
228 Selection::toggle (jack_nframes_t start, jack_nframes_t end)
230 AudioRangeComparator cmp;
232 /* XXX this implementation is incorrect */
234 time.push_back (AudioRange (start, end, next_time_id++));
240 return next_time_id - 1;
245 Selection::add (Redirect* r)
247 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
248 redirects.push_back (r);
254 Selection::add (Playlist* pl)
256 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
258 playlists.push_back(pl);
264 Selection::add (const list<Playlist*>& pllist)
266 bool changed = false;
268 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
269 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
271 playlists.push_back (*i);
282 Selection::add (const list<TimeAxisView*>& track_list)
284 bool changed = false;
286 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
287 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
288 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
289 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
290 tracks.push_back (*i);
301 Selection::add (TimeAxisView* track)
303 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
304 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
305 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
306 tracks.push_back (track);
312 Selection::add (AudioRegionView* r)
314 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
315 audio_regions.add (r);
321 Selection::add (vector<AudioRegionView*>& v)
323 bool changed = false;
325 for (vector<AudioRegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
326 if (find (audio_regions.begin(), audio_regions.end(), (*i)) == audio_regions.end()) {
327 audio_regions.add ((*i));
338 Selection::add (jack_nframes_t start, jack_nframes_t end)
340 AudioRangeComparator cmp;
342 /* XXX this implementation is incorrect */
344 time.push_back (AudioRange (start, end, next_time_id++));
350 return next_time_id - 1;
354 Selection::replace (uint32_t sid, jack_nframes_t start, jack_nframes_t end)
356 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
357 if ((*i).id == sid) {
359 time.push_back (AudioRange(start,end, sid));
361 /* don't consolidate here */
364 AudioRangeComparator cmp;
374 Selection::add (AutomationList* ac)
376 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
377 lines.push_back (ac);
383 Selection::remove (Redirect* r)
385 list<Redirect*>::iterator i;
386 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
393 Selection::remove (TimeAxisView* track)
395 list<TimeAxisView*>::iterator i;
396 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
403 Selection::remove (const list<TimeAxisView*>& track_list)
405 bool changed = false;
407 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
409 list<TimeAxisView*>::iterator x;
411 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
423 Selection::remove (Playlist* track)
425 list<Playlist*>::iterator i;
426 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
433 Selection::remove (const list<Playlist*>& pllist)
435 bool changed = false;
437 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
439 list<Playlist*>::iterator x;
441 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
453 Selection::remove (AudioRegionView* r)
455 audio_regions.remove (r);
461 Selection::remove (uint32_t selection_id)
467 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
468 if ((*i).id == selection_id) {
478 Selection::remove (jack_nframes_t start, jack_nframes_t end)
483 Selection::remove (AutomationList *ac)
485 list<AutomationList*>::iterator i;
486 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
493 Selection::set (Redirect *r)
500 Selection::set (TimeAxisView* track)
507 Selection::set (const list<TimeAxisView*>& track_list)
514 Selection::set (Playlist* playlist)
521 Selection::set (const list<Playlist*>& pllist)
528 Selection::set (AudioRegionView* r)
530 clear_audio_regions ();
535 Selection::set (vector<AudioRegionView*>& v)
538 clear_audio_regions ();
539 // make sure to deselect any automation selections
545 Selection::set (TimeAxisView* track, jack_nframes_t start, jack_nframes_t end)
547 if ((start == 0 && end == 0) || end < start) {
552 time.push_back (AudioRange (start, end, next_time_id++));
554 /* reuse the first entry, and remove all the rest */
556 while (time.size() > 1) {
559 time.front().start = start;
560 time.front().end = end;
565 time.group = track->edit_group();
575 return time.front().id;
579 Selection::set (AutomationList *ac)
586 Selection::selected (TimeAxisView* tv)
588 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
592 Selection::selected (AudioRegionView* arv)
594 return find (audio_regions.begin(), audio_regions.end(), arv) != audio_regions.end();
600 return audio_regions.empty () &&
603 playlists.empty () &&
606 playlists.empty () &&
612 Selection::set (list<Selectable*>& selectables)
614 clear_audio_regions();
620 Selection::add (list<Selectable*>& selectables)
622 AudioRegionView* arv;
623 AutomationSelectable* as;
624 vector<AudioRegionView*> arvs;
625 vector<AutomationSelectable*> autos;
627 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
628 if ((arv = dynamic_cast<AudioRegionView*> (*i)) != 0) {
629 arvs.push_back (arv);
630 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
631 autos.push_back (as);
633 fatal << _("programming error: ")
634 << X_("unknown selectable type passed to Selection::set()")
644 if (!autos.empty()) {
650 Selection::clear_points ()
652 if (!points.empty()) {
659 Selection::add (vector<AutomationSelectable*>& autos)
661 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
662 points.push_back (**i);