summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabread.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabread.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabread.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabread.c b/apps/plugins/pdbox/PDa/intern/tabread.c
new file mode 100644
index 0000000000..5cd51b3036
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/tabread.c
@@ -0,0 +1,104 @@
1#include <m_pd.h>
2
3/* ---------- tabread: control, non-interpolating ------------------------ */
4
5static t_class *tabread_class;
6
7typedef struct _tabread
8{
9 t_object x_obj;
10 t_symbol *x_arrayname;
11} t_tabread;
12
13static void tabread_float(t_tabread *x, t_float f)
14{
15 t_garray *a;
16 int npoints;
17 t_sample *vec;
18
19 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
20 pd_error(x, "%s: no such array", x->x_arrayname->s_name);
21 else if (!garray_getfloatarray(a, &npoints, &vec))
22 pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name);
23 else
24 {
25 int n = f;
26 if (n < 0) n = 0;
27 else if (n >= npoints) n = npoints - 1;
28 outlet_float(x->x_obj.ob_outlet, (npoints ? fixtof(vec[n]) : 0));
29 }
30}
31
32static void tabread_set(t_tabread *x, t_symbol *s)
33{
34 x->x_arrayname = s;
35}
36
37static void *tabread_new(t_symbol *s)
38{
39 t_tabread *x = (t_tabread *)pd_new(tabread_class);
40 x->x_arrayname = s;
41 outlet_new(&x->x_obj, &s_float);
42 return (x);
43}
44
45void tabread_setup(void)
46{
47 tabread_class = class_new(gensym("tabread"), (t_newmethod)tabread_new,
48 0, sizeof(t_tabread), 0, A_DEFSYM, 0);
49 class_addfloat(tabread_class, (t_method)tabread_float);
50 class_addmethod(tabread_class, (t_method)tabread_set, gensym("set"),
51 A_SYMBOL, 0);
52}
53#include <m_pd.h>
54
55/* ---------- tabread: control, non-interpolating ------------------------ */
56
57static t_class *tabread_class;
58
59typedef struct _tabread
60{
61 t_object x_obj;
62 t_symbol *x_arrayname;
63} t_tabread;
64
65static void tabread_float(t_tabread *x, t_float f)
66{
67 t_garray *a;
68 int npoints;
69 t_sample *vec;
70
71 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
72 pd_error(x, "%s: no such array", x->x_arrayname->s_name);
73 else if (!garray_getfloatarray(a, &npoints, &vec))
74 pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name);
75 else
76 {
77 int n = f;
78 if (n < 0) n = 0;
79 else if (n >= npoints) n = npoints - 1;
80 outlet_float(x->x_obj.ob_outlet, (npoints ? fixtof(vec[n]) : 0));
81 }
82}
83
84static void tabread_set(t_tabread *x, t_symbol *s)
85{
86 x->x_arrayname = s;
87}
88
89static void *tabread_new(t_symbol *s)
90{
91 t_tabread *x = (t_tabread *)pd_new(tabread_class);
92 x->x_arrayname = s;
93 outlet_new(&x->x_obj, &s_float);
94 return (x);
95}
96
97void tabread_setup(void)
98{
99 tabread_class = class_new(gensym("tabread"), (t_newmethod)tabread_new,
100 0, sizeof(t_tabread), 0, A_DEFSYM, 0);
101 class_addfloat(tabread_class, (t_method)tabread_float);
102 class_addmethod(tabread_class, (t_method)tabread_set, gensym("set"),
103 A_SYMBOL, 0);
104}