Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabwrite.c
blob7f13632225eae6a7b657f1a071f2955b9ffb24b2
1 #include "../src/m_pd.h"
2 /* ------------------ tabwrite: control ------------------------ */
4 static t_class *tabwrite_class;
6 typedef struct _tabwrite
8 t_object x_obj;
9 t_symbol *x_arrayname;
10 t_clock *x_clock;
11 float x_ft1;
12 double x_updtime;
13 int x_set;
14 } t_tabwrite;
16 static void tabwrite_tick(t_tabwrite *x)
18 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
19 if (!a) bug("tabwrite_tick");
20 else garray_redraw(a);
21 x->x_set = 0;
22 x->x_updtime = clock_getsystime();
25 static void tabwrite_float(t_tabwrite *x, t_float f)
27 #ifdef ROCKBOX
28 int vecsize;
29 #else
30 int i, vecsize;
31 #endif
32 t_garray *a;
33 t_sample *vec;
35 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
36 pd_error(x, "%s: no such array", x->x_arrayname->s_name);
37 else if (!garray_getfloatarray(a, &vecsize, &vec))
38 pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name);
39 else
41 int n = x->x_ft1;
42 double timesince = clock_gettimesince(x->x_updtime);
43 if (n < 0) n = 0;
44 else if (n >= vecsize) n = vecsize-1;
45 vec[n] = ftofix(f);
46 if (timesince > 1000)
48 tabwrite_tick(x);
50 else
52 if (x->x_set == 0)
54 clock_delay(x->x_clock, 1000 - timesince);
55 x->x_set = 1;
61 static void tabwrite_set(t_tabwrite *x, t_symbol *s)
63 x->x_arrayname = s;
66 static void tabwrite_free(t_tabwrite *x)
68 clock_free(x->x_clock);
71 static void *tabwrite_new(t_symbol *s)
73 t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class);
74 x->x_ft1 = 0;
75 x->x_arrayname = s;
76 x->x_updtime = clock_getsystime();
77 x->x_clock = clock_new(x, (t_method)tabwrite_tick);
78 floatinlet_new(&x->x_obj, &x->x_ft1);
79 return (x);
82 void tabwrite_setup(void)
84 tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new,
85 (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0);
86 class_addfloat(tabwrite_class, (t_method)tabwrite_float);
87 class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0);