diff options
author | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-10-24 23:41:59 +0000 |
---|---|---|
committer | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-10-24 23:41:59 +0000 |
commit | fbe904db7e926e731e711665d244798d26ca8064 (patch) | |
tree | 0768fca51498c6668dbc956e12cbb8a3373ccd36 | |
parent | c8fdbe3013f1ac6c7e5bca00ec57aff59d8354fd (diff) |
Modified increment
svn path=/trunk/externals/tof/; revision=12665
-rw-r--r-- | help/increment-help.pd | 73 | ||||
-rw-r--r-- | src/increment.c | 81 |
2 files changed, 85 insertions, 69 deletions
diff --git a/help/increment-help.pd b/help/increment-help.pd index 3efa96c..8892e1d 100644 --- a/help/increment-help.pd +++ b/help/increment-help.pd @@ -1,53 +1,42 @@ #N canvas 1174 80 640 574 10; #X obj 22 -23 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 0; -#X text 27 11 author: mrtoftrash@gmail.com; -#X text 27 22 version: 2009-05-07 (initial release); -#X msg 101 166 3; -#X msg 62 166 6; -#X obj 306 347 print; +#X text 26 15 author: mrtoftrash@gmail.com; +#X msg 115 181 3; +#X msg 76 181 6; #X text 27 -24 description: increment a number.; #X text 28 0 tags: flow counter; -#X obj 27 251 increment; -#X msg 134 182 1; -#X msg 166 182 -1; #X obj 27 120 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X obj 27 279 print; -#X obj 305 287 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 --1 -1; -#X obj 306 316 increment 10 3; -#X text 22 89 First inlet:; -#X text 22 100 Bang: Outputs and increments the value.; -#X text 60 147 Second inlet: sets the value; -#X text 135 162 Third inlet: sets the step(incrementation) amount; -#X obj 49 479 print; -#X obj 49 321 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +#X text 24 82 First inlet:; +#X obj 38 427 print; +#X obj 38 317 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#X msg 72 349 set 43; -#X msg 96 376 step 5; -#X msg 125 402 reset; -#X obj 49 448 increment 10 3; -#X text 298 248 Argument 1: start value (defaults to 0); -#X text 298 263 Argument 2: step(incrementation) value (defaults to -1); -#X text 118 349 Set the start value; -#X text 144 376 Set the step value; -#X text 171 400 Reset to the start value; +#X msg 61 345 set 43; +#X text 160 387 Argument 1: start value (defaults to 0); #X obj 166 211 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#X text 188 205 Fourth inlet: resets; -#X connect 3 0 8 1; -#X connect 4 0 8 1; -#X connect 8 0 12 0; -#X connect 9 0 8 2; -#X connect 10 0 8 2; -#X connect 11 0 8 0; -#X connect 13 0 14 0; -#X connect 14 0 5 0; -#X connect 20 0 24 0; -#X connect 21 0 24 0; -#X connect 22 0 24 0; -#X connect 23 0 24 0; -#X connect 24 0 19 0; -#X connect 30 0 8 3; +#X obj 27 251 tof/increment; +#X obj 38 396 tof/increment 10 3; +#X text 26 30 version: 2009-10-23 (two inlet version); +#X text 107 345 Set the value; +#X text 135 145 Second inlet:; +#X text 150 175 bang: resets to 0; +#X text 149 162 float: sets value; +#X text 69 96 bang: outputs and increments the value; +#X text 70 109 float: sets increment amount and outputs incremented +value; +#X text 160 402 Argument 2: incrementation amount (defaults to 1); +#X msg 51 139 2; +#X msg 78 367 1; +#X connect 2 0 14 1; +#X connect 3 0 14 1; +#X connect 6 0 14 0; +#X connect 10 0 15 0; +#X connect 11 0 15 0; +#X connect 13 0 14 1; +#X connect 14 0 7 0; +#X connect 15 0 9 0; +#X connect 24 0 14 0; +#X connect 25 0 15 0; diff --git a/src/increment.c b/src/increment.c index b5a8a59..16ac0d6 100644 --- a/src/increment.c +++ b/src/increment.c @@ -1,6 +1,8 @@ #include "m_pd.h" static t_class *increment_class; +static t_class *increment_inlet2_class; +struct _increment_inlet2; typedef struct _increment { t_object x_obj; @@ -8,10 +10,17 @@ typedef struct _increment { t_float value; t_float inc; t_outlet* outlet1; - t_float start; + //t_float start; + struct _increment_inlet2* inlet2; //t_outlet* outlet2; } t_increment; +typedef struct _increment_inlet2 { + t_object x_obj; + t_increment *x; +} t_increment_inlet2; + + static void increment_bang(t_increment *x) { @@ -22,9 +31,7 @@ static void increment_bang(t_increment *x) x->value = x->value + x->inc; } outlet_float(x->outlet1,x->value); - - - + } /* static void increment_float(t_increment *x, t_float f) @@ -34,43 +41,48 @@ static void increment_float(t_increment *x, t_float f) } */ -static void increment_step(t_increment *x, t_float f) +static void increment_float(t_increment *x, t_float f) { x->inc = f; + increment_bang(x); } -static void increment_reset(t_increment *x) +static void increment_inlet2_bang(t_increment_inlet2 *x) { - //post("before"); - // post("start:%d",(int)x->start); - // post("value:%d",(int)x->value); + - x->value = x->start; - x->reset = 1; + x->x->value = 0; + x->x->reset = 1; - // post("after"); - //post("start:%d",(int)x->start); - //post("value:%d",(int)x->value); + } + static void increment_set(t_increment *x, t_float f) { - - - x->value = f; - x->start = f; x->reset = 1; +} + +static void increment_inlet2_float(t_increment_inlet2 *x, t_float f) +{ + + //post("before"); + // post("start:%d",(int)x->start); + // post("value:%d",(int)x->value); + increment_set(x->x, f); + // post("after"); + //post("start:%d",(int)x->start); + //post("value:%d",(int)x->value); } - /* void increment_list(t_increment *x,t_symbol *s, int argc, t_atom *argv) { @@ -109,19 +121,25 @@ void *increment_new(t_symbol *s, int argc, t_atom *argv) x->inc = 1; } - x->start = x->value; + //x->start = x->value; //post("start:%d",(int)x->start); //post("value:%d",(int)x->value); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, - gensym("float"), gensym("set")); + //inlet_new(&x->x_obj, &x->x_obj.ob_pd, + // gensym("float"), gensym("set")); - floatinlet_new(&x->x_obj, &x->inc); + //floatinlet_new(&x->x_obj, &x->inc); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, - gensym("bang"), gensym("reset")); + //inlet_new(&x->x_obj, &x->x_obj.ob_pd, + // gensym("bang"), gensym("reset")); + + t_increment_inlet2 *inlet2 = (t_increment_inlet2 *)pd_new(increment_inlet2_class); + inlet2->x = x; + x->inlet2 = inlet2; + + inlet_new((t_object *)x, (t_pd *)inlet2, 0, 0); x->outlet1 = outlet_new(&x->x_obj, &s_float); //x->outlet2 = outlet_new(&x->x_obj, &s_float); @@ -138,17 +156,26 @@ void increment_setup(void) { A_GIMME, 0); class_addbang (increment_class, increment_bang); - //class_addfloat (increment_class, increment_float); + class_addfloat (increment_class, increment_float); class_addmethod(increment_class, (t_method)increment_set, gensym("set"), A_DEFFLOAT, 0); + +increment_inlet2_class = class_new(gensym("increment_inlet2"), + 0, 0, sizeof(t_increment_inlet2), CLASS_PD | CLASS_NOINLET, 0); + + class_addbang(increment_inlet2_class, increment_inlet2_bang); + class_addfloat(increment_inlet2_class, increment_inlet2_float); + + + /* class_addmethod(increment_class, (t_method)increment_step, gensym("step"), A_DEFFLOAT, 0); class_addmethod(increment_class, (t_method)increment_reset, gensym("reset"), 0); - + */ //class_addlist (increment_class, increment_list); } |