OSC: add /strip/hide
[ardour.git] / libs / surfaces / osc / osc.cc
index 2bfce8ddb1262e6725caafce2e05b11e1ab443f8..a026e0283a5a2e16c027d8870fd6026274be2f42 100644 (file)
@@ -363,9 +363,9 @@ OSC::surface_destroy (OSCSurface* sur)
 
        OSCCueObserver* co;
        if ((co = dynamic_cast<OSCCueObserver*>(sur->cue_obs)) != 0) {
-               co->clear_observer ();
                delete co;
                sur->cue_obs = 0;
+               sur->sends.clear ();
        }
 
        OSCGlobalObserver* go;
@@ -415,6 +415,11 @@ OSC::register_callbacks()
                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, "/strip/custom/mode", "f", custom_mode);
+               REGISTER_CALLBACK (serv, "/strip/custom/clear", "f", custom_clear);
+               REGISTER_CALLBACK (serv, "/strip/custom/clear", "", custom_clear);
+               REGISTER_CALLBACK (serv, "/surface/list", "", surface_list);
+               REGISTER_CALLBACK (serv, "/surface/list", "f", surface_list);
                REGISTER_CALLBACK (serv, "/add_marker", "", add_marker);
                REGISTER_CALLBACK (serv, "/add_marker", "f", add_marker);
                REGISTER_CALLBACK (serv, "/access_action", "s", access_action);
@@ -473,6 +478,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/mark_out", "f", mark_out);
                REGISTER_CALLBACK (serv, "/toggle_click", "", toggle_click);
                REGISTER_CALLBACK (serv, "/toggle_click", "f", toggle_click);
+               REGISTER_CALLBACK (serv, "/click/level", "f", click_level);
                REGISTER_CALLBACK (serv, "/midi_panic", "", midi_panic);
                REGISTER_CALLBACK (serv, "/midi_panic", "f", midi_panic);
                REGISTER_CALLBACK (serv, "/toggle_roll", "", toggle_roll);
@@ -570,6 +576,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/select/fader", "f", sel_fader);
                REGISTER_CALLBACK (serv, "/select/db_delta", "f", sel_dB_delta);
                REGISTER_CALLBACK (serv, "/select/trimdB", "f", sel_trim);
+               REGISTER_CALLBACK (serv, "/select/hide", "i", sel_hide);
                REGISTER_CALLBACK (serv, "/select/pan_stereo_position", "f", sel_pan_position);
                REGISTER_CALLBACK (serv, "/select/pan_stereo_width", "f", sel_pan_width);
                REGISTER_CALLBACK (serv, "/select/send_gain", "if", sel_sendgain);
@@ -579,6 +586,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/select/send_page", "f", sel_send_page);
                REGISTER_CALLBACK (serv, "/select/plug_page", "f", sel_plug_page);
                REGISTER_CALLBACK (serv, "/select/plugin", "f", sel_plugin);
+               REGISTER_CALLBACK (serv, "/select/plugin/activate", "f", sel_plugin_activate);
                REGISTER_CALLBACK (serv, "/select/expand", "i", sel_expand);
                REGISTER_CALLBACK (serv, "/select/pan_elevation_position", "f", sel_pan_elevation);
                REGISTER_CALLBACK (serv, "/select/pan_frontback_position", "f", sel_pan_frontback);
@@ -610,6 +618,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/strip/monitor_input", "ii", route_monitor_input);
                REGISTER_CALLBACK (serv, "/strip/monitor_disk", "ii", route_monitor_disk);
                REGISTER_CALLBACK (serv, "/strip/expand", "ii", strip_expand);
+               REGISTER_CALLBACK (serv, "/strip/hide", "ii", strip_hide);
                REGISTER_CALLBACK (serv, "/strip/select", "ii", strip_gui_select);
                REGISTER_CALLBACK (serv, "/strip/polarity", "ii", strip_phase);
                REGISTER_CALLBACK (serv, "/strip/gain", "if", route_set_gain_dB);
@@ -790,10 +799,15 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
        /* 15 for /#current_value plus 2 for /<path> */
 
        len = strlen (path);
-       /*
-        * not needed until /strip/listen/ignore fixed
-       OSCSurface *sur = get_surface(get_address (msg));
-       */
+       OSCSurface *sur = get_surface(get_address (msg), true);
+       LinkSet *set;
+       uint32_t ls = sur->linkset;
+
+       if (ls) {
+               set = &(link_sets[ls]);
+               sur->custom_mode = set->custom_mode;
+               sur->custom_strips = set->custom_strips;
+       }
 
        if (strstr (path, "/automation")) {
                ret = set_automation (path, types, argv, argc, msg);
@@ -828,56 +842,54 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
 
                ret = 0;
        } else
-/*     if (strcmp (path, "/strip/listen") == 0) {
-               check_surface (msg);
-
-               cerr << "set up listener\n";
-
-               lo_message reply = lo_message_new ();
-
+       if (strcmp (path, "/strip/listen") == 0) {
                if (argc <= 0) {
-                       lo_message_add_string (reply, "syntax error");
+                       PBD::warning << "OSC: Wrong number of parameters." << endmsg;
+               } else if (sur->custom_mode) {
+                       PBD::warning << "OSC: Can't add strips with custom enabled." << endmsg;
                } else {
                        for (int n = 0; n < argc; ++n) {
-
-                               boost::shared_ptr<Route> r = session->get_remote_nth_route (argv[n]->i);
-
-                               if (!r) {
-                                       lo_message_add_string (reply, "not found");
-                                       cerr << "no such route\n";
-                                       break;
-                               } else {
-                                       cerr << "add listener\n";
-                                       listen_to_route (r, get_address (msg));
-                                       lo_message_add_int32 (reply, argv[n]->i);
+                               boost::shared_ptr<Stripable> s = boost::shared_ptr<Stripable>();
+                               if (types[n] == 'f') {
+                                       s = get_strip ((uint32_t) argv[n]->f, get_address (msg));
+                               } else if (types[n] == 'i') {
+                                       s = get_strip (argv[n]->i, get_address (msg));
+                               }
+                               if (s) {
+                                       sur->custom_strips.push_back (s);
                                }
                        }
+                       if (ls) {
+                               set->custom_strips = sur->custom_strips;
+                       }
                }
-
-               if (sur->feedback[14]) {
-                       lo_send_message (get_address (msg), "/reply", reply);
-               } else {
-                       lo_send_message (get_address (msg), "#reply", reply);
-               }
-               lo_message_free (reply);
-
                ret = 0;
-
        } else
        if (strcmp (path, "/strip/ignore") == 0) {
-               check_surface (msg);
-
-               for (int n = 0; n < argc; ++n) {
-
-                       boost::shared_ptr<Route> r = session->get_remote_nth_route (argv[n]->i);
-
-                       if (r) {
-                               end_listen (r, get_address (msg));
+               if (argc <= 0) {
+                       PBD::warning << "OSC: Wrong number of parameters." << endmsg;
+               } else if (!sur->custom_mode) {
+                       PBD::warning << "OSC: Can't remove strips without custom enabled." << endmsg;
+               } else {
+                       for (int n = 0; n < argc; ++n) {
+                               uint32_t st_no = 0;
+                               if (types[n] == 'f') {
+                                       st_no = (uint32_t) argv[n]->f;
+                               } else if (types[n] == 'i') {
+                                       st_no = (uint32_t) argv[n]->i;
+                               }
+                               if (st_no && st_no <= sur->custom_strips.size ()) {
+                                       sur->custom_strips[argv[n]->i - 1] = boost::shared_ptr<Stripable>();
+                               }
+                       }
+                       if (ls) {
+                               set->custom_strips = sur->custom_strips;
                        }
+                       ret = set_bank (sur->bank, msg);
                }
 
                ret = 0;
-       } else */
+       } else
        if (strstr (path, "/strip") && (argc != 1)) {
                // All of the strip commands below require 1 parameter
                PBD::warning << "OSC: Wrong number of parameters." << endmsg;
@@ -952,6 +964,10 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                int ssid = atoi (&path[14]);
                ret = strip_expand (ssid, argv[0]->i, msg);
        }
