OSC link: first working commit for linking two surfaces as one
[ardour.git] / libs / surfaces / osc / osc.cc
index 9eee330949f0408e168ba035a8a9de72de55fa8c..6e05bd393704eaeb7f09abc679c033e1fb062378 100644 (file)
@@ -105,6 +105,7 @@ OSC::OSC (Session& s, uint32_t port)
        , default_plugin_size (0)
        , tick (true)
        , bank_dirty (false)
+       , observer_busy (true)
        , scrub_speed (0)
        , gui (0)
 {
@@ -115,6 +116,7 @@ OSC::OSC (Session& s, uint32_t port)
 
 OSC::~OSC()
 {
+       tick = false;
        stop ();
        tear_down_gui ();
        _instance = 0;
@@ -234,6 +236,7 @@ OSC::start ()
                }
        }
 
+       observer_busy = false;
        register_callbacks();
 
        session_loaded (*session);
@@ -258,7 +261,10 @@ OSC::start ()
        // order changed
        PresentationInfo::Change.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
 
-       _select = boost::shared_ptr<Stripable>();
+       _select = ControlProtocol::first_selected_stripable();
+       if(!_select) {
+               _select = session->master_out ();
+       }
 
        return 0;
 }
@@ -296,8 +302,18 @@ OSC::thread_init ()
 int
 OSC::stop ()
 {
-       /* stop main loop */
+       periodic_connection.disconnect ();
+       session_connections.drop_connections ();
+
+       // clear surfaces
+       observer_busy = true;
+       for (uint32_t it = 0; it < _surface.size (); ++it) {
+               OSCSurface* sur = &_surface[it];
+               surface_destroy (sur);
+       }
+       _surface.clear();
 
+       /* stop main loop */
        if (local_server) {
                g_source_destroy (local_server);
                g_source_unref (local_server);
@@ -330,60 +346,48 @@ OSC::stop ()
                ::g_unlink (_osc_url_file.c_str() );
        }
 
-       periodic_connection.disconnect ();
-       session_connections.drop_connections ();
-       cueobserver_connections.drop_connections ();
-       Glib::Threads::Mutex::Lock lm (surfaces_lock);
-       // Delete any active route observers
-       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
-
-               OSCRouteObserver* rc;
+       return 0;
+}
 
-               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = route_observers.erase (x);
-               } else {
-                       ++x;
-               }
+void
+OSC::surface_destroy (OSCSurface* sur)
+{
+       OSCSelectObserver* so;
+       if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
+               so->clear_observer ();
+               delete so;
+               sur->sel_obs = 0;
+               PBD::ScopedConnection pc = sur->proc_connection;
+               pc.disconnect ();
        }
-// Should maybe do global_observers too
-       for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end();) {
 
-               OSCGlobalObserver* gc;
-
-               if ((gc = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = global_observers.erase (x);
-               } else {
-                       ++x;
-               }
+       OSCCueObserver* co;
+       if ((co = dynamic_cast<OSCCueObserver*>(sur->cue_obs)) != 0) {
+               co->clear_observer ();
+               delete co;
+               sur->cue_obs = 0;
        }
 
-// delete select observers
-       for (uint32_t it = 0; it < _surface.size(); ++it) {
-               OSCSurface* sur = &_surface[it];
-               OSCSelectObserver* so;
-               if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
-                       delete so;
-               }
+       OSCGlobalObserver* go;
+       if ((go = dynamic_cast<OSCGlobalObserver*>(sur->global_obs)) != 0) {
+               go->clear_observer ();
+               delete go;
+               sur->global_obs = 0;
        }
+       uint32_t st_end = sur->observers.size ();
 
-// delete cue observers
-       for (CueObservers::iterator x = cue_observers.begin(); x != cue_observers.end();) {
-
-               OSCCueObserver* co;
-
-               if ((co = dynamic_cast<OSCCueObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = cue_observers.erase (x);
-               } else {
-                       ++x;
+       for (uint32_t i = 0; i < st_end; i++) {
+               OSCRouteObserver* ro;
+               if ((ro = dynamic_cast<OSCRouteObserver*>(sur->observers[i])) != 0) {
+                       ro->clear_strip ();
+                       delete ro;
+                       ro = 0;
                }
        }
-
-       return 0;
+       sur->observers.clear();
 }
 
+
 void
 OSC::register_callbacks()
 {
@@ -411,6 +415,8 @@ 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, "/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);
@@ -432,7 +438,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/transport_stop", "f", transport_stop);
                REGISTER_CALLBACK (serv, "/transport_play", "", transport_play);
                REGISTER_CALLBACK (serv, "/transport_play", "f", transport_play);
-               REGISTER_CALLBACK (serv, "/transport_frame", "", transport_frame);
+               REGISTER_CALLBACK (serv, "/transport_frame", "", transport_sample);
                REGISTER_CALLBACK (serv, "/transport_speed", "", transport_speed);
                REGISTER_CALLBACK (serv, "/record_enabled", "", record_enabled);
                REGISTER_CALLBACK (serv, "/set_transport_speed", "f", set_transport_speed);
@@ -469,6 +475,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);
@@ -640,7 +647,7 @@ OSC::register_callbacks()
 
                /* this is a special catchall handler,
                 * register at the end so this is only called if no
-                * other handler matches (used for debug) */
+                * other handler matches (also used for debug) */
                lo_server_add_method (serv, 0, 0, _catchall, this);
        }
 }
@@ -695,99 +702,6 @@ OSC::gui_changed ()
        session->set_dirty();
 }
 
-void
-OSC::listen_to_route (boost::shared_ptr<Stripable> strip, lo_address addr)
-{
-       if (!strip) {
-               return;
-       }
-       /* avoid duplicate listens */
-
-       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end(); ++x) {
-
-               OSCRouteObserver* ro;
-
-               if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-
-                       int res = strcmp(lo_address_get_url(ro->address()), lo_address_get_url(addr));
-
-                       if (ro->strip() == strip && res == 0) {
-                               return;
-                       }
-               }
-       }
-
-       OSCSurface *s = get_surface(addr);
-       uint32_t ssid = get_sid (strip, addr);
-       OSCRouteObserver* o = new OSCRouteObserver (strip, ssid, s);
-       route_observers.push_back (o);
-
-       strip->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::route_lost, this, boost::weak_ptr<Stripable> (strip)), this);
-}
-
-void
-OSC::route_lost (boost::weak_ptr<Stripable> wr)
-{
-       tick = false;
-       drop_route (wr);
-       bank_dirty = true;
-}
-
-void
-OSC::drop_route (boost::weak_ptr<Stripable> wr)
-{
-       boost::shared_ptr<Stripable> r = wr.lock ();
-
-       if (!r) {
-               return;
-       }
-
-       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
-
-               OSCRouteObserver* rc;
-
-               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-
-                       if (rc->strip() == r) {
-                               delete *x;
-                               x = route_observers.erase (x);
-                       } else {
-                               ++x;
-                       }
-               } else {
-                       ++x;
-               }
-       }
-}
-
-void
-OSC::end_listen (boost::shared_ptr<Stripable> r, lo_address addr)
-{
-       RouteObservers::iterator x;
-
-       // Remove the route observers
-       for (x = route_observers.begin(); x != route_observers.end();) {
-
-               OSCRouteObserver* ro;
-
-               if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-
-                       int res = strcmp(lo_address_get_url(ro->address()), lo_address_get_url(addr));
-
-                       if (ro->strip() == r && res == 0) {
-                               delete *x;
-                               x = route_observers.erase (x);
-                       }
-                       else {
-                               ++x;
-                       }
-               }
-               else {
-                       ++x;
-               }
-       }
-}
-
 void
 OSC::current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg)
 {
@@ -879,7 +793,10 @@ 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));
+       */
 
        if (strstr (path, "/automation")) {
                ret = set_automation (path, types, argv, argc, msg);
@@ -914,7 +831,7 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
 
                ret = 0;
        } else
