mingw build fixes (tested with i686-w64-mingw32 on linux-x86_64)
[ardour.git] / libs / surfaces / osc / osc.cc
index aa98470829a9cfea460249d09621c23d6823996c..8bc791a1ee5d762bc8115f8bf0e8941ebe6b3fba 100644 (file)
 #include <cerrno>
 #include <algorithm>
 
-#include <sys/poll.h>
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <glib/gstdio.h>
 #include <glibmm/miscutils.h>
-#include <boost/signals2.hpp>
 
+#include <pbd/convert.h>
 #include <pbd/pthread_utils.h>
 #include <pbd/file_utils.h>
-#include <pbd/filesystem.h>
 #include <pbd/failed_constructor.h>
 
+#include "ardour/amp.h"
 #include "ardour/session.h"
 #include "ardour/route.h"
 #include "ardour/audio_track.h"
@@ -44,6 +44,7 @@
 #include "ardour/filesystem_paths.h"
 #include "ardour/panner.h"
 #include "ardour/plugin.h"
+#include "ardour/send.h"
 
 #include "osc.h"
 #include "osc_controllable.h"
@@ -56,8 +57,6 @@ using namespace Glib;
 
 #include "pbd/abstract_ui.cc" // instantiate template
 
-#define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
-
 OSC* OSC::_instance = 0;
 
 #ifdef DEBUG
@@ -73,24 +72,22 @@ static void error_callback(int, const char *, const char *)
 #endif
 
 OSC::OSC (Session& s, uint32_t port)
-       : ControlProtocol (s, "OSC", this)
+       : ControlProtocol (s, X_("Open Sound Control (OSC)"))
        , AbstractUI<OSCUIRequest> ("osc")
+       , local_server (0)
+       , remote_server (0)
        , _port(port)
+       , _ok (true)
+       , _shutdown (false)
+       , _osc_server (0)
+       , _osc_unix_server (0)
+       , _namespace_root ("/ardour")
+       , _send_route_changes (true)
 {
        _instance = this;
-       _shutdown = false;
-       _osc_server = 0;
-       _osc_unix_server = 0;
-       _namespace_root = "/ardour";
-       _send_route_changes = true;
-
-       /* glibmm hack */
-       local_server = 0;
-       remote_server = 0;
 
-       // "Application Hooks"
        session_loaded (s);
-       session->Exported.connect (*this, MISSING_INVALIDATOR, ui_bind (&OSC::session_exported, this, _1, _2), this);
+       session->Exported.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::session_exported, this, _1, _2), this);
 }
 
 OSC::~OSC()
@@ -115,11 +112,21 @@ OSC::do_request (OSCUIRequest* req)
 int
 OSC::set_active (bool yn)
 {
-       if (yn) {
-               return start ();
-       } else {
-               return stop ();
+       if (yn != active()) {
+
+               if (yn) {
+                       if (start ()) {
+                               return -1;
+                       }
+               } else {
+                       if (stop ()) {
+                               return -1;
+                       }
+               }
+               
        }
+
+       return ControlProtocol::set_active (yn);
 }
 
 bool
@@ -168,6 +175,10 @@ OSC::start ()
                _port++;
                continue;
        }
+
+       if (!_osc_server) {
+               return 1;
+       }
        
 #ifdef ARDOUR_OSC_UNIX_SERVER
        
@@ -179,7 +190,7 @@ OSC::start ()
        int fd = mkstemp(tmpstr);
        
        if (fd >= 0 ) {
-               unlink (tmpstr);
+               ::g_unlink (tmpstr);
                close (fd);
                
                _osc_unix_server = lo_server_new (tmpstr, error_callback);
@@ -190,22 +201,20 @@ OSC::start ()
        }
 #endif
        
-       cerr << "OSC @ " << get_server_url () << endl;
+       PBD::info << "OSC @ " << get_server_url () << endmsg;
 
-       PBD::sys::path url_file;
+       std::string url_file;
 