+       else if (!strncmp (path, "/strip/hide/", 12) && strlen (path) > 12) {
+               int ssid = atoi (&path[12]);
+               ret = strip_hide (ssid, argv[0]->i, msg);
+       }
        else if (!strncmp (path, "/strip/select/", 14) && strlen (path) > 14) {
                int ssid = atoi (&path[14]);
                ret = strip_gui_select (ssid, argv[0]->i, msg);
@@ -988,9 +1004,15 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                int ssid = atoi (&path[17]);
                ret = sel_eq_shape (ssid, argv[0]->f, msg);
        }
+       else if (!strncmp (path, "/marker", 7)) {
+               ret = set_marker (types, argv, argc, msg);
+       }
        else if (!strncmp (path, "/set_surface", 12)) {
                ret = surface_parse (path, types, argv, argc, msg);
        }
+       else if (strstr (path, "/link")) {
+               ret = parse_link (path, types, argv, argc, msg);
+       }
        if (ret) {
                check_surface (msg);
        }
@@ -1241,8 +1263,131 @@ OSC::routes_list (lo_message msg)
        // send feedback for newly created control surface
        strip_feedback (sur, true);
        global_feedback (sur);
-       _strip_select (0, get_address (msg));
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
+
+}
+
+void
+OSC::surface_list (lo_message msg)
+{
+               get_surfaces ();
+}
+
+void
+OSC::get_surfaces ()
+{
+
+       /* this function is for debugging and prints lots of
+        * information about what surfaces Ardour knows about and their
+        * internal parameters. It is best accessed by sending:
+        * /surface/list from oscsend. This command does not create
+        * a surface entry.
+        */
+
+       PBD::info << string_compose ("\nList of known Surfaces (%1):\n", _surface.size());
+
+       Glib::Threads::Mutex::Lock lm (surfaces_lock);
+       for (uint32_t it = 0; it < _surface.size(); it++) {
+               OSCSurface* sur = &_surface[it];
+               PBD::info << string_compose ("\n  Surface: %1 - URL: %2\n", it, sur->remote_url);
+               PBD::info << string_compose ("  Number of strips: %1   Bank size: %2   Current Bank %3\n", sur->nstrips, sur->bank_size, sur->bank);
+               PBD::info << string_compose ("  Use Custom: %1   Custom Strips: %2\n", sur->custom_mode, sur->custom_strips.size ());
+               bool ug = false;
+               if (sur->usegroup == PBD::Controllable::UseGroup) {
+                       ug = true;
+               }
+               PBD::info << string_compose ("  Strip Types: %1   Feedback: %2   No_clear flag: %3   Gain mode: %4   Use groups flag %5\n", \
+                       sur->strip_types.to_ulong(), sur->feedback.to_ulong(), sur->no_clear, sur->gainmode, ug);
+               PBD::info << string_compose ("  Using plugin: %1  of  %2 plugins, with %3 params.  Page size: %4  Page: %5\n", \
+                       sur->plugin_id, sur->plugins.size(), sur->plug_params.size(), sur->plug_page_size, sur->plug_page);
+               PBD::info << string_compose ("  Send page size: %1  Page: %2\n", sur->send_page_size, sur->send_page);
+               PBD::info << string_compose ("  Expanded flag %1   Track: %2   Jogmode: %3\n", sur->expand_enable, sur->expand, sur->jogmode);
+               PBD::info << string_compose ("  Personal monitor flag %1,   Aux master: %2,   Number of sends: %3\n", sur->cue, sur->aux, sur->sends.size());
+               PBD::info << string_compose ("  Linkset: %1   Device Id: %2\n", sur->linkset, sur->linkid);
+       }
+       PBD::info << string_compose ("\nList of LinkSets (%1):\n", link_sets.size());
+       std::map<uint32_t, LinkSet>::iterator it;
+       for (it = link_sets.begin(); it != link_sets.end(); it++) {
+               if (!(*it).first) {
+                       continue;
+               }
+               uint32_t devices = 0;
+               LinkSet* set = &(*it).second;
+               if (set->urls.size()) {
+                       devices = set->urls.size() - 1;
+               }
+               PBD::info << string_compose ("\n  Linkset %1 has %2 devices and sees %3 strips\n", (*it).first, devices, set->strips.size());
+               PBD::info << string_compose ("  Bank size: %1   Current bank: %2   Strip Types: %3\n", set->banksize, set->bank, set->strip_types.to_ulong());
+               PBD::info << string_compose ("  Auto bank sizing: %1 Linkset not ready flag: %2\n", set->autobank, set->not_ready);
+               PBD::info << string_compose ("  Use Custom: %1 Number of Custom Strips: %2\n", set->custom_mode, set->custom_strips.size ());
+       }
+       PBD::info << endmsg;
+}
 
+int
+OSC::custom_clear (lo_message msg)
+{
+       if (!session) {
+               return 0;
+       }
+       OSCSurface *sur = get_surface(get_address (msg), true);
+       sur->custom_mode = 0;
+       sur->custom_strips.clear ();
+       sur->strips = get_sorted_stripables(sur->strip_types, sur->cue, false, sur->custom_strips);
+       sur->nstrips = sur->strips.size();
+       LinkSet *set;
+       uint32_t ls = sur->linkset;
+       if (ls) {
+               set = &(link_sets[ls]);
+               set->custom_mode = 0;
+               set->custom_strips.clear ();
+               set->strips = sur->strips;
+       }
+       return set_bank (1, msg);
+}
+
+int
+OSC::custom_mode (float state, lo_message msg)
+{
+       if (!session) {
+               return 0;
+       }
+       OSCSurface *sur = get_surface(get_address (msg), true);
+       LinkSet *set;
+       uint32_t ls = sur->linkset;
+
+       if (ls) {
+               set = &(link_sets[ls]);
+               sur->custom_mode = set->custom_mode;
+               sur->custom_strips = set->custom_strips;
+       }
+       if (state > 0){
+               if (sur->custom_strips.size () == 0) {
+                       PBD::warning << "No custom strips set to enable" << endmsg;
+                       sur->custom_mode = 0;
+                       if (ls) {
+                               set->custom_mode = 0;
+                       }
+                       return -1;
+               } else {
+                       if (sur->bank_size) {
+                               sur->custom_mode = (uint32_t) state | 0x4;
+                       } else {
+                               sur->custom_mode = (uint32_t) state;
+                       }
+                       sur->strips = get_sorted_stripables(sur->strip_types, sur->cue, sur->custom_mode, sur->custom_strips);
+                       sur->nstrips = sur->custom_strips.size();
+               }
+       } else {
+               sur->custom_mode = 0;
+               sur->strips = get_sorted_stripables(sur->strip_types, sur->cue, 0, sur->custom_strips);
+               sur->nstrips = sur->strips.size();
+       }
+       if (ls) {
+               set->custom_mode = sur->custom_mode;
+               set->strips = sur->strips;
+       }
+       return set_bank (1, msg);
 }
 
 int
@@ -1294,6 +1439,7 @@ OSC::clear_devices ()
                surface_destroy (sur);
        }
        _surface.clear();
+       link_sets.clear ();
 
        PresentationInfo::Change.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
 
@@ -1301,6 +1447,214 @@ OSC::clear_devices ()
        tick = true;
 }
 
