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.
21 #include <sigc++/bind.h>
22 #include <pbd/error.h>
23 #include <pbd/stacktrace.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.processors == b.processors;
70 /** Clear everything from the Selection */
84 Selection::dump_region_layers()
86 cerr << "region selection layer dump" << endl;
87 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
88 cerr << "layer: " << (int)(*i)->region()->layer() << endl;
94 Selection::clear_processors ()
96 if (!processors.empty()) {
103 Selection::clear_regions ()
105 if (!regions.empty()) {
106 regions.clear_all ();
112 Selection::clear_tracks ()
114 if (!tracks.empty()) {
121 Selection::clear_time ()
131 Selection::clear_playlists ()
133 /* Selections own their playlists */
135 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
136 /* selections own their own regions, which are copies of the "originals". make them go away */
137 (*i)->drop_regions ();
141 if (!playlists.empty()) {
148 Selection::clear_lines ()
150 if (!lines.empty()) {
157 Selection::toggle (boost::shared_ptr<Processor> r)
159 ProcessorSelection::iterator i;
161 if ((i = find (processors.begin(), processors.end(), r)) == processors.end()) {
162 processors.push_back (r);
164 processors.erase (i);
171 Selection::toggle (boost::shared_ptr<Playlist> pl)
173 PlaylistSelection::iterator i;
175 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
177 playlists.push_back(pl);
186 Selection::toggle (const list<TimeAxisView*>& track_list)
188 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
194 Selection::toggle (TimeAxisView* track)
196 TrackSelection::iterator i;
198 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
199 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
200 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
201 tracks.push_back (track);
210 Selection::toggle (RegionView* r)
212 RegionSelection::iterator i;
214 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
224 Selection::toggle (vector<RegionView*>& r)
226 RegionSelection::iterator i;
228 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
229 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
240 Selection::toggle (nframes_t start, nframes_t end)
242 AudioRangeComparator cmp;
244 /* XXX this implementation is incorrect */
246 time.push_back (AudioRange (start, end, next_time_id++));
252 return next_time_id - 1;
257 Selection::add (boost::shared_ptr<Processor> i)
259 if (find (processors.begin(), processors.end(), i) == processors.end()) {
260 processors.push_back (i);
266 Selection::add (boost::shared_ptr<Playlist> pl)
268 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
270 playlists.push_back(pl);
276 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
278 bool changed = false;
280 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
281 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
283 playlists.push_back (*i);
294 Selection::add (const list<TimeAxisView*>& track_list)
296 bool changed = false;
298 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
299 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
300 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
301 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
302 tracks.push_back (*i);
313 Selection::add (TimeAxisView* track)
315 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
316 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
317 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
318 tracks.push_back (track);
324 Selection::add (RegionView* r)
326 if (find (regions.begin(), regions.end(), r) == regions.end()) {
328 add (&r->get_trackview());
334 Selection::add (vector<RegionView*>& v)
336 bool changed = false;
338 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
339 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
340 changed = regions.add ((*i));
342 add (&(*i)->get_trackview());
353 Selection::add (nframes_t start, nframes_t end)
355 AudioRangeComparator cmp;
357 /* XXX this implementation is incorrect */
359 time.push_back (AudioRange (start, end, next_time_id++));
365 return next_time_id - 1;
369 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
371 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
372 if ((*i).id == sid) {
374 time.push_back (AudioRange(start,end, sid));
376 /* don't consolidate here */
379 AudioRangeComparator cmp;
389 Selection::add (AutomationList* ac)
391 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
392 lines.push_back (ac);
398 Selection::remove (boost::shared_ptr<Processor> r)
400 ProcessorSelection::iterator i;
401 if ((i = find (processors.begin(), processors.end(), r)) != processors.end()) {
402 processors.erase (i);
403 ProcessorsChanged ();
408 Selection::remove (TimeAxisView* track)
410 list<TimeAxisView*>::iterator i;
411 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
418 Selection::remove (const list<TimeAxisView*>& track_list)
420 bool changed = false;
422 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
424 list<TimeAxisView*>::iterator x;
426 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
438 Selection::remove (boost::shared_ptr<Playlist> track)
440 list<boost::shared_ptr<Playlist> >::iterator i;
441 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
448 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
450 bool changed = false;
452 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
454 list<boost::shared_ptr<Playlist> >::iterator x;
456 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
468 Selection::remove (RegionView* r)
470 if (regions.remove (r)) {
474 if (!regions.involves (r->get_trackview())) {
475 remove (&r->get_trackview());
481 Selection::remove (uint32_t selection_id)
487 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
488 if ((*i).id == selection_id) {
498 Selection::remove (nframes_t start, nframes_t end)
503 Selection::remove (AutomationList *ac)
505 list<AutomationList*>::iterator i;
506 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
513 Selection::set (boost::shared_ptr<Processor> i)
520 Selection::set (TimeAxisView* track)
527 Selection::set (const list<TimeAxisView*>& track_list)
534 Selection::set (boost::shared_ptr<Playlist> playlist)
541 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
548 Selection::set (RegionView* r)
556 Selection::set (vector<RegionView*>& v)
560 // make sure to deselect any automation selections
566 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
568 if ((start == 0 && end == 0) || end < start) {
573 time.push_back (AudioRange (start, end, next_time_id++));
575 /* reuse the first entry, and remove all the rest */
577 while (time.size() > 1) {
580 time.front().start = start;
581 time.front().end = end;
586 time.group = track->edit_group();
596 return time.front().id;
600 Selection::set (AutomationList *ac)
607 Selection::selected (TimeAxisView* tv)
609 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
613 Selection::selected (RegionView* rv)
615 return find (regions.begin(), regions.end(), rv) != regions.end();
621 return regions.empty () &&
624 playlists.empty () &&
627 playlists.empty () &&
633 Selection::toggle (const vector<AutomationSelectable*>& autos)
635 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
636 if ((*x)->get_selected()) {
639 points.push_back (**x);
645 PointsChanged (); /* EMIT SIGNAL */
649 Selection::toggle (list<Selectable*>& selectables)
652 AutomationSelectable* as;
653 vector<RegionView*> rvs;
654 vector<AutomationSelectable*> autos;
656 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
657 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
659 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
660 autos.push_back (as);
662 fatal << _("programming error: ")
663 << X_("unknown selectable type passed to Selection::toggle()")
673 if (!autos.empty()) {
679 Selection::set (list<Selectable*>& selectables)
688 Selection::add (list<Selectable*>& selectables)
691 AutomationSelectable* as;
692 vector<RegionView*> rvs;
693 vector<AutomationSelectable*> autos;
695 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
696 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
698 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
699 autos.push_back (as);
701 fatal << _("programming error: ")
702 << X_("unknown selectable type passed to Selection::add()")
712 if (!autos.empty()) {
718 Selection::clear_points ()
720 if (!points.empty()) {
727 Selection::add (vector<AutomationSelectable*>& autos)
729 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
730 points.push_back (**i);