From b8cef69c5bd27cddfa93dd273bdafbee43579f91 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Sun, 25 Oct 2009 15:33:56 +0000 Subject: Made param gui display relative paths and removed unnecessary char buffers svn path=/trunk/externals/tof/; revision=12674 --- src/paramGui.h | 64 +++++++++++++++++++++++++++++++++++++++++----------------- src/path.c | 31 +++++++++++++++------------- src/tof.h | 4 ++-- 3 files changed, 65 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/paramGui.h b/src/paramGui.h index a825d62..0a6e918 100644 --- a/src/paramGui.h +++ b/src/paramGui.h @@ -1,6 +1,10 @@ static t_class *paramGui_class; +#define GUI_X_STEP 200 +#define GUI_Y_STEP 18 + + typedef struct _paramGui { @@ -56,9 +60,13 @@ static void paramGui_bang(t_paramGui *x) { t_symbol* send; t_symbol* receive; + int i; + t_symbol* shortpath; + int gui_built = 1; // ac & av for updating the values of the gui (p->get()) + // after it is created int ac_got = 0; t_atom* av_got; t_symbol* s_got; @@ -69,7 +77,32 @@ static void paramGui_bang(t_paramGui *x) { p->GUI(p->x,&ac,&av,&send,&receive); if ( send == NULL ) send = x->s_empty; if ( receive == NULL ) receive = x->s_empty; + + /* + // This code alows the positioning of the guis, but creates + // too many problems + if ( IS_A_FLOAT(av,0) ) { + pos_x = GUI_X_STEP * atom_getfloat(av); + av++; + ac--; + } + + if ( IS_A_FLOAT(av,0) ) { + pos_y = GUI_Y_STEP * atom_getfloat(av); + av++; + ac--; + } + */ if ( IS_A_SYMBOL(av,0)) { + + // Make shortpath (removes what is common between paths) + // Do not make shortpath if we are at the root (x->path_l==1) + if ( x->path_l < 2) { + shortpath = p->path; + } else { + shortpath = gensym(p->path->s_name + x->path_l); + } + type = atom_getsymbol(av); if ( type == x->s_nbx ) { SETSYMBOL(&atoms[0],x->s_obj); @@ -84,7 +117,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[9],0); SETSYMBOL(&atoms[10],send); SETSYMBOL(&atoms[11],receive); - SETSYMBOL(&atoms[12],p->path); + SETSYMBOL(&atoms[12],shortpath); SETFLOAT(&atoms[13],50); SETFLOAT(&atoms[14],8); SETFLOAT(&atoms[15],0); @@ -95,7 +128,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[20],0); SETFLOAT(&atoms[21],256); pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; } else if (type == x->s_bng) { SETSYMBOL(&atoms[0],x->s_obj); @@ -108,7 +141,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[7],0); SETSYMBOL(&atoms[8],send); SETSYMBOL(&atoms[9],receive); - SETSYMBOL(&atoms[10],p->path); + SETSYMBOL(&atoms[10],shortpath); SETFLOAT(&atoms[11],17); SETFLOAT(&atoms[12],7); SETFLOAT(&atoms[13],0); @@ -117,7 +150,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[16],-1); SETFLOAT(&atoms[17],-1); pd_forwardmess((t_pd*)x->childcanvas, 18, atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; } 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); @@ -139,7 +172,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[9],0); SETSYMBOL(&atoms[10],send); SETSYMBOL(&atoms[11],receive); - SETSYMBOL(&atoms[12],p->path); + SETSYMBOL(&atoms[12],shortpath); SETFLOAT(&atoms[13],105); SETFLOAT(&atoms[14],7); SETFLOAT(&atoms[15],0); @@ -150,7 +183,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[20],0); SETFLOAT(&atoms[21],1); pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; } else if (type == x->s_tgl) { SETSYMBOL(&atoms[0],x->s_obj); @@ -161,7 +194,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[5],0); SETSYMBOL(&atoms[6],send); SETSYMBOL(&atoms[7],receive); - SETSYMBOL(&atoms[8],p->path); + SETSYMBOL(&atoms[8],shortpath); SETFLOAT(&atoms[9],17); SETFLOAT(&atoms[10],7); SETFLOAT(&atoms[11],0); @@ -172,7 +205,7 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[16],0); SETFLOAT(&atoms[17],1); pd_forwardmess((t_pd*)x->childcanvas, 18, atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; } else if ( type == x->s_symbolatom || type == x->s_sym) { @@ -183,18 +216,18 @@ static void paramGui_bang(t_paramGui *x) { SETFLOAT(&atoms[4],0); SETFLOAT(&atoms[5],0); SETFLOAT(&atoms[6],1); - SETSYMBOL(&atoms[7],p->path); + SETSYMBOL(&atoms[7],shortpath); SETSYMBOL(&atoms[8],receive); SETSYMBOL(&atoms[9],send); pd_forwardmess((t_pd*)x->childcanvas, 10,atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; } else { SETSYMBOL(&atoms[0],x->s_text); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],p->path); + SETSYMBOL(&atoms[3],shortpath); pd_forwardmess((t_pd*)x->childcanvas, 4,atoms); - pos_y = pos_y + 18; + pos_y = pos_y + GUI_Y_STEP; gui_built = 0; } @@ -308,7 +341,7 @@ static void *paramGui_new(t_symbol *s, int ac, t_atom *av) { } - inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("bang"), gensym("reset")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd,&s_bang, gensym("reset")); @@ -332,10 +365,5 @@ void paramGui_setup(void) { class_sethelpsymbol(paramGui_class,gensym("param")); - //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/path.c b/src/path.c index d44ab95..d75e6bd 100644 --- a/src/path.c +++ b/src/path.c @@ -2,6 +2,9 @@ #include "tof.h" #define SLASH '/' +static char path_buf_a[MAXPDSTRING]; +static char path_buf_b[MAXPDSTRING]; + static t_class *path_class; typedef struct _path { @@ -143,8 +146,8 @@ static void path_bang(t_path *x) static void path_symbol(t_path *x, t_symbol *s) { - strcpy(tof_buf_temp_a,s->s_name); - int length = strlen(tof_buf_temp_a); + strcpy(path_buf_a,s->s_name); + int length = strlen(path_buf_a); t_symbol* result; if ( x->mode == x->s_relative ) { @@ -153,11 +156,11 @@ static void path_symbol(t_path *x, t_symbol *s) { // Is this a relative path? // Checks for a starting / or a : as second character - if ( path_is_absolute(tof_buf_temp_a,length )) { - getRelativeFilename(tof_buf_temp_b,x->dir->s_name,tof_buf_temp_a); - result = gensym(tof_buf_temp_b); + if ( path_is_absolute(path_buf_a,length )) { + getRelativeFilename(path_buf_b,x->dir->s_name,path_buf_a); + result = gensym(path_buf_b); } else { - result = gensym(tof_buf_temp_a); + result = gensym(path_buf_a); } } else { @@ -165,16 +168,16 @@ static void path_symbol(t_path *x, t_symbol *s) { // TRANFORM RELATIVE PATHS TO ABSOLUTE PATHS // Is this a relative path? - if ( path_is_absolute(tof_buf_temp_a,length) ) { - result = gensym(tof_buf_temp_a); + if ( path_is_absolute(path_buf_a,length) ) { + result = gensym(path_buf_a); } else { // remove extra ../ - strcpy(tof_buf_temp_b,x->dir->s_name); - char* dir = tof_buf_temp_b; + strcpy(path_buf_b,x->dir->s_name); + char* dir = path_buf_b; char* p; int l = strlen(dir); if (dir[l-1] == '/') dir[l-1] = '\0'; - char* file = tof_buf_temp_a; + char* file = path_buf_a; while( strncmp(file,"../",3) == 0 ) { file = file + 3; p = strrchr(dir,'/'); @@ -226,10 +229,10 @@ void *path_new(t_symbol *s, int argc, t_atom *argv) x->dir = tof_get_dir(tof_get_root_canvas(tof_get_canvas())); } - strcpy(tof_buf_temp_a,x->dir->s_name); + strcpy(path_buf_a,x->dir->s_name); - //strcat(tof_buf_temp_a,"/"); - x->dir = gensym(tof_buf_temp_a); + //strcat(path_buf_a,"/"); + x->dir = gensym(path_buf_a); /* inlet_new(&x->x_obj, &x->x_obj.ob_pd, diff --git a/src/tof.h b/src/tof.h index 48ed597..80c5e0a 100644 --- a/src/tof.h +++ b/src/tof.h @@ -11,8 +11,8 @@ -static char tof_buf_temp_a[MAXPDSTRING]; -static char tof_buf_temp_b[MAXPDSTRING]; +//static char tof_buf_temp_a[MAXPDSTRING]; +//static char tof_buf_temp_b[MAXPDSTRING]; /* -- cgit v1.2.1