Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin...
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabread.c
blob5cd51b30362a2c15928f35ba80998749fb557b95
1 #include <m_pd.h>
3 /* ---------- tabread: control, non-interpolating ------------------------ */
5 static t_class *tabread_class;
7 typedef struct _tabread
9 t_object x_obj;
10 t_symbol *x_arrayname;
11 } t_tabread;
13 static void tabread_float(t_tabread *x, t_float f)
15 t_garray *a;
16 int npoints;
17 t_sample *vec;
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
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));
32 static void tabread_set(t_tabread *x, t_symbol *s)
34 x->x_arrayname = s;
37 static void *tabread_new(t_symbol *s)
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);
45 void tabread_setup(void)
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);
53 #include <m_pd.h>
55 /* ---------- tabread: control, non-interpolating ------------------------ */
57 static t_class *tabread_class;
59 typedef struct _tabread
61 t_object x_obj;
62 t_symbol *x_arrayname;
63 } t_tabread;
65 static void tabread_float(t_tabread *x, t_float f)
67 t_garray *a;
68 int npoints;
69 t_sample *vec;
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
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));
84 static void tabread_set(t_tabread *x, t_symbol *s)
86 x->x_arrayname = s;
89 static void *tabread_new(t_symbol *s)
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);
97 void tabread_setup(void)
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);