merge with master, primarily for adrian's maximise-mixer change
[ardour.git] / libs / surfaces / wiimote / wiimote.h
1 /*
2     Copyright (C) 2009-2013 Paul Davis
3     Authors: Sampo Savolainen, Jannis Pohlmann
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef ardour_wiimote_control_protocol_h
22 #define ardour_wiimote_control_protocol_h
23
24 #include <cwiid.h>
25
26 #define ABSTRACT_UI_EXPORTS
27 #include "pbd/abstract_ui.h"
28 #include "ardour/types.h"
29 #include "control_protocol/control_protocol.h"
30
31 struct WiimoteControlUIRequest : public BaseUI::BaseRequestObject {
32 public:
33         WiimoteControlUIRequest () {}
34         ~WiimoteControlUIRequest () {}
35 };
36
37 class WiimoteControlProtocol
38         : public ARDOUR::ControlProtocol
39         , public AbstractUI<WiimoteControlUIRequest>
40 {
41 public:
42         WiimoteControlProtocol (ARDOUR::Session &);
43         virtual ~WiimoteControlProtocol ();
44
45         static bool probe ();
46         int set_active (bool yn);
47
48         XMLNode& get_state ();
49         int set_state (const XMLNode&, int version);
50
51         void start_wiimote_discovery ();
52         void stop_wiimote_discovery ();
53
54         void wiimote_callback (int mesg_count, union cwiid_mesg mesg[]);
55
56 protected:
57         void do_request (WiimoteControlUIRequest*);
58         int start ();
59         int stop ();
60
61         void thread_init ();
62
63         bool connect_idle ();
64         bool connect_wiimote ();
65
66         void update_led_state ();
67
68 protected:
69         PBD::ScopedConnectionList session_connections;
70         cwiid_wiimote_t* wiimote;
71         GSource *idle_source;
72         uint16_t button_state;
73         bool callback_thread_registered;
74 };
75
76 #endif  /* ardour_wiimote_control_protocol_h */
77