Mercurial > hg > beaglert
comparison include/libpd/m_pd.h @ 467:03a2cd5f151b prerelease
Libpd headers moved to include/, rm useless basic_libpd example, fixed Makefile to actually build default_libpd_render
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 20 Jun 2016 16:57:35 +0100 |
parents | examples/basic_libpd/m_pd.h@dbeed520b014 |
children |
comparison
equal
deleted
inserted
replaced
466:1d585c5fa663 | 467:03a2cd5f151b |
---|---|
1 /* Copyright (c) 1997-1999 Miller Puckette. | |
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL | |
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | |
4 | |
5 #ifndef __m_pd_h_ | |
6 | |
7 #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) | |
8 extern "C" { | |
9 #endif | |
10 | |
11 #define PD_MAJOR_VERSION 0 | |
12 #define PD_MINOR_VERSION 46 | |
13 #define PD_BUGFIX_VERSION 6 | |
14 #define PD_TEST_VERSION "" | |
15 extern int pd_compatibilitylevel; /* e.g., 43 for pd 0.43 compatibility */ | |
16 | |
17 /* old name for "MSW" flag -- we have to take it for the sake of many old | |
18 "nmakefiles" for externs, which will define NT and not MSW */ | |
19 #if defined(NT) && !defined(MSW) | |
20 #define MSW | |
21 #endif | |
22 | |
23 /* These pragmas are only used for MSVC, not MinGW or Cygwin <hans@at.or.at> */ | |
24 #ifdef _MSC_VER | |
25 /* #pragma warning( disable : 4091 ) */ | |
26 #pragma warning( disable : 4305 ) /* uncast const double to float */ | |
27 #pragma warning( disable : 4244 ) /* uncast float/int conversion etc. */ | |
28 #pragma warning( disable : 4101 ) /* unused automatic variables */ | |
29 #endif /* _MSC_VER */ | |
30 | |
31 /* the external storage class is "extern" in UNIX; in MSW it's ugly. */ | |
32 #ifdef _WIN32 | |
33 #ifdef PD_INTERNAL | |
34 #define EXTERN __declspec(dllexport) extern | |
35 #else | |
36 #define EXTERN __declspec(dllimport) extern | |
37 #endif /* PD_INTERNAL */ | |
38 #else | |
39 #define EXTERN extern | |
40 #endif /* _WIN32 */ | |
41 | |
42 /* and depending on the compiler, hidden data structures are | |
43 declared differently: */ | |
44 #if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ ) | |
45 #define EXTERN_STRUCT struct | |
46 #else | |
47 #define EXTERN_STRUCT extern struct | |
48 #endif | |
49 | |
50 /* Define some attributes, specific to the compiler */ | |
51 #if defined(__GNUC__) | |
52 #define ATTRIBUTE_FORMAT_PRINTF(a, b) __attribute__ ((format (printf, a, b))) | |
53 #else | |
54 #define ATTRIBUTE_FORMAT_PRINTF(a, b) | |
55 #endif | |
56 | |
57 #if !defined(_SIZE_T) && !defined(_SIZE_T_) | |
58 #include <stddef.h> /* just for size_t -- how lame! */ | |
59 #endif | |
60 | |
61 /* Microsoft Visual Studio is not C99, it does not provide stdint.h */ | |
62 #ifdef _MSC_VER | |
63 typedef signed __int8 int8_t; | |
64 typedef signed __int16 int16_t; | |
65 typedef signed __int32 int32_t; | |
66 typedef signed __int64 int64_t; | |
67 typedef unsigned __int8 uint8_t; | |
68 typedef unsigned __int16 uint16_t; | |
69 typedef unsigned __int32 uint32_t; | |
70 typedef unsigned __int64 uint64_t; | |
71 #else | |
72 # include <stdint.h> | |
73 #endif | |
74 | |
75 /* for FILE, needed by sys_fopen() and sys_fclose() only */ | |
76 #include <stdio.h> | |
77 | |
78 #define MAXPDSTRING 1000 /* use this for anything you want */ | |
79 #define MAXPDARG 5 /* max number of args we can typecheck today */ | |
80 | |
81 /* signed and unsigned integer types the size of a pointer: */ | |
82 #if !defined(PD_LONGINTTYPE) | |
83 #define PD_LONGINTTYPE long | |
84 #endif | |
85 | |
86 #if !defined(PD_FLOATSIZE) | |
87 /* normally, our floats (t_float, t_sample,...) are 32bit */ | |
88 # define PD_FLOATSIZE 32 | |
89 #endif | |
90 | |
91 #if PD_FLOATSIZE == 32 | |
92 # define PD_FLOATTYPE float | |
93 /* an unsigned int of the same size as FLOATTYPE: */ | |
94 # define PD_FLOATUINTTYPE unsigned int | |
95 | |
96 #elif PD_FLOATSIZE == 64 | |
97 # define PD_FLOATTYPE double | |
98 # define PD_FLOATUINTTYPE unsigned long | |
99 #else | |
100 # error invalid FLOATSIZE: must be 32 or 64 | |
101 #endif | |
102 | |
103 typedef PD_LONGINTTYPE t_int; /* pointer-size integer */ | |
104 typedef PD_FLOATTYPE t_float; /* a float type at most the same size */ | |
105 typedef PD_FLOATTYPE t_floatarg; /* float type for function calls */ | |
106 | |
107 typedef struct _symbol | |
108 { | |
109 char *s_name; | |
110 struct _class **s_thing; | |
111 struct _symbol *s_next; | |
112 } t_symbol; | |
113 | |
114 EXTERN_STRUCT _array; | |
115 #define t_array struct _array /* g_canvas.h */ | |
116 | |
117 /* pointers to glist and array elements go through a "stub" which sticks | |
118 around after the glist or array is freed. The stub itself is deleted when | |
119 both the glist/array is gone and the refcount is zero, ensuring that no | |
120 gpointers are pointing here. */ | |
121 | |
122 #define GP_NONE 0 /* the stub points nowhere (has been cut off) */ | |
123 #define GP_GLIST 1 /* the stub points to a glist element */ | |
124 #define GP_ARRAY 2 /* ... or array */ | |
125 | |
126 typedef struct _gstub | |
127 { | |
128 union | |
129 { | |
130 struct _glist *gs_glist; /* glist we're in */ | |
131 struct _array *gs_array; /* array we're in */ | |
132 } gs_un; | |
133 int gs_which; /* GP_GLIST/GP_ARRAY */ | |
134 int gs_refcount; /* number of gpointers pointing here */ | |
135 } t_gstub; | |
136 | |
137 typedef struct _gpointer /* pointer to a gobj in a glist */ | |
138 { | |
139 union | |
140 { | |
141 struct _scalar *gp_scalar; /* scalar we're in (if glist) */ | |
142 union word *gp_w; /* raw data (if array) */ | |
143 } gp_un; | |
144 int gp_valid; /* number which must match gpointee */ | |
145 t_gstub *gp_stub; /* stub which points to glist/array */ | |
146 } t_gpointer; | |
147 | |
148 typedef union word | |
149 { | |
150 t_float w_float; | |
151 t_symbol *w_symbol; | |
152 t_gpointer *w_gpointer; | |
153 t_array *w_array; | |
154 struct _binbuf *w_binbuf; | |
155 int w_index; | |
156 } t_word; | |
157 | |
158 typedef enum | |
159 { | |
160 A_NULL, | |
161 A_FLOAT, | |
162 A_SYMBOL, | |
163 A_POINTER, | |
164 A_SEMI, | |
165 A_COMMA, | |
166 A_DEFFLOAT, | |
167 A_DEFSYM, | |
168 A_DOLLAR, | |
169 A_DOLLSYM, | |
170 A_GIMME, | |
171 A_CANT | |
172 } t_atomtype; | |
173 | |
174 #define A_DEFSYMBOL A_DEFSYM /* better name for this */ | |
175 | |
176 typedef struct _atom | |
177 { | |
178 t_atomtype a_type; | |
179 union word a_w; | |
180 } t_atom; | |
181 | |
182 EXTERN_STRUCT _class; | |
183 #define t_class struct _class | |
184 | |
185 EXTERN_STRUCT _outlet; | |
186 #define t_outlet struct _outlet | |
187 | |
188 EXTERN_STRUCT _inlet; | |
189 #define t_inlet struct _inlet | |
190 | |
191 EXTERN_STRUCT _binbuf; | |
192 #define t_binbuf struct _binbuf | |
193 | |
194 EXTERN_STRUCT _clock; | |
195 #define t_clock struct _clock | |
196 | |
197 EXTERN_STRUCT _outconnect; | |
198 #define t_outconnect struct _outconnect | |
199 | |
200 EXTERN_STRUCT _glist; | |
201 #define t_glist struct _glist | |
202 #define t_canvas struct _glist /* LATER lose this */ | |
203 | |
204 typedef t_class *t_pd; /* pure datum: nothing but a class pointer */ | |
205 | |
206 typedef struct _gobj /* a graphical object */ | |
207 { | |
208 t_pd g_pd; /* pure datum header (class) */ | |
209 struct _gobj *g_next; /* next in list */ | |
210 } t_gobj; | |
211 | |
212 typedef struct _scalar /* a graphical object holding data */ | |
213 { | |
214 t_gobj sc_gobj; /* header for graphical object */ | |
215 t_symbol *sc_template; /* template name (LATER replace with pointer) */ | |
216 t_word sc_vec[1]; /* indeterminate-length array of words */ | |
217 } t_scalar; | |
218 | |
219 typedef struct _text /* patchable object - graphical, with text */ | |
220 { | |
221 t_gobj te_g; /* header for graphical object */ | |
222 t_binbuf *te_binbuf; /* holder for the text */ | |
223 t_outlet *te_outlet; /* linked list of outlets */ | |
224 t_inlet *te_inlet; /* linked list of inlets */ | |
225 short te_xpix; /* x&y location (within the toplevel) */ | |
226 short te_ypix; | |
227 short te_width; /* requested width in chars, 0 if auto */ | |
228 unsigned int te_type:2; /* from defs below */ | |
229 } t_text; | |
230 | |
231 #define T_TEXT 0 /* just a textual comment */ | |
232 #define T_OBJECT 1 /* a MAX style patchable object */ | |
233 #define T_MESSAGE 2 /* a MAX stype message */ | |
234 #define T_ATOM 3 /* a cell to display a number or symbol */ | |
235 | |
236 #define te_pd te_g.g_pd | |
237 | |
238 /* t_object is synonym for t_text (LATER unify them) */ | |
239 | |
240 typedef struct _text t_object; | |
241 | |
242 #define ob_outlet te_outlet | |
243 #define ob_inlet te_inlet | |
244 #define ob_binbuf te_binbuf | |
245 #define ob_pd te_g.g_pd | |
246 #define ob_g te_g | |
247 | |
248 typedef void (*t_method)(void); | |
249 typedef void *(*t_newmethod)( void); | |
250 | |
251 /* in ARM 64 a varargs prototype generates a different function call sequence | |
252 from a fixed one, so in that special case we make a more restrictive | |
253 definition for t_gotfn. This will break some code in the "chaos" package | |
254 in Pd extended. (that code will run incorrectly anyhow so why not catch it | |
255 at compile time anyhow.) */ | |
256 #if defined(__APPLE__) && defined(__aarch64__) | |
257 typedef void (*t_gotfn)(void *x); | |
258 #else | |
259 typedef void (*t_gotfn)(void *x, ...); | |
260 #endif | |
261 | |
262 /* ---------------- pre-defined objects and symbols --------------*/ | |
263 EXTERN t_pd pd_objectmaker; /* factory for creating "object" boxes */ | |
264 EXTERN t_pd pd_canvasmaker; /* factory for creating canvases */ | |
265 EXTERN t_symbol s_pointer; | |
266 EXTERN t_symbol s_float; | |
267 EXTERN t_symbol s_symbol; | |
268 EXTERN t_symbol s_bang; | |
269 EXTERN t_symbol s_list; | |
270 EXTERN t_symbol s_anything; | |
271 EXTERN t_symbol s_signal; | |
272 EXTERN t_symbol s__N; | |
273 EXTERN t_symbol s__X; | |
274 EXTERN t_symbol s_x; | |
275 EXTERN t_symbol s_y; | |
276 EXTERN t_symbol s_; | |
277 | |
278 /* --------- prototypes from the central message system ----------- */ | |
279 EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv); | |
280 EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv); | |
281 EXTERN t_symbol *gensym(const char *s); | |
282 EXTERN t_gotfn getfn(t_pd *x, t_symbol *s); | |
283 EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s); | |
284 EXTERN void nullfn(void); | |
285 EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...); | |
286 | |
287 /* the following macrose are for sending non-type-checkable mesages, i.e., | |
288 using function lookup but circumventing type checking on arguments. Only | |
289 use for internal messaging protected by A_CANT so that the message can't | |
290 be generated at patch level. */ | |
291 #define mess0(x, s) ((*getfn((x), (s)))((x))) | |
292 typedef void (*t_gotfn1)(void *x, void *arg1); | |
293 #define mess1(x, s, a) ((*(t_gotfn1)getfn((x), (s)))((x), (a))) | |
294 typedef void (*t_gotfn2)(void *x, void *arg1, void *arg2); | |
295 #define mess2(x, s, a,b) ((*(t_gotfn2)getfn((x), (s)))((x), (a),(b))) | |
296 typedef void (*t_gotfn3)(void *x, void *arg1, void *arg2, void *arg3); | |
297 #define mess3(x, s, a,b,c) ((*(t_gotfn3)getfn((x), (s)))((x), (a),(b),(c))) | |
298 typedef void (*t_gotfn4)(void *x, | |
299 void *arg1, void *arg2, void *arg3, void *arg4); | |
300 #define mess4(x, s, a,b,c,d) \ | |
301 ((*(t_gotfn4)getfn((x), (s)))((x), (a),(b),(c),(d))) | |
302 typedef void (*t_gotfn5)(void *x, | |
303 void *arg1, void *arg2, void *arg3, void *arg4, void *arg5); | |
304 #define mess5(x, s, a,b,c,d,e) \ | |
305 ((*(t_gotfn5)getfn((x), (s)))((x), (a),(b),(c),(d),(e))) | |
306 | |
307 EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv); | |
308 EXTERN t_pd *pd_newest(void); | |
309 | |
310 /* --------------- memory management -------------------- */ | |
311 EXTERN void *getbytes(size_t nbytes); | |
312 EXTERN void *getzbytes(size_t nbytes); | |
313 EXTERN void *copybytes(void *src, size_t nbytes); | |
314 EXTERN void freebytes(void *x, size_t nbytes); | |
315 EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize); | |
316 | |
317 /* -------------------- atoms ----------------------------- */ | |
318 | |
319 #define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0) | |
320 #define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0) | |
321 #define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \ | |
322 (atom)->a_w.w_gpointer = (gp)) | |
323 #define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f)) | |
324 #define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \ | |
325 (atom)->a_w.w_symbol = (s)) | |
326 #define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \ | |
327 (atom)->a_w.w_index = (n)) | |
328 #define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \ | |
329 (atom)->a_w.w_symbol= (s)) | |
330 | |
331 EXTERN t_float atom_getfloat(t_atom *a); | |
332 EXTERN t_int atom_getint(t_atom *a); | |
333 EXTERN t_symbol *atom_getsymbol(t_atom *a); | |
334 EXTERN t_symbol *atom_gensym(t_atom *a); | |
335 EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv); | |
336 EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv); | |
337 EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv); | |
338 | |
339 EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize); | |
340 | |
341 /* ------------------ binbufs --------------- */ | |
342 | |
343 EXTERN t_binbuf *binbuf_new(void); | |
344 EXTERN void binbuf_free(t_binbuf *x); | |
345 EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y); | |
346 | |
347 EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size); | |
348 EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp); | |
349 EXTERN void binbuf_clear(t_binbuf *x); | |
350 EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv); | |
351 EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...); | |
352 EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y); | |
353 EXTERN void binbuf_addsemi(t_binbuf *x); | |
354 EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv); | |
355 EXTERN void binbuf_print(t_binbuf *x); | |
356 EXTERN int binbuf_getnatom(t_binbuf *x); | |
357 EXTERN t_atom *binbuf_getvec(t_binbuf *x); | |
358 EXTERN int binbuf_resize(t_binbuf *x, int newsize); | |
359 EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv); | |
360 EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname, | |
361 int crflag); | |
362 EXTERN int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas, | |
363 int crflag); | |
364 EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname, | |
365 int crflag); | |
366 EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir, | |
367 int crflag); | |
368 EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir); | |
369 EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, | |
370 int tonew); | |
371 | |
372 /* ------------------ clocks --------------- */ | |
373 | |
374 EXTERN t_clock *clock_new(void *owner, t_method fn); | |
375 EXTERN void clock_set(t_clock *x, double systime); | |
376 EXTERN void clock_delay(t_clock *x, double delaytime); | |
377 EXTERN void clock_unset(t_clock *x); | |
378 EXTERN void clock_setunit(t_clock *x, double timeunit, int sampflag); | |
379 EXTERN double clock_getlogicaltime(void); | |
380 EXTERN double clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */ | |
381 EXTERN double clock_gettimesince(double prevsystime); | |
382 EXTERN double clock_gettimesincewithunits(double prevsystime, | |
383 double units, int sampflag); | |
384 EXTERN double clock_getsystimeafter(double delaytime); | |
385 EXTERN void clock_free(t_clock *x); | |
386 | |
387 /* ----------------- pure data ---------------- */ | |
388 EXTERN t_pd *pd_new(t_class *cls); | |
389 EXTERN void pd_free(t_pd *x); | |
390 EXTERN void pd_bind(t_pd *x, t_symbol *s); | |
391 EXTERN void pd_unbind(t_pd *x, t_symbol *s); | |
392 EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c); | |
393 EXTERN void pd_pushsym(t_pd *x); | |
394 EXTERN void pd_popsym(t_pd *x); | |
395 EXTERN t_symbol *pd_getfilename(void); | |
396 EXTERN t_symbol *pd_getdirname(void); | |
397 EXTERN void pd_bang(t_pd *x); | |
398 EXTERN void pd_pointer(t_pd *x, t_gpointer *gp); | |
399 EXTERN void pd_float(t_pd *x, t_float f); | |
400 EXTERN void pd_symbol(t_pd *x, t_symbol *s); | |
401 EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv); | |
402 EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv); | |
403 #define pd_class(x) (*(x)) | |
404 | |
405 /* ----------------- pointers ---------------- */ | |
406 EXTERN void gpointer_init(t_gpointer *gp); | |
407 EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto); | |
408 EXTERN void gpointer_unset(t_gpointer *gp); | |
409 EXTERN int gpointer_check(const t_gpointer *gp, int headok); | |
410 | |
411 /* ----------------- patchable "objects" -------------- */ | |
412 EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, | |
413 t_symbol *s2); | |
414 EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp); | |
415 EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp); | |
416 EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp); | |
417 EXTERN t_inlet *signalinlet_new(t_object *owner, t_float f); | |
418 EXTERN void inlet_free(t_inlet *x); | |
419 | |
420 EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s); | |
421 EXTERN void outlet_bang(t_outlet *x); | |
422 EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp); | |
423 EXTERN void outlet_float(t_outlet *x, t_float f); | |
424 EXTERN void outlet_symbol(t_outlet *x, t_symbol *s); | |
425 EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv); | |
426 EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv); | |
427 EXTERN t_symbol *outlet_getsymbol(t_outlet *x); | |
428 EXTERN void outlet_free(t_outlet *x); | |
429 EXTERN t_object *pd_checkobject(t_pd *x); | |
430 | |
431 | |
432 /* -------------------- canvases -------------- */ | |
433 | |
434 EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir); | |
435 | |
436 EXTERN void canvas_setargs(int argc, t_atom *argv); | |
437 EXTERN void canvas_getargs(int *argcp, t_atom **argvp); | |
438 EXTERN t_symbol *canvas_getcurrentdir(void); | |
439 EXTERN t_glist *canvas_getcurrent(void); | |
440 EXTERN void canvas_makefilename(t_glist *c, char *file, | |
441 char *result,int resultsize); | |
442 EXTERN t_symbol *canvas_getdir(t_glist *x); | |
443 EXTERN char sys_font[]; /* default typeface set in s_main.c */ | |
444 EXTERN char sys_fontweight[]; /* default font weight set in s_main.c */ | |
445 EXTERN int sys_fontwidth(int fontsize); | |
446 EXTERN int sys_fontheight(int fontsize); | |
447 EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b); | |
448 EXTERN int canvas_open(t_canvas *x, const char *name, const char *ext, | |
449 char *dirresult, char **nameresult, unsigned int size, int bin); | |
450 | |
451 /* ---------------- widget behaviors ---------------------- */ | |
452 | |
453 EXTERN_STRUCT _widgetbehavior; | |
454 #define t_widgetbehavior struct _widgetbehavior | |
455 | |
456 EXTERN_STRUCT _parentwidgetbehavior; | |
457 #define t_parentwidgetbehavior struct _parentwidgetbehavior | |
458 EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x); | |
459 | |
460 /* -------------------- classes -------------- */ | |
461 | |
462 #define CLASS_DEFAULT 0 /* flags for new classes below */ | |
463 #define CLASS_PD 1 | |
464 #define CLASS_GOBJ 2 | |
465 #define CLASS_PATCHABLE 3 | |
466 #define CLASS_NOINLET 8 | |
467 | |
468 #define CLASS_TYPEMASK 3 | |
469 | |
470 | |
471 EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod, | |
472 t_method freemethod, size_t size, int flags, t_atomtype arg1, ...); | |
473 EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s, | |
474 t_atomtype type1, ...); | |
475 EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel, | |
476 t_atomtype arg1, ...); | |
477 EXTERN void class_addbang(t_class *c, t_method fn); | |
478 EXTERN void class_addpointer(t_class *c, t_method fn); | |
479 EXTERN void class_doaddfloat(t_class *c, t_method fn); | |
480 EXTERN void class_addsymbol(t_class *c, t_method fn); | |
481 EXTERN void class_addlist(t_class *c, t_method fn); | |
482 EXTERN void class_addanything(t_class *c, t_method fn); | |
483 EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s); | |
484 EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w); | |
485 EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w); | |
486 EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c); | |
487 EXTERN char *class_getname(t_class *c); | |
488 EXTERN char *class_gethelpname(t_class *c); | |
489 EXTERN char *class_gethelpdir(t_class *c); | |
490 EXTERN void class_setdrawcommand(t_class *c); | |
491 EXTERN int class_isdrawcommand(t_class *c); | |
492 EXTERN void class_domainsignalin(t_class *c, int onset); | |
493 EXTERN void class_set_extern_dir(t_symbol *s); | |
494 #define CLASS_MAINSIGNALIN(c, type, field) \ | |
495 class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0) | |
496 | |
497 /* prototype for functions to save Pd's to a binbuf */ | |
498 typedef void (*t_savefn)(t_gobj *x, t_binbuf *b); | |
499 EXTERN void class_setsavefn(t_class *c, t_savefn f); | |
500 EXTERN t_savefn class_getsavefn(t_class *c); | |
501 EXTERN void obj_saveformat(t_object *x, t_binbuf *bb); /* add format to bb */ | |
502 | |
503 /* prototype for functions to open properties dialogs */ | |
504 typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist); | |
505 EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f); | |
506 EXTERN t_propertiesfn class_getpropertiesfn(t_class *c); | |
507 | |
508 #ifndef PD_CLASS_DEF | |
509 #define class_addbang(x, y) class_addbang((x), (t_method)(y)) | |
510 #define class_addpointer(x, y) class_addpointer((x), (t_method)(y)) | |
511 #define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y)) | |
512 #define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y)) | |
513 #define class_addlist(x, y) class_addlist((x), (t_method)(y)) | |
514 #define class_addanything(x, y) class_addanything((x), (t_method)(y)) | |
515 #endif | |
516 | |
517 /* ------------ printing --------------------------------- */ | |
518 EXTERN void post(const char *fmt, ...); | |
519 EXTERN void startpost(const char *fmt, ...); | |
520 EXTERN void poststring(const char *s); | |
521 EXTERN void postfloat(t_floatarg f); | |
522 EXTERN void postatom(int argc, t_atom *argv); | |
523 EXTERN void endpost(void); | |
524 EXTERN void error(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2); | |
525 EXTERN void verbose(int level, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3); | |
526 EXTERN void bug(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2); | |
527 EXTERN void pd_error(void *object, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3); | |
528 EXTERN void logpost(const void *object, const int level, const char *fmt, ...) | |
529 ATTRIBUTE_FORMAT_PRINTF(3, 4); | |
530 EXTERN void sys_logerror(const char *object, const char *s); | |
531 EXTERN void sys_unixerror(const char *object); | |
532 EXTERN void sys_ouch(void); | |
533 | |
534 | |
535 /* ------------ system interface routines ------------------- */ | |
536 EXTERN int sys_isreadablefile(const char *name); | |
537 EXTERN int sys_isabsolutepath(const char *dir); | |
538 EXTERN void sys_bashfilename(const char *from, char *to); | |
539 EXTERN void sys_unbashfilename(const char *from, char *to); | |
540 EXTERN int open_via_path(const char *dir, const char *name, const char *ext, | |
541 char *dirresult, char **nameresult, unsigned int size, int bin); | |
542 EXTERN int sched_geteventno(void); | |
543 EXTERN double sys_getrealtime(void); | |
544 EXTERN int (*sys_idlehook)(void); /* hook to add idle time computation */ | |
545 | |
546 /* Win32's open()/fopen() do not handle UTF-8 filenames so we need | |
547 * these internal versions that handle UTF-8 filenames the same across | |
548 * all platforms. They are recommended for use in external | |
549 * objectclasses as well so they work with Unicode filenames on Windows */ | |
550 EXTERN int sys_open(const char *path, int oflag, ...); | |
551 EXTERN int sys_close(int fd); | |
552 EXTERN FILE *sys_fopen(const char *filename, const char *mode); | |
553 EXTERN int sys_fclose(FILE *stream); | |
554 | |
555 /* ------------ threading ------------------- */ | |
556 EXTERN void sys_lock(void); | |
557 EXTERN void sys_unlock(void); | |
558 EXTERN int sys_trylock(void); | |
559 | |
560 | |
561 /* --------------- signals ----------------------------------- */ | |
562 | |
563 typedef PD_FLOATTYPE t_sample; | |
564 typedef union _sampleint_union { | |
565 t_sample f; | |
566 PD_FLOATUINTTYPE i; | |
567 } t_sampleint_union; | |
568 #define MAXLOGSIG 32 | |
569 #define MAXSIGSIZE (1 << MAXLOGSIG) | |
570 | |
571 typedef struct _signal | |
572 { | |
573 int s_n; /* number of points in the array */ | |
574 t_sample *s_vec; /* the array */ | |
575 t_float s_sr; /* sample rate */ | |
576 int s_refcount; /* number of times used */ | |
577 int s_isborrowed; /* whether we're going to borrow our array */ | |
578 struct _signal *s_borrowedfrom; /* signal to borrow it from */ | |
579 struct _signal *s_nextfree; /* next in freelist */ | |
580 struct _signal *s_nextused; /* next in used list */ | |
581 int s_vecsize; /* allocated size of array in points */ | |
582 } t_signal; | |
583 | |
584 typedef t_int *(*t_perfroutine)(t_int *args); | |
585 | |
586 EXTERN t_int *plus_perform(t_int *args); | |
587 EXTERN t_int *zero_perform(t_int *args); | |
588 EXTERN t_int *copy_perform(t_int *args); | |
589 | |
590 EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n); | |
591 EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n); | |
592 EXTERN void dsp_add_scalarcopy(t_float *in, t_sample *out, int n); | |
593 EXTERN void dsp_add_zero(t_sample *out, int n); | |
594 | |
595 EXTERN int sys_getblksize(void); | |
596 EXTERN t_float sys_getsr(void); | |
597 EXTERN int sys_get_inchannels(void); | |
598 EXTERN int sys_get_outchannels(void); | |
599 | |
600 EXTERN void dsp_add(t_perfroutine f, int n, ...); | |
601 EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec); | |
602 EXTERN void pd_fft(t_float *buf, int npoints, int inverse); | |
603 EXTERN int ilog2(int n); | |
604 | |
605 EXTERN void mayer_fht(t_sample *fz, int n); | |
606 EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag); | |
607 EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag); | |
608 EXTERN void mayer_realfft(int n, t_sample *real); | |
609 EXTERN void mayer_realifft(int n, t_sample *real); | |
610 | |
611 EXTERN float *cos_table; | |
612 #define LOGCOSTABSIZE 9 | |
613 #define COSTABSIZE (1<<LOGCOSTABSIZE) | |
614 | |
615 EXTERN int canvas_suspend_dsp(void); | |
616 EXTERN void canvas_resume_dsp(int oldstate); | |
617 EXTERN void canvas_update_dsp(void); | |
618 EXTERN int canvas_dspstate; | |
619 | |
620 /* up/downsampling */ | |
621 typedef struct _resample | |
622 { | |
623 int method; /* up/downsampling method ID */ | |
624 | |
625 int downsample; /* downsampling factor */ | |
626 int upsample; /* upsampling factor */ | |
627 | |
628 t_sample *s_vec; /* here we hold the resampled data */ | |
629 int s_n; | |
630 | |
631 t_sample *coeffs; /* coefficients for filtering... */ | |
632 int coefsize; | |
633 | |
634 t_sample *buffer; /* buffer for filtering */ | |
635 int bufsize; | |
636 } t_resample; | |
637 | |
638 EXTERN void resample_init(t_resample *x); | |
639 EXTERN void resample_free(t_resample *x); | |
640 | |
641 EXTERN void resample_dsp(t_resample *x, t_sample *in, int insize, t_sample *out, int outsize, int method); | |
642 EXTERN void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method); | |
643 EXTERN void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method); | |
644 | |
645 /* ----------------------- utility functions for signals -------------- */ | |
646 EXTERN t_float mtof(t_float); | |
647 EXTERN t_float ftom(t_float); | |
648 EXTERN t_float rmstodb(t_float); | |
649 EXTERN t_float powtodb(t_float); | |
650 EXTERN t_float dbtorms(t_float); | |
651 EXTERN t_float dbtopow(t_float); | |
652 | |
653 EXTERN t_float q8_sqrt(t_float); | |
654 EXTERN t_float q8_rsqrt(t_float); | |
655 #ifndef N32 | |
656 EXTERN t_float qsqrt(t_float); /* old names kept for extern compatibility */ | |
657 EXTERN t_float qrsqrt(t_float); | |
658 #endif | |
659 /* --------------------- data --------------------------------- */ | |
660 | |
661 /* graphical arrays */ | |
662 EXTERN_STRUCT _garray; | |
663 #define t_garray struct _garray | |
664 | |
665 EXTERN t_class *garray_class; | |
666 EXTERN int garray_getfloatarray(t_garray *x, int *size, t_float **vec); | |
667 EXTERN int garray_getfloatwords(t_garray *x, int *size, t_word **vec); | |
668 EXTERN void garray_redraw(t_garray *x); | |
669 EXTERN int garray_npoints(t_garray *x); | |
670 EXTERN char *garray_vec(t_garray *x); | |
671 EXTERN void garray_resize(t_garray *x, t_floatarg f); /* avoid; use this: */ | |
672 EXTERN void garray_resize_long(t_garray *x, long n); /* better version */ | |
673 EXTERN void garray_usedindsp(t_garray *x); | |
674 EXTERN void garray_setsaveit(t_garray *x, int saveit); | |
675 EXTERN t_glist *garray_getglist(t_garray *x); | |
676 EXTERN t_array *garray_getarray(t_garray *x); | |
677 EXTERN t_class *scalar_class; | |
678 | |
679 EXTERN t_float *value_get(t_symbol *s); | |
680 EXTERN void value_release(t_symbol *s); | |
681 EXTERN int value_getfloat(t_symbol *s, t_float *f); | |
682 EXTERN int value_setfloat(t_symbol *s, t_float f); | |
683 | |
684 /* ------- GUI interface - functions to send strings to TK --------- */ | |
685 typedef void (*t_guicallbackfn)(t_gobj *client, t_glist *glist); | |
686 | |
687 EXTERN void sys_vgui(char *fmt, ...); | |
688 EXTERN void sys_gui(char *s); | |
689 EXTERN void sys_pretendguibytes(int n); | |
690 EXTERN void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f); | |
691 EXTERN void sys_unqueuegui(void *client); | |
692 /* dialog window creation and destruction */ | |
693 EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd); | |
694 EXTERN void gfxstub_deleteforkey(void *key); | |
695 | |
696 extern t_class *glob_pdobject; /* object to send "pd" messages */ | |
697 | |
698 /*------------- Max 0.26 compatibility --------------------*/ | |
699 | |
700 /* the following reflects the new way classes are laid out, with the class | |
701 pointing to the messlist and not vice versa. Externs shouldn't feel it. */ | |
702 typedef t_class *t_externclass; | |
703 | |
704 EXTERN void c_extern(t_externclass *cls, t_newmethod newroutine, | |
705 t_method freeroutine, t_symbol *name, size_t size, int tiny, \ | |
706 t_atomtype arg1, ...); | |
707 EXTERN void c_addmess(t_method fn, t_symbol *sel, t_atomtype arg1, ...); | |
708 | |
709 #define t_getbytes getbytes | |
710 #define t_freebytes freebytes | |
711 #define t_resizebytes resizebytes | |
712 #define typedmess pd_typedmess | |
713 #define vmess pd_vmess | |
714 | |
715 /* A definition to help gui objects straddle 0.34-0.35 changes. If this is | |
716 defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */ | |
717 | |
718 #define PD_USE_TE_XPIX | |
719 | |
720 #ifndef _MSC_VER /* Microoft compiler can't handle "inline" function/macros */ | |
721 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) | |
722 /* a test for NANs and denormals. Should only be necessary on i386. */ | |
723 # if PD_FLOATSIZE == 32 | |
724 static inline int PD_BADFLOAT(t_sample f) { | |
725 t_sampleint_union u; | |
726 u.f=f; | |
727 return ((u.i & 0x7f800000)==0) || ((u.i&0x7f800000)==0x7f800000); | |
728 } | |
729 /* more stringent test: anything not between 1e-19 and 1e19 in absolute val */ | |
730 static inline int PD_BIGORSMALL(t_sample f) { | |
731 t_sampleint_union u; | |
732 u.f=f; | |
733 return ((u.i & 0x60000000)==0) || ((u.i & 0x60000000)==0x60000000); | |
734 } | |
735 # else | |
736 # warning 64bit mode: BIGORSMALL not implemented yet | |
737 # define PD_BADFLOAT(f) 0 | |
738 # define PD_BIGORSMALL(f) 0 | |
739 # endif | |
740 #else | |
741 # define PD_BADFLOAT(f) 0 | |
742 # define PD_BIGORSMALL(f) 0 | |
743 #endif | |
744 #else /* _MSC_VER */ | |
745 #define PD_BADFLOAT(f) ((((*(unsigned int*)&(f))&0x7f800000)==0) || \ | |
746 (((*(unsigned int*)&(f))&0x7f800000)==0x7f800000)) | |
747 /* more stringent test: anything not between 1e-19 and 1e19 in absolute val */ | |
748 #define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \ | |
749 (((*(unsigned int*)&(f))&0x60000000)==0x60000000)) | |
750 #endif /* _MSC_VER */ | |
751 /* get version number at run time */ | |
752 EXTERN void sys_getversion(int *major, int *minor, int *bugfix); | |
753 | |
754 EXTERN_STRUCT _pdinstance; | |
755 #define t_pdinstance struct _pdinstance /* m_imp.h */ | |
756 | |
757 /* m_pd.c */ | |
758 | |
759 EXTERN t_pdinstance *pdinstance_new( void); | |
760 EXTERN void pd_setinstance(t_pdinstance *x); | |
761 EXTERN void pdinstance_free(t_pdinstance *x); | |
762 EXTERN t_canvas *pd_getcanvaslist(void); | |
763 EXTERN int pd_getdspstate(void); | |
764 | |
765 #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) | |
766 } | |
767 #endif | |
768 | |
769 #define __m_pd_h_ | |
770 #endif /* __m_pd_h_ */ |