Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabplay~.c
blobd95bac0637e80ea764126ada48acc8565124152c
2 #ifndef ROCKBOX
3 #define FIXEDPOINT
4 #endif
6 #include "../src/m_pd.h"
7 #include <../src/m_fixed.h>
9 static t_class *tabplay_tilde_class;
11 typedef struct _tabplay_tilde
13 t_object x_obj;
14 t_outlet *x_bangout;
15 int x_phase;
16 int x_nsampsintab;
17 int x_limit;
18 t_sample *x_vec;
19 t_symbol *x_arrayname;
20 t_clock *x_clock;
21 } t_tabplay_tilde;
23 static void tabplay_tilde_tick(t_tabplay_tilde *x);
25 static void *tabplay_tilde_new(t_symbol *s)
27 t_tabplay_tilde *x = (t_tabplay_tilde *)pd_new(tabplay_tilde_class);
28 x->x_clock = clock_new(x, (t_method)tabplay_tilde_tick);
29 x->x_phase = 0x7fffffff;
30 x->x_limit = 0;
31 x->x_arrayname = s;
32 outlet_new(&x->x_obj, &s_signal);
33 x->x_bangout = outlet_new(&x->x_obj, &s_bang);
34 return (x);
37 static t_int *tabplay_tilde_perform(t_int *w)
39 t_tabplay_tilde *x = (t_tabplay_tilde *)(w[1]);
40 t_sample *out = (t_sample *)(w[2]), *fp;
41 int n = (int)(w[3]), phase = x->x_phase,
42 endphase = (x->x_nsampsintab < x->x_limit ?
43 x->x_nsampsintab : x->x_limit), nxfer, n3;
44 if (!x->x_vec || phase >= endphase)
45 goto zero;
47 nxfer = endphase - phase;
48 fp = x->x_vec + phase;
49 if (nxfer > n)
50 nxfer = n;
51 n3 = n - nxfer;
52 phase += nxfer;
53 while (nxfer--)
54 *out++ = *fp++;
55 if (phase >= endphase)
57 clock_delay(x->x_clock, 0);
58 x->x_phase = 0x7fffffff;
59 while (n3--)
60 *out++ = 0;
62 else x->x_phase = phase;
64 return (w+4);
65 zero:
66 while (n--) *out++ = 0;
67 return (w+4);
70 void tabplay_tilde_set(t_tabplay_tilde *x, t_symbol *s)
72 t_garray *a;
74 x->x_arrayname = s;
75 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
77 if (*s->s_name) pd_error(x, "tabplay~: %s: no such array",
78 x->x_arrayname->s_name);
79 x->x_vec = 0;
81 else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
83 error("%s: bad template for tabplay~", x->x_arrayname->s_name);
84 x->x_vec = 0;
86 else garray_usedindsp(a);
89 static void tabplay_tilde_dsp(t_tabplay_tilde *x, t_signal **sp)
91 tabplay_tilde_set(x, x->x_arrayname);
92 dsp_add(tabplay_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
95 static void tabplay_tilde_list(t_tabplay_tilde *x, t_symbol *s,
96 int argc, t_atom *argv)
98 long start = atom_getfloatarg(0, argc, argv);
99 long length = atom_getfloatarg(1, argc, argv);
101 #ifdef ROCKBOX
102 (void) s;
103 #endif
105 if (start < 0) start = 0;
106 if (length <= 0)
107 x->x_limit = 0x7fffffff;
108 else
109 x->x_limit = start + length;
110 x->x_phase = start;
113 static void tabplay_tilde_stop(t_tabplay_tilde *x)
115 x->x_phase = 0x7fffffff;
118 static void tabplay_tilde_tick(t_tabplay_tilde *x)
120 outlet_bang(x->x_bangout);
123 static void tabplay_tilde_free(t_tabplay_tilde *x)
125 clock_free(x->x_clock);
128 void tabplay_tilde_setup(void)
130 tabplay_tilde_class = class_new(gensym("tabplay~"),
131 (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free,
132 sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0);
133 class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_dsp,
134 gensym("dsp"), 0);
135 class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_stop,
136 gensym("stop"), 0);
137 class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_set,
138 gensym("set"), A_DEFSYM, 0);
139 class_addlist(tabplay_tilde_class, tabplay_tilde_list);