-       if (strcmp (path, "/strip/listen") == 0) {
+/*     if (strcmp (path, "/strip/listen") == 0) {
                check_surface (msg);
 
                cerr << "set up listener\n";
@@ -963,7 +880,7 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                }
 
                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;
@@ -1077,6 +994,9 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
        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);
        }
@@ -1187,37 +1107,37 @@ OSC::current_value (const char */*path*/, const char */*types*/, lo_arg **/*argv
        if (strcmp (argv[0]->s, "transport_frame") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else if (strcmp (argv[0]->s, "transport_speed") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else if (strcmp (argv[0]->s, "transport_locked") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else if (strcmp (argv[0]->s, "punch_in") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else if (strcmp (argv[0]->s, "punch_out") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else if (strcmp (argv[0]->s, "rec_enable") == 0) {
 
                if (session) {
-                       lo_send (addr, retpath, "i", session->transport_frame());
+                       lo_send (addr, retpath, "i", session->transport_sample());
                }
 
        } else {
@@ -1234,8 +1154,7 @@ OSC::routes_list (lo_message msg)
        if (!session) {
                return;
        }
-       OSCSurface *sur = get_surface(get_address (msg));
-       sur->no_clear = true;
+       OSCSurface *sur = get_surface(get_address (msg), true);
 
        for (int n = 0; n < (int) sur->nstrips; ++n) {
 
@@ -1296,10 +1215,6 @@ OSC::routes_list (lo_message msg)
                        if (s->rec_enable_control()) {
                                lo_message_add_int32 (reply, s->rec_enable_control()->get_value());
                        }
-
-                       //Automatically listen to stripables listed
-                       listen_to_route(s, get_address (msg));
-
                        if (sur->feedback[14]) {
                                lo_send_message (get_address (msg), "/reply", reply);
                        } else {
@@ -1313,8 +1228,8 @@ OSC::routes_list (lo_message msg)
        lo_message reply = lo_message_new ();
 
        lo_message_add_string (reply, "end_route_list");
-       lo_message_add_int64 (reply, session->frame_rate());
-       lo_message_add_int64 (reply, session->current_end_frame());
+       lo_message_add_int64 (reply, session->sample_rate());
+       lo_message_add_int64 (reply, session->current_end_sample());
        if (session->monitor_out()) {
                // this session has a monitor section
                lo_message_add_int32 (reply, 1);
@@ -1329,6 +1244,59 @@ OSC::routes_list (lo_message msg)
        }
 
        lo_message_free (reply);
+       // send feedback for newly created control surface
+       strip_feedback (sur, true);
+       global_feedback (sur);
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
+
+}
+
+void
+OSC::surface_list (lo_message msg)
+{
+       /* 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.
+        */
+
+       cerr << "List of known Surfaces: " << _surface.size() << "\n\n";
+
+       Glib::Threads::Mutex::Lock lm (surfaces_lock);
+       for (uint32_t it = 0; it < _surface.size(); it++) {
+               OSCSurface* sur = &_surface[it];
+               cerr << string_compose ("  Surface: %1 URL: %2\n", it, sur->remote_url);
+               cerr << string_compose ("       Number of strips: %1 Bank size: %2 Current Bank %3\n", sur->nstrips, sur->bank_size, sur->bank);
+               bool ug = false;
+               if (sur->usegroup == PBD::Controllable::UseGroup) {
+                       ug = true;
+               }
+               cerr << string_compose ("       Strip Types: %1 Feedback: %2 no_clear: %3 gain mode: %4 use groups? %5\n", \
+                       sur->strip_types.to_ulong(), sur->feedback.to_ulong(), sur->no_clear, sur->gainmode, ug);
+               cerr << 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);
+               cerr << string_compose ("       send page size: %1 page: %2\n", sur->send_page_size, sur->send_page);
+               cerr << string_compose ("       expanded? %1 track: %2 jogmode: %3\n", sur->expand_enable, sur->expand, sur->jogmode);
+               cerr << string_compose ("       personal monitor? %1, Aux master: %2, number of sends: %3\n", sur->cue, sur->aux, sur->sends.size());
+               cerr << string_compose ("       Linkset: %1 Device Id: %2\n", sur->linkset, sur->linkid);
+       }
+       cerr << "\nList of LinkSets " << link_sets.size() << "\n\n";
+       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->linked.size()) {
+                       devices = set->linked.size() - 1;
+               }
+               cerr << string_compose ("  Linkset %1 has %2 devices and sees %3 strips\n", (*it).first, devices, set->strips.size());
+               cerr << string_compose ("       Bank size: %1 Current bank: %2 Strip Types: %3\n", set->banksize, set->bank, set->strip_types.to_ulong());
+               cerr << string_compose ("       auto bank sizing: %1 linkset not ready: %2\n", set->autobank, set->not_ready);
+       }
+       cerr << "\n";
 }
 
 int
@@ -1354,10 +1322,17 @@ OSC::get_address (lo_message msg)
 int
 OSC::refresh_surface (lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       OSCSurface *s = get_surface(get_address (msg), true);
+       uint32_t bs = s->bank_size;
+       uint32_t st = (uint32_t) s->strip_types.to_ulong();
+       uint32_t fb = (uint32_t) s->feedback.to_ulong();
+       uint32_t gm = (uint32_t) s->gainmode;
+       uint32_t sp = s->send_page_size;
+       uint32_t pp = s->plug_page_size;
+
+       surface_destroy (s);
        // restart all observers
-       set_surface (s->bank_size, (uint32_t) s->strip_types.to_ulong(), (uint32_t) s->feedback.to_ulong(), \
-               (uint32_t) s->gainmode, (uint32_t) s->send_page_size, (uint32_t) s->plug_page_size, msg);
+       set_surface (bs, st, fb, gm, sp, pp, msg);
        return 0;
 }
 
@@ -1365,61 +1340,155 @@ void
 OSC::clear_devices ()
 {
        tick = false;
-       Glib::Threads::Mutex::Lock lm (surfaces_lock);
-       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
+       observer_busy = true;
+       session_connections.drop_connections ();
+       // clear out surfaces
+       for (uint32_t it = 0; it < _surface.size(); ++it) {
+               OSCSurface* sur = &_surface[it];
+               surface_destroy (sur);
+       }
+       _surface.clear();
+       link_sets.clear ();
 
-               OSCRouteObserver* rc;
+       PresentationInfo::Change.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
 
-               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = route_observers.erase (x);
+       observer_busy = false;
+       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 {
-                       ++x;
+                       set = argv[0]->i;
                }
-               // slow devices need time to clear buffers
-               usleep ((uint32_t) 10);
+       } else {
+               PBD::warning << "OSC: wrong number of parameters." << endmsg;
+               return ret;
        }
-       // Should maybe do global_observers too
-       for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end();) {
+       OSCSurface *sur = get_surface(get_address (msg));
+       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;
+                       link_sets[set] = new_ls;
+               }
+               ls = &link_sets[set];
 
-               OSCGlobalObserver* gc;
+       } else {
+               // User expects this surface to be removed from any sets
+               int oldset = sur->linkset;
+               if (oldset) {
+                       int oldid = sur->linkid;
+                       sur->linkid = 1;
+                       sur->linkset = 0;
+                       ls = &link_sets[oldid];
+                       if (ls) {
+                               ls->not_ready = 1;
+                               ls->linked[(uint32_t) data] = 0;
+                       }
+               }
+               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;
+                       strip_feedback (sur, true);
+               } else {
+                       _set_bank (ls->bank, get_address (msg));
+               }
+               ret = 0;
 
