Fix another crash at exit.
[ardour.git] / gtk2_ardour / route_processor_selection.cc
index 8975bf90bcd13fdb953570d0051ca61f83dbd94c..0dc15e7f8a2b17a1d66013d4889d35ca10bc594a 100644 (file)
 
 #include <algorithm>
 #include <sigc++/bind.h>
+
 #include "pbd/error.h"
+#include "pbd/i18n.h"
+
+#include "ardour/selection.h"
+#include "ardour/session.h"
+#include "ardour/session_handle.h"
 
+#include "axis_provider.h"
 #include "gui_thread.h"
 #include "mixer_strip.h"
+#include "mixer_ui.h"
 #include "route_processor_selection.h"
 #include "route_ui.h"
 
-#include "i18n.h"
-
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-RouteProcessorSelection::RouteProcessorSelection()
-       : _no_route_change_signal (false)
+RouteProcessorSelection::RouteProcessorSelection (SessionHandlePtr& s, AxisViewProvider& ap)
+       : shp (s), avp (ap)
 {
 }
 
@@ -41,8 +47,8 @@ RouteProcessorSelection&
 RouteProcessorSelection::operator= (const RouteProcessorSelection& other)
 {
        if (&other != this) {
-               processors = other.processors;
-               routes = other.routes;
+               (*((ProcessorSelection*) this)) = (*((ProcessorSelection const *) &other));
+               axes = other.axes;
        }
        return *this;
 }
@@ -51,7 +57,7 @@ bool
 operator== (const RouteProcessorSelection& a, const RouteProcessorSelection& b)
 {
        // XXX MUST TEST PROCESSORS SOMEHOW
-       return a.routes == b.routes;
+       return a.axes == b.axes;
 }
 
 void
@@ -62,97 +68,93 @@ RouteProcessorSelection::clear ()
 }
 
 void
-RouteProcessorSelection::clear_processors ()
+RouteProcessorSelection::clear_routes ()
 {
-       processors.clear ();
-       ProcessorsChanged ();
+       if (shp.session()) {
+               PresentationInfo::ChangeSuspender cs;
+               shp.session()->selection().clear_stripables ();
+       }
 }
 
 void
-RouteProcessorSelection::clear_routes ()
+RouteProcessorSelection::presentation_info_changed (PropertyChange const & what_changed)
 {
-       for (RouteUISelection::iterator i = routes.begin(); i != routes.end(); ++i) {
-               (*i)->set_selected (false);
+       Session* s = shp.session();
+
+       if (!s) {
+               /* too early ... session handle provider doesn't know about the
+                  session yet.
+               */
+               return;
        }
-       routes.clear ();
-       drop_connections ();
-       if (!_no_route_change_signal) {
-               RoutesChanged ();
+
+       PropertyChange pc;
+       pc.add (Properties::selected);
+
+       CoreSelection::StripableAutomationControls sc;
+       s->selection().get_stripables (sc);
+
+       for (AxisViewSelection::iterator a = axes.begin(); a != axes.end(); ++a) {
+               (*a)->set_selected (false);
        }
-}
 
-void
-RouteProcessorSelection::add (XMLNode* node)
-{
-       // XXX check for duplicate
-       processors.add (node);
-       ProcessorsChanged();
-}
+       axes.clear ();
 
-void
-RouteProcessorSelection::set (XMLNode* node)
-{
-       clear_processors ();
-       processors.set (node);
-       ProcessorsChanged ();
+       for (CoreSelection::StripableAutomationControls::const_iterator i = sc.begin(); i != sc.end(); ++i) {
+               AxisView* av = avp.axis_view_by_stripable ((*i).stripable);
+               if (av) {
+                       axes.insert (av);
+                       av->set_selected (true);
+               }
+       }
 }
 
 void
-RouteProcessorSelection::add (RouteUI* r)
+RouteProcessorSelection::add (AxisView* r)
 {
-       if (find (routes.begin(), routes.end(), r) == routes.end()) {
-               if (routes.insert (r).second) {
-                       r->set_selected (true);
-
-                       MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
-                       
-                       if (ms) {
-                               ms->CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RouteProcessorSelection::remove, this, _1), gui_context());
-                       }
-                       
-                       if (!_no_route_change_signal) {
-                               RoutesChanged();
-                       }
+       if (!shp.session()) {
+               return;
+       }
+
+       if (axes.insert (r).second) {
+
+               shp.session()->selection().add (r->stripable(), boost::shared_ptr<AutomationControl>());
+
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+
+               if (ms) {
+                       ms->CatchDeletion.connect (*this, invalidator (*this), boost::bind (&RouteProcessorSelection::remove, this, _1), gui_context());
                }
        }
 }
 
 void
-RouteProcessorSelection::remove (RouteUI* r)
+RouteProcessorSelection::remove (AxisView* r)
 {
-       ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
-
-       RouteUISelection::iterator i;
-       if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
-               (*i)->set_selected (false);
-               routes.erase (i);
-               if (!_no_route_change_signal) {
-                       RoutesChanged ();
-               }
+       if (!shp.session()) {
+               return;
        }
+       ENSURE_GUI_THREAD (*this, &RouteProcessorSelection::remove, r);
+       shp.session()->selection().remove (r->stripable(), boost::shared_ptr<AutomationControl>());
 }
 
 void
-RouteProcessorSelection::set (RouteUI* r)
+RouteProcessorSelection::set (AxisView* r)
 {
-       clear_routes ();
-       add (r);
+       if (!shp.session()) {
+               return;
+       }
+       shp.session()->selection().set (r->stripable(), boost::shared_ptr<AutomationControl>());
 }
 
 bool
-RouteProcessorSelection::selected (RouteUI* r)
+RouteProcessorSelection::selected (AxisView* r)
 {
-       return find (routes.begin(), routes.end(), r) != routes.end();
+       return find (axes.begin(), axes.end(), r) != axes.end();
 }
 
 bool
 RouteProcessorSelection::empty ()
 {
-       return processors.empty () && routes.empty ();
-}
-
-void
-RouteProcessorSelection::block_routes_changed (bool yn)
-{
-       _no_route_change_signal = yn;
+       return processors.empty () && axes.empty ();
 }