Debian Codegraph @

src/core/hidio_sdl.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: hidio_sdl.h
28 // desc: HID io over SDL header
29 //
30 // author: Spencer Salazar ([email protected])
31 // Ge Wang ([email protected])
32 // Ananya Misra ([email protected])
33 // Perry R. Cook ([email protected])
34 // date: Summer 2005
35 //-----------------------------------------------------------------------------
36 #ifndef __HID_IO_H__
37 #define __HID_IO_H__
38
39 #include "chuck_def.h"
40 #include "util_buffers.h"
41 #include "util_thread.h"
42
43 #include "util_hid.h"
44
45 // forward reference
46 struct PhyHidDevIn;
47 struct PhyHidDevOut;
48
49 /* constants */
50 #define CK_MAX_HID_DEVICES 1024
51
52 //-----------------------------------------------------------------------------
53 // name: struct HidOut
54 // desc: HID out
55 //-----------------------------------------------------------------------------
56 class HidOut
57 {
58 public:
59 HidOut();
60 ~HidOut();
61
62 public:
63 t_CKBOOL open( t_CKUINT device_num = 0 );
64 t_CKBOOL close();
65 t_CKBOOL good() { return m_valid; }
66 t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; }
67
68 public:
69 void set_suppress( t_CKBOOL print_or_not )
70 { m_suppress_output = print_or_not; }
71 t_CKBOOL get_suppress()
72 { return m_suppress_output; }
73
74 public:
75 t_CKUINT send( const HidMsg * msg );
76
77 public:
78 PhyHidDevOut * phout;
79 std::vector<unsigned char> m_msg;
80 t_CKUINT m_device_num;
81 t_CKBOOL m_valid;
82 t_CKBOOL m_suppress_output;
83 };
84
85 //-----------------------------------------------------------------------------
86 // name: class HidIn
87 // desc: HID input
88 //-----------------------------------------------------------------------------
89 struct HidIn : public Chuck_Event
90 {
91 public:
92 HidIn();
93 ~HidIn();
94
95 public:
96 t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE );
97 t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type /*= CK_HID_DEV_COUNT*/, std::string & name, t_CKBOOL suppressErrMsg = FALSE );
98 t_CKBOOL close();
99 t_CKBOOL read( t_CKINT type, t_CKINT num, HidMsg * msg );
100 t_CKBOOL send( const HidMsg * msg );
101 t_CKBOOL good() { return m_valid; }
102 t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; }
103
104 public:
105 void set_suppress( t_CKBOOL print_or_not )
106 { m_suppress_output = print_or_not; }
107 t_CKBOOL get_suppress()
108 { return m_suppress_output; }
109
110 public:
111 t_CKBOOL empty();
112 t_CKUINT recv( HidMsg * msg );
113 std::string name();
114
115 public:
116 PhyHidDevIn * phin;
117 CBufferAdvance * m_buffer;
118 t_CKUINT m_read_index;
119 t_CKBOOL m_valid;
120 t_CKINT m_device_num;
121 Chuck_Object * SELF;
122 t_CKBOOL m_suppress_output;
123 };
124
125 class HidInManager
126 {
127 public:
128 static void init();
129 static void init_default_drivers();
130 static void cleanup( t_CKUINT msWait = 0 );
131 static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE );
132 static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name, t_CKBOOL suppressErrMsg = FALSE );
133 static t_CKBOOL close( HidIn * hin );
134 static void cleanup_buffer( Chuck_VM * vm );
135
136 static void probeHidIn();
137 static void probeHidOut();
138
139 #ifndef __PLATFORM_WINDOWS__
140 static void * cb_hid_input( void * );
141 #else
142 static unsigned __stdcall cb_hid_input( void * );
143 #endif
144
145 static void push_message( HidMsg & msg );
146
147 static std::map< Chuck_VM *, CBufferSimple * > m_event_buffers;
148
149 protected:
150 static std::vector< std::vector<PhyHidDevIn *> > the_matrix;
151 static XThread * the_thread;
152 static CBufferSimple * msg_buffer;
153 static t_CKBOOL thread_going;
154 static t_CKBOOL has_init;
155 };
156
157
158 class HidOutManager
159 {
160 public:
161 static t_CKBOOL open( HidOut * hout, t_CKINT device_num );
162 static t_CKBOOL close( HidOut * hout );
163
164 protected:
165 HidOutManager();
166 ~HidOutManager();
167
168 static std::vector<PhyHidDevOut *> the_phouts;
169 };
170
171 extern Chuck_Hid_Driver * default_drivers;
172
173 #endif