diff options
-rw-r--r-- | list_sum/help-list_sum.pd | 41 | ||||
-rw-r--r-- | list_sum/list_sum.c | 45 |
2 files changed, 53 insertions, 33 deletions
diff --git a/list_sum/help-list_sum.pd b/list_sum/help-list_sum.pd index 4b98f79..7259add 100644 --- a/list_sum/help-list_sum.pd +++ b/list_sum/help-list_sum.pd @@ -1,22 +1,41 @@ -#N canvas 0 0 520 251 10; -#X obj 84 137 list_sum; -#X floatatom 127 166 0 0 0 3 length - -; -#X floatatom 84 186 0 0 0 3 total - -; -#X msg 84 55 200.5 498 166.3 81.7 94.4; +#N canvas 0 0 707 528 10; +#X obj 84 255 list_sum; +#X floatatom 101 358 0 0 0 3 length - -; +#X floatatom 84 391 0 0 0 3 total - -; #X msg 150 82 set 2 100; #X msg 149 98 set 2 498; #X msg 32 106 clear; #X msg 149 121 set 5 777; -#X text 87 40 a list in the inlet calculates the sum of its elements. -; #X text 215 81 individual elements can be set; -#X text 206 168 list_sum; -#X text 206 183 calculate the sum of elements in a list.; -#X text 207 198 Edward Kelly 2007; +#X text 206 286 list_sum; +#X text 205 327 Edward Kelly 2007; +#X msg 84 55 all 200.5 498 166.3 81.7 94.4; +#X text 84 36 all in the left inlet calculates the sum of its elements. +; +#X msg 173 145 3; +#X msg 173 162 9; +#X msg 211 162 4; +#X msg 211 179 8; +#X text 200 144 max length; +#X text 241 162 wrap value; +#X obj 300 116 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 331 116 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 206 301 calculate the sum of elements in a list \, wrapping +the list.; #X connect 0 0 2 0; #X connect 0 1 1 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 0 0; #X connect 6 0 0 0; -#X connect 7 0 0 0; +#X connect 10 0 0 0; +#X connect 12 0 0 1; +#X connect 13 0 0 1; +#X connect 14 0 0 2; +#X connect 15 0 0 2; +#X connect 18 0 13 0; +#X connect 18 0 14 0; +#X connect 19 0 12 0; +#X connect 19 0 15 0; diff --git a/list_sum/list_sum.c b/list_sum/list_sum.c index 81aef40..6a2cee9 100644 --- a/list_sum/list_sum.c +++ b/list_sum/list_sum.c @@ -29,10 +29,10 @@ typedef struct _list_sum t_object x_obj; t_contents contents; t_float total, highest, maxlen, wrap, reset, accum, remainder, firsttime; - t_outlet *sum, *length, *remains, *diff; + t_outlet *sum, *length; /*, *remains, *diff;*/ } t_list_sum; -void list_sum_all(t_list_sum *x, int argc, t_atom *argv) +void list_sum_all(t_list_sum *x, t_symbol *s, int argc, t_atom *argv) { argc = argc < 1024 ? argc : 1024; int i, j, maxindex; @@ -98,22 +98,22 @@ void list_sum_set(t_list_sum *x, t_floatarg element, t_floatarg value) } //next: list_sum_follow - clock based? -void list_sum_follow(t_list_sum *x, t_floatarg index, t_floatarg value) -{ - int i = (int) index; - if(index == (int)x->reset || x->firsttime == 1) - { - x->accum = 0; - x->remainder = total; - } - float current = atom_getfloatarg(i, 1024, x->contents.list); - float diff = value - current; - x->accum += diff; - outlet_float(x->diff, x->accum); - x->remainder -=current; - outlet_float(x->remains, x->remainder); - x->firsttime = 0; -} +//void list_sum_follow(t_list_sum *x, t_symbol *s, t_floatarg index, t_floatarg value) +//{ +// int i = (int) index; +// if(index == (int)x->reset || x->firsttime == 1) +// { +// x->accum = 0; +// x->remainder = x->total; +// x->firsttime = 0; +// } +// float current = atom_getfloatarg(i, 1024, x->contents.list); +// float diff = value - current; +// x->accum += diff; +// outlet_float(x->diff, x->accum); +// x->remainder -=current; +// outlet_float(x->remains, x->remainder); +//} void list_sum_clear(t_list_sum *x) @@ -146,6 +146,7 @@ void *list_sum_new(t_symbol *s, int argc, t_atom *argv) x->highest = 0; x->maxlen = 1024; x->wrap = 1024; + x->reset = 16; x->firsttime = 1; for(i=0;i<1024;i++) { @@ -153,11 +154,11 @@ void *list_sum_new(t_symbol *s, int argc, t_atom *argv) } floatinlet_new(&x->x_obj, &x->maxlen); floatinlet_new(&x->x_obj, &x->wrap); - floatinlet_new(&x->x_obj, &x->reset); + // floatinlet_new(&x->x_obj, &x->reset); x->sum = outlet_new(&x->x_obj, &s_float); x->length = outlet_new(&x->x_obj, &s_float); - x->remains = outlet_new(&x->x_obj, &s_float); - x->diff = outlet_new(&x->x_obj, &s_float); + // x->remains = outlet_new(&x->x_obj, &s_float); + // x->diff = outlet_new(&x->x_obj, &s_float); return (void *)x; } @@ -170,7 +171,7 @@ void list_sum_setup(void) { post("|<<<calculate the sum of a list, with wrapping>>>|"); post("|<<<<<<<<<edward-------kelly-------2007>>>>>>>>>>|"); class_sethelpsymbol(list_sum_class, gensym("help-list_sum")); - class_addmethod(list_sum_class, (t_method)list_sum_follow, gensym("follow"), A_DEFFLOAT, A_DEFFLOAT, 0); + // class_addmethod(list_sum_class, (t_method)list_sum_follow, gensym("follow"), A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(list_sum_class, (t_method)list_sum_all, gensym("all"), A_GIMME, 0); class_addmethod(list_sum_class, (t_method)list_sum_clear, gensym("clear"), A_DEFFLOAT, 0); class_addmethod(list_sum_class, (t_method)list_sum_print, gensym("print"), A_DEFFLOAT, 0); |