annotate examples/08-PureData/basic_libpd/m_pd.h @ 464:8fcfbfb32aa0 prerelease

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