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 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
156 redirects.push_back (r);
162 Selection::toggle (Playlist* pl)
164 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
166 playlists.push_back(pl);
172 Selection::toggle (const list<Playlist*>& pllist)
174 bool changed = false;
176 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
177 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
179 playlists.push_back (*i);
190 Selection::toggle (const list<TimeAxisView*>& track_list)
192 bool changed = false;
194 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
195 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
196 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
197 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
198 tracks.push_back (*i);
209 Selection::toggle (TimeAxisView* track)
211 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
212 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
213 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
214 tracks.push_back (track);
220 Selection::toggle (AudioRegionView* r)
222 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
223 audio_regions.add (r);
229 Selection::toggle (vector<AudioRegionView*>& v)
231 bool changed = false;
233 for (vector<AudioRegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
234 if (find (audio_regions.begin(), audio_regions.end(), (*i)) == audio_regions.end()) {
235 audio_regions.add ((*i));
246 Selection::toggle (jack_nframes_t start, jack_nframes_t end)
248 AudioRangeComparator cmp;
250 /* XXX this implementation is incorrect */
252 time.push_back (AudioRange (start, end, next_time_id++));
258 return next_time_id - 1;
263 Selection::add (Redirect* r)
265 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
266 redirects.push_back (r);
272 Selection::add (Playlist* pl)
274 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
276 playlists.push_back(pl);
282 Selection::add (const list<Playlist*>& pllist)
284 bool changed = false;
286 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
287 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
289 playlists.push_back (*i);
300 Selection::add (const list<TimeAxisView*>& track_list)
302 bool changed = false;
304 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
305 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
306 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
307 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
308 tracks.push_back (*i);
319 Selection::add (TimeAxisView* track)
321 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
322 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
323 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
324 tracks.push_back (track);
330 Selection::add (AudioRegionView* r)
332 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
333 audio_regions.add (r);
339 Selection::add (vector<AudioRegionView*>& v)
341 bool changed = false;
343 for (vector<AudioRegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
344 if (find (audio_regions.begin(), audio_regions.end(), (*i)) == audio_regions.end()) {
345 audio_regions.add ((*i));
356 Selection::add (jack_nframes_t start, jack_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, jack_nframes_t start, jack_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 (AutomationList* ac)
394 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
395 lines.push_back (ac);
401 Selection::remove (Redirect* r)
403 list<Redirect*>::iterator i;
404 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
411 Selection::remove (TimeAxisView* track)
413 list<TimeAxisView*>::iterator i;
414 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
421 Selection::remove (const list<TimeAxisView*>& track_list)
423 bool changed = false;
425 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
427 list<TimeAxisView*>::iterator x;
429 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
441 Selection::remove (Playlist* track)
443 list<Playlist*>::iterator i;
444 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
451 Selection::remove (const list<Playlist*>& pllist)
453 bool changed = false;
455 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
457 list<Playlist*>::iterator x;
459 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
471 Selection::remove (AudioRegionView* r)
473 audio_regions.remove (r);
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 (jack_nframes_t start, jack_nframes_t end)
501 Selection::remove (AutomationList *ac)
503 list<AutomationList*>::iterator i;
504 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
511 Selection::set (Redirect *r)
518 Selection::set (TimeAxisView* track)
525 Selection::set (const list<TimeAxisView*>& track_list)
532 Selection::set (Playlist* playlist)
539 Selection::set (const list<Playlist*>& pllist)
546 Selection::set (AudioRegionView* r)
548 clear_audio_regions ();
553 Selection::set (vector<AudioRegionView*>& v)
556 clear_audio_regions ();
557 // make sure to deselect any automation selections
563 Selection::set (TimeAxisView* track, jack_nframes_t start, jack_nframes_t end)
565 if ((start == 0 && end == 0) || end < start) {
570 time.push_back (AudioRange (start, end, next_time_id++));
572 /* reuse the first entry, and remove all the rest */
574 while (time.size() > 1) {
577 time.front().start = start;
578 time.front().end = end;
583 time.group = track->edit_group();
593 return time.front().id;
597 Selection::set (AutomationList *ac)
604 Selection::selected (TimeAxisView* tv)
606 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
610 Selection::selected (AudioRegionView* arv)
612 return find (audio_regions.begin(), audio_regions.end(), arv) != audio_regions.end();
618 return audio_regions.empty () &&
621 playlists.empty () &&
624 playlists.empty () &&
630 Selection::set (list<Selectable*>& selectables)
632 clear_audio_regions();
638 Selection::add (list<Selectable*>& selectables)
640 AudioRegionView* arv;
641 AutomationSelectable* as;
642 vector<AudioRegionView*> arvs;
643 vector<AutomationSelectable*> autos;
645 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
646 if ((arv = dynamic_cast<AudioRegionView*> (*i)) != 0) {
647 arvs.push_back (arv);
648 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
649 autos.push_back (as);
651 fatal << _("programming error: ")
652 << X_("unknown selectable type passed to Selection::set()")
662 if (!autos.empty()) {
668 Selection::clear_points ()
670 if (!points.empty()) {
677 Selection::add (vector<AutomationSelectable*>& autos)
679 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
680 points.push_back (**i);