Commit 16512c1c authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

added experimental optimization for binding abstractions as per following post...

added experimental optimization for binding abstractions as per following post on the pd-list: http://lists.puredata.info/pipermail/pd-list/2013-08/103688.html
parent 9000cc70
...@@ -54,6 +54,9 @@ void canvas_reflecttitle(t_canvas *x); ...@@ -54,6 +54,9 @@ void canvas_reflecttitle(t_canvas *x);
static void canvas_addtolist(t_canvas *x); static void canvas_addtolist(t_canvas *x);
static void canvas_takeofflist(t_canvas *x); static void canvas_takeofflist(t_canvas *x);
static void canvas_pop(t_canvas *x, t_floatarg fvis); 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 ----------- */ /* --------- functions to handle the canvas environment ----------- */
...@@ -232,12 +235,10 @@ void canvas_makefilename(t_canvas *x, char *file, char *result, int resultsize) ...@@ -232,12 +235,10 @@ void canvas_makefilename(t_canvas *x, char *file, char *result, int resultsize)
void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir) void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir)
{ {
if (strcmp(x->gl_name->s_name, "Pd")) canvas_unbind(x);
pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
x->gl_name = s; x->gl_name = s;
if (strcmp(x->gl_name->s_name, "Pd")) canvas_bind(x);
pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name)); if (x->gl_havewindow) //was glist_isvisible(x)
if (glist_isvisible(x))
canvas_reflecttitle(x); canvas_reflecttitle(x);
if (dir && dir != &s_) if (dir && dir != &s_)
{ {
...@@ -407,8 +408,7 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv) ...@@ -407,8 +408,7 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
x->gl_owner = owner; x->gl_owner = owner;
x->gl_name = (*s->s_name ? s : x->gl_name = (*s->s_name ? s :
(canvas_newfilename ? canvas_newfilename : gensym("Pd"))); (canvas_newfilename ? canvas_newfilename : gensym("Pd")));
if (strcmp(x->gl_name->s_name, "Pd")) canvas_bind(x);
pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
x->gl_loading = 1; x->gl_loading = 1;
//fprintf(stderr,"loading = 1 .x%lx owner=.x%lx\n", (t_int)x, (t_int)x->gl_owner); //fprintf(stderr,"loading = 1 .x%lx owner=.x%lx\n", (t_int)x, (t_int)x->gl_owner);
x->gl_goprect = 0; /* no GOP rectangle unless it's turned on later */ x->gl_goprect = 0; /* no GOP rectangle unless it's turned on later */
...@@ -548,9 +548,8 @@ t_glist *glist_addglist(t_glist *g, t_symbol *sym, ...@@ -548,9 +548,8 @@ t_glist *glist_addglist(t_glist *g, t_symbol *sym,
x->gl_screenx1 = x->gl_screeny1 = 0; x->gl_screenx1 = x->gl_screeny1 = 0;
x->gl_screenx2 = 450; x->gl_screenx2 = 450;
x->gl_screeny2 = 300; 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; x->gl_owner = g;
canvas_bind(x);
x->gl_isgraph = 1; x->gl_isgraph = 1;
x->gl_goprect = 0; x->gl_goprect = 0;
x->gl_obj.te_binbuf = binbuf_new(); x->gl_obj.te_binbuf = binbuf_new();
...@@ -901,11 +900,7 @@ void canvas_free(t_canvas *x) ...@@ -901,11 +900,7 @@ void canvas_free(t_canvas *x)
if (x->gl_editor) if (x->gl_editor)
canvas_destroy_editor(x); canvas_destroy_editor(x);
canvas_unbind(x);
if (strcmp(x->gl_name->s_name, "Pd")) {
//fprintf(stderr,"canvas_free calling pd_unbind\n");
pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
}
if (x->gl_env) if (x->gl_env)
{ {
freebytes(x->gl_env->ce_argv, x->gl_env->ce_argc * sizeof(t_atom)); freebytes(x->gl_env->ce_argv, x->gl_env->ce_argc * sizeof(t_atom));
...@@ -1318,6 +1313,26 @@ int canvas_isabstraction(t_canvas *x) ...@@ -1318,6 +1313,26 @@ int canvas_isabstraction(t_canvas *x)
return (x->gl_env != 0); 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 is a "table". */ /* return true if the "canvas" object is a "table". */
int canvas_istable(t_canvas *x) int canvas_istable(t_canvas *x)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment