diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabwrite.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/tabwrite.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabwrite.c b/apps/plugins/pdbox/PDa/intern/tabwrite.c new file mode 100644 index 0000000000..8d6a6c0da8 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/tabwrite.c | |||
@@ -0,0 +1,168 @@ | |||
1 | #include <m_pd.h> | ||
2 | /* ------------------ tabwrite: control ------------------------ */ | ||
3 | |||
4 | static t_class *tabwrite_class; | ||
5 | |||
6 | typedef struct _tabwrite | ||
7 | { | ||
8 | t_object x_obj; | ||
9 | t_symbol *x_arrayname; | ||
10 | t_clock *x_clock; | ||
11 | float x_ft1; | ||
12 | double x_updtime; | ||
13 | int x_set; | ||
14 | } t_tabwrite; | ||
15 | |||
16 | static void tabwrite_tick(t_tabwrite *x) | ||
17 | { | ||
18 | t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); | ||
19 | if (!a) bug("tabwrite_tick"); | ||
20 | else garray_redraw(a); | ||
21 | x->x_set = 0; | ||
22 | x->x_updtime = clock_getsystime(); | ||
23 | } | ||
24 | |||
25 | static void tabwrite_float(t_tabwrite *x, t_float f) | ||
26 | { | ||
27 | int i, vecsize; | ||
28 | t_garray *a; | ||
29 | t_sample *vec; | ||
30 | |||
31 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
32 | pd_error(x, "%s: no such array", x->x_arrayname->s_name); | ||
33 | else if (!garray_getfloatarray(a, &vecsize, &vec)) | ||
34 | pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name); | ||
35 | else | ||
36 | { | ||
37 | int n = x->x_ft1; | ||
38 | double timesince = clock_gettimesince(x->x_updtime); | ||
39 | if (n < 0) n = 0; | ||
40 | else if (n >= vecsize) n = vecsize-1; | ||
41 | vec[n] = ftofix(f); | ||
42 | if (timesince > 1000) | ||
43 | { | ||
44 | tabwrite_tick(x); | ||
45 | } | ||
46 | else | ||
47 | { | ||
48 | if (x->x_set == 0) | ||
49 | { | ||
50 | clock_delay(x->x_clock, 1000 - timesince); | ||
51 | x->x_set = 1; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | |||
57 | static void tabwrite_set(t_tabwrite *x, t_symbol *s) | ||
58 | { | ||
59 | x->x_arrayname = s; | ||
60 | } | ||
61 | |||
62 | static void tabwrite_free(t_tabwrite *x) | ||
63 | { | ||
64 | clock_free(x->x_clock); | ||
65 | } | ||
66 | |||
67 | static void *tabwrite_new(t_symbol *s) | ||
68 | { | ||
69 | t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class); | ||
70 | x->x_ft1 = 0; | ||
71 | x->x_arrayname = s; | ||
72 | x->x_updtime = clock_getsystime(); | ||
73 | x->x_clock = clock_new(x, (t_method)tabwrite_tick); | ||
74 | floatinlet_new(&x->x_obj, &x->x_ft1); | ||
75 | return (x); | ||
76 | } | ||
77 | |||
78 | void tabwrite_setup(void) | ||
79 | { | ||
80 | tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new, | ||
81 | (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0); | ||
82 | class_addfloat(tabwrite_class, (t_method)tabwrite_float); | ||
83 | class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0); | ||
84 | } | ||
85 | #include <m_pd.h> | ||
86 | /* ------------------ tabwrite: control ------------------------ */ | ||
87 | |||
88 | static t_class *tabwrite_class; | ||
89 | |||
90 | typedef struct _tabwrite | ||
91 | { | ||
92 | t_object x_obj; | ||
93 | t_symbol *x_arrayname; | ||
94 | t_clock *x_clock; | ||
95 | float x_ft1; | ||
96 | double x_updtime; | ||
97 | int x_set; | ||
98 | } t_tabwrite; | ||
99 | |||
100 | static void tabwrite_tick(t_tabwrite *x) | ||
101 | { | ||
102 | t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); | ||
103 | if (!a) bug("tabwrite_tick"); | ||
104 | else garray_redraw(a); | ||
105 | x->x_set = 0; | ||
106 | x->x_updtime = clock_getsystime(); | ||
107 | } | ||
108 | |||
109 | static void tabwrite_float(t_tabwrite *x, t_float f) | ||
110 | { | ||
111 | int i, vecsize; | ||
112 | t_garray *a; | ||
113 | t_sample *vec; | ||
114 | |||
115 | if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) | ||
116 | pd_error(x, "%s: no such array", x->x_arrayname->s_name); | ||
117 | else if (!garray_getfloatarray(a, &vecsize, &vec)) | ||
118 | pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name); | ||
119 | else | ||
120 | { | ||
121 | int n = x->x_ft1; | ||
122 | double timesince = clock_gettimesince(x->x_updtime); | ||
123 | if (n < 0) n = 0; | ||
124 | else if (n >= vecsize) n = vecsize-1; | ||
125 | vec[n] = ftofix(f); | ||
126 | if (timesince > 1000) | ||
127 | { | ||
128 | tabwrite_tick(x); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | if (x->x_set == 0) | ||
133 | { | ||
134 | clock_delay(x->x_clock, 1000 - timesince); | ||
135 | x->x_set = 1; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | static void tabwrite_set(t_tabwrite *x, t_symbol *s) | ||
142 | { | ||
143 | x->x_arrayname = s; | ||
144 | } | ||
145 | |||
146 | static void tabwrite_free(t_tabwrite *x) | ||
147 | { | ||
148 | clock_free(x->x_clock); | ||
149 | } | ||
150 | |||
151 | static void *tabwrite_new(t_symbol *s) | ||
152 | { | ||
153 | t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class); | ||
154 | x->x_ft1 = 0; | ||
155 | x->x_arrayname = s; | ||
156 | x->x_updtime = clock_getsystime(); | ||
157 | x->x_clock = clock_new(x, (t_method)tabwrite_tick); | ||
158 | floatinlet_new(&x->x_obj, &x->x_ft1); | ||
159 | return (x); | ||
160 | } | ||
161 | |||
162 | void tabwrite_setup(void) | ||
163 | { | ||
164 | tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new, | ||
165 | (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0); | ||
166 | class_addfloat(tabwrite_class, (t_method)tabwrite_float); | ||
167 | class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0); | ||
168 | } | ||