OSC: set Automation mode for fader
[ardour.git] / libs / surfaces / osc / osc.cc
index a0985f7850bd8a49b78860346cd0fee8a3833c94..f97bdf55a57db12fe7312d3b59784974cdcf880c 100644 (file)
@@ -862,6 +862,10 @@ 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);
+
+       } else
        if (len >= 17 && !strcmp (&path[len-15], "/#current_value")) {
                current_value_query (path, len, argv, argc, msg);
                ret = 0;
@@ -2179,6 +2183,99 @@ 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)
+{
+       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 aut = 0;
+
+       //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;
+                       } else {
+                               aut = argv[1]->i;
+                       }
+               } else {
+                       uint32_t 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)) {
+               if (sur->expand_enable && sur->expand) {
+                       strp = get_strip (sur->expand, get_address (msg));
+               } 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) {
+               if ((!strncmp (&path[ctr], "fader", 5)) || (!strncmp (&path[ctr], "gain", 4))) {
+                       if (strp->gain_control ()) {
+                               switch (aut) {
+                                       case 0:
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Off);
+                                               ret = 0;
+                                               break;
+                                       case 'm':
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Off);
+                                               ret = 0;
+                                               break;
+                                       case 1:
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Play);
+                                               ret = 0;
+                                               break;
+                                       case 'p':
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Play);
+                                               ret = 0;
+                                               break;
+                                       case 2:
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Write);
+                                               ret = 0;
+                                               break;
+                                       case 'w':
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Write);
+                                               ret = 0;
+                                               break;
+                                       case 3:
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Touch);
+                                               ret = 0;
+                                               break;
+                                       case 't':
+                                               strp->gain_control()->set_automation_state (ARDOUR::AutoState::Touch);
+                                               ret = 0;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+               }
+       }
+
+       return ret;
+}
+
 int
 OSC::route_mute (int ssid, int yn, lo_message msg)
 {
@@ -4031,21 +4128,21 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
        }
        else if (!strncmp (path, "/cue/connect", 12)) {
                // Connect to default Aux bus
-               if (argv[0]->i) {
+               if ((!argc) || argv[0]->i) {
                        cue_set (1, msg);
                }
                ret = 0;
        }
        else if (!strncmp (path, "/cue/next_aux", 13)) {
                // switch to next Aux bus
-               if (argv[0]->i) {
+               if ((!argc) || argv[0]->i) {
                        cue_next (msg);
                }
                ret = 0;
        }
        else if (!strncmp (path, "/cue/previous_aux", 17)) {
                // switch to previous Aux bus
-               if (argv[0]->i) {
+               if ((!argc) || argv[0]->i) {
                        cue_previous (msg);
                }
                ret = 0;