Debian Codegraph @

spigot~.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* spigot~ -- route a signal to its right or left output */
2
3 /* Copyleft 2001 Yves Degoyon.
4 Permission is granted to use this software for any purpose provided you
5 keep this copyright notice intact.
6
7 THE AUTHOR AND HIS EXPLOITERS MAKE NO WARRANTY, EXPRESS OR IMPLIED,
8 IN CONNECTION WITH THIS SOFTWARE.
9
10 */
11
12 #include "m_pd.h"
13
14 typedef struct _spigot
15 {
16 t_object x_obj;
17 t_int x_on;
18 t_float x_f;
19 } t_spigot;
20
21 static t_class *spigot_class;
22
23 static char *spigot_version = "spigot~: a signal router : version 0.1, written by Yves Degoyon ([email protected])";
24
25 static void *spigot_new(void)
26 {
27 t_spigot *x = (t_spigot *)pd_new(spigot_class);
28 x->x_on = 0;
29 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("seton") );
30 outlet_new(&x->x_obj, &s_signal);
31 outlet_new(&x->x_obj, &s_signal);
32 return (x);
33 }
34
35 static t_int *spigot_perform(t_int *w)
36 {
37 t_float *in = (t_float *)(w[1]);
38 t_float *outr = (t_float *)(w[2]);
39 t_float *outl = (t_float *)(w[3]);
40 int n = (int)(w[4]);
41 t_spigot* x = (t_spigot*)(w[5]);
42 while (n--)
43 {
44 if ( (x->x_on)==0.0 )
45 {
46 *(outl)=0.0;
47 *(outr)=*(in);
48 }
49 else
50 {
51 *(outl)=*(in);
52 *(outr)=0.0;
53 }
54 in++;
55 outl++;
56 outr++;
57 }
58 return (w+6);
59 }
60
61 static void spigot_dsp(t_spigot *x, t_signal **sp)
62 {
63 dsp_add(spigot_perform, 5, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
64 sp[0]->s_n, x);
65 }
66
67 static void spigot_set(t_spigot *x, t_float f)
68 {
69 x->x_on=f;
70 }
71
72 void spigot_tilde_setup(void)
73 {
•74 logpost(NULL, 4, "%s", spigot_version );
75 spigot_class = class_new(gensym("spigot~"), (t_newmethod)spigot_new, 0,
76 sizeof(t_spigot), 0, 0);
77 CLASS_MAINSIGNALIN( spigot_class, t_spigot, x_f );
78 class_addmethod(spigot_class, (t_method)spigot_dsp, gensym("dsp"), 0);
79 class_addmethod(spigot_class, (t_method)spigot_set, gensym("seton"), A_FLOAT, 0);
80 }