1
/* --------------------- vthreshold ----------------------------- */
6
static t_class *vthreshold_class;
8
typedef struct _vthreshold
11
t_outlet *x_outlet1; /* bang out for high thresh */
12
t_outlet *x_outlet2; /* bang out for low thresh */
13
int *x_state; /* 1 = high, 0 = low */
15
float x_hithresh; /* value of high vthreshold */
16
float x_lothresh; /* value of low vthreshold */
17
float x_hideadtime; /* hi dead */
18
float x_lodeadtime; /* lo dead */
21
/* "set" message to specify vthresholds and dead times */
22
static void vthreshold_set(t_vthreshold *x,
23
t_floatarg hithresh, t_floatarg hideadtime,
24
t_floatarg lothresh, t_floatarg lodeadtime,
27
if (lothresh > hithresh)
29
x->x_hithresh = hithresh;
30
x->x_hideadtime = hideadtime;
31
x->x_lothresh = lothresh;
32
x->x_lodeadtime = lodeadtime;
33
freebytes(x->x_state,x->x_n);
35
x->x_state = (int *)getbytes(sizeof(int)*x->x_n);
36
memset(x->x_state , 0, x->x_n);
39
static t_vthreshold *vthreshold_new(t_floatarg hithresh,
40
t_floatarg hideadtime, t_floatarg lothresh, t_floatarg lodeadtime, t_floatarg n)
42
t_vthreshold *x = (t_vthreshold *)
43
pd_new(vthreshold_class);
44
x->x_state = 0; /* low state */
45
x->x_outlet1 = outlet_new(&x->x_obj, gensym("float"));
46
x->x_outlet2 = outlet_new(&x->x_obj, gensym("float"));
47
vthreshold_set(x, hithresh, hideadtime, lothresh, lodeadtime, n);
51
static void vthreshold_free(t_vthreshold *x)
53
freebytes(x->x_state,x->x_n);
56
static void vthreshold_perform(t_vthreshold *x, t_symbol *s, int argc, t_atom *argv)
62
if (argc>x->x_n) argc=x->x_n;
66
f=atom_getfloat(argv++);
72
outlet_float(x->x_outlet1, (float)i); // on
80
outlet_float(x->x_outlet2, (float)i); // off
89
static void vthreshold_ff(t_vthreshold *x)
91
freebytes(x->x_state,x->x_n);
94
void vthreshold_setup( void)
96
vthreshold_class = class_new(gensym("vthreshold"),
97
(t_newmethod)vthreshold_new, (t_method)vthreshold_free,
98
sizeof(t_vthreshold), 0,
99
A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
101
class_addlist(vthreshold_class, (t_method)vthreshold_perform);
102
class_addmethod(vthreshold_class, (t_method)vthreshold_set,
103
gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
104
// class_addmethod(vthreshold_class, (t_method)vthreshold_ft1,
105
// gensym("ft1"), A_FLOAT, 0);