summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/d_global.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_global.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/d_global.c616
1 files changed, 616 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_global.c b/apps/plugins/pdbox/PDa/src/d_global.c
new file mode 100644
index 0000000000..2b129ac5f4
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/d_global.c
@@ -0,0 +1,616 @@
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/* send~, receive~, throw~, catch~ */
6
7#include "m_pd.h"
8#include <string.h>
9
10#define DEFSENDVS 64 /* LATER get send to get this from canvas */
11
12/* ----------------------------- send~ ----------------------------- */
13static t_class *sigsend_class;
14
15typedef struct _sigsend
16{
17 t_object x_obj;
18 t_symbol *x_sym;
19 int x_n;
20 t_sample *x_vec;
21 float x_f;
22} t_sigsend;
23
24static void *sigsend_new(t_symbol *s)
25{
26 t_sigsend *x = (t_sigsend *)pd_new(sigsend_class);
27 pd_bind(&x->x_obj.ob_pd, s);
28 x->x_sym = s;
29 x->x_n = DEFSENDVS;
30 x->x_vec = (t_sample *)getbytes(DEFSENDVS * sizeof(t_sample));
31 memset((char *)(x->x_vec), 0, DEFSENDVS * sizeof(t_sample));
32 x->x_f = 0;
33 return (x);
34}
35
36static t_int *sigsend_perform(t_int *w)
37{
38 t_sample *in = (t_sample *)(w[1]);
39 t_sample *out = (t_sample *)(w[2]);
40 int n = (int)(w[3]);
41 while (n--)
42 {
43 *out = (PD_BIGORSMALL(*in) ? 0 : *in);
44 out++;
45 in++;
46 }
47 return (w+4);
48}
49
50static void sigsend_dsp(t_sigsend *x, t_signal **sp)
51{
52 if (x->x_n == sp[0]->s_n)
53 dsp_add(sigsend_perform, 3, sp[0]->s_vec, x->x_vec, sp[0]->s_n);
54 else error("sigsend %s: unexpected vector size", x->x_sym->s_name);
55}
56
57static void sigsend_free(t_sigsend *x)
58{
59 pd_unbind(&x->x_obj.ob_pd, x->x_sym);
60 freebytes(x->x_vec, x->x_n * sizeof(float));
61}
62
63static void sigsend_setup(void)
64{
65 sigsend_class = class_new(gensym("send~"), (t_newmethod)sigsend_new,
66 (t_method)sigsend_free, sizeof(t_sigsend), 0, A_DEFSYM, 0);
67 class_addcreator((t_newmethod)sigsend_new, gensym("s~"), A_DEFSYM, 0);
68 CLASS_MAINSIGNALIN(sigsend_class, t_sigsend, x_f);
69 class_addmethod(sigsend_class, (t_method)sigsend_dsp, gensym("dsp"), 0);
70}
71
72/* ----------------------------- receive~ ----------------------------- */
73static t_class *sigreceive_class;
74
75typedef struct _sigreceive
76{
77 t_object x_obj;
78 t_symbol *x_sym;
79 t_sample *x_wherefrom;
80 int x_n;
81} t_sigreceive;
82
83static void *sigreceive_new(t_symbol *s)
84{
85 t_sigreceive *x = (t_sigreceive *)pd_new(sigreceive_class);
86 x->x_n = DEFSENDVS; /* LATER find our vector size correctly */
87 x->x_sym = s;
88 x->x_wherefrom = 0;
89 outlet_new(&x->x_obj, &s_signal);
90 return (x);
91}
92
93static t_int *sigreceive_perform(t_int *w)
94{
95 t_sigreceive *x = (t_sigreceive *)(w[1]);
96 t_sample *out = (t_sample *)(w[2]);
97 int n = (int)(w[3]);
98 t_sample *in = x->x_wherefrom;
99 if (in)
100 {
101 while (n--)
102 *out++ = *in++;
103 }
104 else
105 {
106 while (n--)
107 *out++ = 0;
108 }
109 return (w+4);
110}
111
112static void sigreceive_set(t_sigreceive *x, t_symbol *s)
113{
114 t_sigsend *sender = (t_sigsend *)pd_findbyclass((x->x_sym = s),
115 sigsend_class);
116 if (sender)
117 {
118 if (sender->x_n == x->x_n)
119 x->x_wherefrom = sender->x_vec;
120 else
121 {
122 pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
123 x->x_wherefrom = 0;
124 }
125 }
126 else
127 {
128 pd_error(x, "receive~ %s: no matching send", x->x_sym->s_name);
129 x->x_wherefrom = 0;
130 }
131}
132
133static void sigreceive_dsp(t_sigreceive *x, t_signal **sp)
134{
135 if (sp[0]->s_n != x->x_n)
136 {
137 pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
138 }
139 else
140 {
141 sigreceive_set(x, x->x_sym);
142 dsp_add(sigreceive_perform, 3,
143 x, sp[0]->s_vec, sp[0]->s_n);
144 }
145}
146
147static void sigreceive_setup(void)
148{
149 sigreceive_class = class_new(gensym("receive~"),
150 (t_newmethod)sigreceive_new, 0,
151 sizeof(t_sigreceive), 0, A_DEFSYM, 0);
152 class_addcreator((t_newmethod)sigreceive_new, gensym("r~"), A_DEFSYM, 0);
153 class_addmethod(sigreceive_class, (t_method)sigreceive_set, gensym("set"),
154 A_SYMBOL, 0);
155 class_addmethod(sigreceive_class, (t_method)sigreceive_dsp, gensym("dsp"),
156 0);
157 class_sethelpsymbol(sigreceive_class, gensym("send~"));
158}
159
160/* ----------------------------- catch~ ----------------------------- */
161static t_class *sigcatch_class;
162
163typedef struct _sigcatch
164{
165 t_object x_obj;
166 t_symbol *x_sym;
167 int x_n;
168 t_sample *x_vec;
169} t_sigcatch;
170
171static void *sigcatch_new(t_symbol *s)
172{
173 t_sigcatch *x = (t_sigcatch *)pd_new(sigcatch_class);
174 pd_bind(&x->x_obj.ob_pd, s);
175 x->x_sym = s;
176 x->x_n = DEFSENDVS;
177 x->x_vec = (t_sample *)getbytes(DEFSENDVS * sizeof(t_sample));
178 memset((char *)(x->x_vec), 0, DEFSENDVS * sizeof(t_sample));
179 outlet_new(&x->x_obj, &s_signal);
180 return (x);
181}
182
183static t_int *sigcatch_perform(t_int *w)
184{
185 t_sample *in = (t_sample *)(w[1]);
186 t_sample *out = (t_sample *)(w[2]);
187 int n = (int)(w[3]);
188 while (n--) *out++ = *in, *in++ = 0;
189 return (w+4);
190}
191
192static void sigcatch_dsp(t_sigcatch *x, t_signal **sp)
193{
194 if (x->x_n == sp[0]->s_n)
195 dsp_add(sigcatch_perform, 3, x->x_vec, sp[0]->s_vec, sp[0]->s_n);
196 else error("sigcatch %s: unexpected vector size", x->x_sym->s_name);
197}
198
199static void sigcatch_free(t_sigcatch *x)
200{
201 pd_unbind(&x->x_obj.ob_pd, x->x_sym);
202 freebytes(x->x_vec, x->x_n * sizeof(float));
203}
204
205static void sigcatch_setup(void)
206{
207 sigcatch_class = class_new(gensym("catch~"), (t_newmethod)sigcatch_new,
208 (t_method)sigcatch_free, sizeof(t_sigcatch), CLASS_NOINLET, A_DEFSYM, 0);
209 class_addmethod(sigcatch_class, (t_method)sigcatch_dsp, gensym("dsp"), 0);
210 class_sethelpsymbol(sigcatch_class, gensym("throw~"));
211}
212
213/* ----------------------------- throw~ ----------------------------- */
214static t_class *sigthrow_class;
215
216typedef struct _sigthrow
217{
218 t_object x_obj;
219 t_symbol *x_sym;
220 t_sample *x_whereto;
221 int x_n;
222 t_float x_f;
223} t_sigthrow;
224
225static void *sigthrow_new(t_symbol *s)
226{
227 t_sigthrow *x = (t_sigthrow *)pd_new(sigthrow_class);
228 x->x_sym = s;
229 x->x_whereto = 0;
230 x->x_n = DEFSENDVS;
231 x->x_f = 0;
232 return (x);
233}
234
235static t_int *sigthrow_perform(t_int *w)
236{
237 t_sigthrow *x = (t_sigthrow *)(w[1]);
238 t_sample *in = (t_sample *)(w[2]);
239 int n = (int)(w[3]);
240 t_sample *out = x->x_whereto;
241 if (out)
242 {
243 while (n--)
244 {
245 *out += (PD_BIGORSMALL(*in) ? 0 : *in);
246 out++;
247 in++;
248 }
249 }
250 return (w+4);
251}
252
253static void sigthrow_set(t_sigthrow *x, t_symbol *s)
254{
255 t_sigcatch *catcher = (t_sigcatch *)pd_findbyclass((x->x_sym = s),
256 sigcatch_class);
257 if (catcher)
258 {
259 if (catcher->x_n == x->x_n)
260 x->x_whereto = catcher->x_vec;
261 else
262 {
263 pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
264 x->x_whereto = 0;
265 }
266 }
267 else
268 {
269 pd_error(x, "throw~ %s: no matching catch", x->x_sym->s_name);
270 x->x_whereto = 0;
271 }
272}
273
274static void sigthrow_dsp(t_sigthrow *x, t_signal **sp)
275{
276 if (sp[0]->s_n != x->x_n)
277 {
278 pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
279 }
280 else
281 {
282 sigthrow_set(x, x->x_sym);
283 dsp_add(sigthrow_perform, 3,
284 x, sp[0]->s_vec, sp[0]->s_n);
285 }
286}
287
288static void sigthrow_setup(void)
289{
290 sigthrow_class = class_new(gensym("throw~"), (t_newmethod)sigthrow_new, 0,
291 sizeof(t_sigthrow), 0, A_DEFSYM, 0);
292 class_addcreator((t_newmethod)sigthrow_new, gensym("r~"), A_DEFSYM, 0);
293 class_addmethod(sigthrow_class, (t_method)sigthrow_set, gensym("set"),
294 A_SYMBOL, 0);
295 CLASS_MAINSIGNALIN(sigthrow_class, t_sigthrow, x_f);
296 class_addmethod(sigthrow_class, (t_method)sigthrow_dsp, gensym("dsp"), 0);
297}
298
299/* ----------------------- global setup routine ---------------- */
300
301void d_global_setup(void)
302{
303 sigsend_setup();
304 sigreceive_setup();
305 sigcatch_setup();
306 sigthrow_setup();
307}
308
309/* Copyright (c) 1997-1999 Miller Puckette.
310* For information on usage and redistribution, and for a DISCLAIMER OF ALL
311* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
312
313/* send~, receive~, throw~, catch~ */
314
315#include "m_pd.h"
316#include <string.h>
317
318#define DEFSENDVS 64 /* LATER get send to get this from canvas */
319
320/* ----------------------------- send~ ----------------------------- */
321static t_class *sigsend_class;
322
323typedef struct _sigsend
324{
325 t_object x_obj;
326 t_symbol *x_sym;
327 int x_n;
328 t_sample *x_vec;
329 float x_f;
330} t_sigsend;
331
332static void *sigsend_new(t_symbol *s)
333{
334 t_sigsend *x = (t_sigsend *)pd_new(sigsend_class);
335 pd_bind(&x->x_obj.ob_pd, s);
336 x->x_sym = s;
337 x->x_n = DEFSENDVS;
338 x->x_vec = (t_sample *)getbytes(DEFSENDVS * sizeof(t_sample));
339 memset((char *)(x->x_vec), 0, DEFSENDVS * sizeof(t_sample));
340 x->x_f = 0;
341 return (x);
342}
343
344static t_int *sigsend_perform(t_int *w)
345{
346 t_sample *in = (t_sample *)(w[1]);
347 t_sample *out = (t_sample *)(w[2]);
348 int n = (int)(w[3]);
349 while (n--)
350 {
351 *out = (PD_BIGORSMALL(*in) ? 0 : *in);
352 out++;
353 in++;
354 }
355 return (w+4);
356}
357
358static void sigsend_dsp(t_sigsend *x, t_signal **sp)
359{
360 if (x->x_n == sp[0]->s_n)
361 dsp_add(sigsend_perform, 3, sp[0]->s_vec, x->x_vec, sp[0]->s_n);
362 else error("sigsend %s: unexpected vector size", x->x_sym->s_name);
363}
364
365static void sigsend_free(t_sigsend *x)
366{
367 pd_unbind(&x->x_obj.ob_pd, x->x_sym);
368 freebytes(x->x_vec, x->x_n * sizeof(float));
369}
370
371static void sigsend_setup(void)
372{
373 sigsend_class = class_new(gensym("send~"), (t_newmethod)sigsend_new,
374 (t_method)sigsend_free, sizeof(t_sigsend), 0, A_DEFSYM, 0);
375 class_addcreator((t_newmethod)sigsend_new, gensym("s~"), A_DEFSYM, 0);
376 CLASS_MAINSIGNALIN(sigsend_class, t_sigsend, x_f);
377 class_addmethod(sigsend_class, (t_method)sigsend_dsp, gensym("dsp"), 0);
378}
379
380/* ----------------------------- receive~ ----------------------------- */
381static t_class *sigreceive_class;
382
383typedef struct _sigreceive
384{
385 t_object x_obj;
386 t_symbol *x_sym;
387 t_sample *x_wherefrom;
388 int x_n;
389} t_sigreceive;
390
391static void *sigreceive_new(t_symbol *s)
392{
393 t_sigreceive *x = (t_sigreceive *)pd_new(sigreceive_class);
394 x->x_n = DEFSENDVS; /* LATER find our vector size correctly */
395 x->x_sym = s;
396 x->x_wherefrom = 0;
397 outlet_new(&x->x_obj, &s_signal);
398 return (x);
399}
400
401static t_int *sigreceive_perform(t_int *w)
402{
403 t_sigreceive *x = (t_sigreceive *)(w[1]);
404 t_sample *out = (t_sample *)(w[2]);
405 int n = (int)(w[3]);
406 t_sample *in = x->x_wherefrom;
407 if (in)
408 {
409 while (n--)
410 *out++ = *in++;
411 }
412 else
413 {
414 while (n--)
415 *out++ = 0;
416 }
417 return (w+4);
418}
419
420static void sigreceive_set(t_sigreceive *x, t_symbol *s)
421{
422 t_sigsend *sender = (t_sigsend *)pd_findbyclass((x->x_sym = s),
423 sigsend_class);
424 if (sender)
425 {
426 if (sender->x_n == x->x_n)
427 x->x_wherefrom = sender->x_vec;
428 else
429 {
430 pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
431 x->x_wherefrom = 0;
432 }
433 }
434 else
435 {
436 pd_error(x, "receive~ %s: no matching send", x->x_sym->s_name);
437 x->x_wherefrom = 0;
438 }
439}
440
441static void sigreceive_dsp(t_sigreceive *x, t_signal **sp)
442{
443 if (sp[0]->s_n != x->x_n)
444 {
445 pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
446 }
447 else
448 {
449 sigreceive_set(x, x->x_sym);
450 dsp_add(sigreceive_perform, 3,
451 x, sp[0]->s_vec, sp[0]->s_n);
452 }
453}
454
455static void sigreceive_setup(void)
456{
457 sigreceive_class = class_new(gensym("receive~"),
458 (t_newmethod)sigreceive_new, 0,
459 sizeof(t_sigreceive), 0, A_DEFSYM, 0);
460 class_addcreator((t_newmethod)sigreceive_new, gensym("r~"), A_DEFSYM, 0);
461 class_addmethod(sigreceive_class, (t_method)sigreceive_set, gensym("set"),
462 A_SYMBOL, 0);
463 class_addmethod(sigreceive_class, (t_method)sigreceive_dsp, gensym("dsp"),
464 0);
465 class_sethelpsymbol(sigreceive_class, gensym("send~"));
466}
467
468/* ----------------------------- catch~ ----------------------------- */
469static t_class *sigcatch_class;
470
471typedef struct _sigcatch
472{
473 t_object x_obj;
474 t_symbol *x_sym;
475 int x_n;
476 t_sample *x_vec;
477} t_sigcatch;
478
479static void *sigcatch_new(t_symbol *s)
480{
481 t_sigcatch *x = (t_sigcatch *)pd_new(sigcatch_class);
482 pd_bind(&x->x_obj.ob_pd, s);
483 x->x_sym = s;
484 x->x_n = DEFSENDVS;
485 x->x_vec = (t_sample *)getbytes(DEFSENDVS * sizeof(t_sample));
486 memset((char *)(x->x_vec), 0, DEFSENDVS * sizeof(t_sample));
487 outlet_new(&x->x_obj, &s_signal);
488 return (x);
489}
490
491static t_int *sigcatch_perform(t_int *w)
492{
493 t_sample *in = (t_sample *)(w[1]);
494 t_sample *out = (t_sample *)(w[2]);
495 int n = (int)(w[3]);
496 while (n--) *out++ = *in, *in++ = 0;
497 return (w+4);
498}
499
500static void sigcatch_dsp(t_sigcatch *x, t_signal **sp)
501{
502 if (x->x_n == sp[0]->s_n)
503 dsp_add(sigcatch_perform, 3, x->x_vec, sp[0]->s_vec, sp[0]->s_n);
504 else error("sigcatch %s: unexpected vector size", x->x_sym->s_name);
505}
506
507static void sigcatch_free(t_sigcatch *x)
508{
509 pd_unbind(&x->x_obj.ob_pd, x->x_sym);
510 freebytes(x->x_vec, x->x_n * sizeof(float));
511}
512
513static void sigcatch_setup(void)
514{
515 sigcatch_class = class_new(gensym("catch~"), (t_newmethod)sigcatch_new,
516 (t_method)sigcatch_free, sizeof(t_sigcatch), CLASS_NOINLET, A_DEFSYM, 0);
517 class_addmethod(sigcatch_class, (t_method)sigcatch_dsp, gensym("dsp"), 0);
518 class_sethelpsymbol(sigcatch_class, gensym("throw~"));
519}
520
521/* ----------------------------- throw~ ----------------------------- */
522static t_class *sigthrow_class;
523
524typedef struct _sigthrow
525{
526 t_object x_obj;
527 t_symbol *x_sym;
528 t_sample *x_whereto;
529 int x_n;
530 t_float x_f;
531} t_sigthrow;
532
533static void *sigthrow_new(t_symbol *s)
534{
535 t_sigthrow *x = (t_sigthrow *)pd_new(sigthrow_class);
536 x->x_sym = s;
537 x->x_whereto = 0;
538 x->x_n = DEFSENDVS;
539 x->x_f = 0;
540 return (x);
541}
542
543static t_int *sigthrow_perform(t_int *w)
544{
545 t_sigthrow *x = (t_sigthrow *)(w[1]);
546 t_sample *in = (t_sample *)(w[2]);
547 int n = (int)(w[3]);
548 t_sample *out = x->x_whereto;
549 if (out)
550 {
551 while (n--)
552 {
553 *out += (PD_BIGORSMALL(*in) ? 0 : *in);
554 out++;
555 in++;
556 }
557 }
558 return (w+4);
559}
560
561static void sigthrow_set(t_sigthrow *x, t_symbol *s)
562{
563 t_sigcatch *catcher = (t_sigcatch *)pd_findbyclass((x->x_sym = s),
564 sigcatch_class);
565 if (catcher)
566 {
567 if (catcher->x_n == x->x_n)
568 x->x_whereto = catcher->x_vec;
569 else
570 {
571 pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
572 x->x_whereto = 0;
573 }
574 }
575 else
576 {
577 pd_error(x, "throw~ %s: no matching catch", x->x_sym->s_name);
578 x->x_whereto = 0;
579 }
580}
581
582static void sigthrow_dsp(t_sigthrow *x, t_signal **sp)
583{
584 if (sp[0]->s_n != x->x_n)
585 {
586 pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
587 }
588 else
589 {
590 sigthrow_set(x, x->x_sym);
591 dsp_add(sigthrow_perform, 3,
592 x, sp[0]->s_vec, sp[0]->s_n);
593 }
594}
595
596static void sigthrow_setup(void)
597{
598 sigthrow_class = class_new(gensym("throw~"), (t_newmethod)sigthrow_new, 0,
599 sizeof(t_sigthrow), 0, A_DEFSYM, 0);
600 class_addcreator((t_newmethod)sigthrow_new, gensym("r~"), A_DEFSYM, 0);
601 class_addmethod(sigthrow_class, (t_method)sigthrow_set, gensym("set"),
602 A_SYMBOL, 0);
603 CLASS_MAINSIGNALIN(sigthrow_class, t_sigthrow, x_f);
604 class_addmethod(sigthrow_class, (t_method)sigthrow_dsp, gensym("dsp"), 0);
605}
606
607/* ----------------------- global setup routine ---------------- */
608
609void d_global_setup(void)
610{
611 sigsend_setup();
612 sigreceive_setup();
613 sigcatch_setup();
614 sigthrow_setup();
615}
616