OSC: Add setup to GUI
authorLen Ovens <len@ovenwerks.net>
Fri, 19 Aug 2016 21:22:55 +0000 (14:22 -0700)
committerLen Ovens <len@ovenwerks.net>
Fri, 19 Aug 2016 21:22:55 +0000 (14:22 -0700)
libs/surfaces/osc/osc.cc
libs/surfaces/osc/osc.h
libs/surfaces/osc/osc_gui.cc

index 7e2b7e69a7c0ed8d8f219d8e502e5cdf5745de8b..729dc186e0ea12b22cbb7e782fe13883aee24a68 100644 (file)
@@ -1219,48 +1219,52 @@ OSC::refresh_surface (lo_message msg)
 {
        if (address_only) {
                // get rid of all surfaces and observers.
-               for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
+               clear_devices();
+       }
+       OSCSurface *s = get_surface(get_address (msg));
+       // 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, msg);
+       return 0;
+}
 
-                       OSCRouteObserver* rc;
+void
+OSC::clear_devices ()
+{
+       for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
 
-                       if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
-                               delete *x;
-                               x = route_observers.erase (x);
-                       } else {
-                               ++x;
-                       }
+               OSCRouteObserver* rc;
+
+               if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+                       delete *x;
+                       x = route_observers.erase (x);
+               } else {
+                       ++x;
                }
-               // Should maybe do global_observers too
-               for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end();) {
+       }
+       // Should maybe do global_observers too
+       for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end();) {
 
-                       OSCGlobalObserver* gc;
+               OSCGlobalObserver* gc;
 
-                       if ((gc = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
-                               delete *x;
-                               x = global_observers.erase (x);
-                       } else {
-                               ++x;
-                       }
+               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;
-                       }
+       }
+       // 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;
                }
-               // add one from msg + port - Nope get_surface will do that for us
-               // but we do want to clear out surfaces
-               _surface.clear();
        }
-       OSCSurface *s = get_surface(get_address (msg));
-       // 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, msg);
-       return 0;
+       // clear out surfaces
+       _surface.clear();
 }
 
