OSC: only use gain change signals if value changes
authorLen Ovens <len@ovenwerks.net>
Mon, 24 Jul 2017 17:14:21 +0000 (10:14 -0700)
committerLen Ovens <len@ovenwerks.net>
Mon, 24 Jul 2017 17:21:31 +0000 (10:21 -0700)
libs/surfaces/osc/osc_cue_observer.cc
libs/surfaces/osc/osc_cue_observer.h
libs/surfaces/osc/osc_global_observer.cc
libs/surfaces/osc/osc_global_observer.h
libs/surfaces/osc/osc_route_observer.cc
libs/surfaces/osc/osc_route_observer.h
libs/surfaces/osc/osc_select_observer.cc
libs/surfaces/osc/osc_select_observer.h

index 11d62073cf8fd4e3746d05b6c399dacbbe348146..7d027b4f188eb0464972b2bc1b06468936e98de0 100644 (file)
@@ -49,6 +49,7 @@ OSCCueObserver::OSCCueObserver (boost::shared_ptr<Stripable> s, std::vector<boos
        send_change_message ("/cue/mute", 0, _strip->mute_control());
 
        gain_timeout.push_back (0);
+       _last_gain.push_back (0.0);
        _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control()), OSC::instance());
        send_gain_message (0, _strip->gain_control());
 
@@ -132,6 +133,7 @@ OSCCueObserver::send_init()
 
                        if (send->gain_control()) {
                                gain_timeout.push_back (0);
+                               _last_gain.push_back (0.0);
                                send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control()), OSC::instance());
                                send_gain_message (i + 1, send->gain_control());
                        }
