2
/* 1903:forum::f�r::uml�ute:2005 */
5
* mulitplex : multiplex a specified input to the output
7
* THINK: should the selector-inlet be the first or the last ???
9
* the 1st inlet being the selector is not consistant with pd (hot/cold)
10
* but as it since the hot inlet is selectable, the whole object is not really consitant
11
* numbering would have to start with 1 (for the 1st not-leftmost inlet)
12
* if the selector is rightmost this would mean: cold is right(most), hot is (somewhere) left
13
* numbering would be ok
15
* conclusio: make the selector rightmost
23
/* ------------------------- mux ------------------------------- */
29
static t_class *mux_class;
30
static t_class *muxproxy_class;
35
struct _muxproxy **x_proxy;
43
typedef struct _muxproxy
50
static void mux_select(t_mux *x, t_float f)
55
static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, t_atom *argv)
58
if(y->id==x->i_selected)
59
outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
62
static void *mux_new(t_symbol *s, int argc, t_atom *argv)
64
int n = (argc < 2)?2:argc;
65
t_mux *x = (t_mux *)pd_new(mux_class);
69
x->in = (t_inlet **)getbytes(x->i_count * sizeof(t_inlet *));
70
x->x_proxy = (t_muxproxy**)getbytes(x->i_count * sizeof(t_muxproxy*));
72
for (n = 0; n<x->i_count; n++) {
73
x->x_proxy[n]=(t_muxproxy*)pd_new(muxproxy_class);
74
x->x_proxy[n]->p_master = x;
76
x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
79
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym(""));
81
outlet_new(&x->x_obj, 0);
85
static void mux_free(t_mux*x){
86
const int count = x->i_count;
88
if(x->in && x->x_proxy){
90
for(n=0; n<count; n++){
96
t_muxproxy *y=x->x_proxy[n];
103
freebytes(x->in, x->i_count * sizeof(t_inlet *));
104
freebytes(x->x_proxy, x->i_count * sizeof(t_muxproxy*));
107
/* pd_free(&y->p_pd); */
110
void multiplex_setup(void)
112
mux_class = class_new(gensym("multiplex"), (t_newmethod)mux_new,
113
(t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME, 0);
114
class_addcreator((t_newmethod)mux_new, gensym("mux"), A_GIMME, 0);
116
class_addmethod (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, 0);
118
muxproxy_class = class_new(0, 0, 0,
120
CLASS_PD | CLASS_NOINLET, 0);
121
class_addanything(muxproxy_class, mux_anything);
124
zexy_register("multiplex");