-       if (find_file_in_search_path (ardour_search_path() + system_config_search_path(),
-                                     "osc_url", url_file)) {
+       if (find_file_in_search_path (ardour_config_search_path(), "osc_url", url_file)) {
                
-               _osc_url_file = url_file.to_string();
+               _osc_url_file = url_file;
                ofstream urlfile;
                urlfile.open(_osc_url_file.c_str(), ios::trunc);
                
-               if ( urlfile ){
+               if (urlfile) {
                        urlfile << get_server_url () << endl;
                        urlfile.close();
-               }
-               else {  
+               } else {  
                        cerr << "Couldn't write '" <<  _osc_url_file << "'" <<endl;
                }
        }
@@ -224,9 +233,7 @@ OSC::start ()
 void
 OSC::thread_init ()
 {
-       char* c = new char[4];
-       strcpy (c, X_("OSC"));
-       pthread_set_name (c);
+       pthread_set_name (X_("OSC"));
 
        if (_osc_unix_server) {
                Glib::RefPtr<IOSource> src = IOSource::create (lo_server_get_socket_fd (_osc_unix_server), IO_IN|IO_HUP|IO_ERR);
@@ -250,7 +257,7 @@ OSC::thread_init ()
 
 int
 OSC::stop ()
-{      
+{
        /* stop main loop */
 
        if (local_server) {
@@ -286,13 +293,26 @@ OSC::stop ()
        }
        
        if (!_osc_unix_socket_path.empty()) {
-               unlink (_osc_unix_socket_path.c_str());
+               ::g_unlink (_osc_unix_socket_path.c_str());
        }
        
        if (!_osc_url_file.empty() ) {
-               unlink (_osc_url_file.c_str() );
+               ::g_unlink (_osc_url_file.c_str() );
        }
 
+       // Delete any active route observers
+       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
+
+               OSCRouteObserver* rc;
+               
+               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+                       delete *x;
+                       x = route_observers.erase (x);
+               } else {
+                       ++x;
+               }
+       }
+       
        return 0;
 }
 
@@ -316,9 +336,10 @@ OSC::register_callbacks()
                /* this is a special catchall handler */
                
                lo_server_add_method (serv, 0, 0, _catchall, this);
-
+               
 #define REGISTER_CALLBACK(serv,path,types, function) lo_server_add_method (serv, path, types, OSC::_ ## function, this)
                
+               REGISTER_CALLBACK (serv, "/routes/list", "", routes_list);
                REGISTER_CALLBACK (serv, "/ardour/add_marker", "", add_marker);
                REGISTER_CALLBACK (serv, "/ardour/access_action", "s", access_action);
                REGISTER_CALLBACK (serv, "/ardour/loop_toggle", "", loop_toggle);
@@ -328,7 +349,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/ardour/ffwd", "", ffwd);
                REGISTER_CALLBACK (serv, "/ardour/transport_stop", "", transport_stop);
                REGISTER_CALLBACK (serv, "/ardour/transport_play", "", transport_play);
-               //REGISTER_CALLBACK (serv, "/ardour/transport_frame", "", transport_frame);
+               REGISTER_CALLBACK (serv, "/ardour/transport_frame", "", transport_frame);
                REGISTER_CALLBACK (serv, "/ardour/set_transport_speed", "f", set_transport_speed);
                 REGISTER_CALLBACK (serv, "/ardour/locate", "ii", locate);
                REGISTER_CALLBACK (serv, "/ardour/save_state", "", save_state);
@@ -350,8 +371,8 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/ardour/routes/pan_stereo_width", "if", route_set_pan_stereo_width);
                REGISTER_CALLBACK (serv, "/ardour/routes/plugin/parameter", "iiif", route_plugin_parameter);
                REGISTER_CALLBACK (serv, "/ardour/routes/plugin/parameter/print", "iii", route_plugin_parameter_print);
-
-               
+               REGISTER_CALLBACK (serv, "/ardour/routes/send/gainabs", "iif", route_set_send_gain_abs);
+               REGISTER_CALLBACK (serv, "/ardour/routes/send/gaindB", "iif", route_set_send_gain_dB);
 
                /* still not-really-standardized query interface */
                //REGISTER_CALLBACK (serv, "/ardour/*/#current_value", "", current_value);
@@ -410,6 +431,85 @@ OSC::get_unix_server_url()
        return url;
 }
 
+void
+OSC::listen_to_route (boost::shared_ptr<Route> route, lo_address addr)
+{
+       /* avoid duplicate listens */
+       
+       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end(); ++x) {
+               
+               OSCRouteObserver* ro;
+
+               if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+
+                       int res = strcmp(lo_address_get_hostname(ro->address()), lo_address_get_hostname(addr));
+                       
+                       if (ro->route() == route && res == 0) {
+                               return;
+                       }
+               }
+       }
+
+       OSCRouteObserver* o = new OSCRouteObserver (route, addr);
+       route_observers.push_back (o);
+
+       route->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::drop_route, this, boost::weak_ptr<Route> (route)), this);
+}
+
+void
+OSC::drop_route (boost::weak_ptr<Route> wr)
+{
+       boost::shared_ptr<Route> r = wr.lock ();
+
+       if (!r) {
+               return;
+       }
+
+       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
+
+               OSCRouteObserver* rc;
+               
+               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+                 
+                       if (rc->route() == r) {
+                               delete *x;
+                               x = route_observers.erase (x);
+                       } else {
+                               ++x;
+                       }
+               } else {
+                       ++x;
+               }
+       }
+}
+
+void
+OSC::end_listen (boost::shared_ptr<Route> r, lo_address addr)
+{
+       RouteObservers::iterator x;
+       
+       // Remove the route observers
+       for (x = route_observers.begin(); x != route_observers.end();) {
+
+               OSCRouteObserver* ro;
+               
+               if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+                 
+                       int res = strcmp(lo_address_get_hostname(ro->address()), lo_address_get_hostname(addr));
+
+                       if (ro->route() == r && res == 0) {
+                               delete *x;
+                               x = route_observers.erase (x);
+                       }
+                       else {
+                               ++x;
+                       }
+               }
+               else {
+                       ++x;
+               }
+       }
+}
 
 void
 OSC::current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg)
