OSC: Fix select fader automation play feedback as well fixes issue #7160
[ardour.git] / libs / surfaces / osc / osc_select_observer.cc
index 657b46ff93eec0c4295e9b628e4622108ad3daaf..2cc42569cc86c57ca0fc64bd4848d4e77ee486ea 100644 (file)
 #include "ardour/solo_isolate_control.h"
 #include "ardour/solo_safe_control.h"
 #include "ardour/route.h"
+#include "ardour/send.h"
+#include "ardour/processor.h"
 
 #include "osc.h"
 #include "osc_select_observer.h"
 
+#include <glibmm.h>
+
 #include "pbd/i18n.h"
 
 using namespace std;
@@ -45,8 +49,10 @@ OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address
        ,gainmode (gm)
        ,feedback (fb)
        ,nsends (0)
+       ,_last_gain (0.0)
 {
        addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
+       as = ARDOUR::AutoState::Off;
 
        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());
@@ -95,12 +101,15 @@ OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address
        }
 
        if (feedback[1]) { // level controls
+               boost::shared_ptr<GainControl> gain_cont = _strip->gain_control();
                if (gainmode) {
-                       _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
-                       gain_message ("/select/fader", _strip->gain_control());
+                       gain_cont->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::gain_automation, this, X_("/select/fader")), OSC::instance());
+                       gain_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), gain_cont), OSC::instance());
+                       gain_automation ("/select/fader");
                } else {
-                       _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
-                       gain_message ("/select/gain", _strip->gain_control());
+                       gain_cont->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCSelectObserver::gain_automation, this, X_("/select/gain")), OSC::instance());
+                       gain_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
+                       gain_automation ("/strip/gain");
                }
 
                boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
@@ -175,11 +184,10 @@ OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address
 
 OSCSelectObserver::~OSCSelectObserver ()
 {
-
        strip_connections.drop_connections ();
        // all strip buttons should be off and faders 0 and etc.
-       clear_strip ("/select/expand", 0);
        if (feedback[0]) { // buttons are separate feedback
+               clear_strip ("/select/expand", 0);
                text_message ("/select/name", " ");
                text_message ("/select/comment", " ");
                clear_strip ("/select/mute", 0);
@@ -240,19 +248,28 @@ OSCSelectObserver::send_init()
        do {
                sends = false;
                if (_strip->send_level_controllable (nsends)) {
-                       _strip->send_level_controllable(nsends)->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, nsends, _strip->send_level_controllable(nsends)), OSC::instance());
+                       _strip->send_level_controllable(nsends)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, nsends, _strip->send_level_controllable(nsends)), OSC::instance());
                        send_timeout.push_back (0);
                        send_gain (nsends, _strip->send_level_controllable(nsends));
                        sends = true;
                }
 
                if (_strip->send_enable_controllable (nsends)) {
-                       _strip->send_enable_controllable(nsends)->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message_with_id, this, X_("/select/send_enable"), nsends + 1, _strip->send_enable_controllable(nsends)), OSC::instance());
+                       _strip->send_enable_controllable(nsends)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message_with_id, this, X_("/select/send_enable"), nsends + 1, _strip->send_enable_controllable(nsends)), OSC::instance());
                        enable_message_with_id ("/select/send_enable", nsends + 1, _strip->send_enable_controllable(nsends));
                        sends = true;
                } else if (sends) {
-                       // not used by Ardour, just mixbus so in Ardour always true
-                       clear_strip_with_id ("/select/send_enable", nsends + 1, 1);
+                       boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_strip);
+                       if (!r) {
+                               // should never get here
+                               clear_strip_with_id ("/select/send_enable", nsends + 1, 0);
+                       }
+                       boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (r->nth_send(nsends));
+                       if (snd) {
+                               boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (snd);
+                               proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), nsends + 1, proc), OSC::instance());
+                               clear_strip_with_id ("/select/send_enable", nsends + 1, proc->enabled());
+                       }
                }
                // this should get signalled by the route the send goes to, (TODO)
                if (!gainmode && sends) { // if the gain control is there, this is too
@@ -354,6 +371,18 @@ OSCSelectObserver::tick ()
                        }
                }
        }
+       if (feedback[1]) {
+               if (as != ARDOUR::AutoState::Off) {
+                       if(_last_gain != _strip->gain_control()->get_value()) {
+                               _last_gain = _strip->gain_control()->get_value();
+                               if (gainmode) {
+                                       gain_message ("/select/fader", _strip->gain_control());
+                               } else {
+                                       gain_message ("/select/fader", _strip->gain_control());
+                               }
+                       }
+               }
+       }
 
 }
 
@@ -498,6 +527,20 @@ OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> co
        lo_message_free (msg);
 }
 
+void
+OSCSelectObserver::gain_automation (string path)
+{
+       lo_message msg = lo_message_new ();
+       string apath = string_compose ("%1/automation", path);
+
+       boost::shared_ptr<GainControl> control = _strip->gain_control();
+       as = control->alist()->automation_state();
+       lo_message_add_float (msg, as);
+       gain_message (path, control);
+       lo_send_message (addr, apath.c_str(), msg);
+       lo_message_free (msg);
+}
+
 void
 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
 {
@@ -542,6 +585,15 @@ OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable>
        lo_message_free (msg);
 }
 
+void
+OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
+{
+       // with no delay value is wrong
+       Glib::usleep(10);
+
+       clear_strip_with_id ("/select/send_enable", id, proc->enabled());
+}
+
 void
 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
 {
@@ -612,8 +664,12 @@ OSCSelectObserver::eq_end ()
 {
        //need to check feedback for [13]
        eq_connections.drop_connections ();
-       clear_strip ("/select/eq_hpf", 0);
-       clear_strip ("/select/eq_enable", 0);
+       if (_strip->eq_hpf_controllable ()) {
+               clear_strip ("/select/eq_hpf", 0);
+       }
+       if (_strip->eq_enable_controllable ()) {
+               clear_strip ("/select/eq_enable", 0);
+       }
 
        for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
                text_with_id ("/select/eq_band_name", i, " ");