-               if ((gc = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = global_observers.erase (x);
+       } else if (!strncmp (path, "/link/set", 9)) {
+               sur->linkset = set;
+               sur->linkid = (uint32_t) data;
+               if (ls->linked.size() <= (uint32_t) data) {
+                       ls->linked.resize((int) data + 1);
+               }
+               ls->linked[(uint32_t) data] = sur;
+               ls->not_ready = link_check (set);
+               if (ls->not_ready) {
+                       strip_feedback (sur, true);
                } else {
-                       ++x;
+                       _set_bank (1, get_address (msg));
                }
+               ret = 0;
        }
-       // delete select observers
-       for (uint32_t it = 0; it < _surface.size(); ++it) {
-               OSCSurface* sur = &_surface[it];
-               OSCSelectObserver* so;
-               if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
-                       delete so;
+
+       return ret;
+}
+
+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;
+       uint32_t set_ready = 0;
+       for (uint32_t dv = 1; dv < ls->linked.size(); dv++) {
+               if ((ls->linked[dv]) && ((ls->linked[dv]))->linkset == set) {
+                       OSCSurface *su = (ls->linked[dv]);
+                       bank_total = bank_total + su->bank_size;
+               } else if (!set_ready) {
+                       set_ready = dv;
                }
        }
-       // delete cue observers
-       for (CueObservers::iterator x = cue_observers.begin(); x != cue_observers.end();) {
-               OSCCueObserver* co;
-               if ((co = dynamic_cast<OSCCueObserver*>(*x)) != 0) {
-                       delete *x;
-                       x = cue_observers.erase (x);
-               } else {
-                       ++x;
+       if (ls->autobank) {
+               ls->banksize = bank_total;
+       } else {
+               if (!set_ready && bank_total != ls->banksize) {
+                       set_ready = ls->linked.size();
                }
        }
-
-       // clear out surfaces
-       _surface.clear();
-       tick = true;
+       return set_ready;
 }
 
 int
 OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
 {
        int ret = 1; /* unhandled */
-       OSCSurface *sur = get_surface(get_address (msg));
+       OSCSurface *sur = get_surface(get_address (msg), true);
        int pi_page = sur->plug_page_size;
        int se_page = sur->send_page_size;
        int fadermode = sur->gainmode;
@@ -1428,42 +1497,42 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
        int bank_size = sur->bank_size;
 
 
-       if (!strncmp (path, "/set_surface/feedback", 21)) {
+       if (argc == 1 && !strncmp (path, "/set_surface/feedback", 21)) {
                if (types[0] == 'f') {
                        ret = set_surface_feedback ((int)argv[0]->f, msg);
                } else {
                        ret = set_surface_feedback (argv[0]->i, msg);
                }
        }
-       else if (!strncmp (path, "/set_surface/bank_size", 22)) {
+       else if (argc == 1 && !strncmp (path, "/set_surface/bank_size", 22)) {
                if (types[0] == 'f') {
                        ret = set_surface_bank_size ((int)argv[0]->f, msg);
                } else {
                        ret = set_surface_bank_size (argv[0]->i, msg);
                }
        }
-       else if (!strncmp (path, "/set_surface/gainmode", 21)) {
+       else if (argc == 1 && !strncmp (path, "/set_surface/gainmode", 21)) {
                if (types[0] == 'f') {
                        ret = set_surface_gainmode ((int)argv[0]->f, msg);
                } else {
                        ret = set_surface_gainmode (argv[0]->i, msg);
                }
        }
-       else if (!strncmp (path, "/set_surface/strip_types", 24)) {
+       else if (argc == 1 && !strncmp (path, "/set_surface/strip_types", 24)) {
                if (types[0] == 'f') {
                        ret = set_surface_strip_types ((int)argv[0]->f, msg);
                } else {
                        ret = set_surface_strip_types (argv[0]->i, msg);
                }
        }
-       else if (!strncmp (path, "/set_surface/send_page_size", 27)) {
+       else if (argc == 1 && !strncmp (path, "/set_surface/send_page_size", 27)) {
                if (types[0] == 'f') {
                        ret = sel_send_pagesize ((int)argv[0]->f, msg);
                } else {
                        ret = sel_send_pagesize (argv[0]->i, msg);
                }
        }
-       else if (!strncmp (path, "/set_surface/plugin_page_size", 29)) {
+       else if (argc == 1 && !strncmp (path, "/set_surface/plugin_page_size", 29)) {
                if (types[0] == 'f') {
                        ret = sel_plug_pagesize ((int)argv[0]->f, msg);
                } else {
@@ -1593,7 +1662,10 @@ OSC::surface_parse (const char *path, const char* types, lo_arg **argv, int argc
 int
 OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, uint32_t se_size, uint32_t pi_size, lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       if (observer_busy) {
+               return -1;
+       }
+       OSCSurface *s = get_surface(get_address (msg), true);
        s->bank_size = b_size;
        s->strip_types = strips;
        s->feedback = fb;
@@ -1606,9 +1678,11 @@ 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
-       set_bank(s->bank, msg);
+       // XXXX check if we are already in a linkset
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg), true);
+       strip_feedback(s, true);
 
-       global_feedback (*s, get_address (msg));
+       global_feedback (s);
        sel_send_pagesize (se_size, msg);
        sel_plug_pagesize (pi_size, msg);
        return 0;
@@ -1617,18 +1691,27 @@ OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, ui
 int
 OSC::set_surface_bank_size (uint32_t bs, lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       if (observer_busy) {
+               return -1;
+       }
+       OSCSurface *s = get_surface(get_address (msg), true);
        s->bank_size = bs;
+       // XXXX check if we are already in a linkset
+       s->bank = 1;
 
        // set bank and strip feedback
-       set_bank(s->bank, msg);
+       strip_feedback (s, true);
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
 int
 OSC::set_surface_strip_types (uint32_t st, lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       if (observer_busy) {
+               return -1;
+       }
+       OSCSurface *s = get_surface(get_address (msg), true);
        s->strip_types = st;
        if (s->strip_types[10]) {
                s->usegroup = PBD::Controllable::UseGroup;
@@ -1637,7 +1720,10 @@ OSC::set_surface_strip_types (uint32_t st, lo_message msg)
        }
 
        // set bank and strip feedback
-       set_bank(s->bank, msg);
+       // XXXX check for linkset
+       s->bank = 1;
+       strip_feedback (s, true);
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
@@ -1645,28 +1731,30 @@ OSC::set_surface_strip_types (uint32_t st, lo_message msg)
 int
 OSC::set_surface_feedback (uint32_t fb, lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       if (observer_busy) {
+               return -1;
+       }
+       OSCSurface *s = get_surface(get_address (msg), true);
        s->feedback = fb;
 
-       // set bank and strip feedback
-       set_bank(s->bank, msg);
-
-       // Set global/master feedback
-       global_feedback (*s, get_address (msg));
+       strip_feedback (s, false);
+       global_feedback (s);
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
 int
 OSC::set_surface_gainmode (uint32_t gm, lo_message msg)
 {
-       OSCSurface *s = get_surface(get_address (msg));
+       if (observer_busy) {
+               return -1;
+       }
+       OSCSurface *s = get_surface(get_address (msg), true);
        s->gainmode = gm;
 
-       // set bank and strip feedback
-       set_bank(s->bank, msg);
-
-       // Set global/master feedback
-       global_feedback (*s, get_address (msg));
+       strip_feedback (s, false);
+       global_feedback (s);
+       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), get_address (msg));
        return 0;
 }
 
@@ -1681,7 +1769,7 @@ OSC::check_surface (lo_message msg)
 }
 
 OSC::OSCSurface *
-OSC::get_surface (lo_address addr)
+OSC::get_surface (lo_address addr , bool quiet)
 {
        string r_url;
        char * rurl;
@@ -1695,9 +1783,8 @@ OSC::get_surface (lo_address addr)
        r_url = rurl;
        free (rurl);
        {
-               Glib::Threads::Mutex::Lock lm (surfaces_lock);
                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];
                        }
@@ -1711,6 +1798,9 @@ OSC::get_surface (lo_address addr)
        s.jogmode = JOG;
        s.bank = 1;
        s.bank_size = default_banksize;
+       s.observers.clear();
+       s.sel_obs = 0;
+       s.global_obs = 0;
        s.strip_types = default_strip;
        s.feedback = default_feedback;
        s.gainmode = default_gainmode;
@@ -1720,62 +1810,76 @@ OSC::get_surface (lo_address addr)
        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.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();
        {
-               Glib::Threads::Mutex::Lock lm (surfaces_lock);
                _surface.push_back (s);
        }
-       // moved this down here as selection may need s.<anything to do with select> set
-       if (!_select || (_select != ControlProtocol::first_selected_stripable())) {
-               gui_selection_changed();
-       }
-
-       // set bank and strip feedback
-       _set_bank(s.bank, addr);
 
-       // Set global/master feedback
-       global_feedback (s, addr);
+       if (!quiet) {
+               strip_feedback (&s, true);
+               global_feedback (&s);
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr);
+       }
 
        return &_surface[_surface.size() - 1];
 }
 
 // setup global feedback for a surface
 void
-OSC::global_feedback (OSCSurface sur, lo_address addr)
+OSC::global_feedback (OSCSurface* sur)
 {
-       // first destroy global observer for this surface
-       GlobalObservers::iterator x;
-       for (x = global_observers.begin(); x != global_observers.end();) {
+       if (sur->feedback[4] || sur->feedback[3] || sur->feedback[5] || sur->feedback[6]) {
 
-               OSCGlobalObserver* go;
+               // create a new Global Observer for this surface
+               OSCGlobalObserver* o = new OSCGlobalObserver (*this, *session, sur);
+               sur->global_obs = o;
+       }
+}
 
-               if ((go = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
+void
+OSC::strip_feedback (OSCSurface* sur, bool new_bank_size)
+{
+       sur->strips = get_sorted_stripables(sur->strip_types, sur->cue);
+       sur->nstrips = sur->strips.size();
+       if (new_bank_size || (!sur->feedback[0] && !sur->feedback[1])) {
+               // delete old observers
+               for (uint32_t i = 0; i < sur->observers.size(); i++) {
+                       if (!sur->bank_size) {
+                               sur->observers[i]->clear_strip ();
+                       }
+                       delete sur->observers[i];
+               }
+               sur->observers.clear();
 
-                       int res = strcmp(lo_address_get_url(go->address()), lo_address_get_url(addr));
+               uint32_t bank_size = sur->bank_size;
+               if (!bank_size) {
+                       bank_size = sur->nstrips;
+               }
 
-                       if (res == 0) {
-                               delete *x;
-                               x = global_observers.erase (x);
-                       } else {
-                               ++x;
+               if (sur->feedback[0] || sur->feedback[1]) {
+                       for (uint32_t i = 0; i < bank_size; i++) {
+                               OSCRouteObserver* o = new OSCRouteObserver (*this, i + 1, sur);
+                               sur->observers.push_back (o);
+                       }
+               }
+       } else {
+               if (sur->feedback[0] || sur->feedback[1]) {
+                       for (uint32_t i = 0; i < sur->observers.size(); i++) {
+                               sur->observers[i]->refresh_strip(true);
                        }
-               } else {
-                       ++x;
                }
        }
-       std::bitset<32> feedback = sur.feedback;
-       if (feedback[4] || feedback[3] || feedback[5] || feedback[6]) {
-               // create a new Global Observer for this surface
-               OSCGlobalObserver* o = new OSCGlobalObserver (*session, &sur);
-               global_observers.push_back (o);
-       }
+       bank_leds (sur);
 }
 
 void
@@ -1802,40 +1906,45 @@ OSC::recalcbanks ()
 void
 OSC::_recalcbanks ()
 {
-       if (!_select || (_select != ControlProtocol::first_selected_stripable())) {
-               _select = ControlProtocol::first_selected_stripable();
+       if (observer_busy) {
+               return;
        }
-
-       // do a set_bank for each surface we know about.
+       /*
+        * We have two different ways of working here:
+        * 1) banked: The controller has a bank of strips and only can deal
+        * with banksize strips. We start banksize observers which run until
+        * either banksize is changed or Ardour exits.
+        *
+        * 2) banksize is 0 or unlimited and so is the same size as the number
+        * of strips. For a recalc, We want to tear down all strips but not send
+        * a reset value for any of the controls and then rebuild all observers.
+        * this is easier than detecting change in "bank" size and deleting or
+        * adding just a few.
+        */
+
+       // refresh each surface we know about.
        for (uint32_t it = 0; it < _surface.size(); ++it) {
                OSCSurface* sur = &_surface[it];
+               sur->strips = get_sorted_stripables(sur->strip_types, sur->cue);
+               sur->nstrips = sur->strips.size();
                // find lo_address
                lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr, true);
                if (sur->cue) {
                        _cue_set (sur->aux, addr);
-               } else {
-                       _set_bank (sur->bank, addr);
-               }
-               if (sur->no_clear) {
+               } else if (!sur->bank_size) {
+                       strip_feedback (sur, true);
                        // This surface uses /strip/list tell it routes have changed
                        lo_message reply;
                        reply = lo_message_new ();
                        lo_send_message (addr, "/strip/list", reply);
                        lo_message_free (reply);
+               } else {
+                       strip_feedback (sur, false);
                }
        }
 }
 
-/*
- * This gets called not only when bank changes but also:
- *  - bank size change
- *  - feedback change
- *  - strip types changes
- *  - fadermode changes
- *  - stripable creation/deletion/flag
- *  - to refresh what is "displayed"
- * Basically any time the bank needs to be rebuilt
- */
 int
 OSC::set_bank (uint32_t bank_start, lo_message msg)
 {
@@ -1849,72 +1958,107 @@ 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 (ControlProtocol::first_selected_stripable(), addr);
+       Sorted striplist = s->strips;
+       uint32_t nstrips = s->nstrips;
 
-       // undo all listeners for this url
-       StripableList stripables;
-       session->get_stripables (stripables);
-       for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
+       LinkSet *set;
+       uint32_t l_set = s->linkset;
 
-               boost::shared_ptr<Stripable> stp = *it;
-               if (stp) {
-                       end_listen (stp, addr);
+       if (l_set) {
+               //we have a linkset... deal with each surface
+               set = &(link_sets[l_set]);
+               if (set->not_ready) {
+                       return 1;
                }
-               // slow devices need time to clear buffers
-               usleep ((uint32_t) 10);
+               uint32_t s_count = set->linked.size();
+               set->strips = striplist;
+               bank_start = bank_limits_check (bank_start, set->banksize, nstrips);
+               set->bank = bank_start;
+               for (uint32_t ls = 1; ls < s_count; ls++) {
+                       OSCSurface *sur = (set->linked[ls]);
+                       if (!sur || sur->linkset != l_set) {
+                               if (!set->not_ready) {
+                                       set->not_ready = ls;
+                               }
+                               set->bank = 1;
+                               return 1;
+                       }
+                       lo_address sur_addr = lo_address_new_from_url (sur->remote_url.c_str());
+                       _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr, true);
+
+                       sur->bank = bank_start;
+                       bank_start = bank_start + sur->bank_size;
+                       strip_feedback (sur, false);
+                       bank_leds (sur);
+                       lo_address_free (sur_addr);
+               }
+       } else {
+
+               _strip_select (boost::shared_ptr<ARDOUR::Stripable>(), addr, true);
+               s->bank = bank_limits_check (bank_start, s->bank_size, nstrips);
+               strip_feedback (s, true);
+               bank_leds (s);
        }
 
-       s->strips = get_sorted_stripables(s->strip_types, s->cue);
-       s->nstrips = s->strips.size();
 
+       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 (!s->bank_size) {
+       if (!size) {
                // no banking - bank includes all stripables
-               b_size = s->nstrips;
+               b_size = total;
        } else {
-               b_size = s->bank_size;
+               b_size = 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)) {
+       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_start = (uint32_t)((s->nstrips - b_size) + 1);
+               bank = (uint32_t)((total - b_size) + 1);
        }
-       //save bank after bank limit checks
-       s->bank = bank_start;
-
-       if (s->feedback[0] || s->feedback[1]) {
-
-               for (uint32_t n = bank_start; n < (min ((b_size + bank_start), s->nstrips + 1)); ++n) {
-                       if (n <= s->strips.size()) {
-                               boost::shared_ptr<Stripable> stp = s->strips[n - 1];
+       return bank;
+}
 
-                               if (stp) {
-                                       listen_to_route(stp, addr);
-                               }
-                       }
-                       // slow devices need time to clear buffers
-                       usleep ((uint32_t) 20);
+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->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;
        }
-       // light bankup or bankdown buttons if it is possible to bank in that direction
-       if (s->feedback[4] && !s->no_clear) {
+       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);
@@ -1922,7 +2066,7 @@ OSC::_set_bank (uint32_t bank_start, lo_address addr)
                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);
@@ -1930,20 +2074,12 @@ OSC::_set_bank (uint32_t bank_start, lo_address addr)
                lo_send_message (addr, "/bank_down", reply);
                lo_message_free (reply);
        }
-       bank_dirty = false;
-       tick = true;
-       return 0;
 }
 
 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
@@ -1952,12 +2088,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;
@@ -1966,16 +2124,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
@@ -2168,13 +2317,13 @@ OSC::_sel_plugin (int id, lo_address addr)
 }
 
 void
-OSC::transport_frame (lo_message msg)
+OSC::transport_sample (lo_message msg)
 {
        if (!session) {
                return;
        }
        check_surface (msg);
-       framepos_t pos = session->transport_frame ();
+       samplepos_t pos = session->transport_sample ();
 
        lo_message reply = lo_message_new ();
        lo_message_add_int64 (reply, pos);
@@ -2224,7 +2373,7 @@ OSC::scrub (float delta, lo_message msg)
        if (!session) return -1;
        check_surface (msg);
 
-       scrub_place = session->transport_frame ();
+       scrub_place = session->transport_sample ();
 
        float speed;
 
@@ -2250,7 +2399,7 @@ OSC::scrub (float delta, lo_message msg)
                if (speed == 1) {
                        session->request_transport_speed (.5);
                } else {
-                       session->request_transport_speed (1);
+                       session->request_transport_speed (9.9);
                }
        } else if (speed < 0) {
                if (speed == -1) {
@@ -2289,7 +2438,7 @@ OSC::jog (float delta, lo_message msg)
                        text_message (path, "Shuttle", get_address (msg));
                        if (delta) {
                                double speed = get_transport_speed ();
-                               set_transport_speed (speed + (delta / 8));
+                               set_transport_speed (speed + (delta / 8.1));
                        } else {
                                set_transport_speed (0);
                        }
@@ -2348,31 +2497,42 @@ OSC::jog_mode (float mode, lo_message msg)
        if (!session) return -1;
 
        OSCSurface *s = get_surface(get_address (msg));
+       if (get_transport_speed () != 1.0) {
+               set_transport_speed (0);
+       }
 
        switch((uint32_t)mode)
        {
                case JOG  :
+                       text_message ("/jog/mode/name", "Jog", get_address (msg));
                        s->jogmode = JOG;
                        break;
                case SCRUB:
+                       text_message ("/jog/mode/name", "Scrub", get_address (msg));
                        s->jogmode = SCRUB;
                        break;
                case SHUTTLE:
+                       text_message ("/jog/mode/name", "Shuttle", get_address (msg));
                        s->jogmode = SHUTTLE;
                        break;
                case SCROLL:
+                       text_message ("/jog/mode/name", "Scroll", get_address (msg));
                        s->jogmode = SCROLL;
                        break;
                case TRACK:
+                       text_message ("/jog/mode/name", "Track", get_address (msg));
                        s->jogmode = TRACK;
                        break;
                case BANK:
+                       text_message ("/jog/mode/name", "Bank", get_address (msg));
                        s->jogmode = BANK;
                        break;
                case NUDGE:
+                       text_message ("/jog/mode/name", "Nudge", get_address (msg));
                        s->jogmode = NUDGE;
                        break;
                case MARKER:
+                       text_message ("/jog/mode/name", "Marker", get_address (msg));
                        s->jogmode = MARKER;
                        break;
                default:
@@ -2384,11 +2544,20 @@ OSC::jog_mode (float mode, lo_message msg)
        lo_message_free (reply);
 
        }
-       jog (0, msg);
        return 0;
 
 }
 
+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)
@@ -2675,6 +2844,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);
@@ -2753,7 +2923,7 @@ OSC::set_automation (const char *path, const char* types, lo_arg **argv, int arg
                if (sur->expand_enable && sur->expand) {
                        strp = get_strip (sur->expand, get_address (msg));
                } else {
-                       strp = ControlProtocol::first_selected_stripable();
+                       strp = _select;
                }
                ctr = 8;
        } else {
@@ -2839,7 +3009,7 @@ OSC::touch_detect (const char *path, const char* types, lo_arg **argv, int argc,
                if (sur->expand_enable && sur->expand) {
                        strp = get_strip (sur->expand, get_address (msg));
                } else {
-                       strp = ControlProtocol::first_selected_stripable();
+                       strp = _select;
                }
                ctr = 8;
        } else {
@@ -2861,11 +3031,11 @@ OSC::touch_detect (const char *path, const char* types, lo_arg **argv, int argc,
                if (control) {
                        if (touch) {
                                //start touch
-                               control->start_touch (control->session().transport_frame());
+                               control->start_touch (control->session().transport_sample());
                                ret = 0;
                        } else {
                                // end touch
-                               control->stop_touch (control->session().transport_frame());
+                               control->stop_touch (control->session().transport_sample());
                                ret = 0;
                        }
                        // just in case some crazy surface starts sending control values before touch
@@ -2885,7 +3055,7 @@ 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());
+               ctrl->start_touch (ctrl->session().transport_sample());
                _touch_timeout[ctrl] = 10;
                }
        }
@@ -2907,7 +3077,7 @@ OSC::route_mute (int ssid, int yn, lo_message msg)
                }
        }
 
-       return route_send_fail ("mute", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/mute", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -2926,7 +3096,7 @@ OSC::sel_mute (uint32_t yn, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("mute", 0, get_address (msg));
+       return float_message("/select/mute", 0, get_address (msg));
 }
 
 int
@@ -2942,7 +3112,7 @@ OSC::route_solo (int ssid, int yn, lo_message msg)
                }
        }
 
-       return route_send_fail ("solo", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/solo", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -2959,7 +3129,7 @@ OSC::route_solo_iso (int ssid, int yn, lo_message msg)
                }
        }
 
-       return route_send_fail ("solo_iso", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/solo_iso", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -2976,7 +3146,7 @@ OSC::route_solo_safe (int ssid, int yn, lo_message msg)
                }
        }
 
-       return route_send_fail ("solo_safe", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/solo_safe", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -2994,7 +3164,7 @@ OSC::sel_solo (uint32_t yn, lo_message msg)
                        session->set_control (s->solo_control(), yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
                }
        }
-       return sel_fail ("solo", 0, get_address (msg));
+       return float_message("/select/solo", 0, get_address (msg));
 }
 
 int
@@ -3013,7 +3183,7 @@ OSC::sel_solo_iso (uint32_t yn, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("solo_iso", 0, get_address (msg));
+       return float_message("/select/solo_iso", 0, get_address (msg));
 }
 
 int
@@ -3032,7 +3202,7 @@ OSC::sel_solo_safe (uint32_t yn, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("solo_safe", 0, get_address (msg));
+       return float_message("/select/solo_safe", 0, get_address (msg));
 }
 
 int
@@ -3053,7 +3223,7 @@ OSC::sel_recenable (uint32_t yn, lo_message msg)
                        }
                }
        }
