summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabsend~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabsend~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabsend~.c196
1 files changed, 196 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabsend~.c b/apps/plugins/pdbox/PDa/intern/tabsend~.c
new file mode 100644
index 0000000000..4d7ac9007e
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/tabsend~.c
@@ -0,0 +1,196 @@
1
2#include <m_pd.h>
3#include <m_fixed.h>
4static t_class *tabsend_class;
5
6typedef struct _tabsend
7{
8 t_object x_obj;
9 t_sample *x_vec;
10 int x_graphperiod;
11 int x_graphcount;
12 t_symbol *x_arrayname;
13 t_clock *x_clock;
14 float x_f;
15} t_tabsend;
16
17static void tabsend_tick(t_tabsend *x);
18
19static void *tabsend_new(t_symbol *s)
20{
21 t_tabsend *x = (t_tabsend *)pd_new(tabsend_class);
22 x->x_graphcount = 0;
23 x->x_arrayname = s;
24 x->x_clock = clock_new(x, (t_method)tabsend_tick);
25 x->x_f = 0;
26 return (x);
27}
28
29static t_int *tabsend_perform(t_int *w)
30{
31 t_tabsend *x = (t_tabsend *)(w[1]);
32 t_sample *in = (t_sample *)(w[2]);
33 int n = w[3];
34 t_sample *dest = x->x_vec;
35 int i = x->x_graphcount;
36 if (!x->x_vec) goto bad;
37
38 while (n--)
39 {
40 t_sample f = *in++;
41 if (PD_BADFLOAT(f))
42 f = 0;
43 *dest++ = f;
44 }
45 if (!i--)
46 {
47 clock_delay(x->x_clock, 0);
48 i = x->x_graphperiod;
49 }
50 x->x_graphcount = i;
51bad:
52 return (w+4);
53}
54
55static void tabsend_dsp(t_tabsend *x, t_signal **sp)
56{
57 int i, vecsize;
58 t_garray *a;
59
60 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
61 {
62 if (*x->x_arrayname->s_name)
63 error("tabsend~: %s: no such array", x->x_arrayname->s_name);
64 }
65 else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
66 error("%s: bad template for tabsend~", x->x_arrayname->s_name);
67 else
68 {
69 int n = sp[0]->s_n;
70 int ticksper = sp[0]->s_sr/n;
71 if (ticksper < 1) ticksper = 1;
72 x->x_graphperiod = ticksper;
73 if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
74 if (n < vecsize) vecsize = n;
75 garray_usedindsp(a);
76 dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize);
77 }
78}
79
80static void tabsend_tick(t_tabsend *x)
81{
82 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
83 if (!a) bug("tabsend_tick");
84 else garray_redraw(a);
85}
86
87static void tabsend_free(t_tabsend *x)
88{
89 clock_free(x->x_clock);
90}
91
92void tabsend_tilde_setup(void)
93{
94 tabsend_class = class_new(gensym("tabsend~"), (t_newmethod)tabsend_new,
95 (t_method)tabsend_free, sizeof(t_tabsend), 0, A_DEFSYM, 0);
96 CLASS_MAINSIGNALIN(tabsend_class, t_tabsend, x_f);
97 class_addmethod(tabsend_class, (t_method)tabsend_dsp, gensym("dsp"), 0);
98}
99
100#include <m_pd.h>
101#include <m_fixed.h>
102static t_class *tabsend_class;
103
104typedef struct _tabsend
105{
106 t_object x_obj;
107 t_sample *x_vec;
108 int x_graphperiod;
109 int x_graphcount;
110 t_symbol *x_arrayname;
111 t_clock *x_clock;
112 float x_f;
113} t_tabsend;
114
115static void tabsend_tick(t_tabsend *x);
116
117static void *tabsend_new(t_symbol *s)
118{
119 t_tabsend *x = (t_tabsend *)pd_new(tabsend_class);
120 x->x_graphcount = 0;
121 x->x_arrayname = s;
122 x->x_clock = clock_new(x, (t_method)tabsend_tick);
123 x->x_f = 0;
124 return (x);
125}
126
127static t_int *tabsend_perform(t_int *w)
128{
129 t_tabsend *x = (t_tabsend *)(w[1]);
130 t_sample *in = (t_sample *)(w[2]);
131 int n = w[3];
132 t_sample *dest = x->x_vec;
133 int i = x->x_graphcount;
134 if (!x->x_vec) goto bad;
135
136 while (n--)
137 {
138 t_sample f = *in++;
139 if (PD_BADFLOAT(f))
140 f = 0;
141 *dest++ = f;
142 }
143 if (!i--)
144 {
145 clock_delay(x->x_clock, 0);
146 i = x->x_graphperiod;
147 }
148 x->x_graphcount = i;
149bad:
150 return (w+4);
151}
152
153static void tabsend_dsp(t_tabsend *x, t_signal **sp)
154{
155 int i, vecsize;
156 t_garray *a;
157
158 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
159 {
160 if (*x->x_arrayname->s_name)
161 error("tabsend~: %s: no such array", x->x_arrayname->s_name);
162 }
163 else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
164 error("%s: bad template for tabsend~", x->x_arrayname->s_name);
165 else
166 {
167 int n = sp[0]->s_n;
168 int ticksper = sp[0]->s_sr/n;
169 if (ticksper < 1) ticksper = 1;
170 x->x_graphperiod = ticksper;
171 if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
172 if (n < vecsize) vecsize = n;
173 garray_usedindsp(a);
174 dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize);
175 }
176}
177
178static void tabsend_tick(t_tabsend *x)
179{
180 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
181 if (!a) bug("tabsend_tick");
182 else garray_redraw(a);
183}
184
185static void tabsend_free(t_tabsend *x)
186{
187 clock_free(x->x_clock);
188}
189
190void tabsend_tilde_setup(void)
191{
192 tabsend_class = class_new(gensym("tabsend~"), (t_newmethod)tabsend_new,
193 (t_method)tabsend_free, sizeof(t_tabsend), 0, A_DEFSYM, 0);
194 CLASS_MAINSIGNALIN(tabsend_class, t_tabsend, x_f);
195 class_addmethod(tabsend_class, (t_method)tabsend_dsp, gensym("dsp"), 0);
196}