Added evoral dependency
[ardour.git] / libs / surfaces / wiimote / wiimote.h
1 #ifndef ardour_wiimote_control_protocol_h
2 #define ardour_wiimote_control_protocol_h
3
4 #include <ardour/types.h>
5 #include <control_protocol/control_protocol.h>
6
7 #include <glibmm/thread.h>
8
9 #include <pbd/abstract_ui.h>
10
11 #include <cwiid.h>
12
13
14 namespace ARDOUR {
15         class Session;
16 }
17
18 #define ENSURE_WIIMOTE_THREAD(slot) \
19         if (Glib::Thread::self() != main_thread) {\
20                 slot_mutex.lock();\
21                 slot_list.push_back(slot);\
22                 slot_cond.signal();\
23                 slot_mutex.unlock();\
24                 return;\
25         } 
26
27
28 class WiimoteControlProtocol : public ARDOUR::ControlProtocol {
29         public:
30                 WiimoteControlProtocol (ARDOUR::Session &);
31                 virtual ~WiimoteControlProtocol ();
32
33                 static bool probe();
34
35                 int set_active (bool yn);
36                 XMLNode& get_state();
37                 int set_state(const XMLNode&);
38
39                 void wiimote_callback(cwiid_wiimote_t *, int, union cwiid_mesg [], 
40                                       struct timespec *);
41
42         private:
43                 
44                 void wiimote_main();
45                 volatile bool main_thread_quit;
46                 volatile bool restart_discovery;
47
48                 Glib::Thread *main_thread;
49
50                 void update_led_state();
51
52                 bool callback_thread_registered_for_ardour;
53
54                 static uint16_t button_state;
55
56                 cwiid_wiimote_t *wiimote_handle;
57
58                 Glib::Cond slot_cond;
59                 Glib::Mutex slot_mutex;
60
61                 std::list< sigc::slot<void> > slot_list;
62
63                 sigc::connection transport_state_conn;
64                 sigc::connection record_state_conn;
65 };
66
67
68 #endif  /* ardour_wiimote_control_protocol_h */
69