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"
32 #include "public_editor.h"
36 using namespace ARDOUR;
40 struct AudioRangeComparator {
41 bool operator()(AudioRange a, AudioRange b) {
42 return a.start < b.start;
47 Selection::operator= (const Selection& other)
50 regions = other.regions;
51 tracks = other.tracks;
59 operator== (const Selection& a, const Selection& b)
61 return a.regions == b.regions &&
62 a.tracks == b.tracks &&
63 a.time.track == b.time.track &&
64 a.time.group == b.time.group &&
67 a.playlists == b.playlists;
70 /** Clear everything from the Selection */
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_regions ()
95 if (!regions.empty()) {
102 Selection::clear_tracks ()
104 if (!tracks.empty()) {
111 Selection::clear_time ()
121 Selection::clear_playlists ()
123 /* Selections own their playlists */
125 for (PlaylistSelection::iterator i = playlists.begin(); i != playlists.end(); ++i) {
126 /* selections own their own regions, which are copies of the "originals". make them go away */
127 (*i)->drop_regions ();
131 if (!playlists.empty()) {
138 Selection::clear_lines ()
140 if (!lines.empty()) {
147 Selection::clear_markers ()
149 if (!markers.empty()) {
156 Selection::toggle (boost::shared_ptr<Playlist> pl)
158 PlaylistSelection::iterator i;
160 if ((i = find (playlists.begin(), playlists.end(), pl)) == playlists.end()) {
162 playlists.push_back(pl);
171 Selection::toggle (const list<TimeAxisView*>& track_list)
173 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
179 Selection::toggle (TimeAxisView* track)
181 TrackSelection::iterator i;
183 if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
184 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
185 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
186 tracks.push_back (track);
195 Selection::toggle (RegionView* r)
197 RegionSelection::iterator i;
199 if ((i = find (regions.begin(), regions.end(), r)) == regions.end()) {
209 Selection::toggle (vector<RegionView*>& r)
211 RegionSelection::iterator i;
213 for (vector<RegionView*>::iterator x = r.begin(); x != r.end(); ++x) {
214 if ((i = find (regions.begin(), regions.end(), (*x))) == regions.end()) {
225 Selection::toggle (nframes_t start, nframes_t end)
227 AudioRangeComparator cmp;
229 /* XXX this implementation is incorrect */
231 time.push_back (AudioRange (start, end, next_time_id++));
237 return next_time_id - 1;
241 Selection::add (boost::shared_ptr<Playlist> pl)
243 if (find (playlists.begin(), playlists.end(), pl) == playlists.end()) {
245 playlists.push_back(pl);
251 Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
253 bool changed = false;
255 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
256 if (find (playlists.begin(), playlists.end(), (*i)) == playlists.end()) {
258 playlists.push_back (*i);
269 Selection::add (const list<TimeAxisView*>& track_list)
271 bool changed = false;
273 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
274 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
275 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
276 (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
277 tracks.push_back (*i);
288 Selection::add (TimeAxisView* track)
290 if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
291 void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
292 track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
293 tracks.push_back (track);
299 Selection::add (const RegionSelection& rs)
302 regions.insert (regions.end(), rs.begin(), rs.end());
303 RegionsChanged(); /* EMIT SIGNAL */
308 Selection::add (RegionView* r)
310 if (find (regions.begin(), regions.end(), r) == regions.end()) {
312 if (Config->get_link_region_and_track_selection()) {
313 add (&r->get_trackview());
320 Selection::add (vector<RegionView*>& v)
322 bool changed = false;
324 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
325 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
326 changed = regions.add ((*i));
327 if (Config->get_link_region_and_track_selection() && changed) {
328 add (&(*i)->get_trackview());
334 select_edit_group_regions ();
340 Selection::add (nframes_t start, nframes_t end)
342 AudioRangeComparator cmp;
344 /* XXX this implementation is incorrect */
346 time.push_back (AudioRange (start, end, next_time_id++));
352 return next_time_id - 1;
356 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
358 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
359 if ((*i).id == sid) {
361 time.push_back (AudioRange(start,end, sid));
363 /* don't consolidate here */
366 AudioRangeComparator cmp;
376 Selection::add (AutomationList* ac)
378 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
379 lines.push_back (ac);
385 Selection::remove (TimeAxisView* track)
387 list<TimeAxisView*>::iterator i;
388 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
395 Selection::remove (const list<TimeAxisView*>& track_list)
397 bool changed = false;
399 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
401 list<TimeAxisView*>::iterator x;
403 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
415 Selection::remove (boost::shared_ptr<Playlist> track)
417 list<boost::shared_ptr<Playlist> >::iterator i;
418 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
425 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
427 bool changed = false;
429 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
431 list<boost::shared_ptr<Playlist> >::iterator x;
433 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
445 Selection::remove (RegionView* r)
447 if (regions.remove (r)) {
451 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
452 remove (&r->get_trackview());
458 Selection::remove (uint32_t selection_id)
464 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
465 if ((*i).id == selection_id) {
475 Selection::remove (nframes_t start, nframes_t end)
480 Selection::remove (AutomationList *ac)
482 list<AutomationList*>::iterator i;
483 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
490 Selection::set (TimeAxisView* track)
497 Selection::set (const list<TimeAxisView*>& track_list)
504 Selection::set (boost::shared_ptr<Playlist> playlist)
511 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
518 Selection::set (const RegionSelection& rs)
522 RegionsChanged(); /* EMIT SIGNAL */
526 Selection::set (RegionView* r, bool also_clear_tracks)
529 if (also_clear_tracks) {
536 Selection::set (vector<RegionView*>& v)
539 if (Config->get_link_region_and_track_selection()) {
541 // make sure to deselect any automation selections
548 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
550 if ((start == 0 && end == 0) || end < start) {
555 time.push_back (AudioRange (start, end, next_time_id++));
557 /* reuse the first entry, and remove all the rest */
559 while (time.size() > 1) {
562 time.front().start = start;
563 time.front().end = end;
568 time.group = track->edit_group();
578 return time.front().id;
582 Selection::set (AutomationList *ac)
589 Selection::selected (TimeAxisView* tv)
591 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
595 Selection::selected (RegionView* rv)
597 return find (regions.begin(), regions.end(), rv) != regions.end();
603 return regions.empty () &&
606 playlists.empty () &&
609 playlists.empty () &&
615 Selection::toggle (const vector<AutomationSelectable*>& autos)
617 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
618 if ((*x)->get_selected()) {
621 points.push_back (**x);
627 PointsChanged (); /* EMIT SIGNAL */
631 Selection::toggle (list<Selectable*>& selectables)
634 AutomationSelectable* as;
635 vector<RegionView*> rvs;
636 vector<AutomationSelectable*> autos;
638 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
639 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
641 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
642 autos.push_back (as);
644 fatal << _("programming error: ")
645 << X_("unknown selectable type passed to Selection::toggle()")
655 if (!autos.empty()) {
661 Selection::set (list<Selectable*>& selectables)
670 Selection::add (list<Selectable*>& selectables)
673 AutomationSelectable* as;
674 vector<RegionView*> rvs;
675 vector<AutomationSelectable*> autos;
677 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
678 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
680 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
681 autos.push_back (as);
683 fatal << _("programming error: ")
684 << X_("unknown selectable type passed to Selection::add()")
694 if (!autos.empty()) {
700 Selection::clear_points ()
702 if (!points.empty()) {
709 Selection::add (vector<AutomationSelectable*>& autos)
711 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
712 points.push_back (**i);
719 Selection::select_edit_group_regions ()
721 std::set<RegionView*> regions_to_add;
723 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
724 vector<RegionView*> e;
725 editor->get_equivalent_regions (*i, e);
726 for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
727 regions_to_add.insert(*j);
731 for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
737 Selection::set (Marker* m)
744 Selection::toggle (Marker* m)
746 MarkerSelection::iterator i;
748 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
756 Selection::remove (Marker* m)
758 MarkerSelection::iterator i;
760 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
767 Selection::add (Marker* m)
769 if (find (markers.begin(), markers.end(), m) == markers.end()) {
771 /* disambiguate which remove() for the compiler */
773 void (Selection::*pmf)(Marker*) = &Selection::remove;
775 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
777 markers.push_back (m);