Merge big changes (mostly Controllable) from trunk
[ardour.git] / libs / surfaces / generic_midi / generic_midi_control_protocol.h
1 #ifndef ardour_generic_midi_control_protocol_h
2 #define ardour_generic_midi_control_protocol_h
3
4 #include <set>
5 #include <glibmm/thread.h>
6 #include <ardour/types.h>
7
8 #include <control_protocol/control_protocol.h>
9
10 namespace MIDI {
11         class Port;
12 }
13
14 namespace PBD {
15         class Controllable;
16 }       
17
18 namespace ARDOUR {
19         class Session;
20 }
21
22 class MIDIControllable;
23
24 class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
25   public:
26         GenericMidiControlProtocol (ARDOUR::Session&);
27         virtual ~GenericMidiControlProtocol();
28
29         int set_active (bool yn);
30         static bool probe() { return true; }
31
32         MIDI::Port* port () const { return _port; }
33         void set_feedback_interval (ARDOUR::microseconds_t);
34
35         XMLNode& get_state ();
36         int set_state (const XMLNode&);
37
38   private:
39         MIDI::Port* _port;
40         ARDOUR::microseconds_t _feedback_interval;
41         ARDOUR::microseconds_t last_feedback_time;
42
43         void _send_feedback ();
44         void  send_feedback ();
45
46         typedef std::set<MIDIControllable*> MIDIControllables;
47         MIDIControllables controllables;
48         MIDIControllables pending_controllables;
49         Glib::Mutex controllables_lock;
50         Glib::Mutex pending_lock;
51
52         bool start_learning (PBD::Controllable*);
53         void stop_learning (PBD::Controllable*);
54
55         void learning_stopped (MIDIControllable*);
56 };
57
58 #endif /* ardour_generic_midi_control_protocol_h */