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.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) {
135 /* selections own their own regions, which are copies of the "originals". make them go away */
136 (*i)->drop_regions ();
140 if (!playlists.empty()) {
147 Selection::clear_lines ()
149 if (!lines.empty()) {
156 Selection::toggle (boost::shared_ptr<Redirect> r)
158 RedirectSelection::iterator i;
160 if ((i = find (redirects.begin(), redirects.end(), r)) == redirects.end()) {
161 redirects.push_back (r);
170 Selection::toggle (boost::shared_ptr<Playlist> pl)
172 PlaylistSelection::iterator i;
174 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
176 playlists.push_back(pl);
185 Selection::toggle (const list<TimeAxisView*>& track_list)
187 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
193 Selection::toggle (TimeAxisView* track)
195 TrackSelection::iterator i;
197 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
198 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
199 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
200 tracks.push_back (track);
209 Selection::toggle (RegionView* r)
211 RegionSelection::iterator i;
213 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
223 Selection::toggle (vector<RegionView*>& r)
225 RegionSelection::iterator i;
227 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
228 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
239 Selection::toggle (nframes_t start, nframes_t end)
241 AudioRangeComparator cmp;
243 /* XXX this implementation is incorrect */
245 time.push_back (AudioRange (start, end, next_time_id++));
251 return next_time_id - 1;
256 Selection::add (boost::shared_ptr<Redirect> r)
258 if (find (redirects.begin(), redirects.end(), r) == redirects.end()) {
259 redirects.push_back (r);
265 Selection::add (boost::shared_ptr<Playlist> pl)
267 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
269 playlists.push_back(pl);
275 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
277 bool changed = false;
279 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
280 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
282 playlists.push_back (*i);
293 Selection::add (const list<TimeAxisView*>& track_list)
295 bool changed = false;
297 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
298 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
299 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
300 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
301 tracks.push_back (*i);
312 Selection::add (TimeAxisView* track)
314 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
315 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
316 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
317 tracks.push_back (track);
323 Selection::add (RegionView* r)
325 if (find (regions.begin(), regions.end(), r) == regions.end()) {
327 add (&r->get_trackview());
333 Selection::add (vector<RegionView*>& v)
335 bool changed = false;
337 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
338 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
339 changed = regions.add ((*i));
341 add (&(*i)->get_trackview());
352 Selection::add (nframes_t start, nframes_t end)
354 AudioRangeComparator cmp;
356 /* XXX this implementation is incorrect */
358 time.push_back (AudioRange (start, end, next_time_id++));
364 return next_time_id - 1;
368 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
370 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
371 if ((*i).id == sid) {
373 time.push_back (AudioRange(start,end, sid));
375 /* don't consolidate here */
378 AudioRangeComparator cmp;
388 Selection::add (AutomationList* ac)
390 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
391 lines.push_back (ac);
397 Selection::remove (boost::shared_ptr<Redirect> r)
399 RedirectSelection::iterator i;
400 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
407 Selection::remove (TimeAxisView* track)
409 list<TimeAxisView*>::iterator i;
410 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
417 Selection::remove (const list<TimeAxisView*>& track_list)
419 bool changed = false;
421 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
423 list<TimeAxisView*>::iterator x;
425 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
437 Selection::remove (boost::shared_ptr<Playlist> track)
439 list<boost::shared_ptr<Playlist> >::iterator i;
440 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
447 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
449 bool changed = false;
451 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
453 list<boost::shared_ptr<Playlist> >::iterator x;
455 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
467 Selection::remove (RegionView* r)
469 if (regions.remove (r)) {
473 if (!regions.involves (r->get_trackview())) {
474 remove (&r->get_trackview());
480 Selection::remove (uint32_t selection_id)
486 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
487 if ((*i).id == selection_id) {
497 Selection::remove (nframes_t start, nframes_t end)
502 Selection::remove (AutomationList *ac)
504 list<AutomationList*>::iterator i;
505 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
512 Selection::set (boost::shared_ptr<Redirect> r)
519 Selection::set (TimeAxisView* track)
526 Selection::set (const list<TimeAxisView*>& track_list)
533 Selection::set (boost::shared_ptr<Playlist> playlist)
540 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
547 Selection::set (RegionView* r)
555 Selection::set (vector<RegionView*>& v)
559 // make sure to deselect any automation selections
565 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
567 if ((start == 0 && end == 0) || end < start) {
572 time.push_back (AudioRange (start, end, next_time_id++));
574 /* reuse the first entry, and remove all the rest */
576 while (time.size() > 1) {
579 time.front().start = start;
580 time.front().end = end;
585 time.group = track->edit_group();
595 return time.front().id;
599 Selection::set (AutomationList *ac)
606 Selection::selected (TimeAxisView* tv)
608 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
612 Selection::selected (RegionView* rv)
614 return find (regions.begin(), regions.end(), rv) != regions.end();
620 return regions.empty () &&
623 playlists.empty () &&
626 playlists.empty () &&
632 Selection::toggle (const vector<AutomationSelectable*>& autos)
634 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
635 if ((*x)->get_selected()) {
638 points.push_back (**x);
644 PointsChanged (); /* EMIT SIGNAL */
648 Selection::toggle (list<Selectable*>& selectables)
651 AutomationSelectable* as;
652 vector<RegionView*> rvs;
653 vector<AutomationSelectable*> autos;
655 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
656 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
658 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
659 autos.push_back (as);
661 fatal << _("programming error: ")
662 << X_("unknown selectable type passed to Selection::toggle()")
672 if (!autos.empty()) {
678 Selection::set (list<Selectable*>& selectables)
687 Selection::add (list<Selectable*>& selectables)
690 AutomationSelectable* as;
691 vector<RegionView*> rvs;
692 vector<AutomationSelectable*> autos;
694 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
695 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
697 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
698 autos.push_back (as);
700 fatal << _("programming error: ")
701 << X_("unknown selectable type passed to Selection::add()")
711 if (!autos.empty()) {
717 Selection::clear_points ()
719 if (!points.empty()) {
726 Selection::add (vector<AutomationSelectable*>& autos)
728 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
729 points.push_back (**i);