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 /* send~, receive~, throw~, catch~ */
10 #define DEFSENDVS 64 /* LATER get send to get this from canvas */
12 /* ----------------------------- send~ ----------------------------- */
13 static t_class
*sigsend_class
;
15 typedef struct _sigsend
24 static void *sigsend_new(t_symbol
*s
)
26 t_sigsend
*x
= (t_sigsend
*)pd_new(sigsend_class
);
27 pd_bind(&x
->x_obj
.ob_pd
, s
);
30 x
->x_vec
= (t_sample
*)getbytes(DEFSENDVS
* sizeof(t_sample
));
31 memset((char *)(x
->x_vec
), 0, DEFSENDVS
* sizeof(t_sample
));
36 static t_int
*sigsend_perform(t_int
*w
)
38 t_sample
*in
= (t_sample
*)(w
[1]);
39 t_sample
*out
= (t_sample
*)(w
[2]);
43 *out
= (PD_BIGORSMALL(*in
) ? 0 : *in
);
50 static void sigsend_dsp(t_sigsend
*x
, t_signal
**sp
)
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
);
57 static void sigsend_free(t_sigsend
*x
)
59 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
60 freebytes(x
->x_vec
, x
->x_n
* sizeof(float));
63 static void sigsend_setup(void)
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);
72 /* ----------------------------- receive~ ----------------------------- */
73 static t_class
*sigreceive_class
;
75 typedef struct _sigreceive
79 t_sample
*x_wherefrom
;
83 static void *sigreceive_new(t_symbol
*s
)
85 t_sigreceive
*x
= (t_sigreceive
*)pd_new(sigreceive_class
);
86 x
->x_n
= DEFSENDVS
; /* LATER find our vector size correctly */
89 outlet_new(&x
->x_obj
, &s_signal
);
93 static t_int
*sigreceive_perform(t_int
*w
)
95 t_sigreceive
*x
= (t_sigreceive
*)(w
[1]);
96 t_sample
*out
= (t_sample
*)(w
[2]);
98 t_sample
*in
= x
->x_wherefrom
;
112 static void sigreceive_set(t_sigreceive
*x
, t_symbol
*s
)
114 t_sigsend
*sender
= (t_sigsend
*)pd_findbyclass((x
->x_sym
= s
),
118 if (sender
->x_n
== x
->x_n
)
119 x
->x_wherefrom
= sender
->x_vec
;
122 pd_error(x
, "receive~ %s: vector size mismatch", x
->x_sym
->s_name
);
128 pd_error(x
, "receive~ %s: no matching send", x
->x_sym
->s_name
);
133 static void sigreceive_dsp(t_sigreceive
*x
, t_signal
**sp
)
135 if (sp
[0]->s_n
!= x
->x_n
)
137 pd_error(x
, "receive~ %s: vector size mismatch", x
->x_sym
->s_name
);
141 sigreceive_set(x
, x
->x_sym
);
142 dsp_add(sigreceive_perform
, 3,
143 x
, sp
[0]->s_vec
, sp
[0]->s_n
);
147 static void sigreceive_setup(void)
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"),
155 class_addmethod(sigreceive_class
, (t_method
)sigreceive_dsp
, gensym("dsp"),
157 class_sethelpsymbol(sigreceive_class
, gensym("send~"));
160 /* ----------------------------- catch~ ----------------------------- */
161 static t_class
*sigcatch_class
;
163 typedef struct _sigcatch
171 static void *sigcatch_new(t_symbol
*s
)
173 t_sigcatch
*x
= (t_sigcatch
*)pd_new(sigcatch_class
);
174 pd_bind(&x
->x_obj
.ob_pd
, s
);
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
);
183 static t_int
*sigcatch_perform(t_int
*w
)
185 t_sample
*in
= (t_sample
*)(w
[1]);
186 t_sample
*out
= (t_sample
*)(w
[2]);
188 while (n
--) *out
++ = *in
, *in
++ = 0;
192 static void sigcatch_dsp(t_sigcatch
*x
, t_signal
**sp
)
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
);
199 static void sigcatch_free(t_sigcatch
*x
)
201 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
202 freebytes(x
->x_vec
, x
->x_n
* sizeof(float));
205 static void sigcatch_setup(void)
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~"));
213 /* ----------------------------- throw~ ----------------------------- */
214 static t_class
*sigthrow_class
;
216 typedef struct _sigthrow
225 static void *sigthrow_new(t_symbol
*s
)
227 t_sigthrow
*x
= (t_sigthrow
*)pd_new(sigthrow_class
);
235 static t_int
*sigthrow_perform(t_int
*w
)
237 t_sigthrow
*x
= (t_sigthrow
*)(w
[1]);
238 t_sample
*in
= (t_sample
*)(w
[2]);
240 t_sample
*out
= x
->x_whereto
;
245 *out
+= (PD_BIGORSMALL(*in
) ? 0 : *in
);
253 static void sigthrow_set(t_sigthrow
*x
, t_symbol
*s
)
255 t_sigcatch
*catcher
= (t_sigcatch
*)pd_findbyclass((x
->x_sym
= s
),
259 if (catcher
->x_n
== x
->x_n
)
260 x
->x_whereto
= catcher
->x_vec
;
263 pd_error(x
, "throw~ %s: vector size mismatch", x
->x_sym
->s_name
);
269 pd_error(x
, "throw~ %s: no matching catch", x
->x_sym
->s_name
);
274 static void sigthrow_dsp(t_sigthrow
*x
, t_signal
**sp
)
276 if (sp
[0]->s_n
!= x
->x_n
)
278 pd_error(x
, "throw~ %s: vector size mismatch", x
->x_sym
->s_name
);
282 sigthrow_set(x
, x
->x_sym
);
283 dsp_add(sigthrow_perform
, 3,
284 x
, sp
[0]->s_vec
, sp
[0]->s_n
);
288 static void sigthrow_setup(void)
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"),
295 CLASS_MAINSIGNALIN(sigthrow_class
, t_sigthrow
, x_f
);
296 class_addmethod(sigthrow_class
, (t_method
)sigthrow_dsp
, gensym("dsp"), 0);
299 /* ----------------------- global setup routine ---------------- */
301 void d_global_setup(void)
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. */
313 /* send~, receive~, throw~, catch~ */
318 #define DEFSENDVS 64 /* LATER get send to get this from canvas */
320 /* ----------------------------- send~ ----------------------------- */
321 static t_class
*sigsend_class
;
323 typedef struct _sigsend
332 static void *sigsend_new(t_symbol
*s
)
334 t_sigsend
*x
= (t_sigsend
*)pd_new(sigsend_class
);
335 pd_bind(&x
->x_obj
.ob_pd
, s
);
338 x
->x_vec
= (t_sample
*)getbytes(DEFSENDVS
* sizeof(t_sample
));
339 memset((char *)(x
->x_vec
), 0, DEFSENDVS
* sizeof(t_sample
));
344 static t_int
*sigsend_perform(t_int
*w
)
346 t_sample
*in
= (t_sample
*)(w
[1]);
347 t_sample
*out
= (t_sample
*)(w
[2]);
351 *out
= (PD_BIGORSMALL(*in
) ? 0 : *in
);
358 static void sigsend_dsp(t_sigsend
*x
, t_signal
**sp
)
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
);
365 static void sigsend_free(t_sigsend
*x
)
367 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
368 freebytes(x
->x_vec
, x
->x_n
* sizeof(float));
371 static void sigsend_setup(void)
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);
380 /* ----------------------------- receive~ ----------------------------- */
381 static t_class
*sigreceive_class
;
383 typedef struct _sigreceive
387 t_sample
*x_wherefrom
;
391 static void *sigreceive_new(t_symbol
*s
)
393 t_sigreceive
*x
= (t_sigreceive
*)pd_new(sigreceive_class
);
394 x
->x_n
= DEFSENDVS
; /* LATER find our vector size correctly */
397 outlet_new(&x
->x_obj
, &s_signal
);
401 static t_int
*sigreceive_perform(t_int
*w
)
403 t_sigreceive
*x
= (t_sigreceive
*)(w
[1]);
404 t_sample
*out
= (t_sample
*)(w
[2]);
406 t_sample
*in
= x
->x_wherefrom
;
420 static void sigreceive_set(t_sigreceive
*x
, t_symbol
*s
)
422 t_sigsend
*sender
= (t_sigsend
*)pd_findbyclass((x
->x_sym
= s
),
426 if (sender
->x_n
== x
->x_n
)
427 x
->x_wherefrom
= sender
->x_vec
;
430 pd_error(x
, "receive~ %s: vector size mismatch", x
->x_sym
->s_name
);
436 pd_error(x
, "receive~ %s: no matching send", x
->x_sym
->s_name
);
441 static void sigreceive_dsp(t_sigreceive
*x
, t_signal
**sp
)
443 if (sp
[0]->s_n
!= x
->x_n
)
445 pd_error(x
, "receive~ %s: vector size mismatch", x
->x_sym
->s_name
);
449 sigreceive_set(x
, x
->x_sym
);
450 dsp_add(sigreceive_perform
, 3,
451 x
, sp
[0]->s_vec
, sp
[0]->s_n
);
455 static void sigreceive_setup(void)
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"),
463 class_addmethod(sigreceive_class
, (t_method
)sigreceive_dsp
, gensym("dsp"),
465 class_sethelpsymbol(sigreceive_class
, gensym("send~"));
468 /* ----------------------------- catch~ ----------------------------- */
469 static t_class
*sigcatch_class
;
471 typedef struct _sigcatch
479 static void *sigcatch_new(t_symbol
*s
)
481 t_sigcatch
*x
= (t_sigcatch
*)pd_new(sigcatch_class
);
482 pd_bind(&x
->x_obj
.ob_pd
, s
);
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
);
491 static t_int
*sigcatch_perform(t_int
*w
)
493 t_sample
*in
= (t_sample
*)(w
[1]);
494 t_sample
*out
= (t_sample
*)(w
[2]);
496 while (n
--) *out
++ = *in
, *in
++ = 0;
500 static void sigcatch_dsp(t_sigcatch
*x
, t_signal
**sp
)
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
);
507 static void sigcatch_free(t_sigcatch
*x
)
509 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
510 freebytes(x
->x_vec
, x
->x_n
* sizeof(float));
513 static void sigcatch_setup(void)
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~"));
521 /* ----------------------------- throw~ ----------------------------- */
522 static t_class
*sigthrow_class
;
524 typedef struct _sigthrow
533 static void *sigthrow_new(t_symbol
*s
)
535 t_sigthrow
*x
= (t_sigthrow
*)pd_new(sigthrow_class
);
543 static t_int
*sigthrow_perform(t_int
*w
)
545 t_sigthrow
*x
= (t_sigthrow
*)(w
[1]);
546 t_sample
*in
= (t_sample
*)(w
[2]);
548 t_sample
*out
= x
->x_whereto
;
553 *out
+= (PD_BIGORSMALL(*in
) ? 0 : *in
);
561 static void sigthrow_set(t_sigthrow
*x
, t_symbol
*s
)
563 t_sigcatch
*catcher
= (t_sigcatch
*)pd_findbyclass((x
->x_sym
= s
),
567 if (catcher
->x_n
== x
->x_n
)
568 x
->x_whereto
= catcher
->x_vec
;
571 pd_error(x
, "throw~ %s: vector size mismatch", x
->x_sym
->s_name
);
577 pd_error(x
, "throw~ %s: no matching catch", x
->x_sym
->s_name
);
582 static void sigthrow_dsp(t_sigthrow
*x
, t_signal
**sp
)
584 if (sp
[0]->s_n
!= x
->x_n
)
586 pd_error(x
, "throw~ %s: vector size mismatch", x
->x_sym
->s_name
);
590 sigthrow_set(x
, x
->x_sym
);
591 dsp_add(sigthrow_perform
, 3,
592 x
, sp
[0]->s_vec
, sp
[0]->s_n
);
596 static void sigthrow_setup(void)
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"),
603 CLASS_MAINSIGNALIN(sigthrow_class
, t_sigthrow
, x_f
);
604 class_addmethod(sigthrow_class
, (t_method
)sigthrow_dsp
, gensym("dsp"), 0);
607 /* ----------------------- global setup routine ---------------- */
609 void d_global_setup(void)