-       return sel_fail ("recenable", 0, get_address (msg));
+       return float_message("/select/recenable", 0, get_address (msg));
 }
 
 int
@@ -3071,7 +3241,7 @@ OSC::route_recenable (int ssid, int yn, lo_message msg)
                        }
                }
        }
-       return route_send_fail ("recenable", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/recenable", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3107,7 +3277,7 @@ OSC::sel_recsafe (uint32_t yn, lo_message msg)
                        }
                }
        }
-       return sel_fail ("record_safe", 0, get_address (msg));
+       return float_message("/select/record_safe", 0, get_address (msg));
 }
 
 int
@@ -3124,7 +3294,7 @@ OSC::route_recsafe (int ssid, int yn, lo_message msg)
                        }
                }
        }
-       return route_send_fail ("record_safe", ssid, 0,get_address (msg));
+       return float_message_with_id ("/strip/record_safe", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3138,13 +3308,15 @@ 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;
                        }
                }
        }
 
-       return route_send_fail ("monitor_input", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/monitor_input", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3161,12 +3333,14 @@ 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;
                        }
                }
        }
-       return sel_fail ("monitor_input", 0, get_address (msg));
+       return float_message("/select/monitor_input", 0, get_address (msg));
 }
 
 int
@@ -3180,13 +3354,15 @@ 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;
                        }
                }
        }
 
