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 (boost::shared_ptr<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 (boost::shared_ptr<Playlist> pl)
265 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
267 playlists.push_back(pl);
273 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
275 bool changed = false;
277 for (list<boost::shared_ptr<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()) {
325 add (&r->get_trackview());
331 Selection::add (vector<RegionView*>& v)
333 bool changed = false;
335 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
336 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
337 changed = regions.add ((*i));
339 add (&(*i)->get_trackview());
350 Selection::add (nframes_t start, nframes_t end)
352 AudioRangeComparator cmp;
354 /* XXX this implementation is incorrect */
356 time.push_back (AudioRange (start, end, next_time_id++));
362 return next_time_id - 1;
366 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
368 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
369 if ((*i).id == sid) {
371 time.push_back (AudioRange(start,end, sid));
373 /* don't consolidate here */
376 AudioRangeComparator cmp;
386 Selection::add (AutomationList* ac)
388 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
389 lines.push_back (ac);
395 Selection::remove (boost::shared_ptr<Redirect> r)
397 RedirectSelection::iterator i;
398 if ((i = find (redirects.begin(), redirects.end(), r)) != redirects.end()) {
405 Selection::remove (TimeAxisView* track)
407 list<TimeAxisView*>::iterator i;
408 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
415 Selection::remove (const list<TimeAxisView*>& track_list)
417 bool changed = false;
419 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
421 list<TimeAxisView*>::iterator x;
423 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
435 Selection::remove (boost::shared_ptr<Playlist> track)
437 list<boost::shared_ptr<Playlist> >::iterator i;
438 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
445 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
447 bool changed = false;
449 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
451 list<boost::shared_ptr<Playlist> >::iterator x;
453 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
465 Selection::remove (RegionView* r)
467 if (regions.remove (r)) {
471 if (!regions.involves (r->get_trackview())) {
472 remove (&r->get_trackview());
478 Selection::remove (uint32_t selection_id)
484 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
485 if ((*i).id == selection_id) {
495 Selection::remove (nframes_t start, nframes_t end)
500 Selection::remove (AutomationList *ac)
502 list<AutomationList*>::iterator i;
503 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
510 Selection::set (boost::shared_ptr<Redirect> r)
517 Selection::set (TimeAxisView* track)
524 Selection::set (const list<TimeAxisView*>& track_list)
531 Selection::set (boost::shared_ptr<Playlist> playlist)
538 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
545 Selection::set (RegionView* r)
553 Selection::set (vector<RegionView*>& v)
557 // make sure to deselect any automation selections
563 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
565 if ((start == 0 && end == 0) || end < start) {
570 time.push_back (AudioRange (start, end, next_time_id++));
572 /* reuse the first entry, and remove all the rest */
574 while (time.size() > 1) {
577 time.front().start = start;
578 time.front().end = end;
583 time.group = track->edit_group();
593 return time.front().id;
597 Selection::set (AutomationList *ac)
604 Selection::selected (TimeAxisView* tv)
606 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
610 Selection::selected (RegionView* rv)
612 return find (regions.begin(), regions.end(), rv) != regions.end();
618 return regions.empty () &&
621 playlists.empty () &&
624 playlists.empty () &&
630 Selection::toggle (const vector<AutomationSelectable*>& autos)
632 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
633 if ((*x)->get_selected()) {
636 points.push_back (**x);
642 PointsChanged (); /* EMIT SIGNAL */
646 Selection::toggle (list<Selectable*>& selectables)
649 AutomationSelectable* as;
650 vector<RegionView*> rvs;
651 vector<AutomationSelectable*> autos;
653 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
654 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
656 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
657 autos.push_back (as);
659 fatal << _("programming error: ")
660 << X_("unknown selectable type passed to Selection::toggle()")
670 if (!autos.empty()) {
676 Selection::set (list<Selectable*>& selectables)
685 Selection::add (list<Selectable*>& selectables)
688 AutomationSelectable* as;
689 vector<RegionView*> rvs;
690 vector<AutomationSelectable*> autos;
692 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
693 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
695 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
696 autos.push_back (as);
698 fatal << _("programming error: ")
699 << X_("unknown selectable type passed to Selection::add()")
709 if (!autos.empty()) {
715 Selection::clear_points ()
717 if (!points.empty()) {
724 Selection::add (vector<AutomationSelectable*>& autos)
726 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
727 points.push_back (**i);