#include "m_pd.h" #define MAXOUTS 10 // change to suit your needs, 10 is MAX max. #define DEFOUTS 1 #define DEFSTATE 0 // = closed typedef struct _gate { t_object x_obj; t_int numouts; t_float open; t_outlet *x_out[MAXOUTS]; } t_gate; static void gate_bang(t_gate *x) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_bang(x->x_out[((int)x->open)-1]); } static void gate_pointer(t_gate *x, t_gpointer *gp) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_pointer(x->x_out[((int)x->open)-1], gp); } static void gate_float(t_gate *x, t_floatarg f) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_float(x->x_out[((int)x->open)-1], f); } static void gate_symbol(t_gate *x, t_symbol *s) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_symbol(x->x_out[((int)x->open)-1], s); } static void gate_list(t_gate *x, t_symbol *s, int argc, t_atom *argv) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_list(x->x_out[((int)x->open)-1], s, argc, argv); } static void gate_anything(t_gate *x, t_symbol *s, int argc, t_atom *argv) { if((x->open != 0)&&(x->open <= x->numouts)) outlet_anything(x->x_out[((int)x->open)-1], s, argc, argv); } void gate_debug(t_gate *x) { post ("open = %d",x->open); post ("outlets = %d",x->numouts); } t_class *gate_class; void *gate_new(t_float val) { int i; t_gate *x = (t_gate *)pd_new(gate_class); // post("gate_new"); x->numouts = val; if (x->numouts > MAXOUTS) x->numouts = MAXOUTS; if (x->numouts < 0) x->numouts = DEFOUTS; x->open = DEFSTATE; floatinlet_new (&x->x_obj, &x->open); for (i = 0; i < x->numouts; i++) x->x_out[i] = outlet_new(&x->x_obj, 0); return (void *)x; } void gate_setup(void) { post("gate v0.1 loaded"); gate_class = class_new(gensym("gate"), (t_newmethod)gate_new, 0, sizeof(t_gate), 0, A_DEFFLOAT, 0); class_addmethod(gate_class, (t_method)gate_debug, gensym("debug"), 0); class_addbang(gate_class, gate_bang); class_addpointer(gate_class, gate_pointer); class_addfloat(gate_class, gate_float); class_addsymbol(gate_class, gate_symbol); class_addlist(gate_class, gate_list); class_addanything(gate_class, gate_anything); }