-       return route_send_fail ("monitor_disk", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/monitor_disk", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3203,12 +3379,14 @@ 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;
                        }
                }
        }
-       return sel_fail ("monitor_disk", 0, get_address (msg));
+       return float_message("/select/monitor_disk", 0, get_address (msg));
 }
 
 
@@ -3226,7 +3404,7 @@ OSC::strip_phase (int ssid, int yn, lo_message msg)
                }
        }
 
-       return route_send_fail ("polarity", ssid, 0, get_address (msg));
+       return float_message_with_id ("/strip/polarity", ssid, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3245,7 +3423,7 @@ OSC::sel_phase (uint32_t yn, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("polarity", 0, get_address (msg));
+       return float_message("/select/polarity", 0, get_address (msg));
 }
 
 int
@@ -3258,42 +3436,50 @@ OSC::strip_expand (int ssid, int yn, lo_message msg)
        if (yn) {
                s = get_strip (ssid, get_address (msg));
        } else {
-               s = ControlProtocol::first_selected_stripable();
+               s = _select;
        }
 
        return _strip_select (s, get_address (msg));
 }
 
 int
-OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
+OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr, bool quiet)
 {
        if (!session) {
                return -1;
        }
-       OSCSurface *sur = get_surface(addr);
-       if (sur->sel_obs) {
-               delete sur->sel_obs;
-               sur->sel_obs = 0;
+       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()) {
+                       s = ControlProtocol::first_selected_stripable();
+               } else {
+                       s = session->master_out ();
+               }
+                       _select = s;
        }
-       bool feedback_on = sur->feedback[13];
-       if (s && feedback_on) {
-               OSCSelectObserver* sel_fb = new OSCSelectObserver (s, addr, sur);
-               s->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
+       sur->select = s;
+       s->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
+
+       OSCSelectObserver* so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs);
+       if (sur->feedback[13]) {
+               if (so != 0) {
+                       delete so;
+               }
+               OSCSelectObserver* sel_fb = new OSCSelectObserver (*this, sur);
                sur->sel_obs = sel_fb;
-       } else 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 (_select && feedback_on) {
-                       s = _select;
-                       OSCSelectObserver* sel_fb = new OSCSelectObserver (s, addr, sur);
-                       s->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
-                       sur->sel_obs = sel_fb;
-               }
-       } else if (feedback_on) {
-               route_send_fail ("select", sur->expand, 0 , addr);
-       }
-       // need to set monitor for processor changed signal
+       } 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
        boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
        if (r) {
@@ -3301,51 +3487,8 @@ OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
                processor_changed (addr);
        }
 
