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