2
/* 1903:forum::f�r::uml�ute:2005 */
5
* mulitplex : zpack 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
/* ------------------------- zpack ------------------------------- */
29
static t_class *zpack_class;
30
static t_class *zpackproxy_class;
35
struct _zpackproxy **x_proxy;
44
typedef struct _zpackproxy
52
static void setatom(t_zpack *x, t_atom*from, int to) {
53
x->x_argv[to].a_type=from->a_type;
54
x->x_argv[to].a_w =from->a_w;
57
static void zpack_bang(t_zpack*x) {
58
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->x_argc, x->x_argv);
61
static void zpack_list0(t_zpack*x, t_symbol *s, int argc, t_atom *argv) {
63
for(i=0; i<argc && i<x->x_argc; i++)
64
setatom(x, argv+i, i);
68
static void zpack_list(t_zpackproxy *y, t_symbol *s, int argc, t_atom *argv)
71
setatom(y->p_master, argv, y->id);
74
static void *zpack_new(t_symbol *s, int argc, t_atom *argv)
76
t_zpack *x = (t_zpack *)pd_new(zpack_class);
79
x->x_argc = (argc < 1)?2:argc;
83
x->x_argv=(t_atom*)getbytes(2*sizeof(t_atom));
84
SETFLOAT(x->x_argv+0, 0.f);
85
SETFLOAT(x->x_argv+1, 0.f);
88
x->x_argv=(t_atom*)getbytes(x->x_argc*sizeof(t_atom));
89
for(i=0; i<x->x_argc; i++)
90
setatom(x, argv+i, i);
93
x->in = (t_inlet **)getbytes(x->x_argc * sizeof(t_inlet *));
94
x->x_proxy = (t_zpackproxy**)getbytes(x->x_argc * sizeof(t_zpackproxy*));
99
for (n = 1; n<x->x_argc; n++) {
100
x->x_proxy[n]=(t_zpackproxy*)pd_new(zpackproxy_class);
101
x->x_proxy[n]->p_master = x;
103
x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
106
outlet_new(&x->x_obj, 0);
110
static void zpack_free(t_zpack*x){
111
const int count = x->x_argc;
113
if(x->in && x->x_proxy){
115
for(n=0; n<count; n++){
117
inlet_free(x->in[n]);
121
t_zpackproxy *y=x->x_proxy[n];
128
freebytes(x->in, x->x_argc * sizeof(t_inlet *));
129
freebytes(x->x_proxy, x->x_argc * sizeof(t_zpackproxy*));
133
void zpack_setup(void)
135
zpack_class = class_new(gensym("zexy/pack"), (t_newmethod)zpack_new,
136
(t_method)zpack_free, sizeof(t_zpack), 0, A_GIMME, 0);
138
/* oops Pd-0.42 allows us to override built-ins
139
* this is bad as long as the 2 objects are not compatible */
140
class_addcreator((t_newmethod)zpack_new, gensym("pack"), A_GIMME, 0);
142
class_addbang(zpack_class, zpack_bang);
143
class_addlist(zpack_class, zpack_list0);
145
zpackproxy_class = class_new(gensym("zpack proxy"), 0, 0,
146
sizeof(t_zpackproxy),
147
CLASS_PD | CLASS_NOINLET, 0);
148
class_addlist(zpackproxy_class, zpack_list);
151
zexy_register("pack");
154
void pack_setup(void)