aboutsummaryrefslogtreecommitdiff
path: root/src/multiplex.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
commit2b60d55c919e7588f5aff15936e83c300b3660bb (patch)
tree14d860de7f28083d3756ad91b627de70f26788f6 /src/multiplex.c
parentc500bc542cb7cc78d6dac3f7da3bff626056b1aa (diff)
zexy-2.0:
- use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641
Diffstat (limited to 'src/multiplex.c')
-rw-r--r--src/multiplex.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/multiplex.c b/src/multiplex.c
new file mode 100644
index 0000000..571db96
--- /dev/null
+++ b/src/multiplex.c
@@ -0,0 +1,106 @@
+
+/* 1903:forum::für::umläute:2005 */
+
+/*
+ * mulitplex : multiplex a specified input to the output
+ *
+ * THINK: should the selector-inlet be the first or the last ???
+ * pros/cons:
+ * the 1st inlet being the selector is not consistant with pd (hot/cold)
+ * but as it since the hot inlet is selectable, the whole object is not really consitant
+ * numbering would have to start with 1 (for the 1st not-leftmost inlet)
+ * if the selector is rightmost this would mean: cold is right(most), hot is (somewhere) left
+ * numbering would be ok
+ *
+ * conclusio: make the selector rightmost
+ *
+ */
+
+#include "zexy.h"
+#include <stdio.h>
+
+
+/* ------------------------- mux ------------------------------- */
+
+/*
+ a multiplexer
+*/
+
+static t_class *mux_class;
+static t_class *muxproxy_class;
+
+typedef struct _mux
+{
+ t_object x_obj;
+ struct _muxproxy **x_proxy;
+
+ int i_count;
+ int i_selected;
+ t_inlet **in;
+} t_mux;
+
+
+typedef struct _muxproxy
+{
+ t_object p_ob;
+ t_mux *p_master;
+ int id;
+} t_muxproxy;
+
+static void mux_select(t_mux *x, t_float f)
+{
+ x->i_selected=f;
+}
+
+static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, t_atom *argv)
+{
+ t_mux*x=y->p_master;
+ if(y->id==x->i_selected)
+ outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
+}
+
+static void *mux_new(t_symbol *s, int argc, t_atom *argv)
+{
+ int n = (argc < 2)?2:argc;
+ t_mux *x = (t_mux *)pd_new(mux_class);
+ // t_muxproxy *y=(t_muxproxy*)pd_new(muxproxy_class);
+ x->x_proxy = (t_muxproxy**)getbytes(sizeof(t_muxproxy*));
+
+ x->i_selected=0;
+ x->i_count = n;
+ x->in = (t_inlet **)getbytes(x->i_count * sizeof(t_inlet *));
+
+ for (n = 0; n<x->i_count; n++) {
+ x->x_proxy[n]=(t_muxproxy*)pd_new(muxproxy_class);
+ x->x_proxy[n]->p_master = x;
+ x->x_proxy[n]->id=n;
+ x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
+ }
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym(""));
+
+ outlet_new(&x->x_obj, 0);
+ return (x);
+}
+
+static void mux_free(t_mux*x){
+
+}
+
+void multiplex_setup(void)
+{
+ mux_class = class_new(gensym("multiplex"), (t_newmethod)mux_new,
+ (t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME, 0);
+ class_addcreator((t_newmethod)mux_new, gensym("mux"), A_GIMME, 0);
+
+ class_addmethod (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, 0);
+
+ muxproxy_class = class_new(gensym("mux proxy"), 0, 0,
+ sizeof(t_muxproxy),
+ CLASS_PD | CLASS_NOINLET, 0);
+ class_addanything(muxproxy_class, mux_anything);
+
+ class_sethelpsymbol(mux_class, gensym("zexy/multiplex"));
+
+ zexy_register("multiplex");
+}