[PATCH] don't bind abstraction instances to pd-<filename>

Claude Heiland-Allen claude at mathr.co.uk
Fri Aug 9 15:57:14 CEST 2013


---
 src/g_canvas.c |   39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/g_canvas.c b/src/g_canvas.c
index 804ac57..c7a22d6 100644
--- a/src/g_canvas.c
+++ b/src/g_canvas.c
@@ -55,6 +55,9 @@ void canvas_reflecttitle(t_canvas *x);
 static void canvas_addtolist(t_canvas *x);
 static void canvas_takeofflist(t_canvas *x);
 static void canvas_pop(t_canvas *x, t_floatarg fvis);
+static int canvas_should_bind(t_canvas *x);
+static void canvas_bind(t_canvas *x);
+static void canvas_unbind(t_canvas *x);
 
 /* --------- functions to handle the canvas environment ----------- */
 
@@ -205,11 +208,9 @@ void canvas_makefilename(t_canvas *x, char *file, char *result, int resultsize)
 
 void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir)
 {
-    if (strcmp(x->gl_name->s_name, "Pd"))
-        pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+    canvas_unbind(x);
     x->gl_name = s;
-    if (strcmp(x->gl_name->s_name, "Pd"))
-        pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+    canvas_bind(x);
     if (x->gl_havewindow)
         canvas_reflecttitle(x);
     if (dir && dir != &s_)
@@ -379,8 +380,7 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
     x->gl_owner = owner;
     x->gl_name = (*s->s_name ? s : 
         (canvas_newfilename ? canvas_newfilename : gensym("Pd")));
-    if (strcmp(x->gl_name->s_name, "Pd"))
-        pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+    canvas_bind(x);
     x->gl_loading = 1;
     x->gl_goprect = 0;      /* no GOP rectangle unless it's turned on later */
         /* cancel "vis" flag if we're a subpatch of an
@@ -479,9 +479,8 @@ t_glist *glist_addglist(t_glist *g, t_symbol *sym,
     x->gl_screeny1 = GLIST_DEFCANVASYLOC;
     x->gl_screenx2 = 450;
     x->gl_screeny2 = 300;
-    if (strcmp(x->gl_name->s_name, "Pd"))
-        pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
     x->gl_owner = g;
+    canvas_bind(x);
     x->gl_isgraph = 1;
     x->gl_goprect = 0;
     x->gl_obj.te_binbuf = binbuf_new();
@@ -723,8 +722,7 @@ void canvas_free(t_canvas *x)
         canvas_vis(x, 0);
     if (x->gl_editor)
         canvas_destroy_editor(x);   /* bug workaround; should already be gone*/
-    if (strcmp(x->gl_name->s_name, "Pd"))
-        pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+    canvas_unbind(x);
 
     if (x->gl_env)
     {
@@ -985,6 +983,27 @@ int canvas_isabstraction(t_canvas *x)
     return (x->gl_env != 0);
 }
 
+    /* return true if the "canvas" object should be bound to a name */
+static int canvas_should_bind(t_canvas *x)
+{
+        /* FIXME should have a "backwards compatible" mode */
+        /* not named "Pd" && (is top level || is subpatch) */
+    return strcmp(x->gl_name->s_name, "Pd") && (!x->gl_owner || !x->gl_env);
+}
+
+static void canvas_bind(t_canvas *x)
+{
+    if (canvas_should_bind(x))
+        pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+}
+
+static void canvas_unbind(t_canvas *x)
+{
+    if (canvas_should_bind(x))
+        pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+}
+
+
     /* return true if the "canvas" object should be treated as a text
     object.  This is true for abstractions but also for "table"s... */
 /* JMZ: add a flag to gop-abstractions to hide the title */
-- 
1.7.10.4


--------------090004060200010008000809--



More information about the Pd-list mailing list