flext  0.6.2
flstdc.h
Go to the documentation of this file.
1 /*
2 flext - C++ layer for Max and Pure Data externals
3 
4 Copyright (c) 2001-2022 Thomas Grill (gr@grrrr.org)
5 For information on usage and redistribution, and for a DISCLAIMER OF ALL
6 WARRANTIES, see the file, "license.txt," in this distribution.
7 */
8 
16 #ifndef __FLEXT_STDC_H
17 #define __FLEXT_STDC_H
18 
19 #if defined(_MSC_VER) && (_MSC_VER < 0x1300)
20 /*
21  include math.h here - when included with PD or Max/MSP headers,
22  C linkage would be used which disturbs MSVC6
23 */
24 #include <cmath>
25 #endif
26 
27 #ifdef _MSC_VER
28 #include <crtdbg.h>
29 #endif
30 #include <cassert>
31 
32 // PD stuff
33 
34 #if FLEXT_SYS == FLEXT_SYS_PD
35 
36 /* PD definitions start here */
37 
38 #ifdef _MSC_VER
39  #pragma warning (push)
40  #pragma warning (disable:4091 4005)
41 #endif
42 
43 #if FLEXT_OS == FLEXT_OS_WIN && !defined(NT)
44 #define NT
45 #endif
46 
47 extern "C" {
48  // Include the relevant PD header files
49  #ifdef FLEXT_DEBUG
50  /* PD header file structure has changed with version 0.37
51  from then on m_imp.h needs m_pd.h to be included before
52  on the other hand versions < 0.37 don't like that....
53  (they want m_imp.h solely as m_pd.h is included therein)
54  So better use the m_pd.h here also for the debug version.
55  Change that if really needed for debugging PD internals...
56  */
57 
58  #ifndef PD_VERSION
59  // include only if not already included
60  #include <m_pd.h>
61  #endif
62 // #include <m_imp.h> // for easier debugging
63  #else
64  #ifndef PD_VERSION
65  // include only if not already included
66  #include <m_pd.h>
67  #endif
68  #endif
69 }
70 
71 #ifdef _MSC_VER
72  #pragma warning (pop)
73 #endif
74 
75 #include "flpushns.h"
76 
77 #ifdef cabs
78 #undef cabs // this is defined in m_pd.h (clashes with math.h in MacOSX)
79 #endif
80 
81 #define internal_error(fmt, ...) pd_error(NULL, fmt, __VA_ARGS__)
82 
83 typedef t_object t_sigobj;
84 typedef t_gpointer *t_ptrtype;
85 
86 typedef t_float t_flint;
87 typedef t_symbol *t_symtype;
88 typedef t_class **t_thing;
89 
90 typedef t_clock t_qelem;
91 
92 #define A_NOTHING A_NULL
93 #define A_FLINT A_FLOAT
94 #define A_DEFFLINT A_DEFFLOAT
95 #define A_DEFSYMBOL A_DEFSYM
96 
97 #include "flpopns.h"
98 
99 
100 #elif FLEXT_SYS == FLEXT_SYS_MAX
101 
102 /* -------------- Max/MSP ------------------- */
103 
104 // 2-byte alignment for Max/MSP structures
105 #ifdef _MSC_VER
106 #pragma pack(push,flext_maxsdk)
107 #pragma pack(2)
108 #endif
109 
110 // Include the relevant Max/MSP header files
111 
112 #if FLEXT_OS == FLEXT_OS_MAC
113  #if FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH
114  // MachO version - must insert prefix header
115  #include <Carbon/Carbon.h>
116  #else
117  // CFM version
118  #ifndef __MRC__
119  #define powerc
120  #endif
121  #define __MOTO__ 0
122 
123  #include <MacTypes.h>
124  #endif
125 #elif FLEXT_OS == FLEXT_OS_WIN
126  #define WIN_VERSION 1
127  #define WIN_EXT_VERSION 1
128 #endif
129 
130 
131 #ifdef FLEXT_USE_MAXAPI
132 // using https://github.com/Cycling74/max-api (usually as part of the Max Devkit package)
133 
134  #include <c74_msp.h>
135  using namespace c74::max;
136 
137  #if MSP64
138  typedef double t_sample;
139  #else
140  typedef float t_sample;
141  #endif
142 
143  #define _FLEXT_MAX5SDK
144 
145 #else // FLEXT_USE_MAXAPI
146 
147  // necessary for the old OS9 SDK
148  extern "C" {
149 
150  #include "ext.h"
151  #include "ext_user.h"
152 
153  #if FLEXT_OS != FLEXT_OS_MAC || defined(MAC_VERSION)
154  // doesn't exist for OS9
155  #include "ext_critical.h"
156  #include "buffer.h"
157  #else
158  // for OS9 include "inofficial" header file
159  #include "flmspbuffer.h"
160  #endif
161 
162  #include "z_dsp.h"
163  #include "ext_obex.h"
164 
165  // check for Max5 SDK
166  #include "commonsyms.h"
167 
168 #if C74_MAX_SDK_VERSION >= 0x0500 || COMMON_SYMBOLS_VERSION >= 500
169  #define _FLEXT_MAX5SDK
170 #endif
171 
172 } // extern "C"
173 
174 #endif // FLEXT_USE_MAXAPI
175 
176 #include "flpushns.h"
177 
178 #undef WIN_VERSION
179 
180 typedef t_pxobject t_sigobj; // that's the all-in-one object type of Max/MSP (not very memory-efficent, i guess)
181 typedef t_patcher t_canvas;
182 
183 typedef t_int t_flint;
184 typedef t_symbol *t_symtype;
185 typedef t_object *t_thing;
186 
187 #ifndef _FLEXT_MAX5SDK
188  // for the following to work you should have the latest SDK
189  #if FLEXT_OS == FLEXT_OS_MAC //&& !defined(MAC_VERSION)
190  typedef struct qelem t_qelem;
191  #else
192  typedef void *t_qelem;
193  #endif
194 #endif
195 
196 #ifndef FLEXT_USE_MAXAPI
197  typedef void t_outlet;
198 #endif
199 
200 typedef method t_method;
201 typedef method t_newmethod;
202 typedef int t_atomtype;
203 
204 #ifndef _FLEXT_MAX5SDK
205 typedef struct clock t_clock; // this is defined in the Max5 SDK
206 #endif
207 
208 typedef void t_binbuf;
209 
210 #undef clock_free
211 #define clock_free(tick) freeobject((object *)tick)
212 
213 #define A_NULL A_NOTHING
214 #define A_DEFFLINT A_DEFLONG
215 
216 #ifndef A_INT
217 #define A_INT A_LONG
218 #endif
219 
220 #ifndef A_DEFINT
221 #define A_DEFINT A_DEFLONG
222 #endif
223 
224 #ifndef A_SYMBOL
225 #define A_SYMBOL A_SYM
226 #endif
227 
228 #ifndef A_DEFSYMBOL
229 #define A_DEFSYMBOL A_DEFSYM
230 #endif
231 
232 #if FLEXT_OS == FLEXT_OS_MAC && !defined(MAC_VERSION)
233 // simulate non-existing functions for OS9
234 #define critical_enter(N)
235 #define critical_exit(N)
236 #endif
237 
238 #define internal_error error
239 
240 #ifdef _MSC_VER
241 #pragma pack(pop,flext_maxsdk)
242 #endif
243 
244 #include "flpopns.h"
245 
246 #else
247 #error Platform not supported
248 #endif // FLEXT_SYS
249 
250 
251 // general definitions
252 
253 #include "flpushns.h"
254 
255 typedef t_symbol *t_symptr;
256 
257 // -------------------------
258 
259 #ifdef FLEXT_LOGGING
260 /* If FLEXT_LOGGING is defined implement logging */
261 
262 #ifdef _MSC_VER
263 #define FLEXT_LOG(s) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s)
264 #define FLEXT_LOG1(s,v1) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1)
265 #define FLEXT_LOG2(s,v1,v2) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2)
266 #define FLEXT_LOG3(s,v1,v2,v3) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3)
267 #define FLEXT_LOG4(s,v1,v2,v3,v4) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4)
268 #define FLEXT_LOG5(s,v1,v2,v3,v4,v5) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5)
269 #define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6)
270 #define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7)
271 #define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7,v8)
272 #define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",s,v1,v2,v3,v4,v5,v6,v7,v8,v9)
273 #else
274 #define FLEXT_LOG(s) post(s)
275 #define FLEXT_LOG1(s,v1) post(s,v1)
276 #define FLEXT_LOG2(s,v1,v2) post(s,v1,v2)
277 #define FLEXT_LOG3(s,v1,v2,v3) post(s,v1,v2,v3)
278 #define FLEXT_LOG4(s,v1,v2,v3,v4) post(s,v1,v2,v3,v4)
279 #define FLEXT_LOG5(s,v1,v2,v3,v4,v5) post(s,v1,v2,v3,v4,v5)
280 #define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) post(s,v1,v2,v3,v4,v5,v6)
281 #define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) post(s,v1,v2,v3,v4,v5,v6,v7)
282 #define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) post(s,v1,v2,v3,v4,v5,v6,v7,v8)
283 #define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) post(s,v1,v2,v3,v4,v5,v6,v7,v8,v9)
284 #endif
285 
286 #else
287 
288 /* If FLEXT_LOGGING is not defined avoid logging */
289 #define FLEXT_LOG(s) ((void)0)
290 #define FLEXT_LOG1(s,v1) ((void)0)
291 #define FLEXT_LOG2(s,v1,v2) ((void)0)
292 #define FLEXT_LOG3(s,v1,v2,v3) ((void)0)
293 #define FLEXT_LOG4(s,v1,v2,v3,v4) ((void)0)
294 #define FLEXT_LOG5(s,v1,v2,v3,v4,v5) ((void)0)
295 #define FLEXT_LOG6(s,v1,v2,v3,v4,v5,v6) ((void)0)
296 #define FLEXT_LOG7(s,v1,v2,v3,v4,v5,v6,v7) ((void)0)
297 #define FLEXT_LOG8(s,v1,v2,v3,v4,v5,v6,v7,v8) ((void)0)
298 #define FLEXT_LOG9(s,v1,v2,v3,v4,v5,v6,v7,v8,v9) ((void)0)
299 
300 #endif
301 
302 #define FLEXT_UNUSED(x) (void)(x)
303 
304 #ifdef FLEXT_DEBUG
305 #ifdef _MSC_VER
306 #define FLEXT_ASSERT(b) do { if(!(b)) _CrtDbgReport(_CRT_ASSERT,__FILE__,__LINE__,"flext",#b); } while(false)
307 #define FLEXT_WARN(str) _CrtDbgReport(_CRT_WARN,__FILE__,__LINE__,"flext",NULL)
308 #define FLEXT_ERROR(str) _CrtDbgReport(_CRT_ERROR,__FILE__,__LINE__,"flext",NULL)
309 #else
310 #define FLEXT_ASSERT(b) assert(b)
311 //#define FLEXT_ASSERT(b) do { if(!(b)) error("Assertion failed: " #b " - in " __FILE__ " line %i",(int)__LINE__); } while(false)
312 #define FLEXT_WARN(str) internal_error("Warning: in " __FILE__ " line %i",(int)__LINE__)
313 #define FLEXT_ERROR(str) internal_error("Error: in " __FILE__ " line %i",(int)__LINE__)
314 #endif
315 #else
316 #define FLEXT_ASSERT(b) FLEXT_UNUSED(b)
317 #define FLEXT_WARN(str) FLEXT_UNUSED(str)
318 #define FLEXT_ERROR(str) internal_error("Error: in " __FILE__ " line %i",(int)__LINE__)
319 #endif
320 
321 #define ERRINTERNAL() internal_error("flext: Internal error in file " __FILE__ ", line %i - please report",(int)__LINE__)
322 
323 // ----- disable attribute editor for PD version < devel_0_36 or 0.37
324 #ifndef PD_MAJOR_VERSION
325 # undef FLEXT_NOATTREDIT
326 # define FLEXT_NOATTREDIT
327 #endif
328 
329 
330 // ----- set message queue mode -----
331 #if FLEXT_SYS == FLEXT_SYS_PD && PD_MINOR_VERSION >= 37
332 // for PD version >= 0.37test10 FLEXT_PDLOCK is standard
333 # undef FLEXT_PDLOCK
334 # define FLEXT_PDLOCK
335 #endif
336 
337 #ifndef FLEXT_QMODE
338 # if FLEXT_SYS == FLEXT_SYS_PD && PD_MINOR_VERSION >= 38 && defined(PD_DEVEL_VERSION)
339 // use idle callback
340 # define FLEXT_QMODE 1
341 # elif defined(FLEXT_PDLOCK)
342 // new PD thread locking functionality shall be used
343 # if FLEXT_SYS == FLEXT_SYS_PD
344 # ifdef FLEXT_THREADS
345 // can only be used with PD and threaded build
346 # define FLEXT_QMODE 2
347 # else
348 # define FLEXT_QMODE 0
349 # endif
350 # else
351 # error FLEXT_PDLOCK can only be defined with PD
352 # endif
353 # else
354 # define FLEXT_QMODE 0
355 # endif
356 #endif
357 
358 #ifndef FLEXT_QMODE
359 # error Internal error: Queueing mode not defined
360 #endif
361 
362 #include "flpopns.h"
363 
364 #endif
Definition of the Max/MSP buffer structure.
t_symbol * t_symptr
Definition: flstdc.h:255