summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabwrite~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabwrite~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabwrite~.c131
1 files changed, 0 insertions, 131 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabwrite~.c b/apps/plugins/pdbox/PDa/intern/tabwrite~.c
index 47a49cd833..6f9113c30c 100644
--- a/apps/plugins/pdbox/PDa/intern/tabwrite~.c
+++ b/apps/plugins/pdbox/PDa/intern/tabwrite~.c
@@ -131,134 +131,3 @@ void tabwrite_tilde_setup(void)
131 class_addfloat(tabwrite_tilde_class, tabwrite_tilde_float); 131 class_addfloat(tabwrite_tilde_class, tabwrite_tilde_float);
132} 132}
133 133
134#include <m_pd.h>
135#include <m_fixed.h>
136
137static t_class *tabwrite_tilde_class;
138
139typedef struct _tabwrite_tilde
140{
141 t_object x_obj;
142 int x_phase;
143 int x_nsampsintab;
144 t_sample *x_vec;
145 t_symbol *x_arrayname;
146 t_clock *x_clock;
147 float x_f;
148} t_tabwrite_tilde;
149
150static void tabwrite_tilde_tick(t_tabwrite_tilde *x);
151
152static void *tabwrite_tilde_new(t_symbol *s)
153{
154 t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class);
155 x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick);
156 x->x_phase = 0x7fffffff;
157 x->x_arrayname = s;
158 x->x_f = 0;
159 return (x);
160}
161
162static t_int *tabwrite_tilde_perform(t_int *w)
163{
164 t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
165 t_sample *in = (t_sample *)(w[2]);
166 int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
167 if (!x->x_vec) goto bad;
168
169 if (endphase > phase)
170 {
171 int nxfer = endphase - phase;
172 t_sample *fp = x->x_vec + phase;
173 if (nxfer > n) nxfer = n;
174 phase += nxfer;
175 while (nxfer--)
176 {
177 t_sample f = *in++;
178 *fp++ = f;
179 }
180 if (phase >= endphase)
181 {
182 clock_delay(x->x_clock, 0);
183 phase = 0x7fffffff;
184 }
185 x->x_phase = phase;
186 }
187bad:
188 return (w+4);
189}
190
191void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
192{
193 t_garray *a;
194
195 x->x_arrayname = s;
196 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
197 {
198 if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
199 x->x_arrayname->s_name);
200 x->x_vec = 0;
201 }
202 else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
203 {
204 error("%s: bad template for tabwrite~", x->x_arrayname->s_name);
205 x->x_vec = 0;
206 }
207 else garray_usedindsp(a);
208}
209
210static void tabwrite_tilde_dsp(t_tabwrite_tilde *x, t_signal **sp)
211{
212 tabwrite_tilde_set(x, x->x_arrayname);
213 dsp_add(tabwrite_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
214}
215
216static void tabwrite_tilde_bang(t_tabwrite_tilde *x)
217{
218 x->x_phase = 0;
219}
220
221static void tabwrite_tilde_float(t_tabwrite_tilde *x,t_float n)
222{
223 if (n < x->x_nsampsintab)
224 x->x_phase = n;
225 else
226 x->x_phase = 0;
227}
228
229static void tabwrite_tilde_stop(t_tabwrite_tilde *x)
230{
231 if (x->x_phase != 0x7fffffff)
232 {
233 tabwrite_tilde_tick(x);
234 x->x_phase = 0x7fffffff;
235 }
236}
237
238static void tabwrite_tilde_tick(t_tabwrite_tilde *x)
239{
240 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
241 if (!a) bug("tabwrite_tilde_tick");
242 else garray_redraw(a);
243}
244
245static void tabwrite_tilde_free(t_tabwrite_tilde *x)
246{
247 clock_free(x->x_clock);
248}
249
250void tabwrite_tilde_setup(void)
251{
252 tabwrite_tilde_class = class_new(gensym("tabwrite~"),
253 (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free,
254 sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
255 CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f);
256 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp,
257 gensym("dsp"), 0);
258 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set,
259 gensym("set"), A_SYMBOL, 0);
260 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop,
261 gensym("stop"), 0);
262 class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang);
263 class_addfloat(tabwrite_tilde_class, tabwrite_tilde_float);
264}