diff options
author | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-10-26 20:32:27 +0000 |
---|---|---|
committer | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-10-26 20:32:27 +0000 |
commit | 7541b9f1ba232dce4aceb41115c17292bd7298f4 (patch) | |
tree | b4dde0f6f22577896bdaaa4fa698e987491098e6 | |
parent | d6e37fa5490c8e3465eb4e92a0f9d9a60d3dbc4b (diff) |
Delocalized param
svn path=/trunk/externals/tof/; revision=12679
-rw-r--r-- | help/param-help.pd | 46 | ||||
-rw-r--r-- | src/param.c | 25 | ||||
-rw-r--r-- | src/param.h | 2 | ||||
-rw-r--r-- | src/paramCustom.h | 26 | ||||
-rw-r--r-- | src/paramFile.h | 82 | ||||
-rw-r--r-- | src/paramGui.h | 30 | ||||
-rw-r--r-- | src/paramRoute.h | 53 |
7 files changed, 166 insertions, 98 deletions
diff --git a/help/param-help.pd b/help/param-help.pd index 264c69b..4624ca8 100644 --- a/help/param-help.pd +++ b/help/param-help.pd @@ -1,4 +1,4 @@ -#N canvas 139 45 722 412 10; +#N canvas 98 175 722 412 10; #X obj -23 2 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 0; #X text -18 54 author: mrtoftrash@gmail.com; @@ -10,37 +10,24 @@ system.; :); #X floatatom 144 229 5 0 0 0 - - -; #X obj 136 351 dac~; -#X obj 387 263 hsl 100 15 0 1 0 0 \$0/FM_MOD/volume \$0/FM_MOD/volume_ -/FM_MOD/volume 105 7 0 10 -262144 -1 -1 0 1; -#X obj 387 283 hsl 100 15 200 2000 0 0 \$0/FM_MOD/carrier \$0/FM_MOD/carrier_ -/FM_MOD/carrier 105 7 0 10 -262144 -1 -1 2200 1; -#X obj 385 322 nbx 5 14 -1e+37 1e+37 0 0 \$0/FM_MOD/modulation/index -\$0/FM_MOD/modulation/index_ /FM_MOD/modulation/index 57 7 0 10 -262144 --1 -1 20 256; -#X obj 385 303 nbx 5 14 -1e+37 1e+37 0 0 \$0/FM_MOD/modulation/freq -\$0/FM_MOD/modulation/freq_ /FM_MOD/modulation/freq 57 7 0 10 -262144 --1 -1 3 256; #X obj 184 275 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 --1 -1 0 1; +-1 -1 9400 1; #X msg 144 251 /modulation/index \$1; #X msg 181 297 /volume \$1; -#X obj 144 322 ./param-abs /id FM_MOD /carrier 600; #N canvas 237 177 542 366 [param 0; #X text 210 53 argument 1: param name (must start with a slash); #X obj 21 56 tof/param /my_name my_value; #X text 210 70 argument 2...: param value (can be anything; #X text 210 86 argument ...: special keywords; -#X text 85 303 (\$0)/abstraction's name/.../param's name; -#X text 22 158 If the param object is created directly in the root -patch (as the my_name example above) \, its path is as follows:; #X text 24 120 A param object creates a storage area for anything. This data can be accessed through a unique symbolic path.; -#X text 77 193 (\$0)/param's name; #X text 24 227 If the param is inside an abstraction (or inside an abstraction contained inside another abstraction an so forth) \, the path starts at the root and follows every child patch (abstraction) until it reaches the param object \, at which point the param's name is appended:; +#X text 85 303 /abstraction's name/.../param's name; +#X text 147 171 /my_name; #X restore -16 164 pd [param /name]; #N canvas 0 0 975 555 keywords 0; #X text 565 152 nbx: creates a numberbox; @@ -125,7 +112,7 @@ that path.; #X connect 7 0 0 0; #X connect 9 0 7 0; #X restore -16 235 pd [param dump]; -#N canvas 0 0 637 377 [param 0; +#N canvas 288 382 637 377 [param 0; #X obj 336 180 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 -1 0; #X obj 392 230 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 @@ -191,9 +178,20 @@ name \, will be used to build the path.; #X connect 2 0 4 0; #X connect 3 0 2 0; #X restore -16 210 pd [param path]; -#X connect 6 0 13 0; -#X connect 12 0 14 0; -#X connect 13 0 15 0; -#X connect 14 0 15 0; -#X connect 15 0 7 0; -#X connect 15 0 7 1; +#X obj 144 322 ./param-abs /id FM_MOD /carrier 600; +#X obj 404 243 cnv 15 200 20 empty empty /FM_MOD/ 2 12 0 8 -258401 +-262144 0; +#X obj 404 266 nbx 5 14 -1e+37 1e+37 0 0 /FM_MOD/modulation/freq /FM_MOD/modulation/freq_ +modulation/freq 50 8 0 8 -262144 -1 -1 0 256; +#X obj 404 284 nbx 5 14 -1e+37 1e+37 0 0 /FM_MOD/modulation/index /FM_MOD/modulation/index_ +modulation/index 50 8 0 8 -262144 -1 -1 0 256; +#X obj 404 302 hsl 100 15 0 1 0 0 /FM_MOD/volume /FM_MOD/volume_ volume +105 7 0 8 -262144 -1 -1 7328 1; +#X obj 404 320 hsl 100 15 200 2000 0 0 /FM_MOD/carrier /FM_MOD/carrier_ +carrier 105 7 0 8 -262144 -1 -1 6200 1; +#X connect 6 0 9 0; +#X connect 8 0 10 0; +#X connect 9 0 20 0; +#X connect 10 0 20 0; +#X connect 20 0 7 0; +#X connect 20 0 7 1; diff --git a/src/param.c b/src/param.c index ae1f0c2..fc2daf0 100644 --- a/src/param.c +++ b/src/param.c @@ -19,6 +19,9 @@ * MA 02110-1301, USA. */ +//#define PARAMDEBUG +//#define LOCAL + #include "param.h" #include "paramCustom.h" #include "paramDump.h" @@ -262,7 +265,10 @@ static void* paramClass_new(t_symbol *s, int ac, t_atom *av) int l = strlen(path->s_name) + strlen(root->s_name) + 2; char* receiver = getbytes( l * sizeof(*receiver)); + receiver[0]='\0'; + #ifdef LOCAL strcat(receiver,root->s_name); + #endif strcat(receiver,path->s_name); x->receive = gensym(receiver); strcat(receiver,"_"); @@ -310,17 +316,18 @@ static void* param_new(t_symbol *s, int argc, t_atom *argv) { //post("RUNNING COMMON NEW"); - t_pd* x; + t_pd* x = NULL; if ( !argc || argv[0].a_type == A_FLOAT ) { x = NULL; } else { - t_symbol *s2 = argv[0].a_w.w_symbol; + t_symbol *s2 = argv[0].a_w.w_symbol; - //post("Loading: %s",s2->s_name); - - if (s2 == gensym("custom")) + //post("Loading: %s",s2->s_name); + if ( s2->s_name[0] == '/' ) + x = paramClass_new(s, argc, argv); + else if (s2 == gensym("custom")) x = paramCustom_new(s, argc-1, argv+1); else if (s2 == gensym("dump")) x = paramDump_new(s, argc-1, argv+1); @@ -333,11 +340,11 @@ static void* param_new(t_symbol *s, int argc, t_atom *argv) { else if (s2 == gensym("gui")) x = paramGui_new(s, argc-1, argv+1); else - x = paramClass_new(s, argc, argv); + post("Param is missing an argument. Possible values: custom, dump, file, path, route, gui or a /name."); } + /* if ( x == NULL) { - post("Param is missing a symbolic argument. Possible values: custom, dump, file, path, route, gui or a /name."); - //post(" custom"); + //post(" custom"); //dump file id route gui or a /\"name\" //post("- dump"); //post("- file"); @@ -346,7 +353,7 @@ static void* param_new(t_symbol *s, int argc, t_atom *argv) { //post("- gui"); //post("- or a /name."); } - + */ return (x); } diff --git a/src/param.h b/src/param.h index 1c0b3a5..46daca6 100644 --- a/src/param.h +++ b/src/param.h @@ -2,7 +2,7 @@ #include <stdio.h> #include <fcntl.h> -//#define PARAMDEBUG + typedef void (*t_paramGetMethod)(void*,t_symbol**,int*,t_atom**); typedef void (*t_paramSaveMethod)(void*,t_binbuf*,int); diff --git a/src/paramCustom.h b/src/paramCustom.h index 3d3f979..db1e66e 100644 --- a/src/paramCustom.h +++ b/src/paramCustom.h @@ -10,7 +10,7 @@ typedef struct _paramCustom { t_outlet* outlet; t_outlet* outlet2; t_binbuf* bb; - t_symbol* receive; + //t_symbol* receive; struct _paramCustom_receive* r; int nopresets; } t_paramCustom; @@ -66,7 +66,7 @@ static void paramCustom_anything(t_paramCustom *x, t_symbol *selector, int argc, static void paramCustom_free(t_paramCustom *x) { - if (x->receive) pd_unbind(&x->r->x_obj.ob_pd, x->receive); + //if (x->receive) pd_unbind(&x->r->x_obj.ob_pd, x->receive); if (x->param) param_unregister(x->param); @@ -83,8 +83,9 @@ static void paramClass_get(t_paramClass *x, t_symbol** s, int* ac, t_atom** av) */ // SPECIAL PARAM SAVE FUNCTION -static void paramCustom_save(t_paramCustom *x, t_binbuf* bb, int f) { +static void paramCustom_save(t_paramCustom_receive *r, t_binbuf* bb, int f) { + t_paramCustom* x = r->owner; // f = -1 for the main save file // f => 0 if it is a preset if ( f >= 0 && x->nopresets) return; @@ -134,9 +135,15 @@ static void* paramCustom_new(t_symbol *s, int ac, t_atom *av) // FIND THE NO PRESET TAG: /nps x->nopresets = tof_find_symbol(gensym("/nps"), ac-1, av+1); + // Set up param 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 ); - x->param = param_register(x,root,path, NULL,\ + x->param = param_register(r,root,path, NULL,\ (t_paramSaveMethod) paramCustom_save,NULL); if (!x->param) return NULL; @@ -147,9 +154,8 @@ static void* paramCustom_new(t_symbol *s, int ac, t_atom *av) 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); + //x->receive = gensym(receiver); + freebytes(receiver, l * sizeof(*receiver)); #ifdef PARAMDEBUG @@ -161,13 +167,7 @@ static void* paramCustom_new(t_symbol *s, int ac, t_atom *av) 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 ); diff --git a/src/paramFile.h b/src/paramFile.h index 42d568b..66d016c 100644 --- a/src/paramFile.h +++ b/src/paramFile.h @@ -100,56 +100,69 @@ static void paramFile_do_load(t_paramFile* x, t_float f) { t_symbol* filename = paramFile_makefilename(x,f); post("Reading: %s",filename->s_name); - int r_error; - //t_symbol* filename = param_makefilename(basename, n); + t_symbol* root = x->root; + + t_param* pp = get_param_list(root); + t_param* p; + + if (pp) { + int r_error; t_binbuf *bbuf = binbuf_new(); r_error= (binbuf_read_via_canvas(bbuf, filename->s_name, x->canvas, 0)); - //pd_error(x, "%s: read failed", filename->s_name); - - t_symbol* root = x->root; - + int bb_ac = binbuf_getnatom(bbuf); int ac = 0; t_atom *bb_av = binbuf_getvec(bbuf); t_atom *av = bb_av; + t_symbol* s; + while (bb_ac--) { if (bb_av->a_type == A_SEMI) { if ( IS_A_SYMBOL(av,0) && ac > 1) { + /* + #ifdef LOCAL 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 + t_symbol* s = gensym(param_buf_temp_a); + #else + t_symbol* s = atom_getsymbol(av); + #endif + */ + s = atom_getsymbol(av); + p = pp; + while(p && p->path != s) p=p->next; - // STUPID SYMBOL WITH SPACES MANAGEMENT - if ( s->s_thing && ac > 3 && IS_A_SYMBOL(av,1) && atom_getsymbol(av+1) == &s_symbol) { - // This whole block is simply to convert symbols saved with spaces to complete symbols - - t_binbuf *bbuf_stupid = binbuf_new(); - binbuf_add(bbuf_stupid, ac-2, av+2); - - char *char_buf; - int char_length; - binbuf_gettext(bbuf_stupid, &char_buf, &char_length); - char_buf = resizebytes(char_buf, char_length, char_length+1); - char_buf[char_length] = 0; - t_symbol* stupid_symbol = gensym(char_buf); - //post("STUPID: %s",stupid_symbol->s_name); - freebytes(char_buf, char_length+1); - binbuf_free(bbuf_stupid); - t_atom* stupid_atom = getbytes(sizeof(*stupid_atom)); - SETSYMBOL(stupid_atom, stupid_symbol); - pd_typedmess(s->s_thing, &s_symbol, 1, stupid_atom); - freebytes(stupid_atom, sizeof(*stupid_atom)); - - } else { - if ( s->s_thing) pd_forwardmess(s->s_thing, ac-1, av+1); + + if (p) { + if ( ac > 3 && IS_A_SYMBOL(av,1) && atom_getsymbol(av+1) == &s_symbol) { + // STUPID MANAGEMENT OF SYMBOLS WITH SPACES + // This whole block is simply to convert symbols saved with spaces to complete symbols + + t_binbuf *bbuf_stupid = binbuf_new(); + binbuf_add(bbuf_stupid, ac-2, av+2); + + char *char_buf; + int char_length; + binbuf_gettext(bbuf_stupid, &char_buf, &char_length); + char_buf = resizebytes(char_buf, char_length, char_length+1); + char_buf[char_length] = 0; + t_symbol* stupid_symbol = gensym(char_buf); + //post("STUPID: %s",stupid_symbol->s_name); + freebytes(char_buf, char_length+1); + binbuf_free(bbuf_stupid); + t_atom* stupid_atom = getbytes(sizeof(*stupid_atom)); + SETSYMBOL(stupid_atom, stupid_symbol); + pd_typedmess(p->x, &s_symbol, 1, stupid_atom); + freebytes(stupid_atom, sizeof(*stupid_atom)); + + } else { + pd_forwardmess(p->x, ac-1, av+1); + } } } @@ -165,6 +178,9 @@ static void paramFile_do_load(t_paramFile* x, t_float f) { binbuf_free(bbuf); if ( r_error) pd_error(x, "%s: read failed", filename->s_name); + } + + x->working = 0; diff --git a/src/paramGui.h b/src/paramGui.h index 0a6e918..ecac8f1 100644 --- a/src/paramGui.h +++ b/src/paramGui.h @@ -31,6 +31,7 @@ typedef struct _paramGui t_symbol* s_symbolatom; t_symbol* s_sym; t_symbol* s_text; + t_symbol* s_cnv; //t_symbol* target; //t_class* empty_s; @@ -49,10 +50,33 @@ static void paramGui_bang(t_paramGui *x) { // Clear the canvas pd_typedmess((t_pd*)x->childcanvas,x->s_clear,0,NULL); + + int pos_x = 0; int pos_y = 0; t_atom atoms[22]; // This should be the maximum number of atoms + // PINK HEADER + SETSYMBOL(&atoms[0],x->s_obj); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],x->s_cnv); + SETFLOAT(&atoms[4],15); + SETFLOAT(&atoms[5],200); + SETFLOAT(&atoms[6],20); + SETSYMBOL(&atoms[7],x->s_empty); + SETSYMBOL(&atoms[8],x->s_empty); + SETSYMBOL(&atoms[9],x->path); + SETFLOAT(&atoms[10],2); + SETFLOAT(&atoms[11],12); + SETFLOAT(&atoms[12],0); + SETFLOAT(&atoms[13],8); + SETFLOAT(&atoms[14],-258401); + SETFLOAT(&atoms[15],-262144); + SETFLOAT(&atoms[16],0); + pd_forwardmess((t_pd*)x->childcanvas, 17, atoms); + pos_y = pos_y + 23; + t_param* p = get_param_list(x->root); int ac; t_atom* av; @@ -71,6 +95,8 @@ static void paramGui_bang(t_paramGui *x) { t_atom* av_got; t_symbol* s_got; + + while (p) { gui_built = 1; if (p->GUI && (strncmp(p->path->s_name,x->path->s_name,x->path_l)==0)) { @@ -103,6 +129,9 @@ static void paramGui_bang(t_paramGui *x) { shortpath = gensym(p->path->s_name + x->path_l); } + + + type = atom_getsymbol(av); if ( type == x->s_nbx ) { SETSYMBOL(&atoms[0],x->s_obj); @@ -302,6 +331,7 @@ static void *paramGui_new(t_symbol *s, int ac, t_atom *av) { x->s_symbolatom = gensym("symbolatom"); x->s_sym = gensym("sym"); x->s_text = gensym("text"); + x->s_cnv = gensym("cnv"); diff --git a/src/paramRoute.h b/src/paramRoute.h index b5d862f..c336367 100644 --- a/src/paramRoute.h +++ b/src/paramRoute.h @@ -12,32 +12,47 @@ typedef struct _paramRoute t_symbol* s_empty; t_canvas* canvas; t_symbol* root; - + t_symbol* previousSymbol; + t_symbol* target; } t_paramRoute; static void paramRoute_anything(t_paramRoute *x, t_symbol *s, int ac, t_atom *av) { + t_param* p = get_param_list(x->root); - // t_symbol* path; - t_symbol* target; - if (ac) { - if ( s->s_name[0] == '/' && strlen(s->s_name) > 1) { - 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+1); - //path = gensym(param_buf_temp_b); - strcat(param_buf_temp_a, param_buf_temp_b); - target = gensym(param_buf_temp_a); - - if (target->s_thing) { - pd_forwardmess(target->s_thing, ac, av); - } else { - outlet_anything(x->x_outlet,s,ac,av); - } + if ( p != NULL && s->s_name[0] == '/' && strlen(s->s_name) > 1) { + + + + + if (x->previousSymbol != s) { + param_buf_temp_a[0] = '\0'; + #ifdef LOCAL + strcpy(param_buf_temp_a, x->root->s_name); + strcat(param_buf_temp_a, x->path->s_name); + strcat(param_buf_temp_b, s->s_name+1); + //strcat(param_buf_temp_a, param_buf_temp_b); + x->target = gensym(param_buf_temp_a); + #else + strcpy(param_buf_temp_a, x->path->s_name); + strcat(param_buf_temp_a, s->s_name+1); + x->target = gensym(param_buf_temp_a); + #endif + x->previousSymbol = s; + } + + while (p && p->path != x->target) p=p->next; + + if (p) { + pd_forwardmess(p->x, ac, av); + } else { + outlet_anything(x->x_outlet,s,ac,av); + } + + } else { outlet_anything(x->x_outlet,s,ac,av); } @@ -59,6 +74,8 @@ static void *paramRoute_new(t_symbol *s, int ac, t_atom *av) { x->s_load = gensym("load"); x->s_empty = gensym(""); + x->target = NULL; + x->previousSymbol = NULL; // GET THE CURRENT CANVAS t_canvas *canvas=tof_get_canvas(); |