aboutsummaryrefslogtreecommitdiff
path: root/src/param.c
diff options
context:
space:
mode:
authorThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-07 00:41:31 +0000
committerThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-07 00:41:31 +0000
commitcd658ffed1329080f06f84e890dcda4302ca5864 (patch)
treeac51de57a2ff6289dc8b06ec29876091fe5534e7 /src/param.c
parentdcd3ce848a86fc70339ed94432d96aee73d63e62 (diff)
replacing the old param with the new param
svn path=/trunk/externals/tof/; revision=12553
Diffstat (limited to 'src/param.c')
-rw-r--r--src/param.c302
1 files changed, 184 insertions, 118 deletions
diff --git a/src/param.c b/src/param.c
index 6551748..2aab6aa 100644
--- a/src/param.c
+++ b/src/param.c
@@ -20,8 +20,6 @@
*/
-
-
#include "tof.h"
#include "param.h"
@@ -29,55 +27,67 @@ extern int sys_noloadbang;
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;
- int noloadbang;
-} t_param;
-
-typedef struct _param_inlet2
-{
- t_object x_obj;
- t_param *p_owner;
-} t_param_inlet2;
+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;
+} t_paramClass;
+typedef struct _paramClass_inlet2
+{
+ t_object x_obj;
+ t_paramClass *p_owner;
+} t_paramClass_inlet2;
-static void param_bang(t_param *x)
+static void paramClass_bang(t_paramClass *x)
{
- if ( x->x_param) {
- param_output(x->x_param,x->x_obj.ob_outlet);
+ outlet_anything(x->outlet, x->selector, x->ac, x->av);
- //if (PARAMECHO) param_send_prepend(x->x_param, x->s_PARAM ,x->x_param->path );
- if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_param->send ,x->s_set );
- }
+ if(x->selector != &s_bang ) tof_send_anything_prepend(x->send,x->selector,x->ac,x->av,x->set_s );
+
}
-static void param_loadbang(t_param *x)
+static void paramClass_loadbang(t_paramClass *x)
{
if (!sys_noloadbang && !x->noloadbang)
- param_bang(x);
+ paramClass_bang(x);
}
-static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av)
+static void paramClass_anything(t_paramClass *x, t_symbol *s, int ac, t_atom *av)
{
#ifdef PARAMDEBUG
post("RECEIVING SOMETHING");
#endif
- if ( x->x_param) set_param_anything(x->x_param,s,ac,av);
+ 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);
+ }
- param_bang(x);
+ paramClass_bang(x);
}
@@ -86,120 +96,176 @@ static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av)
// SECOND INLET METHOD
-static void param_inlet2_anything(t_param_inlet2 *p, t_symbol *s, int ac, t_atom *av)
+static void paramClass_inlet2_anything(t_paramClass_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);
+ paramClass_anything(p->p_owner, s,ac,av);
}
// DECONSTRUCTOR
-static void param_free(t_param *x)
+static void paramClass_free(t_paramClass *x)
{
- if(x->x_param_inlet2) pd_free((t_pd *)x->x_param_inlet2);
+ if(x->inlet2) pd_free((t_pd *)x->inlet2);
- if (x->x_param) {
- pd_unbind(&x->x_obj.ob_pd, x->x_param->receive);
- param_unregister(x->x_param);
- }
+ 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) {
+ //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) {
+ *ac = x->gac;
+ *av = x->gav;
+}
+
+
+
// CONSTRUCTOR
-static void *param_new(t_symbol *s, int ac, t_atom *av)
+static void* paramClass_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;
+ t_paramClass *x = (t_paramClass *)pd_new(param_class);
- // GET THE CURRENT CANVAS
- t_canvas* canvas=tof_get_canvas();
+
+ // GET THE CURRENT CANVAS
+ t_canvas* canvas=tof_get_canvas();
- // GET THE NAME
- t_symbol* name = param_get_name(ac,av);
+ // GET THE NAME
+ t_symbol* name = param_get_name(ac,av);
- if (name) {
-
- t_symbol* path = param_get_path(canvas,name);
- t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas));
-
-
- // FIND PARAM VALUE
- // A. In canvas' arguments
- // B. In object's arguments
- // C. Defaults to a bang
+ if (!name) return NULL;
- int ac_p = 0;
- t_atom* av_p = NULL;
+ t_symbol* path = param_get_path(canvas,name);
+ t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas));
-
- // 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);
+ x->param = param_register(x,root,path,\
+ (t_paramGetMethod) paramClass_get,\
+ (t_paramSaveMethod) paramClass_save,\
+ (t_paramGUIMethod) paramClass_GUI);
- // 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;
- //}
- }
+ 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;
+ //}
+ }
- // FIND THE NO LOADBANG TAG: /nlb
- int i;
- x->noloadbang = 0;
- for ( i =0; i < ac; i++) {
- if ( IS_A_SYMBOL(av,i) && (strcmp("/nlb",atom_getsymbol(av+i)->s_name) == 0)) {
- x->noloadbang = 1;
- break;
- }
+
+ // FIND THE NO LOADBANG TAG: /nlb
+ int i;
+ x->noloadbang = 0;
+
+ for ( i =0; i < ac; i++) {
+ if ( IS_A_SYMBOL(av,i) && (strcmp("/nlb",atom_getsymbol(av+i)->s_name) == 0)) {
+ x->noloadbang = 1;
+ break;
}
+ }
+
+
-
- //FIND THE GUI OPTIONS: /g
- int ac_g = 0;
- t_atom* av_g = NULL;
+ //FIND THE GUI OPTIONS: /g
+ int ac_g = 0;
+ t_atom* av_g = NULL;
// There could be a problem if the the name is also /g
tof_find_tagged_argument('/',gensym("/g"), ac, av,&ac_g,&av_g);
+ x->gac = ac_g;
+ x->gav = getbytes(x->gac * sizeof(*(x->gav)));
+ tof_copy_atoms(av_g,x->gav,x->gac);
- x->x_param = param_register(root,path,ac_p,av_p,ac_g,av_g);
+
+ 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->x_param->receive->s_name);
- post("send:%s",x->x_param->send->s_name);
+ 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->x_param->receive );
- // CREATE INLETS AND OUTLETS
- inlet_new((t_object *)x, (t_pd *)p, 0, 0);
- outlet_new(&x->x_obj, &s_list);
+ pd_bind(&x->x_obj.ob_pd, x->receive );
- } else {
+ // 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);
- pd_error(x,"Could not create param. See possible errors above.");
- }
+
+
+ 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);
}
@@ -207,18 +273,18 @@ static void *param_new(t_symbol *s, int ac, t_atom *av)
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);
+ (t_newmethod)paramClass_new, (t_method)paramClass_free,
+ sizeof(t_paramClass), 0, A_GIMME, 0);
- class_addanything(param_class, param_anything);
- class_addbang(param_class, param_bang);
+ class_addanything(param_class, paramClass_anything);
+ class_addbang(param_class, paramClass_bang);
- class_addmethod(param_class, (t_method)param_loadbang, gensym("loadbang"), 0);
+ class_addmethod(param_class, (t_method)paramClass_loadbang, gensym("loadbang"), 0);
param_inlet2_class = class_new(gensym("_param_inlet2"),
- 0, 0, sizeof(t_param_inlet2), CLASS_PD | CLASS_NOINLET, 0);
+ 0, 0, sizeof(t_paramClass_inlet2), CLASS_PD | CLASS_NOINLET, 0);
- class_addanything(param_inlet2_class, param_inlet2_anything);
+ class_addanything(param_inlet2_class, paramClass_inlet2_anything);
}