OSC: Some surfaces may use float for ssid. Accept this too.
[ardour.git] / libs / surfaces / osc / osc.cc
index 0a412ee7de9d88b5c1f9847f52f6df50a96fbfb4..4818f9340c9a47c23a4e8a0aba9282c41aa337c1 100644 (file)
@@ -409,6 +409,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/refresh", "", refresh_surface);
                REGISTER_CALLBACK (serv, "/refresh", "f", refresh_surface);
                REGISTER_CALLBACK (serv, "/strip/list", "", routes_list);
+               REGISTER_CALLBACK (serv, "/strip/list", "f", routes_list);
                REGISTER_CALLBACK (serv, "/add_marker", "", add_marker);
                REGISTER_CALLBACK (serv, "/add_marker", "f", add_marker);
                REGISTER_CALLBACK (serv, "/access_action", "s", access_action);
@@ -574,7 +575,12 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/select/comp_mode", "f", sel_comp_mode);
                REGISTER_CALLBACK (serv, "/select/comp_makeup", "f", sel_comp_makeup);
                REGISTER_CALLBACK (serv, "/select/eq_enable", "f", sel_eq_enable);
-               REGISTER_CALLBACK (serv, "/select/eq_hpf", "f", sel_eq_hpf);
+               REGISTER_CALLBACK (serv, "/select/eq_hpf/freq", "f", sel_eq_hpf_freq);
+               REGISTER_CALLBACK (serv, "/select/eq_hpf/enable", "f", sel_eq_hpf_enable);
+               REGISTER_CALLBACK (serv, "/select/eq_hpf/slope", "f", sel_eq_hpf_slope);
+               REGISTER_CALLBACK (serv, "/select/eq_lpf/freq", "f", sel_eq_lpf_freq);
+               REGISTER_CALLBACK (serv, "/select/eq_lpf/enable", "f", sel_eq_lpf_enable);
+               REGISTER_CALLBACK (serv, "/select/eq_lpf/slope", "f", sel_eq_lpf_slope);
                REGISTER_CALLBACK (serv, "/select/eq_gain", "if", sel_eq_gain);
                REGISTER_CALLBACK (serv, "/select/eq_freq", "if", sel_eq_freq);
                REGISTER_CALLBACK (serv, "/select/eq_q", "if", sel_eq_q);
