From fc3d3c0a4f110a23335398c327ac0a4fc949d5cb Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Mon, 17 Jun 2002 10:13:57 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r12, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ggee/; revision=13 --- control/unwonk.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 control/unwonk.c (limited to 'control/unwonk.c') diff --git a/control/unwonk.c b/control/unwonk.c new file mode 100755 index 0000000..e44ef10 --- /dev/null +++ b/control/unwonk.c @@ -0,0 +1,119 @@ +/* (C) Guenter Geiger */ + + +#include + + +/* -------------------------- unwonk ------------------------------ */ + +static t_class *unwonk_class; + +typedef struct unwonkout +{ + t_atomtype u_type; + t_outlet *u_outlet; +} t_unwonkout; + +typedef struct _unwonk +{ + t_object x_obj; + t_int x_n; + t_unwonkout *x_vec; +} t_unwonk; + +static void *unwonk_new(t_symbol *s, int argc, t_atom *argv) +{ + t_unwonk *x = (t_unwonk *)pd_new(unwonk_class); + t_atom defarg[2], *ap; + t_unwonkout *u; + int i; + if (!argc) + { + argv = defarg; + argc = 2; + SETFLOAT(&defarg[0], 0); + SETFLOAT(&defarg[1], 0); + } + + x->x_n = argc + 1; + x->x_vec = (t_unwonkout *)getbytes(x->x_n * sizeof(*x->x_vec)); + + for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++) + { + t_atomtype type = ap->a_type; + if (type == A_SYMBOL) + { + char c = *ap->a_w.w_symbol->s_name; + if (c == 's') + { + u->u_type = A_SYMBOL; + u->u_outlet = outlet_new(&x->x_obj, &s_symbol); + } + else if (c == 'p') + { + u->u_type = A_POINTER; + u->u_outlet = outlet_new(&x->x_obj, &s_pointer); + } + else + { + if (c != 'f') error("unwonk: %s: bad type", + ap->a_w.w_symbol->s_name); + u->u_type = A_FLOAT; + u->u_outlet = outlet_new(&x->x_obj, &s_float); + } + } + else + { + u->u_type = A_FLOAT; + u->u_outlet = outlet_new(&x->x_obj, &s_float); + } + } + + u->u_type = A_GIMME; + u->u_outlet = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +static void unwonk_list(t_unwonk *x, t_symbol *s, int argc, t_atom *argv) +{ + t_atom *ap; + t_unwonkout *u; + int i; + int margc = argc; + + + if (argc > x->x_n - 1) margc = x->x_n - 1; + + if (argc - margc > 0) { + ap = argv + margc; + u = x->x_vec + margc; + outlet_list(u->u_outlet,0,argc - margc, ap); + } + + for (i = margc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;) + { + t_atomtype type = u->u_type; + if (type != ap->a_type) + error("unwonk: type mismatch"); + else if (type == A_FLOAT) + outlet_float(u->u_outlet, ap->a_w.w_float); + else if (type == A_SYMBOL) + outlet_symbol(u->u_outlet, ap->a_w.w_symbol); + else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer); + } + + +} + +static void unwonk_free(t_unwonk *x) +{ + freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec)); +} + +void unwonk_setup(void) +{ + unwonk_class = class_new(gensym("unwonk"), (t_newmethod)unwonk_new, + (t_method)unwonk_free, sizeof(t_unwonk), 0, A_GIMME, 0); + class_addlist(unwonk_class, unwonk_list); +} -- cgit v1.2.1