+int
+OSC::parse_link (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
+{
+       int ret = 1; /* unhandled */
+       int set = 0;
+       if (!argc) {
+               PBD::warning << "OSC: /link/* needs at least one parameter" << endmsg;
+               return ret;
+       }
+       float data = 0;
+       if (types[argc - 1] == 'f') {
+               data = argv[argc - 1]->f;
+       } else {
+               data = argv[argc - 1]->i;
+       }
+       if (isdigit(strrchr (path, '/')[1])) {
+               set = atoi (&(strrchr (path, '/')[1]));
+       } else if (argc == 2) {
+               if (types[0] == 'f') {
+                       set = (int) argv[0]->f;
+               } else {
+                       set = argv[0]->i;
+               }
+       } else {
+               PBD::warning << "OSC: wrong number of parameters." << endmsg;
+               return ret;
+       }
+       LinkSet *ls = get_linkset (set, get_address (msg));
+
+       if (!set) {
+               return 0;
+       }
+       if (!strncmp (path, "/link/bank_size", 15)) {
+               ls->banksize = (uint32_t) data;
+               ls->autobank = false;
+               ls->not_ready = link_check (set);
+               if (ls->not_ready) {
+                       ls->bank = 1;
+                       surface_link_state (ls);
+               } else {
+                       _set_bank (ls->bank, get_address (msg));
+               }
+               ret = 0;
+
+       } else if (!strncmp (path, "/link/set", 9)) {
+               ret = set_link (set, (uint32_t) data, get_address (msg));
+       }
+
+       return ret;
+}
+
+OSC::LinkSet *
+OSC::get_linkset (uint32_t set, lo_address addr)
+{
+       OSCSurface *sur = get_surface(addr);
+       LinkSet *ls = 0;
+
+       if (set) {
+               // need to check if set is wanted
+               std::map<uint32_t, LinkSet>::iterator it;
+               it = link_sets.find(set);
+               if (it == link_sets.end()) {
+                       // no such linkset make it
+                       LinkSet new_ls;
+                       new_ls.banksize = 0;
+                       new_ls.bank = 1;
+                       new_ls.autobank = true;
+                       new_ls.not_ready = true;
+                       new_ls.strip_types = sur->strip_types;
+                       new_ls.strips = sur->strips;
+                       new_ls.custom_strips = sur->custom_strips;
+                       new_ls.custom_mode = sur->custom_mode;
+                       new_ls.urls.resize (2);
+                       link_sets[set] = new_ls;
+               }
+               ls = &link_sets[set];
+
+       } else {
+               // User expects this surface to be removed from any sets
+               uint32_t oldset = sur->linkset;
+               if (oldset) {
+                       uint32_t oldid = sur->linkid;
+                       sur->linkid = 1;
+                       sur->linkset = 0;
+                       LinkSet *ols = &link_sets[oldset];
+                       if (ols) {
+                               ols->not_ready = oldid;
+                               ols->urls[oldid] = "";
+                               surface_link_state (ols);
+                       }
+               }
+       }
+       return ls;
+}
+
+int
+OSC::set_link (uint32_t set, uint32_t id, lo_address addr)
+{
+       OSCSurface *sur = get_surface(addr, true);
+       sur->linkset = set;
+       sur->linkid = id;
+       LinkSet *ls = get_linkset (set, addr);
+       if (ls->urls.size() <= (uint32_t) id) {
+               ls->urls.resize ((int) id + 1);
+       }
+       ls->urls[(uint32_t) id] = sur->remote_url;
+       ls->not_ready = link_check (set);
+       if (ls->not_ready) {
+               surface_link_state (ls);
+       } else {
+               _set_bank (1, addr);
+       }
+       return 0;
+}
+
+void
+OSC::link_strip_types (uint32_t linkset, uint32_t striptypes)
+{
+       LinkSet *ls = 0;
+
+       if (!linkset) {
+               return;
+       }
+       std::map<uint32_t, LinkSet>::iterator it;
+       it = link_sets.find(linkset);
+       if (it == link_sets.end()) {
+               // this should never happen... but
+               return;
+       }
+       ls = &link_sets[linkset];
+       ls->strip_types = striptypes;
+       for (uint32_t dv = 1; dv < ls->urls.size(); dv++) {
+               OSCSurface *su;
+
+               if (ls->urls[dv] != "") {
+                       string url = ls->urls[dv];
+                       su = get_surface (lo_address_new_from_url (url.c_str()), true);
+                       if (su->linkset == linkset) {
+                               su->strip_types = striptypes;
+                               if (su->strip_types[10]) {
+                                       su->usegroup = PBD::Controllable::UseGroup;
+                               } else {
+                                       su->usegroup = PBD::Controllable::NoGroup;
+                               }
+                       } else {
+                               ls->urls[dv] = "";
+                       }
+               }
+       }
+}
+
+void
+OSC::surface_link_state (LinkSet * set)
+{
+       for (uint32_t dv = 1; dv < set->urls.size(); dv++) {
+
+               if (set->urls[dv] != "") {
+                       string url = set->urls[dv];
+                       OSCSurface *sur = get_surface (lo_address_new_from_url (url.c_str()), true);
+                       for (uint32_t i = 0; i < sur->observers.size(); i++) {
+                               sur->observers[i]->set_link_ready (set->not_ready);
+                       }
+               }
+       }
+}
+
+int
+OSC::link_check (uint32_t set)
+{
+       LinkSet *ls = 0;
+
+       if (!set) {
+               return 1;
+       }
+       std::map<uint32_t, LinkSet>::iterator it;
+       it = link_sets.find(set);
+       if (it == link_sets.end()) {
+               // this should never happen... but
+               return 1;
+       }
+       ls = &link_sets[set];
+       uint32_t bank_total = 0;
+       for (uint32_t dv = 1; dv < ls->urls.size(); dv++) {
+               OSCSurface *su;
+
+               if (ls->urls[dv] != "") {
+                       string url = ls->urls[dv];
+                       su = get_surface (lo_address_new_from_url (url.c_str()), true);
+               } else {
+                       return dv;
+               }
+               if (su->linkset == set) {
+                       bank_total = bank_total + su->bank_size;
+               } else {
+                       ls->urls[dv] = "";
+                       return dv;
+               }
+               if (ls->autobank) {
+                       ls->banksize = bank_total;
+               } else {
+                       if (bank_total != ls->banksize) {
+                               return ls->urls.size();
+                       }
+               }
+       }
+       return 0;
+}
+
 int
 OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
 {
@@ -1312,6 +1666,8 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
        int feedback = sur->feedback.to_ulong();
        int strip_types = sur->strip_types.to_ulong();
        int bank_size = sur->bank_size;
+       int linkset = sur->linkset;
+       int linkid = sur->linkid;
 
 
        if (argc == 1 && !strncmp (path, "/set_surface/feedback", 21)) {
@@ -1359,6 +1715,18 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
 
                // command is in /set_surface iii form
                switch (argc) {
+                       case 8:
+                               if (types[7] == 'f') {
+                                       linkid = (int) argv[7]->f;
+                               } else {
+                                       linkid = argv[7]->i;
+                               }
+                       case 7:
+                               if (types[6] == 'f') {
+                                       linkset = (int) argv[6]->f;
+                               } else {
+                                       linkset = argv[6]->i;
+                               }
                        case 6:
                                if (types[5] == 'f') {
                                        pi_page = (int) argv[5]->f;
@@ -1396,6 +1764,9 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
                                        bank_size = argv[0]->i;
                                }
                                ret = set_surface (bank_size, strip_types, feedback, fadermode, se_page, pi_page, msg);
+                               if ((uint32_t) linkset != sur->linkset) {
+                                       set_link (linkset, linkid, get_address (msg));
+                               }
                                break;
                        case 0:
                                // send current setup
@@ -1407,6 +1778,8 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
                                        lo_message_add_int32 (reply, fadermode);
                                        lo_message_add_int32 (reply, se_page);
                                        lo_message_add_int32 (reply, pi_page);
+                                       lo_message_add_int32 (reply, (int) linkset);
+                                       lo_message_add_int32 (reply, (int) linkid);
                                        lo_send_message (get_address (msg), "/set_surface", reply);
                                        lo_message_free (reply);
                                        return 0;
@@ -1436,6 +1809,26 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
                                                const char * pp = strstr (&sp[1], "/");
                                                if (pp) {
                                                        pi_page = atoi (&pp[1]);
+                                                       const char * ls = strstr (&pp[1], "/");
+                                                       if (ls) {
+                                                               linkset = atoi (&ls[1]);
+                                                               const char * li = strstr (&ls[1], "/");
+                                                               if (li) {
+                                                                       linkid = atoi (&li[1]);
+                                                               } else {
+                                                                       if (types[0] == 'f') {
+                                                                               linkid = (int) argv[0]->f;
+                                                                       } else if (types[0] == 'i') {
+                                                                               linkid = argv[0]->i;
+                                                                       }
+                                                               }
+                                                       } else {
+                                                               if (types[0] == 'f') {
+                                                                       linkset = (int) argv[0]->f;
+                                                               } else if (types[0] == 'i') {
+                                                                       linkset = argv[0]->i;
+                                                               }
+                                                       }
                                                } else {
                                                        if (types[0] == 'f') {
                                                                pi_page = (int) argv[0]->f;
@@ -1472,6 +1865,9 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
                        }
                }
                ret = set_surface (bank_size, strip_types, feedback, fadermode, se_page, pi_page, msg);
+               if ((uint32_t) linkset != sur->linkset) {
+                       set_link (linkset, linkid, get_address (msg));
+               }
        }
        return ret;
 }
@@ -1484,6 +1880,9 @@ OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, ui
        }
        OSCSurface *s = get_surface(get_address (msg), true);
        s->bank_size = b_size;
+       if (s->custom_mode && b_size) {
+               s->custom_mode = s->custom_mode | 0x4;
+       }
        s->strip_types = strips;
        s->feedback = fb;
        s->gainmode = gm;
@@ -1494,11 +1893,16 @@ OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, ui
        }
        s->send_page_size = se_size;
        s->plug_page_size = pi_size;
