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::add (Redirect* r)
155 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
156 redirects.push_back (r);
162 Selection::add (Playlist* pl)
164 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
166 playlists.push_back(pl);
172 Selection::add (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::add (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::add (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::add (AudioRegionView* r)
222 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
223 audio_regions.add (r);
229 Selection::add (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::add (jack_nframes_t start, jack_nframes_t end)
248 AudioRangeComparator cmp;
250 time.push_back (AudioRange (start, end, next_time_id++));
256 return next_time_id - 1;
260 Selection::replace (uint32_t sid, jack_nframes_t start, jack_nframes_t end)
262 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
263 if ((*i).id == sid) {
265 time.push_back (AudioRange(start,end, sid));
267 /* don't consolidate here */
270 AudioRangeComparator cmp;
280 Selection::add (AutomationList* ac)
282 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
283 lines.push_back (ac);
289 Selection::remove (Redirect* r)
291 list<Redirect*>::iterator i;
292 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
299 Selection::remove (TimeAxisView* track)
301 list<TimeAxisView*>::iterator i;
302 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
309 Selection::remove (const list<TimeAxisView*>& track_list)
311 bool changed = false;
313 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
315 list<TimeAxisView*>::iterator x;
317 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
329 Selection::remove (Playlist* track)
331 list<Playlist*>::iterator i;
332 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
339 Selection::remove (const list<Playlist*>& pllist)
341 bool changed = false;
343 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
345 list<Playlist*>::iterator x;
347 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
359 Selection::remove (AudioRegionView* r)
361 audio_regions.remove (r);
367 Selection::remove (uint32_t selection_id)
373 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
374 if ((*i).id == selection_id) {
384 Selection::remove (jack_nframes_t start, jack_nframes_t end)
389 Selection::remove (AutomationList *ac)
391 list<AutomationList*>::iterator i;
392 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
399 Selection::set (Redirect *r)
406 Selection::set (TimeAxisView* track)
413 Selection::set (const list<TimeAxisView*>& track_list)
420 Selection::set (Playlist* playlist)
427 Selection::set (const list<Playlist*>& pllist)
434 Selection::set (AudioRegionView* r)
436 clear_audio_regions ();
441 Selection::set (vector<AudioRegionView*>& v)
444 clear_audio_regions ();
445 // make sure to deselect any automation selections
451 Selection::set (TimeAxisView* track, jack_nframes_t start, jack_nframes_t end)
453 if ((start == 0 && end == 0) || end < start) {
458 time.push_back (AudioRange (start, end, next_time_id++));
460 /* reuse the first entry, and remove all the rest */
462 while (time.size() > 1) {
465 time.front().start = start;
466 time.front().end = end;
471 time.group = track->edit_group();
481 return time.front().id;
485 Selection::set (AutomationList *ac)
492 Selection::selected (TimeAxisView* tv)
494 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
498 Selection::selected (AudioRegionView* arv)
500 return find (audio_regions.begin(), audio_regions.end(), arv) != audio_regions.end();
506 return audio_regions.empty () &&
509 playlists.empty () &&
512 playlists.empty () &&
518 Selection::set (list<Selectable*>& selectables)
520 clear_audio_regions();
526 Selection::add (list<Selectable*>& selectables)
528 AudioRegionView* arv;
529 AutomationSelectable* as;
530 vector<AudioRegionView*> arvs;
531 vector<AutomationSelectable*> autos;
533 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
534 if ((arv = dynamic_cast<AudioRegionView*> (*i)) != 0) {
535 arvs.push_back (arv);
536 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
537 autos.push_back (as);
539 fatal << _("programming error: ")
540 << X_("unknown selectable type passed to Selection::set()")
550 if (!autos.empty()) {
556 Selection::clear_points ()
558 if (!points.empty()) {
565 Selection::add (vector<AutomationSelectable*>& autos)
567 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
568 points.push_back (**i);