summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabreceive~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabreceive~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabreceive~.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabreceive~.c b/apps/plugins/pdbox/PDa/intern/tabreceive~.c
new file mode 100644
index 0000000000..82f2ff388a
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/tabreceive~.c
@@ -0,0 +1,122 @@
1#include <m_pd.h>
2#include <m_fixed.h>
3
4static t_class *tabreceive_class;
5
6typedef struct _tabreceive
7{
8 t_object x_obj;
9 t_sample *x_vec;
10 t_symbol *x_arrayname;
11} t_tabreceive;
12
13static t_int *tabreceive_perform(t_int *w)
14{
15 t_tabreceive *x = (t_tabreceive *)(w[1]);
16 t_sample *out = (t_sample *)(w[2]);
17 int n = w[3];
18 t_sample *from = x->x_vec;
19 if (from) while (n--) *out++ = *from++;
20 else while (n--) *out++ = 0;
21 return (w+4);
22}
23
24static void tabreceive_dsp(t_tabreceive *x, t_signal **sp)
25{
26 t_garray *a;
27 int vecsize;
28
29 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
30 {
31 if (*x->x_arrayname->s_name)
32 error("tabsend~: %s: no such array", x->x_arrayname->s_name);
33 }
34 else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
35 error("%s: bad template for tabreceive~", x->x_arrayname->s_name);
36 else
37 {
38 int n = sp[0]->s_n;
39 if (n < vecsize) vecsize = n;
40 garray_usedindsp(a);
41 dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize);
42 }
43}
44
45static void *tabreceive_new(t_symbol *s)
46{
47 t_tabreceive *x = (t_tabreceive *)pd_new(tabreceive_class);
48 x->x_arrayname = s;
49 outlet_new(&x->x_obj, &s_signal);
50 return (x);
51}
52
53void tabreceive_tilde_setup(void)
54{
55 tabreceive_class = class_new(gensym("tabreceive~"),
56 (t_newmethod)tabreceive_new, 0,
57 sizeof(t_tabreceive), 0, A_DEFSYM, 0);
58 class_addmethod(tabreceive_class, (t_method)tabreceive_dsp,
59 gensym("dsp"), 0);
60}
61
62#include <m_pd.h>
63#include <m_fixed.h>
64
65static t_class *tabreceive_class;
66
67typedef struct _tabreceive
68{
69 t_object x_obj;
70 t_sample *x_vec;
71 t_symbol *x_arrayname;
72} t_tabreceive;
73
74static t_int *tabreceive_perform(t_int *w)
75{
76 t_tabreceive *x = (t_tabreceive *)(w[1]);
77 t_sample *out = (t_sample *)(w[2]);
78 int n = w[3];
79 t_sample *from = x->x_vec;
80 if (from) while (n--) *out++ = *from++;
81 else while (n--) *out++ = 0;
82 return (w+4);
83}
84
85static void tabreceive_dsp(t_tabreceive *x, t_signal **sp)
86{
87 t_garray *a;
88 int vecsize;
89
90 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
91 {
92 if (*x->x_arrayname->s_name)
93 error("tabsend~: %s: no such array", x->x_arrayname->s_name);
94 }
95 else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
96 error("%s: bad template for tabreceive~", x->x_arrayname->s_name);
97 else
98 {
99 int n = sp[0]->s_n;
100 if (n < vecsize) vecsize = n;
101 garray_usedindsp(a);
102 dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize);
103 }
104}
105
106static void *tabreceive_new(t_symbol *s)
107{
108 t_tabreceive *x = (t_tabreceive *)pd_new(tabreceive_class);
109 x->x_arrayname = s;
110 outlet_new(&x->x_obj, &s_signal);
111 return (x);
112}
113
114void tabreceive_tilde_setup(void)
115{
116 tabreceive_class = class_new(gensym("tabreceive~"),
117 (t_newmethod)tabreceive_new, 0,
118 sizeof(t_tabreceive), 0, A_DEFSYM, 0);
119 class_addmethod(tabreceive_class, (t_method)tabreceive_dsp,
120 gensym("dsp"), 0);
121}
122