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;
39 struct AudioRangeComparator {
40 bool operator()(AudioRange a, AudioRange b) {
41 return a.start < b.start;
46 Selection::operator= (const Selection& other)
49 audio_regions = other.audio_regions;
50 tracks = other.tracks;
58 operator== (const Selection& a, const Selection& b)
60 return a.audio_regions == b.audio_regions &&
61 a.tracks == b.tracks &&
62 a.time.track == b.time.track &&
63 a.time.group == b.time.group &&
66 a.playlists == b.playlists &&
67 a.redirects == b.redirects;
74 clear_audio_regions ();
83 Selection::dump_region_layers()
85 cerr << "region selection layer dump" << endl;
86 for (AudioRegionSelection::iterator i = audio_regions.begin(); i != audio_regions.end(); ++i) {
87 cerr << "layer: " << (int)(*i)->region.layer() << endl;
93 Selection::clear_redirects ()
95 if (!redirects.empty()) {
102 Selection::clear_audio_regions ()
104 if (!audio_regions.empty()) {
105 audio_regions.clear_all ();
111 Selection::clear_tracks ()
113 if (!tracks.empty()) {
120 Selection::clear_time ()
130 Selection::clear_playlists ()
132 /* Selections own their playlists */
134 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
138 if (!playlists.empty()) {
145 Selection::clear_lines ()
147 if (!lines.empty()) {
154 Selection::toggle (boost::shared_ptr<Redirect> r)
156 RedirectSelection::iterator i;
158 if ((i = find (redirects.begin(), redirects.end(), r)) == redirects.end()) {
159 redirects.push_back (r);
168 Selection::toggle (Playlist* pl)
170 PlaylistSelection::iterator i;
172 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
174 playlists.push_back(pl);
183 Selection::toggle (TimeAxisView* track)
185 TrackSelection::iterator i;
187 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
188 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
189 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
190 tracks.push_back (track);
199 Selection::toggle (AudioRegionView* r)
201 AudioRegionSelection::iterator i;
203 if ((i = find (audio_regions.begin(), audio_regions.end(), r)) == audio_regions.end()) {
204 audio_regions.add (r);
206 audio_regions.erase (i);
213 Selection::toggle (vector<AudioRegionView*>& r)
215 AudioRegionSelection::iterator i;
217 for (vector<AudioRegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
218 if ((i = find (audio_regions.begin(), audio_regions.end(), (*x))) == audio_regions.end()) {
219 audio_regions.add ((*x));
221 audio_regions.erase (i);
229 Selection::toggle (jack_nframes_t start, jack_nframes_t end)
231 AudioRangeComparator cmp;
233 /* XXX this implementation is incorrect */
235 time.push_back (AudioRange (start, end, next_time_id++));
241 return next_time_id - 1;
246 Selection::add (boost::shared_ptr<Redirect> r)
248 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
249 redirects.push_back (r);
255 Selection::add (Playlist* pl)
257 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
259 playlists.push_back(pl);
265 Selection::add (const list<Playlist*>& pllist)
267 bool changed = false;
269 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
270 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
272 playlists.push_back (*i);
283 Selection::add (const list<TimeAxisView*>& track_list)
285 bool changed = false;
287 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
288 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
289 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
290 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
291 tracks.push_back (*i);
302 Selection::add (TimeAxisView* track)
304 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
305 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
306 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
307 tracks.push_back (track);
313 Selection::add (AudioRegionView* r)
315 if (find (audio_regions.begin(), audio_regions.end(), r) == audio_regions.end()) {
316 audio_regions.add (r);
322 Selection::add (vector<AudioRegionView*>& v)
324 bool changed = false;
326 for (vector<AudioRegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
327 if (find (audio_regions.begin(), audio_regions.end(), (*i)) == audio_regions.end()) {
328 audio_regions.add ((*i));
339 Selection::add (jack_nframes_t start, jack_nframes_t end)
341 AudioRangeComparator cmp;
343 /* XXX this implementation is incorrect */
345 time.push_back (AudioRange (start, end, next_time_id++));
351 return next_time_id - 1;
355 Selection::replace (uint32_t sid, jack_nframes_t start, jack_nframes_t end)
357 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
358 if ((*i).id == sid) {
360 time.push_back (AudioRange(start,end, sid));
362 /* don't consolidate here */
365 AudioRangeComparator cmp;
375 Selection::add (AutomationList* ac)
377 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
378 lines.push_back (ac);
384 Selection::remove (boost::shared_ptr<Redirect> r)
386 RedirectSelection::iterator i;
387 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
394 Selection::remove (TimeAxisView* track)
396 list<TimeAxisView*>::iterator i;
397 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
404 Selection::remove (const list<TimeAxisView*>& track_list)
406 bool changed = false;
408 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
410 list<TimeAxisView*>::iterator x;
412 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
424 Selection::remove (Playlist* track)
426 list<Playlist*>::iterator i;
427 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
434 Selection::remove (const list<Playlist*>& pllist)
436 bool changed = false;
438 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
440 list<Playlist*>::iterator x;
442 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
454 Selection::remove (AudioRegionView* r)
456 audio_regions.remove (r);
462 Selection::remove (uint32_t selection_id)
468 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
469 if ((*i).id == selection_id) {
479 Selection::remove (jack_nframes_t start, jack_nframes_t end)
484 Selection::remove (AutomationList *ac)
486 list<AutomationList*>::iterator i;
487 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
494 Selection::set (boost::shared_ptr<Redirect> r)
501 Selection::set (TimeAxisView* track)
508 Selection::set (const list<TimeAxisView*>& track_list)
515 Selection::set (Playlist* playlist)
522 Selection::set (const list<Playlist*>& pllist)
529 Selection::set (AudioRegionView* r)
531 clear_audio_regions ();
536 Selection::set (vector<AudioRegionView*>& v)
539 clear_audio_regions ();
540 // make sure to deselect any automation selections
546 Selection::set (TimeAxisView* track, jack_nframes_t start, jack_nframes_t end)
548 if ((start == 0 && end == 0) || end < start) {
553 time.push_back (AudioRange (start, end, next_time_id++));
555 /* reuse the first entry, and remove all the rest */
557 while (time.size() > 1) {
560 time.front().start = start;
561 time.front().end = end;
566 time.group = track->edit_group();
576 return time.front().id;
580 Selection::set (AutomationList *ac)
587 Selection::selected (TimeAxisView* tv)
589 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
593 Selection::selected (AudioRegionView* arv)
595 return find (audio_regions.begin(), audio_regions.end(), arv) != audio_regions.end();
601 return audio_regions.empty () &&
604 playlists.empty () &&
607 playlists.empty () &&
613 Selection::set (list<Selectable*>& selectables)
615 clear_audio_regions();
621 Selection::add (list<Selectable*>& selectables)
623 AudioRegionView* arv;
624 AutomationSelectable* as;
625 vector<AudioRegionView*> arvs;
626 vector<AutomationSelectable*> autos;
628 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
629 if ((arv = dynamic_cast<AudioRegionView*> (*i)) != 0) {
630 arvs.push_back (arv);
631 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
632 autos.push_back (as);
634 fatal << _("programming error: ")
635 << X_("unknown selectable type passed to Selection::set()")
645 if (!autos.empty()) {
651 Selection::clear_points ()
653 if (!points.empty()) {
660 Selection::add (vector<AutomationSelectable*>& autos)
662 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
663 points.push_back (**i);