summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/d_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_misc.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/d_misc.c524
1 files changed, 524 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_misc.c b/apps/plugins/pdbox/PDa/src/d_misc.c
new file mode 100644
index 0000000000..f601d66d90
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/d_misc.c
@@ -0,0 +1,524 @@
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. */
4
5/* miscellaneous: print~; more to come.
6*/
7
8#include "m_pd.h"
9#include <stdio.h>
10#include <string.h>
11
12/* ------------------------- print~ -------------------------- */
13static t_class *print_class;
14
15typedef struct _print
16{
17 t_object x_obj;
18 float x_f;
19 t_symbol *x_sym;
20 int x_count;
21} t_print;
22
23static t_int *print_perform(t_int *w)
24{
25 t_print *x = (t_print *)(w[1]);
26 t_float *in = (t_float *)(w[2]);
27 int n = (int)(w[3]);
28 if (x->x_count)
29 {
30 post("%s:", x->x_sym->s_name);
31 if (n == 1) post("%8g", in[0]);
32 else if (n == 2) post("%8g %8g", in[0], in[1]);
33 else if (n == 4) post("%8g %8g %8g %8g",
34 in[0], in[1], in[2], in[3]);
35 else while (n > 0)
36 {
37 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
38 in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
39 n -= 8;
40 in += 8;
41 }
42 x->x_count--;
43 }
44 return (w+4);
45}
46
47static void print_dsp(t_print *x, t_signal **sp)
48{
49 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
50}
51
52static void print_float(t_print *x, t_float f)
53{
54 if (f < 0) f = 0;
55 x->x_count = f;
56}
57
58static void print_bang(t_print *x)
59{
60 x->x_count = 1;
61}
62
63static void *print_new(t_symbol *s)
64{
65 t_print *x = (t_print *)pd_new(print_class);
66 x->x_sym = (s->s_name[0]? s : gensym("print~"));
67 x->x_count = 0;
68 x->x_f = 0;
69 return (x);
70}
71
72static void print_setup(void)
73{
74 print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
75 sizeof(t_print), 0, A_DEFSYM, 0);
76 CLASS_MAINSIGNALIN(print_class, t_print, x_f);
77 class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
78 class_addbang(print_class, print_bang);
79 class_addfloat(print_class, print_float);
80}
81
82/* ------------------------- scope~ -------------------------- */
83/* this has been replaced by arrays; to be deleted later */
84
85#include "g_canvas.h"
86
87static t_class *scope_class;
88
89#define SCOPESIZE 256
90
91typedef struct _scope
92{
93 t_object x_obj;
94 t_sample x_samps[SCOPESIZE];
95 int x_phase;
96 int x_drawn;
97 void *x_canvas;
98} t_scope;
99
100static t_int *scope_perform(t_int *w)
101{
102 t_scope *x = (t_scope *)(w[1]);
103 t_float *in = (t_float *)(w[2]);
104 int n = (int)(w[3]), phase = x->x_phase;
105 while (n--)
106 {
107 x->x_samps[phase] = *in++;
108 phase = (phase + 1) & (SCOPESIZE-1);
109 }
110 x->x_phase = phase;
111 return (w+4);
112}
113
114static void scope_dsp(t_scope *x, t_signal **sp)
115{
116 dsp_add(scope_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
117}
118
119static void scope_erase(t_scope *x)
120{
121 if (x->x_drawn) sys_vgui(".x%x.c delete gumbo\n", x->x_canvas);
122}
123
124#define X1 10.
125#define X2 20.
126#define YC 5.
127static void scope_bang(t_scope *x)
128{
129 int n, phase;
130 char hugebuf[10000], *s = hugebuf;
131 scope_erase(x);
132 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x->x_canvas);
133 sprintf(s, ".x%x.c create line ", (t_int)x->x_canvas);
134 s += strlen(s);
135 for (n = 0, phase = x->x_phase;
136 n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
137 {
138 sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
139 YC - 5 * x->x_samps[phase]);
140 s += strlen(s);
141 /* post("phase %d", phase); */
142 }
143 sprintf(s, "-tags gumbo\n");
144 sys_gui(hugebuf);
145 x->x_drawn = 1;
146}
147
148static void scope_free(t_scope *x)
149{
150 scope_erase(x);
151}
152
153static void *scope_new(t_symbol *s)
154{
155 t_scope *x = (t_scope *)pd_new(scope_class);
156 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
157 x->x_phase = 0;
158 x->x_drawn = 0;
159 x->x_canvas = canvas_getcurrent();
160 return (x);
161}
162
163static void scope_setup(void)
164{
165 scope_class = class_new(gensym("scope~"), (t_newmethod)scope_new,
166 (t_method)scope_free, sizeof(t_scope), 0, A_DEFSYM, 0);
167 class_addmethod(scope_class, nullfn, gensym("signal"), 0);
168 class_addmethod(scope_class, (t_method)scope_dsp, gensym("dsp"), 0);
169 class_addbang(scope_class, scope_bang);
170}
171
172/* ------------------------ bang~ -------------------------- */
173
174static t_class *bang_tilde_class;
175
176typedef struct _bang
177{
178 t_object x_obj;
179 t_clock *x_clock;
180} t_bang;
181
182static t_int *bang_tilde_perform(t_int *w)
183{
184 t_bang *x = (t_bang *)(w[1]);
185 clock_delay(x->x_clock, 0);
186 return (w+2);
187}
188
189static void bang_tilde_dsp(t_bang *x, t_signal **sp)
190{
191 dsp_add(bang_tilde_perform, 1, x);
192}
193
194static void bang_tilde_tick(t_bang *x)
195{
196 outlet_bang(x->x_obj.ob_outlet);
197}
198
199static void bang_tilde_free(t_bang *x)
200{
201 clock_free(x->x_clock);
202}
203
204static void *bang_tilde_new(t_symbol *s)
205{
206 t_bang *x = (t_bang *)pd_new(bang_tilde_class);
207 x->x_clock = clock_new(x, (t_method)bang_tilde_tick);
208 outlet_new(&x->x_obj, &s_bang);
209 return (x);
210}
211
212static void bang_tilde_setup(void)
213{
214 bang_tilde_class = class_new(gensym("bang~"), (t_newmethod)bang_tilde_new,
215 (t_method)bang_tilde_free, sizeof(t_bang), 0, 0);
216 class_addmethod(bang_tilde_class, (t_method)bang_tilde_dsp,
217 gensym("dsp"), 0);
218}
219
220/* ------------------------ samplerate~~ -------------------------- */
221
222static t_class *samplerate_tilde_class;
223
224typedef struct _samplerate
225{
226 t_object x_obj;
227} t_samplerate;
228
229static void samplerate_tilde_bang(t_samplerate *x)
230{
231 outlet_float(x->x_obj.ob_outlet, sys_getsr());
232}
233
234static void *samplerate_tilde_new(t_symbol *s)
235{
236 t_samplerate *x = (t_samplerate *)pd_new(samplerate_tilde_class);
237 outlet_new(&x->x_obj, &s_float);
238 return (x);
239}
240
241static void samplerate_tilde_setup(void)
242{
243 samplerate_tilde_class = class_new(gensym("samplerate~"),
244 (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
245 class_addbang(samplerate_tilde_class, samplerate_tilde_bang);
246}
247
248/* ------------------------ global setup routine ------------------------- */
249
250void d_misc_setup(void)
251{
252#ifndef FIXEDPOINT
253 print_setup();
254#endif
255 scope_setup();
256 bang_tilde_setup();
257 samplerate_tilde_setup();
258}
259
260
261
262
263/* Copyright (c) 1997-1999 Miller Puckette.
264* For information on usage and redistribution, and for a DISCLAIMER OF ALL
265* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
266
267/* miscellaneous: print~; more to come.
268*/
269
270#include "m_pd.h"
271#include <stdio.h>
272#include <string.h>
273
274/* ------------------------- print~ -------------------------- */
275static t_class *print_class;
276
277typedef struct _print
278{
279 t_object x_obj;
280 float x_f;
281 t_symbol *x_sym;
282 int x_count;
283} t_print;
284
285static t_int *print_perform(t_int *w)
286{
287 t_print *x = (t_print *)(w[1]);
288 t_float *in = (t_float *)(w[2]);
289 int n = (int)(w[3]);
290 if (x->x_count)
291 {
292 post("%s:", x->x_sym->s_name);
293 if (n == 1) post("%8g", in[0]);
294 else if (n == 2) post("%8g %8g", in[0], in[1]);
295 else if (n == 4) post("%8g %8g %8g %8g",
296 in[0], in[1], in[2], in[3]);
297 else while (n > 0)
298 {
299 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
300 in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
301 n -= 8;
302 in += 8;
303 }
304 x->x_count--;
305 }
306 return (w+4);
307}
308
309static void print_dsp(t_print *x, t_signal **sp)
310{
311 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
312}
313
314static void print_float(t_print *x, t_float f)
315{
316 if (f < 0) f = 0;
317 x->x_count = f;
318}
319
320static void print_bang(t_print *x)
321{
322 x->x_count = 1;
323}
324
325static void *print_new(t_symbol *s)
326{
327 t_print *x = (t_print *)pd_new(print_class);
328 x->x_sym = (s->s_name[0]? s : gensym("print~"));
329 x->x_count = 0;
330 x->x_f = 0;
331 return (x);
332}
333
334static void print_setup(void)
335{
336 print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
337 sizeof(t_print), 0, A_DEFSYM, 0);
338 CLASS_MAINSIGNALIN(print_class, t_print, x_f);
339 class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
340 class_addbang(print_class, print_bang);
341 class_addfloat(print_class, print_float);
342}
343
344/* ------------------------- scope~ -------------------------- */
345/* this has been replaced by arrays; to be deleted later */
346
347#include "g_canvas.h"
348
349static t_class *scope_class;
350
351#define SCOPESIZE 256
352
353typedef struct _scope
354{
355 t_object x_obj;
356 t_sample x_samps[SCOPESIZE];
357 int x_phase;
358 int x_drawn;
359 void *x_canvas;
360} t_scope;
361
362static t_int *scope_perform(t_int *w)
363{
364 t_scope *x = (t_scope *)(w[1]);
365 t_float *in = (t_float *)(w[2]);
366 int n = (int)(w[3]), phase = x->x_phase;
367 while (n--)
368 {
369 x->x_samps[phase] = *in++;
370 phase = (phase + 1) & (SCOPESIZE-1);
371 }
372 x->x_phase = phase;
373 return (w+4);
374}
375
376static void scope_dsp(t_scope *x, t_signal **sp)
377{
378 dsp_add(scope_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
379}
380
381static void scope_erase(t_scope *x)
382{
383 if (x->x_drawn) sys_vgui(".x%x.c delete gumbo\n", x->x_canvas);
384}
385
386#define X1 10.
387#define X2 20.
388#define YC 5.
389static void scope_bang(t_scope *x)
390{
391 int n, phase;
392 char hugebuf[10000], *s = hugebuf;
393 scope_erase(x);
394 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x->x_canvas);
395 sprintf(s, ".x%x.c create line ", (t_int)x->x_canvas);
396 s += strlen(s);
397 for (n = 0, phase = x->x_phase;
398 n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
399 {
400 sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
401 YC - 5 * x->x_samps[phase]);
402 s += strlen(s);
403 /* post("phase %d", phase); */
404 }
405 sprintf(s, "-tags gumbo\n");
406 sys_gui(hugebuf);
407 x->x_drawn = 1;
408}
409
410static void scope_free(t_scope *x)
411{
412 scope_erase(x);
413}
414
415static void *scope_new(t_symbol *s)
416{
417 t_scope *x = (t_scope *)pd_new(scope_class);
418 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
419 x->x_phase = 0;
420 x->x_drawn = 0;
421 x->x_canvas = canvas_getcurrent();
422 return (x);
423}
424
425static void scope_setup(void)
426{
427 scope_class = class_new(gensym("scope~"), (t_newmethod)scope_new,
428 (t_method)scope_free, sizeof(t_scope), 0, A_DEFSYM, 0);
429 class_addmethod(scope_class, nullfn, gensym("signal"), 0);
430 class_addmethod(scope_class, (t_method)scope_dsp, gensym("dsp"), 0);
431 class_addbang(scope_class, scope_bang);
432}
433
434/* ------------------------ bang~ -------------------------- */
435
436static t_class *bang_tilde_class;
437
438typedef struct _bang
439{
440 t_object x_obj;
441 t_clock *x_clock;
442} t_bang;
443
444static t_int *bang_tilde_perform(t_int *w)
445{
446 t_bang *x = (t_bang *)(w[1]);
447 clock_delay(x->x_clock, 0);
448 return (w+2);
449}
450
451static void bang_tilde_dsp(t_bang *x, t_signal **sp)
452{
453 dsp_add(bang_tilde_perform, 1, x);
454}
455
456static void bang_tilde_tick(t_bang *x)
457{
458 outlet_bang(x->x_obj.ob_outlet);
459}
460
461static void bang_tilde_free(t_bang *x)
462{
463 clock_free(x->x_clock);
464}
465
466static void *bang_tilde_new(t_symbol *s)
467{
468 t_bang *x = (t_bang *)pd_new(bang_tilde_class);
469 x->x_clock = clock_new(x, (t_method)bang_tilde_tick);
470 outlet_new(&x->x_obj, &s_bang);
471 return (x);
472}
473
474static void bang_tilde_setup(void)
475{
476 bang_tilde_class = class_new(gensym("bang~"), (t_newmethod)bang_tilde_new,
477 (t_method)bang_tilde_free, sizeof(t_bang), 0, 0);
478 class_addmethod(bang_tilde_class, (t_method)bang_tilde_dsp,
479 gensym("dsp"), 0);
480}
481
482/* ------------------------ samplerate~~ -------------------------- */
483
484static t_class *samplerate_tilde_class;
485
486typedef struct _samplerate
487{
488 t_object x_obj;
489} t_samplerate;
490
491static void samplerate_tilde_bang(t_samplerate *x)
492{
493 outlet_float(x->x_obj.ob_outlet, sys_getsr());
494}
495
496static void *samplerate_tilde_new(t_symbol *s)
497{
498 t_samplerate *x = (t_samplerate *)pd_new(samplerate_tilde_class);
499 outlet_new(&x->x_obj, &s_float);
500 return (x);
501}
502
503static void samplerate_tilde_setup(void)
504{
505 samplerate_tilde_class = class_new(gensym("samplerate~"),
506 (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
507 class_addbang(samplerate_tilde_class, samplerate_tilde_bang);
508}
509
510/* ------------------------ global setup routine ------------------------- */
511
512void d_misc_setup(void)
513{
514#ifndef FIXEDPOINT
515 print_setup();
516#endif
517 scope_setup();
518 bang_tilde_setup();
519 samplerate_tilde_setup();
520}
521
522
523
524