| 1 | #include "m_pd.h" |
| 2 | #include <unistd.h> //sleep() |
| 3 | #include <stdio.h> //printf() |
| 4 | |
| 5 | static t_class *counter_class; |
| 6 | |
| 7 | typedef struct _counter { |
| 8 | t_object x_obj; |
| 9 | t_outlet *x_out2; |
| 10 | t_outlet *x_out3; |
| 11 | t_int i_count; |
| 12 | t_float step; |
| 13 | } t_counter; |
| 14 | |
| 15 | void counter_bang(t_counter *x) |
| 16 | { |
| 17 | x->i_count+=x->step; |
| 18 | t_float f=x->i_count; |
| 19 | t_float g=x->i_count*2; |
| 20 | outlet_float(x->x_obj.ob_outlet, f); |
| 21 | outlet_float(x->x_out2, g); |
| 22 | } |
| 23 | |
| 24 | void counter_reset(t_counter *x) |
| 25 | { |
| 26 | t_float f = x->i_count = 0; |
| 27 | outlet_float(x->x_obj.ob_outlet, f); |
| 28 | } |
| 29 | |
| 30 | void *counter_new(t_floatarg f) |
| 31 | { |
| 32 | t_counter *x = (t_counter *)pd_new(counter_class); |
| 33 | x->i_count=f; |
| 34 | x->step = 1; |
| 35 | outlet_new(&x->x_obj, &s_float); |
| 36 | x->x_out2 = outlet_new(&x->x_obj, &s_float); |
| 37 | x->x_out3 = outlet_new(&x->x_obj, &s_list); |
| 38 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("lol"), gensym("reset")); |
| 39 | floatinlet_new(&x->x_obj, &x->step); |
| 40 | return (void *)x; |
| 41 | } |
| 42 | |
| 43 | void counter_setup(void) { |
| 44 | counter_class = class_new(gensym("counter"), |
| 45 | (t_newmethod)counter_new, |
| 46 | 0, sizeof(t_counter), |
| 47 | CLASS_DEFAULT, |
| 48 | A_DEFFLOAT, 0 |
| 49 | ); |
| 50 | class_addbang(counter_class, counter_bang); |
| 51 | class_addmethod(counter_class, (t_method)counter_reset, gensym("reset"), 0); |
| 52 | } |
| 53 | |