diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arguments.c | 152 | ||||
-rw-r--r-- | src/param.c | 59 | ||||
-rw-r--r-- | src/paramGui.h | 99 |
3 files changed, 232 insertions, 78 deletions
diff --git a/src/arguments.c b/src/arguments.c new file mode 100644 index 0000000..c5ba961 --- /dev/null +++ b/src/arguments.c @@ -0,0 +1,152 @@ + + + #include "m_pd.h" + +#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL) +#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT) + +#define TOKEN 0 +#define COMMA 1 +#define ALL 2 + +static t_class *arguments_class; + + +typedef struct _arguments +{ + t_object x_obj; + t_outlet* outlet; + t_canvas* canvas; + t_symbol* s_comma; + int mode; + char token; + int size; + int ac; + t_atom* av; +} t_arguments; + + +// Prepends the proper selector +static void arguments_output(t_outlet* o, int argc, t_atom* argv) { + + if (!argc) outlet_bang(o); + else if (IS_A_SYMBOL(argv,0)) outlet_anything(o,atom_getsymbol(argv),argc-1,argv+1); + else if (IS_A_FLOAT(argv,0) && argc==1) outlet_float(o,atom_getfloat(argv)); + else outlet_anything(o,&s_list,argc,argv); +} + + +static int next_token(char tag, int ac, t_atom *av, int* ac_a, t_atom ** av_a, int* iter) { + int i; + + if ( ac == 0 || *iter >= ac) { + *ac_a = 0; + *av_a = NULL; + return 0; + } + + for ( i= *iter + 1; i < ac; i++ ) { + if ( (av+i)->a_type == A_SYMBOL + && (atom_getsymbol(av+i))->s_name[0] == tag) break; + } + *ac_a = i - *iter; + *av_a = av + *iter; + *iter = i; + + return (*ac_a); +} + +// Dump arguments +static void arguments_bang(t_arguments *x) { + + + + + if ( x->mode == TOKEN ) { + int ac_a; + t_atom* av_a; + t_symbol* selector_a; + int iter = 0 ; + while ( next_token(x->token, x->ac, x->av, &ac_a, &av_a,&iter)) { + arguments_output(x->outlet,ac_a,av_a); + } + } else if (x->mode == COMMA) { + // we are trusting the system that the commas are split from the + // neighboring floats and symbols + int ac = x->ac; + t_atom* av = x->av; + t_symbol* selector; + + int i =0; + int j; + for (j=0; j<ac; j++) { + if ( (IS_A_SYMBOL(av,j) && atom_getsymbol(av+j)==x->s_comma ) ) { + if ( (j != i) ) arguments_output(x->outlet, j - i, av+i); + + i = j+1; + } + } + // Output any leftovers + if ( j != i) arguments_output(x->outlet, ac-i, av+i); + } else { //x->mode = ALL + arguments_output(x->outlet, x->ac, x->av); + } +} + + +static void arguments_free(t_arguments *x) +{ + freebytes(x->av,x->ac*sizeof(*(x->av))); +} + +static void copy_atoms(t_atom *src, t_atom *dst, int n) +{ + while(n--) + *dst++ = *src++; +} + + + +static void *arguments_new(t_symbol *selector, int argc, t_atom* argv) { + t_arguments *x = (t_arguments *)pd_new(arguments_class); + + x->s_comma = gensym(","); + + if ( argc && IS_A_SYMBOL(argv,0) ) { + t_symbol* s = atom_getsymbol(argv); + if ( s == gensym("comma") || s == x->s_comma ) { + x->mode = COMMA; + post("COMMA"); + } else { + x->mode = TOKEN; + x->token = s->s_name[0]; + post("TOKEN: %c",x->token); + } + } else { + post("ALL"); + x->mode = ALL; + } + + + int ac; + t_atom* av; + canvas_getargs(&ac, &av); + + x->ac = ac; + x->av = getbytes(x->ac * sizeof(*(x->av))); + copy_atoms(av,x->av,x->ac); + + x->outlet = outlet_new(&x->x_obj, &s_anything); + + return (x); +} + +void arguments_setup(void) { + arguments_class = class_new(gensym("arguments"), + (t_newmethod)arguments_new, (t_method)arguments_free, + sizeof(t_arguments), 0, A_GIMME, 0); + + class_addbang(arguments_class, arguments_bang); + + +} diff --git a/src/param.c b/src/param.c index 9464a40..a0779f2 100644 --- a/src/param.c +++ b/src/param.c @@ -19,17 +19,37 @@ * MA 02110-1301, USA. */ -// Post a lot of debug messages +// Post a lot of debug messages. //#define PARAMDEBUG -// Adds the root's $0 to the start of the paths +// Adds the root's $0 to the start of the paths. //#define LOCAL // Uses the symbol's s_thing to target the proper param -// This is faster but can potentially target two params +// Instead of searching through paramroots for a match. +// This is faster but can potentially target two params. #define USEBINDINGS #include "param.h" + +// Global symbols +static t_symbol* s_vis; +static t_symbol* s_empty; +static t_symbol* s_clear; +static t_symbol* s_set; +static t_symbol* s_obj; +static t_symbol* s_nbx; +static t_symbol* s_bng; +static t_symbol* s_slider; +static t_symbol* s_hsl; +static t_symbol* s_knob; +static t_symbol* s_tgl; +static t_symbol* s_symbolatom; +static t_symbol* s_sym; +static t_symbol* s_text; +static t_symbol* s_cnv; + + #include "paramCustom.h" #include "paramDump.h" #include "paramFile.h" @@ -37,6 +57,7 @@ #include "paramRoute.h" #include "paramGui.h" +// For loadbang extern int sys_noloadbang; static t_class *param_class; @@ -349,18 +370,7 @@ static void* param_new(t_symbol *s, int argc, t_atom *argv) { else post("Param is missing an argument. Possible values: custom, dump, file, path, route, gui or a /name."); } - /* - if ( x == NULL) { - //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); } @@ -402,5 +412,24 @@ void param_setup(void) class_addcreator((t_newmethod)param_new, gensym("param"), A_GIMME, 0); class_addcreator((t_newmethod)param_new, gensym("tof/param"), A_GIMME, 0); + // GENERATE THE SYMBOLS + + s_vis = gensym("vis"); + s_empty = gensym("empty"); + s_clear = gensym("clear"); + s_set = gensym("set"); + s_obj = gensym("obj"); + s_nbx = gensym("nbx"); + s_bng = gensym("bng"); + s_slider = gensym("slider"); + s_hsl=gensym("hsl"); + s_knob = gensym("knob"); + s_tgl = gensym("tgl"); + s_symbolatom = gensym("symbolatom"); + s_sym = gensym("sym"); + s_text = gensym("text"); + s_cnv = gensym("cnv"); + + } diff --git a/src/paramGui.h b/src/paramGui.h index 8071377..c8d947a 100644 --- a/src/paramGui.h +++ b/src/paramGui.h @@ -16,22 +16,7 @@ typedef struct _paramGui 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* s_cnv; + t_symbol* root; t_symbol* receive; int waiting; @@ -45,7 +30,7 @@ typedef struct _paramGui static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { // Clear the canvas - pd_typedmess((t_pd*)x->childcanvas,x->s_clear,0,NULL); + pd_typedmess((t_pd*)x->childcanvas,s_clear,0,NULL); int pos_x = 0; int pos_y = 0; @@ -53,15 +38,15 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { t_atom atoms[22]; // This should be the maximum number of atoms // PINK HEADER - SETSYMBOL(&atoms[0],x->s_obj); + SETSYMBOL(&atoms[0],s_obj); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],x->s_cnv); + SETSYMBOL(&atoms[3],s_cnv); SETFLOAT(&atoms[4],15); SETFLOAT(&atoms[5],200); SETFLOAT(&atoms[6],20); - SETSYMBOL(&atoms[7],x->s_empty); - SETSYMBOL(&atoms[8],x->s_empty); + SETSYMBOL(&atoms[7],s_empty); + SETSYMBOL(&atoms[8],s_empty); SETSYMBOL(&atoms[9],x->path); SETFLOAT(&atoms[10],2); SETFLOAT(&atoms[11],12); @@ -73,7 +58,7 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { pd_forwardmess((t_pd*)x->childcanvas, 17, atoms); pos_y = pos_y + 23; - t_param* p = get_param_list(x->root); + int ac; t_atom* av; t_symbol* type; @@ -91,14 +76,16 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { t_atom* av_got; t_symbol* s_got; + + t_param* p = get_param_list(x->root); - - while (p) { + 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 ( send == NULL ) send = s_empty; + if ( receive == NULL ) receive = s_empty; /* // This code alows the positioning of the guis, but creates @@ -129,11 +116,11 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { type = atom_getsymbol(av); - if ( type == x->s_nbx ) { - SETSYMBOL(&atoms[0],x->s_obj); + if ( type == s_nbx ) { + SETSYMBOL(&atoms[0],s_obj); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],x->s_nbx); + SETSYMBOL(&atoms[3],s_nbx); SETFLOAT(&atoms[4],5); SETFLOAT(&atoms[5],14); SETFLOAT(&atoms[6],-1.0e+37); @@ -155,11 +142,11 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); pos_y = pos_y + GUI_Y_STEP; - } else if (type == x->s_bng) { - SETSYMBOL(&atoms[0],x->s_obj); + } else if (type == s_bng) { + SETSYMBOL(&atoms[0],s_obj); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],x->s_bng); + SETSYMBOL(&atoms[3],s_bng); SETFLOAT(&atoms[4],15); SETFLOAT(&atoms[5],250); SETFLOAT(&atoms[6],50); @@ -176,11 +163,11 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { SETFLOAT(&atoms[17],-1); pd_forwardmess((t_pd*)x->childcanvas, 18, atoms); 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); + } else if ( (type == s_slider) || (type == s_knob) || (type == s_hsl) ) { + SETSYMBOL(&atoms[0],s_obj); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],x->s_hsl); + SETSYMBOL(&atoms[3],s_hsl); SETFLOAT(&atoms[4],100); SETFLOAT(&atoms[5],15); if (ac > 1 && IS_A_FLOAT(av,1) ) { @@ -210,11 +197,11 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { pd_forwardmess((t_pd*)x->childcanvas, 22, atoms); pos_y = pos_y + GUI_Y_STEP; - } else if (type == x->s_tgl) { - SETSYMBOL(&atoms[0],x->s_obj); + } else if (type == s_tgl) { + SETSYMBOL(&atoms[0],s_obj); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); - SETSYMBOL(&atoms[3],x->s_tgl); + SETSYMBOL(&atoms[3],s_tgl); SETFLOAT(&atoms[4],15); SETFLOAT(&atoms[5],0); SETSYMBOL(&atoms[6],send); @@ -233,8 +220,8 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { pos_y = pos_y + GUI_Y_STEP; - } else if ( type == x->s_symbolatom || type == x->s_sym) { - SETSYMBOL(&atoms[0],x->s_symbolatom); + } else if ( type == s_symbolatom || type == s_sym) { + SETSYMBOL(&atoms[0],s_symbolatom); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); SETFLOAT(&atoms[3],17); @@ -247,7 +234,7 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { pd_forwardmess((t_pd*)x->childcanvas, 10,atoms); pos_y = pos_y + GUI_Y_STEP; } else { - SETSYMBOL(&atoms[0],x->s_text); + SETSYMBOL(&atoms[0],s_text); SETFLOAT(&atoms[1],pos_x); SETFLOAT(&atoms[2],pos_y); SETSYMBOL(&atoms[3],shortpath); @@ -256,16 +243,16 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { gui_built = 0; } - if ((gui_built) && (receive != x->s_empty) && (p->get)) { + if ((gui_built) && (receive != 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); + tof_send_anything_prepend(receive,s_got,ac_got,av_got,s_set); } } } p = p->next; - + } - + // Try to resize the canvas x->childcanvas->gl_screenx1 = x_position; x->childcanvas->gl_screeny1 = y_position; @@ -281,7 +268,7 @@ static void paramGui_buildCanvas(t_paramGui* x,int x_position,int y_position) { // Show canvas t_atom a; SETFLOAT(&a,1); - pd_typedmess((t_pd*)x->childcanvas,x->s_vis,1,&a); + pd_typedmess((t_pd*)x->childcanvas,s_vis,1,&a); } @@ -312,7 +299,7 @@ static void paramGui_bang(t_paramGui *x) { // Show canvas t_atom a; SETFLOAT(&a,1); - pd_typedmess((t_pd*)x->childcanvas,x->s_vis,1,&a); + pd_typedmess((t_pd*)x->childcanvas,s_vis,1,&a); } } else { @@ -358,24 +345,10 @@ static void *paramGui_new(t_symbol *s, int ac, t_atom *av) { 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"); - x->s_cnv = gensym("cnv"); + char buf[MAXPDSTRING]; - sprintf(buf, "#%lx", (t_int)x); + sprintf(buf, "#%lx", (long)x); x->receive = gensym(buf); pd_bind(&x->x_obj.ob_pd, x->receive ); |