-       if (!feedback_on) {
-               return 0;
-       }
-       //update buttons on surface
-       int b_s = sur->bank_size;
-       if (!b_s) { // bank size 0 means we need to know how many strips there are.
-               b_s = sur->nstrips;
-       }
-       for (int i = 1;  i <= b_s; i++) {
-               string path = "expand";
-
-               if ((i == (int) sur->expand) && sur->expand_enable) {
-                       lo_message reply = lo_message_new ();
-                       if (sur->feedback[2]) {
-                               ostringstream os;
-                               os << "/strip/" << path << "/" << i;
-                               path = os.str();
-                       } else {
-                               ostringstream os;
-                               os << "/strip/" << path;
-                               path = os.str();
-                               lo_message_add_int32 (reply, i);
-                       }
-                       lo_message_add_float (reply, (float) 1);
-
-                       lo_send_message (addr, path.c_str(), reply);
-                       lo_message_free (reply);
-                       reply = lo_message_new ();
-                       lo_message_add_float (reply, 1.0);
-                       lo_send_message (addr, "/select/expand", reply);
-                       lo_message_free (reply);
-
-               } else {
-                       lo_message reply = lo_message_new ();
-                       lo_message_add_int32 (reply, i);
-                       lo_message_add_float (reply, 0.0);
-                       lo_send_message (addr, "/strip/expand", reply);
-                       lo_message_free (reply);
-               }
-       }
-       if (!sur->expand_enable) {
-               lo_message reply = lo_message_new ();
-               lo_message_add_float (reply, 0.0);
-               lo_send_message (addr, "/select/expand", reply);
-               lo_message_free (reply);
+       if (!quiet) {
+               strip_feedback (sur, false);
        }
 
        return 0;
@@ -3379,7 +3522,7 @@ OSC::strip_gui_select (int ssid, int yn, lo_message msg)
                SetStripableSelection (s);
        } else {
                if ((int) (sur->feedback.to_ulong())) {
-                       route_send_fail ("select", ssid, 0, get_address (msg));
+                       float_message_with_id ("/strip/select", ssid, 0, sur->feedback[2], get_address (msg));
                }
        }
 
@@ -3395,7 +3538,7 @@ OSC::sel_expand (uint32_t state, lo_message msg)
        if (state && sur->expand) {
                s = get_strip (sur->expand, get_address (msg));
        } else {
-               s = ControlProtocol::first_selected_stripable();
+               s = _select;
        }
 
        return _strip_select (s, get_address (msg));
@@ -3426,9 +3569,9 @@ int
 OSC::route_set_gain_dB (int ssid, float dB, lo_message msg)
 {
        if (!session) {
-               route_send_fail ("gain", ssid, -193, get_address (msg));
                return -1;
        }
+       OSCSurface *sur = get_surface(get_address (msg));
        int ret;
        if (dB < -192) {
                ret = route_set_gain_abs (ssid, 0.0, msg);
@@ -3436,7 +3579,7 @@ OSC::route_set_gain_dB (int ssid, float dB, lo_message msg)
                ret = route_set_gain_abs (ssid, dB_to_coefficient (dB), msg);
        }
        if (ret != 0) {
-               return route_send_fail ("gain", ssid, -193, get_address (msg));
+               return float_message_with_id ("/strip/gain", ssid, -193, sur->feedback[2], get_address (msg));
        }
        return 0;
 }
@@ -3468,7 +3611,7 @@ OSC::sel_gain (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("gain", -193, get_address (msg));
+       return float_message("/select/gain", -193, get_address (msg));
 }
 
 int
@@ -3499,7 +3642,7 @@ OSC::sel_dB_delta (float delta, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("gain", -193, get_address (msg));
+       return float_message("/select/gain", -193, get_address (msg));
 }
 
 int
@@ -3516,10 +3659,10 @@ OSC::route_set_gain_fader (int ssid, float pos, lo_message msg)
                        fake_touch (s->gain_control());
                        s->gain_control()->set_value (s->gain_control()->interface_to_internal (pos), sur->usegroup);
                } else {
-                       return route_send_fail ("fader", ssid, 0, get_address (msg));
+                       return float_message_with_id ("/strip/fader", ssid, 0, sur->feedback[2], get_address (msg));
                }
        } else {
-               return route_send_fail ("fader", ssid, 0, get_address (msg));
+               return float_message_with_id ("/strip/fader", ssid, 0, sur->feedback[2], get_address (msg));
        }
        return 0;
 }
@@ -3565,7 +3708,7 @@ OSC::sel_fader (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("fader", 0, get_address (msg));
+       return float_message("/select/fader", 0, get_address (msg));
 }
 
 int
@@ -3589,10 +3732,11 @@ OSC::route_set_trim_abs (int ssid, float level, lo_message msg)
 int
 OSC::route_set_trim_dB (int ssid, float dB, lo_message msg)
 {
+       OSCSurface *sur = get_surface(get_address (msg));
        int ret;
        ret = route_set_trim_abs(ssid, dB_to_coefficient (dB), msg);
        if (ret != 0) {
-               return route_send_fail ("trimdB", ssid, 0, get_address (msg));
+               return float_message_with_id ("/strip/trimdB", ssid, 0, sur->feedback[2], get_address (msg));
        }
 
 return 0;
@@ -3614,7 +3758,7 @@ OSC::sel_trim (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("trimdB", 0, get_address (msg));
+       return float_message("/select/trimdB", 0, get_address (msg));
 }
 
 int
@@ -3633,7 +3777,7 @@ OSC::sel_pan_position (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("pan_stereo_position", 0.5, get_address (msg));
+       return float_message("/select/pan_stereo_position", 0.5, get_address (msg));
 }
 
 int
@@ -3652,7 +3796,7 @@ OSC::sel_pan_width (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("pan_stereo_width", 1, get_address (msg));
+       return float_message("/select/pan_stereo_width", 1, get_address (msg));
 }
 
 int
@@ -3669,7 +3813,7 @@ OSC::route_set_pan_stereo_position (int ssid, float pos, lo_message msg)
                }
        }
 
-       return route_send_fail ("pan_stereo_position", ssid, 0.5, get_address (msg));
+       return float_message_with_id ("/strip/pan_stereo_position", ssid, 0.5, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3686,7 +3830,7 @@ OSC::route_set_pan_stereo_width (int ssid, float pos, lo_message msg)
                }
        }
 
