Debian Codegraph @

src/core/chuck_def.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: chuck_def.h
28 // desc: ChucK defines for the system
29 //
30 // author: Ge Wang ([email protected] | [email protected])
31 // Perry R. Cook ([email protected])
32 // date: Autumn 2002
33 //-----------------------------------------------------------------------------
34 #ifndef __CHUCK_DEF_H__
35 #define __CHUCK_DEF_H__
36
37 #include <stdlib.h>
38 #include <memory.h>
39 #include <assert.h>
40
41
42
43
44 //-----------------------------------------------------------------------------
45 // ChucK version string
46 //-----------------------------------------------------------------------------
47 // from host (non-chugin) -- can retrieve using ChucK::version()
48 // from chugin -- can access directly as CHUCK_VERSION_STRING
49 // 1.5.0.0 (ge) | moved to chuck.h for at-a-glance visibility
50 // 1.5.2.0 (ge) | moved to chuck_def.h for chugins headers streamlining
51 //-----------------------------------------------------------------------------
52 #define CHUCK_VERSION_STRING "1.5.5.8 (chai)"
53 //-----------------------------------------------------------------------------
54
55
56
57
58 //-------------------------------------------
59 // chuck types
60 //-------------------------------------------
61 #ifndef __EMSCRIPTEN__
62 //-------------------------------------------
63 #define t_CKTIME double
64 #define t_CKDUR double
65 #define t_CKSINGLE float
66 #define t_CKDOUBLE double
67 #define t_CKFLOAT double
68 #define CK_FLT_MAX DBL_MAX
69 #define CK_FLT_MIN DBL_MIN
70 #ifdef _WIN64 // REFACTOR-2017
71 #define t_CKINT long long // REFACTOR-2017
72 #define CK_INT_MAX LLONG_MAX
73 #else
74 #define t_CKINT long
75 #define CK_INT_MAX LONG_MAX
76 #endif
77 //-------------------------------------------
78 #else // below is for __EMSCRIPTEN__
79 //-------------------------------------------
80 #define t_CKTIME double
81 #define t_CKDUR double
82 #define t_CKFLOAT double
83 #define t_CKDOUBLE double
84 #define t_CKSINGLE float
85 #define t_CKINT int // REFACTOR-2017
86 #define CK_FLT_MAX DBL_MAX
87 #define CK_FLT_MIN DBL_MIN
88 #define CK_INT_MAX INT_MAX
89 //-------------------------------------------
90 #endif
91 //-------------------------------------------
92
93 // additional types
94 #define t_CKUINT unsigned t_CKINT
95 #define t_CKBOOL unsigned t_CKINT
96 #define t_CKBYTE unsigned char
97 #define t_CKVOID void
98 #define t_CKVOIDPTR void *
99
100 // complex type
101 typedef struct { t_CKFLOAT re ; t_CKFLOAT im ; } t_CKCOMPLEX;
102 // polar type
103 typedef struct { t_CKFLOAT modulus ; t_CKFLOAT phase ; } t_CKPOLAR;
104
105 // vector types
106 typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; } t_CKVEC2;
107 typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; t_CKFLOAT z ; } t_CKVEC3;
108 typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; t_CKFLOAT z ; t_CKFLOAT w ; } t_CKVEC4;
109 typedef struct { t_CKUINT N ; t_CKFLOAT * values ; } t_CKVECTOR;
110
111 // size of types
112 #define sz_TIME sizeof(t_CKTIME)
113 #define sz_DUR sizeof(t_CKDUR)
114 #define sz_FLOAT sizeof(t_CKFLOAT)
115 #define sz_DOUBLE sizeof(t_CKDOUBLE)
116 #define sz_SINGLE sizeof(t_CKSINGLE)
117 #define sz_INT sizeof(t_CKINT)
118 #define sz_UINT sizeof(t_CKUINT)
119 #define sz_BOOL sizeof(t_CKBOOL)
120 #define sz_BYTE sizeof(t_CKBYTE)
121 #define sz_VOIDPTR sizeof(t_CKVOIDPTR)
122 #define sz_COMPLEX sizeof(t_CKCOMPLEX)
123 #define sz_POLAR sizeof(t_CKPOLAR)
124 #define sz_VEC2 sizeof(t_CKVEC2)
125 #define sz_VEC3 sizeof(t_CKVEC3)
126 #define sz_VEC4 sizeof(t_CKVEC4)
127 #define sz_VECTOR sizeof(t_CKVECTOR)
128 #define sz_VOID 0
129 #define sz_WORD 4
130
131 // kinds (added 1.3.1.0 to faciliate 64-bit support)
132 // to differentiate in case int and float have same size
133 enum te_KindOf
134 {
135 kindof_VOID = 0,
136 kindof_INT,
137 kindof_FLOAT,
138 kindof_VEC2, // 1.5.1.7 (ge) was kindof_COMPLEX
139 kindof_VEC3,
140 kindof_VEC4
141 };
142
143 typedef char * c_str;
144 typedef const char * c_constr;
145
146 // use 64-bit samples in the audio engine
147 // #define __CHUCK_USE_64_BIT_SAMPLE__
148
149 // type for audio sample
150 //-------------------------------------------
151 #ifdef __CHUCK_USE_64_BIT_SAMPLE__
152 //-------------------------------------------
153 #define SAMPLE double
154 #define CK_SILENCE 0.0
155 #define CK_DDN CK_DDN_DOUBLE
156 //-------------------------------------------
157 #else
158 //-------------------------------------------
159 #define SAMPLE float
160 #define CK_SILENCE 0.0f
161 #define CK_DDN CK_DDN_SINGLE
162 //-------------------------------------------
163 #endif
164 //-------------------------------------------
165 #define t_CKSAMPLE SAMPLE
166
167 // sample complex
168 typedef struct { SAMPLE re ; SAMPLE im ; } t_CKCOMPLEX_SAMPLE;
169
170 // bool
171 #ifndef TRUE
172 #define TRUE 1
173 #define FALSE 0
174 #endif
175
176 // special non-zero value to denote "no value" | added 1.4.2.0 (ge)
177 #define CK_NO_VALUE 0xffffffff
178
179 // 3.1415926535897932384626433832795028841971693993751058209749445...
180 #define CK_ONE_PI (3.14159265358979323846)
181 #define CK_TWO_PI (2.0 * CK_ONE_PI)
182 #define CK_SQRT2 (1.41421356237309504880)
183
184 // macro for cleaning up: tests for NULL before and sets to NULL after
185 #define CK_SAFE_DELETE(x) do { if(x){ delete (x); (x) = NULL; } } while(0)
186 #define CK_SAFE_DELETE_ARRAY(x) do { if(x){ delete [] (x); (x) = NULL; } } while(0)
187 #define CK_SAFE_RELEASE(x) do { if(x){ (x)->release(); (x) = NULL; } } while(0)
188 #define CK_SAFE_ADD_REF(x) do { if(x){ (x)->add_ref(); } } while(0)
189 // NOTE the ref assign accounts for the case that lhs == rhs and the reference==1: add BEFORE release
190 #define CK_SAFE_REF_ASSIGN(lhs,rhs) do { Chuck_VM_Object * temp = (lhs); (lhs) = (rhs); CK_SAFE_ADD_REF(lhs); CK_SAFE_RELEASE(temp); } while(0)
191 #define CK_SAFE_FREE(x) do { if(x){ free(x); (x) = NULL; } } while(0)
192 #define CK_SAFE_UNLOCK_DELETE(x) do { if(x){ (x)->unlock(); delete (x); (x) = NULL; } } while(0)
193 #define CK_SAFE_UNLOCK_RELEASE(x) do { if(x){ (x)->unlock(); (x)->release(); (x) = NULL; } } while(0)
194
195 // max + min
196 #define ck_max(x,y) ( (x) >= (y) ? (x) : (y) )
197 #define ck_min(x,y) ( (x) <= (y) ? (x) : (y) )
198
199 #ifndef __arm__
200 // dedenormal
201 #define CK_DDN_SINGLE(f) f = ( f >= 0 ? \
202 ( ( f > (t_CKSINGLE)1e-15 && f < (t_CKSINGLE)1e15 ) ? f : (t_CKSINGLE)0.0 ) : \
203 ( ( f < (t_CKSINGLE)-1e-15 && f > (t_CKSINGLE)-1e15 ) ? f : (t_CKSINGLE)0.0 ) )
204 #define CK_DDN_DOUBLE(f) f = ( f >= 0 ? \
205 ( ( f > (t_CKDOUBLE)1e-15 && f < (t_CKDOUBLE)1e15 ) ? f : 0.0 ) : \
206 ( ( f < (t_CKDOUBLE)-1e-15 && f > (t_CKDOUBLE)-1e15 ) ? f : 0.0 ) )
207 #else
208 #define CK_DDN_SINGLE(f) (f)
209 #define CK_DDN_DOUBLE(f) (f)
210 #endif // __arm__
211
212 // stats tracking
213 #if defined(__CHUCK_STAT_TRACK__)
214 #define CK_TRACK( stmt ) stmt
215 #else
216 #define CK_TRACK( stmt )
217 #endif
218
219
220 //-------------------------------------------
221 // operating system identification
222 // https://sourceforge.net/p/predef/wiki/OperatingSystems/
223 // http://web.archive.org/web/20191012035921/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
224 //-------------------------------------------
225
226 //-------------------------------------------
227 // platform: Apple
228 // related macros: __MACOSX_CORE__ __CHIP_MODE__
229 // NOTE: __CHIP_MODE__ is ChucK for iPhone; implies iOS
230 //-------------------------------------------
231 #if defined(__APPLE__) // && defined(__MACH__)
232 //-------------------------------------------
233 #ifndef __PLATFORM_APPLE__
234 #define __PLATFORM_APPLE__
235 #endif
236
237 // get information about the target sub-platform
238 #include <TargetConditionals.h>
239 #if TARGET_OS_MAC == 1
240 #if TARGET_OS_IPHONE != 1
241 #define __PLATFORM_MACOS__ // macOS
242 #else // TARGET_OS_IPHONE not 0
243 #define __PLATFORM_IOS__ // iOS, tvOS, or watchOS device
244 // even more information within iOS
245 #if TARGET_OS_EMBEDDED == 1
246 #define __PLATFORM_IOS_DEVICE__ // device actual
247 #else // TARGET_OS_EMBEDDED not 1
248 #define __PLATFORM_IOS_SIMULATOR__ // simulator
249 #endif
250 #endif
251 #else // TARGET_OS_MAC not 1
252 // apparently on Apple; but cannot determine platform target
253 // #error "[chuck build]: unknown Apple platform target"
254 #endif
255 //-------------------------------------------
256 #endif // defined(__APPLE__) && defined(__MACH__)
257 //-------------------------------------------
258
259
260 //-------------------------------------------
261 // platform: linux
262 // related macros: __LINUX_ALSA__ __LINUX_PULSE__ __LINUX_OSS__ __LINUX_JACK__ __UNIX_JACK__
263 //-------------------------------------------
264 #if defined(__linux__) || defined(__FreeBSD__)
265 //-------------------------------------------
266 #ifndef __PLATFORM_LINUX__
267 #define __PLATFORM_LINUX__
268 #endif
269 //-------------------------------------------
270 #endif // defined(__linux__) || defined(__FreeBSD__)
271 //-------------------------------------------
272
273
274 //-------------------------------------------
275 // platform: windows
276 // related macros: __WINDOWS_DS__ __WINDOWS_WASAPI__ __WINDOWS_ASIO__
277 // NOTE: Windows defines _WIN32 for both 32-bit and 64-bit
278 //-------------------------------------------
279 #if defined(_WIN32) || defined(_WIN64)
280 //-------------------------------------------
281 #ifndef __PLATFORM_WINDOWS__
282 #define __PLATFORM_WINDOWS__
283 #endif
284
285 // legacy; new code should use __PLATFORM_WINDOWS__
286 #ifndef __PLATFORM_WIN32__
287 #define __PLATFORM_WIN32__
288 #endif
289 //-------------------------------------------
290 #endif // defined(_WIN32) || defined(_WIN64)
291 //-------------------------------------------
292
293
294 //-------------------------------------------
295 // platform: Cygwin (on Windows)
296 //-------------------------------------------
297 #if defined(__CYGWIN__)
298 //-------------------------------------------
299 #ifndef __PLATFORM_CYGWIN__
300 #define __PLATFORM_CYGWIN__
301 #endif
302 #ifndef __WINDOWS_PTHREAD__
303 #define __WINDOWS_PTHREAD__
304 #endif
305 //-------------------------------------------
306 #endif // defined(__CYGWIN__)
307 //-------------------------------------------
308
309
310 //-------------------------------------------
311 // platform: web assembly
312 //-------------------------------------------
313 #if defined(__EMSCRIPTEN__)
314 //-------------------------------------------
315 #ifndef __PLATFORM_EMSCRIPTEN__
316 #define __PLATFORM_EMSCRIPTEN__
317 #endif
318 //-------------------------------------------
319 #endif // defined(__EMSCRIPTEN__)
320 //-------------------------------------------
321
322
323 //-------------------------------------------
324 // platform: android
325 // NOTE: android is based on linux; linux macros are also defined
326 //-------------------------------------------
327 #if defined(__ANDROID__)
328 //-------------------------------------------
329 #ifndef __PLATFORM_ANDROID__
330 #define __PLATFORM_ANDROID__
331 #endif
332 //-------------------------------------------
333 #endif // defined(__ANDROID__)
334 //-------------------------------------------
335
336
337 #ifdef __PLATFORM_WINDOWS__
338 // 1.4.2.0 (ge and spencer) added for legacy windows, as part of switch to snprintf
339 // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
340 #if defined(_MSC_VER) && _MSC_VER < 1900
341 #define snprintf(buf,len, format,...) _snprintf_s(buf, len,len, format, __VA_ARGS__)
342 #endif
343 #pragma warning (disable : 4996) // stdio deprecation
344 #pragma warning (disable : 4786) // stl debug info
345 #pragma warning (disable : 4312) // type casts from void*
346 #pragma warning (disable : 4311) // type casts to void*
347 #pragma warning (disable : 4244) // truncation
348 #pragma warning (disable : 4068) // unknown pragma
349 #pragma warning (disable : 4018) // signed/unsigned mismatch
350 #endif // #ifdef __PLATFORM_WINDOWS__
351
352 #ifdef __CHIP_MODE__
353 #define __DISABLE_MIDI__
354 //#define __DISABLE_SNDBUF__
355 #define __DISABLE_WATCHDOG__
356 #define __DISABLE_RAW__
357 #define __DISABLE_KBHIT__
358 #define __DISABLE_PROMPTER__
359 #define __DISABLE_OTF_SERVER__
360 #define __ALTER_HID__
361 #define __ALTER_ENTRY_POINT__
362 #define __STK_USE_SINGLE_PRECISION__
363 #endif
364
365 #ifdef __arm__
366 // enable additional optimization
367 #define __STK_USE_SINGLE_PRECISION__
368 #endif // __arm__
369
370 #endif