giuliomoro@230: /* Copyright (c) 1997-1999 Miller Puckette. giuliomoro@230: * For information on usage and redistribution, and for a DISCLAIMER OF ALL giuliomoro@230: * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ giuliomoro@230: giuliomoro@230: #ifndef __m_pd_h_ giuliomoro@230: giuliomoro@230: #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) giuliomoro@230: extern "C" { giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: #define PD_MAJOR_VERSION 0 giuliomoro@230: #define PD_MINOR_VERSION 46 giuliomoro@230: #define PD_BUGFIX_VERSION 6 giuliomoro@230: #define PD_TEST_VERSION "" giuliomoro@230: extern int pd_compatibilitylevel; /* e.g., 43 for pd 0.43 compatibility */ giuliomoro@230: giuliomoro@230: /* old name for "MSW" flag -- we have to take it for the sake of many old giuliomoro@230: "nmakefiles" for externs, which will define NT and not MSW */ giuliomoro@230: #if defined(NT) && !defined(MSW) giuliomoro@230: #define MSW giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* These pragmas are only used for MSVC, not MinGW or Cygwin */ giuliomoro@230: #ifdef _MSC_VER giuliomoro@230: /* #pragma warning( disable : 4091 ) */ giuliomoro@230: #pragma warning( disable : 4305 ) /* uncast const double to float */ giuliomoro@230: #pragma warning( disable : 4244 ) /* uncast float/int conversion etc. */ giuliomoro@230: #pragma warning( disable : 4101 ) /* unused automatic variables */ giuliomoro@230: #endif /* _MSC_VER */ giuliomoro@230: giuliomoro@230: /* the external storage class is "extern" in UNIX; in MSW it's ugly. */ giuliomoro@230: #ifdef _WIN32 giuliomoro@230: #ifdef PD_INTERNAL giuliomoro@230: #define EXTERN __declspec(dllexport) extern giuliomoro@230: #else giuliomoro@230: #define EXTERN __declspec(dllimport) extern giuliomoro@230: #endif /* PD_INTERNAL */ giuliomoro@230: #else giuliomoro@230: #define EXTERN extern giuliomoro@230: #endif /* _WIN32 */ giuliomoro@230: giuliomoro@230: /* and depending on the compiler, hidden data structures are giuliomoro@230: declared differently: */ giuliomoro@230: #if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ ) giuliomoro@230: #define EXTERN_STRUCT struct giuliomoro@230: #else giuliomoro@230: #define EXTERN_STRUCT extern struct giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* Define some attributes, specific to the compiler */ giuliomoro@230: #if defined(__GNUC__) giuliomoro@230: #define ATTRIBUTE_FORMAT_PRINTF(a, b) __attribute__ ((format (printf, a, b))) giuliomoro@230: #else giuliomoro@230: #define ATTRIBUTE_FORMAT_PRINTF(a, b) giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: #if !defined(_SIZE_T) && !defined(_SIZE_T_) giuliomoro@230: #include /* just for size_t -- how lame! */ giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* Microsoft Visual Studio is not C99, it does not provide stdint.h */ giuliomoro@230: #ifdef _MSC_VER giuliomoro@230: typedef signed __int8 int8_t; giuliomoro@230: typedef signed __int16 int16_t; giuliomoro@230: typedef signed __int32 int32_t; giuliomoro@230: typedef signed __int64 int64_t; giuliomoro@230: typedef unsigned __int8 uint8_t; giuliomoro@230: typedef unsigned __int16 uint16_t; giuliomoro@230: typedef unsigned __int32 uint32_t; giuliomoro@230: typedef unsigned __int64 uint64_t; giuliomoro@230: #else giuliomoro@230: # include giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* for FILE, needed by sys_fopen() and sys_fclose() only */ giuliomoro@230: #include giuliomoro@230: giuliomoro@230: #define MAXPDSTRING 1000 /* use this for anything you want */ giuliomoro@230: #define MAXPDARG 5 /* max number of args we can typecheck today */ giuliomoro@230: giuliomoro@230: /* signed and unsigned integer types the size of a pointer: */ giuliomoro@230: #if !defined(PD_LONGINTTYPE) giuliomoro@230: #define PD_LONGINTTYPE long giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: #if !defined(PD_FLOATSIZE) giuliomoro@230: /* normally, our floats (t_float, t_sample,...) are 32bit */ giuliomoro@230: # define PD_FLOATSIZE 32 giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: #if PD_FLOATSIZE == 32 giuliomoro@230: # define PD_FLOATTYPE float giuliomoro@230: /* an unsigned int of the same size as FLOATTYPE: */ giuliomoro@230: # define PD_FLOATUINTTYPE unsigned int giuliomoro@230: giuliomoro@230: #elif PD_FLOATSIZE == 64 giuliomoro@230: # define PD_FLOATTYPE double giuliomoro@230: # define PD_FLOATUINTTYPE unsigned long giuliomoro@230: #else giuliomoro@230: # error invalid FLOATSIZE: must be 32 or 64 giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: typedef PD_LONGINTTYPE t_int; /* pointer-size integer */ giuliomoro@230: typedef PD_FLOATTYPE t_float; /* a float type at most the same size */ giuliomoro@230: typedef PD_FLOATTYPE t_floatarg; /* float type for function calls */ giuliomoro@230: giuliomoro@230: typedef struct _symbol giuliomoro@230: { giuliomoro@230: char *s_name; giuliomoro@230: struct _class **s_thing; giuliomoro@230: struct _symbol *s_next; giuliomoro@230: } t_symbol; giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _array; giuliomoro@230: #define t_array struct _array /* g_canvas.h */ giuliomoro@230: giuliomoro@230: /* pointers to glist and array elements go through a "stub" which sticks giuliomoro@230: around after the glist or array is freed. The stub itself is deleted when giuliomoro@230: both the glist/array is gone and the refcount is zero, ensuring that no giuliomoro@230: gpointers are pointing here. */ giuliomoro@230: giuliomoro@230: #define GP_NONE 0 /* the stub points nowhere (has been cut off) */ giuliomoro@230: #define GP_GLIST 1 /* the stub points to a glist element */ giuliomoro@230: #define GP_ARRAY 2 /* ... or array */ giuliomoro@230: giuliomoro@230: typedef struct _gstub giuliomoro@230: { giuliomoro@230: union giuliomoro@230: { giuliomoro@230: struct _glist *gs_glist; /* glist we're in */ giuliomoro@230: struct _array *gs_array; /* array we're in */ giuliomoro@230: } gs_un; giuliomoro@230: int gs_which; /* GP_GLIST/GP_ARRAY */ giuliomoro@230: int gs_refcount; /* number of gpointers pointing here */ giuliomoro@230: } t_gstub; giuliomoro@230: giuliomoro@230: typedef struct _gpointer /* pointer to a gobj in a glist */ giuliomoro@230: { giuliomoro@230: union giuliomoro@230: { giuliomoro@230: struct _scalar *gp_scalar; /* scalar we're in (if glist) */ giuliomoro@230: union word *gp_w; /* raw data (if array) */ giuliomoro@230: } gp_un; giuliomoro@230: int gp_valid; /* number which must match gpointee */ giuliomoro@230: t_gstub *gp_stub; /* stub which points to glist/array */ giuliomoro@230: } t_gpointer; giuliomoro@230: giuliomoro@230: typedef union word giuliomoro@230: { giuliomoro@230: t_float w_float; giuliomoro@230: t_symbol *w_symbol; giuliomoro@230: t_gpointer *w_gpointer; giuliomoro@230: t_array *w_array; giuliomoro@230: struct _binbuf *w_binbuf; giuliomoro@230: int w_index; giuliomoro@230: } t_word; giuliomoro@230: giuliomoro@230: typedef enum giuliomoro@230: { giuliomoro@230: A_NULL, giuliomoro@230: A_FLOAT, giuliomoro@230: A_SYMBOL, giuliomoro@230: A_POINTER, giuliomoro@230: A_SEMI, giuliomoro@230: A_COMMA, giuliomoro@230: A_DEFFLOAT, giuliomoro@230: A_DEFSYM, giuliomoro@230: A_DOLLAR, giuliomoro@230: A_DOLLSYM, giuliomoro@230: A_GIMME, giuliomoro@230: A_CANT giuliomoro@230: } t_atomtype; giuliomoro@230: giuliomoro@230: #define A_DEFSYMBOL A_DEFSYM /* better name for this */ giuliomoro@230: giuliomoro@230: typedef struct _atom giuliomoro@230: { giuliomoro@230: t_atomtype a_type; giuliomoro@230: union word a_w; giuliomoro@230: } t_atom; giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _class; giuliomoro@230: #define t_class struct _class giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _outlet; giuliomoro@230: #define t_outlet struct _outlet giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _inlet; giuliomoro@230: #define t_inlet struct _inlet giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _binbuf; giuliomoro@230: #define t_binbuf struct _binbuf giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _clock; giuliomoro@230: #define t_clock struct _clock giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _outconnect; giuliomoro@230: #define t_outconnect struct _outconnect giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _glist; giuliomoro@230: #define t_glist struct _glist giuliomoro@230: #define t_canvas struct _glist /* LATER lose this */ giuliomoro@230: giuliomoro@230: typedef t_class *t_pd; /* pure datum: nothing but a class pointer */ giuliomoro@230: giuliomoro@230: typedef struct _gobj /* a graphical object */ giuliomoro@230: { giuliomoro@230: t_pd g_pd; /* pure datum header (class) */ giuliomoro@230: struct _gobj *g_next; /* next in list */ giuliomoro@230: } t_gobj; giuliomoro@230: giuliomoro@230: typedef struct _scalar /* a graphical object holding data */ giuliomoro@230: { giuliomoro@230: t_gobj sc_gobj; /* header for graphical object */ giuliomoro@230: t_symbol *sc_template; /* template name (LATER replace with pointer) */ giuliomoro@230: t_word sc_vec[1]; /* indeterminate-length array of words */ giuliomoro@230: } t_scalar; giuliomoro@230: giuliomoro@230: typedef struct _text /* patchable object - graphical, with text */ giuliomoro@230: { giuliomoro@230: t_gobj te_g; /* header for graphical object */ giuliomoro@230: t_binbuf *te_binbuf; /* holder for the text */ giuliomoro@230: t_outlet *te_outlet; /* linked list of outlets */ giuliomoro@230: t_inlet *te_inlet; /* linked list of inlets */ giuliomoro@230: short te_xpix; /* x&y location (within the toplevel) */ giuliomoro@230: short te_ypix; giuliomoro@230: short te_width; /* requested width in chars, 0 if auto */ giuliomoro@230: unsigned int te_type:2; /* from defs below */ giuliomoro@230: } t_text; giuliomoro@230: giuliomoro@230: #define T_TEXT 0 /* just a textual comment */ giuliomoro@230: #define T_OBJECT 1 /* a MAX style patchable object */ giuliomoro@230: #define T_MESSAGE 2 /* a MAX stype message */ giuliomoro@230: #define T_ATOM 3 /* a cell to display a number or symbol */ giuliomoro@230: giuliomoro@230: #define te_pd te_g.g_pd giuliomoro@230: giuliomoro@230: /* t_object is synonym for t_text (LATER unify them) */ giuliomoro@230: giuliomoro@230: typedef struct _text t_object; giuliomoro@230: giuliomoro@230: #define ob_outlet te_outlet giuliomoro@230: #define ob_inlet te_inlet giuliomoro@230: #define ob_binbuf te_binbuf giuliomoro@230: #define ob_pd te_g.g_pd giuliomoro@230: #define ob_g te_g giuliomoro@230: giuliomoro@230: typedef void (*t_method)(void); giuliomoro@230: typedef void *(*t_newmethod)( void); giuliomoro@230: giuliomoro@230: /* in ARM 64 a varargs prototype generates a different function call sequence giuliomoro@230: from a fixed one, so in that special case we make a more restrictive giuliomoro@230: definition for t_gotfn. This will break some code in the "chaos" package giuliomoro@230: in Pd extended. (that code will run incorrectly anyhow so why not catch it giuliomoro@230: at compile time anyhow.) */ giuliomoro@230: #if defined(__APPLE__) && defined(__aarch64__) giuliomoro@230: typedef void (*t_gotfn)(void *x); giuliomoro@230: #else giuliomoro@230: typedef void (*t_gotfn)(void *x, ...); giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* ---------------- pre-defined objects and symbols --------------*/ giuliomoro@230: EXTERN t_pd pd_objectmaker; /* factory for creating "object" boxes */ giuliomoro@230: EXTERN t_pd pd_canvasmaker; /* factory for creating canvases */ giuliomoro@230: EXTERN t_symbol s_pointer; giuliomoro@230: EXTERN t_symbol s_float; giuliomoro@230: EXTERN t_symbol s_symbol; giuliomoro@230: EXTERN t_symbol s_bang; giuliomoro@230: EXTERN t_symbol s_list; giuliomoro@230: EXTERN t_symbol s_anything; giuliomoro@230: EXTERN t_symbol s_signal; giuliomoro@230: EXTERN t_symbol s__N; giuliomoro@230: EXTERN t_symbol s__X; giuliomoro@230: EXTERN t_symbol s_x; giuliomoro@230: EXTERN t_symbol s_y; giuliomoro@230: EXTERN t_symbol s_; giuliomoro@230: giuliomoro@230: /* --------- prototypes from the central message system ----------- */ giuliomoro@230: EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv); giuliomoro@230: EXTERN t_symbol *gensym(const char *s); giuliomoro@230: EXTERN t_gotfn getfn(t_pd *x, t_symbol *s); giuliomoro@230: EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s); giuliomoro@230: EXTERN void nullfn(void); giuliomoro@230: EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...); giuliomoro@230: giuliomoro@230: /* the following macrose are for sending non-type-checkable mesages, i.e., giuliomoro@230: using function lookup but circumventing type checking on arguments. Only giuliomoro@230: use for internal messaging protected by A_CANT so that the message can't giuliomoro@230: be generated at patch level. */ giuliomoro@230: #define mess0(x, s) ((*getfn((x), (s)))((x))) giuliomoro@230: typedef void (*t_gotfn1)(void *x, void *arg1); giuliomoro@230: #define mess1(x, s, a) ((*(t_gotfn1)getfn((x), (s)))((x), (a))) giuliomoro@230: typedef void (*t_gotfn2)(void *x, void *arg1, void *arg2); giuliomoro@230: #define mess2(x, s, a,b) ((*(t_gotfn2)getfn((x), (s)))((x), (a),(b))) giuliomoro@230: typedef void (*t_gotfn3)(void *x, void *arg1, void *arg2, void *arg3); giuliomoro@230: #define mess3(x, s, a,b,c) ((*(t_gotfn3)getfn((x), (s)))((x), (a),(b),(c))) giuliomoro@230: typedef void (*t_gotfn4)(void *x, giuliomoro@230: void *arg1, void *arg2, void *arg3, void *arg4); giuliomoro@230: #define mess4(x, s, a,b,c,d) \ giuliomoro@230: ((*(t_gotfn4)getfn((x), (s)))((x), (a),(b),(c),(d))) giuliomoro@230: typedef void (*t_gotfn5)(void *x, giuliomoro@230: void *arg1, void *arg2, void *arg3, void *arg4, void *arg5); giuliomoro@230: #define mess5(x, s, a,b,c,d,e) \ giuliomoro@230: ((*(t_gotfn5)getfn((x), (s)))((x), (a),(b),(c),(d),(e))) giuliomoro@230: giuliomoro@230: EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: EXTERN t_pd *pd_newest(void); giuliomoro@230: giuliomoro@230: /* --------------- memory management -------------------- */ giuliomoro@230: EXTERN void *getbytes(size_t nbytes); giuliomoro@230: EXTERN void *getzbytes(size_t nbytes); giuliomoro@230: EXTERN void *copybytes(void *src, size_t nbytes); giuliomoro@230: EXTERN void freebytes(void *x, size_t nbytes); giuliomoro@230: EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize); giuliomoro@230: giuliomoro@230: /* -------------------- atoms ----------------------------- */ giuliomoro@230: giuliomoro@230: #define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0) giuliomoro@230: #define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0) giuliomoro@230: #define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \ giuliomoro@230: (atom)->a_w.w_gpointer = (gp)) giuliomoro@230: #define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f)) giuliomoro@230: #define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \ giuliomoro@230: (atom)->a_w.w_symbol = (s)) giuliomoro@230: #define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \ giuliomoro@230: (atom)->a_w.w_index = (n)) giuliomoro@230: #define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \ giuliomoro@230: (atom)->a_w.w_symbol= (s)) giuliomoro@230: giuliomoro@230: EXTERN t_float atom_getfloat(t_atom *a); giuliomoro@230: EXTERN t_int atom_getint(t_atom *a); giuliomoro@230: EXTERN t_symbol *atom_getsymbol(t_atom *a); giuliomoro@230: EXTERN t_symbol *atom_gensym(t_atom *a); giuliomoro@230: EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv); giuliomoro@230: EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv); giuliomoro@230: EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv); giuliomoro@230: giuliomoro@230: EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize); giuliomoro@230: giuliomoro@230: /* ------------------ binbufs --------------- */ giuliomoro@230: giuliomoro@230: EXTERN t_binbuf *binbuf_new(void); giuliomoro@230: EXTERN void binbuf_free(t_binbuf *x); giuliomoro@230: EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y); giuliomoro@230: giuliomoro@230: EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size); giuliomoro@230: EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp); giuliomoro@230: EXTERN void binbuf_clear(t_binbuf *x); giuliomoro@230: EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv); giuliomoro@230: EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...); giuliomoro@230: EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y); giuliomoro@230: EXTERN void binbuf_addsemi(t_binbuf *x); giuliomoro@230: EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv); giuliomoro@230: EXTERN void binbuf_print(t_binbuf *x); giuliomoro@230: EXTERN int binbuf_getnatom(t_binbuf *x); giuliomoro@230: EXTERN t_atom *binbuf_getvec(t_binbuf *x); giuliomoro@230: EXTERN int binbuf_resize(t_binbuf *x, int newsize); giuliomoro@230: EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv); giuliomoro@230: EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname, giuliomoro@230: int crflag); giuliomoro@230: EXTERN int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas, giuliomoro@230: int crflag); giuliomoro@230: EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname, giuliomoro@230: int crflag); giuliomoro@230: EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir, giuliomoro@230: int crflag); giuliomoro@230: EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir); giuliomoro@230: EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, giuliomoro@230: int tonew); giuliomoro@230: giuliomoro@230: /* ------------------ clocks --------------- */ giuliomoro@230: giuliomoro@230: EXTERN t_clock *clock_new(void *owner, t_method fn); giuliomoro@230: EXTERN void clock_set(t_clock *x, double systime); giuliomoro@230: EXTERN void clock_delay(t_clock *x, double delaytime); giuliomoro@230: EXTERN void clock_unset(t_clock *x); giuliomoro@230: EXTERN void clock_setunit(t_clock *x, double timeunit, int sampflag); giuliomoro@230: EXTERN double clock_getlogicaltime(void); giuliomoro@230: EXTERN double clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */ giuliomoro@230: EXTERN double clock_gettimesince(double prevsystime); giuliomoro@230: EXTERN double clock_gettimesincewithunits(double prevsystime, giuliomoro@230: double units, int sampflag); giuliomoro@230: EXTERN double clock_getsystimeafter(double delaytime); giuliomoro@230: EXTERN void clock_free(t_clock *x); giuliomoro@230: giuliomoro@230: /* ----------------- pure data ---------------- */ giuliomoro@230: EXTERN t_pd *pd_new(t_class *cls); giuliomoro@230: EXTERN void pd_free(t_pd *x); giuliomoro@230: EXTERN void pd_bind(t_pd *x, t_symbol *s); giuliomoro@230: EXTERN void pd_unbind(t_pd *x, t_symbol *s); giuliomoro@230: EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c); giuliomoro@230: EXTERN void pd_pushsym(t_pd *x); giuliomoro@230: EXTERN void pd_popsym(t_pd *x); giuliomoro@230: EXTERN t_symbol *pd_getfilename(void); giuliomoro@230: EXTERN t_symbol *pd_getdirname(void); giuliomoro@230: EXTERN void pd_bang(t_pd *x); giuliomoro@230: EXTERN void pd_pointer(t_pd *x, t_gpointer *gp); giuliomoro@230: EXTERN void pd_float(t_pd *x, t_float f); giuliomoro@230: EXTERN void pd_symbol(t_pd *x, t_symbol *s); giuliomoro@230: EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: #define pd_class(x) (*(x)) giuliomoro@230: giuliomoro@230: /* ----------------- pointers ---------------- */ giuliomoro@230: EXTERN void gpointer_init(t_gpointer *gp); giuliomoro@230: EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto); giuliomoro@230: EXTERN void gpointer_unset(t_gpointer *gp); giuliomoro@230: EXTERN int gpointer_check(const t_gpointer *gp, int headok); giuliomoro@230: giuliomoro@230: /* ----------------- patchable "objects" -------------- */ giuliomoro@230: EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, giuliomoro@230: t_symbol *s2); giuliomoro@230: EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp); giuliomoro@230: EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp); giuliomoro@230: EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp); giuliomoro@230: EXTERN t_inlet *signalinlet_new(t_object *owner, t_float f); giuliomoro@230: EXTERN void inlet_free(t_inlet *x); giuliomoro@230: giuliomoro@230: EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s); giuliomoro@230: EXTERN void outlet_bang(t_outlet *x); giuliomoro@230: EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp); giuliomoro@230: EXTERN void outlet_float(t_outlet *x, t_float f); giuliomoro@230: EXTERN void outlet_symbol(t_outlet *x, t_symbol *s); giuliomoro@230: EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv); giuliomoro@230: EXTERN t_symbol *outlet_getsymbol(t_outlet *x); giuliomoro@230: EXTERN void outlet_free(t_outlet *x); giuliomoro@230: EXTERN t_object *pd_checkobject(t_pd *x); giuliomoro@230: giuliomoro@230: giuliomoro@230: /* -------------------- canvases -------------- */ giuliomoro@230: giuliomoro@230: EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir); giuliomoro@230: giuliomoro@230: EXTERN void canvas_setargs(int argc, t_atom *argv); giuliomoro@230: EXTERN void canvas_getargs(int *argcp, t_atom **argvp); giuliomoro@230: EXTERN t_symbol *canvas_getcurrentdir(void); giuliomoro@230: EXTERN t_glist *canvas_getcurrent(void); giuliomoro@230: EXTERN void canvas_makefilename(t_glist *c, char *file, giuliomoro@230: char *result,int resultsize); giuliomoro@230: EXTERN t_symbol *canvas_getdir(t_glist *x); giuliomoro@230: EXTERN char sys_font[]; /* default typeface set in s_main.c */ giuliomoro@230: EXTERN char sys_fontweight[]; /* default font weight set in s_main.c */ giuliomoro@230: EXTERN int sys_fontwidth(int fontsize); giuliomoro@230: EXTERN int sys_fontheight(int fontsize); giuliomoro@230: EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b); giuliomoro@230: EXTERN int canvas_open(t_canvas *x, const char *name, const char *ext, giuliomoro@230: char *dirresult, char **nameresult, unsigned int size, int bin); giuliomoro@230: giuliomoro@230: /* ---------------- widget behaviors ---------------------- */ giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _widgetbehavior; giuliomoro@230: #define t_widgetbehavior struct _widgetbehavior giuliomoro@230: giuliomoro@230: EXTERN_STRUCT _parentwidgetbehavior; giuliomoro@230: #define t_parentwidgetbehavior struct _parentwidgetbehavior giuliomoro@230: EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x); giuliomoro@230: giuliomoro@230: /* -------------------- classes -------------- */ giuliomoro@230: giuliomoro@230: #define CLASS_DEFAULT 0 /* flags for new classes below */ giuliomoro@230: #define CLASS_PD 1 giuliomoro@230: #define CLASS_GOBJ 2 giuliomoro@230: #define CLASS_PATCHABLE 3 giuliomoro@230: #define CLASS_NOINLET 8 giuliomoro@230: giuliomoro@230: #define CLASS_TYPEMASK 3 giuliomoro@230: giuliomoro@230: giuliomoro@230: EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod, giuliomoro@230: t_method freemethod, size_t size, int flags, t_atomtype arg1, ...); giuliomoro@230: EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s, giuliomoro@230: t_atomtype type1, ...); giuliomoro@230: EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel, giuliomoro@230: t_atomtype arg1, ...); giuliomoro@230: EXTERN void class_addbang(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_addpointer(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_doaddfloat(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_addsymbol(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_addlist(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_addanything(t_class *c, t_method fn); giuliomoro@230: EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s); giuliomoro@230: EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w); giuliomoro@230: EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w); giuliomoro@230: EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c); giuliomoro@230: EXTERN char *class_getname(t_class *c); giuliomoro@230: EXTERN char *class_gethelpname(t_class *c); giuliomoro@230: EXTERN char *class_gethelpdir(t_class *c); giuliomoro@230: EXTERN void class_setdrawcommand(t_class *c); giuliomoro@230: EXTERN int class_isdrawcommand(t_class *c); giuliomoro@230: EXTERN void class_domainsignalin(t_class *c, int onset); giuliomoro@230: EXTERN void class_set_extern_dir(t_symbol *s); giuliomoro@230: #define CLASS_MAINSIGNALIN(c, type, field) \ giuliomoro@230: class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0) giuliomoro@230: giuliomoro@230: /* prototype for functions to save Pd's to a binbuf */ giuliomoro@230: typedef void (*t_savefn)(t_gobj *x, t_binbuf *b); giuliomoro@230: EXTERN void class_setsavefn(t_class *c, t_savefn f); giuliomoro@230: EXTERN t_savefn class_getsavefn(t_class *c); giuliomoro@230: EXTERN void obj_saveformat(t_object *x, t_binbuf *bb); /* add format to bb */ giuliomoro@230: giuliomoro@230: /* prototype for functions to open properties dialogs */ giuliomoro@230: typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist); giuliomoro@230: EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f); giuliomoro@230: EXTERN t_propertiesfn class_getpropertiesfn(t_class *c); giuliomoro@230: giuliomoro@230: #ifndef PD_CLASS_DEF giuliomoro@230: #define class_addbang(x, y) class_addbang((x), (t_method)(y)) giuliomoro@230: #define class_addpointer(x, y) class_addpointer((x), (t_method)(y)) giuliomoro@230: #define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y)) giuliomoro@230: #define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y)) giuliomoro@230: #define class_addlist(x, y) class_addlist((x), (t_method)(y)) giuliomoro@230: #define class_addanything(x, y) class_addanything((x), (t_method)(y)) giuliomoro@230: #endif giuliomoro@230: giuliomoro@230: /* ------------ printing --------------------------------- */ giuliomoro@230: EXTERN void post(const char *fmt, ...); giuliomoro@230: EXTERN void startpost(const char *fmt, ...); giuliomoro@230: EXTERN void poststring(const char *s); giuliomoro@230: EXTERN void postfloat(t_floatarg f); giuliomoro@230: EXTERN void postatom(int argc, t_atom *argv); giuliomoro@230: EXTERN void endpost(void); giuliomoro@230: EXTERN void error(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2); giuliomoro@230: EXTERN void verbose(int level, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3); giuliomoro@230: EXTERN void bug(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2); giuliomoro@230: EXTERN void pd_error(void *object, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3); giuliomoro@230: EXTERN void logpost(const void *object, const int level, const char *fmt, ...) giuliomoro@230: ATTRIBUTE_FORMAT_PRINTF(3, 4); giuliomoro@230: EXTERN void sys_logerror(const char *object, const char *s); giuliomoro@230: EXTERN void sys_unixerror(const char *object); giuliomoro@230: EXTERN void sys_ouch(void); giuliomoro@230: giuliomoro@230: giuliomoro@230: /* ------------ system interface routines ------------------- */ giuliomoro@230: EXTERN int sys_isreadablefile(const char *name); giuliomoro@230: EXTERN int sys_isabsolutepath(const char *dir); giuliomoro@230: EXTERN void sys_bashfilename(const char *from, char *to); giuliomoro@230: EXTERN void sys_unbashfilename(const char *from, char *to); giuliomoro@230: EXTERN int open_via_path(const char *dir, const char *name, const char *ext, giuliomoro@230: char *dirresult, char **nameresult, unsigned int size, int bin); giuliomoro@230: EXTERN int sched_geteventno(void); giuliomoro@230: EXTERN double sys_getrealtime(void); giuliomoro@230: EXTERN int (*sys_idlehook)(void); /* hook to add idle time computation */ giuliomoro@230: giuliomoro@230: /* Win32's open()/fopen() do not handle UTF-8 filenames so we need giuliomoro@230: * these internal versions that handle UTF-8 filenames the same across giuliomoro@230: * all platforms. They are recommended for use in external giuliomoro@230: * objectclasses as well so they work with Unicode filenames on Windows */ giuliomoro@230: EXTERN int sys_open(const char *path, int oflag, ...); giuliomoro@230: EXTERN int sys_close(int fd); giuliomoro@230: EXTERN FILE *sys_fopen(const char *filename, const char *mode); giuliomoro@230: EXTERN int sys_fclose(FILE *stream); giuliomoro@230: giuliomoro@230: /* ------------ threading ------------------- */ giuliomoro@230: EXTERN void sys_lock(void); giuliomoro@230: EXTERN void sys_unlock(void); giuliomoro@230: EXTERN int sys_trylock(void); giuliomoro@230: giuliomoro@230: giuliomoro@230: /* --------------- signals ----------------------------------- */ giuliomoro@230: giuliomoro@230: typedef PD_FLOATTYPE t_sample; giuliomoro@230: typedef union _sampleint_union { giuliomoro@230: t_sample f; giuliomoro@230: PD_FLOATUINTTYPE i; giuliomoro@230: } t_sampleint_union; giuliomoro@230: #define MAXLOGSIG 32 giuliomoro@230: #define MAXSIGSIZE (1 << MAXLOGSIG) giuliomoro@230: giuliomoro@230: typedef struct _signal giuliomoro@230: { giuliomoro@230: int s_n; /* number of points in the array */ giuliomoro@230: t_sample *s_vec; /* the array */ giuliomoro@230: t_float s_sr; /* sample rate */ giuliomoro@230: int s_refcount; /* number of times used */ giuliomoro@230: int s_isborrowed; /* whether we're going to borrow our array */ giuliomoro@230: struct _signal *s_borrowedfrom; /* signal to borrow it from */ giuliomoro@230: struct _signal *s_nextfree; /* next in freelist */ giuliomoro@230: struct _signal *s_nextused; /* next in used list */ giuliomoro@230: int s_vecsize; /* allocated size of array in points */ giuliomoro@230: } t_signal; giuliomoro@230: giuliomoro@230: typedef t_int *(*t_perfroutine)(t_int *args); giuliomoro@230: giuliomoro@230: EXTERN t_int *plus_perform(t_int *args); giuliomoro@230: EXTERN t_int *zero_perform(t_int *args); giuliomoro@230: EXTERN t_int *copy_perform(t_int *args); giuliomoro@230: giuliomoro@230: EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n); giuliomoro@230: EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n); giuliomoro@230: EXTERN void dsp_add_scalarcopy(t_float *in, t_sample *out, int n); giuliomoro@230: EXTERN void dsp_add_zero(t_sample *out, int n); giuliomoro@230: giuliomoro@230: EXTERN int sys_getblksize(void); giuliomoro@230: EXTERN t_float sys_getsr(void); giuliomoro@230: EXTERN int sys_get_inchannels(void); giuliomoro@230: EXTERN int sys_get_outchannels(void); giuliomoro@230: giuliomoro@230: EXTERN void dsp_add(t_perfroutine f, int n, ...); giuliomoro@230: EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec); giuliomoro@230: EXTERN void pd_fft(t_float *buf, int npoints, int inverse); giuliomoro@230: EXTERN int ilog2(int n); giuliomoro@230: giuliomoro@230: EXTERN void mayer_fht(t_sample *fz, int n); giuliomoro@230: EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag); giuliomoro@230: EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag); giuliomoro@230: EXTERN void mayer_realfft(int n, t_sample *real); giuliomoro@230: EXTERN void mayer_realifft(int n, t_sample *real); giuliomoro@230: giuliomoro@230: EXTERN float *cos_table; giuliomoro@230: #define LOGCOSTABSIZE 9 giuliomoro@230: #define COSTABSIZE (1<