OSC: Added feedback for /select
authorLen Ovens <len@ovenwerks.net>
Sun, 5 Jun 2016 14:25:54 +0000 (07:25 -0700)
committerLen Ovens <len@ovenwerks.net>
Sun, 5 Jun 2016 14:25:54 +0000 (07:25 -0700)
libs/surfaces/osc/osc.cc
libs/surfaces/osc/osc.h
libs/surfaces/osc/osc_route_observer.cc
libs/surfaces/osc/osc_select_observer.cc [new file with mode: 0644]
libs/surfaces/osc/osc_select_observer.h [new file with mode: 0644]
libs/surfaces/osc/wscript

index 19516045dcb699bef9d82430ef0cc5747e3b4e54..f7772ab29b6a0cc831969a0bb0c2f95405a7bbec 100644 (file)
@@ -47,6 +47,7 @@
 #include "ardour/presentation_info.h"
 #include "ardour/send.h"
 
+#include "osc_select_observer.h"
 #include "osc.h"
 #include "osc_controllable.h"
 #include "osc_route_observer.h"
@@ -326,6 +327,25 @@ OSC::stop ()
                }
        }
 // 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;
+               }
+       }
+// 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 0;
 }
@@ -488,7 +508,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/monitor/gain", "f", monitor_set_gain);
                REGISTER_CALLBACK (serv, "/monitor/fader", "i", monitor_set_fader);
                REGISTER_CALLBACK (serv, "/select/recenable", "i", sel_recenable);
-               REGISTER_CALLBACK (serv, "/select/record_safe", "ii", sel_recsafe);
+               REGISTER_CALLBACK (serv, "/select/record_safe", "i", sel_recsafe);
 
 
                /* These commands require the route index in addition to the arg; TouchOSC (et al) can't use these  */ 
@@ -1063,6 +1083,8 @@ OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, lo
        OSCSurface *s = get_surface(lo_message_get_source (msg));
        s->bank_size = b_size;
        s->strip_types = strips;
+       //next line could be a call that finds out how many strips there are
+       s->nstrips = session->nroutes(); // need to do this for strips
        s->feedback = fb;
        s->gainmode = gm;
        // set bank and strip feedback
@@ -1089,6 +1111,8 @@ OSC::set_surface_strip_types (uint32_t st, lo_message msg)
 {
        OSCSurface *s = get_surface(lo_message_get_source (msg));
        s->strip_types = st;
+       //next line could be a call that finds out how many strips there are
+       s->nstrips = session->nroutes(); // need to do this for strips
 
        // set bank and strip feedback
        set_bank(s->bank, msg);
@@ -1143,12 +1167,14 @@ OSC::get_surface (lo_address addr)
        OSCSurface s;
        s.remote_url = r_url;
        s.bank = 1;
-       s.bank_size = 0;
+       s.bank_size = 0; // need to find out how many strips there are
+       s.nstrips = session->nroutes(); // may need to do this after MARK below
        s.strip_types = 31; // 31 is tracks, busses, and VCAs (no master/monitor)
        s.feedback = 0;
        s.gainmode = 0;
        //get sorted should go here
        _surface.push_back (s);
+       //MARK
        return &_surface[_surface.size() - 1];
 }
 
@@ -1589,13 +1615,38 @@ OSC::strip_select (int ssid, int yn, lo_message msg)
        int rid = get_rid (ssid, lo_message_get_source (msg));
        boost::shared_ptr<Stripable> s = session->get_remote_nth_stripable (rid, PresentationInfo::Route);
        OSCSurface *sur = get_surface(lo_message_get_source (msg));
-       sur->surface_sel = ssid;
+       delete sur->sel_obs;
 
        if (s) {
-               sur->sel = s;
+               sur->surface_sel = ssid;
+               OSCSelectObserver* sel_fb = new OSCSelectObserver (s, lo_message_get_source (msg), ssid, sur->gainmode, sur->feedback);
+               sur->sel_obs = sel_fb;
        } else {
                route_send_fail ("/strip/select", ssid, msg);
        }
+       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++) {
+                       if (i==ssid) {
+                               string path = "/strip/select";
+                               lo_message reply = lo_message_new ();
+                               if (sur->feedback[2]) {
+                                       ostringstream os;
+                                       os << path << "/" << ssid;
+                                       path = os.str();
+                               } else {
+                               lo_message_add_int32 (reply, ssid);
+                               }
+                               lo_message_add_float (reply, (float) 1);
+
+                               lo_send_message (lo_message_get_source (msg), path.c_str(), reply);
+                               lo_message_free (reply);
+                       } else {
+                               route_send_fail ("/strip/select", i, msg);
+                       }
+       }
 
        return 0;
 }
