Slightly tweaked patch from royvegard to add optional threshold for catch-up of non...
authorCarl Hetherington <carl@carlh.net>
Wed, 13 Jun 2012 21:53:50 +0000 (21:53 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 13 Jun 2012 21:53:50 +0000 (21:53 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12716 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/surfaces/generic_midi/generic_midi_control_protocol.cc
libs/surfaces/generic_midi/generic_midi_control_protocol.h
libs/surfaces/generic_midi/gmcp_gui.cc
libs/surfaces/generic_midi/midicontrollable.cc

index a9f5aa93415a9dfcb045be4aee264be719a38c77..d28d4f5fb130992269dd849d73d13bac3cd70099 100644 (file)
@@ -55,6 +55,7 @@ using namespace std;
 GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
        : ControlProtocol (s, _("Generic MIDI"))
        , _motorised (false)
+       , _threshold (10)
        , gui (0)
 {
        _input_port = MIDI::Manager::instance()->midi_input_port ();
@@ -647,6 +648,13 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
                        } else {
                                _motorised = false;
                        }
+
+                       if ((prop = (*citer)->property ("threshold")) != 0) {
+                               _threshold = atoi (prop->value ());
+                       } else {
+                               _threshold = 10;
+                       }
+
                }
 
                if ((*citer)->name() == "Binding") {
@@ -1011,3 +1019,9 @@ GenericMidiControlProtocol::set_motorised (bool m)
 {
        _motorised = m;
 }
+
+void
+GenericMidiControlProtocol::set_threshold (int t)
+{
+       _threshold = t;
+}
index a86808948f276f02a210b0474cf9471fc51e0a23..7248c83ba1e29a1361cdafffa912acb4cf0bc6f5 100644 (file)
@@ -87,6 +87,12 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
                return _motorised;
        }
 
+       void set_threshold (int);
+
+       int threshold () const {
+               return _threshold;
+       }
+
   private:
        MIDI::Port* _input_port;
        MIDI::Port* _output_port;
@@ -136,6 +142,7 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
            values jumping around when things are not in sync.
        */
        bool _motorised;
+       int _threshold;
 
        mutable void *gui;
        void build_gui ();
index 807e4bba2232b6eda520d12b6f7250cc2af9307d..e36562311b141e02b9ec456fe87f4ac60ec69f38 100644 (file)
@@ -46,10 +46,13 @@ private:
        Gtk::Adjustment bank_adjustment;
        Gtk::SpinButton bank_spinner;
        Gtk::CheckButton motorised_button;
+       Gtk::Adjustment threshold_adjustment;
+       Gtk::SpinButton threshold_spinner;
 
        void binding_changed ();
        void bank_changed ();
        void motorised_changed ();
+       void threshold_changed ();
 };
 
 using namespace PBD;
@@ -86,6 +89,8 @@ GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
        , bank_adjustment (1, 1, 100, 1, 10)
        , bank_spinner (bank_adjustment)
        , motorised_button ("Motorised")
+       , threshold_adjustment (1, 1, 127, 1, 10)
+       , threshold_spinner (threshold_adjustment)
 {
        vector<string> popdowns;
        popdowns.push_back (_("Reset All"));
@@ -140,7 +145,20 @@ GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
 
        motorised_button.show ();
 
+       threshold_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &GMCPGUI::threshold_changed));
+
+       label = manage (new Label (_("Threshold:")));
+       label->set_alignment (0, 0.5);
+       table->attach (*label, 0, 1, n, n + 1);
+       table->attach (threshold_spinner, 1, 2, n, n + 1);
+       ++n;
+
+       threshold_spinner.show ();
+       label->show ();
+
        pack_start (*table, false, false);
+
+       binding_changed ();
 }
 
 GMCPGUI::~GMCPGUI ()
@@ -166,6 +184,7 @@ GMCPGUI::binding_changed ()
                        if (str == x->name) {
                                cp.load_bindings (x->path);
                                motorised_button.set_active (cp.motorised ());
+                               threshold_adjustment.set_value (cp.threshold ());
                                break;
                        }
                }
@@ -177,3 +196,9 @@ GMCPGUI::motorised_changed ()
 {
        cp.set_motorised (motorised_button.get_active ());
 }
+
+void
+GMCPGUI::threshold_changed ()
+{
+       cp.set_threshold (threshold_adjustment.get_value());
+}
index ec586d353291366d56963ab1bfbf6b6c17cd2e9c..50662abdb7df0b6fc90ac17f97207011a4378ba1 100644 (file)
@@ -220,7 +220,7 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
                        float max_value = max(last_controllable_value, new_value);
                        float min_value = min(last_controllable_value, new_value);
                        float range = max_value - min_value;
-                       float threshold = 10;
+                       float threshold = (float) _surface->threshold ();
 
                        bool const in_sync = (
                                range < threshold &&