@@ -486,7 +586,7 @@ OSC::_catchall (const char *path, const char *types, lo_arg **argv, int argc, vo
 }
 
 int
-OSC::catchall (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg) 
+OSC::catchall (const char *path, const char* /*types*/, lo_arg **argv, int argc, lo_message msg) 
 {
        size_t len;
        int ret = 1; /* unhandled */
@@ -501,19 +601,7 @@ OSC::catchall (const char *path, const char *types, lo_arg **argv, int argc, lo_
        if (len >= 17 && !strcmp (&path[len-15], "/#current_value")) {
                current_value_query (path, len, argv, argc, msg);
                ret = 0;
-       } else if (strcmp (path, "/ardour/transport_frame") == 0) {
-               
-               framepos_t pos = transport_frame ();
-               
-               lo_message reply = lo_message_new ();
-               lo_message_add_int64 (reply, pos);
-               
-               lo_send_message (lo_message_get_source (msg), "/ardour/transport_frame", reply);
-               
-               lo_message_free (reply);
-               
-               ret = 0;
-               
+
        } else if (strcmp (path, "/routes/listen") == 0) {
                
                cerr << "set up listener\n";
@@ -555,229 +643,31 @@ OSC::catchall (const char *path, const char *types, lo_arg **argv, int argc, lo_
                        }
                }
                
-               ret = 0;
-               
-       } else if (strcmp (path, "/routes/list") == 0) {
-
-               for (int n = 0; n < (int) session->nroutes(); ++n) {
-
-                       boost::shared_ptr<Route> r = session->route_by_remote_id (n);
-                       
-                       if (r) {
-
-                               lo_message reply = lo_message_new ();
-                       
-                               if (boost::dynamic_pointer_cast<AudioTrack>(r)) {
-                                       lo_message_add_string (reply, "AT");
-                               } else if (boost::dynamic_pointer_cast<MidiTrack>(r)) {
-                                       lo_message_add_string (reply, "MT");
-                               } else {
-                                       lo_message_add_string (reply, "B");
-                               }
-                               
-                               lo_message_add_string (reply, r->name().c_str());
-                               lo_message_add_int32 (reply, r->n_inputs().n_audio());
-                               lo_message_add_int32 (reply, r->n_outputs().n_audio());
-                               lo_message_add_int32 (reply, r->muted());
-                               lo_message_add_int32 (reply, r->soloed());
-                               lo_message_add_int32 (reply, r->remote_control_id());
-                               
-                               if (boost::dynamic_pointer_cast<AudioTrack>(r) 
-                                       || boost::dynamic_pointer_cast<MidiTrack>(r)) {
-               
-                                       boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(r);
-                                       lo_message_add_int32 (reply, t->record_enabled());
-                               }
-                               
-                               lo_send_message (lo_message_get_source (msg), "#reply", reply);
-                               lo_message_free (reply);
-                               
-                               //Automatically listen to routes listed
-                               listen_to_route(r, lo_message_get_source (msg));
-                       }
-               }
-       
-               // Send end of listing message
-               lo_message reply = lo_message_new ();
-
-               lo_message_add_string (reply, "end_route_list");
-               lo_message_add_int64 (reply, session->frame_rate());
-               lo_message_add_int64 (reply, session->current_end_frame());
-               
-               lo_send_message (lo_message_get_source (msg), "#reply", reply);
-               
-               lo_message_free (reply);
-               
-               ret = 0;
-       }
+               ret = 0;        
+       } 
 
        return ret;
 }
 
 void
