1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
14
******************************************************/
17
step~ : will make a unity step at a desired point in the signal-vector; the second input specifies a
18
length: after the so-specified time has elapsed, the step will toggle back to the previous
20
the length can be passed as an argument when creating the object
21
with length==1 you might do the dirac~ thing a little bit more complicated
22
with length==0 the output just toggles between 0 and 1 every time you bang the object
24
NOTE : the inlets do NOT specify any times but sample-NUMBERS; there are 64 samples in a signal-vector,
25
each "lasting" for 1/44100 secs.
30
/* ------------------------ step~ ----------------------------- */
32
static t_class *step_class;
46
static void step_bang(t_step *x)
48
x->wait4stop = x->length + (x->wait4start = x->position);
51
static void step_float(t_step *x, t_float where)
53
x->wait4stop = x->length +
55
(x->position = (where>0)*where)
59
static void step_setlength(t_step *x, t_float arg)
61
x->length = 1 + (arg>0)*arg;
66
static t_int *step_perform(t_int *w)
68
t_step *x = (t_step *)(w[1]);
69
t_sample *out = (t_sample *)(w[2]);
72
int toggle = x->toggle;
74
int wait4start = x->wait4start, wait4stop = x->wait4stop;
79
if (!wait4start--) toggle ^= 1;
80
else if (!wait4stop) toggle ^= 1;
85
x->wait4start = wait4start;
86
x->wait4stop = wait4stop;
92
static void step_dsp(t_step *x, t_signal **sp)
94
dsp_add(step_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
98
static void step_helper(void)
100
post("%c step~-object :: generates a unity-step", HEARTSYMBOL);
101
post("creation : \"dirac~ [<position> [<length>]]\" : create a rectangular window\n"
102
"\t\t\tat specified position and with specified length (in samples)\n"
103
"inlet1\t: <position>\t: create a rectangular window at new position\n"
104
"\t 'bang'\t: create a rectangular window at specified position\n"
105
"\t 'help'\t: view this\n"
106
"inlet2\t: <length>\t: define new window length ('0' will make a unity-step)\n"
107
"outlet\t: signal~");
111
static void *step_new(t_floatarg farg)
113
t_step *x = (t_step *)pd_new(step_class);
115
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
116
outlet_new(&x->x_obj, &s_signal);
119
x->wait4start = x->wait4stop = 0;
122
step_setlength(x, farg);
127
void step_tilde_setup(void)
129
step_class = class_new(gensym("step~"), (t_newmethod)step_new, 0,
130
sizeof(t_step), 0, A_DEFFLOAT, 0);
132
class_addfloat(step_class, step_float);
133
class_addbang(step_class, step_bang);
134
class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), A_FLOAT, 0);
135
class_addmethod(step_class, (t_method)step_dsp, gensym("dsp"), 0);
137
class_addmethod(step_class, (t_method)step_helper, gensym("help"), 0);
139
zexy_register("step~");