From 6c2dc661c28e5f3e49ed7879a298d4e80e68bb80 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Fri, 18 Sep 2009 21:59:56 +0000 Subject: new version of param that uses root concepts svn path=/trunk/externals/tof/; revision=12398 --- test/param-help.pd | 33 ++-- test/param.c | 162 ++++++++++--------- test/param.h | 424 ++++++++++++++++++++++++++++++++++++------------- test/paramDump.c | 38 +++-- test/paramFile-help.pd | 75 +++------ test/paramFile.c | 11 +- test/paramGui.pd | 152 +++++++++--------- test/paramRoute.c | 47 +++--- 8 files changed, 564 insertions(+), 378 deletions(-) diff --git a/test/param-help.pd b/test/param-help.pd index 246fdd8..d6f0b39 100644 --- a/test/param-help.pd +++ b/test/param-help.pd @@ -1,11 +1,11 @@ -#N canvas 1027 43 1018 689 10; +#N canvas 1024 0 1018 716 10; #X obj 42 514 dac~; #X obj 47 192 nbx 5 14 -1e+37 1e+37 0 0 /wow/OSC1/freq /wow/OSC1/freq_ -/wow/OSC1/freq 0 -8 0 10 -262144 -1 -1 320 256; +/wow/OSC1/freq 0 -8 0 10 -262144 -1 -1 0 256; #X obj 161 190 hsl 128 15 0 1 0 0 /wow/OSC1/amp /wow/OSC1/amp_ /wow/OSC1/amp -2 -8 0 10 -262144 -1 -1 0 1; #X obj 49 231 nbx 5 14 -1e+37 1e+37 0 0 /wow/OSC2/freq /wow/OSC2/freq_ -/wow/OSC2/freq 0 -8 0 10 -262144 -1 -1 400 256; +/wow/OSC2/freq 0 -8 0 10 -262144 -1 -1 0 256; #X obj 163 229 hsl 128 15 0 1 0 0 /wow/OSC2/amp /wow/OSC2/amp_ /wow/OSC2/amp -2 -8 0 10 -262144 -1 -1 0 1; #X obj 387 215 print PARAM; @@ -31,7 +31,7 @@ to examine how they are linked to the abstraction below.; #N canvas 0 0 450 300 more_about_hierachy 0; #X restore 607 532 pd more_about_hierachy; #X obj 49 158 hsl 128 15 0 1 0 0 /masterVolume /masterVolume_ /masterVolume --2 -8 0 10 -262144 -1 -1 1270 1; +-2 -8 0 10 -262144 -1 -1 0 1; #X text 605 488 -- the /ID keyword --; #X text 107 124 -- example --; #X text 468 202 You can "listen" to the param "stream" by receiving @@ -62,20 +62,24 @@ of some the example's sliders or number boxes to print out this stream. #X obj 73 430 param /masterVolume 0 /gui slider 0 1; #X msg 520 495 /wow; #X msg 615 643 guis /wow; -#X obj 422 366 print yeah; -#X msg 170 327 save; #X msg 621 25 save; #X msg 810 79 save; #X obj 742 116 paramRoute; -#X obj 52 365 examples/param-synth /id wow /OSC1/freq 320; -#X obj 399 339 param /t_test 0 /gui tgl; #X obj 32 587 OSCToParam 7493; #X text 134 583 OSCToParam can send all icomming OSC message to matching parameters. For example \, the OSC message '/masterVolume 0.56' on port 7493 will be forwarded to the parameter '/masterVolume' that will then take the value '0.56'.; +#X obj 422 366 print yeah; +#X obj 399 339 param /t_test 0 /gui tgl; +#X obj 676 343 paramFile; +#X obj 678 296 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X msg 613 564 guis; +#X obj 51 366 examples/param-synth /id tom /OSC1/freq 320; +#X obj 440 117 ./examples/boubou; #X connect 6 0 7 0; -#X connect 7 0 52 0; +#X connect 7 0 57 0; #X connect 8 0 5 0; #X connect 12 0 8 1; #X connect 14 0 8 0; @@ -96,8 +100,9 @@ then take the value '0.56'.; #X connect 44 0 18 0; #X connect 45 0 40 0; #X connect 46 0 29 0; -#X connect 48 0 52 0; -#X connect 49 0 42 0; -#X connect 50 0 51 0; -#X connect 52 0 19 0; -#X connect 53 0 47 0; +#X connect 47 0 42 0; +#X connect 48 0 49 0; +#X connect 53 0 52 0; +#X connect 55 0 54 0; +#X connect 56 0 29 0; +#X connect 57 0 19 0; diff --git a/test/param.c b/test/param.c index 576379f..787fa38 100644 --- a/test/param.c +++ b/test/param.c @@ -21,6 +21,7 @@ + #include "tof.h" #include "param.h" @@ -36,9 +37,9 @@ typedef struct _param t_object x_obj; struct _param_inlet2 *x_param_inlet2; - t_symbol *x_path; + //t_symbol *x_path; t_symbol *s_PARAM; - t_symbol *x_update_gui; + //t_symbol *x_update_gui; t_symbol *s_set; struct param *x_param; } t_param; @@ -49,65 +50,26 @@ typedef struct _param_inlet2 t_param *p_owner; } t_param_inlet2; -/* -static void output_param(t_param *x) { - if (x->x_param) { - if((x->x_param->selector == &s_bang) ) { - outlet_bang(x->x_obj.ob_outlet); - } else { - outlet_anything(x->x_obj.ob_outlet, x->x_param->selector, x->x_param->ac, x->x_param->av); - } - } -} -*/ -/* -static void send_param(t_param *x, t_symbol* s,t_symbol* prepend ) { - if (x->x_param) { - if((x->x_param->selector == &s_bang)) { - if (s->s_thing) - pd_bang(s->s_thing); - } else { - if (s->s_thing) { - if ( x->x_param->selector == &s_list || x->x_param->selector == &s_float || x->x_param->selector == &s_symbol ) { - typedmess(s->s_thing, prepend, x->x_param->ac, x->x_param->av); - } else { - int ac = x->x_param->ac + 1; - t_atom *av = getbytes(ac*sizeof(*av)); - tof_copy_atoms(x->x_param->av,av+1,x->x_param->ac); - SETSYMBOL(av, x->x_param->selector); - typedmess(s->s_thing, prepend, ac, av); - freebytes(av, ac*sizeof(*av)); - } - } - } - } - -} -*/ static void param_bang(t_param *x) { - param_output(x->x_param,x->x_obj.ob_outlet); + if ( x->x_param) { + param_output(x->x_param,x->x_obj.ob_outlet); - param_send_prepend(x->x_param, x->s_PARAM ,x->x_path ); - if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_update_gui ,x->s_set ); - + //param_send_prepend(x->x_param, x->s_PARAM ,x->x_param->path ); + //if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_param->send ,x->s_set ); + } } static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av) { + post("RECEIVING SOMETHING"); + if ( x->x_param) set_param_anything(x->x_param,s,ac,av); param_bang(x); - - /* - param_output(x->x_param,x->x_obj.ob_outlet); - - param_send_prepend(x->x_param, x->s_PARAM ,x->x_path ); - if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_update_gui ,x->s_set ); - */ - + } @@ -127,11 +89,11 @@ static void param_free(t_param *x) { if(x->x_param_inlet2) pd_free((t_pd *)x->x_param_inlet2); - - - if (x->x_param) unregister_param(x->x_param); - - if ( x->x_path) pd_unbind(&x->x_obj.ob_pd, x->x_path); + + if (x->x_param) { + pd_unbind(&x->x_obj.ob_pd, x->x_param->receive); + param_unregister(x->x_param); + } } @@ -149,30 +111,76 @@ static void *param_new(t_symbol *s, int ac, t_atom *av) x->x_param_inlet2 = p; p->p_owner = x; + // GET THE CURRENT CANVAS + t_canvas* canvas=tof_get_canvas(); + + // GET THE NAME + t_symbol* name = param_get_name(ac,av); + + if (name) { + + t_symbol* path = param_get_path(canvas,name); + t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas)); + + + // FIND PARAM VALUE + // A. In canvas' arguments + // B. In object's arguments + // C. Defaults to a bang + + int ac_p = 0; + t_atom* av_p = NULL; + + + // A. In canvas' arguments + int ac_c = 0; + t_atom* av_c = NULL; + + t_canvas * before = tof_get_canvas_before_root(canvas); + tof_get_canvas_arguments(before,&ac_c , &av_c); + param_find_value(name, ac_c, av_c,&ac_p,&av_p); + + // B. I object's arguments + if ( ac_p == 0 && ac > 1) { + int start = 1; + int count = 0; + tof_get_tagged_argument('/',ac,av,&start,&count); + if (count > 0) { + ac_p = count; + av_p = av + start; + } + } + + + + + //FIND THE GUI TAGS + int ac_g = 0; + t_atom* av_g = NULL; + // There could be a problem if the the name is also /gui + param_find_value(gensym("/gui"), ac, av,&ac_g,&av_g); + + x->x_param = param_register(root,path,ac_p,av_p,ac_g,av_g); + + #ifdef PARAMDEBUG + post("receive:%s",x->x_param->receive->s_name); + post("send:%s",x->x_param->send->s_name); + #endif + + // BIND RECEIVER + pd_bind(&x->x_obj.ob_pd, x->x_param->receive ); + // CREATE INLETS AND OUTLETS + inlet_new((t_object *)x, (t_pd *)p, 0, 0); + outlet_new(&x->x_obj, &s_list); + + + } else { + + pd_error(x,"Could not create param. See possible errors above."); + } + + - x->x_param = NULL; - - - // GET THE CURRENT CANVAS - t_canvas *canvas=tof_get_canvas(); - - struct param_build_info build_info; - get_param_build_info(canvas,ac,av,&build_info,1); - - - if ( build_info.path ) { - x->x_path = build_info.path; - x->x_update_gui = build_info.path_g; - // BIND RECEIVER - pd_bind(&x->x_obj.ob_pd, build_info.path ); - // REGISTER PARAM - x->x_param = register_param(&build_info); - // CREATE INLETS AND OUTLETS - inlet_new((t_object *)x, (t_pd *)p, 0, 0); - outlet_new(&x->x_obj, &s_list); - } else { - pd_error(x,"[param] requires a name(first argument) that starts with a /"); - } diff --git a/test/param.h b/test/param.h index 4230f8a..7a383db 100644 --- a/test/param.h +++ b/test/param.h @@ -1,37 +1,40 @@ - +#define PARAMDEBUG #include +char param_buf_temp_a[MAXPDSTRING]; +char param_buf_temp_b[MAXPDSTRING]; +char* separator = "/"; + + struct param { - t_symbol* selector; //Type of data stored - int ac; //Number of values stored - int alloc; //Memory allocated - t_atom* av; //Values stored - t_symbol* path; //Path(name) of the param - t_symbol* path_g; - //t_symbol* basepath; - struct param* next; //Next param - struct param* previous; //Previous param - int users; //Number of param objects using this param - t_symbol* id; //An id set only if it is saveable - int ac_g; - t_atom* av_g; + + t_symbol* root; + t_symbol* path; //Path(name) of the param + t_symbol* send; + t_symbol* receive; + t_symbol* selector; //Type of data stored + int alloc; //Memory allocated + int ac; //Number of values stored + t_atom* av; //Values stored + struct param* next; //Next param + struct param* previous; //Previous param + int users; //Number of param objects using this param + t_symbol* id; //The base id + int ac_g; //Gui argument count + t_atom* av_g; //Gui argument values }; +struct paramroot { + t_symbol* root; + struct param* params; //param list + struct paramroot* next; //Next paramroot + struct paramroot* previous; //Previous paramroot +}; -struct param* paramlist; +struct paramroot* paramroots; +//struct param* paramlist; -typedef struct param_build_info { - int ac; - t_atom* av; - t_symbol* path; - t_symbol* id; - t_symbol* path_g; - int ac_g; - t_atom* av_g; - t_symbol* basepath; - t_symbol* basename; -}t_param_build_info; static void set_param_anything( struct param* p, t_symbol* s, int ac, t_atom *av) { @@ -58,21 +61,38 @@ static void set_param( struct param* p, int ac, t_atom *av) { } - - - - -static struct param* get_param_list(void) { +static void param_find_value(t_symbol *name, int ac, t_atom *av, int *ac_r,t_atom** av_r) { - if (paramlist == NULL) { - //post("No params found"); - return NULL; - } + int i; + int j = 0; + for (i=0;is_name); + if ( IS_A_SYMBOL(av,i) && name == atom_getsymbol(av+i) && (i+1)s_name[0] == '/' ) { + //j = j-1; + break; + } + } + break; + } + } + j = j-i; + //post("i:%d j:%d",i,j); - return paramlist; -} + if ( j > 0) { + *ac_r = j; + *av_r = av+i; + } else { + *ac_r = 0; + } + } + +/* static void print_all_params(void) { struct param* p = paramlist; @@ -84,29 +104,209 @@ static void print_all_params(void) { } } +*/ + + +static struct paramroot* param_get_root(t_symbol* root) { + + if (paramroots == NULL) { + #ifdef PARAMDEBUG + post("Could not get...not even one root created"); + #endif + return NULL; + } + + + // Pointer to the start of paramroots + struct paramroot* branch = paramroots; + + while( branch ) { + if ( branch->root == root) { + #ifdef PARAMDEBUG + post("Found root:%s",root->s_name); + #endif + + return branch; + } + branch = branch->next; + } + #ifdef PARAMDEBUG + post("Could not find root"); + #endif + return branch; + +} + + +static struct paramroot* param_root_attach(t_symbol* root){ + + // Pointer to the start of paramroots + struct paramroot* branch = paramroots; + + while( branch ) { + if ( branch->root == root) { + #ifdef PARAMDEBUG + post("Found root:%s",root->s_name); + #endif + + return branch; + } + if ( branch->next == NULL ) break; + branch = branch->next; + } + + // we did not find a paramroot linked to this root canvas + // so we create it + #ifdef PARAMDEBUG + post("Creating root:%s",root->s_name); + #endif + + // Create and add paramroot to the end + struct paramroot* newbranch = getbytes(sizeof(*newbranch)); + newbranch->root = root; + newbranch->next = NULL; + newbranch->params = NULL; + + if (branch) { + #ifdef PARAMDEBUG + post("Appending it to previous roots"); + #endif + newbranch->previous = branch; + branch->next = newbranch; + } else { + #ifdef PARAMDEBUG + post("Creating first root"); + #endif + newbranch->previous = NULL; + paramroots = newbranch; + } + + + return newbranch; + +} + -//static struct param* register_param( t_symbol* path, int ac, t_atom* av, t_symbol* id -static struct param* register_param( t_param_build_info* build) { +static struct param* get_param_list(t_symbol* root) { + + + struct paramroot* branch = param_get_root(root); + if (branch) { + + #ifdef PARAMDEBUG + post("Getting params from %s",branch->root->s_name); + if (!branch->params) post("Root contains no params"); + #endif + return branch->params; + } + + return NULL; + + +} + +static t_symbol* param_get_name ( int ac, t_atom* av ) { + + if (ac && IS_A_SYMBOL(av, 0)) { + char *firstChar = (atom_getsymbol(av))->s_name; + if (*firstChar == *separator) { + return atom_getsymbol(av); + } + } + post("param requires a name that starts with a \"/\""); + return NULL; +} + +// Name can be NULL + +static t_symbol* param_get_path( t_canvas* i_canvas, t_symbol* name) { + + char* sbuf_name = param_buf_temp_a; + char* sbuf_temp = param_buf_temp_b; + sbuf_name[0] = '\0'; + sbuf_temp[0] = '\0'; + //char* separator = "/"; + - //post("registering %s", path->s_name); - t_symbol* path = build->path; - t_symbol* path_g = build->path_g; - int ac = build->ac; - t_atom* av = build->av; - t_symbol* id = build->id; - int ac_g = build->ac_g; - t_atom* av_g = build->av_g; + t_symbol* id_s = gensym("/id"); // symbol that points to "/id" symbol + + // arguments of the current canvas being analyzed + int i_ac; + t_atom * i_av; + // temp pointer to the current id being added to the path + t_symbol* id_temp; - //if ( path) post("path:%s",path->s_name); - //if ( id) post("id:%s",id->s_name); + /* FIND ID AND BASEPATH */ + while( i_canvas->gl_owner) { + // Ignore all supatches + if ( tof_canvas_is_not_subpatch(i_canvas) ) { + tof_get_canvas_arguments(i_canvas,&i_ac, &i_av); + id_temp=tof_get_canvas_name(i_canvas); + //id_temp= canvas_realizedollar(i_canvas, gensym("$0")); + int start = 0; + int count = 0; + //found_id_flag = 0; + + while( tof_get_tagged_argument(*separator,i_ac,i_av,&start,&count) ) { + + if ( IS_A_SYMBOL(i_av,start) + && (id_s == (i_av+start)->a_w.w_symbol) + && (count > 1) ) { + id_temp = atom_getsymbol(i_av+start+1); + //id_canvas = i_canvas; + //found_id_flag = 1; + break; + } + start= start + count; + } + // if ever an /id is missing, this param is not saveable + //if (found_id_flag == 0) saveable = 0; + + // Prepend newly found ID + strcpy(sbuf_temp,sbuf_name); + strcpy(sbuf_name, separator); + strcat(sbuf_name, id_temp->s_name); + strcat(sbuf_name,sbuf_temp); + } + i_canvas = i_canvas->gl_owner; + } + //strcat(sbuf_name,separator); + if ( name != NULL) { + strcat(sbuf_name,name->s_name); + } else { + strcat(sbuf_name, separator); + } + + return gensym(sbuf_name); - struct param* last = paramlist; +} + + + +// root, path, ac, av, ac_g, av_g +// From there, deduct id, path_, etc... + +//static struct param* register_param( t_canvas* canvas, int o_ac, t_atom* o_av) { + +static struct param* param_register(t_symbol* root, t_symbol* path, int ac, t_atom* av,int ac_g, t_atom* av_g) { + + + //char *separator = "/"; + + + + /* GET POINTER TO PARAMLIST FOR THAT ROOT */ + struct paramroot* branch = param_root_attach(root); + struct param* last = branch->params; + // Search for param with same path while( last ) { if ( last->path == path) { - //post("Found param with same name"); + #ifdef PARAMDEBUG + post("Found param with same name"); + #endif last->users = last->users + 1; return last; } @@ -115,37 +315,54 @@ static struct param* register_param( t_param_build_info* build) { } // Create and add param to the end + + + + struct param* p = getbytes(sizeof(*p)); + p->root = root; p->alloc = 0; p->path = path; - p->path_g = path_g; + + // Create receive and send symbols: $0/path + strcpy(param_buf_temp_a,p->root->s_name); + //strcat(param_buf_temp_a,separator); + strcat(param_buf_temp_a,p->path->s_name); + p->receive = gensym(param_buf_temp_a); + strcat(param_buf_temp_a,"_"); + p->send = gensym(param_buf_temp_a); + p->next = NULL; p->users = 1; - p->id = id; + //p->id = id; set_param( p, ac, av); p->ac_g = ac_g; p->av_g = getbytes(ac_g*sizeof(*(p->av_g))); tof_copy_atoms(av_g,p->av_g,ac_g); if (last) { - //post("Appending param"); + #ifdef PARAMDEBUG + post("Appending param"); + #endif p->previous = last; last->next = p; } else { - //post("Creating first param"); + #ifdef PARAMDEBUG + post("Creating first param"); + #endif p->previous = NULL; - paramlist = p; + branch->params = p; } - //print_all_params(); - - return p; - + return p; + } -static void unregister_param( struct param* p) { +static void param_unregister(struct param* p) { //post("unregistering %s", p->path->s_name); + struct paramroot* branch = param_get_root(p->root); + struct param* paramlist = branch->params; if ( paramlist) { @@ -172,50 +389,36 @@ static void unregister_param( struct param* p) { freebytes(p, sizeof *p); } + // Update the params for that root + if (paramlist == NULL) { + if (branch->previous) { + branch->previous->next = branch->next; + if (branch->next) branch->next->previous = branch->previous; + } else { + paramroots = branch->next; + if ( branch->next != NULL) branch->next->previous = NULL; + } + #ifdef PARAMDEBUG + post("Removing root:%s",branch->root->s_name); + #endif + freebytes(branch, sizeof *branch); + } else { + branch->params = paramlist; + } + } else { post("Euh... no params found!"); } - //print_all_params(); } -//////////////////// -static void param_find_value(t_symbol *name, int ac, t_atom *av, int *ac_r,t_atom** av_r) { - - int i; - int j = 0; - for (i=0;is_name); - if ( IS_A_SYMBOL(av,i) && name == atom_getsymbol(av+i) && (i+1)s_name[0] == '/' ) { - //j = j-1; - break; - } - } - break; - } - } - j = j-i; - //post("i:%d j:%d",i,j); - - - if ( j > 0) { - *ac_r = j; - *av_r = av+i; - //x->x_param = register_param( x->x_path , j, av+i,saveable); - } else { - *ac_r = 0; - } - } +/* static void get_param_build_info(t_canvas* canvas, int o_ac, t_atom* o_av, struct param_build_info* pbi, int flag) { pbi->path = NULL; @@ -254,10 +457,6 @@ static void get_param_build_info(t_canvas* canvas, int o_ac, t_atom* o_av, struc t_symbol* id_s = NULL; - // A HACK to find out if we are in a subpatch or an abstraction - // A subpatch always has the same $0 as it's parent - //t_symbol* p_id_s = canvas_realizedollar(i_canvas, gensym("$0")); - //t_symbol* p_id_s = gensym(""); while( i_canvas->gl_owner) { // Ignore all supatches @@ -265,8 +464,6 @@ static void get_param_build_info(t_canvas* canvas, int o_ac, t_atom* o_av, struc tof_get_canvas_arguments(i_canvas,&i_ac, &i_av); id_s= canvas_realizedollar(i_canvas, gensym("$0")); - //if (id_s != p_id_s) { - // p_id_s = id_s; int start = 0; int count = 0; @@ -290,16 +487,12 @@ static void get_param_build_info(t_canvas* canvas, int o_ac, t_atom* o_av, struc if (found_id_flag == 0) saveable = 0; - //if (id_s != p_id_s) { // Prepend newly found ID strcpy(sbuf_temp,sbuf_name); strcpy(sbuf_name, "/"); strcat(sbuf_name, id_s->s_name); strcat(sbuf_name,sbuf_temp); - //} - // p_id_s = id_s; - - //} + } i_canvas = i_canvas->gl_owner; } @@ -392,7 +585,7 @@ static void get_param_build_info(t_canvas* canvas, int o_ac, t_atom* o_av, struc } } - +*/ static void param_send_prepend(struct param *p, t_symbol* s,t_symbol* prepend) { @@ -449,8 +642,9 @@ static void param_output_prepend(struct param* p, t_outlet* outlet, t_symbol* s) } - -static int param_write(t_canvas* canvas, t_symbol* filename, t_symbol* id) { +// Write will only save the params that share the same root +static int param_write(t_canvas* canvas, t_symbol* filename) { + int w_error; @@ -458,9 +652,9 @@ static int param_write(t_canvas* canvas, t_symbol* filename, t_symbol* id) { t_binbuf *bbuf = binbuf_new(); - struct param *p = get_param_list(); + struct param *p = get_param_list(tof_get_dollarzero(canvas)); while(p) { - if ( p->id && ( id == NULL || p->id == id) && (p->selector != &s_bang)) { + if ((p->selector != &s_bang)) { int ac = p->ac + 2; t_atom *av = getbytes(ac*sizeof(*av)); tof_copy_atoms(p->av,av+2,p->ac); @@ -486,7 +680,7 @@ static int param_write(t_canvas* canvas, t_symbol* filename, t_symbol* id) { binbuf_free(bbuf); return w_error; - + } @@ -502,7 +696,7 @@ static int param_read(t_canvas* canvas, t_symbol* filename) r_error= (binbuf_read_via_canvas(bbuf, filename->s_name, canvas, 0)); //pd_error(x, "%s: read failed", filename->s_name); - + t_symbol* root = tof_get_dollarzero(canvas); int bb_ac = binbuf_getnatom(bbuf); int ac = 0; @@ -512,7 +706,13 @@ static int param_read(t_canvas* canvas, t_symbol* filename) while (bb_ac--) { if (bb_av->a_type == A_SEMI) { if ( IS_A_SYMBOL(av,0) && ac > 1) { - t_symbol* s = atom_getsymbol(av); + t_symbol* path = atom_getsymbol(av); + strcpy(param_buf_temp_a,root->s_name); + strcat(param_buf_temp_a,path->s_name); + t_symbol* s = gensym(param_buf_temp_a); + #ifdef PARAMDEBUG + post("Restoring:%s",s->s_name); + #endif if ( s->s_thing) pd_forwardmess(s->s_thing, ac-1, av+1); diff --git a/test/paramDump.c b/test/paramDump.c index 15921cd..af7bd16 100644 --- a/test/paramDump.c +++ b/test/paramDump.c @@ -22,7 +22,6 @@ #include "tof.h" #include "param.h" -#include @@ -34,11 +33,13 @@ typedef struct _paramDump t_object x_obj; t_outlet* outlet; t_symbol* s_set; + t_symbol* root; } t_paramDump; // Dump out the values of a specific id //static void paramDump_values(t_paramDump *x, t_symbol* s, int a_ac, t_atom* a_av) { +/* static void paramDump_values(t_paramDump *x, t_symbol* s) { //if ( s == &s_list && a_ac > 0 && IS_A_SYMBOL(a_av,0) ) s = atom_getsymbol(a_av); @@ -50,7 +51,7 @@ static void paramDump_values(t_paramDump *x, t_symbol* s) { struct param* pp = get_param_list(); while (pp) { - if (pp->id && (all || pp->id == s) ) { + if (pp->root == x->root && (all || pp->id == s) ) { param_output_prepend(pp,x->outlet,pp->path); } @@ -59,14 +60,16 @@ static void paramDump_values(t_paramDump *x, t_symbol* s) { //} } +*/ + static void paramDump_guis(t_paramDump *x, t_symbol* s) { - char* star = "*"; - int all = !(strcmp(s->s_name, star)); + //char* star = "*"; + //int all = !(strcmp(s->s_name, star)); - struct param* pp = get_param_list(); + struct param* pp = get_param_list(x->root); while (pp) { - if (pp->ac_g && (all || pp->id == s) ) { + if (pp->ac_g ) { outlet_anything(x->outlet,pp->path,pp->ac_g,pp->av_g); @@ -75,6 +78,7 @@ static void paramDump_guis(t_paramDump *x, t_symbol* s) { } } +/* static void paramDump_update_guis(t_paramDump *x, t_symbol* s) { char* star = "*"; @@ -82,9 +86,9 @@ static void paramDump_update_guis(t_paramDump *x, t_symbol* s) { struct param* pp = get_param_list(); while (pp) { - if (pp->ac_g && (all || pp->id == s) ) { + if (pp->ac_g && pp->root == x->root && (all || pp->id == s) ) { - param_send_prepend(pp, pp->path_g ,x->s_set ); + param_send_prepend(pp, pp->path_ ,x->s_set ); //if ( pp->path_g->s_thing) // pd_typedmess(pp->path_g->s_thing, pp->selector,pp->ac, pp->av); @@ -94,16 +98,21 @@ static void paramDump_update_guis(t_paramDump *x, t_symbol* s) { pp = pp->next; } } - +*/ // Dump out everything (OR THE ID'S OR JUST THE NAMES?) static void paramDump_bang(t_paramDump *x) { - struct param* pp = get_param_list(); + struct param* pp = get_param_list(x->root); + if (pp == NULL) { + post("No params found"); + } else { + post("Found params"); + } while (pp) { - //if (pp->id) { + //if (pp->root == x->root) { param_output_prepend(pp,x->outlet,pp->path); //} @@ -125,6 +134,9 @@ static void paramDump_free(t_paramDump *x) static void *paramDump_new(t_symbol *s, int ac, t_atom *av) { t_paramDump *x = (t_paramDump *)pd_new(paramDump_class); + x->root = tof_get_dollarzero(tof_get_root_canvas(tof_get_canvas())); + + x->s_set = gensym("set"); x->outlet = outlet_new(&x->x_obj, &s_list); @@ -139,9 +151,9 @@ void paramDump_setup(void) { class_addbang(paramDump_class, paramDump_bang); - class_addmethod(paramDump_class, (t_method) paramDump_values, gensym("values"), A_DEFSYMBOL,0); + //class_addmethod(paramDump_class, (t_method) paramDump_values, gensym("values"), A_DEFSYMBOL,0); class_addmethod(paramDump_class, (t_method) paramDump_guis, gensym("guis"), A_DEFSYMBOL,0); - class_addmethod(paramDump_class, (t_method) paramDump_update_guis, gensym("update"), A_DEFSYMBOL,0); + //class_addmethod(paramDump_class, (t_method) paramDump_update_guis, gensym("update"), A_DEFSYMBOL,0); } diff --git a/test/paramFile-help.pd b/test/paramFile-help.pd index fc635f8..72296ae 100644 --- a/test/paramFile-help.pd +++ b/test/paramFile-help.pd @@ -1,59 +1,30 @@ -#N canvas 1138 171 606 437 10; -#X msg 245 346 save; -#X msg 284 347 load; -#X text 244 327 no presets:; -#X obj 440 328 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 +#N canvas 1024 0 1018 716 10; +#X obj 265 196 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 -1 0; -#X obj 499 354 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 +#X obj 316 247 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 -1 0; -#X msg 440 348 save \$1; -#X msg 499 375 load \$1; -#X text 435 310 with presets:; #X obj 11 36 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 0; #X text 16 92 author: mrtoftrash@gmail.com; #X text 16 113 version: 2009-04-14 (initial release); -#X text 16 37 description: paramFile is an abstraction than can save -and restore params.; -#X obj 245 383 paramFile fileName; -#X obj 440 399 paramFile fileName; -#X text 14 155 argument 1: the file name's prefix. A ".param" is always -appended to the file name stored on the computer. In preset mode \, -the preset number is also include in the stored file name.; -#X text 16 71 tags: state file; -#X obj 391 225 param /test bob; -#X obj 55 261 paramFile; -#X obj 55 231 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +#X obj 30 252 paramFile; +#X obj 30 171 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#X obj 222 222 param /music 43; -#X obj 342 255 param /mtime is 1506; -#X obj 54 297 print FILE; -#X floatatom 230 253 5 0 0 0 - - -; -#X floatatom 155 229 5 0 0 0 - - -; -#X obj 335 281 print mtime; -#X obj 105 231 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 --1 -1; -#X msg 146 289 3; -#X msg 490 259 yuyt; -#X msg 120 333 2; -#X msg 448 283 tom; -#X msg 195 280 2; -#X msg 203 314 3; -#X connect 0 0 12 0; -#X connect 1 0 12 0; -#X connect 3 0 5 0; -#X connect 4 0 6 0; -#X connect 5 0 13 0; -#X connect 6 0 13 0; -#X connect 17 0 21 0; -#X connect 18 0 17 0; -#X connect 19 0 22 0; -#X connect 20 0 24 0; -#X connect 23 0 19 0; -#X connect 25 0 17 1; -#X connect 26 0 17 0; -#X connect 27 0 20 0; -#X connect 28 0 17 0; -#X connect 29 0 20 0; -#X connect 30 0 17 1; -#X connect 31 0 17 1; +#X obj 81 211 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X text 16 37 description: paramFile is an abstraction than saves and +restores params in individual files on the hard disk.; +#X text 16 71 tags: state file param; +#X text 52 169 Save preset "000"; +#X text 108 207 Load preset "000"; +#X obj 265 295 paramFile; +#X floatatom 265 220 5 0 0 0 - - -; +#X floatatom 316 269 5 0 0 0 - - -; +#X text 305 218 Save preset N; +#X text 354 268 Load preset N; +#X connect 0 0 13 0; +#X connect 1 0 14 0; +#X connect 6 0 5 0; +#X connect 7 0 5 1; +#X connect 13 0 12 0; +#X connect 14 0 12 1; diff --git a/test/paramFile.c b/test/paramFile.c index 7302bbc..181048a 100644 --- a/test/paramFile.c +++ b/test/paramFile.c @@ -32,14 +32,14 @@ static t_symbol* paramFile_makefilename(t_symbol* basename, t_float f) { if ( f > 127) f = 127; int i = (int) f; - int length = strlen(basename->s_name)+6; + int length = strlen(basename->s_name)+10; char* buf = getbytes( length * sizeof (*buf)); - sprintf(buf,"%s%03d.p",basename->s_name,i); + sprintf(buf,"%s%03d.param",basename->s_name,i); //strcpy(buf,basename->s_name); //strcat(buf,".param"); t_symbol* filename = gensym(buf); freebytes(buf, length * sizeof (*buf)); - post("File name:%s",filename->s_name); + //post("File name:%s",filename->s_name); return filename; } @@ -48,7 +48,8 @@ static void paramFile_write(t_paramFile *x, t_float f) { t_symbol* filename = paramFile_makefilename(x->basename,f); - if ( param_write(x->canvas,filename,NULL) ) pd_error("%s: write failed", filename->s_name); + post("Writing to:%s",filename->s_name); + if ( param_write(x->canvas,filename) ) pd_error(x,"%s: write failed", filename->s_name); } @@ -57,7 +58,7 @@ static void paramFile_read(t_paramFile *x, t_float f) { t_symbol* filename = paramFile_makefilename(x->basename,f); - + post("Reading from:%s",filename->s_name); if (param_read(x->canvas, filename)) pd_error(x, "%s: read failed", filename->s_name); diff --git a/test/paramGui.pd b/test/paramGui.pd index f0f7670..fc9ae97 100644 --- a/test/paramGui.pd +++ b/test/paramGui.pd @@ -1,95 +1,91 @@ -#N canvas 1027 0 997 713 10; -#N canvas 417 395 450 315 \$0target 0; -#X text 0 0 Please Copy and Paste; -#X obj 0 20 hsl 100 15 0 1 0 0 /me/amp /me/amp_ /me/amp 105 7 0 10 --262144 -1 -1 0 1; -#X obj 0 40 nbx 5 14 -1e+37 1e+37 0 0 /me/freq /me/freq_ /me/freq 57 -7 0 10 -262144 -1 -1 0 256; -#X obj 0 60 hsl 100 15 0 1 0 0 /masterVolume /masterVolume_ /masterVolume -105 7 0 10 -262144 -1 -1 0 1; -#X obj 0 80 hsl 100 15 0 1 0 0 /wow/OSC1/amp /wow/OSC1/amp_ /wow/OSC1/amp -105 7 0 10 -262144 -1 -1 0 1; -#X obj 0 100 nbx 5 14 -1e+37 1e+37 0 0 /wow/OSC1/freq /wow/OSC1/freq_ -/wow/OSC1/freq 57 7 0 10 -262144 -1 -1 0 256; -#X obj 0 120 hsl 100 15 0 1 0 0 /wow/OSC2/amp /wow/OSC2/amp_ /wow/OSC2/amp -105 7 0 10 -262144 -1 -1 0 1; -#X obj 0 140 nbx 5 14 -1e+37 1e+37 0 0 /wow/OSC2/freq /wow/OSC2/freq_ -/wow/OSC2/freq 57 7 0 10 -262144 -1 -1 0 256; -#X symbolatom 0 160 17 0 0 1 /s /s_ /s; +#N canvas 1027 0 997 703 10; +#N canvas 425 135 450 315 \$0target 0; #X restore 77 109 pd \$0target; #X obj 260 140 list split 1; #X obj 101 566 s pd-\$0target; -#X obj 362 333 list prepend; +#X obj 273 341 list prepend; #X obj 386 399 list trim; #X obj 423 199 value \$0y; -#X obj 228 226 value \$0y; -#X obj 178 213 t a b; -#X obj 178 275 list prepend; -#X obj 272 256 t f f; -#X msg -37 460 obj 0 \$1 bng 15 250 50 0 \$2 \$2_ \$2 17 7 0 10 -262144 --1 -1; -#X obj 574 200 s pd-\$0target; -#X msg 132 483 obj 0 \$1 nbx 5 14 -1e+37 1e+37 0 0 \$2 \$2_ \$2 57 -7 0 10 -262144 -1 -1 0 256; +#X obj -156 281 value \$0y; +#X obj -112 311 t f f; +#X obj 497 164 s pd-\$0target; #X obj 266 106 paramDump; #X obj 323 -167 inlet path; #X obj 316 -119 route bang; #X obj 375 -93 symbol; #X obj 299 -27 t b a b b; #X msg 110 182 vis 1; -#X obj 322 230 + 20; -#X msg 419 159 20; -#X msg 578 158 clear \, text 0 0 Please Copy and Paste; -#X msg 600 228 clear; -#X msg 289 515 obj 0 \$1 hsl 100 15 \$3 \$4 0 0 \$2 \$2_ \$2 105 7 -0 10 -262144 -1 -1 0 1; -#X obj 451 313 list split 1; +#X obj -62 285 + 20; +#X obj 434 277 list split 1; #X obj 394 374 list; -#X msg 753 490 text 0 \$1 Unknown gui type for \$2; -#X msg 523 448 symbolatom 0 \$1 17 0 0 1 \$2 \$2_ \$2; +#X msg 729 492 text 0 \$1 Unknown gui type for \$2; #X obj 294 -79 symbol *; -#X msg 272 57 guis \$1 \, update \$1; #X obj 384 423 route bng nbx slider symbolatom tgl; -#X msg 528 476 obj 0 \$1 tgl 15 0 \$2 \$2_ \$2 17 7 0 10 -262144 -1 +#X obj 469 389 print; +#X msg 272 57 guis \$1; +#X obj 0 302 zexy/makesymbol %s%s%s; +#X msg 0 278 list $ 0 \$1; +#X msg 89 279 list $ 0 \$1_; +#X obj 54 344 zexy/makesymbol %s%s%s; +#X obj -2 210 t b a a a; +#X obj -5 386 pack f s s s; +#X msg -37 460 obj 0 \$1 bng 15 250 50 0 \$2 \$3 \$4 17 7 0 10 -262144 +-1 -1; +#X msg 132 483 obj 0 \$1 nbx 5 14 -1e+37 1e+37 0 0 \$2 \$3 \$4 57 7 +0 10 -262144 -1 -1 0 256; +#X msg 289 515 obj 0 \$1 hsl 100 15 \$5 \$6 0 0 \$2 \$3 \$4 105 7 0 +10 -262144 -1 -1 0 1; +#X msg 528 476 obj 0 \$1 tgl 15 0 \$2 \$3 \$4 17 7 0 10 -262144 -1 -1 0 1; -#X connect 1 0 7 0; -#X connect 1 1 24 0; -#X connect 3 0 25 0; -#X connect 4 0 30 0; -#X connect 6 0 9 0; -#X connect 7 0 8 0; -#X connect 7 1 6 0; -#X connect 8 0 3 0; -#X connect 9 0 8 1; -#X connect 9 1 19 0; -#X connect 10 0 2 0; -#X connect 12 0 2 0; -#X connect 13 0 1 0; -#X connect 14 0 15 0; -#X connect 15 0 28 0; -#X connect 15 1 16 0; -#X connect 16 0 17 0; -#X connect 17 0 18 0; -#X connect 17 1 29 0; -#X connect 17 2 20 0; -#X connect 17 3 21 0; +#X msg 521 448 symbolatom 0 \$1 17 0 0 1 \$4 \$3 \$2; +#X msg 496 89 clear \, text 0 0 YOU MUST COPY AND PASTE THE FOLLOWING +INTERFACES INSIDE THE ROOT PATCH OR INSIDE A SUBPATCH OF THE ROOT PATCH +OR THEY WILL NOT WORK!; +#X msg 419 159 50; +#X connect 1 0 27 0; +#X connect 1 1 16 0; +#X connect 3 0 17 0; +#X connect 4 0 21 0; +#X connect 4 0 20 0; +#X connect 6 0 7 0; +#X connect 7 0 28 0; +#X connect 7 1 15 0; +#X connect 9 0 1 0; +#X connect 10 0 11 0; +#X connect 11 0 19 0; +#X connect 11 1 12 0; +#X connect 12 0 13 0; +#X connect 13 0 14 0; +#X connect 13 1 22 0; +#X connect 13 2 35 0; +#X connect 13 3 34 0; +#X connect 14 0 2 0; +#X connect 15 0 6 0; +#X connect 16 0 3 1; +#X connect 16 1 17 1; +#X connect 17 0 4 0; #X connect 18 0 2 0; -#X connect 19 0 6 0; -#X connect 20 0 5 0; -#X connect 21 0 11 0; -#X connect 22 0 11 0; -#X connect 23 0 2 0; -#X connect 24 0 3 1; -#X connect 24 1 25 1; -#X connect 25 0 4 0; -#X connect 26 0 2 0; -#X connect 27 0 2 0; -#X connect 28 0 17 0; -#X connect 29 0 13 0; -#X connect 30 0 10 0; -#X connect 30 1 12 0; -#X connect 30 2 23 0; -#X connect 30 3 27 0; -#X connect 30 4 31 0; -#X connect 30 5 26 0; +#X connect 19 0 13 0; +#X connect 20 0 29 0; +#X connect 20 1 30 0; +#X connect 20 2 31 0; +#X connect 20 3 33 0; +#X connect 20 4 32 0; +#X connect 20 5 18 0; +#X connect 22 0 9 0; +#X connect 23 0 28 1; +#X connect 24 0 23 0; +#X connect 25 0 26 0; +#X connect 26 0 28 2; +#X connect 27 0 6 0; +#X connect 27 1 24 0; +#X connect 27 2 25 0; +#X connect 27 3 28 3; +#X connect 28 0 3 0; +#X connect 29 0 2 0; +#X connect 30 0 2 0; #X connect 31 0 2 0; +#X connect 32 0 2 0; +#X connect 33 0 2 0; +#X connect 34 0 8 0; +#X connect 35 0 5 0; diff --git a/test/paramRoute.c b/test/paramRoute.c index 780dfed..4e4f756 100644 --- a/test/paramRoute.c +++ b/test/paramRoute.c @@ -31,17 +31,17 @@ static t_class *paramRoute_class; typedef struct _paramRoute { t_object x_obj; - t_symbol *basepath; + t_symbol *path; t_outlet *x_outlet; t_symbol *s_save; t_symbol *s_load; t_symbol* s_empty; t_canvas* canvas; - t_symbol* id; + t_symbol* root; } t_paramRoute; - +/* static t_symbol* paramRoute_makefilename( t_symbol *basename, t_float n) { @@ -75,7 +75,7 @@ static t_symbol* paramRoute_makefilename( t_symbol *basename, t_float n) { post("File name:%s",filename->s_name); return filename; } - +*/ static void paramRoute_anything(t_paramRoute *x, t_symbol *s, int ac, t_atom *av) { //I DEACTIVATED THE SAVE & LOAD FEATURES UNTIL I BETTER DEFINE PARAMROUTE'S STATE SAVING @@ -104,18 +104,21 @@ static void paramRoute_anything(t_paramRoute *x, t_symbol *s, int ac, t_atom *av } else { // Try to send if (ac) { - int sendBufLength = strlen(x->basepath->s_name) + strlen(s->s_name) + 1; - char *sendBuf = (char*)getbytes((sendBufLength)*sizeof(char)); + //int sendBufLength = strlen(x->path->s_name) + strlen(s->s_name) + 1; + //char *sendBuf = (char*)getbytes((sendBufLength)*sizeof(char)); - strcpy(sendBuf, x->basepath->s_name); - strcat(sendBuf, s->s_name); - t_symbol* target = gensym(sendBuf); - freebytes(sendBuf, (sendBufLength)*sizeof(char)); - + strcpy(param_buf_temp_a, x->root->s_name); + strcpy(param_buf_temp_b, x->path->s_name); + strcat(param_buf_temp_b, s->s_name); + t_symbol* path = gensym(param_buf_temp_b); + strcat(param_buf_temp_a, param_buf_temp_b); + t_symbol* target = gensym(param_buf_temp_a); + //freebytes(sendBuf, (sendBufLength)*sizeof(char)); + //post("target:%s",target->s_name); if (target->s_thing) { - if (target->s_thing) pd_forwardmess(target->s_thing, ac, av); + pd_forwardmess(target->s_thing, ac, av); } else { - outlet_anything(x->x_outlet,s,ac,av); + outlet_anything(x->x_outlet,path,ac,av); } } @@ -138,12 +141,6 @@ static void *paramRoute_new(t_symbol *s, int ac, t_atom *av) { x->s_load = gensym("load"); x->s_empty = gensym(""); - // String variables - char *separator = "/"; - char sbuf_name[MAXPDSTRING]; - char sbuf_temp[MAXPDSTRING]; - sbuf_name[0] = '\0'; - sbuf_temp[0] = '\0'; // GET THE CURRENT CANVAS t_canvas *canvas=tof_get_canvas(); @@ -151,14 +148,10 @@ static void *paramRoute_new(t_symbol *s, int ac, t_atom *av) { // Get the root canvas x->canvas = tof_get_root_canvas(canvas); - struct param_build_info build_info; - get_param_build_info(canvas,ac,av,&build_info,0); - - //param_get_id_stuff(canvas,sbuf_name, sbuf_temp, &(x->x_saveable)); - x->id = build_info.id; - x->basepath = build_info.basepath; - //if (x->basepath) post("PARAMROUTE BASEPATH: %s",x->basepath->s_name); - //if (x->id) post("PARAMROUTE ID: %s",x->id->s_name); + x->root = tof_get_dollarzero(x->canvas); + + x->path = param_get_path(canvas,NULL); + // INLETS AND OUTLETS x->x_outlet = outlet_new(&x->x_obj, &s_list); return (x); -- cgit v1.2.1