aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-06-23 17:29:43 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-06-23 17:29:43 +0000
commitb024c0a1197b973f3b0b50e4945d75e8f81332f7 (patch)
treeeaa38b4f696aa8e4fce956432dc1384d5ec25ec6
parentcdc3807935c0811964e7a5a582ada65fced54694 (diff)
a kind of opposite of "sendcanvas"; but it really only receives the messages from the gui
svn path=/trunk/externals/iem/iemguts/; revision=11813
-rw-r--r--src/receivecanvas.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/receivecanvas.c b/src/receivecanvas.c
new file mode 100644
index 0000000..26ed5a6
--- /dev/null
+++ b/src/receivecanvas.c
@@ -0,0 +1,89 @@
+
+/*****************************************************
+ *
+ * receivecanvas - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 2007:forum::für::umläute:2007
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+
+/*
+ * this object provides a way to send messages to upstream canvases
+ * by default it sends messages to the containing canvas, but you can give the
+ * "depth" as argument;
+ * e.g. [receivecanvas 1] will send messages to the parent of the containing canvas
+ */
+
+#include "m_pd.h"
+#include "g_canvas.h"
+
+#include <stdio.h>
+
+
+int glist_getindex(t_glist *x, t_gobj *y);
+
+/* ------------------------- receivecanvas ---------------------------- */
+
+static t_class *receivecanvas_class;
+
+typedef struct _receivecanvas
+{
+ t_object x_obj;
+ t_symbol *x_sym;
+} t_receivecanvas;
+
+static void receivecanvas_anything(t_receivecanvas *x, t_symbol*s, int argc, t_atom*argv)
+{
+ outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
+}
+
+static void receivecanvas_free(t_receivecanvas *x)
+{
+ if(x->x_sym)
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+}
+
+static void *receivecanvas_new(t_floatarg f)
+{
+ t_receivecanvas *x = (t_receivecanvas *)pd_new(receivecanvas_class);
+ t_glist *glist=(t_glist *)canvas_getcurrent();
+ t_canvas *canvas=(t_canvas*)glist_getcanvas(glist);
+ int depth=(int)f;
+ if(depth<0)depth=0;
+
+ while(depth && canvas) {
+ canvas=canvas->gl_owner;
+ depth--;
+ }
+
+ x->x_sym=NULL;
+
+ if(canvas) {
+ char buf[40];
+ snprintf(buf, 40, ".x%lx", (t_int)canvas);
+ x->x_sym=gensym(buf);
+
+ pd_bind(&x->x_obj.ob_pd, x->x_sym);
+
+ }
+
+ outlet_new(&x->x_obj, 0);
+
+ return (x);
+}
+
+void receivecanvas_setup(void)
+{
+ receivecanvas_class = class_new(gensym("receivecanvas"), (t_newmethod)receivecanvas_new,
+ (t_method)receivecanvas_free, sizeof(t_receivecanvas), CLASS_NOINLET, A_DEFFLOAT, 0);
+ class_addanything(receivecanvas_class, (t_method)receivecanvas_anything);
+}