From 2b60d55c919e7588f5aff15936e83c300b3660bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 22 Mar 2005 20:58:25 +0000 Subject: zexy-2.0: - use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641 --- src/tabdump.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/tabdump.c (limited to 'src/tabdump.c') diff --git a/src/tabdump.c b/src/tabdump.c new file mode 100644 index 0000000..d308454 --- /dev/null +++ b/src/tabdump.c @@ -0,0 +1,117 @@ + +/****************************************************** + * + * zexy - implementation file + * + * copyleft (c) IOhannes m zmölnig + * + * 1999:forum::für::umläute:2004 + * + * institute of electronic music and acoustics (iem) + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + + +/* hack : 2108:forum::für::umläute:1999 @ iem */ + +#include "zexy.h" + + +/* =================== tabdump ====================== */ + +static t_class *tabdump_class; + +typedef struct _tabdump +{ + t_object x_obj; + t_symbol *x_arrayname; + t_int startindex, stopindex; +} t_tabdump; + +static void tabdump_bang(t_tabdump *x) +{ + t_garray *A; + int npoints; + t_float *vec; + + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + error("%s: no such array", x->x_arrayname->s_name); + else if (!garray_getfloatarray(A, &npoints, &vec)) + error("%s: bad template for tabdump", x->x_arrayname->s_name); + else + { + int n; + t_atom *atombuf; + + int start=x->startindex; + int stop =x->stopindex; + if(start<0||start>stop)start=0; + if(stopnpoints)stop=npoints; + npoints=stop-start; + + atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); + for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], vec[start+n]); + outlet_list(x->x_obj.ob_outlet, &s_list, npoints, atombuf); + freebytes(atombuf,sizeof(t_atom)*npoints); + } +} + +static void tabdump_list(t_tabdump *x, t_symbol*s,int argc, t_atom*argv) +{ + int a,b; + switch(argc){ + case 2: + a=atom_getint(argv); + b=atom_getint(argv+1); + x->startindex=(astopindex =(a>b)?a:b; + tabdump_bang(x); + break; + default: + error("tabdump: list must be 2 floats (is %d atoms)", argc); + } +} + +static void tabdump_set(t_tabdump *x, t_symbol *s) +{ + x->x_arrayname = s; +} + +static void *tabdump_new(t_symbol *s) +{ + t_tabdump *x = (t_tabdump *)pd_new(tabdump_class); + x->x_arrayname = s; + x->startindex=0; + x->stopindex=-1; + outlet_new(&x->x_obj, &s_list); + + return (x); +} + +static void tabdump_helper(void) +{ + post("\n%c tabdump - object : dumps a table as a package of floats", HEARTSYMBOL); + post("'set '\t: read out another table\n" + "'bang'\t\t: dump the table\n" + "outlet\t\t: table-data as package of floats"); + post("creation\t: \"tabdump
\""); + +} + +void tabdump_setup(void) +{ + tabdump_class = class_new(gensym("tabdump"), (t_newmethod)tabdump_new, + 0, sizeof(t_tabdump), 0, A_DEFSYM, 0); + class_addbang(tabdump_class, (t_method)tabdump_bang); + class_addlist(tabdump_class, (t_method)tabdump_list); + + class_addmethod(tabdump_class, (t_method)tabdump_set, gensym("set"), + A_SYMBOL, 0); + + class_addmethod(tabdump_class, (t_method)tabdump_helper, gensym("help"), 0); + class_sethelpsymbol(tabdump_class, gensym("zexy/tabdump")); +} -- cgit v1.2.1