From d82c79024b44f96d3c5f613cfb93cc9c9d917ff9 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Thu, 22 Oct 2009 19:48:22 +0000 Subject: Added single file version of param svn path=/trunk/externals/tof/; revision=12644 --- src/paramCustom.h | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 src/paramCustom.h (limited to 'src/paramCustom.h') diff --git a/src/paramCustom.h b/src/paramCustom.h new file mode 100644 index 0000000..9d34f83 --- /dev/null +++ b/src/paramCustom.h @@ -0,0 +1,200 @@ + + +static t_class *paramCustom_class; +static t_class *paramCustom_receive_class; +struct _paramCustom_receive; + +typedef struct _paramCustom { + t_object x_obj; + t_param* param; + t_outlet* outlet; + t_outlet* outlet2; + t_binbuf* bb; + t_symbol* receive; + struct _paramCustom_receive* r; + int nopresets; +} t_paramCustom; + +typedef struct _paramCustom_receive +{ + t_object x_obj; + t_paramCustom *owner; +} t_paramCustom_receive; + + + +static void paramCustom_bang(t_paramCustom *x) +{ + /* + outlet_anything(x->outlet, x->selector, x->ac, x->av); + + if(x->selector != &s_bang ) tof_send_anything_prepend(x->send,x->selector,x->ac,x->av,x->set_s ); + */ +} +/* + +static void paramClass_loadbang(t_paramClass *x) +{ + if (!sys_noloadbang && !x->noloadbang) + paramClass_bang(x); +} +*/ + +static void paramCustom_anything(t_paramCustom *x, t_symbol *selector, int argc, t_atom *argv) +{ + if (x->bb) { + if ((selector != &s_bang)) { + int ac = argc + 2; + t_atom *av = getbytes(ac*sizeof(*av)); + tof_copy_atoms(argv,av+2,argc); + SETSYMBOL(av, x->param->path); + SETSYMBOL(av+1, selector); + binbuf_add(x->bb, ac, av); + binbuf_addsemi(x->bb); + freebytes(av, ac*sizeof(*av)); + } + } else { + pd_error(x,"No save triggered"); + } +} + + + + +// DECONSTRUCTOR + +static void paramCustom_free(t_paramCustom *x) +{ + + if (x->receive) pd_unbind(&x->r->x_obj.ob_pd, x->receive); + + if (x->param) param_unregister(x->param); + + +} + +// SPECIAL PARAM GET FUNCTION +/* +static void paramClass_get(t_paramClass *x, t_symbol** s, int* ac, t_atom** av) { + *s = x->selector; + *ac = x->ac; + *av = x->av; +} +*/ + +// SPECIAL PARAM SAVE FUNCTION +static void paramCustom_save(t_paramCustom *x, t_binbuf* bb, int f) { + + // f = -1 for the main save file + // f => 0 if it is a preset + if ( f >= 0 && x->nopresets) return; + + + if ( !x->bb ) { + + x->bb = bb; + // TRIGGER OUTPUT + outlet_bang(x->outlet); + x->bb = NULL; + + } else { + pd_error(x,"paramCustom is already saving"); + } + +} + + + +static void paramCustom_receive_anything(t_paramCustom_receive *r, t_symbol *s, int ac, t_atom *av){ + + outlet_anything(r->owner->outlet2,s,ac,av); + + +} + + + +// CONSTRUCTOR +static void* paramCustom_new(t_symbol *s, int ac, t_atom *av) +{ + t_paramCustom *x = (t_paramCustom *)pd_new(paramCustom_class); + + + // GET THE CURRENT CANVAS + t_canvas* canvas=tof_get_canvas(); + + // GET THE NAME + t_symbol* name = param_get_name(ac,av); + + if (!name) return NULL; + + t_symbol* path = param_get_path(canvas,name); + t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas)); + + // FIND THE NO PRESET TAG: /nps + x->nopresets = tof_find_tag('/',gensym("/nps"), ac-1, av+1); + + + + x->param = param_register(x,root,path, NULL,\ + (t_paramSaveMethod) paramCustom_save,NULL); + + if (!x->param) return NULL; + + + + int l = strlen(path->s_name) + strlen(root->s_name) + 2; + char* receiver = getbytes( l * sizeof(*receiver)); + strcat(receiver,root->s_name); + strcat(receiver,path->s_name); + x->receive = gensym(receiver); + //strcat(receiver,"_"); + // x->send = gensym(receiver); + freebytes(receiver, l * sizeof(*receiver)); + + #ifdef PARAMDEBUG + post("receive:%s",x->receive->s_name); + //post("send:%s",x->send->s_name); + #endif + + + x->bb = NULL; + + + // Set up receive proxy + t_paramCustom_receive *r = (t_paramCustom_receive *)pd_new(paramCustom_receive_class); + x->r = r; + r->owner = x; + + // BIND RECEIVER + pd_bind(&r->x_obj.ob_pd, x->receive ); + + + + + // CREATE INLETS AND OUTLETS + //inlet_new((t_object *)x, (t_pd *)p, 0, 0); + x->outlet = outlet_new(&x->x_obj, &s_list); + x->outlet2 = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +void paramCustom_setup(void) +{ + paramCustom_class = class_new(gensym("paramCustom"), + (t_newmethod)paramCustom_new, (t_method)paramCustom_free, + sizeof(t_paramCustom), 0, A_GIMME, 0); + + + class_addanything(paramCustom_class, paramCustom_anything); + class_addbang(paramCustom_class, paramCustom_bang); + + //class_addmethod(param_class, (t_method)paramClass_loadbang, gensym("loadbang"), 0); + + paramCustom_receive_class = class_new(gensym("_paramCustom_receive"), + 0, 0, sizeof(t_paramCustom_receive), CLASS_PD | CLASS_NOINLET, 0); + + class_addanything(paramCustom_receive_class, paramCustom_receive_anything); + +} -- cgit v1.2.1