-OSC::update_clock (){
-  
-}
-
-void
-OSC::listen_to_route (boost::shared_ptr<Route> route, lo_address addr)
+OSC::update_clock ()
 {
-       Controllables::iterator x;
-       bool route_exists = false;
-
-       cerr << "listen to route\n";
-
-       /* avoid duplicate listens */
-       
-       for (x = controllables.begin(); x != controllables.end(); ++x) {
-               
-               OSCRouteControllable* rc;
-
-               if ((rc = dynamic_cast<OSCRouteControllable*>(*x)) != 0) {
-                       
-                       if (rc->route() == route) {
-                               route_exists = true;
-                               
-                               /* XXX NEED lo_address_equal() */
-                               int res = strcmp(lo_address_get_hostname(rc->address()), lo_address_get_hostname(addr));
-                               
-                               if (res == 0) {
-                                       cerr << "already listening to route" << endl;
-                                       return;
-                               }
-                       }
-               }
-       }
-
-       cerr << "listener binding to signals\n";
-
-       OSCControllable* c;
-       string path;
-       
-       if (boost::dynamic_pointer_cast<AudioTrack>(route) || boost::dynamic_pointer_cast<MidiTrack>(route)) {
-               
-               boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track>(route);
-               
-               path = X_("/route/rec");
-               c = new OSCRouteControllable (addr, path, track->rec_enable_control(), track);
-               controllables.push_back (c);
-       }
-
-       path = X_("/route/solo");
-       c = new OSCRouteControllable (addr, path, route->solo_control(), route);
-       controllables.push_back (c);
-
-       path = X_("/route/mute");
-       c = new OSCRouteControllable (addr, path, route->mute_control(), route);
-       controllables.push_back (c);
-
-       path = X_("/route/gain");
-       c = new OSCRouteControllable (addr, path, route->gain_control(), route);
-       controllables.push_back (c);
-       
-       cerr << "Now have " << controllables.size() << " controllables\n";
-
-       OSCRouteObserver* o;
-       
-       o = new OSCRouteObserver (addr, path, route);
-       observables.push_back (o);
-       
-       /* if there is no existing controllable related to this route, make sure we clean up
-          if it is ever deleted.
-       */
-       
-       if (!route_exists) {
-               route->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::drop_route, this, boost::weak_ptr<Route> (route)), this);
-       }
+  
 }
 
+// "Application Hook" Handlers //
 void
-OSC::drop_route (boost::weak_ptr<Route> wr)
+OSC::session_loaded (Session& s)
 {
-       boost::shared_ptr<Route> r = wr.lock ();
-
-       if (!r) {
-               return;
-       }
-
-       for (Controllables::iterator x = controllables.begin(); x != controllables.end();) {
-
-               OSCRouteControllable* rc;
-               
-               if ((rc = dynamic_cast<OSCRouteControllable*>(*x)) != 0) {
-                       if (rc->route() == r) {
-                               delete *x;
-                               x = controllables.erase (x);
-                       } else {
-                               ++x;
-                       }
-               } else {
-                       ++x;
-               }
-       }
+       lo_address listener = lo_address_new (NULL, "7770");
+       lo_send (listener, "/session/loaded", "ss", s.path().c_str(), s.name().c_str());
 }
 
 void