-       return route_send_fail ("pan_stereo_width", ssid, 1, get_address (msg));
+       return float_message_with_id ("/strip/pan_stereo_width", ssid, 1, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3748,7 +3892,7 @@ OSC::sel_sendgain (int id, float val, lo_message msg)
 {
        OSCSurface *sur = get_surface(get_address (msg));
        if (sur->send_page_size && (id > (int)sur->send_page_size)) {
-               return sel_send_fail ("send_gain", id, -193, get_address (msg));
+               return float_message_with_id ("/select/send_gain", id, -193, sur->feedback[2], get_address (msg));
        }
        boost::shared_ptr<Stripable> s;
        if (sur->expand_enable) {
@@ -3779,7 +3923,7 @@ OSC::sel_sendgain (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("send_gain", id, -193, get_address (msg));
+       return float_message_with_id ("/select/send_gain", id, -193, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3787,7 +3931,7 @@ OSC::sel_sendfader (int id, float val, lo_message msg)
 {
        OSCSurface *sur = get_surface(get_address (msg));
        if (sur->send_page_size && (id > (int)sur->send_page_size)) {
-               return sel_send_fail ("send_fader", id, 0, get_address (msg));
+               return float_message_with_id ("/select/send_fader", id, 0, sur->feedback[2], get_address (msg));
        }
        boost::shared_ptr<Stripable> s;
        if (sur->expand_enable) {
@@ -3812,7 +3956,7 @@ OSC::sel_sendfader (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("send_fader", id, 0, get_address (msg));
+       return float_message_with_id ("/select/send_fader", id, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3863,7 +4007,7 @@ OSC::sel_sendenable (int id, float val, lo_message msg)
 {
        OSCSurface *sur = get_surface(get_address (msg));
        if (sur->send_page_size && (id > (int)sur->send_page_size)) {
-               return sel_send_fail ("send_enable", id, 0, get_address (msg));
+               return float_message_with_id ("/select/send_enable", id, 0, sur->feedback[2], get_address (msg));
        }
        boost::shared_ptr<Stripable> s;
        if (sur->expand_enable) {
@@ -3887,7 +4031,7 @@ OSC::sel_sendenable (int id, float val, lo_message msg)
                        boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
                        if (!r) {
                                // should never get here
-                               return sel_send_fail ("send_enable", id, 0, get_address (msg));
+                               return float_message_with_id ("/select/send_enable", id, 0, sur->feedback[2], get_address (msg));
                        }
                        boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (r->nth_send(send_id));
                        if (snd) {
@@ -3900,7 +4044,7 @@ OSC::sel_sendenable (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("send_enable", id, 0, get_address (msg));
+       return float_message_with_id ("/select/send_enable", id, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -3919,14 +4063,14 @@ OSC::sel_master_send_enable (int state, lo_message msg)
                        return 0;
                }
        }
-       return cue_float_message ("/select/master_send_enable", 0, get_address(msg));
+       return float_message ("/select/master_send_enable", 0, get_address(msg));
 }
 
 int
 OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg) {
        OSCSurface *sur = get_surface(get_address (msg));
        int paid;
-       int piid = sur->plugin_id;
+       uint32_t piid = sur->plugin_id;
        float value = 0;
        if (argc > 1) {
                // no inline args
@@ -3972,13 +4116,11 @@ OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv
                PBD::warning << "OSC: Must have parameters." << endmsg;
                return -1;
        }
-       if (piid != sur->plugin_id) {
-               // if the user is sending to a non-existant plugin, don't adjust one we do have
-               PBD::warning << "OSC: plugin: " << piid << " out of range" << endmsg;
-               return -1;
+       if (!piid || piid > sur->plugins.size ()) {
+               return float_message_with_id ("/select/plugin/parameter", paid, 0, sur->feedback[2], get_address (msg));
        }
        if (sur->plug_page_size && (paid > (int)sur->plug_page_size)) {
-               return sel_send_fail ("plugin/parameter", paid, 0, get_address (msg));
+               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) {
@@ -4001,7 +4143,7 @@ OSC::select_plugin_parameter (const char *path, const char* types, lo_arg **argv
        int parid = paid + (int)(sur->plug_page_size * (sur->plug_page - 1));
        if (parid > (int) sur->plug_params.size ()) {
                if (sur->feedback[13]) {
-                       sel_send_fail ("plugin/parameter", paid, 0, get_address (msg));
+                       float_message_with_id ("/select/plugin/parameter", paid, 0, sur->feedback[2], get_address (msg));
                }
                return 0;
        }
@@ -4434,7 +4576,7 @@ OSC::sel_pan_elevation (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("pan_elevation_position", 0, get_address (msg));
+       return float_message("/select/pan_elevation_position", 0, get_address (msg));
 }
 
 int
@@ -4453,7 +4595,7 @@ OSC::sel_pan_frontback (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("pan_frontback_position", 0.5, get_address (msg));
+       return float_message("/select/pan_frontback_position", 0.5, get_address (msg));
 }
 
 int
@@ -4472,7 +4614,7 @@ OSC::sel_pan_lfe (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("pan_lfe_control", 0, get_address (msg));
+       return float_message("/select/pan_lfe_control", 0, get_address (msg));
 }
 
 // compressor control
@@ -4492,7 +4634,7 @@ OSC::sel_comp_enable (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("comp_enable", 0, get_address (msg));
+       return float_message("/select/comp_enable", 0, get_address (msg));
 }
 
 int
@@ -4511,7 +4653,7 @@ OSC::sel_comp_threshold (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("comp_threshold", 0, get_address (msg));
+       return float_message("/select/comp_threshold", 0, get_address (msg));
 }
 
 int
@@ -4530,7 +4672,7 @@ OSC::sel_comp_speed (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("comp_speed", 0, get_address (msg));
+       return float_message("/select/comp_speed", 0, get_address (msg));
 }
 
 int
@@ -4549,7 +4691,7 @@ OSC::sel_comp_mode (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("comp_mode", 0, get_address (msg));
+       return float_message("/select/comp_mode", 0, get_address (msg));
 }
 
 int
@@ -4568,7 +4710,7 @@ OSC::sel_comp_makeup (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("comp_makeup", 0, get_address (msg));
+       return float_message("/select/comp_makeup", 0, get_address (msg));
 }
 
 // EQ control
@@ -4589,7 +4731,7 @@ OSC::sel_eq_enable (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_enable", 0, get_address (msg));
+       return float_message("/select/eq_enable", 0, get_address (msg));
 }
 
 int
@@ -4608,7 +4750,7 @@ OSC::sel_eq_hpf_freq (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_hpf/freq", 0, get_address (msg));
+       return float_message("/select/eq_hpf/freq", 0, get_address (msg));
 }
 
 int
@@ -4627,7 +4769,7 @@ OSC::sel_eq_lpf_freq (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_lpf/freq", 0, get_address (msg));
+       return float_message("/select/eq_lpf/freq", 0, get_address (msg));
 }
 
 int
@@ -4646,7 +4788,7 @@ OSC::sel_eq_hpf_enable (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_hpf/enable", 0, get_address (msg));
+       return float_message("/select/eq_hpf/enable", 0, get_address (msg));
 }
 
 int
@@ -4665,7 +4807,7 @@ OSC::sel_eq_lpf_enable (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_lpf/enable", 0, get_address (msg));
+       return float_message("/select/eq_lpf/enable", 0, get_address (msg));
 }
 
 int
@@ -4684,7 +4826,7 @@ OSC::sel_eq_hpf_slope (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_hpf/slope", 0, get_address (msg));
+       return float_message("/select/eq_hpf/slope", 0, get_address (msg));
 }
 
 int
@@ -4703,7 +4845,7 @@ OSC::sel_eq_lpf_slope (float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_fail ("eq_lpf/slope", 0, get_address (msg));
+       return float_message("/select/eq_lpf/slope", 0, get_address (msg));
 }
 
 int
@@ -4725,7 +4867,7 @@ OSC::sel_eq_gain (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("eq_gain", id + 1, 0, get_address (msg));
+       return float_message_with_id ("/select/eq_gain", id + 1, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -4747,7 +4889,7 @@ OSC::sel_eq_freq (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("eq_freq", id + 1, 0, get_address (msg));
+       return float_message_with_id ("/select/eq_freq", id + 1, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -4769,7 +4911,7 @@ OSC::sel_eq_q (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("eq_q", id + 1, 0, get_address (msg));
+       return float_message_with_id ("/select/eq_q", id + 1, 0, sur->feedback[2], get_address (msg));
 }
 
 int
@@ -4791,38 +4933,22 @@ OSC::sel_eq_shape (int id, float val, lo_message msg)
                        return 0;
                }
        }
-       return sel_send_fail ("eq_shape", id + 1, 0, get_address (msg));
-}
-
-void
-OSC::gui_selection_changed ()
-{
-       boost::shared_ptr<Stripable> strip = ControlProtocol::first_selected_stripable();
-
-       if (strip) {
-               _select = strip;
-               for (uint32_t it = 0; it < _surface.size(); ++it) {
-                       OSCSurface* sur = &_surface[it];
-                       if(!sur->expand_enable) {
-                               lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
-                               _strip_select (strip, addr);
-                       }
-               }
-       }
+       return float_message_with_id ("/select/eq_shape", id + 1, 0, sur->feedback[2], get_address (msg));
 }
 
 // timer callbacks
 bool
 OSC::periodic (void)
 {
+       if (observer_busy) {
+               return true;
+       }
        if (!tick) {
                Glib::usleep(100); // let flurry of signals subside
                if (global_init) {
-                       Glib::Threads::Mutex::Lock lm (surfaces_lock);
                        for (uint32_t it = 0; it < _surface.size(); it++) {
                                OSCSurface* sur = &_surface[it];
-                               lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
-                               global_feedback (*sur, addr);
+                               global_feedback (sur);
                        }
                        global_init = false;
                        tick = true;
@@ -4832,6 +4958,7 @@ OSC::periodic (void)
                        bank_dirty = false;
                        tick = true;
                }
+               return true;
        }
 
        if (scrub_speed != 0) {
@@ -4845,44 +4972,34 @@ OSC::periodic (void)
                        session->request_locate (scrub_place, false);
                }
        }
-
-       for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end(); x++) {
-
-               OSCGlobalObserver* go;
-
-               if ((go = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
-                       go->tick();
-               }
-       }
-       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end(); x++) {
-
-               OSCRouteObserver* ro;
-
-               if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-                       ro->tick();
-               }
-       }
        for (uint32_t it = 0; it < _surface.size(); it++) {
                OSCSurface* sur = &_surface[it];
                OSCSelectObserver* so;
                if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
-                       so->tick();
+                       so->tick ();
                }
-       }
-       for (CueObservers::iterator x = cue_observers.begin(); x != cue_observers.end(); x++) {
-
                OSCCueObserver* co;
-
-               if ((co = dynamic_cast<OSCCueObserver*>(*x)) != 0) {
-                       co->tick();
+               if ((co = dynamic_cast<OSCCueObserver*>(sur->cue_obs)) != 0) {
+                       co->tick ();
+               }
+               OSCGlobalObserver* go;
+               if ((go = dynamic_cast<OSCGlobalObserver*>(sur->global_obs)) != 0) {
+                       go->tick ();
+               }
+               for (uint32_t i = 0; i < sur->observers.size(); i++) {
+                       OSCRouteObserver* ro;
+                       if ((ro = dynamic_cast<OSCRouteObserver*>(sur->observers[i])) != 0) {
+                               ro->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 (ctrl->session().transport_frame());
+                       ctrl->stop_touch (ctrl->session().transport_sample());
                        _touch_timeout.erase (x++);
                } else {
                        x++;
@@ -4891,78 +5008,6 @@ OSC::periodic (void)
        return true;
 }
 
-int
-OSC::route_send_fail (string path, uint32_t ssid, float val, lo_address addr)
-{
-       OSCSurface *sur = get_surface(addr);
-
-       ostringstream os;
-       lo_message reply;
-       if (ssid) {
-               reply = lo_message_new ();
-               if (sur->feedback[2]) {
-                       os << "/strip/" << path << "/" << ssid;
-               } else {
-                       os << "/strip/" << path;
-                       lo_message_add_int32 (reply, ssid);
-               }
-               string str_pth = os.str();
-               lo_message_add_float (reply, (float) val);
-
-               lo_send_message (addr, str_pth.c_str(), reply);
-               lo_message_free (reply);
-       }
-       if ((_select == get_strip (ssid, addr)) || ((sur->expand == ssid) && (sur->expand_enable))) {
-               os.str("");
-               os << "/select/" << path;
-               string sel_pth = os.str();
-               reply = lo_message_new ();
-               lo_message_add_float (reply, (float) val);
-               lo_send_message (addr, sel_pth.c_str(), reply);
-               lo_message_free (reply);
-       }
-
-       return 0;
-}
-
-int
-OSC::sel_fail (string path, float val, lo_address addr)
-{
-       ostringstream os;
-       os.str("");
-       os << "/select/" << path;
-       string sel_pth = os.str();
-       lo_message reply = lo_message_new ();
-       lo_message_add_float (reply, (float) val);
-       lo_send_message (addr, sel_pth.c_str(), reply);
-       lo_message_free (reply);
-
-       return 0;
-}
-
-int
-OSC::sel_send_fail (string path, uint32_t id, float val, lo_address addr)
-{
-       OSCSurface *sur = get_surface(addr);
-
-       ostringstream os;
-       lo_message reply;
-       reply = lo_message_new ();
-       if (sur->feedback[2]) {
-               os << "/select/" << path << "/" << id;
-       } else {
-               os << "/select/" << path;
-               lo_message_add_int32 (reply, id);
-       }
-       string str_pth = os.str();
-       lo_message_add_float (reply, (float) val);
-
-       lo_send_message (addr, str_pth.c_str(), reply);
-       lo_message_free (reply);
-
-       return 0;
-}
-
 XMLNode&
 OSC::get_state ()
 {
@@ -5155,6 +5200,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));
 }
 
@@ -5179,28 +5225,6 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
        }
        s->aux = aux;
 
-       // get rid of any old CueObsevers for this address
-       //cueobserver_connections.drop_connections ();
-       CueObservers::iterator x;
-       for (x = cue_observers.begin(); x != cue_observers.end();) {
-
-               OSCCueObserver* co;
-
-               if ((co = dynamic_cast<OSCCueObserver*>(*x)) != 0) {
-
-                       int res = strcmp(lo_address_get_url(co->address()), lo_address_get_url(addr));
-
-                       if (res == 0) {
-                               delete *x;
-                               x = cue_observers.erase (x);
-                       } else {
-                               ++x;
-                       }
-               } else {
-                       ++x;
-               }
-       }
-
        // get a list of Auxes
        for (uint32_t n = 0; n < s->nstrips; ++n) {
                boost::shared_ptr<Stripable> stp = s->strips[n];
@@ -5213,9 +5237,13 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
 
                                // make a list of stripables with sends that go to this bus
                                s->sends = cue_get_sorted_stripables(stp, aux, addr);
-                               // start cue observer
-                               OSCCueObserver* co = new OSCCueObserver (stp, s->sends, addr);
-                               cue_observers.push_back (co);
+                               if (s->cue_obs) {
+                                       s->cue_obs->refresh_strip (false);
+                               } else {
+                                       // start cue observer
+                                       OSCCueObserver* co = new OSCCueObserver (*this, s);
+                                       s->cue_obs = co;
+                               }
                                ret = 0;
                        }
 
@@ -5289,7 +5317,7 @@ OSC::cue_aux_fader (float position, lo_message msg)
                        }
                }
        }
-       cue_float_message ("/cue/fader", 0, get_address (msg));
+       float_message ("/cue/fader", 0, get_address (msg));
        return -1;
 }
 
@@ -5310,7 +5338,7 @@ OSC::cue_aux_mute (float state, lo_message msg)
                        }
                }
        }
-       cue_float_message ("/cue/mute", 0, get_address (msg));
+       float_message ("/cue/mute", 0, get_address (msg));
        return -1;
 }
 
@@ -5327,7 +5355,7 @@ OSC::cue_send_fader (uint32_t id, float val, lo_message msg)
                        return 0;
                }
        }
-       cue_float_message (string_compose ("/cue/send/fader/%1", id), 0, get_address (msg));
+       float_message (string_compose ("/cue/send/fader/%1", id), 0, get_address (msg));
        return -1;
 }
 
@@ -5345,12 +5373,13 @@ OSC::cue_send_enable (uint32_t id, float state, lo_message msg)
                }
                return 0;
        }
