Remove the template description XMLNode before saving the template
[ardour.git] / libs / surfaces / generic_midi / generic_midi_control_protocol.h
index e0867fad7808916a5389988234c17c0d9b905c3d..6585c7ea2440a3bf8636ed2ba9cc53c37e62063b 100644 (file)
@@ -1,6 +1,6 @@
 /*
     Copyright (C) 2006 Paul Davis
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
 #define ardour_generic_midi_control_protocol_h
 
 #include <list>
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
+
 #include "ardour/types.h"
+#include "ardour/port.h"
 
 #include "control_protocol/control_protocol.h"
 
-namespace MIDI {
-       class Port;
-}
-
 namespace PBD {
        class Controllable;
-}      
+}
 
 namespace ARDOUR {
+       class AsyncMIDIPort;
+       class ControllableDescriptor;
+       class MidiPort;
        class Session;
 }
 
+namespace MIDI {
+    class Port;
+}
+
 class MIDIControllable;
 class MIDIFunction;
+class MIDIAction;
 
 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
   public:
@@ -49,12 +55,22 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        int set_active (bool yn);
        static bool probe() { return true; }
 
-       MIDI::Port* port () const { return _port; }
+       void stripable_selection_changed () {}
+
+       std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
+
+       boost::shared_ptr<ARDOUR::Port> input_port () const;
+       boost::shared_ptr<ARDOUR::Port> output_port () const;
+
        void set_feedback_interval (ARDOUR::microseconds_t);
 
        int set_feedback (bool yn);
        bool get_feedback () const;
 
+        boost::shared_ptr<PBD::Controllable> lookup_controllable (const ARDOUR::ControllableDescriptor&) const;
+
+       void maybe_start_touch (PBD::Controllable*);
+
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
@@ -64,7 +80,9 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
 
        int load_bindings (const std::string&);
        void drop_bindings ();
-       
+
+       void check_used_event (int, int);
+
        std::string current_binding() const { return _current_binding; }
 
        struct MapInfo {
@@ -79,8 +97,26 @@ 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;
+       }
+
+       PBD::Signal0<void> ConnectionChange;
+
   private:
-       MIDI::Port* _port;
+       boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
+       boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
+       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
+       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
+
        ARDOUR::microseconds_t _feedback_interval;
        ARDOUR::microseconds_t last_feedback_time;
 
@@ -94,11 +130,23 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
        typedef std::list<MIDIFunction*> MIDIFunctions;
        MIDIFunctions functions;
 
-       typedef std::pair<MIDIControllable*,PBD::ScopedConnection> MIDIPendingControllable;
+       typedef std::list<MIDIAction*> MIDIActions;
+       MIDIActions actions;
+
+       struct MIDIPendingControllable {
+               MIDIControllable* mc;
+               bool own_mc;
+               PBD::ScopedConnection connection;
+
+               MIDIPendingControllable (MIDIControllable* c, bool omc)
+                       : mc (c)
+                       , own_mc (omc)
+               {}
+       };
        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*);
@@ -110,16 +158,36 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
 
        MIDIControllable* create_binding (const XMLNode&);
        MIDIFunction* create_function (const XMLNode&);
+       MIDIAction* create_action (const XMLNode&);
 
        void reset_controllables ();
        void drop_all ();
 
+       enum ConnectionState {
+               InputConnected = 0x1,
+               OutputConnected = 0x2
+       };
+
+       int connection_state;
+       bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
+       PBD::ScopedConnection port_connection;
+       void connected();
+
        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 ();
+
+
 };
 
 #endif /* ardour_generic_midi_control_protocol_h */