@@ -860,7 +866,11 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
        len = strlen (path);
 
        if (strstr (path, "/automation")) {
-               ret = set_automation (path, len, argv, argc, msg);
+               ret = set_automation (path, types, argv, argc, msg);
+
+       } else
+       if (strstr (path, "/touch")) {
+               ret = touch_detect (path, types, argv, argc, msg);
 
        } else
        if (len >= 17 && !strcmp (&path[len-15], "/#current_value")) {
@@ -2197,7 +2207,7 @@ OSC::route_get_receives(lo_message msg) {
 // strip calls
 
 int
-OSC::set_automation (const char *path, size_t len, lo_arg **argv, int argc, lo_message msg)
+OSC::set_automation (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
 {
        if (!session) return -1;
 
@@ -2206,25 +2216,29 @@ OSC::set_automation (const char *path, size_t len, lo_arg **argv, int argc, lo_m
        boost::shared_ptr<Stripable> strp = boost::shared_ptr<Stripable>();
        uint32_t ctr = 0;
        uint32_t aut = 0;
+       uint32_t ssid;
+
+       if (argc) {
+               if (argv[argc - 1]->f) {
+                       aut = (int)argv[argc - 1]->f;
+               } else {
+                       aut = argv[argc - 1]->i;
+               }
+       }
 
        //parse path first to find stripable
        if (!strncmp (path, "/strip/", 7)) {
                // find ssid and stripable
                if (argc > 1) {
-                       strp = get_strip (argv[0]->i, get_address (msg));
-                       if (argv[1]->f) {
-                               aut = (int)argv[1]->f;
+                       if (types[1] == 'f') {
+                               ssid = (uint32_t)argv[0]->f;
                        } else {
-                               aut = argv[1]->i;
+                               ssid = argv[0]->i;
                        }
+                       strp = get_strip (ssid, get_address (msg));
                } else {
-                       uint32_t ssid = atoi (&(strrchr (path, '/' ))[1]);
+                       ssid = atoi (&(strrchr (path, '/' ))[1]);
                        strp = get_strip (ssid, get_address (msg));
-                       if (argv[0]->f) {
-                               aut = (int)argv[0]->f;
-                       } else {
-                               aut = argv[0]->i;
-                       }
                }
                ctr = 7;
        } else if (!strncmp (path, "/select/", 8)) {
@@ -2233,17 +2247,13 @@ OSC::set_automation (const char *path, size_t len, lo_arg **argv, int argc, lo_m
                } else {
                        strp = ControlProtocol::first_selected_stripable();
                }
-               if (argv[0]->f) {
-                       aut = (int)argv[0]->f;
-               } else {
-                       aut = argv[0]->i;
-               }
                ctr = 8;
        } else {
                return ret;
        }
        if (strp) {
                boost::shared_ptr<AutomationControl> control = boost::shared_ptr<AutomationControl>();
+               // other automatable controls can be added by repeating the next 6.5 lines
                if ((!strncmp (&path[ctr], "fader", 5)) || (!strncmp (&path[ctr], "gain", 4))) {
                        if (strp->gain_control ()) {
                                control = strp->gain_control ();
@@ -2282,6 +2292,101 @@ OSC::set_automation (const char *path, size_t len, lo_arg **argv, int argc, lo_m
        return ret;
 }
 
+int
+OSC::touch_detect (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
+{
+       if (!session) return -1;
+
+       int ret = 1;
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> strp = boost::shared_ptr<Stripable>();
+       uint32_t ctr = 0;
+       uint32_t touch = 0;
+       uint32_t ssid;
+
+       if (argc) {
+               if (argv[argc - 1]->f) {
+                       touch = (int)argv[argc - 1]->f;
+               } else {
+                       touch = argv[argc - 1]->i;
+               }
+       }
+
+       //parse path first to find stripable
+       if (!strncmp (path, "/strip/", 7)) {
+               // find ssid and stripable
+               if (argc > 1) {
+                       if (types[1] == 'f') {
+                               ssid = (uint32_t)argv[0]->f;
+                       } else {
+                               ssid = argv[0]->i;
+                       }
+                       strp = get_strip (ssid, get_address (msg));
+               } else {
+                       ssid = atoi (&(strrchr (path, '/' ))[1]);
+                       strp = get_strip (ssid, get_address (msg));
+               }
+               ctr = 7;
+       } else if (!strncmp (path, "/select/", 8)) {
+               if (sur->expand_enable && sur->expand) {
+                       strp = get_strip (sur->expand, get_address (msg));
+               } else {
+                       strp = ControlProtocol::first_selected_stripable();
+               }
+               ctr = 8;
+       } else {
+               return ret;
+       }
+       if (strp) {
+               boost::shared_ptr<AutomationControl> control = boost::shared_ptr<AutomationControl>();
+               // other automatable controls can be added by repeating the next 6.5 lines
+               if ((!strncmp (&path[ctr], "fader", 5)) || (!strncmp (&path[ctr], "gain", 4))) {
+                       if (strp->gain_control ()) {
+                               control = strp->gain_control ();
+                       } else {
+                               PBD::warning << "No fader for this strip" << endmsg;
+                       }
+               } else {
+                       PBD::warning << "Automation not available for " << path << endmsg;
+               }
+
+               if (control) {
+                       if (touch) {
+                               //start touch
+                               if (control->automation_state() == Touch && !control->touching ()) {
+                                       control->start_touch (control->session().transport_frame());
+                                       ret = 0;
+                               }
+                       } else {
+                               // end touch
+                               control->stop_touch (true, control->session().transport_frame());
+                               ret = 0;
+                       }
+                       // just in case some crazy surface starts sending control values before touch
+                       FakeTouchMap::iterator x = _touch_timeout.find(control);
+                       if (x != _touch_timeout.end()) {
+                               _touch_timeout.erase (x);
+                       }
+               }
+       }
+
+       return ret;
+}
+
+int
+OSC::fake_touch (boost::shared_ptr<ARDOUR::AutomationControl> ctrl)
+{
+       if (ctrl) {
+               //start touch
+               if (ctrl->automation_state() == Touch && !ctrl->touching ()) {
+               ctrl->start_touch (ctrl->session().transport_frame());
+               _touch_timeout[ctrl] = 10;
+               }
+       }
+
+       return 0;
+}
+
 int
 OSC::route_mute (int ssid, int yn, lo_message msg)
 {
@@ -2767,6 +2872,7 @@ OSC::route_set_gain_abs (int ssid, float level, lo_message msg)
 
        if (s) {
                if (s->gain_control()) {
+                       fake_touch (s->gain_control());
                        s->gain_control()->set_value (level, PBD::Controllable::NoGroup);
                } else {
                        return 1;
@@ -2815,6 +2921,7 @@ OSC::sel_gain (float val, lo_message msg)
                        abs = dB_to_coefficient (val);
                }
                if (s->gain_control()) {
+                       fake_touch (s->gain_control());
                        s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
                        return 0;
                }
@@ -2851,6 +2958,7 @@ OSC::sel_fader (float val, lo_message msg)
                float abs;
                abs = slider_position_to_gain_with_max (val, 2.0);
                if (s->gain_control()) {
+                       fake_touch (s->gain_control());
                        s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
                        return 0;
                }
@@ -3696,7 +3804,7 @@ OSC::sel_eq_enable (float val, lo_message msg)
 }
 
 int
-OSC::sel_eq_hpf (float val, lo_message msg)
+OSC::sel_eq_hpf_freq (float val, lo_message msg)
 {
        OSCSurface *sur = get_surface(get_address (msg));
        boost::shared_ptr<Stripable> s;
@@ -3711,7 +3819,102 @@ OSC::sel_eq_hpf (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_hpf", 0, get_address (msg));
+       return sel_fail ("eq_hpf/freq", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_lpf_freq (float val, lo_message msg)
+{
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> s;
+       if (sur->expand_enable) {
+               s = get_strip (sur->expand, get_address (msg));
+       } else {
+               s = _select;
+       }
+       if (s) {
+               if (s->filter_freq_controllable(false)) {
+                       s->filter_freq_controllable(false)->set_value (s->filter_freq_controllable(false)->interface_to_internal (val), PBD::Controllable::NoGroup);
+                       return 0;
+               }
+       }
+       return sel_fail ("eq_lpf/freq", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_hpf_enable (float val, lo_message msg)
+{
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> s;
+       if (sur->expand_enable) {
+               s = get_strip (sur->expand, get_address (msg));
+       } else {
+               s = _select;
+       }
+       if (s) {
+               if (s->filter_enable_controllable(true)) {
+                       s->filter_enable_controllable(true)->set_value (s->filter_enable_controllable(true)->interface_to_internal (val), PBD::Controllable::NoGroup);
+                       return 0;
+               }
+       }
+       return sel_fail ("eq_hpf/enable", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_lpf_enable (float val, lo_message msg)
+{
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> s;
+       if (sur->expand_enable) {
+               s = get_strip (sur->expand, get_address (msg));
+       } else {
+               s = _select;
+       }
+       if (s) {
+               if (s->filter_enable_controllable(false)) {
+                       s->filter_enable_controllable(false)->set_value (s->filter_enable_controllable(false)->interface_to_internal (val), PBD::Controllable::NoGroup);
+                       return 0;
+               }
+       }
+       return sel_fail ("eq_lpf/enable", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_hpf_slope (float val, lo_message msg)
+{
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> s;
+       if (sur->expand_enable) {
+               s = get_strip (sur->expand, get_address (msg));
+       } else {
+               s = _select;
+       }
+       if (s) {
+               if (s->filter_slope_controllable(true)) {
+                       s->filter_slope_controllable(true)->set_value (s->filter_slope_controllable(true)->interface_to_internal (val), PBD::Controllable::NoGroup);
+                       return 0;
+               }
+       }
+       return sel_fail ("eq_hpf/slope", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_lpf_slope (float val, lo_message msg)
+{
+       OSCSurface *sur = get_surface(get_address (msg));
+       boost::shared_ptr<Stripable> s;
+       if (sur->expand_enable) {
+               s = get_strip (sur->expand, get_address (msg));
+       } else {
+               s = _select;
+       }
+       if (s) {
+               if (s->filter_slope_controllable(false)) {
+                       s->filter_slope_controllable(false)->set_value (s->filter_slope_controllable(false)->interface_to_internal (val), PBD::Controllable::NoGroup);
+                       return 0;
+               }
+       }
+       return sel_fail ("eq_lpf/slope", 0, get_address (msg));
 }
 
 int
@@ -3884,6 +4087,17 @@ OSC::periodic (void)
                        co->tick();
                }
        }
+       for (FakeTouchMap::iterator x = _touch_timeout.begin(); x != _touch_timeout.end();) {
+               _touch_timeout[(*x).first] = (*x).second - 1;
+               if (!(*x).second) {
+                       boost::shared_ptr<ARDOUR::AutomationControl> ctrl = (*x).first;
+                       // turn touch off
+                       ctrl->stop_touch (true, ctrl->session().transport_frame());
+                       _touch_timeout.erase (x++);
+               } else {
+                       x++;
+               }
+       }
        return true;
 }