Relent a bit and make adding a route to a group which already contains that group...
[ardour.git] / gtk2_ardour / selection.cc
index c16c913658dd6984739da8d67b9f5a99dfa241dd..a7658ed2b9ab358e08743789bd3ebdeb83305742 100644 (file)
@@ -25,6 +25,7 @@
 #include "ardour/playlist.h"
 #include "ardour/rc_configuration.h"
 
+#include "gui_thread.h"
 #include "midi_cut_buffer.h"
 #include "region_view.h"
 #include "selection.h"
@@ -38,7 +39,6 @@
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
-using namespace sigc;
 
 struct AudioRangeComparator {
     bool operator()(AudioRange a, AudioRange b) {
@@ -46,6 +46,23 @@ struct AudioRangeComparator {
     }
 };
 
+Selection::Selection (const PublicEditor* e)
+       : tracks (e)
+       , editor (e)
+       , next_time_id (0) 
+{
+       clear ();
+
+       /* we have disambiguate which remove() for the compiler */
+
+       void (Selection::*track_remove)(TimeAxisView*) = &Selection::remove;
+       TimeAxisView::CatchDeletion.connect (*this, ui_bind (track_remove, this, _1), gui_context());
+
+       void (Selection::*marker_remove)(Marker*) = &Selection::remove;
+       Marker::CatchDeletion.connect (*this, ui_bind (marker_remove, this, _1), gui_context());
+}      
+
+#if 0
 Selection&
 Selection::operator= (const Selection& other)
 {
@@ -59,14 +76,13 @@ Selection::operator= (const Selection& other)
        }
        return *this;
 }
+#endif
 
 bool
 operator== (const Selection& a, const Selection& b)
 {
        return a.regions == b.regions &&
                a.tracks == b.tracks &&
-               a.time.track == b.time.track &&
-               a.time.group == b.time.group &&
                a.time == b.time &&
                a.lines == b.lines &&
                a.playlists == b.playlists &&
@@ -140,8 +156,6 @@ Selection::clear_midi_regions ()
 void
 Selection::clear_time ()
 {
-       time.track = 0;
-       time.group = 0;
        time.clear();
 
        TimeChanged ();
@@ -198,9 +212,9 @@ Selection::toggle (boost::shared_ptr<Playlist> pl)
 }
 
 void
-Selection::toggle (const list<TimeAxisView*>& track_list)
+Selection::toggle (const TrackViewList& track_list)
 {
-       for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
+       for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
                toggle ((*i));
        }
 }
@@ -211,8 +225,6 @@ Selection::toggle (TimeAxisView* track)
        TrackSelection::iterator i;
 
        if ((i = find (tracks.begin(), tracks.end(), track)) == tracks.end()) {
-               void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
-               track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
                tracks.push_back (track);
        } else {
                tracks.erase (i);
@@ -335,14 +347,9 @@ Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
 }
 
 void
-Selection::add (const list<TimeAxisView*>& track_list)
+Selection::add (const TrackViewList& track_list)
 {
-       list<TimeAxisView*> added = tracks.add (track_list);
-
-       for (list<TimeAxisView*>::const_iterator i = added.begin(); i != added.end(); ++i) {
-               void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
-               (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
-       }
+       TrackViewList added = tracks.add (track_list);
 
        if (!added.empty()) {
                TracksChanged ();
@@ -352,12 +359,9 @@ Selection::add (const list<TimeAxisView*>& track_list)
 void
 Selection::add (TimeAxisView* track)
 {
-       if (find (tracks.begin(), tracks.end(), track) == tracks.end()) {
-               void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
-               track->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), track));
-               tracks.push_back (track);
-               TracksChanged();
-       }
+       TrackViewList tr;
+       tr.push_back (track);
+       add (tr);
 }
 
 void
@@ -517,15 +521,14 @@ Selection::remove (TimeAxisView* track)
 }
 
 void
-Selection::remove (const list<TimeAxisView*>& track_list)
+Selection::remove (const TrackViewList& track_list)
 {
        bool changed = false;
 
-       for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
-
-               list<TimeAxisView*>::iterator x;
+       for (TrackViewList::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
 
-               if ((x = find (tracks.begin(), tracks.end(), (*i))) != tracks.end()) {
+               TrackViewList::iterator x = find (tracks.begin(), tracks.end(), *i);
+               if (x != tracks.end()) {
                        tracks.erase (x);
                        changed = true;
                }
@@ -670,7 +673,7 @@ Selection::set (TimeAxisView* track)
 }
 
 void
-Selection::set (const list<TimeAxisView*>& track_list)
+Selection::set (const TrackViewList& track_list)
 {
        clear_tracks ();
        add (track_list);
@@ -734,8 +737,11 @@ Selection::set (vector<RegionView*>& v)
        add (v);
 }
 
+/** Set the start and end time of the time selection, without changing
+ *  the list of tracks it applies to.
+ */
 long
-Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
+Selection::set (nframes_t start, nframes_t end)
 {
        if ((start == 0 && end == 0) || end < start) {
                return 0;
@@ -753,14 +759,6 @@ Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
                time.front().end = end;
        }
 
-       if (track) {
-               time.track = track;
-               time.group = track->route_group();
-       } else {
-               time.track = 0;
-               time.group = 0;
-       }
-
        time.consolidate ();
 
        TimeChanged ();
@@ -835,14 +833,14 @@ Selection::toggle (const vector<AutomationSelectable*>& autos)
 }
 
 void
-Selection::toggle (list<Selectable*>& selectables)
+Selection::toggle (list<Selectable*> const & selectables)
 {
        RegionView* rv;
        AutomationSelectable* as;
        vector<RegionView*> rvs;
        vector<AutomationSelectable*> autos;
 
-       for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
+       for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
                if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
                        rvs.push_back (rv);
                } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
@@ -865,7 +863,7 @@ Selection::toggle (list<Selectable*>& selectables)
 }
 
 void
-Selection::set (list<Selectable*>& selectables)
+Selection::set (list<Selectable*> const & selectables)
 {
        clear_regions();
        clear_points ();
@@ -874,14 +872,14 @@ Selection::set (list<Selectable*>& selectables)
 
 
 void
-Selection::add (list<Selectable*>& selectables)
+Selection::add (list<Selectable*> const & selectables)
 {
        RegionView* rv;
        AutomationSelectable* as;
        vector<RegionView*> rvs;
        vector<AutomationSelectable*> autos;
 
-       for (std::list<Selectable*>::iterator i = selectables.begin(); i != selectables.end(); ++i) {
+       for (std::list<Selectable*>::const_iterator i = selectables.begin(); i != selectables.end(); ++i) {
                if ((rv = dynamic_cast<RegionView*> (*i)) != 0) {
                        rvs.push_back (rv);
                } else if ((as = dynamic_cast<AutomationSelectable*> (*i)) != 0) {
@@ -956,13 +954,6 @@ void
 Selection::add (Marker* m)
 {
        if (find (markers.begin(), markers.end(), m) == markers.end()) {
-
-               /* disambiguate which remove() for the compiler */
-
-               void (Selection::*pmf)(Marker*) = &Selection::remove;
-
-               m->GoingAway.connect (bind (mem_fun (*this, pmf), m));
-
                markers.push_back (m);
                MarkersChanged();
        }