From d82c79024b44f96d3c5f613cfb93cc9c9d917ff9 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Thu, 22 Oct 2009 19:48:22 +0000 Subject: Added single file version of param svn path=/trunk/externals/tof/; revision=12644 --- src/param.c | 404 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/param.h | 359 ++++++++++++++++++++++++++++++++++++++++++++++++ src/paramCustom.h | 200 +++++++++++++++++++++++++++ src/paramDump.h | 169 +++++++++++++++++++++++ src/paramFile.h | 267 ++++++++++++++++++++++++++++++++++++ src/paramGui.h | 335 ++++++++++++++++++++++++++++++++++++++++++++ src/paramId.h | 52 +++++++ src/paramRoute.h | 110 +++++++++++++++ 8 files changed, 1896 insertions(+) create mode 100644 src/param.c create mode 100644 src/param.h create mode 100644 src/paramCustom.h create mode 100644 src/paramDump.h create mode 100644 src/paramFile.h create mode 100644 src/paramGui.h create mode 100644 src/paramId.h create mode 100644 src/paramRoute.h (limited to 'src') diff --git a/src/param.c b/src/param.c new file mode 100644 index 0000000..2eaf4e1 --- /dev/null +++ b/src/param.c @@ -0,0 +1,404 @@ +/* + * param.c + * + * Copyright 2009 Thomas O Fredericks + * + * 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 "param.h" +#include "paramCustom.h" +#include "paramDump.h" +#include "paramFile.h" +#include "paramId.h" +#include "paramRoute.h" +#include "paramGui.h" + +extern int sys_noloadbang; + +static t_class *param_class; +static t_class *param_inlet2_class; +struct _paramClass_inlet2; + +typedef struct _paramClass { + t_object x_obj; + struct _paramClass_inlet2 *inlet2; + t_param* param; + int noloadbang; + t_symbol* selector; + int alloc; + int ac; + t_atom* av; + int gac; // gui options count + t_atom* gav; // gui options + t_outlet* outlet; + t_symbol* receive; + t_symbol* send; + t_symbol* set_s; + int nowaitforbang; + int nopresets; +} t_paramClass; + +typedef struct _paramClass_inlet2 +{ + t_object x_obj; + t_paramClass *p_owner; +} t_paramClass_inlet2; + + + +static void paramClass_bang(t_paramClass *x) +{ + outlet_anything(x->outlet, x->selector, x->ac, x->av); + + if(x->selector != &s_bang ) tof_send_anything_prepend(x->send,x->selector,x->ac,x->av,x->set_s ); + +} + +static void paramClass_loadbang(t_paramClass *x) +{ + if (!sys_noloadbang && !x->noloadbang) + paramClass_bang(x); +} + +static void paramClass_anything(t_paramClass *x, t_symbol *s, int ac, t_atom *av) +{ + #ifdef PARAMDEBUG + post("RECEIVING SOMETHING"); + #endif + if ( s == &s_bang || ac == 0 ) { + x->ac = 0; + x->selector = s; + } else { + if(ac > x->alloc) { + x->av = resizebytes(x->av, x->alloc*sizeof(*(x->av)), + (10 + ac)*sizeof(*(x->av))); + x->alloc = 10 + ac; + } + x->ac = ac; + x->selector = s; + tof_copy_atoms(av, x->av, ac); + } + + if (x->nowaitforbang) paramClass_bang(x); + +} + + + + +// SECOND INLET METHOD + +static void paramClass_inlet2_anything(t_paramClass_inlet2 *p, t_symbol *s, int ac, t_atom *av) +{ + paramClass_anything(p->p_owner, s,ac,av); +} + +// DECONSTRUCTOR + +static void paramClass_free(t_paramClass *x) +{ + + if(x->inlet2) pd_free((t_pd *)x->inlet2); + + if (x->receive) pd_unbind(&x->x_obj.ob_pd, x->receive); + + if (x->param) param_unregister(x->param); + + freebytes(x->gav, x->gac * sizeof(*(x->gav))); + + freebytes(x->av, x->alloc * sizeof(*(x->av))); + +} + +// SPECIAL PARAM GET FUNCTION +static void paramClass_get(t_paramClass *x, t_symbol** s, int* ac, t_atom** av) { + *s = x->selector; + *ac = x->ac; + *av = x->av; +} + +// SPECIAL PARAM SAVE FUNCTION +static void paramClass_save(t_paramClass *x, t_binbuf* bb,int f) { + + //post("save:%i",f); + + + // f = -1 for the main save file + // f => 0 if it is a preset + if ( f >= 0 && x->nopresets) return; + + //Put my data in binbuf + if ((x->selector != &s_bang)) { + int ac = x->ac + 2; + t_atom *av = getbytes(ac*sizeof(*av)); + tof_copy_atoms(x->av,av+2,x->ac); + SETSYMBOL(av, x->param->path); + SETSYMBOL(av+1, x->selector); + binbuf_add(bb, ac, av); + binbuf_addsemi(bb); + freebytes(av, ac*sizeof(*av)); + } +} + +// SPECIAL PARAM GUI FUNCTION +static void paramClass_GUI(t_paramClass *x, int* ac, t_atom** av, t_symbol** send,t_symbol** receive) { + *ac = x->gac; + *av = x->gav; + *send = x->receive; + *receive = x->send; +} + +/* +// SPECIAL PARAM GUI FUNCTION +static void paramClass_GUIUpdate(t_paramClass *x) { + if(x->selector != &s_bang ) tof_send_anything_prepend(x->send,x->selector,x->ac,x->av,x->set_s ); +} +*/ + +// CONSTRUCTOR +static void* paramClass_new(t_symbol *s, int ac, t_atom *av) +{ + t_paramClass *x = (t_paramClass *)pd_new(param_class); + + + // GET THE CURRENT CANVAS + t_canvas* canvas=tof_get_canvas(); + + // GET THE NAME + t_symbol* name = param_get_name(ac,av); + + if (!name) return NULL; + + t_symbol* path = param_get_path(canvas,name); + t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas)); + + + //FIND THE GUI OPTIONS: /g + int ac_temp = 0; + t_atom* av_temp = NULL; + + tof_find_tagged_argument('/',gensym("/g"), ac-1, av+1,&ac_temp,&av_temp); + x->gac = ac_temp; + x->gav = getbytes(x->gac * sizeof(*(x->gav))); + tof_copy_atoms(av_temp,x->gav,x->gac); + + // FIND THE NO LOADBANG TAG: /nlb + x->noloadbang = tof_find_tag('/',gensym("/nlb"), ac-1, av+1); + //post("nlb: %i",x->noloadbang); + + + + // FIND THE WAIT FOR BANG TAG: /wfb + x->nowaitforbang = !(tof_find_tag('/',gensym("/wfb"), ac-1, av+1)); + // FIND THE NO SAVE TAG: /ns + int nosave = tof_find_tag('/',gensym("/ns"), ac-1, av+1); + //post("ns: %i",nosave); + + // FIND THE NO PRESET TAG: /nps + x->nopresets = tof_find_tag('/',gensym("/nps"), ac-1, av+1); + + + // REGISTER PARAM + t_paramSaveMethod paramSaveMethod = NULL; + t_paramGUIMethod paramGUIMethod = NULL; + + + //post("no save:%i",nosave); + + if ( x->gac > 0 ) paramGUIMethod = (t_paramGUIMethod) paramClass_GUI; + if ( nosave == 0 ) paramSaveMethod = (t_paramSaveMethod) paramClass_save; + + x->param = param_register(x,root,path, \ + (t_paramGetMethod) paramClass_get, \ + paramSaveMethod, \ + paramGUIMethod); + + if (!x->param) return NULL; + + // 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); + tof_find_tagged_argument('/',name, ac_c, av_c,&ac_p,&av_p); + + // B. I object's arguments + if ( ac_p == 0 && ac > 1) { + int ac_a = 0; + t_atom* av_a = NULL; + tof_find_tagged_argument('/',name, ac, av,&ac_p,&av_p); + //tof_get_tagged_argument('/',ac,av,&start,&count); + //if (count > 1) { + // ac_p = ac_a; + // av_p = av_a + 1; + //} + } + + + + int l = strlen(path->s_name) + strlen(root->s_name) + 2; + char* receiver = getbytes( l * sizeof(*receiver)); + strcat(receiver,root->s_name); + strcat(receiver,path->s_name); + x->receive = gensym(receiver); + strcat(receiver,"_"); + x->send = gensym(receiver); + freebytes(receiver, l * sizeof(*receiver)); + #ifdef PARAMDEBUG + post("receive:%s",x->receive->s_name); + post("send:%s",x->send->s_name); + #endif + + + // BIND RECEIVER + pd_bind(&x->x_obj.ob_pd, x->receive ); + + + // Create memory space + t_symbol* selector; + tof_set_selector(&selector,&ac_p,&av_p); + x->selector = selector; + x->alloc = ac_p + 10; + x->ac = ac_p; + x->av = getbytes(x->alloc * sizeof(*(x->av))); + tof_copy_atoms(av_p, x->av, x->ac); + + + + x->set_s = gensym("set"); + + // Set up second inlet proxy + t_paramClass_inlet2 *p = (t_paramClass_inlet2 *)pd_new(param_inlet2_class); + x->inlet2 = p; + p->p_owner = x; + + // CREATE INLETS AND OUTLETS + inlet_new((t_object *)x, (t_pd *)p, 0, 0); + x->outlet = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +static void* param_new(t_symbol *s, int argc, t_atom *argv) { + + //post("RUNNING COMMON NEW"); + + t_pd* x; + + if ( !argc || argv[0].a_type == A_FLOAT ) { + x = NULL; + } else { + + t_symbol *s2 = argv[0].a_w.w_symbol; + + //post("Loading: %s",s2->s_name); + + 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); + else if (s2 == gensym("file")) + x = paramFile_new(s, argc-1, argv+1); + else if (s2 == gensym("id")) + x = paramId_new(s, argc-1, argv+1); + else if (s2 == gensym("route")) + x = paramRoute_new(s, argc-1, argv+1); + else if (s2 == gensym("gui")) + x = paramGui_new(s, argc-1, argv+1); + else + x = paramClass_new(s, argc, argv); + } + if ( x == NULL) { + post("Param is missing a symbolic argument. Possible values: custom, dump, file, id, route, gui or a /name."); + //post(" custom"); + //dump file id route gui or a /\"name\" + //post("- dump"); + //post("- file"); + //post("- id"); + //post("- route"); + //post("- gui"); + //post("- or a /name."); + } + + return (x); + +} + + + +void param_setup(void) +{ + + /* + alist_setup(); + list_append_setup(); + list_prepend_setup(); + list_split_setup(); + list_trim_setup(); + list_length_setup(); + class_addcreator((t_newmethod)list_new, &s_list, A_GIMME, 0); + */ + + /* + + + + */ + ///////////// + + + // SETUP THE PARAM CLASS + param_class = class_new(gensym("param /"), + (t_newmethod)paramClass_new, (t_method)paramClass_free, + sizeof(t_paramClass), 0, A_GIMME, 0); + + + class_addanything(param_class, paramClass_anything); + class_addbang(param_class, paramClass_bang); + + class_addmethod(param_class, (t_method)paramClass_loadbang, gensym("loadbang"), 0); + + param_inlet2_class = class_new(gensym("_param_inlet2"), + 0, 0, sizeof(t_paramClass_inlet2), CLASS_PD | CLASS_NOINLET, 0); + + class_addanything(param_inlet2_class, paramClass_inlet2_anything); + + + // SETUP OTHER CLASSES + paramCustom_setup(); + paramDump_setup(); + paramFile_setup(); + paramId_setup(); + paramRoute_setup(); + paramGui_setup(); + + + // ADD THE COMMON CREATOR + + class_addcreator((t_newmethod)param_new, gensym("param"), A_GIMME, 0); + class_addcreator((t_newmethod)param_new, gensym("tof/param"), A_GIMME, 0); +} diff --git a/src/param.h b/src/param.h new file mode 100644 index 0000000..dfe8588 --- /dev/null +++ b/src/param.h @@ -0,0 +1,359 @@ +#include "tof.h" +#include +#include + +//#define PARAMDEBUG + +typedef void (*t_paramGetMethod)(void*,t_symbol**,int*,t_atom**); +typedef void (*t_paramSaveMethod)(void*,t_binbuf*,int); +typedef void (*t_paramGUIMethod)(void*,int*,t_atom**,t_symbol**,t_symbol**); +//typedef void (*t_paramGUIUpdateMethod)(void*); + +static char param_buf_temp_a[MAXPDSTRING]; +static char param_buf_temp_b[MAXPDSTRING]; +static char* param_separator = "/"; + + +//char PARAMECHO = 0; + +//struct _paramroot; + +typedef struct _param { + t_symbol* root; + t_symbol* path; //Path(name) of the param + void* x; + struct _param* next; //Next param + struct _param* previous; //Previous param + t_paramGetMethod get; //Function to get current value + t_paramSaveMethod save; //Function to save + t_paramGUIMethod GUI; + // t_paramGUIUpdateMethod GUIUpdate; + //t_symbol* send; + //t_symbol* receive; +} t_param; + +typedef struct _paramroot { + t_symbol* root; + t_param* params; //param list + struct _paramroot* next; //Next paramroot + struct _paramroot* previous; //Previous paramroot +} t_paramroot; + +static t_paramroot* PARAMROOTS; + + +static t_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 + t_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 t_paramroot* param_root_attach(t_symbol* root){ + + // Pointer to the start of paramroots + t_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 + t_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 t_param* get_param_list(t_symbol* root) { + + + t_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* name = atom_getsymbol(av)->s_name; + if (*name == *param_separator ) { + int length = strlen(name); + if (name[length-1] != '_' || name[length-1] != '/') return atom_getsymbol(av); + } + } + post("Param names must start with a \"/\" and can not end with either a \"_\" or a \"/\"!"); + return 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 = "/"; + + + 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; + + /* 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=NULL; + //id_temp= canvas_realizedollar(i_canvas, gensym("$0")); + int ac_a = 0; + t_atom* av_a = NULL; + int iter = 0; + //found_id_flag = 0; + + while( tof_next_tagged_argument(*param_separator,i_ac,i_av,&ac_a,&av_a,&iter) ) { + + if ( IS_A_SYMBOL(av_a,0) + && (id_s == av_a->a_w.w_symbol) + && (ac_a > 1) ) { + id_temp = atom_getsymbol(av_a+1); + //id_canvas = i_canvas; + //found_id_flag = 1; + break; + } + } + + if (id_temp == NULL) { + + id_temp = tof_remove_extension(tof_get_canvas_name(i_canvas)); + } + // 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, param_separator); + strcat(sbuf_name, id_temp->s_name); + strcat(sbuf_name,sbuf_temp); + } + i_canvas = i_canvas->gl_owner; + } + + // If no name, the path will always end with a / + + if ( name != NULL) { + strcat(sbuf_name,name->s_name); + } else { + //if (strlen(sbuf_name)==0) + strcat(sbuf_name,param_separator); + } + + return gensym(sbuf_name); + +} + + + +// 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 t_param* param_register(void* x,t_symbol* root, t_symbol* path,\ + t_paramGetMethod get, t_paramSaveMethod save, t_paramGUIMethod GUI) { + + + //char *separator = "/"; + + /* GET POINTER TO PARAMLIST FOR THAT ROOT */ + t_paramroot* branch = param_root_attach(root); + t_param* last = branch->params; + + // Search for param with same path + while( last ) { + if ( last->path == path) { + + pd_error(x,"Found param with same name: %s", path->s_name); + + return NULL; + } + if ( last->next == NULL ) break; + last = last->next; + } + + // Create and add param to the end + + t_param* p = getbytes(sizeof(*p)); + p->root = root; + //p->alloc = 0; + p->path = path; + + // 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->x = x; + p->get = get; + p->save = save; + p->GUI = GUI; + //p->GUIUpdate = GUIUpdate; + //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) { + #ifdef PARAMDEBUG + post("Appending param"); + #endif + p->previous = last; + last->next = p; + } else { + #ifdef PARAMDEBUG + post("Creating first param"); + #endif + p->previous = NULL; + branch->params = p; + } + + + return p; + +} + +static void param_unregister(t_param* p) { + + //post("unregistering %s", p->path->s_name); + t_paramroot* branch = param_get_root(p->root); + t_param* paramlist = branch->params; + + 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); + //} + + // 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!"); + } + + +} + + + diff --git a/src/paramCustom.h b/src/paramCustom.h new file mode 100644 index 0000000..9d34f83 --- /dev/null +++ b/src/paramCustom.h @@ -0,0 +1,200 @@ + + +static t_class *paramCustom_class; +static t_class *paramCustom_receive_class; +struct _paramCustom_receive; + +typedef struct _paramCustom { + t_object x_obj; + t_param* param; + t_outlet* outlet; + t_outlet* outlet2; + t_binbuf* bb; + t_symbol* receive; + struct _paramCustom_receive* r; + int nopresets; +} t_paramCustom; + +typedef struct _paramCustom_receive +{ + t_object x_obj; + t_paramCustom *owner; +} t_paramCustom_receive; + + + +static void paramCustom_bang(t_paramCustom *x) +{ + /* + outlet_anything(x->outlet, x->selector, x->ac, x->av); + + if(x->selector != &s_bang ) tof_send_anything_prepend(x->send,x->selector,x->ac,x->av,x->set_s ); + */ +} +/* + +static void paramClass_loadbang(t_paramClass *x) +{ + if (!sys_noloadbang && !x->noloadbang) + paramClass_bang(x); +} +*/ + +static void paramCustom_anything(t_paramCustom *x, t_symbol *selector, int argc, t_atom *argv) +{ + if (x->bb) { + if ((selector != &s_bang)) { + int ac = argc + 2; + t_atom *av = getbytes(ac*sizeof(*av)); + tof_copy_atoms(argv,av+2,argc); + SETSYMBOL(av, x->param->path); + SETSYMBOL(av+1, selector); + binbuf_add(x->bb, ac, av); + binbuf_addsemi(x->bb); + freebytes(av, ac*sizeof(*av)); + } + } else { + pd_error(x,"No save triggered"); + } +} + + + + +// DECONSTRUCTOR + +static void paramCustom_free(t_paramCustom *x) +{ + + if (x->receive) pd_unbind(&x->r->x_obj.ob_pd, x->receive); + + if (x->param) param_unregister(x->param); + + +} + +// SPECIAL PARAM GET FUNCTION +/* +static void paramClass_get(t_paramClass *x, t_symbol** s, int* ac, t_atom** av) { + *s = x->selector; + *ac = x->ac; + *av = x->av; +} +*/ + +// SPECIAL PARAM SAVE FUNCTION +static void paramCustom_save(t_paramCustom *x, t_binbuf* bb, int f) { + + // f = -1 for the main save file + // f => 0 if it is a preset + if ( f >= 0 && x->nopresets) return; + + + if ( !x->bb ) { + + x->bb = bb; + // TRIGGER OUTPUT + outlet_bang(x->outlet); + x->bb = NULL; + + } else { + pd_error(x,"paramCustom is already saving"); + } + +} + + + +static void paramCustom_receive_anything(t_paramCustom_receive *r, t_symbol *s, int ac, t_atom *av){ + + outlet_anything(r->owner->outlet2,s,ac,av); + + +} + + + +// CONSTRUCTOR +static void* paramCustom_new(t_symbol *s, int ac, t_atom *av) +{ + t_paramCustom *x = (t_paramCustom *)pd_new(paramCustom_class); + + + // GET THE CURRENT CANVAS + t_canvas* canvas=tof_get_canvas(); + + // GET THE NAME + t_symbol* name = param_get_name(ac,av); + + if (!name) return NULL; + + t_symbol* path = param_get_path(canvas,name); + t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas)); + + // FIND THE NO PRESET TAG: /nps + x->nopresets = tof_find_tag('/',gensym("/nps"), ac-1, av+1); + + + + x->param = param_register(x,root,path, NULL,\ + (t_paramSaveMethod) paramCustom_save,NULL); + + if (!x->param) return NULL; + + + + int l = strlen(path->s_name) + strlen(root->s_name) + 2; + char* receiver = getbytes( l * sizeof(*receiver)); + strcat(receiver,root->s_name); + strcat(receiver,path->s_name); + x->receive = gensym(receiver); + //strcat(receiver,"_"); + // x->send = gensym(receiver); + freebytes(receiver, l * sizeof(*receiver)); + + #ifdef PARAMDEBUG + post("receive:%s",x->receive->s_name); + //post("send:%s",x->send->s_name); + #endif + + + x->bb = NULL; + + + // Set up receive proxy + t_paramCustom_receive *r = (t_paramCustom_receive *)pd_new(paramCustom_receive_class); + x->r = r; + r->owner = x; + + // BIND RECEIVER + pd_bind(&r->x_obj.ob_pd, x->receive ); + + + + + // CREATE INLETS AND OUTLETS + //inlet_new((t_object *)x, (t_pd *)p, 0, 0); + x->outlet = outlet_new(&x->x_obj, &s_list); + x->outlet2 = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +void paramCustom_setup(void) +{ + paramCustom_class = class_new(gensym("paramCustom"), + (t_newmethod)paramCustom_new, (t_method)paramCustom_free, + sizeof(t_paramCustom), 0, A_GIMME, 0); + + + class_addanything(paramCustom_class, paramCustom_anything); + class_addbang(paramCustom_class, paramCustom_bang); + + //class_addmethod(param_class, (t_method)paramClass_loadbang, gensym("loadbang"), 0); + + paramCustom_receive_class = class_new(gensym("_paramCustom_receive"), + 0, 0, sizeof(t_paramCustom_receive), CLASS_PD | CLASS_NOINLET, 0); + + class_addanything(paramCustom_receive_class, paramCustom_receive_anything); + +} diff --git a/src/paramDump.h b/src/paramDump.h new file mode 100644 index 0000000..2d00f13 --- /dev/null +++ b/src/paramDump.h @@ -0,0 +1,169 @@ + + +static t_class *paramDump_class; + + +typedef struct _paramDump +{ + t_object x_obj; + t_outlet* outlet; + t_symbol* empty_s; + t_symbol* root; + +} t_paramDump; + +/* +static void paramDump_updateguis(t_paramDump *x, t_symbol* s) { + + t_param* p = get_param_list(x->root); + int ac; + t_atom* av; + + if ( s == x->empty_s ) { + while (p) { + if (p->GUIUpdate) { + p->GUIUpdate(p->x); + } + p = p->next; + } + } else { + int length = strlen(s->s_name); + while (p) { + if (p->GUIUpdate && (strncmp(p->path->s_name,s->s_name,length)==0) ) { + p->GUIUpdate(p->x); + + } + p = p->next; + } + } + +} +*/ +static void paramDump_guis(t_paramDump *x, t_symbol* s) { + + t_param* p = get_param_list(x->root); + int ac; + t_atom* av; + t_symbol* send; + t_symbol* receive; + + if ( s == x->empty_s ) { + while (p) { + if (p->GUI ) { + p->GUI(p->x,&ac,&av,&send,&receive); + outlet_anything(x->outlet,p->path,ac,av); + + } + p = p->next; + } + } else { + int length = strlen(s->s_name); + while (p) { + if (p->GUI && (strncmp(p->path->s_name,s->s_name,length)==0) ) { + p->GUI(p->x,&ac,&av,&send,&receive); + outlet_anything(x->outlet,p->path,ac,av); + + } + p = p->next; + } + } + +} + + +static void paramDump_symbol(t_paramDump *x, t_symbol* s) { + + t_param* p = get_param_list(x->root); + #ifdef PARAMDEBUG + if (p == NULL) { + post("No params found"); + } else { + post("Found params"); + } + #endif + + t_symbol* selector; + int ac; + t_atom* av; + + + + int length = strlen(s->s_name); + + while (p) { + if ( p->get && (strncmp(p->path->s_name,s->s_name,length)==0) ) { + p->get(p->x, &selector, &ac, &av); + tof_outlet_anything_prepend(x->outlet,selector,ac,av,p->path); + } + p = p->next; + } + +} + +// Dump out +static void paramDump_bang(t_paramDump *x) { + + t_param* p = get_param_list(x->root); + #ifdef PARAMDEBUG + if (p == NULL) { + post("No params found"); + } else { + post("Found params"); + } + #endif + + t_symbol* selector; + int ac; + t_atom* av; + + + while (p) { + if ( p->get ) { + p->get(p->x, &selector, &ac, &av); + tof_outlet_anything_prepend(x->outlet,selector,ac,av,p->path); + } + p = p->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->root = tof_get_dollarzero(tof_get_root_canvas(tof_get_canvas())); + x->empty_s = gensym(""); + + //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_addsymbol(paramDump_class, paramDump_symbol); + + //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_updateguis, gensym("updateguis"), A_DEFSYMBOL,0); + + + //class_addmethod(paramDump_class, (t_method) paramDump_update_guis, gensym("update"), A_DEFSYMBOL,0); + +} diff --git a/src/paramFile.h b/src/paramFile.h new file mode 100644 index 0000000..a835df6 --- /dev/null +++ b/src/paramFile.h @@ -0,0 +1,267 @@ + + +static t_class *paramFile_class; +static t_class *paramFile_inlet2_class; +struct _paramFile_inlet2; + +typedef struct _paramFile +{ + t_object x_obj; + t_canvas *canvas; + t_symbol* basename; + t_symbol* root; + struct _paramFile_inlet2 *inlet2; + int working; +} t_paramFile; + + +typedef struct _paramFile_inlet2 { + t_object x_obj; + t_paramFile *x; +} t_paramFile_inlet2; + +static t_symbol* paramFile_makefilename(t_paramFile* x, t_float f) { + t_symbol* filename; + + int i = (int) f; + + if (i<0) { + int length = strlen(x->basename->s_name)+7; + char* buf = getbytes( length * sizeof (*buf)); + sprintf(buf,"%s.param",x->basename->s_name); + filename = gensym(buf); + freebytes(buf, length * sizeof (*buf)); + } else { + int length = strlen(x->basename->s_name)+11; + char* buf = getbytes( length * sizeof (*buf)); + sprintf(buf,"%s-%03d.param",x->basename->s_name,i); + filename = gensym(buf); + freebytes(buf, length * sizeof (*buf)); + } + return filename; +} + +static void paramFile_do_save(t_paramFile* x, t_float f) { + + + + if ( x->working ) { + pd_error(x,"paramFile can only save or load to one file at a time"); + return; + } + t_symbol* filename = paramFile_makefilename(x,f); + + x->working = 1; + + + post("Writing: %s",filename->s_name); + + int w_error; + + t_binbuf *bbuf = binbuf_new(); + + t_param *p = get_param_list(x->root); + + while(p) { + + if ( p->save ) p->save(p->x,bbuf,f); + + p = p->next; + } + + + char buf[MAXPDSTRING]; + canvas_makefilename(x->canvas, filename->s_name,buf, MAXPDSTRING); + + + w_error = (binbuf_write(bbuf, buf, "", 0)); + + + binbuf_free(bbuf); + + if (w_error) pd_error(x,"%s: write failed", filename->s_name); + + x->working = 0; + +} + + + + + +static void paramFile_do_load(t_paramFile* x, t_float f) { + + if ( x->working ) { + pd_error(x,"paramFile can only save or load to one file at a time"); + return; + } + x->working = 1; + + t_symbol* filename = paramFile_makefilename(x,f); + post("Reading: %s",filename->s_name); + + 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, 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; + + while (bb_ac--) { + if (bb_av->a_type == A_SEMI) { + if ( IS_A_SYMBOL(av,0) && ac > 1) { + 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 + + // 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); + } + } + + ac = 0; + av = bb_av + 1; + } else { + + ac = ac + 1; + } + bb_av++; + } + + binbuf_free(bbuf); + + if ( r_error) pd_error(x, "%s: read failed", filename->s_name); + + x->working = 0; + +} + + + + + +static void paramFile_bang(t_paramFile *x) { + + paramFile_do_save(x,-1); +} + + +static void paramFile_float(t_paramFile *x, t_float f) { + + if (f < 0 || f > 999 ) { + pd_error(x,"paramFile preset number must be between 0 and 999"); + return; + } + + paramFile_do_save(x,f); + +} + + +static void paramFile_inlet2_bang(t_paramFile_inlet2 *inlet2) { + + paramFile_do_load(inlet2->x,-1); + +} + +static void paramFile_inlet2_float(t_paramFile_inlet2 *inlet2,t_float f) { + + if (f < 0 || f > 999 ) { + pd_error(inlet2->x,"paramFile preset number must be between 0 and 999"); + return; + } + + paramFile_do_load(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 .) + x->basename = tof_remove_extension(canvasname); + + x->working = 0; + + x->root = tof_get_dollarzero(x->canvas); + + //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_load, gensym("load"), A_DEFFLOAT,0); + //class_addmethod(paramFile_class, (t_method) paramFile_float, gensym("save"), A_DEFFLOAT,0); + +} + + diff --git a/src/paramGui.h b/src/paramGui.h new file mode 100644 index 0000000..fdfaf33 --- /dev/null +++ b/src/paramGui.h @@ -0,0 +1,335 @@ + +static t_class *paramGui_class; + + +typedef struct _paramGui +{ + t_object x_obj; + //t_outlet* outlet; + //t_symbol* canvasname; + t_canvas* childcanvas; + //t_symbol* fullpath; + t_symbol* path; + int path_l; + int build; + t_symbol* s_vis; + t_symbol* s_empty; + t_symbol* s_clear; + t_symbol* s_set; + t_symbol* root; + t_symbol* s_obj; + t_symbol* s_nbx; + t_symbol* s_bng; + t_symbol* s_slider; + t_symbol* s_hsl; + t_symbol* s_knob; + t_symbol* s_tgl; + t_symbol* s_symbolatom; + t_symbol* s_sym; + t_symbol* s_text; + + //t_symbol* target; + //t_class* empty_s; + //t_symbol* root; + +} t_paramGui; + + + +// Dump out +static void paramGui_bang(t_paramGui *x) { + + if (x->childcanvas) { + + if (x->build) { + // 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 + + t_param* p = get_param_list(x->root); + int ac; + t_atom* av; + t_symbol* type; + t_symbol* send; + t_symbol* receive; + + int gui_built = 1; + + // ac & av for updating the values of the gui (p->get()) + int ac_got = 0; + 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)) { + p->GUI(p->x,&ac,&av,&send,&receive); + if ( send == NULL ) send = x->s_empty; + if ( receive == NULL ) receive = x->s_empty; + if ( IS_A_SYMBOL(av,0)) { + type = atom_getsymbol(av); + if ( type == x->s_nbx ) { + SETSYMBOL(&atoms[0],x->s_obj); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],x->s_nbx); + SETFLOAT(&atoms[4],5); + SETFLOAT(&atoms[5],14); + SETFLOAT(&atoms[6],-1.0e+37); + SETFLOAT(&atoms[7],1.0e+37); + SETFLOAT(&atoms[8],0); + SETFLOAT(&atoms[9],0); + SETSYMBOL(&atoms[10],send); + SETSYMBOL(&atoms[11],receive); + SETSYMBOL(&atoms[12],p->path); + SETFLOAT(&atoms[13],50); + SETFLOAT(&atoms[14],8); + SETFLOAT(&atoms[15],0); + SETFLOAT(&atoms[16],8); + SETFLOAT(&atoms[17],-262144); + SETFLOAT(&atoms[18],-1); + SETFLOAT(&atoms[19],-1); + SETFLOAT(&atoms[20],0); + SETFLOAT(&atoms[21],256); + pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); + pos_y = pos_y + 18; + + } else if (type == x->s_bng) { + SETSYMBOL(&atoms[0],x->s_obj); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],x->s_bng); + SETFLOAT(&atoms[4],15); + SETFLOAT(&atoms[5],250); + SETFLOAT(&atoms[6],50); + SETFLOAT(&atoms[7],0); + SETSYMBOL(&atoms[8],send); + SETSYMBOL(&atoms[9],receive); + SETSYMBOL(&atoms[10],p->path); + SETFLOAT(&atoms[11],17); + SETFLOAT(&atoms[12],7); + SETFLOAT(&atoms[13],0); + SETFLOAT(&atoms[14],8); + SETFLOAT(&atoms[15],-262144); + SETFLOAT(&atoms[16],-1); + SETFLOAT(&atoms[17],-1); + pd_forwardmess((t_pd*)x->childcanvas, 18, atoms); + pos_y = pos_y + 18; + } else if ( (type == x->s_slider) || (type == x->s_knob) || (type == x->s_hsl) ) { + SETSYMBOL(&atoms[0],x->s_obj); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],x->s_hsl); + SETFLOAT(&atoms[4],100); + SETFLOAT(&atoms[5],15); + if (ac > 1 && IS_A_FLOAT(av,1) ) { + SETFLOAT(&atoms[6],atom_getfloat(av+1)); + } else { + SETFLOAT(&atoms[6],0); + } + if (ac > 2 && IS_A_FLOAT(av,2) ) { + SETFLOAT(&atoms[7],atom_getfloat(av+2)); + } else { + SETFLOAT(&atoms[7],1); + } + SETFLOAT(&atoms[8],0); + SETFLOAT(&atoms[9],0); + SETSYMBOL(&atoms[10],send); + SETSYMBOL(&atoms[11],receive); + SETSYMBOL(&atoms[12],p->path); + SETFLOAT(&atoms[13],105); + SETFLOAT(&atoms[14],7); + SETFLOAT(&atoms[15],0); + SETFLOAT(&atoms[16],8); + SETFLOAT(&atoms[17],-262144); + SETFLOAT(&atoms[18],-1); + SETFLOAT(&atoms[19],-1); + SETFLOAT(&atoms[20],0); + SETFLOAT(&atoms[21],1); + pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); + pos_y = pos_y + 18; + + } else if (type == x->s_tgl) { + SETSYMBOL(&atoms[0],x->s_obj); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],x->s_tgl); + SETFLOAT(&atoms[4],15); + SETFLOAT(&atoms[5],0); + SETSYMBOL(&atoms[6],send); + SETSYMBOL(&atoms[7],receive); + SETSYMBOL(&atoms[8],p->path); + SETFLOAT(&atoms[9],17); + SETFLOAT(&atoms[10],7); + SETFLOAT(&atoms[11],0); + SETFLOAT(&atoms[12],8); + SETFLOAT(&atoms[13],-262144); + SETFLOAT(&atoms[14],1); + SETFLOAT(&atoms[15],-1); + SETFLOAT(&atoms[16],0); + SETFLOAT(&atoms[17],1); + pd_forwardmess((t_pd*)x->childcanvas, 18, atoms); + pos_y = pos_y + 18; + + + } else if ( type == x->s_symbolatom || type == x->s_sym) { + SETSYMBOL(&atoms[0],x->s_symbolatom); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETFLOAT(&atoms[3],17); + SETFLOAT(&atoms[4],0); + SETFLOAT(&atoms[5],0); + SETFLOAT(&atoms[6],1); + SETSYMBOL(&atoms[7],p->path); + SETSYMBOL(&atoms[8],receive); + SETSYMBOL(&atoms[9],send); + pd_forwardmess((t_pd*)x->childcanvas, 10,atoms); + pos_y = pos_y + 18; + } else { + SETSYMBOL(&atoms[0],x->s_text); + SETFLOAT(&atoms[1],pos_x); + SETFLOAT(&atoms[2],pos_y); + SETSYMBOL(&atoms[3],p->path); + pd_forwardmess((t_pd*)x->childcanvas, 4,atoms); + pos_y = pos_y + 18; + gui_built = 0; + } + + if ((gui_built) && (receive != x->s_empty) && (p->get)) { + p->get(p->x,&s_got,&ac_got,&av_got); + tof_send_anything_prepend(receive,s_got,ac_got,av_got,x->s_set); + } + } + } + p = p->next; + + } + } + + x->build = 0; + + // Show canvas + t_atom a; + SETFLOAT(&a,1); + pd_typedmess((t_pd*)x->childcanvas,x->s_vis,1,&a); + + } else { + + pd_error(x,"No canvas to write to!"); + + } +} + +static void paramGui_reset(t_paramGui *x) { + x->build = 1; + paramGui_bang(x); +} + + +static void paramGui_free(t_paramGui *x) +{ + if (x->childcanvas) { + //post("Deleting it"); + pd_free((t_pd *)x->childcanvas); + } + x->childcanvas = NULL; +} + + +static void *paramGui_new(t_symbol *s, int ac, t_atom *av) { + t_paramGui *x = (t_paramGui *)pd_new(paramGui_class); + + + x->build = 1; + + x->s_vis = gensym("vis"); + x->s_empty = gensym("empty"); + x->s_clear = gensym("clear"); + x->s_set = gensym("set"); + x->s_obj = gensym("obj"); + x->s_nbx = gensym("nbx"); + x->s_bng = gensym("bng"); + x->s_slider = gensym("slider"); + x->s_hsl=gensym("hsl"); + x->s_knob = gensym("knob"); + x->s_tgl = gensym("tgl"); + x->s_symbolatom = gensym("symbolatom"); + x->s_sym = gensym("sym"); + x->s_text = gensym("text"); + + + + t_canvas* currentcanvas = tof_get_canvas(); + + x->root = tof_get_dollarzero(tof_get_root_canvas(currentcanvas)); + + + x->path = param_get_path(currentcanvas, NULL); + x->path_l = strlen(x->path->s_name); + // Prepend $0 to path + t_symbol* dollarzero = tof_get_dollarzero(currentcanvas); + int zeropath_len = strlen(dollarzero->s_name)+strlen(x->path->s_name)+1; + char* zeropath = getbytes(zeropath_len * sizeof(* zeropath)); + strcpy(zeropath,dollarzero->s_name); + strcat(zeropath,x->path->s_name); + t_symbol* fullpath = gensym(zeropath); + freebytes(zeropath,zeropath_len * sizeof(* zeropath)); + + //post("path: %s",x->path->s_name); + + // create a new canvas + + + t_atom a; + SETSYMBOL(&a, fullpath); + pd_typedmess(&pd_objectmaker,gensym("pd"),1,&a); + + // From this point on, we are hoping the "pd" object has been created + x->childcanvas = (t_canvas*) pd_newest(); + /* + // Change saved name to match pd's canvas naming scheme + int pdcanvasname_len = strlen(x->fullpath->s_name ) + 4; + char* pdcanvasname = getbytes(pdcanvasname_len * sizeof(*pdcanvasname)); + strcpy(pdcanvasname,"pd-"); + strcat(pdcanvasname,x->fullpath->s_name); + x->canvasname = gensym(pdcanvasname); + freebytes(pdcanvasname,pdcanvasname_len * sizeof(*pdcanvasname)); + */ + + + // Hide the window (stupid way of doing this) + if (x->childcanvas) { + SETFLOAT(&a,0); + pd_typedmess((t_pd*)x->childcanvas,gensym("vis"),1,&a); + } + + + //x->outlet = outlet_new(&x->x_obj, &s_list); + + + inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("bang"), gensym("reset")); + + + return (x); +} + +void paramGui_setup(void) { + paramGui_class = class_new(gensym("paramGui"), + (t_newmethod)paramGui_new, (t_method)paramGui_free, + sizeof(t_paramGui), 0, A_GIMME, 0); + + class_addbang(paramGui_class, paramGui_bang); + //class_addsymbol(paramGui_class, paramGui_symbol); + + class_addmethod(paramGui_class, (t_method) paramGui_reset, gensym("reset"), 0); + + //class_addmethod(paramGui_class, (t_method) paramGui_guis, gensym("guis"), A_DEFSYMBOL,0); + //class_addmethod(paramGui_class, (t_method) paramGui_updateguis, gensym("updateguis"), A_DEFSYMBOL,0); + + + //class_addmethod(paramGui_class, (t_method) paramGui_update_guis, gensym("update"), A_DEFSYMBOL,0); + +} diff --git a/src/paramId.h b/src/paramId.h new file mode 100644 index 0000000..d36167b --- /dev/null +++ b/src/paramId.h @@ -0,0 +1,52 @@ + + +static t_class *paramId_class; + + +typedef struct _paramId +{ + t_object x_obj; + t_outlet* outlet; + t_symbol* path; + //t_symbol* root; +} t_paramId; + + + +// Dump out everything (OR THE ID'S OR JUST THE NAMES?) +static void paramId_bang(t_paramId *x) { + + outlet_symbol(x->outlet,x->path); + + +} + + + +static void paramId_free(t_paramId *x) +{ + + +} + + +static void *paramId_new(t_symbol *s, int ac, t_atom *av) { + t_paramId *x = (t_paramId *)pd_new(paramId_class); + + //x->root = tof_get_dollarzero(tof_get_root_canvas(tof_get_canvas())); + t_canvas* canvas = tof_get_canvas(); + x->path = param_get_path(canvas,NULL); + + x->outlet = outlet_new(&x->x_obj, &s_list); + + return (x); +} + +void paramId_setup(void) { + paramId_class = class_new(gensym("paramId"), + (t_newmethod)paramId_new, (t_method)paramId_free, + sizeof(t_paramId), 0, A_GIMME, 0); + + class_addbang(paramId_class, paramId_bang); + +} diff --git a/src/paramRoute.h b/src/paramRoute.h new file mode 100644 index 0000000..f284c29 --- /dev/null +++ b/src/paramRoute.h @@ -0,0 +1,110 @@ + + +static t_class *paramRoute_class; + +typedef struct _paramRoute +{ + t_object x_obj; + t_symbol *path; + t_outlet *x_outlet; + t_symbol *s_save; + t_symbol *s_load; + t_symbol* s_empty; + t_canvas* canvas; + t_symbol* root; + +} t_paramRoute; + + +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->path->s_name) + strlen(s->s_name) + 1; + //char *sendBuf = (char*)getbytes((sendBufLength)*sizeof(char)); + 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); + 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) { + pd_forwardmess(target->s_thing, ac, av); + } else { + outlet_anything(x->x_outlet,path,ac,av); + } + } else { + pd_error(x,"Target name must start with a \"/\""); + } + } + + } + +} + +// 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(""); + + + // GET THE CURRENT CANVAS + t_canvas *canvas=tof_get_canvas(); + + // Get the root canvas + x->canvas = tof_get_root_canvas(canvas); + + 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); +} + +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); + +} -- cgit v1.2.1