-       // set bank and strip feedback
-       strip_feedback(s, true);
+       if (s->linkset) {
+               set_link (s->linkset, s->linkid, get_address (msg));
+               link_strip_types (s->linkset, s->strip_types.to_ulong());
+       } else {
+               // set bank and strip feedback
+               strip_feedback(s, true);
+               _set_bank (1, get_address (msg));
+       }
 
        global_feedback (s);
-       _strip_select (0, get_address (msg));
        sel_send_pagesize (se_size, msg);
        sel_plug_pagesize (pi_size, msg);
        return 0;
@@ -1512,11 +1916,15 @@ OSC::set_surface_bank_size (uint32_t bs, lo_message msg)
        }
        OSCSurface *s = get_surface(get_address (msg), true);
        s->bank_size = bs;
-       s->bank = 1;
-
-       // set bank and strip feedback
-       strip_feedback (s, true);
-       _strip_select (0, get_address (msg));
+       if (s->custom_mode && bs) {
+               s->custom_mode = s->custom_mode | 0x4;
+       }
+       if (s->linkset) {
+               set_link (s->linkset, s->linkid, get_address (msg));
+       } else {
+               // set bank and strip feedback
+               _set_bank (1, get_address (msg));
+       }
        return 0;
 }
 
@@ -1533,11 +1941,12 @@ OSC::set_surface_strip_types (uint32_t st, lo_message msg)
        } else {
                s->usegroup = PBD::Controllable::NoGroup;
        }
+       if (s->linkset) {
+               link_strip_types (s->linkset, st);
+       }
 
        // set bank and strip feedback
-       s->bank = 1;
-       strip_feedback (s, true);
-       _strip_select (0, get_address (msg));
+       _set_bank (1, get_address (msg));
        return 0;
 }
 
@@ -1551,9 +1960,9 @@ OSC::set_surface_feedback (uint32_t fb, lo_message msg)
        OSCSurface *s = get_surface(get_address (msg), true);
        s->feedback = fb;
 
-       strip_feedback (s, false);
+       strip_feedback (s, true);
        global_feedback (s);
-       _strip_select (0, get_address (msg));
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
@@ -1566,9 +1975,9 @@ OSC::set_surface_gainmode (uint32_t gm, lo_message msg)
        OSCSurface *s = get_surface(get_address (msg), true);
        s->gainmode = gm;
 
-       strip_feedback (s, false);
+       strip_feedback (s, true);
        global_feedback (s);
-       _strip_select (0, get_address (msg));
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
@@ -1598,7 +2007,7 @@ OSC::get_surface (lo_address addr , bool quiet)
        free (rurl);
        {
                for (uint32_t it = 0; it < _surface.size(); ++it) {
-                       //find setup for this server
+                       //find setup for this surface
                        if (!_surface[it].remote_url.find(r_url)){
                                return &_surface[it];
                        }
@@ -1619,18 +2028,22 @@ OSC::get_surface (lo_address addr , bool quiet)
        s.feedback = default_feedback;
        s.gainmode = default_gainmode;
        s.usegroup = PBD::Controllable::NoGroup;
+       s.custom_strips.clear ();
+       s.custom_mode = 0;
        s.sel_obs = 0;
        s.expand = 0;
        s.expand_enable = false;
        s.cue = false;
        s.aux = 0;
        s.cue_obs = 0;
-       s.strips = get_sorted_stripables(s.strip_types, s.cue);
+       s.strips = get_sorted_stripables(s.strip_types, s.cue, false, s.custom_strips);
        s.send_page = 1;
        s.send_page_size = default_send_size;
        s.plug_page = 1;
        s.plug_page_size = default_plugin_size;
        s.plugin_id = 1;
+       s.linkset = 0;
+       s.linkid = 1;
 
        s.nstrips = s.strips.size();
        {
@@ -1640,7 +2053,7 @@ OSC::get_surface (lo_address addr , bool quiet)
        if (!quiet) {
                strip_feedback (&s, true);
                global_feedback (&s);
-               _strip_select (0, addr);
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr);
        }
 
        return &_surface[_surface.size() - 1];
@@ -1650,6 +2063,8 @@ OSC::get_surface (lo_address addr , bool quiet)
 void
 OSC::global_feedback (OSCSurface* sur)
 {
+       OSCGlobalObserver* o = sur->global_obs;
+       delete o;
        if (sur->feedback[4] || sur->feedback[3] || sur->feedback[5] || sur->feedback[6]) {
 
                // create a new Global Observer for this surface
@@ -1661,8 +2076,26 @@ OSC::global_feedback (OSCSurface* sur)
 void
 OSC::strip_feedback (OSCSurface* sur, bool new_bank_size)
 {
-       sur->strips = get_sorted_stripables(sur->strip_types, sur->cue);
+       LinkSet *set;
+       uint32_t ls = sur->linkset;
+
+       if (ls) {
+               set = &(link_sets[ls]);
+               if (set->not_ready) {
+                       return;
+               }
+               sur->custom_mode = set->custom_mode;
+               sur->custom_strips = set->custom_strips;
+       }
+       if (sur->custom_strips.size () == 0) {
+               sur->custom_mode = 0;
+       }
+       sur->strips = get_sorted_stripables(sur->strip_types, sur->cue, sur->custom_mode, sur->custom_strips);
        sur->nstrips = sur->strips.size();
+       if (ls) {
+               set->strips = sur->strips;
+       }
+
        if (new_bank_size || (!sur->feedback[0] && !sur->feedback[1])) {
                // delete old observers
                for (uint32_t i = 0; i < sur->observers.size(); i++) {
@@ -1673,7 +2106,6 @@ OSC::strip_feedback (OSCSurface* sur, bool new_bank_size)
                }
                sur->observers.clear();
 
-               // get freash striplist - just in case
                uint32_t bank_size = sur->bank_size;
                if (!bank_size) {
                        bank_size = sur->nstrips;
@@ -1688,7 +2120,8 @@ OSC::strip_feedback (OSCSurface* sur, bool new_bank_size)
        } else {
                if (sur->feedback[0] || sur->feedback[1]) {
                        for (uint32_t i = 0; i < sur->observers.size(); i++) {
-                               sur->observers[i]->refresh_strip(true);
+                               boost::shared_ptr<ARDOUR::Stripable> str = get_strip (i + 1, lo_address_new_from_url (sur->remote_url.c_str()));
+                               sur->observers[i]->refresh_strip(str, true);
                        }
                }
        }
@@ -1740,7 +2173,6 @@ OSC::_recalcbanks ()
                OSCSurface* sur = &_surface[it];
                // find lo_address
                lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
-               _strip_select (0, addr);
                if (sur->cue) {
                        _cue_set (sur->aux, addr);
                } else if (!sur->bank_size) {
@@ -1753,6 +2185,7 @@ OSC::_recalcbanks ()
                } else {
                        strip_feedback (sur, false);
                }
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr);
        }
 }
 
@@ -1769,58 +2202,122 @@ OSC::_set_bank (uint32_t bank_start, lo_address addr)
        if (!session) {
                return -1;
        }
-       // no nstripables yet
        if (!session->nroutes()) {
                return -1;
        }
 
-       OSCSurface *s = get_surface (addr);
+       OSCSurface *s = get_surface (addr, true);
 
-       // revert any expand to select
-        s->expand = 0;
-        s->expand_enable = false;
-       _strip_select (0, addr);
+       Sorted striplist = s->strips;
+       uint32_t nstrips = s->nstrips;
 
-       s->strips = get_sorted_stripables(s->strip_types, s->cue);
-       s->nstrips = s->strips.size();
+       LinkSet *set;
+       uint32_t ls = s->linkset;
+
+       if (ls) {
+               //we have a linkset... deal with each surface
+               set = &(link_sets[ls]);
+               if (set->not_ready) {
+                       return 1;
+               }
+               uint32_t d_count = set->urls.size();
+               set->strips = striplist;
+               bank_start = bank_limits_check (bank_start, set->banksize, nstrips);
+               set->bank = bank_start;
+               uint32_t not_ready = 0;
+               for (uint32_t dv = 1; dv < d_count; dv++) {
+                       OSCSurface *sur;
+                       if (set->urls[dv] != "") {
+                               string url = set->urls[dv];
+                               sur = get_surface (lo_address_new_from_url (url.c_str()));
+                       } else {
+                               not_ready = dv;
+                       }
+                       if (sur->linkset != ls) {
+                               set->urls[dv] = "";
+                               not_ready = dv;
+                       }
+                       if (not_ready) {
+                               if (!set->not_ready) {
+                                       set->not_ready = not_ready;
+                               }
+                               set->bank = 1;
+                               break;
+                       }
+                       lo_address sur_addr = lo_address_new_from_url (sur->remote_url.c_str());
+
+                       sur->bank = bank_start;
+                       bank_start = bank_start + sur->bank_size;
+                       strip_feedback (sur, false);
+                       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), sur_addr);
+                       bank_leds (sur);
+                       lo_address_free (sur_addr);
+               }
+               if (not_ready) {
+                       surface_link_state (set);
+               }
 
-       uint32_t b_size;
-       if (!s->bank_size) {
-               // no banking - bank includes all stripables
-               b_size = s->nstrips;
        } else {
-               b_size = s->bank_size;
-       }
 
-       // Do limits checking
-       if (bank_start < 1) bank_start = 1;
-       if (b_size >= s->nstrips)  {
-               bank_start = 1;
-       } else if (bank_start > ((s->nstrips - b_size) + 1)) {
-               // top bank is always filled if there are enough strips for at least one bank
-               bank_start = (uint32_t)((s->nstrips - b_size) + 1);
+               s->bank = bank_limits_check (bank_start, s->bank_size, nstrips);
+               strip_feedback (s, true);
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr);
+               bank_leds (s);
        }
-       //save bank after bank limit checks
-       s->bank = bank_start;
 
-       if (s->feedback[0] || s->feedback[1]) {
-               strip_feedback (s, false);
-       }
-       bank_leds (s);
+
        bank_dirty = false;
        tick = true;
        return 0;
 }
 