@@ -213,6 +215,11 @@ OSCCueObserver::text_with_id (string path, uint32_t id, string val)
 void
 OSCCueObserver::send_gain_message (uint32_t id,  boost::shared_ptr<Controllable> controllable)
 {
+       if (_last_gain[id] != controllable->get_value()) {
+               _last_gain[id] = controllable->get_value();
+       } else {
+               return;
+       }
        string path = "/cue";
        if (id) {
                path = "/cue/send";
index 37c61a622b508fc3a5c5faf10d3a476df5a71540..fe318c9d916418f434687c0d556bfff1b5029538 100644 (file)
@@ -54,6 +54,7 @@ class OSCCueObserver
        float _last_meter;
        std::vector<uint32_t> gain_timeout;
        bool tick_enable;
+       std::vector<float> _last_gain;
 
        void name_changed (const PBD::PropertyChange& what_changed, uint32_t id);
        void send_change_message (std::string path, uint32_t id, boost::shared_ptr<PBD::Controllable> controllable);
index a76463d467e5ee92eda72a65a5e0267cc62274cc..0649626271c15aa0e734d1f90ff49e028cbfca71 100644 (file)
@@ -39,6 +39,9 @@ using namespace ArdourSurface;
 OSCGlobalObserver::OSCGlobalObserver (Session& s, ArdourSurface::OSC::OSCSurface* su)
        : sur (su)
        ,_init (true)
+       ,_last_master_gain (0.0)
+       ,_last_master_trim (0.0)
+       ,_last_monitor_gain (0.0)
 {
        addr = lo_address_new_from_url  (sur->remote_url.c_str());
        //addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
@@ -268,10 +271,25 @@ OSCGlobalObserver::send_change_message (string path, boost::shared_ptr<Controlla
 void
 OSCGlobalObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
 {
+       bool ismaster = false;
+       if (path.find("master") != std::string::npos) {
+               ismaster = true;
+               if (_last_master_gain != controllable->get_value()) {
+                       _last_master_gain = controllable->get_value();
+               } else {
+                       return;
+               }
+       } else {
+               if (_last_monitor_gain != controllable->get_value()) {
+                       _last_monitor_gain = controllable->get_value();
+               } else {
+                       return;
+               }
+       }
        if (gainmode) {
                float_message (string_compose ("%1fader", path), controllable->internal_to_interface (controllable->get_value()));
                text_message (string_compose ("%1name", path), string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
-               if (path.find("master") != std::string::npos) {
+               if (ismaster) {
                        master_timeout = 8;
                } else {
                        monitor_timeout = 8;
@@ -289,6 +307,11 @@ OSCGlobalObserver::send_gain_message (string path, boost::shared_ptr<Controllabl
 void
 OSCGlobalObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
 {
+       if (_last_master_trim != controllable->get_value()) {
+               _last_master_trim = controllable->get_value();
+       } else {
+               return;
+       }
        float_message (X_("/master/trimdB"), (float) accurate_coefficient_to_dB (controllable->get_value()));
 }
 
index 9c4e0d6ddcb370dc6fe3e41b4c94fbb1008be386..ea5a0702a5392f90b9292842b6a3c5353e03e75f 100644 (file)
@@ -51,6 +51,9 @@ class OSCGlobalObserver
 
        ArdourSurface::OSC::OSCSurface* sur;
        bool _init;
+       float _last_master_gain;
+       float _last_master_trim;
+       float _last_monitor_gain;
        lo_address addr;
        std::string path;
        uint32_t gainmode;
index 506ad8aea660622ded99437fb72c83fa34e87345..550fd396a08ee584adcc61c2eceeb1e172aa0470 100644 (file)
@@ -43,6 +43,7 @@ OSCRouteObserver::OSCRouteObserver (boost::shared_ptr<Stripable> s, uint32_t ss,
        ,ssid (ss)
        ,sur (su)
        ,_last_gain (0.0)
+       ,_last_trim (0.0)
        ,_init (true)
 {
        addr = lo_address_new_from_url  (sur->remote_url.c_str());
@@ -342,6 +343,11 @@ OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controlla
 void
 OSCRouteObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
 {
+       if (_last_trim != controllable->get_value()) {
+               _last_trim = controllable->get_value();
+       } else {
+               return;
+       }
        if (gainmode) {
                text_with_id ("/strip/name", ssid, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
                trim_timeout = 8;
@@ -364,6 +370,11 @@ OSCRouteObserver::send_trim_message (string path, boost::shared_ptr<Controllable
 void
 OSCRouteObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
 {
+       if (_last_gain != controllable->get_value()) {
+               _last_gain = controllable->get_value();
+       } else {
+               return;
+       }
        lo_message msg = lo_message_new ();
 
        if (feedback[2]) {
index acf4a8744b69485a98d3f7020a1efa0827b05099..7c80dae9366806e1e2ee5c3311df13dc6a8e913a 100644 (file)
@@ -59,6 +59,7 @@ class OSCRouteObserver
        uint32_t gain_timeout;
        uint32_t trim_timeout;
        float _last_gain;
+       float _last_trim;
        bool _init;
        ARDOUR::AutoState as;
 
index 092da95a5a358b9ba965a82e94b53cb710ac04cb..9abe57839002f1f0208d095e322366c97679dc4a 100644 (file)
@@ -54,6 +54,7 @@ OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address
        ,sur (su)
        ,nsends (0)
        ,_last_gain (0.0)
+       ,_last_trim (0.0)
        ,_init (true)
 {
        addr = lo_address_new_from_url  (sur->remote_url.c_str());
@@ -278,6 +279,8 @@ OSCSelectObserver::send_init()
        uint32_t last_send = sur->send_page * send_size;
        uint32_t c = 1;
        send_timeout.push_back (2);
+       _last_send.clear();
+       _last_send.push_back (0.0);
 
        for (uint32_t s = page_start; s < last_send; ++s, ++c) {
 
@@ -285,6 +288,7 @@ OSCSelectObserver::send_init()
                if (_strip->send_level_controllable (s)) {
                        _strip->send_level_controllable(s)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, c, _strip->send_level_controllable(s)), OSC::instance());
                        send_timeout.push_back (2);
+                       _last_send.push_back (0.0);
                        send_gain (c, _strip->send_level_controllable(s));
                        send_valid = true;
                }
@@ -619,6 +623,11 @@ OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
 void
 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
 {
+       if (_last_trim != controllable->get_value()) {
+               _last_trim = controllable->get_value();
+       } else {
+               return;
+       }
        lo_message msg = lo_message_new ();
 
        lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
@@ -631,6 +640,11 @@ void
 OSCSelectObserver::gain_message ()
 {
        float value = _strip->gain_control()->get_value();
+       if (_last_gain != value) {
+               _last_gain = value;
+       } else {
+               return;
+       }
 
        if (gainmode) {
                text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)));
@@ -686,6 +700,11 @@ OSCSelectObserver::gain_automation ()
 void
 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
 {
+       if (_last_send[id] != controllable->get_value()) {
+               _last_send[id] = controllable->get_value();
+       } else {
+               return;
+       }
        lo_message msg = lo_message_new ();
        string path;
        float value;
index 71640fd106f84eea39b210a580d804215a5248ef..393a19dc70c11b9ac60c7d4a6a34780a529f0642 100644 (file)
@@ -66,6 +66,8 @@ class OSCSelectObserver
        float _last_meter;
        uint32_t nsends;
        float _last_gain;
+       float _last_trim;
+       std::vector<float> _last_send;
        bool _init;
        float _comp_redux;
        ARDOUR::AutoState as;