-
 int
 OSC::set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gm, lo_message msg)
 {
@@ -3143,8 +3147,8 @@ OSC::get_state ()
 {
        XMLNode& node (ControlProtocol::get_state());
        node.add_property("debugmode", (int) _debugmode); // TODO: enum2str
-       node.add_property ("address_only", address_only);
-       node.add_property ("remote_port", remote_port);
+       node.add_property ("address-only", address_only);
+       node.add_property ("remote-port", remote_port);
        node.add_property ("banksize", default_banksize);
        node.add_property ("striptypes", default_strip);
        node.add_property ("feedback", default_feedback);
@@ -3176,13 +3180,13 @@ OSC::set_state (const XMLNode& node, int version)
        if (p) {
                _debugmode = OSCDebugMode (PBD::atoi(p->value ()));
        }
-       p = node.property (X_("address_only"));
+       p = node.property (X_("address-only"));
        if (p) {
                address_only = OSCDebugMode (PBD::atoi(p->value ()));
        }
-       p = node.property (X_("remote_port"));
+       p = node.property (X_("remote-port"));
        if (p) {
-               remote_port = OSCDebugMode (PBD::atoi(p->value ()));
+               remote_port = p->value ();
        }
        p = node.property (X_("banksize"));
        if (p) {
index 6ebb1d05dacdbe2423f2ad009c284d43ad2aa773..d7dec3c39b07c4c53251eae106d96c80981f4cf9 100644 (file)
@@ -129,6 +129,7 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
                 * [10] - Send Playhead position as samples
                 * [11] - Send Playhead position as minutes seconds
                 * [12] - Send Playhead position like primary/secondary GUI clocks
+                * [13] - Send well known feedback (for /select/command
                 */
 
 
@@ -139,6 +140,19 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
        std::string get_server_url ();
        void set_debug_mode (OSCDebugMode m) { _debugmode = m; }
        OSCDebugMode get_debug_mode () { return _debugmode; }
+       int get_portmode() { return address_only; }
+       void set_portmode (int pm) { address_only = pm; }
+       int get_banksize () { return default_banksize; }
+       void set_banksize (int bs) {default_banksize = bs; }
+       int get_gainmode() { return default_gainmode; }
+       void set_gainmode (int gm) { default_gainmode = gm; }
+       int get_defaultstrip() { return default_strip; }
+       void set_defaultstrip (int st) { default_strip = st; }
+       int get_defaultfeedback() { return default_feedback; }
+       void set_defaultfeedback (int fb) { default_feedback = fb; }
+       void clear_devices ();
+       std::string get_remote_port () { return remote_port; }
+       void set_remote_port (std::string pt) { remote_port = pt; }
 
   protected:
         void thread_init ();
index 9fd2fce070f3d183b043655019dee20956e8fecb..b32203ceccb93cd28792366919345ab6b35a15f1 100644 (file)
@@ -25,6 +25,8 @@
 #include <gtkmm/box.h>
 #include <gtkmm/table.h>
 #include <gtkmm/label.h>
+#include <gtkmm/button.h>
+#include <gtkmm/spinbutton.h>
 #include <gtkmm/comboboxtext.h>
 
 #include "gtkmm2ext/gtk_ui.h"
@@ -45,8 +47,20 @@ class OSC_GUI : public Gtk::VBox
 
 private:
        Gtk::ComboBoxText debug_combo;
+       Gtk::ComboBoxText portmode_combo;
+       Gtk::SpinButton port_entry;
+       Gtk::SpinButton bank_entry;
+       Gtk::SpinButton striptypes_spin; // dropdown would be nicer
+       Gtk::SpinButton feedback_spin; // dropdown would be nicer
+       Gtk::ComboBoxText gainmode_combo;
        void debug_changed ();
-
+       void portmode_changed ();
+       void gainmode_changed ();
+       void clear_device ();
+       void port_changed ();
+       void bank_changed ();
+       void strips_changed ();
+       void feedback_changed ();
        OSC& cp;
 };
 
@@ -96,13 +110,109 @@ OSC_GUI::OSC_GUI (OSC& p)
        int n = 0; // table row
        Table* table = manage (new Table);
        Label* label;
+       Button* button;
 
+       // show our url
        label = manage (new Gtk::Label(_("Connection:")));
        table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        label = manage (new Gtk::Label(cp.get_server_url()));
        table->attach (*label, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        ++n;
 
+       // show and set port to auto (default) or manual (one surface only)
+       label = manage (new Gtk::Label(_("Port Mode:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (portmode_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       std::vector<std::string> portmode_options;
+       portmode_options.push_back (_("Auto"));
+       portmode_options.push_back (_("Manual"));
+
+       set_popdown_strings (portmode_combo, portmode_options);
+       portmode_combo.set_active ((int)cp.get_portmode());
+       ++n;
+
+       // port entry box
+       label = manage (new Gtk::Label(_("Manual Port:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (port_entry, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       port_entry.set_range(1024, 0xffff);
+       port_entry.set_increments (1, 100);
+       port_entry.set_text(cp.get_remote_port().c_str());
+       if (!cp.get_portmode()) {
+               port_entry.set_sensitive (false);
+       }
+       ++n;
+
+       // default banksize setting
+       label = manage (new Gtk::Label(_("Bank Size:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (bank_entry, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       bank_entry.set_range (0, 0xffff);
+       bank_entry.set_increments (1, 8);
+       bank_entry.set_value (cp.get_banksize());
+
+       ++n;
+
+       // Default strip types
+       label = manage (new Gtk::Label(_("Strip Types:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (striptypes_spin, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       striptypes_spin.set_range (0, 0x3ff);
+       striptypes_spin.set_increments (1, 10);
+       striptypes_spin.set_value (cp.get_defaultstrip());
+
+/*     std::vector<std::string> strip_options;
+       strip_options.push_back (_("Audio Tracks"));
+       strip_options.push_back (_("Midi Tracks"));
+       strip_options.push_back (_("Audio Buses"));
+       strip_options.push_back (_("Midi Buses"));
+       strip_options.push_back (_("Control Masters"));
+       strip_options.push_back (_("Master"));
+       strip_options.push_back (_("Monitor"));
+       strip_options.push_back (_("Selected"));
+       strip_options.push_back (_("Hidden"));*/
+
+       ++n;
+
+       // default feedback settings
+       label = manage (new Gtk::Label(_("Feedback:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (feedback_spin, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       feedback_spin.set_range (0, 0x3fff);
+       feedback_spin.set_increments (1, 10);
+       feedback_spin.set_value (cp.get_defaultfeedback());
+       /*std::vector<std::string> feedback_options;
+       feedback_options.push_back (_("Strip Buttons"));
+       feedback_options.push_back (_("Strip Controls"));
+       feedback_options.push_back (_("Use SSID as Path Extension"));
+       feedback_options.push_back (_("Send heart beat"));
+       feedback_options.push_back (_("Master and Transport Feedback"));
+       feedback_options.push_back (_("Send Bar and Beat"));
+       feedback_options.push_back (_("Send SMPTE Time"));
+       feedback_options.push_back (_("Send metering"));
+       feedback_options.push_back (_("Send  LED strip metering"));
+       feedback_options.push_back (_("Signal Present"));
+       feedback_options.push_back (_("Strip Controls"));
+       feedback_options.push_back (_("Playhead Position as Samples"));
+       feedback_options.push_back (_("Playhead Position as Minutes Seconds"));
+       feedback_options.push_back (_("Playhead Position as per GUI Clock"));
+       feedback_options.push_back (_("Extra Select Channel Controls"));*/
+
+       ++n;
+
+       // Gain Mode
+       label = manage (new Gtk::Label(_("Gain Mode:")));
+       table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+       table->attach (gainmode_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+       std::vector<std::string> gainmode_options;
+       gainmode_options.push_back (_("dB"));
+       gainmode_options.push_back (_("Position"));
+
+       set_popdown_strings (gainmode_combo, gainmode_options);
+       gainmode_combo.set_active ((int)cp.get_gainmode());
+       ++n;
+
+       // debug setting
        label = manage (new Gtk::Label(_("Debug:")));
        table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        table->attach (debug_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
@@ -114,11 +224,23 @@ OSC_GUI::OSC_GUI (OSC& p)
 
        set_popdown_strings (debug_combo, debug_options);
        debug_combo.set_active ((int)cp.get_debug_mode());
+       ++n;
+
+       // refresh button
+       button = manage (new Gtk::Button(_("Clear OSC Devices")));
+       table->attach (*button, 0, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
 
        table->show_all ();
        pack_start (*table, false, false);
 
        debug_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::debug_changed));
+       portmode_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::portmode_changed));
+       gainmode_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::gainmode_changed));
+       button->signal_clicked().connect (sigc::mem_fun (*this, &OSC_GUI::clear_device));
+       port_entry.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::port_changed));
+       bank_entry.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::bank_changed));
+       striptypes_spin.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::strips_changed));
+       feedback_spin.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::feedback_changed));
 }
 
 OSC_GUI::~OSC_GUI ()
@@ -143,3 +265,72 @@ OSC_GUI::debug_changed ()
                assert (0);
        }
 }
+
+void
+OSC_GUI::portmode_changed ()
+{
+       std::string str = portmode_combo.get_active_text ();
+       if (str == _("Auto")) {
+               cp.set_portmode (0);
+               port_entry.set_sensitive (false);
+       }
+       else if (str == _("Manual")) {
+               cp.set_portmode (1);
+               port_entry.set_sensitive (true);
+       }
+       else {
+               std::cerr << "Invalid OSC Port Mode\n";
+               assert (0);
+       }
+}
+
+void
+OSC_GUI::port_changed ()
+{
+       std::string str = port_entry.get_text ();
+       cp.set_remote_port (str);
+}
+
+void
+OSC_GUI::bank_changed ()
+{
+       uint32_t bsize = bank_entry.get_value ();
+       cp.set_banksize (bsize);
+
+}
+
+void
+OSC_GUI::strips_changed ()
+{
+       uint32_t st = striptypes_spin.get_value ();
+       cp.set_defaultstrip (st);
+}
+
+void
+OSC_GUI::feedback_changed ()
+{
+       uint32_t fb = feedback_spin.get_value ();
+       cp.set_defaultfeedback (fb);
+}
+
+void
+OSC_GUI::gainmode_changed ()
+{
+       std::string str = gainmode_combo.get_active_text ();
+       if (str == _("dB")) {
+               cp.set_gainmode (0);
+       }
+       else if (str == _("Position")) {
+               cp.set_gainmode (1);
+       }
+       else {
+               std::cerr << "Invalid OSC Gain Mode\n";
+               assert (0);
+       }
+}
+
+void
+OSC_GUI::clear_device ()
+{
+       cp.clear_devices();
+}