major redesign of MIDI port heirarchy and management (part 2)
[ardour.git] / libs / surfaces / generic_midi / generic_midi_control_protocol.h
index 7ad23d9373be34eef97fa57d6e9a440203ce6055..a4a51b7f99a5c2114894ee0aff282f15904cfafe 100644 (file)
 #define ardour_generic_midi_control_protocol_h
 
 #include <list>
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
+
 #include "ardour/types.h"
 
 #include "control_protocol/control_protocol.h"
 
-namespace MIDI {
-       class Port;
-}
-
 namespace PBD {
        class Controllable;
+       class ControllableDescriptor;
 }      
 
 namespace ARDOUR {
        class Session;
+       class MidiPort;
+}
+
+namespace MIDI {
+    class Port;
 }
 
 class MIDIControllable;
@@ -50,13 +53,15 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        int set_active (bool yn);
        static bool probe() { return true; }
 
-       MIDI::Port* input_port () const { return _input_port; }
-       MIDI::Port* output_port () const { return _output_port; }
+        MIDI::Port* input_port () const { return _input_port; }
+        MIDI::Port* output_port () const { return _output_port; }
        void set_feedback_interval (ARDOUR::microseconds_t);
 
        int set_feedback (bool yn);
        bool get_feedback () const;
 
+        boost::shared_ptr<PBD::Controllable> lookup_controllable (const PBD::ControllableDescriptor&) const;
+
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
@@ -81,9 +86,21 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        void next_bank ();
        void prev_bank ();
 
+       void set_motorised (bool);
+       
+       bool motorised () const {
+               return _motorised;
+       }
+
+       void set_threshold (int);
+
+       int threshold () const {
+               return _threshold;
+       }
+
   private:
-       MIDI::Port* _input_port;
-       MIDI::Port* _output_port;
+        MIDI::Port* _input_port;
+        MIDI::Port* _output_port;
        ARDOUR::microseconds_t _feedback_interval;
        ARDOUR::microseconds_t last_feedback_time;
 
@@ -103,8 +120,8 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
        typedef std::list<MIDIPendingControllable* > MIDIPendingControllables;
        MIDIPendingControllables pending_controllables;
-       Glib::Mutex controllables_lock;
-       Glib::Mutex pending_lock;
+        Glib::Threads::Mutex controllables_lock;
+        Glib::Threads::Mutex pending_lock;
 
        bool start_learning (PBD::Controllable*);
        void stop_learning (PBD::Controllable*);
@@ -124,6 +141,13 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        std::string _current_binding;
        uint32_t _bank_size;
        uint32_t _current_bank;
+       /** true if this surface is motorised.  If it is, we assume
+           that the surface's controls are never out of sync with
+           Ardour's state, so we don't have to take steps to avoid
+           values jumping around when things are not in sync.
+       */
+       bool _motorised;
+       int _threshold;
 
        mutable void *gui;
        void build_gui ();