OSC: set Automation mode for fader
[ardour.git] / libs / surfaces / osc / osc.cc
index 6da35ffc9c2832c82086851c451b11ab7511e4e2..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;
@@ -878,7 +882,6 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                        std::string action_path = path;
 
                        access_action (action_path.substr(15));
-                       std::cout << "access_action path = " << action_path.substr(15) << "\n";
                }
 
                ret = 0;
@@ -1335,7 +1338,8 @@ OSC::clear_devices ()
        for (CueObservers::iterator x = cue_observers.begin(); x != cue_observers.end();) {
                OSCCueObserver* co;
                if ((co = dynamic_cast<OSCCueObserver*>(*x)) != 0) {
-                       delete co;
+                       delete *x;
+                       x = cue_observers.erase (x);
                } else {
                        ++x;
                }
@@ -1806,7 +1810,7 @@ OSC::jog (float delta, lo_message msg)
 
        OSCSurface *s = get_surface(get_address (msg));
 
-       string path = "/jog/mode";
+       string path = "/jog/mode/name";
        switch(s->jogmode)
        {
                case JOG  :
@@ -1912,6 +1916,10 @@ OSC::jog_mode (float mode, lo_message msg)
                default:
                        PBD::warning << "Jog Mode: " << mode << " is not valid." << endmsg;
                        break;
+       lo_message reply = lo_message_new ();
+       lo_message_add_int32 (reply, s->jogmode);
+       lo_send_message (get_address(msg), "/jog/mode", reply);
+       lo_message_free (reply);
 
        }
        jog (0, msg);
@@ -2175,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)
 {
@@ -3993,17 +4094,13 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
                                                sorted.push_back (s);
                                        }
                                }
-                       } else
-                       if (types[3] && (s->presentation_info().flags() & PresentationInfo::MidiBus)) {
+                       } else if (types[3] && (s->presentation_info().flags() & PresentationInfo::MidiBus)) {
                                sorted.push_back (s);
-                       } else
-                       if (types[4] && (s->presentation_info().flags() & PresentationInfo::VCA)) {
+                       } else if (types[4] && (s->presentation_info().flags() & PresentationInfo::VCA)) {
                                sorted.push_back (s);
-                       } else
-                       if (types[8] && (s->presentation_info().flags() & PresentationInfo::Selected)) {
+                       } else if (types[8] && (s->is_selected())) {
                                sorted.push_back (s);
-                       } else
-                       if (types[9] && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
+                       } else if (types[9] && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
                                sorted.push_back (s);
                        }
                }
@@ -4030,18 +4127,24 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
                ret = 0;
        }
        else if (!strncmp (path, "/cue/connect", 12)) {
-               // switch to next Aux bus
-               cue_set (0, msg);
+               // Connect to default Aux bus
+               if ((!argc) || argv[0]->i) {
+                       cue_set (1, msg);
+               }
                ret = 0;
        }
        else if (!strncmp (path, "/cue/next_aux", 13)) {
                // switch to next Aux bus
-               cue_next (msg);
+               if ((!argc) || argv[0]->i) {
+                       cue_next (msg);
+               }
                ret = 0;
        }
        else if (!strncmp (path, "/cue/previous_aux", 17)) {
                // switch to previous Aux bus
-               cue_previous (msg);
+               if ((!argc) || argv[0]->i) {
+                       cue_previous (msg);
+               }
                ret = 0;
        }
        else if (!strncmp (path, "/cue/send/fader/", 16) && strlen (path) > 16) {
@@ -4063,12 +4166,6 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
                ret = 0;
        }
 
-       if ((ret && _debugmode == Unhandled)) {
-               debugmsg (_("Unhandled OSC cue message"), path, types, argv, argc);
-       } else if ((!ret && _debugmode == All)) {
-               debugmsg (_("OSC cue"), path, types, argv, argc);
-       }
-
        return ret;
 }
 
@@ -4087,12 +4184,19 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
        s->feedback = 0;
        s->gainmode = 1;
        s->cue = true;
-       s->aux = aux;
        s->strips = get_sorted_stripables(s->strip_types, s->cue);
 
        s->nstrips = s->strips.size();
+
+       if (aux < 1) {
+               aux = 1;
+       } else if (aux > s->nstrips) {
+               aux = s->nstrips;
+       }
+       s->aux = aux;
+
        // get rid of any old CueObsevers for this address
-       cueobserver_connections.drop_connections ();
+       //cueobserver_connections.drop_connections ();
        CueObservers::iterator x;
        for (x = cue_observers.begin(); x != cue_observers.end();) {
 
@@ -4140,6 +4244,11 @@ int
 OSC::cue_next (lo_message msg)
 {
        OSCSurface *s = get_surface(get_address (msg));
+
+       if (!s->cue) {
+               cue_set (1, msg);
+               return 0;
+       }
        if (s->aux < s->nstrips) {
                cue_set (s->aux + 1, msg);
        } else {
@@ -4152,6 +4261,10 @@ int
 OSC::cue_previous (lo_message msg)
 {
        OSCSurface *s = get_surface(get_address (msg));
+       if (!s->cue) {
+               cue_set (1, msg);
+               return 0;
+       }
        if (s->aux > 1) {
                cue_set (s->aux - 1, msg);
        }