@@ -1613,10 +1664,9 @@ OSC::strip_gui_select (int ssid, int yn, lo_message msg)
        int rid = get_rid (ssid, lo_message_get_source (msg));
        boost::shared_ptr<Stripable> s = session->get_remote_nth_stripable (rid, PresentationInfo::Route);
        OSCSurface *sur = get_surface(lo_message_get_source (msg));
-       sur->surface_sel = ssid;
 
        if (s) {
-               sur->sel = s;
+               sur->surface_sel = ssid;
        } else {
                route_send_fail ("/strip/gui_select", ssid, msg);
        }
@@ -1884,7 +1934,13 @@ OSC::periodic (void)
                        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();
+               }
+       }
        return true;
 }
 
index f4cd7dcd7f14b9c69d7a1d35db6354b6b5e81968..9b045e2b751cda024bf88114d02363617d6ad00e 100644 (file)
@@ -44,6 +44,7 @@
 class OSCControllable;
 class OSCRouteObserver;
 class OSCGlobalObserver;
+class OSCSelectObserver;
 
 namespace ARDOUR {
 class Session;
@@ -98,14 +99,15 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
 // keep a surface's global setup by remote server url
        struct OSCSurface {
        public:
-               std::string remote_url;                                         // the url these setting belong to
-               uint32_t bank;                                                          // current bank
-               uint32_t bank_size;                                                     // size of banks for this surface
-               std::bitset<32> strip_types;                            // what strip types are a part of this bank
-               std::bitset<32> feedback;                                       // What is fed back? strips/meters/timecode/bar_beat/global
-               int gainmode;                                                           // what kind of faders do we have Gain db or position 0 to 1023?
-               boost::shared_ptr<ARDOUR::Stripable> sel;       //
-               uint32_t surface_sel;                                           // which strip within the bank is locally selected
+               std::string remote_url;         // the url these setting belong to
+               uint32_t bank;                          // current bank
+               uint32_t bank_size;                     // size of banks for this surface
+               std::bitset<32> strip_types;// what strip types are a part of this bank
+               uint32_t nstrips;                       // how many strips are there for strip_types
+               std::bitset<32> feedback;       // What is fed back? strips/meters/timecode/bar_beat/global
+               int gainmode;                           // what kind of faders do we have Gain db or position 0 to 1023?
+               uint32_t surface_sel;           // which strip within the bank is locally selected
+               OSCSelectObserver* sel_obs;     // So we can sync select feedback with selected channel
                //StripableList strips; //list of stripables for the current bank
        };
                /*
index 8f7abe2991557e3c4803ef70d8d4c6cbe1d0f8e9..f0758ba71a0e063299f88f3a5325b5497adcbe2c 100644 (file)
@@ -121,6 +121,7 @@ OSCRouteObserver::~OSCRouteObserver ()
                clear_strip ("/strip/monitor_input", 0);
                clear_strip ("/strip/monitor_disk", 0);
                clear_strip ("/strip/gui_select", 0);
+               clear_strip ("/strip/select", 0);
        }
        if (feedback[1]) { // level controls
                if (gainmode) {
diff --git a/libs/surfaces/osc/osc_select_observer.cc b/libs/surfaces/osc/osc_select_observer.cc
new file mode 100644 (file)
index 0000000..37c5f16
--- /dev/null
@@ -0,0 +1,314 @@
+/*
+    Copyright (C) 2009 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "boost/lambda/lambda.hpp"
+
+#include "ardour/session.h"
+#include "ardour/track.h"
+#include "ardour/monitor_control.h"
+#include "ardour/dB.h"
+#include "ardour/meter.h"
+
+#include "osc.h"
+#include "osc_select_observer.h"
+
+#include "i18n.h"
+
+using namespace std;
+using namespace PBD;
+using namespace ARDOUR;
+using namespace ArdourSurface;
+
+OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
+       : _strip (s)
+       ,ssid (ss)
+       ,gainmode (gm)
+       ,feedback (fb)
+{
+       addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
+
+       if (feedback[0]) { // buttons are separate feedback
+               _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
+               name_changed (ARDOUR::Properties::name);
+
+               _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
+               send_change_message ("/select/mute", _strip->mute_control());
+
+               _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
+               send_change_message ("/select/solo", _strip->solo_control());
+
+               boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
+               if (track) {
+               track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
+               send_monitor_status (track->monitoring_control());
+               }
+
+               boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
+               if (rec_controllable) {
+                       rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
+                       send_change_message ("/select/recenable", _strip->rec_enable_control());
+               }
+               boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
+               if (rec_controllable) {
+                       recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
+                       send_change_message ("/select/record_safe", _strip->rec_safe_control());
+               }
+       }
+
+       if (feedback[1]) { // level controls
+               if (gainmode) {
+                       _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
+                       send_gain_message ("/select/fader", _strip->gain_control());
+               } else {
+                       _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
+                       send_gain_message ("/select/gain", _strip->gain_control());
+               }
+
+               boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
+               if (trim_controllable) {
+                       trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
+                       send_trim_message ("/select/trimdB", _strip->trim_control());
+               }
+
+               boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
+               if (pan_controllable) {
+                       pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::send_change_message, this, X_("/select/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
+                       send_change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
+               }
+       }
+       tick();
+}
+
+OSCSelectObserver::~OSCSelectObserver ()
+{
+
+       strip_connections.drop_connections ();
+       // all strip buttons should be off and faders 0 and etc.
+       if (feedback[0]) { // buttons are separate feedback
+               lo_message msg = lo_message_new ();
+               // name is a string do it first
+               string path = "/select/name";
+               lo_message_add_string (msg, " ");
+               lo_send_message (addr, path.c_str(), msg);
+               lo_message_free (msg);
+               clear_strip ("/select/mute", 0);
+               clear_strip ("/select/solo", 0);
+               clear_strip ("/select/recenable", 0);
+               clear_strip ("/select/record_safe", 0);
+               clear_strip ("/select/monitor_input", 0);
+               clear_strip ("/select/monitor_disk", 0);
+       }
+       if (feedback[1]) { // level controls
+               if (gainmode) {
+                       clear_strip ("/select/fader", 0);
+               } else {
+                       clear_strip ("/select/gain", -193);
+               }
+               clear_strip ("/select/trimdB", 0);
+               clear_strip ("/select/pan_stereo_position", 0.5);
+       }
+       if (feedback[9]) {
+               clear_strip ("/select/signal", 0);
+       }
+       if (feedback[7]) {
+               if (gainmode) {
+                       clear_strip ("/select/meter", 0);
+               } else {
+                       clear_strip ("/select/meter", -193);
+               }
+       }else if (feedback[8]) {
+               clear_strip ("/select/meter", 0);
+       }
+
+       lo_address_free (addr);
+}
+
+void
+OSCSelectObserver::tick ()
+{
+       if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
+
+               float now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
+               if (now_meter < -193) now_meter = -193;
+               if (_last_meter != now_meter) {
+                       if (feedback[7] || feedback[8]) {
+                               string path = "/select/meter";
+                               lo_message msg = lo_message_new ();
+                               if (gainmode && feedback[7]) {
+                                       uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
+                                       lo_message_add_int32 (msg, lev1023);
+                                       lo_send_message (addr, path.c_str(), msg);
+                               } else if ((!gainmode) && feedback[7]) {
+                                       lo_message_add_float (msg, now_meter);
+                                       lo_send_message (addr, path.c_str(), msg);
+                               } else if (feedback[8]) {
+                                       uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
+                                       uint16_t ledbits = ~(0xfff<<ledlvl);
+                                       lo_message_add_int32 (msg, ledbits);
+                                       lo_send_message (addr, path.c_str(), msg);
+                               }
+                               lo_message_free (msg);
+                       }
+                       if (feedback[9]) {
+                               string path = "/select/signal";
+                               lo_message msg = lo_message_new ();
+                               float signal;
+                               if (now_meter < -40) {
+                                       signal = 0;
+                               } else {
+                                       signal = 1;
+                               }
+                               lo_message_add_float (msg, signal);
+                               lo_send_message (addr, path.c_str(), msg);
+                               lo_message_free (msg);
+                       }
+               }
+               _last_meter = now_meter;
+
+       }
+
+}
+
+void
+OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
+{
+       if (!what_changed.contains (ARDOUR::Properties::name)) {
+           return;
+       }
+
+       if (!_strip) {
+               return;
+       }
+
+       lo_message msg = lo_message_new ();
+
+       // ssid is the strip on the surface this observer refers to
+       // not part of the internal ordering.
+       string path = "/select/name";
+       /*if (feedback[2]) {
+               path = set_path (path);
+       } else {
+               lo_message_add_int32 (msg, ssid);
+       }*/
+       lo_message_add_string (msg, _strip->name().c_str());
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+}
+
+void
+OSCSelectObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
+{
+       lo_message msg = lo_message_new ();
+
+       lo_message_add_float (msg, (float) controllable->get_value());
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+}
+
+void
+OSCSelectObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
+{
+       int disk, input;
+       float val = controllable->get_value();
+       switch ((int) val) {
+               case 1:
+                       disk = 0;
+                       input = 1;
+                       break;
+               case 2:
+                       disk = 1;
+                       input = 0;
+                       break;
+               default:
+                       disk = 0;
+                       input = 0;
+       }
+
+       lo_message msg = lo_message_new ();
+       string path = "/select/monitor_input";
+       lo_message_add_int32 (msg, (float) input);
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+
+       msg = lo_message_new ();
+       path = "/select/monitor_disk";
+       lo_message_add_int32 (msg, (float) disk);
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+
+}
+
+void
+OSCSelectObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
+{
+       lo_message msg = lo_message_new ();
+
+       lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+}
+
+void
+OSCSelectObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
+{
+       lo_message msg = lo_message_new ();
+
+       if (gainmode) {
+               if (controllable->get_value() == 1) {
+                       lo_message_add_int32 (msg, 800);
+               } else {
+                       lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
+               }
+       } else {
+               if (controllable->get_value() < 1e-15) {
+                       lo_message_add_float (msg, -200);
+               } else {
+                       lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
+               }
+       }
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+}
+
+string
+OSCSelectObserver::set_path (string path)
+{
+       if (feedback[2]) {
+  ostringstream os;
+  os << path << "/" << ssid;
+  path = os.str();
+       }
+       return path;
+}
+
+void
+OSCSelectObserver::clear_strip (string path, float val)
+{
+       lo_message msg = lo_message_new ();
+       lo_message_add_float (msg, val);
+
+       lo_send_message (addr, path.c_str(), msg);
+       lo_message_free (msg);
+
+}
+
diff --git a/libs/surfaces/osc/osc_select_observer.h b/libs/surfaces/osc/osc_select_observer.h
new file mode 100644 (file)
index 0000000..66b4f04
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+    Copyright (C) 2009 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __osc_oscselectobserver_h__
+#define __osc_oscselectobserver_h__
+
+#include <string>
+#include <bitset>
+#include <boost/shared_ptr.hpp>
+#include <sigc++/sigc++.h>
+#include <lo/lo.h>
+
+#include "pbd/controllable.h"
+#include "pbd/stateful.h"
+#include "ardour/types.h"
+
+class OSCSelectObserver
+{
+
+  public:
+       OSCSelectObserver (boost::shared_ptr<ARDOUR::Stripable>, lo_address addr, uint32_t sid, uint32_t gainmode, std::bitset<32> feedback);
+       ~OSCSelectObserver ();
+
+       boost::shared_ptr<ARDOUR::Stripable> strip () const { return _strip; }
+       lo_address address() const { return addr; };
+       void tick (void);
+
+  private:
+       boost::shared_ptr<ARDOUR::Stripable> _strip;
+
+       PBD::ScopedConnectionList strip_connections;
+
+       lo_address addr;
+       std::string path;
+       uint32_t ssid;
+       uint32_t gainmode;
+       std::bitset<32> feedback;
+       float _last_meter;
+
+
+       void name_changed (const PBD::PropertyChange& what_changed);
+       void send_change_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
+       void send_monitor_status (boost::shared_ptr<PBD::Controllable> controllable);
+       void send_gain_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
+       void send_trim_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
+       std::string set_path (std::string path);
+       void clear_strip (std::string path, float val);
+};
+
+#endif /* __osc_oscselectobserver_h__ */
index 09252c03ccdab621161e00c5422fb137c26ddc1a..6f2bbfa0a53f1a9869ba5eefc072034a50ea8fff 100644 (file)
@@ -18,6 +18,7 @@ def build(bld):
             osc.cc
             osc_controllable.cc
             osc_route_observer.cc
+            osc_select_observer.cc
             osc_global_observer.cc
             interface.cc
             osc_gui.cc