1 #include "../src/m_pd.h"
2 /* ------------------ tabwrite: control ------------------------ */
4 static t_class
*tabwrite_class
;
6 typedef struct _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
);
22 x
->x_updtime
= clock_getsystime();
25 static void tabwrite_float(t_tabwrite
*x
, t_float f
)
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
);
42 double timesince
= clock_gettimesince(x
->x_updtime
);
44 else if (n
>= vecsize
) n
= vecsize
-1;
54 clock_delay(x
->x_clock
, 1000 - timesince
);
61 static void tabwrite_set(t_tabwrite
*x
, t_symbol
*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
);
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
);
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);