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 (vector<RegionView*>& v)
301 /* XXX This method or the add (const RegionSelection&) needs to go
304 bool changed = false;
306 for (vector<RegionView*>::iterator i = v.begin(); i != v.end(); ++i) {
307 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
308 changed = regions.add ((*i));
309 if (Config->get_link_region_and_track_selection() && changed) {
310 add (&(*i)->get_trackview());
321 Selection::add (const RegionSelection& rs)
323 /* XXX This method or the add (const vector<RegionView*>&) needs to go
326 bool changed = false;
328 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
329 if (find (regions.begin(), regions.end(), (*i)) == regions.end()) {
330 changed = regions.add ((*i));
331 if (Config->get_link_region_and_track_selection() && changed) {
332 add (&(*i)->get_trackview());
338 select_edit_group_regions ();
344 Selection::add (RegionView* r)
346 if (find (regions.begin(), regions.end(), r) == regions.end()) {
348 if (Config->get_link_region_and_track_selection()) {
349 add (&r->get_trackview());
356 Selection::add (nframes_t start, nframes_t end)
358 AudioRangeComparator cmp;
360 /* XXX this implementation is incorrect */
362 time.push_back (AudioRange (start, end, next_time_id++));
368 return next_time_id - 1;
372 Selection::replace (uint32_t sid, nframes_t start, nframes_t end)
374 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
375 if ((*i).id == sid) {
377 time.push_back (AudioRange(start,end, sid));
379 /* don't consolidate here */
382 AudioRangeComparator cmp;
392 Selection::add (AutomationList* ac)
394 if (find (lines.begin(), lines.end(), ac) == lines.end()) {
395 lines.push_back (ac);
401 Selection::remove (TimeAxisView* track)
403 list<TimeAxisView*>::iterator i;
404 if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
411 Selection::remove (const list<TimeAxisView*>& track_list)
413 bool changed = false;
415 for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
417 list<TimeAxisView*>::iterator x;
419 if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
431 Selection::remove (boost::shared_ptr<Playlist> track)
433 list<boost::shared_ptr<Playlist> >::iterator i;
434 if ((i = find (playlists.begin(), playlists.end(), track)) != playlists.end()) {
441 Selection::remove (const list<boost::shared_ptr<Playlist> >& pllist)
443 bool changed = false;
445 for (list<boost::shared_ptr<Playlist> >::const_iterator i = pllist.begin(); i != pllist.end(); ++i) {
447 list<boost::shared_ptr<Playlist> >::iterator x;
449 if ((x = find (playlists.begin(), playlists.end(), (*i))) != playlists.end()) {
461 Selection::remove (RegionView* r)
463 if (regions.remove (r)) {
467 if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
468 remove (&r->get_trackview());
474 Selection::remove (uint32_t selection_id)
480 for (list<AudioRange>::iterator i = time.begin(); i != time.end(); ++i) {
481 if ((*i).id == selection_id) {
491 Selection::remove (nframes_t start, nframes_t end)
496 Selection::remove (AutomationList *ac)
498 list<AutomationList*>::iterator i;
499 if ((i = find (lines.begin(), lines.end(), ac)) != lines.end()) {
506 Selection::set (TimeAxisView* track)
513 Selection::set (const list<TimeAxisView*>& track_list)
520 Selection::set (boost::shared_ptr<Playlist> playlist)
527 Selection::set (const list<boost::shared_ptr<Playlist> >& pllist)
534 Selection::set (const RegionSelection& rs)
538 RegionsChanged(); /* EMIT SIGNAL */
542 Selection::set (RegionView* r, bool also_clear_tracks)
545 if (also_clear_tracks) {
552 Selection::set (vector<RegionView*>& v)
555 if (Config->get_link_region_and_track_selection()) {
557 // make sure to deselect any automation selections
564 Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
566 if ((start == 0 && end == 0) || end < start) {
571 time.push_back (AudioRange (start, end, next_time_id++));
573 /* reuse the first entry, and remove all the rest */
575 while (time.size() > 1) {
578 time.front().start = start;
579 time.front().end = end;
584 time.group = track->edit_group();
594 return time.front().id;
598 Selection::set (AutomationList *ac)
605 Selection::selected (TimeAxisView* tv)
607 return find (tracks.begin(), tracks.end(), tv) != tracks.end();
611 Selection::selected (RegionView* rv)
613 return find (regions.begin(), regions.end(), rv) != regions.end();
619 return regions.empty () &&
622 playlists.empty () &&
625 playlists.empty () &&
631 Selection::toggle (const vector<AutomationSelectable*>& autos)
633 for (vector<AutomationSelectable*>::const_iterator x = autos.begin(); x != autos.end(); ++x) {
634 if ((*x)->get_selected()) {
637 points.push_back (**x);
643 PointsChanged (); /* EMIT SIGNAL */
647 Selection::toggle (list<Selectable*>& selectables)
650 AutomationSelectable* as;
651 vector<RegionView*> rvs;
652 vector<AutomationSelectable*> autos;
654 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
655 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
657 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
658 autos.push_back (as);
660 fatal << _("programming error: ")
661 << X_("unknown selectable type passed to Selection::toggle()")
671 if (!autos.empty()) {
677 Selection::set (list<Selectable*>& selectables)
686 Selection::add (list<Selectable*>& selectables)
689 AutomationSelectable* as;
690 vector<RegionView*> rvs;
691 vector<AutomationSelectable*> autos;
693 for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
694 if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
696 } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
697 autos.push_back (as);
699 fatal << _("programming error: ")
700 << X_("unknown selectable type passed to Selection::add()")
710 if (!autos.empty()) {
716 Selection::clear_points ()
718 if (!points.empty()) {
725 Selection::add (vector<AutomationSelectable*>& autos)
727 for (vector<AutomationSelectable*>::iterator i = autos.begin(); i != autos.end(); ++i) {
728 points.push_back (**i);
735 Selection::select_edit_group_regions ()
737 std::set<RegionView*> regions_to_add;
739 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
740 vector<RegionView*> e;
741 editor->get_equivalent_regions (*i, e);
742 for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
743 regions_to_add.insert(*j);
747 for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
753 Selection::set (Marker* m)
760 Selection::toggle (Marker* m)
762 MarkerSelection::iterator i;
764 if ((i = find (markers.begin(), markers.end(), m)) == markers.end()) {
772 Selection::remove (Marker* m)
774 MarkerSelection::iterator i;
776 if ((i = find (markers.begin(), markers.end(), m)) != markers.end()) {
783 Selection::add (Marker* m)
785 if (find (markers.begin(), markers.end(), m) == markers.end()) {
787 /* disambiguate which remove() for the compiler */
789 void (Selection::*pmf)(Marker*) = &Selection::remove;
791 m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
793 markers.push_back (m);