most of the 2.X->3.0 commit (up to rev 4299) except for gtk2_ardour/editor_canvas...
[ardour.git] / libs / surfaces / wiimote / interface.cc
1 #include <pbd/failed_constructor.h>
2
3 #include <control_protocol/control_protocol.h>
4 #include "wiimote.h"
5
6 #include <ardour/session.h>
7
8 using namespace ARDOUR;
9
10 static WiimoteControlProtocol *foo;
11
12 ControlProtocol*
13 new_wiimote_protocol (ControlProtocolDescriptor* descriptor, Session* s)
14 {
15         WiimoteControlProtocol* wmcp;
16                 
17         try {
18                 wmcp =  new WiimoteControlProtocol (*s);
19         } catch (failed_constructor& err) {
20                 return 0;
21         }
22         
23         if (wmcp-> set_active (true)) {
24                 delete wmcp;
25                 return 0;
26         }
27
28         foo = wmcp;
29
30         return wmcp;
31 }
32
33 void
34 wiimote_control_protocol_cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count, union cwiid_mesg mesg[], struct timespec *t)
35 {
36         assert(foo != 0);
37
38         foo->wiimote_callback(wiimote,mesg_count,mesg,t);
39 }
40
41 void
42 delete_wiimote_protocol (ControlProtocolDescriptor* descriptor, ControlProtocol* cp)
43 {
44         foo = 0;
45         delete cp;
46 }
47
48 bool
49 probe_wiimote_protocol (ControlProtocolDescriptor* descriptor)
50 {
51         return WiimoteControlProtocol::probe ();
52 }
53
54 static ControlProtocolDescriptor wiimote_descriptor = {
55         name : "Wiimote",
56         id : "uri://ardour.org/surfaces/wiimote:0",
57         ptr : 0,
58         module : 0,
59         mandatory : 0,
60         supports_feedback : false,
61         probe : probe_wiimote_protocol,
62         initialize : new_wiimote_protocol,
63         destroy : delete_wiimote_protocol
64 };
65         
66
67 extern "C" {
68 ControlProtocolDescriptor* 
69 protocol_descriptor () {
70         return &wiimote_descriptor;
71 }
72 }
73