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 cerr << "about to toggle a regionview\n";
204 if ((i = find (audio_regions.begin(), audio_regions.end(), r)) == audio_regions.end()) {
205 audio_regions.add (r);
208 audio_regions.erase (i);
209 cerr << "\tremoved\n";
217 Selection::toggle (jack_nframes_t start, jack_nframes_t end)
219 AudioRangeComparator cmp;
221 /* XXX this implementation is incorrect */
223 time.push_back (AudioRange (start, end, next_time_id++));
229 return next_time_id - 1;
234 Selection::add (Redirect* r)
236 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
237 redirects.push_back (r);
243 Selection::add (Playlist* pl)
245 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
247 playlists.push_back(pl);
253 Selection::add (const list<Playlist*>& pllist)
255 bool changed = false;
257 for (list<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 bool changed = false;
275 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
276 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
277 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
278 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
279 tracks.push_back (*i);
290 Selection::add (TimeAxisView* track)
292 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
293 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
294 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
295 tracks.push_back (track);
301 Selection::add (AudioRegionView* r)
303 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
304 audio_regions.add (r);
310 Selection::add (vector<AudioRegionView*>& v)
312 bool changed = false;
314 for (vector<AudioRegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
315 if (find (audio_regions.begin(), audio_regions.end(), (*i)) == audio_regions.end()) {
316 audio_regions.add ((*i));
327 Selection::add (jack_nframes_t start, jack_nframes_t end)
329 AudioRangeComparator cmp;
331 /* XXX this implementation is incorrect */
333 time.push_back (AudioRange (start, end, next_time_id++));
339 return next_time_id - 1;
343 Selection::replace (uint32_t sid, jack_nframes_t start, jack_nframes_t end)
345 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
346 if ((*i).id == sid) {
348 time.push_back (AudioRange(start,end, sid));
350 /* don't consolidate here */
353 AudioRangeComparator cmp;
363 Selection::add (AutomationList* ac)
365 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
366 lines.push_back (ac);
372 Selection::remove (Redirect* r)
374 list<Redirect*>::iterator i;
375 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
382 Selection::remove (TimeAxisView* track)
384 list<TimeAxisView*>::iterator i;
385 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
392 Selection::remove (const list<TimeAxisView*>& track_list)
394 bool changed = false;
396 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
398 list<TimeAxisView*>::iterator x;
400 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
412 Selection::remove (Playlist* track)
414 list<Playlist*>::iterator i;
415 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
422 Selection::remove (const list<Playlist*>& pllist)
424 bool changed = false;
426 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
428 list<Playlist*>::iterator x;
430 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
442 Selection::remove (AudioRegionView* r)
444 audio_regions.remove (r);
450 Selection::remove (uint32_t selection_id)
456 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
457 if ((*i).id == selection_id) {
467 Selection::remove (jack_nframes_t start, jack_nframes_t end)
472 Selection::remove (AutomationList *ac)
474 list<AutomationList*>::iterator i;
475 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
482 Selection::set (Redirect *r)
489 Selection::set (TimeAxisView* track)
496 Selection::set (const list<TimeAxisView*>& track_list)
503 Selection::set (Playlist* playlist)
510 Selection::set (const list<Playlist*>& pllist)
517 Selection::set (AudioRegionView* r)
519 clear_audio_regions ();
524 Selection::set (vector<AudioRegionView*>& v)
527 clear_audio_regions ();
528 // make sure to deselect any automation selections
534 Selection::set (TimeAxisView* track, jack_nframes_t start, jack_nframes_t end)
536 if ((start == 0 && end == 0) || end < start) {
541 time.push_back (AudioRange (start, end, next_time_id++));
543 /* reuse the first entry, and remove all the rest */
545 while (time.size() > 1) {
548 time.front().start = start;
549 time.front().end = end;
554 time.group = track->edit_group();
564 return time.front().id;
568 Selection::set (AutomationList *ac)
575 Selection::selected (TimeAxisView* tv)
577 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
581 Selection::selected (AudioRegionView* arv)
583 return find (audio_regions.begin(), audio_regions.end(), arv) != audio_regions.end();
589 return audio_regions.empty () &&
592 playlists.empty () &&
595 playlists.empty () &&
601 Selection::set (list<Selectable*>& selectables)
603 clear_audio_regions();
609 Selection::add (list<Selectable*>& selectables)
611 AudioRegionView* arv;
612 AutomationSelectable* as;
613 vector<AudioRegionView*> arvs;
614 vector<AutomationSelectable*> autos;
616 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
617 if ((arv = dynamic_cast<AudioRegionView*> (*i)) != 0) {
618 arvs.push_back (arv);
619 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
620 autos.push_back (as);
622 fatal << _("programming error: ")
623 << X_("unknown selectable type passed to Selection::set()")
633 if (!autos.empty()) {
639 Selection::clear_points ()
641 if (!points.empty()) {
648 Selection::add (vector<AutomationSelectable*>& autos)
650 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
651 points.push_back (**i);