+uint32_t
+OSC::bank_limits_check (uint32_t bank, uint32_t size, uint32_t total)
+{
+       uint32_t b_size;
+       if (!size) {
+               // no banking - bank includes all stripables
+               b_size = total;
+       } else {
+               b_size = size;
+       }
+       // Do limits checking
+       if (bank < 1) bank = 1;
+       if (b_size >= total)  {
+               bank = 1;
+       } else if (bank > ((total - b_size) + 1)) {
+               // top bank is always filled if there are enough strips for at least one bank
+               bank = (uint32_t)((total - b_size) + 1);
+       }
+       return bank;
+}
+
 void
 OSC::bank_leds (OSCSurface* s)
 {
+       uint32_t bank = 0;
+       uint32_t size = 0;
+       uint32_t total = 0;
        // light bankup or bankdown buttons if it is possible to bank in that direction
        lo_address addr = lo_address_new_from_url (s->remote_url.c_str());
-       if (s->feedback[4] && !s->no_clear) {
+       if (s->linkset) {
+               LinkSet *set;
+               set = &(link_sets[s->linkset]);
+               bank = set->bank;
+               size = set->banksize;
+               total = s->nstrips;
+               if (set->not_ready) {
+                       total = 1;
+               }
+       } else {
+               bank = s->bank;
+               size = s->bank_size;
+               total = s->nstrips;
+       }
+       if (size && (s->feedback[0] || s->feedback[1] || s->feedback[4])) {
                lo_message reply;
                reply = lo_message_new ();
-               if ((s->bank > (s->nstrips - s->bank_size)) || (s->nstrips < s->bank_size)) {
+               if ((total <= size) || (bank > (total - size))) {
                        lo_message_add_int32 (reply, 0);
                } else {
                        lo_message_add_int32 (reply, 1);
@@ -1828,7 +2325,7 @@ OSC::bank_leds (OSCSurface* s)
                lo_send_message (addr, "/bank_up", reply);
                lo_message_free (reply);
                reply = lo_message_new ();
-               if (s->bank > 1) {
+               if (bank > 1) {
                        lo_message_add_int32 (reply, 1);
                } else {
                        lo_message_add_int32 (reply, 0);
@@ -1841,12 +2338,7 @@ OSC::bank_leds (OSCSurface* s)
 int
 OSC::bank_up (lo_message msg)
 {
-       if (!session) {
-               return -1;
-       }
-       OSCSurface *s = get_surface(get_address (msg));
-       set_bank (s->bank + s->bank_size, msg);
-       return 0;
+       return bank_delta (1.0, msg);
 }
 
 int
@@ -1855,12 +2347,34 @@ OSC::bank_delta (float delta, lo_message msg)
        if (!session) {
                return -1;
        }
+       // only do deltas of -1 0 or 1
+       if (delta > 0) {
+               delta = 1;
+       } else if (delta < 0) {
+               delta = -1;
+       } else {
+               // 0  key release ignore
+               return 0;
+       }
        OSCSurface *s = get_surface(get_address (msg));
-       uint32_t new_bank = s->bank + (s->bank_size * (int) delta);
+       if (!s->bank_size) {
+               // bank size of 0 means use all strips no banking
+               return 0;
+       }
+       uint32_t old_bank = 0;
+       uint32_t bank_size = 0;
+       if (s->linkset) {
+               old_bank = link_sets[s->linkset].bank;
+               bank_size = link_sets[s->linkset].banksize;
+       } else {
+               old_bank = s->bank;
+               bank_size = s->bank_size;
+       }
+       uint32_t new_bank = old_bank + (bank_size * (int) delta);
        if ((int)new_bank < 1) {
                new_bank = 1;
        }
-       if (new_bank != s->bank) {
+       if (new_bank != old_bank) {
                set_bank (new_bank, msg);
        }
        return 0;
@@ -1869,16 +2383,7 @@ OSC::bank_delta (float delta, lo_message msg)
 int
 OSC::bank_down (lo_message msg)
 {
-       if (!session) {
-               return -1;
-       }
-       OSCSurface *s = get_surface(get_address (msg));
-       if (s->bank < s->bank_size) {
-               set_bank (1, msg);
-       } else {
-               set_bank (s->bank - s->bank_size, msg);
-       }
-       return 0;
+       return bank_delta (-1.0, msg);
 }
 
 int
@@ -1942,7 +2447,7 @@ OSC::sel_send_pagesize (uint32_t size, lo_message msg)
        OSCSurface *s = get_surface(get_address (msg));
        if  (size != s->send_page_size) {
                s->send_page_size = size;
-               s->sel_obs->renew_sends();
+               s->sel_obs->set_send_size(size);
        }
        return 0;
 }
@@ -1951,8 +2456,18 @@ int
 OSC::sel_send_page (int page, lo_message msg)
 {
        OSCSurface *s = get_surface(get_address (msg));
+       uint32_t send_size = s->send_page_size;
+       if (!send_size) {
+               send_size = s->nsends;
+       }
+       uint32_t max_page = (uint32_t)(s->nsends / send_size) + 1;
        s->send_page = s->send_page + page;
-       s->sel_obs->renew_sends();
+       if (s->send_page < 1) {
+               s->send_page = 1;
+       } else if ((uint32_t)s->send_page > max_page) {
+               s->send_page = max_page;
+       }
+       s->sel_obs->set_send_page (s->send_page);
        return 0;
 }
 
@@ -1962,7 +2477,7 @@ OSC::sel_plug_pagesize (uint32_t size, lo_message msg)
        OSCSurface *s = get_surface(get_address (msg));
        if (size != s->plug_page_size) {
                s->plug_page_size = size;
-               s->sel_obs->renew_plugin();
+               s->sel_obs->set_plugin_size(size);
        }
        return 0;
 }
@@ -1970,15 +2485,35 @@ OSC::sel_plug_pagesize (uint32_t size, lo_message msg)
 int
 OSC::sel_plug_page (int page, lo_message msg)
 {
+       if (!page) {
+               return 0;
+       }
+       int new_page = 0;
        OSCSurface *s = get_surface(get_address (msg));
-       s->plug_page = s->plug_page + page;
-       s->sel_obs->renew_plugin();
+       if (page > 0) {
+               new_page = s->plug_page + s->plug_page_size;
+               if ((uint32_t) new_page > s->plug_params.size ()) {
+                       new_page = s->plug_page;
+               }
+       } else {
+               new_page = s->plug_page - s->plug_page_size;
+               if (new_page < 1) {
+                       new_page = 1;
+               }
+       }
+       if (new_page != s->plug_page) {
+               s->plug_page = new_page;
+               s->sel_obs->set_plugin_page(s->plug_page);
+       }
        return 0;
 }
 
 int
 OSC::sel_plugin (int delta, lo_message msg)
 {
+       if (!delta) {
+               return 0;
+       }
        OSCSurface *sur = get_surface(get_address (msg));
        return _sel_plugin (sur->plugin_id + delta, get_address (msg));
 }
@@ -1987,12 +2522,7 @@ int
 OSC::_sel_plugin (int id, lo_address addr)
 {
        OSCSurface *sur = get_surface(addr);
-       boost::shared_ptr<Stripable> s;
-       if (sur->expand_enable) {
-               s = get_strip (sur->expand, addr);
-       } else {
-               s = _select;
-       }
+       boost::shared_ptr<Stripable> s = sur->select;
        if (s) {
                boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
                if (!r) {
@@ -2016,24 +2546,28 @@ OSC::_sel_plugin (int id, lo_address addr)
                                                if (!pi->is_channelstrip()) {
 #endif
                                                        sur->plugins.push_back (nplugs);
+                                                       nplugs++;
 #ifdef MIXBUS
                                                }
                                        }
 #endif
                                }
                                plugs = true;
-                               nplugs++;
                        }
                } while (plugs);
 
                // limit plugin_id to actual plugins
-               if (!sur->plugins.size()) {
+               if (sur->plugins.size() < 1) {
                        sur->plugin_id = 0;
+                       sur->plug_page = 1;
+                       if (sur->sel_obs) {
+                               sur->sel_obs->set_plugin_id(-1, 1);
+                       }
                        return 0;
+               } else if (id < 1) {
+                       sur->plugin_id = 1;
                } else if (sur->plugins.size() < (uint32_t) id) {
                        sur->plugin_id = sur->plugins.size();
-               } else  if (sur->plugins.size() && !id) {
-                       sur->plugin_id = 1;
                } else {
                        sur->plugin_id = id;
                }
@@ -2063,7 +2597,7 @@ OSC::_sel_plugin (int id, lo_address addr)
                sur->plug_page = 1;
 
                if (sur->sel_obs) {
-                       sur->sel_obs->renew_plugin();
+                       sur->sel_obs->set_plugin_id(sur->plugins[sur->plugin_id - 1], sur->plug_page);
                }
                return 0;
        }
@@ -2292,16 +2826,90 @@ 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);
 
-       }
        return 0;
 
 }
 
+// two structs to help with going to markers
+struct LocationMarker {
+       LocationMarker (const std::string& l, samplepos_t w)
+               : label (l), when (w) {}
+       std::string label;
+       samplepos_t  when;
+};
+
+struct LocationMarkerSort {
+       bool operator() (const LocationMarker& a, const LocationMarker& b) {
+               return (a.when < b.when);
+       }
+};
+
+int
+OSC::set_marker (const char* types, lo_arg **argv, int argc, lo_message msg)
+{
+       if (argc != 1) {
+               PBD::warning << "Wrong number of parameters, one only." << endmsg;
+               return -1;
+       }
+       const Locations::LocationList& ll (session->locations ()->list ());
+       uint32_t marker = 0;
+
+       switch (types[0]) {
+               case 's':
+                       for (Locations::LocationList::const_iterator l = ll.begin(); l != ll.end(); ++l) {
+                               if ((*l)->is_mark ()) {
+                                       if (strcmp (&argv[0]->s, (*l)->name().c_str()) == 0) {
+                                               session->request_locate ((*l)->start (), false);
+                                               return 0;
+                                       }
+                               }
+                       }
+                       break;
+               case 'i':
+                       marker = (uint32_t) argv[0]->i - 1;
+                       break;
+               case 'f':
+                       marker = (uint32_t) argv[0]->f - 1;
+                       break;
+               default:
+                       return -1;
+                       break;
+       }
+       std::vector<LocationMarker> lm;
+       // get Locations that are marks
+       for (Locations::LocationList::const_iterator l = ll.begin(); l != ll.end(); ++l) {
+               if ((*l)->is_mark ()) {
+                       lm.push_back (LocationMarker((*l)->name(), (*l)->start ()));
+               }
+       }
+       // sort them by position
+       LocationMarkerSort location_marker_sort;
+       std::sort (lm.begin(), lm.end(), location_marker_sort);
+       // go there
+       if (marker < lm.size()) {
+               session->request_locate (lm[marker].when, false);
+               return 0;
+       }
+       // we were unable to deal with things
+       return -1;
+}
+
+int
+OSC::click_level (float position)
+{
+       if (!session) return -1;
+       if (session->click_gain()->gain_control()) {
+               session->click_gain()->gain_control()->set_value (session->click_gain()->gain_control()->interface_to_internal (position), PBD::Controllable::NoGroup);
+       }
+       return 0;
+}
+
 // master and monitor calls
 int
 OSC::master_set_gain (float dB)
@@ -2588,6 +3196,7 @@ OSC::route_get_receives(lo_message msg) {
        boost::shared_ptr<RouteList> route_list = session->get_routes();
 
        lo_message reply = lo_message_new();
+       lo_message_add_int32(reply, rid);
 
        for (RouteList::iterator i = route_list->begin(); i != route_list->end(); ++i) {
                boost::shared_ptr<Route> tr = boost::dynamic_pointer_cast<Route> (*i);
@@ -3051,7 +3660,9 @@ OSC::route_monitor_input (int ssid, int yn, lo_message msg)
                boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
                if (track) {
                        if (track->monitoring_control()) {
-                               track->monitoring_control()->set_value (yn ? 1.0 : 0.0, sur->usegroup);
+                               std::bitset<32> value = track->monitoring_control()->get_value ();
+                               value[0] = yn ? 1 : 0;
+                               track->monitoring_control()->set_value (value.to_ulong(), sur->usegroup);
                                return 0;
                        }
                }
@@ -3074,7 +3685,9 @@ OSC::sel_monitor_input (uint32_t yn, lo_message msg)
                boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
                if (track) {
                        if (track->monitoring_control()) {
-                               track->monitoring_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+                               std::bitset<32> value = track->monitoring_control()->get_value ();
+                               value[0] = yn ? 1 : 0;
+                               track->monitoring_control()->set_value (value.to_ulong(), sur->usegroup);
                                return 0;
                        }
                }
@@ -3093,7 +3706,9 @@ OSC::route_monitor_disk (int ssid, int yn, lo_message msg)
                boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
                if (track) {
                        if (track->monitoring_control()) {
-                               track->monitoring_control()->set_value (yn ? 2.0 : 0.0, sur->usegroup);
+                               std::bitset<32> value = track->monitoring_control()->get_value ();
+                               value[1] = yn ? 1 : 0;
+                               track->monitoring_control()->set_value (value.to_ulong(), sur->usegroup);
                                return 0;
                        }
                }
@@ -3116,7 +3731,9 @@ OSC::sel_monitor_disk (uint32_t yn, lo_message msg)
                boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
                if (track) {
                        if (track->monitoring_control()) {
-                               track->monitoring_control()->set_value (yn ? 2.0 : 0.0, PBD::Controllable::NoGroup);
+                               std::bitset<32> value = track->monitoring_control()->get_value ();
+                               value[1] = yn ? 1 : 0;
+                               track->monitoring_control()->set_value (value.to_ulong(), sur->usegroup);
                                return 0;
                        }
                }
@@ -3177,6 +3794,19 @@ OSC::strip_expand (int ssid, int yn, lo_message msg)
        return _strip_select (s, get_address (msg));
 }
 
+int
+OSC::strip_hide (int ssid, int state, lo_message msg)
+{
+       boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+       if (s) {
+               if (state != s->is_hidden ()) {
+                       s->presentation_info().set_hidden ((bool) state);
+               }
+       }
+       return 0;
+}
+
 int
 OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
 {
@@ -3185,12 +3815,10 @@ OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
        }
        OSCSurface *sur = get_surface(addr, true);
        if (!s) {
-               if (sur->expand_enable) {
-                       // expand doesn't point to a stripable, turn it off and use select
-                       sur->expand = 0;
-                       sur->expand_enable = false;
-               }
-               if(ControlProtocol::first_selected_stripable()) {
+               // expand doesn't point to a stripable, turn it off and use select
+               sur->expand = 0;
+               sur->expand_enable = false;
+               if (ControlProtocol::first_selected_stripable()) {
                        s = ControlProtocol::first_selected_stripable();
                } else {
                        s = session->master_out ();
@@ -3198,41 +3826,59 @@ OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
                        _select = s;
        }
        sur->select = s;
+       bool sends;
+       uint32_t nsends  = 0;
+       do {
+               sends = false;
+               if (s->send_level_controllable (nsends)) {
+                       sends = true;
+                       nsends++;
+               }
+       } while (sends);
+       sur->nsends = nsends;
+
        s->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
 
-       OSCSelectObserver* so = 0;
+       OSCSelectObserver* so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs);
        if (sur->feedback[13]) {
-               if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
-                       so->refresh_strip (false);
+               if (so != 0) {
+                       so->refresh_strip (s, nsends, sur->gainmode, true);
                } else {
                        OSCSelectObserver* sel_fb = new OSCSelectObserver (*this, sur);
                        sur->sel_obs = sel_fb;
                }
+               sur->sel_obs->set_expand (sur->expand_enable);
+               uint32_t obs_expand = 0;
+               if (sur->expand_enable) {
+                       obs_expand = sur->expand;
+               } else {
+                       obs_expand = 0;
+               }
+               for (uint32_t i = 0; i < sur->observers.size(); i++) {
+                       sur->observers[i]->set_expand (obs_expand);
+               }
        } else {
                if (so != 0) {
                        delete so;
                        sur->sel_obs = 0;
                }
        }
-
        // need to set monitor for processor changed signal (for paging)
-       // detecting processor changes requires cast to route
+       string address = lo_address_get_url (addr);
        boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
        if (r) {
-               r->processors_changed.connect  (sur->proc_connection, MISSING_INVALIDATOR, boost::bind (&OSC::processor_changed, this, addr), this);
-               processor_changed (addr);
+               r->processors_changed.connect  (sur->proc_connection, MISSING_INVALIDATOR, boost::bind (&OSC::processor_changed, this, address), this);
+               _sel_plugin (sur->plugin_id, addr);
        }
 
-       strip_feedback (sur, false);
-
        return 0;
 }
 
 void
-OSC::processor_changed (lo_address addr)
+OSC::processor_changed (string address)
 {
+       lo_address addr = lo_address_new_from_url (address.c_str());
        OSCSurface *sur = get_surface (addr);
-       sur->proc_connection.disconnect ();
        _sel_plugin (sur->plugin_id, addr);
        if (sur->sel_obs) {
                sur->sel_obs->renew_sends ();
@@ -3268,10 +3914,11 @@ OSC::sel_expand (uint32_t state, lo_message msg)
 {
        OSCSurface *sur = get_surface(get_address (msg));
        boost::shared_ptr<Stripable> s;
-       sur->expand_enable = (bool) state;
        if (state && sur->expand) {
+               sur->expand_enable = (bool) state;
                s = get_strip (sur->expand, get_address (msg));
        } else {
+               sur->expand_enable = false;
                s = _select;
        }
 
@@ -3495,6 +4142,24 @@ OSC::sel_trim (float val, lo_message msg)
        return float_message("/select/trimdB", 0, get_address (msg));
 }
 
+int
+OSC::sel_hide (uint32_t state, 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 (state != s->is_hidden ()) {
+                       s->presentation_info().set_hidden ((bool) state);
+               }
+       }
+       return 0;
+}
+
 int
 OSC::sel_pan_position (float val, lo_message msg)
 {
@@ -3856,12 +4521,7 @@ OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv
        if (sur->plug_page_size && (paid > (int)sur->plug_page_size)) {
                return float_message_with_id ("/select/plugin/parameter", paid, 0, sur->feedback[2], get_address (msg));
        }
-       boost::shared_ptr<Stripable> s;
-       if (sur->expand_enable) {
-               s = get_strip (sur->expand, get_address (msg));
-       } else {
-               s = _select;
-       }
+       boost::shared_ptr<Stripable> s = sur->select;
        boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
        if (!r) {
                return 1;
@@ -3874,7 +4534,7 @@ OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv
        }
        boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
        // paid is paged parameter convert to absolute
-       int parid = paid + (int)(sur->plug_page_size * (sur->plug_page - 1));
+       int parid = paid + (int)sur->plug_page - 1;
        if (parid > (int) sur->plug_params.size ()) {
                if (sur->feedback[13]) {
                        float_message_with_id ("/select/plugin/parameter", paid, 0, sur->feedback[2], get_address (msg));
@@ -3907,6 +4567,38 @@ OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv
        return 1;
 }
 
+int
+OSC::sel_plugin_activate (float state, lo_message msg)
+{
+       if (!session) {
+               return -1;
+       }
+       OSCSurface *sur = get_surface(get_address (msg));
+       if (sur->plugins.size() > 0) {
+               boost::shared_ptr<Stripable> s = sur->select;
+
+               boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
+
+               if (r) {
+                       boost::shared_ptr<Processor> redi=r->nth_plugin (sur->plugins[sur->plugin_id -1]);
+                       if (redi) {
+                               boost::shared_ptr<PluginInsert> pi;
+                               if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
+                                       if(state > 0) {
+                                               pi->activate();
+                                       } else {
+                                               pi->deactivate();
+                                       }
+                                       return 0;
+                               }
+                       }
+               }
+       }
+       float_message ("/select/plugin/activate", 0, get_address (msg));
+       PBD::warning << "OSC: Select has no Plugin." << endmsg;
+       return 0;
+}
+
 int
 OSC::route_plugin_list (int ssid, lo_message msg) {
        if (!session) {
@@ -4804,18 +5496,51 @@ struct StripableByPresentationOrder
 };
 
 OSC::Sorted
-OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
+OSC::get_sorted_stripables(std::bitset<32> types, bool cue, uint32_t custom, Sorted my_list)
 {
        Sorted sorted;
        StripableList stripables;
+       StripableList custom_list;
 
        // fetch all stripables
        session->get_stripables (stripables);
-
+       if (custom) {
+               uint32_t nstps = my_list.size ();
+               // check each custom strip to see if it still exists
+               boost::shared_ptr<Stripable> s;
+               for (uint32_t i = 0; i < nstps; i++) {
+                       bool exists = false;
+                       s = my_list[i];
+                       for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
+                               boost::shared_ptr<Stripable> sl = *it;
+                               if (s == sl) {
+                                       exists = true;
+                                       break;
+                               }
+                       }
+                       if(!exists) {
+                               my_list[i] = boost::shared_ptr<Stripable>();
+                       } else {
+                               custom_list.push_back (s);
+                       }
+               }
+               if (custom == 1) {
+                       return my_list;
+               } else {
+                       stripables = custom_list;
+               }
+       }
        // Look for stripables that match bit in sur->strip_types
        for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
 
                boost::shared_ptr<Stripable> s = *it;
+               if (!s) {
+                       break;
+               }
+               if (custom == 2) {
+                       // banking off use all valid custom strips
+                       sorted.push_back (s);
+               } else
                if ((!cue) && (!types[9]) && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
                        // do nothing... skip it
                } else if (types[8] && (s->is_selected())) {
@@ -4863,14 +5588,18 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
                        }
                }
        }
-       sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
-       // Master/Monitor might be anywhere... we put them at the end - Sorry ;)
-       if (types[5]) {
-               sorted.push_back (session->master_out());
+       if (!custom || (custom & 0x2)) {
+               sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
        }
-       if (types[6]) {
-               if (session->monitor_out()) {
-                       sorted.push_back (session->monitor_out());
+       if (!custom) {
+               // Master/Monitor might be anywhere... we put them at the end - Sorry ;)
+               if (types[5]) {
+                       sorted.push_back (session->master_out());
+               }
+               if (types[6]) {
+                       if (session->monitor_out()) {
+                               sorted.push_back (session->monitor_out());
+                       }
                }
        }
        return sorted;
@@ -4879,19 +5608,30 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
 int
 OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
 {
+       OSCSurface *s = get_surface(get_address (msg), true);
+       s->bank_size = 0;
+       float value = 0;
+       if (argc == 1) {
+               if (types[0] == 'f') {
+                       value = argv[0]->f;
+               } else if (types[0] == 'i') {
+                       value = (float) argv[0]->i;
+               }
+       }
        int ret = 1; /* unhandled */
-
        if (!strncmp (path, "/cue/aux", 8)) {
                // set our Aux bus
-               if (argv[0]->f) {
-                       ret = cue_set (argv[0]->f, msg);
-               } else {
-                       ret = 0;
+               if (argc) {
+                       if (value) {
+                               ret = cue_set ((uint32_t) value, msg);
+                       } else {
+                               ret = 0;
+                       }
                }
        }
        else if (!strncmp (path, "/cue/connect", 12)) {
                // Connect to default Aux bus
-               if ((!argc) || argv[0]->f) {
+               if ((!argc) || argv[0]->f || argv[0]->i) {
                        ret = cue_set (1, msg);
                } else {
                        ret = 0;
@@ -4899,7 +5639,7 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
        }
        else if (!strncmp (path, "/cue/next_aux", 13)) {
                // switch to next Aux bus
-               if ((!argc) || argv[0]->f) {
+               if ((!argc) || argv[0]->f || argv[0]->i) {
                        ret = cue_next (msg);
                } else {
                        ret = 0;
@@ -4907,25 +5647,33 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
        }
        else if (!strncmp (path, "/cue/previous_aux", 17)) {
                // switch to previous Aux bus
-               if ((!argc) || argv[0]->f) {
+               if ((!argc) || argv[0]->f || argv[0]->i) {
                        ret = cue_previous (msg);
                } else {
                        ret = 0;
                }
        }
        else if (!strncmp (path, "/cue/send/fader/", 16) && strlen (path) > 16) {
-               int id = atoi (&path[16]);
-               ret = cue_send_fader (id, argv[0]->f, msg);
+               if (argc == 1) {
+                       int id = atoi (&path[16]);
+                       ret = cue_send_fader (id, value, msg);
+               }
        }
        else if (!strncmp (path, "/cue/send/enable/", 17) && strlen (path) > 17) {
-               int id = atoi (&path[17]);
-               ret = cue_send_enable (id, argv[0]->f, msg);
+               if (argc == 1) {
+                       int id = atoi (&path[17]);
+                       ret = cue_send_enable (id, value, msg);
+               }
        }
        else if (!strncmp (path, "/cue/fader", 10)) {
-               ret = cue_aux_fader (argv[0]->f, msg);
+               if (argc == 1) {
+                       ret = cue_aux_fader (value, msg);
+               }
        }
        else if (!strncmp (path, "/cue/mute", 9)) {
-               ret = cue_aux_mute (argv[0]->f, msg);
+               if (argc == 1) {
+                       ret = cue_aux_mute (value, msg);
+               }
        }
 
        return ret;
@@ -4934,7 +5682,7 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
 int
 OSC::cue_set (uint32_t aux, lo_message msg)
 {
-       set_surface_feedback (0, msg);
+
        return _cue_set (aux, get_address (msg));
 }
 
@@ -4942,13 +5690,13 @@ int
 OSC::_cue_set (uint32_t aux, lo_address addr)
 {
        int ret = 1;
-       OSCSurface *s = get_surface(addr);
+       OSCSurface *s = get_surface(addr, true);
        s->bank_size = 0;
        s->strip_types = 128;
        s->feedback = 0;
        s->gainmode = 1;
        s->cue = true;
-       s->strips = get_sorted_stripables(s->strip_types, s->cue);
+       s->strips = get_sorted_stripables(s->strip_types, s->cue, false, s->custom_strips);
 
        s->nstrips = s->strips.size();
 
@@ -4958,7 +5706,6 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
                aux = s->nstrips;
        }
        s->aux = aux;
-
        // get a list of Auxes
        for (uint32_t n = 0; n < s->nstrips; ++n) {
                boost::shared_ptr<Stripable> stp = s->strips[n];
@@ -4966,13 +5713,12 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
                        text_message (string_compose ("/cue/name/%1", n+1), stp->name(), addr);
                        if (aux == n+1) {
                                // aux must be at least one
-                               // need a signal if aux vanishes
-                               stp->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::_cue_set, this, aux, addr), this);
 
+                               stp->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::_cue_set, this, aux, addr), this);
                                // make a list of stripables with sends that go to this bus
                                s->sends = cue_get_sorted_stripables(stp, aux, addr);
                                if (s->cue_obs) {
-                                       s->cue_obs->refresh_strip (false);
+                                       s->cue_obs->refresh_strip (stp, s->sends, true);
                                } else {
                                        // start cue observer
                                        OSCCueObserver* co = new OSCCueObserver (*this, s);
@@ -4990,7 +5736,7 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
 int
 OSC::cue_next (lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       OSCSurface *s = get_surface(get_address (msg), true);
        int ret = 1;
 
        if (!s->cue) {
@@ -5007,13 +5753,15 @@ OSC::cue_next (lo_message msg)
 int
 OSC::cue_previous (lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       OSCSurface *s = get_surface(get_address (msg), true);
        int ret = 1;
        if (!s->cue) {
                ret = cue_set (1, msg);
        }
        if (s->aux > 1) {
                ret = cue_set (s->aux - 1, msg);
+       } else {
+               ret = cue_set (1, msg);
        }
        return ret;
 }
@@ -5021,7 +5769,7 @@ OSC::cue_previous (lo_message msg)
 boost::shared_ptr<Send>
 OSC::cue_get_send (uint32_t id, lo_address addr)
 {
-       OSCSurface *s = get_surface(addr);
+       OSCSurface *s = get_surface(addr, true);
        if (id && s->aux > 0 && id <= s->sends.size()) {
                boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s->sends[id - 1]);
                boost::shared_ptr<Stripable> aux = get_strip (s->aux, addr);
@@ -5038,7 +5786,7 @@ OSC::cue_aux_fader (float position, lo_message msg)
 {
        if (!session) return -1;
 
-       OSCSurface *sur = get_surface(get_address (msg));
+       OSCSurface *sur = get_surface(get_address (msg), true);
        if (sur->cue) {
                if (sur->aux) {
                        boost::shared_ptr<Stripable> s = get_strip (sur->aux, get_address (msg));
@@ -5060,7 +5808,7 @@ OSC::cue_aux_mute (float state, lo_message msg)
 {
        if (!session) return -1;
 
-       OSCSurface *sur = get_surface(get_address (msg));
+       OSCSurface *sur = get_surface(get_address (msg), true);
        if (sur->cue) {
                if (sur->aux) {
                        boost::shared_ptr<Stripable> s = get_strip (sur->aux, get_address (msg));