first part of MIDI cut/copy/paste ; fix for input/output_streams of an IOProcessor...
[ardour.git] / gtk2_ardour / selection.cc
index da0047eefc36da4949f83f81141aeee12817b148..be7552b0bd6109d58318f3f813e897ac3414c504 100644 (file)
@@ -23,6 +23,7 @@
 #include "pbd/stacktrace.h"
 
 #include "ardour/playlist.h"
+#include "ardour/rc_configuration.h"
 
 #include "region_view.h"
 #include "selection.h"
@@ -33,6 +34,7 @@
 
 #include "i18n.h"
 
+using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace sigc;
@@ -51,6 +53,7 @@ Selection::operator= (const Selection& other)
                tracks = other.tracks;
                time = other.time;
                lines = other.lines;
+               midi = other.midi;
        }
        return *this;
 }
@@ -64,7 +67,8 @@ operator== (const Selection& a, const Selection& b)
                a.time.group == b.time.group && 
                a.time == b.time &&
                a.lines == b.lines &&
-               a.playlists == b.playlists;
+               a.playlists == b.playlists &&
+               a.midi == b.midi;
 }
 
 /** Clear everything from the Selection */
@@ -77,6 +81,7 @@ Selection::clear ()
        clear_lines();
        clear_time ();
        clear_playlists ();
+       clear_midi ();
 }
 
 void
@@ -107,6 +112,15 @@ Selection::clear_tracks ()
        }
 }
 
+void
+Selection::clear_midi ()
+{
+       if (!midi.empty()) {
+               midi.clear ();
+               MidiChanged ();
+       }
+}
+
 void
 Selection::clear_time ()
 {
@@ -205,6 +219,20 @@ Selection::toggle (RegionView* r)
        RegionsChanged ();
 }
 
+void
+Selection::toggle (MidiRegionView* mrv)
+{
+       MidiSelection::iterator i;
+
+       if ((i = find (midi.begin(), midi.end(), mrv)) == midi.end()) {
+               add (mrv);
+       } else {
+               midi.erase (i);
+       }
+
+       MidiChanged ();
+}
+
 void
 Selection::toggle (vector<RegionView*>& r)
 {
@@ -268,18 +296,14 @@ Selection::add (const list<boost::shared_ptr<Playlist> >& pllist)
 void
 Selection::add (const list<TimeAxisView*>& track_list)
 {
-       bool changed = false;
+       list<TimeAxisView*> added = tracks.add (track_list);
 
-       for (list<TimeAxisView*>::const_iterator i = track_list.begin(); i != track_list.end(); ++i) {
-               if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
-                       void (Selection::*pmf)(TimeAxisView*) = &Selection::remove;
-                       (*i)->GoingAway.connect (sigc::bind (mem_fun (*this, pmf), (*i)));
-                       tracks.push_back (*i);
-                       changed = true;
-               }
+       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)));
        }
        
-       if (changed) {
+       if (!added.empty()) {
                TracksChanged ();
        }
 }
@@ -335,7 +359,6 @@ Selection::add (const RegionSelection& rs)
        }
        
        if (changed) {
-               select_edit_group_regions ();
                RegionsChanged ();
        }
 }
@@ -352,6 +375,21 @@ Selection::add (RegionView* r)
        }
 }
 
+void
+Selection::add (MidiRegionView* mrv)
+{
+       if (find (midi.begin(), midi.end(), mrv) == midi.end()) {
+               midi.push_back (mrv);
+               /* XXX should we do this? */
+#if 0
+               if (Config->get_link_region_and_track_selection()) {
+                       add (&mrv->get_trackview());
+               }
+#endif
+               MidiChanged ();
+       }
+}
+
 long
 Selection::add (nframes_t start, nframes_t end)
 {
@@ -476,6 +514,24 @@ Selection::remove (RegionView* r)
        }
 }
 
+void
+Selection::remove (MidiRegionView* mrv)
+{
+       MidiSelection::iterator x;
+
+       if ((x = find (midi.begin(), midi.end(), mrv)) != midi.end()) {
+               midi.erase (x);
+               MidiChanged ();
+       }
+
+#if 0
+       /* XXX fix this up ? */
+       if (Config->get_link_region_and_track_selection() && !regions.involves (r->get_trackview())) {
+               remove (&r->get_trackview());
+       }
+#endif
+}
+
 
 void
 Selection::remove (uint32_t selection_id)
@@ -495,7 +551,7 @@ Selection::remove (uint32_t selection_id)
 }
 
 void
-Selection::remove (nframes_t start, nframes_t end)
+Selection::remove (nframes_t /*start*/, nframes_t /*end*/)
 {
 }
 
@@ -545,6 +601,13 @@ Selection::set (const RegionSelection& rs)
        RegionsChanged(); /* EMIT SIGNAL */
 }
 
+void
+Selection::set (MidiRegionView* mrv) 
+{
+       clear_midi ();
+       add (mrv);
+}
+
 void
 Selection::set (RegionView* r, bool also_clear_tracks)
 {
@@ -588,7 +651,7 @@ Selection::set (TimeAxisView* track, nframes_t start, nframes_t end)
 
        if (track) {
                time.track = track;
-               time.group = track->edit_group();
+               time.group = track->route_group();
        } else {
                time.track = 0;
                time.group = 0;
@@ -744,24 +807,6 @@ Selection::add (vector<AutomationSelectable*>& autos)
        PointsChanged ();
 }
 
-void
-Selection::select_edit_group_regions ()
-{
-       std::set<RegionView*> regions_to_add;
-       
-       for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
-               vector<RegionView*> e;
-               editor->get_equivalent_regions (*i, e);
-               for (vector<RegionView*>::iterator j = e.begin(); j != e.end(); ++j) {
-                       regions_to_add.insert(*j);
-               }
-       }
-
-       for (std::set<RegionView*>::iterator i = regions_to_add.begin(); i != regions_to_add.end(); ++i) {
-               add (*i);
-       }
-}
-
 void
 Selection::set (Marker* m)
 {