diff options
-rw-r--r-- | test/Makefile | 31 | ||||
-rw-r--r-- | test/OSCToParam-help.pd | 12 | ||||
-rw-r--r-- | test/OSCToParam.pd | 4 | ||||
-rw-r--r-- | test/param-help.pd | 103 | ||||
-rw-r--r-- | test/param.c | 197 | ||||
-rw-r--r-- | test/param.h | 538 | ||||
-rw-r--r-- | test/paramDump.c | 147 | ||||
-rw-r--r-- | test/paramFile-help.pd | 59 | ||||
-rw-r--r-- | test/paramFile.c | 153 | ||||
-rw-r--r-- | test/paramFile.pd | 45 | ||||
-rw-r--r-- | test/paramGui.pd | 95 | ||||
-rw-r--r-- | test/paramRoute.c | 174 |
12 files changed, 1558 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..8b83adb --- /dev/null +++ b/test/Makefile @@ -0,0 +1,31 @@ +PARAM: param paramDump paramRoute paramFile
+
+current:
+ echo make pd_linux
+
+clean:
+ rm -f *.pd_linux *.o
+
+# ----------------------- LINUX i386 -----------------------
+
+#paramL: param.pd_linux
+
+#patchArguments: patchArguments.pd_linux
+
+.SUFFIXES: .pd_linux
+
+PDPATH = /home/tom/src/pure-data/pd
+
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXINCLUDE = -I$(PDPATH)/src
+
+#.pd_linux: .c
+
+.c:
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ ld --export-dynamic -shared -o $*.pd_linux $*.o -lc -lm
+ strip --strip-unneeded $*.pd_linux
+ rm $*.o
diff --git a/test/OSCToParam-help.pd b/test/OSCToParam-help.pd new file mode 100644 index 0000000..30468a0 --- /dev/null +++ b/test/OSCToParam-help.pd @@ -0,0 +1,12 @@ +#N canvas 1298 247 515 325 10; +#X obj -8 -53 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text -3 -9 author: mrtoftrash@gmail.com; +#X text -3 2 version: 2009-04-14 (initial release); +#X text -3 13 arguments: @; +#X text -3 -54 description: forwards all incomming OSC messages to +matching params.; +#X obj -3 82 OSCToParam 3475; +#X text 97 71 All OSC messages received on port 3475 will be forwarded +to matching params.; +#X text -3 -20 tags: routing param OSC; diff --git a/test/OSCToParam.pd b/test/OSCToParam.pd new file mode 100644 index 0000000..f06e117 --- /dev/null +++ b/test/OSCToParam.pd @@ -0,0 +1,4 @@ +#N canvas 452 316 450 300 10; +#X obj 88 46 oscx/dumpOSC \$1; +#X obj 89 149 maxlib/remote; +#X connect 0 0 1 0; diff --git a/test/param-help.pd b/test/param-help.pd new file mode 100644 index 0000000..246fdd8 --- /dev/null +++ b/test/param-help.pd @@ -0,0 +1,103 @@ +#N canvas 1027 43 1018 689 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; +#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; +#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; +#X floatatom 52 304 5 0 0 0 - - -; +#X msg 52 334 /OSC1/freq \$1; +#X obj 387 187 spigot; +#X obj -23 22 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text -18 74 author: mrtoftrash@gmail.com; +#X text -19 95 version: 2009-04-14 (initial release); +#X obj 480 172 tgl 15 0 empty empty listen 17 7 0 10 -262144 -1 -1 +0 1; +#X text -18 21 description: param is a state saving and message routing +system.; +#X obj 387 160 receive PARAM; +#X text 544 140 -- listening stream --; +#X text 586 266 -- saving and loading --; +#X text 11 248 Open the properties dialog of the above gui objects +to examine how they are linked to the abstraction below.; +#X floatatom 73 453 5 0 0 0 - - -; +#X obj 52 475 *~ 0; +#X obj 73 401 loadbang; +#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; +#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 +PARAM messages. Enable(click) the "listen" toggle then change the value +of some the example's sliders or number boxes to print out this stream. +; +#X text 531 461 -- implementing params in your own abstractions -- +; +#X text 606 508 -- default values --; +#X text 528 433 DOCUMENTATION TODO:; +#X obj 685 598 paramDump; +#X obj 685 571 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X obj 685 626 print; +#X text 121 553 -- linking with OSC and MIDI --; +#X text -19 53 tags: state routing gui; +#X msg 771 560 values /wow; +#X msg 772 584 values /; +#X msg 802 509 values *; +#X msg 586 595 ------; +#X msg 797 617 guis *; +#X msg 801 643 guis /; +#X obj 492 528 paramGui; +#X floatatom 180 404 5 0 0 0 - - -; +#X obj 581 61 ./examples/param-generator /id me; +#X obj 492 497 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#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 connect 6 0 7 0; +#X connect 7 0 52 0; +#X connect 8 0 5 0; +#X connect 12 0 8 1; +#X connect 14 0 8 0; +#X connect 18 0 19 1; +#X connect 19 0 0 0; +#X connect 19 0 0 1; +#X connect 20 0 44 0; +#X connect 29 0 31 0; +#X connect 30 0 29 0; +#X connect 34 0 29 0; +#X connect 35 0 29 0; +#X connect 36 0 29 0; +#X connect 37 0 31 0; +#X connect 38 0 29 0; +#X connect 39 0 29 0; +#X connect 41 0 44 0; +#X connect 43 0 40 0; +#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; diff --git a/test/param.c b/test/param.c new file mode 100644 index 0000000..576379f --- /dev/null +++ b/test/param.c @@ -0,0 +1,197 @@ +/* + * param.c + * + * Copyright 2009 Thomas O Fredericks <tom@hp> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + + +#include "tof.h" +#include "param.h" + + + + +static t_class *param_class; +static t_class *param_inlet2_class; +struct _param_inlet2; + +typedef struct _param +{ + t_object x_obj; + struct _param_inlet2 *x_param_inlet2; + + t_symbol *x_path; + t_symbol *s_PARAM; + t_symbol *x_update_gui; + t_symbol *s_set; + struct param *x_param; +} t_param; + +typedef struct _param_inlet2 +{ + t_object x_obj; + 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); + + 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 ); + +} + +static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av) +{ + + 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 ); + */ + +} + + + + +// SECOND INLET METHOD + +static void param_inlet2_anything(t_param_inlet2 *p, t_symbol *s, int ac, t_atom *av) +{ + + if ( p->p_owner->x_param ) set_param_anything(p->p_owner->x_param, s,ac,av); +} + +// DECONSTRUCTOR + +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); + +} + +// CONSTRUCTOR +static void *param_new(t_symbol *s, int ac, t_atom *av) +{ + t_param *x = (t_param *)pd_new(param_class); + t_param_inlet2 *p = (t_param_inlet2 *)pd_new(param_inlet2_class); + + // Stuff + x->s_set = gensym("set"); + x->s_PARAM = gensym("PARAM"); + + // Set up second inlet proxy + x->x_param_inlet2 = p; + p->p_owner = x; + + + 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 /"); + } + + + + return (x); +} + +void param_setup(void) +{ + param_class = class_new(gensym("param"), + (t_newmethod)param_new, (t_method)param_free, + sizeof(t_param), 0, A_GIMME, 0); + + + class_addanything(param_class, param_anything); + class_addbang(param_class, param_bang); + + param_inlet2_class = class_new(gensym("_param_inlet2"), + 0, 0, sizeof(t_param_inlet2), CLASS_PD | CLASS_NOINLET, 0); + + class_addanything(param_inlet2_class, param_inlet2_anything); + +} diff --git a/test/param.h b/test/param.h new file mode 100644 index 0000000..4230f8a --- /dev/null +++ b/test/param.h @@ -0,0 +1,538 @@ + +#include <stdio.h> + +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; +}; + + +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) { + + if ( s == &s_bang ) { + p->ac = 0; + p->selector = s; + } else { + if(ac > p->alloc) { + p->av = resizebytes(p->av, p->alloc*sizeof(*(p->av)), + (10 + ac)*sizeof(*(p->av))); + p->alloc = 10 + ac; + } + p->ac = ac; + p->selector = s; + tof_copy_atoms(av, p->av, ac); + } +} + + +static void set_param( struct param* p, int ac, t_atom *av) { + t_symbol* s; + tof_set_selector(&s,&ac, &av ); + set_param_anything(p,s,ac,av); +} + + + + + + +static struct param* get_param_list(void) { + + if (paramlist == NULL) { + //post("No params found"); + return NULL; + } + + return paramlist; + +} + +static void print_all_params(void) { + + struct param* p = paramlist; + post("--paramlist--"); + while(p) { + if ( p->path) post("Path: %s",p->path->s_name); + if (p->id) post("Id: %s",p->id->s_name); + p = p->next; + } + +} + + +//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) { + + //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; + + + //if ( path) post("path:%s",path->s_name); + //if ( id) post("id:%s",id->s_name); + + struct param* last = paramlist; + // Search for param with same path + while( last ) { + if ( last->path == path) { + //post("Found param with same name"); + last->users = last->users + 1; + return last; + } + if ( last->next == NULL ) break; + last = last->next; + } + + // Create and add param to the end + struct param* p = getbytes(sizeof(*p)); + p->alloc = 0; + p->path = path; + p->path_g = path_g; + p->next = NULL; + p->users = 1; + 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"); + p->previous = last; + last->next = p; + } else { + //post("Creating first param"); + p->previous = NULL; + paramlist = p; + } + + + //print_all_params(); + + return p; + +} + +static void unregister_param( struct param* p) { + + //post("unregistering %s", p->path->s_name); + + if ( paramlist) { + + p->users = p->users - 1; + if ( p->users == 0 ) { + // Remove param + //post("Removing last param of this name"); + if (p->previous) { + p->previous->next = p->next; + if (p->next) p->next->previous = p->previous; + /* + if (p->next == NULL) { + p->previous->next = NULL; + } else { + p->previous->next = p->next; + } + */ + } else { + paramlist = p->next; + if ( p->next != NULL) p->next->previous = NULL; + } + freebytes(p->av, p->alloc * sizeof *(p->av) ); + freebytes(p->av_g, p->ac_g * sizeof *(p->av_g) ); + freebytes(p, sizeof *p); + } + + } 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;i<ac;i++) { + //if ( IS_A_SYMBOL(av,i)) post("analyzing %s",atom_getsymbol(av+i)->s_name); + if ( IS_A_SYMBOL(av,i) && name == atom_getsymbol(av+i) && (i+1)<ac ) { + //post("matches"); + i=i+1; + for (j=i;j<ac;j++) { + if ( IS_A_SYMBOL(av,j) && (atom_getsymbol(av+j))->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; + pbi->path_g = NULL; + pbi->av = NULL; + int saveable = 1; + pbi->ac = 0; + pbi->id = NULL; + pbi->ac_g = 0; + pbi->av_g = NULL; + pbi->basepath = NULL; + pbi->basename = NULL; + + int ac; + t_atom* av; + tof_get_canvas_arguments(canvas,&ac, &av); + + char *separator = "/"; + char sbuf_name[MAXPDSTRING]; + char sbuf_temp[MAXPDSTRING]; + sbuf_name[0] = '\0'; + sbuf_temp[0] = '\0'; + + t_symbol* id = gensym("/id"); + t_canvas* id_canvas = canvas; + t_canvas* i_canvas = canvas; + + int i; + + int i_ac; + t_atom * i_av; + + // A simple flag to indicate if an ID was found + int found_id_flag; + + + 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 + if ( tof_canvas_is_not_subpatch(i_canvas) ) { + 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; + found_id_flag = 0; + + while( tof_get_tagged_argument('/',i_ac,i_av,&start,&count) ) { + + if ( IS_A_SYMBOL(i_av,start) + && (id == (i_av+start)->a_w.w_symbol) + && (count > 1) ) { + id_s = 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; + + + //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; + } + + if ( saveable ) { + + if ( id_s) { + + int id_buf_length = strlen(id_s->s_name)+2; + char * id_buf = getbytes(id_buf_length * sizeof (*id_buf)); + strcpy(id_buf, "/"); + strcat(id_buf,id_s->s_name); + pbi->id = gensym(id_buf); + freebytes(id_buf,id_buf_length * sizeof (*id_buf)); + } else { + pbi->id = gensym("/"); + } + + } + + pbi->basepath = gensym(sbuf_name); + + if (flag) { + + // FIND NAME + t_symbol* midpath = NULL; + //t_symbol* basename = NULL; + + if (o_ac && IS_A_SYMBOL(o_av, 0)) { + char *firstChar = (atom_getsymbol(o_av))->s_name; + if (*firstChar == (char)'/') { + strcat(sbuf_name, atom_getsymbol(o_av)->s_name); + pbi->path = gensym(sbuf_name); + strcat(sbuf_temp, atom_getsymbol(o_av)->s_name); + midpath = gensym(sbuf_temp); + strcat(sbuf_name, "_"); + pbi->path_g = gensym(sbuf_name); + pbi->basename = atom_getsymbol(o_av); + } + } + + // if ( x->x_param ) + + + if ( pbi->path) { + + + // FIND VALUE + // A. Find in SUB canvas arguments + // B. In canvas' arguments + // C. In object's arguments + // D. Defaults to a bang + + int p_ac =0; + t_atom* p_av; + + + // A. If name, try to find value in ID canvas' arguments + if ( midpath) { + // GET ID CANVAS ARGUMENTS (may be the same as the local canvas) + //int i_ac; + //t_atom * i_av; + tof_get_canvas_arguments(id_canvas,&i_ac , &i_av); + param_find_value(midpath, i_ac, i_av,&(pbi->ac),&(pbi->av)); + } + + // B. If basename, try to find value in LOCAL canvas' arguments + if ( pbi->basename && pbi->ac == 0 ) { + + param_find_value(pbi->basename, ac, av,&(pbi->ac),&(pbi->av)); + } + + + // C. If no value found in canvas' arguments, check the object's arguments + if ( pbi->ac == 0 && o_ac > 1) { + int start = 1; + int count = 0; + tof_get_tagged_argument('/',o_ac,o_av,&start,&count); + if (count > 0) { + pbi->ac = count; + pbi->av = o_av + start; + } + } + + //FIND THE GUI TAGS + param_find_value(gensym("/gui"), o_ac, o_av,&(pbi->ac_g),&(pbi->av_g)); + //post("GUI COUNT:%d",pbi->ac_g); + + } + +} +} + + +static void param_send_prepend(struct param *p, t_symbol* s,t_symbol* prepend) { + + if (p) { + if((p->selector == &s_bang)) { + // if (s->s_thing) + // pd_bang(s->s_thing); + } else { + if (s->s_thing) { + if ( p->selector == &s_list || p->selector == &s_float || p->selector == &s_symbol ) { + typedmess(s->s_thing, prepend, p->ac, p->av); + } else { + int ac = p->ac + 1; + t_atom *av = getbytes(ac*sizeof(*av)); + tof_copy_atoms(p->av,av+1,p->ac); + SETSYMBOL(av, p->selector); + typedmess(s->s_thing, prepend, ac, av); + freebytes(av, ac*sizeof(*av)); + } + } + } + } +} + +static void param_output(struct param *p, t_outlet* outlet) { + // SHOULD I COPY THIS DATA BEFORE SENDING IT OUT? + // OR IS THE NORM TO ONLY COPY ON INPUT? + if (p) { + if((p->selector == &s_bang) ) { + outlet_bang(outlet); + } else { + outlet_anything(outlet, p->selector, p->ac, p->av); + } + } +} + + +static void param_output_prepend(struct param* p, t_outlet* outlet, t_symbol* s) { + + if (p->selector == &s_list || p->selector == &s_float || p->selector == &s_symbol) { + //t_atom *av = (t_atom *)getbytes(p->ac*sizeof(t_atom)); + //tof_copy_atoms(p->av,av,p->ac); + outlet_anything(outlet,s,p->ac,p->av); + //freebytes(av, p->ac*sizeof(t_atom)); + } else if (p->selector != &s_bang) { + int ac = p->ac + 1; + t_atom *av = (t_atom *)getbytes(ac*sizeof(t_atom)); + tof_copy_atoms(p->av,av+1,p->ac); + SETSYMBOL(av, p->selector); + outlet_anything(outlet,s,ac,av); + freebytes(av, ac*sizeof(t_atom)); + } + +} + + + +static int param_write(t_canvas* canvas, t_symbol* filename, t_symbol* id) { + + int w_error; + + //t_symbol* filename = param_makefilename(basename, n); + + t_binbuf *bbuf = binbuf_new(); + + struct param *p = get_param_list(); + while(p) { + if ( p->id && ( id == NULL || p->id == id) && (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); + SETSYMBOL(av, p->path); + SETSYMBOL(av+1, p->selector); + binbuf_add(bbuf, ac, av); + binbuf_addsemi(bbuf); + + freebytes(av, ac*sizeof(*av)); + } + p = p->next; + } + + + char buf[MAXPDSTRING]; + canvas_makefilename(canvas, filename->s_name, + buf, MAXPDSTRING); + + + w_error = (binbuf_write(bbuf, buf, "", 0)); + //pd_error("%s: write failed", filename->s_name); + + binbuf_free(bbuf); + + return w_error; + +} + + +static int param_read(t_canvas* canvas, t_symbol* filename) +{ + + int r_error; + + //t_symbol* filename = param_makefilename(basename, n); + + t_binbuf *bbuf = binbuf_new(); + + r_error= (binbuf_read_via_canvas(bbuf, filename->s_name, canvas, 0)); + //pd_error(x, "%s: read failed", filename->s_name); + + + + int bb_ac = binbuf_getnatom(bbuf); + int ac = 0; + t_atom *bb_av = binbuf_getvec(bbuf); + t_atom *av = bb_av; + + while (bb_ac--) { + if (bb_av->a_type == A_SEMI) { + if ( IS_A_SYMBOL(av,0) && ac > 1) { + t_symbol* s = atom_getsymbol(av); + if ( s->s_thing) pd_forwardmess(s->s_thing, ac-1, av+1); + + + } + + ac = 0; + av = bb_av + 1; + } else { + + ac = ac + 1; + } + bb_av++; + } + + + binbuf_free(bbuf); + + return r_error; +} + + + + diff --git a/test/paramDump.c b/test/paramDump.c new file mode 100644 index 0000000..15921cd --- /dev/null +++ b/test/paramDump.c @@ -0,0 +1,147 @@ +/* + * paramDump.c + * + * Copyright 2009 Thomas O Fredericks <tom@hp> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include "tof.h" +#include "param.h" +#include <stdio.h> + + + +static t_class *paramDump_class; + + +typedef struct _paramDump +{ + t_object x_obj; + t_outlet* outlet; + t_symbol* s_set; +} 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); + + //if ( !(s == &s_list || s == &s_float) ) { + char* star = "*"; + int all = !(strcmp(s->s_name, star)); + + + struct param* pp = get_param_list(); + while (pp) { + if (pp->id && (all || pp->id == s) ) { + param_output_prepend(pp,x->outlet,pp->path); + + } + pp = pp->next; + } + //} +} + +static void paramDump_guis(t_paramDump *x, t_symbol* s) { + + char* star = "*"; + int all = !(strcmp(s->s_name, star)); + + struct param* pp = get_param_list(); + while (pp) { + if (pp->ac_g && (all || pp->id == s) ) { + + outlet_anything(x->outlet,pp->path,pp->ac_g,pp->av_g); + + } + pp = pp->next; + } +} + +static void paramDump_update_guis(t_paramDump *x, t_symbol* s) { + + char* star = "*"; + int all = !(strcmp(s->s_name, star)); + + struct param* pp = get_param_list(); + while (pp) { + if (pp->ac_g && (all || pp->id == s) ) { + + param_send_prepend(pp, pp->path_g ,x->s_set ); + //if ( pp->path_g->s_thing) + // pd_typedmess(pp->path_g->s_thing, pp->selector,pp->ac, pp->av); + + //outlet_anything(x->outlet,pp->path,pp->ac_g,pp->av_g); + + } + 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(); + while (pp) { + //if (pp->id) { + param_output_prepend(pp,x->outlet,pp->path); + + //} + pp = pp->next; + } + + +} + + + +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->s_set = gensym("set"); + + x->outlet = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +void paramDump_setup(void) { + paramDump_class = class_new(gensym("paramDump"), + (t_newmethod)paramDump_new, (t_method)paramDump_free, + sizeof(t_paramDump), 0, A_GIMME, 0); + + 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_guis, gensym("guis"), 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 new file mode 100644 index 0000000..fc635f8 --- /dev/null +++ b/test/paramFile-help.pd @@ -0,0 +1,59 @@ +#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 +-1 -1 0; +#X obj 499 354 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 +-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; diff --git a/test/paramFile.c b/test/paramFile.c new file mode 100644 index 0000000..7302bbc --- /dev/null +++ b/test/paramFile.c @@ -0,0 +1,153 @@ + +#include "tof.h" +#include "param.h" +#include <stdio.h> +#include <fcntl.h> + + + +static t_class *paramFile_class; +static t_class *paramFile_inlet2_class; +struct _paramFile_inlet2; + +typedef struct _paramFile +{ + t_object x_obj; + //t_outlet *outlet; + t_canvas *canvas; + t_symbol *basename; + struct _paramFile_inlet2 *inlet2; +} t_paramFile; + +typedef struct _paramFile_inlet2 { + t_object x_obj; + t_paramFile *x; +} t_paramFile_inlet2; + + + +static t_symbol* paramFile_makefilename(t_symbol* basename, t_float f) { + + if (f < 0) f = 0; + if ( f > 127) f = 127; + + int i = (int) f; + int length = strlen(basename->s_name)+6; + char* buf = getbytes( length * sizeof (*buf)); + sprintf(buf,"%s%03d.p",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); + return filename; +} + + +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); + +} + + +static void paramFile_read(t_paramFile *x, t_float f) { + + + t_symbol* filename = paramFile_makefilename(x->basename,f); + + if (param_read(x->canvas, filename)) pd_error(x, "%s: read failed", filename->s_name); + + +} + + + +static void paramFile_bang(t_paramFile *x) { + + paramFile_write(x,0); +} + + +static void paramFile_float(t_paramFile *x, t_float f) { + + paramFile_write(x,f); + +} + +static void paramFile_inlet2_bang(t_paramFile_inlet2 *inlet2) { + + paramFile_read(inlet2->x,0); + +} + +static void paramFile_inlet2_float(t_paramFile_inlet2 *inlet2,t_float f) { + + paramFile_read(inlet2->x,f); + +} + +static void paramFile_free(t_paramFile *x) +{ + + if(x->inlet2) pd_free((t_pd *)x->inlet2); + + +} + + +static void* paramFile_new(t_symbol *s, int ac, t_atom *av) { + t_paramFile *x = (t_paramFile *)pd_new(paramFile_class); + t_paramFile_inlet2 *inlet2 = (t_paramFile_inlet2 *)pd_new(paramFile_inlet2_class); + + inlet2->x = x; + x->inlet2 = inlet2; + + t_canvas* canvas = tof_get_canvas(); + x->canvas = tof_get_root_canvas(canvas); + t_symbol* canvasname = tof_get_canvas_name(x->canvas); + + // remove the .pd (actually removes everything after the .) + int length = strlen(canvasname->s_name) + 1; + char* buf = getbytes( (length ) * sizeof (*buf)); + strcpy(buf,canvasname->s_name); + char* lastperiod = strrchr(buf,'.'); + if ( lastperiod != NULL ) { + *lastperiod = '\0'; + x->basename = gensym(buf); + } else { + x->basename = canvasname; + } + freebytes(buf, (length ) * sizeof (*buf)); + + //x->outlet = outlet_new(&x->x_obj, &s_list); + + inlet_new((t_object *)x, (t_pd *)inlet2, 0, 0); + + return (x); + +} + + +void paramFile_setup(void) { + paramFile_class = class_new(gensym("paramFile"), + (t_newmethod)paramFile_new, (t_method)paramFile_free, + sizeof(t_paramFile), 0, A_GIMME, 0); + + class_addbang(paramFile_class, paramFile_bang); + class_addfloat(paramFile_class, paramFile_float); + + paramFile_inlet2_class = class_new(gensym("paramFile_inlet2"), + 0, 0, sizeof(t_paramFile_inlet2), CLASS_PD | CLASS_NOINLET, 0); + + class_addbang(paramFile_inlet2_class, paramFile_inlet2_bang); + class_addfloat(paramFile_inlet2_class, paramFile_inlet2_float); + + class_addmethod(paramFile_class, (t_method) paramFile_read, gensym("load"), A_DEFFLOAT,0); + class_addmethod(paramFile_class, (t_method) paramFile_write, gensym("save"), A_DEFFLOAT,0); + +} + + diff --git a/test/paramFile.pd b/test/paramFile.pd new file mode 100644 index 0000000..7142b6b --- /dev/null +++ b/test/paramFile.pd @@ -0,0 +1,45 @@ +#N canvas 1115 286 849 405 10; +#X obj 151 128 paramDump; +#X obj 151 156 list prepend add; +#X obj 151 184 list trim; +#X msg 414 219 clear; +#X obj 132 80 t s b b; +#X obj -89 236 zexy/msgfile; +#X msg 81 128 write \$1; +#X obj -89 272 list trim; +#X obj -89 305 maxlib/remote; +#X obj -100 -19 route load save; +#X obj -100 -47 inlet; +#X msg -89 102 clear \, read \$1 \, flush; +#X obj 42 33 makefilename \$1%d.param; +#X obj -89 71 symbol \$1.param; +#X obj 195 50 symbol \$1.param; +#X obj 42 5 route float; +#X obj -152 21 route float; +#X obj -89 43 b; +#X obj 195 22 b; +#X obj -260 64 makefilename \$1%d.param; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 2 0 5 0; +#X connect 3 0 5 0; +#X connect 4 0 6 0; +#X connect 4 1 0 0; +#X connect 4 2 3 0; +#X connect 5 0 7 0; +#X connect 6 0 5 0; +#X connect 7 0 8 0; +#X connect 9 0 16 0; +#X connect 9 1 15 0; +#X connect 10 0 9 0; +#X connect 11 0 5 0; +#X connect 12 0 4 0; +#X connect 13 0 11 0; +#X connect 14 0 4 0; +#X connect 15 0 12 0; +#X connect 15 1 18 0; +#X connect 16 0 19 0; +#X connect 16 1 17 0; +#X connect 17 0 13 0; +#X connect 18 0 14 0; +#X connect 19 0 11 0; diff --git a/test/paramGui.pd b/test/paramGui.pd new file mode 100644 index 0000000..b98388c --- /dev/null +++ b/test/paramGui.pd @@ -0,0 +1,95 @@ +#N canvas 1027 19 997 713 10; +#N canvas 417 395 450 315 \$0target 1; +#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; +#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 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 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 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 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 +-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 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 31 0 2 0; diff --git a/test/paramRoute.c b/test/paramRoute.c new file mode 100644 index 0000000..780dfed --- /dev/null +++ b/test/paramRoute.c @@ -0,0 +1,174 @@ +/* + * paramRoute.c + * + * Copyright 2009 Thomas O Fredericks <tom@hp> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + + + +#include "tof.h" +#include "param.h" + + +static t_class *paramRoute_class; + +typedef struct _paramRoute +{ + t_object x_obj; + t_symbol *basepath; + t_outlet *x_outlet; + t_symbol *s_save; + t_symbol *s_load; + t_symbol* s_empty; + t_canvas* canvas; + t_symbol* id; + +} t_paramRoute; + + +static t_symbol* paramRoute_makefilename( t_symbol *basename, t_float n) { + + + + int d = (int) n; + int length = strlen(basename->s_name); + char* buf = getbytes( (length + 6) * sizeof (*buf)); + char* number = getbytes( 6 * sizeof (*number)); + + int i; + int j = 0; + for ( i=0; i< length; i++ ) { + if ( (basename->s_name)[i] != '/' ) { + buf[j] = (basename->s_name)[i]; + j++; + } + } + buf[j] = '\0'; + + if ( strlen(buf) == 0 ) { + sprintf(number,"p%03d",d); + } else { + sprintf(number,".p%03d",d); + } + + strcat(buf,number); + t_symbol* filename = gensym(buf); + freebytes(number, 6 * sizeof (*number)); + freebytes(buf, (length + 6) * sizeof (*buf)); + + 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 + + if (s == x->s_save) { // Save + + //~ if (x->id) { + //~ int n = 0; + //~ if ( ac ) n = atom_getfloat(av); + //~ t_symbol* filename = paramRoute_makefilename(x->id,n); + //~ if ( param_write(x->canvas,filename, x->id) ) + //~ pd_error("[paramRoute] could not write %s",filename->s_name); + //~ } else { + //~ pd_error(x,"[paramRoute] requires an /id"); + //~ } + } else if ( s == x->s_load) { // Load + //~ if (x->id) { + //~ int n = 0; + //~ if ( ac ) n = atom_getfloat(av); + //~ t_symbol* filename = paramRoute_makefilename(x->id,n); + //~ if ( param_read(x->canvas, paramRoute_makefilename(x->id,n)) ) + //~ pd_error("[paramRoute] could not read %s",filename->s_name);; + //~ } else { + //~ pd_error(x,"[paramRoute] requires an /id"); + //~ } + } 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)); + + strcpy(sendBuf, x->basepath->s_name); + strcat(sendBuf, s->s_name); + t_symbol* target = gensym(sendBuf); + freebytes(sendBuf, (sendBufLength)*sizeof(char)); + + if (target->s_thing) { + if (target->s_thing) pd_forwardmess(target->s_thing, ac, av); + } else { + outlet_anything(x->x_outlet,s,ac,av); + } + + } + + } + +} + +// DECONSTRUCTOR +static void paramRoute_free(t_paramRoute*x) +{ + +} + +// CONSTRUCTOR +static void *paramRoute_new(t_symbol *s, int ac, t_atom *av) { + t_paramRoute *x = (t_paramRoute *)pd_new(paramRoute_class); + + x->s_save = gensym("save"); + 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(); + + // 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); + // INLETS AND OUTLETS + x->x_outlet = outlet_new(&x->x_obj, &s_list); + return (x); +} + +void paramRoute_setup(void) { + paramRoute_class = class_new(gensym("paramRoute"), + (t_newmethod)paramRoute_new, (t_method)paramRoute_free, + sizeof(t_paramRoute), 0, A_GIMME, 0); + + class_addanything(paramRoute_class, paramRoute_anything); + +} |