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.c308
1 files changed, 0 insertions, 308 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_global.c b/apps/plugins/pdbox/PDa/src/d_global.c
index 2b129ac5f4..893abe1f7d 100644
--- a/apps/plugins/pdbox/PDa/src/d_global.c
+++ b/apps/plugins/pdbox/PDa/src/d_global.c
@@ -306,311 +306,3 @@ void d_global_setup(void)
306 sigthrow_setup(); 306 sigthrow_setup();
307} 307}
308 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