-       cue_float_message (string_compose ("/cue/send/enable/%1", id), 0, get_address (msg));
+       float_message (string_compose ("/cue/send/enable/%1", id), 0, get_address (msg));
        return -1;
 }
 
+// generic send message
 int
-OSC::cue_float_message (string path, float val, lo_address addr)
+OSC::float_message (string path, float val, lo_address addr)
 {
 
        lo_message reply;
@@ -5363,6 +5392,38 @@ OSC::cue_float_message (string path, float val, lo_address addr)
        return 0;
 }
 
+int
+OSC::float_message_with_id (std::string path, uint32_t ssid, float value, bool in_line, lo_address addr)
+{
+       lo_message msg = lo_message_new ();
+       if (in_line) {
+               path = string_compose ("%1/%2", path, ssid);
+       } else {
+               lo_message_add_int32 (msg, ssid);
+       }
+       lo_message_add_float (msg, value);
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+       return 0;
+}
+
+int
+OSC::int_message_with_id (std::string path, uint32_t ssid, int value, bool in_line, lo_address addr)
+{
+       lo_message msg = lo_message_new ();
+       if (in_line) {
+               path = string_compose ("%1/%2", path, ssid);
+       } else {
+               lo_message_add_int32 (msg, ssid);
+       }
+       lo_message_add_int32 (msg, value);
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+       return 0;
+}
+
 int
 OSC::text_message (string path, string val, lo_address addr)
 {
@@ -5377,6 +5438,22 @@ OSC::text_message (string path, string val, lo_address addr)
        return 0;
 }
 
+int
+OSC::text_message_with_id (std::string path, uint32_t ssid, std::string val, bool in_line, lo_address addr)
+{
+       lo_message msg = lo_message_new ();
+       if (in_line) {
+               path = string_compose ("%1/%2", path, ssid);
+       } else {
+               lo_message_add_int32 (msg, ssid);
+       }
+
+       lo_message_add_string (msg, val.c_str());
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+       return 0;
+}
 
 // we have to have a sorted list of stripables that have sends pointed at our aux
 // we can use the one in osc.cc to get an aux list
@@ -5384,7 +5461,6 @@ OSC::Sorted
 OSC::cue_get_sorted_stripables(boost::shared_ptr<Stripable> aux, uint32_t id, lo_message msg)
 {
        Sorted sorted;
-       cueobserver_connections.drop_connections ();
        // fetch all stripables
        StripableList stripables;