-OSC::end_listen (boost::shared_ptr<Route> r, lo_address addr)
+OSC::session_exported (std::string path, std::string name)
 {
-       Controllables::iterator x;
-
-       for (x = controllables.begin(); x != controllables.end();) {
-
-               OSCRouteControllable* rc;
-               
-               if ((rc = dynamic_cast<OSCRouteControllable*>(*x)) != 0) {
-
-                       /* XXX NEED lo_address_equal () */
-                       if (rc->route() == r && (0 == strcmp(lo_address_get_hostname(rc->address()), lo_address_get_hostname(addr)))){
-                               delete *x;
-                               x = controllables.erase (x);
-                       }
-                       else {
-                               ++x;
-                       }
-               }
-               else {
-                       ++x;
-               }
-       }
-       
-       Observables::iterator z;
-       
-       // Remove the route observers
-       for (z = observables.begin(); z != observables.end();) {
-
-               OSCRouteObserver* ro;
-               
-               if ((ro = dynamic_cast<OSCRouteObserver*>(*z)) != 0) {
-
-                       /* XXX NEED lo_address_equal () */
-                       if (ro->route() == r){
-                               delete *z;
-                               z = observables.erase (z);
-                       }
-                       else {
-                               ++z;
-                       }
-               }
-               else {
-                       ++z;
-               }
-       }
-}
-
-
-// "Application Hook" Handlers //
-void
-OSC::session_loaded( Session& s ) {
-       lo_address listener = lo_address_new( NULL, "7770" );
-       lo_send( listener, "/session/loaded", "ss", s.path().c_str(), s.name().c_str() );
-}
-
-void
-OSC::session_exported( std::string path, std::string name ) {
-       lo_address listener = lo_address_new( NULL, "7770" );
-       lo_send( listener, "/session/exported", "ss", path.c_str(), name.c_str() );
+       lo_address listener = lo_address_new (NULL, "7770");
+       lo_send (listener, "/session/exported", "ss", path.c_str(), name.c_str());
 }
 
 // end "Application Hook" Handlers //
