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 "region_view.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 regions = other.regions;
50 tracks = other.tracks;
58 operator== (const Selection& a, const Selection& b)
60 return a.regions == b.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;
83 Selection::dump_region_layers()
85 cerr << "region selection layer dump" << endl;
86 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
87 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
93 Selection::clear_redirects ()
95 if (!redirects.empty()) {
102 Selection::clear_regions ()
104 if (!regions.empty()) {
105 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 (const list<TimeAxisView*>& track_list)
185 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
191 Selection::toggle (TimeAxisView* track)
193 TrackSelection::iterator i;
195 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
196 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
197 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
198 tracks.push_back (track);
207 Selection::toggle (RegionView* r)
209 RegionSelection::iterator i;
211 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
221 Selection::toggle (vector<RegionView*>& r)
223 RegionSelection::iterator i;
225 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
226 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
237 Selection::toggle (nframes_t start, nframes_t end)
239 AudioRangeComparator cmp;
241 /* XXX this implementation is incorrect */
243 time.push_back (AudioRange (start, end, next_time_id++));
249 return next_time_id - 1;
254 Selection::add (boost::shared_ptr<Redirect> r)
256 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
257 redirects.push_back (r);
263 Selection::add (Playlist* pl)
265 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
267 playlists.push_back(pl);
273 Selection::add (const list<Playlist*>& pllist)
275 bool changed = false;
277 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
278 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
280 playlists.push_back (*i);
291 Selection::add (const list<TimeAxisView*>& track_list)
293 bool changed = false;
295 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
296 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
297 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
298 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
299 tracks.push_back (*i);
310 Selection::add (TimeAxisView* track)
312 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
313 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
314 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
315 tracks.push_back (track);
321 Selection::add (RegionView* r)
323 if (find (regions.begin(), regions.end(), r) == regions.end()) {
330 Selection::add (vector<RegionView*>& v)
332 bool changed = false;
334 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
335 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
347 Selection::add (nframes_t start, nframes_t end)
349 AudioRangeComparator cmp;
351 /* XXX this implementation is incorrect */
353 time.push_back (AudioRange (start, end, next_time_id++));
359 return next_time_id - 1;
363 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
365 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
366 if ((*i).id == sid) {
368 time.push_back (AudioRange(start,end, sid));
370 /* don't consolidate here */
373 AudioRangeComparator cmp;
383 Selection::add (AutomationList* ac)
385 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
386 lines.push_back (ac);
392 Selection::remove (boost::shared_ptr<Redirect> r)
394 RedirectSelection::iterator i;
395 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
402 Selection::remove (TimeAxisView* track)
404 list<TimeAxisView*>::iterator i;
405 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
412 Selection::remove (const list<TimeAxisView*>& track_list)
414 bool changed = false;
416 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
418 list<TimeAxisView*>::iterator x;
420 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
432 Selection::remove (Playlist* track)
434 list<Playlist*>::iterator i;
435 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
442 Selection::remove (const list<Playlist*>& pllist)
444 bool changed = false;
446 for (list<Playlist*>::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
448 list<Playlist*>::iterator x;
450 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
462 Selection::remove (RegionView* r)
470 Selection::remove (uint32_t selection_id)
476 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
477 if ((*i).id == selection_id) {
487 Selection::remove (nframes_t start, nframes_t end)
492 Selection::remove (AutomationList *ac)
494 list<AutomationList*>::iterator i;
495 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
502 Selection::set (boost::shared_ptr<Redirect> r)
509 Selection::set (TimeAxisView* track)
516 Selection::set (const list<TimeAxisView*>& track_list)
523 Selection::set (Playlist* playlist)
530 Selection::set (const list<Playlist*>& pllist)
537 Selection::set (RegionView* r)
544 Selection::set (vector<RegionView*>& v)
547 // make sure to deselect any automation selections
553 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
555 if ((start == 0 && end == 0) || end < start) {
560 time.push_back (AudioRange (start, end, next_time_id++));
562 /* reuse the first entry, and remove all the rest */
564 while (time.size() > 1) {
567 time.front().start = start;
568 time.front().end = end;
573 time.group = track->edit_group();
583 return time.front().id;
587 Selection::set (AutomationList *ac)
594 Selection::selected (TimeAxisView* tv)
596 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
600 Selection::selected (RegionView* rv)
602 return find (regions.begin(), regions.end(), rv) != regions.end();
608 return regions.empty () &&
611 playlists.empty () &&
614 playlists.empty () &&
620 Selection::set (list<Selectable*>& selectables)
629 Selection::add (list<Selectable*>& selectables)
632 AutomationSelectable* as;
633 vector<RegionView*> rvs;
634 vector<AutomationSelectable*> autos;
636 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
637 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
639 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
640 autos.push_back (as);
642 fatal << _("programming error: ")
643 << X_("unknown selectable type passed to Selection::set()")
653 if (!autos.empty()) {
659 Selection::clear_points ()
661 if (!points.empty()) {
668 Selection::add (vector<AutomationSelectable*>& autos)
670 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
671 points.push_back (**i);