implement OSC /ardour/route/send/gainabs and /ardour/route/send/gainDB
[ardour.git] / libs / surfaces / osc / osc.cc
index 93b56a8a9769f2571bd068139177a170c9c0ea74..ef07ca17fb10f433428b30c69c10de0ca917a054 100644 (file)
 #include <fcntl.h>
 
 #include <glibmm/miscutils.h>
-#include <boost/signals2.hpp>
 
 #include <pbd/pthread_utils.h>
 #include <pbd/file_utils.h>
-#include <pbd/filesystem.h>
 #include <pbd/failed_constructor.h>
 
 #include "ardour/session.h"
@@ -56,8 +54,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,7 +69,7 @@ static void error_callback(int, const char *, const char *)
 #endif
 
 OSC::OSC (Session& s, uint32_t port)
-       : ControlProtocol (s, "OSC", this)
+       : ControlProtocol (s, "OSC")
        , AbstractUI<OSCUIRequest> ("osc")
        , _port(port)
 {
@@ -90,7 +86,7 @@ OSC::OSC (Session& s, uint32_t port)
 
        // "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()
@@ -190,14 +186,13 @@ 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);
                
@@ -361,8 +356,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);
@@ -576,7 +571,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 */
@@ -870,7 +865,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);
                 }
        }
        
@@ -888,7 +883,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);
                 }
        }
        
@@ -896,6 +891,68 @@ OSC::route_set_pan_stereo_width (int rid, float pos)
 
 }
 
+int
+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 (send);
+       
+       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);
+               }
+       }
+}
+
+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 (send);
+       
+       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);
+               }
+       }
+}
+
 int
 OSC::route_plugin_parameter (int rid, int piid, int par, float val)
 {
@@ -994,7 +1051,12 @@ OSC::route_plugin_parameter_print (int rid, int piid, int par)
 XMLNode& 
 OSC::get_state () 
 {
-       return *(new XMLNode ("OSC"));
+       XMLNode* node = new XMLNode ("Protocol"); 
+
+       node->add_property (X_("name"), "Open Sound Control (OSC)");
+       node->add_property (X_("feedback"), _send_route_changes ? "1" : "0");
+
+       return *node;
 }
 
 int