@@ -844,6 +734,72 @@ OSC::current_value (const char */*path*/, const char */*types*/, lo_arg **/*argv
        return 0;
 }
 
+void
+OSC::routes_list (lo_message msg)
+{
+       for (int n = 0; n < (int) session->nroutes(); ++n) {
+
+               boost::shared_ptr<Route> r = session->route_by_remote_id (n);
+               
+               if (r) {
+
+                       lo_message reply = lo_message_new ();
+               
+                       if (boost::dynamic_pointer_cast<AudioTrack>(r)) {
+                               lo_message_add_string (reply, "AT");
+                       } else if (boost::dynamic_pointer_cast<MidiTrack>(r)) {
+                               lo_message_add_string (reply, "MT");
+                       } else {
+                               lo_message_add_string (reply, "B");
+                       }
+                       
+                       lo_message_add_string (reply, r->name().c_str());
+                       lo_message_add_int32 (reply, r->n_inputs().n_audio());
+                       lo_message_add_int32 (reply, r->n_outputs().n_audio());
+                       lo_message_add_int32 (reply, r->muted());
+                       lo_message_add_int32 (reply, r->soloed());
+                       lo_message_add_int32 (reply, r->remote_control_id());
+                       
+                       if (boost::dynamic_pointer_cast<AudioTrack>(r) 
+                               || boost::dynamic_pointer_cast<MidiTrack>(r)) {
+       
+                               boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(r);
+                               lo_message_add_int32 (reply, t->record_enabled());
+                       }
+
+                       //Automatically listen to routes listed
+                       listen_to_route(r, lo_message_get_source (msg));
+
+                       lo_send_message (lo_message_get_source (msg), "#reply", reply);
+                       lo_message_free (reply);
+               }
+       }
+       
+       // Send end of listing message
+       lo_message reply = lo_message_new ();
+
+       lo_message_add_string (reply, "end_route_list");
+       lo_message_add_int64 (reply, session->frame_rate());
+       lo_message_add_int64 (reply, session->current_end_frame());
+       
+       lo_send_message (lo_message_get_source (msg), "#reply", reply);
+       
+       lo_message_free (reply);
+}
+
+void
+OSC::transport_frame (lo_message msg)
+{
+               framepos_t pos = session->transport_frame ();
+               
+               lo_message reply = lo_message_new ();
+               lo_message_add_int64 (reply, pos);
+               
+               lo_send_message (lo_message_get_source (msg), "/ardour/transport_frame", reply);
+               
+               lo_message_free (reply);
+}
+
 int
 OSC::route_mute (int rid, int yn)
 {
@@ -854,6 +810,7 @@ OSC::route_mute (int rid, int yn)
        if (r) {
                r->set_mute (yn, this);
        }
+       
        return 0;
 }
 
@@ -867,6 +824,7 @@ OSC::route_solo (int rid, int yn)
        if (r) {
                r->set_solo (yn, this);
        }
+       
        return 0;
 }
 
@@ -880,6 +838,7 @@ OSC::route_recenable (int rid, int yn)
        if (r) {
                r->set_record_enabled (yn, this);
        }
+       
        return 0;
 }
 
@@ -921,7 +880,7 @@ OSC::route_set_pan_stereo_position (int rid, float pos)
        if (r) {
                 boost::shared_ptr<Panner> panner = r->panner();
                 if (panner) {
-                        panner->set_stereo_position (pos);
+                        panner->set_position (pos);
                 }
        }
        
@@ -939,7 +898,7 @@ OSC::route_set_pan_stereo_width (int rid, float pos)
        if (r) {
                 boost::shared_ptr<Panner> panner = r->panner();
                 if (panner) {
-                        panner->set_stereo_width (pos);
+                        panner->set_width (pos);
                 }
        }
        
@@ -948,7 +907,71 @@ OSC::route_set_pan_stereo_width (int rid, float pos)
 }
 
 int
-OSC::route_plugin_parameter (int rid,int piid,int par, float val)
+OSC::route_set_send_gain_abs (int rid, int sid, float val)
+{
+        if (!session) { 
+                return -1;
+        }
+
+        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);  
+
+        if (!r) {
+                return -1;
+        }
+
+       /* revert to zero-based counting */
+
+       if (sid > 0) {
+               --sid;
+       }
+
+       boost::shared_ptr<Processor> p = r->nth_send (sid);
+       
+       if (p) {
+               boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(p);
+               boost::shared_ptr<Amp> a = s->amp();
+               
+               if (a) {
+                       a->set_gain (val, this);
+               }
+       }
+       return 0;
+}
+
+int
+OSC::route_set_send_gain_dB (int rid, int sid, float val)
+{
+        if (!session) { 
+                return -1;
+        }
+
+        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);  
+
+        if (!r) {
+                return -1;
+        }
+
+       /* revert to zero-based counting */
+
+       if (sid > 0) {
+               --sid;
+       }
+
+       boost::shared_ptr<Processor> p = r->nth_send (sid);
+       
+       if (p) {
+               boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(p);
+               boost::shared_ptr<Amp> a = s->amp();
+               
+               if (a) {
+                       a->set_gain (dB_to_coefficient (val), this);
+               }
+       }
+       return 0;
+}
+
+int
+OSC::route_plugin_parameter (int rid, int piid, int par, float val)
 {
         if (!session) { 
                 return -1;
@@ -995,7 +1018,7 @@ OSC::route_plugin_parameter (int rid,int piid,int par, float val)
 }
 
 int
-OSC::route_plugin_parameter_print (int rid,int piid,int par)
+OSC::route_plugin_parameter_print (int rid, int piid, int par)
 {
         if (!session) { 
                 return -1;
@@ -1018,7 +1041,8 @@ OSC::route_plugin_parameter_print (int rid,int piid,int par)
         if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
                 return -1;
         }
-        boost::shared_ptr<ARDOUR::Plugin> pip=pi->plugin();
+        
+        boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
         bool ok=false;
         
         uint32_t controlid = pip->nth_parameter (par,ok);
@@ -1044,11 +1068,26 @@ OSC::route_plugin_parameter_print (int rid,int piid,int par)
 XMLNode& 
 OSC::get_state () 
 {
-       return *(new XMLNode ("OSC"));
+       XMLNode& node (ControlProtocol::get_state());
+
+       node.add_property (X_("feedback"), _send_route_changes ? "1" : "0");
+       return node;
 }
-               
+
 int 
-OSC::set_state (const XMLNode&, int /*version*/)
+OSC::set_state (const XMLNode& node, int /*version*/)
 {
+       const XMLProperty* prop = node.property (X_("feedback"));
+
+       if (prop) {
+               if (PBD::string_is_affirmative (prop->value())) {
+                       _send_route_changes = true;
+               } else {
+                       _send_route_changes = false;
+               }
+       } else {
+               /* leave it alone */
+       }
+             
        return 0;
 }