Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / d_misc.c
blobab1b49a1e9d11d07210eba292a3b3c746dfbda70
1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* miscellaneous: print~; more to come.
6 */
8 #ifdef ROCKBOX
9 #include "plugin.h"
10 #include "../../pdbox.h"
11 #endif
13 #include "m_pd.h"
15 #ifndef ROCKBOX
16 #include <stdio.h>
17 #include <string.h>
18 #endif
20 /* ------------------------- print~ -------------------------- */
21 static t_class *print_class;
23 typedef struct _print
25 t_object x_obj;
26 float x_f;
27 t_symbol *x_sym;
28 int x_count;
29 } t_print;
31 static t_int *print_perform(t_int *w)
33 t_print *x = (t_print *)(w[1]);
34 t_float *in = (t_float *)(w[2]);
35 int n = (int)(w[3]);
36 if (x->x_count)
38 post("%s:", x->x_sym->s_name);
39 if (n == 1) post("%8g", in[0]);
40 else if (n == 2) post("%8g %8g", in[0], in[1]);
41 else if (n == 4) post("%8g %8g %8g %8g",
42 in[0], in[1], in[2], in[3]);
43 else while (n > 0)
45 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
46 in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
47 n -= 8;
48 in += 8;
50 x->x_count--;
52 return (w+4);
55 static void print_dsp(t_print *x, t_signal **sp)
57 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
60 static void print_float(t_print *x, t_float f)
62 if (f < 0) f = 0;
63 x->x_count = f;
66 static void print_bang(t_print *x)
68 x->x_count = 1;
71 static void *print_new(t_symbol *s)
73 t_print *x = (t_print *)pd_new(print_class);
74 x->x_sym = (s->s_name[0]? s : gensym("print~"));
75 x->x_count = 0;
76 x->x_f = 0;
77 return (x);
80 #ifndef ROCKBOX
81 static
82 #endif
83 void print_setup(void)
85 print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
86 sizeof(t_print), 0, A_DEFSYM, 0);
87 CLASS_MAINSIGNALIN(print_class, t_print, x_f);
88 class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
89 class_addbang(print_class, print_bang);
90 class_addfloat(print_class, print_float);
93 /* ------------------------- scope~ -------------------------- */
94 /* this has been replaced by arrays; to be deleted later */
96 #include "g_canvas.h"
98 static t_class *scope_class;
100 #define SCOPESIZE 256
102 typedef struct _scope
104 t_object x_obj;
105 t_sample x_samps[SCOPESIZE];
106 int x_phase;
107 int x_drawn;
108 void *x_canvas;
109 } t_scope;
111 static t_int *scope_perform(t_int *w)
113 t_scope *x = (t_scope *)(w[1]);
114 t_float *in = (t_float *)(w[2]);
115 int n = (int)(w[3]), phase = x->x_phase;
116 while (n--)
118 x->x_samps[phase] = *in++;
119 phase = (phase + 1) & (SCOPESIZE-1);
121 x->x_phase = phase;
122 return (w+4);
125 static void scope_dsp(t_scope *x, t_signal **sp)
127 dsp_add(scope_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
130 static void scope_erase(t_scope *x)
132 #ifdef ROCKBOX
133 (void) x;
134 #else
135 if (x->x_drawn) sys_vgui(".x%x.c delete gumbo\n", x->x_canvas);
136 #endif
139 #define X1 10.
140 #define X2 20.
141 #define YC 5.
142 static void scope_bang(t_scope *x)
144 #ifndef ROCKBOX
145 int n, phase;
146 char hugebuf[10000], *s = hugebuf;
147 scope_erase(x);
148 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x->x_canvas);
149 sprintf(s, ".x%x.c create line ", (t_int)x->x_canvas);
150 s += strlen(s);
151 for (n = 0, phase = x->x_phase;
152 n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
154 sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
155 YC - 5 * x->x_samps[phase]);
156 s += strlen(s);
157 /* post("phase %d", phase); */
159 sprintf(s, "-tags gumbo\n");
160 sys_gui(hugebuf);
161 #endif
162 x->x_drawn = 1;
165 static void scope_free(t_scope *x)
167 scope_erase(x);
170 static void *scope_new(t_symbol *s)
172 #ifdef ROCKBOX
173 (void) s;
174 #endif
175 t_scope *x = (t_scope *)pd_new(scope_class);
176 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
177 x->x_phase = 0;
178 x->x_drawn = 0;
179 x->x_canvas = canvas_getcurrent();
180 return (x);
183 static void scope_setup(void)
185 scope_class = class_new(gensym("scope~"), (t_newmethod)scope_new,
186 (t_method)scope_free, sizeof(t_scope), 0, A_DEFSYM, 0);
187 class_addmethod(scope_class, nullfn, gensym("signal"), 0);
188 class_addmethod(scope_class, (t_method)scope_dsp, gensym("dsp"), 0);
189 class_addbang(scope_class, scope_bang);
192 /* ------------------------ bang~ -------------------------- */
194 static t_class *bang_tilde_class;
196 typedef struct _bang
198 t_object x_obj;
199 t_clock *x_clock;
200 } t_bang;
202 static t_int *bang_tilde_perform(t_int *w)
204 t_bang *x = (t_bang *)(w[1]);
205 clock_delay(x->x_clock, 0);
206 return (w+2);
209 static void bang_tilde_dsp(t_bang *x, t_signal **sp)
211 #ifdef ROCKBOX
212 (void) sp;
213 #endif
214 dsp_add(bang_tilde_perform, 1, x);
217 static void bang_tilde_tick(t_bang *x)
219 outlet_bang(x->x_obj.ob_outlet);
222 static void bang_tilde_free(t_bang *x)
224 clock_free(x->x_clock);
227 static void *bang_tilde_new(t_symbol *s)
229 #ifdef ROCKBOX
230 (void) s;
231 #endif
232 t_bang *x = (t_bang *)pd_new(bang_tilde_class);
233 x->x_clock = clock_new(x, (t_method)bang_tilde_tick);
234 outlet_new(&x->x_obj, &s_bang);
235 return (x);
238 static void bang_tilde_setup(void)
240 bang_tilde_class = class_new(gensym("bang~"), (t_newmethod)bang_tilde_new,
241 (t_method)bang_tilde_free, sizeof(t_bang), 0, 0);
242 class_addmethod(bang_tilde_class, (t_method)bang_tilde_dsp,
243 gensym("dsp"), 0);
246 /* ------------------------ samplerate~~ -------------------------- */
248 static t_class *samplerate_tilde_class;
250 typedef struct _samplerate
252 t_object x_obj;
253 } t_samplerate;
255 static void samplerate_tilde_bang(t_samplerate *x)
257 outlet_float(x->x_obj.ob_outlet, sys_getsr());
260 static void *samplerate_tilde_new(t_symbol *s)
262 #ifdef ROCKBOX
263 (void) s;
264 #endif
265 t_samplerate *x = (t_samplerate *)pd_new(samplerate_tilde_class);
266 outlet_new(&x->x_obj, &s_float);
267 return (x);
270 static void samplerate_tilde_setup(void)
272 samplerate_tilde_class = class_new(gensym("samplerate~"),
273 (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
274 class_addbang(samplerate_tilde_class, samplerate_tilde_bang);
277 /* ------------------------ global setup routine ------------------------- */
279 void d_misc_setup(void)
281 #ifndef FIXEDPOINT
282 print_setup();
283 #endif
284 scope_setup();
285 bang_tilde_setup();
286 samplerate_tilde_setup();