From cee87b2cd09cbc7803e968429f4d62fea468042a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 17 Nov 2011 13:32:58 +0000 Subject: hopefully fixed bug #3433140 using loads of proxy stuff svn path=/trunk/externals/iem/iemguts/; revision=15785 --- src/receivecanvas.c | 76 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/src/receivecanvas.c b/src/receivecanvas.c index b545e78..9250c1c 100644 --- a/src/receivecanvas.c +++ b/src/receivecanvas.c @@ -35,16 +35,63 @@ #include -/* ------------------------- receivecanvas ---------------------------- */ +static t_class *receivecanvas_class, *receivecanvas_proxy_class; -static t_class *receivecanvas_class; +typedef struct _receivecanvas_proxy +{ + t_object p_obj; + t_symbol*p_sym; + t_clock *p_clock; + struct _receivecanvas*p_parent; +} t_receivecanvas_proxy; typedef struct _receivecanvas { - t_object x_obj; - t_symbol *x_sym; + t_object x_obj; + t_receivecanvas_proxy*x_proxy; } t_receivecanvas; +/* ------------------------- receivecanvas proxy ---------------------------- */ + +static void receivecanvas_anything(t_receivecanvas *x, t_symbol*s, int argc, t_atom*argv); + +static void receivecanvas_proxy_anything(t_receivecanvas_proxy *p, t_symbol*s, int argc, t_atom*argv) { + if(p->p_parent) + receivecanvas_anything(p->p_parent, s, argc, argv); +} +static void receivecanvas_proxy_free(t_receivecanvas_proxy *p) +{ + if(p->p_sym) + pd_unbind(&p->p_obj.ob_pd, p->p_sym); + p->p_sym=NULL; + + clock_free(p->p_clock); + p->p_clock=NULL; + + p->p_parent=NULL; + pd_free(&p->p_obj.ob_pd); + + p=NULL; +} +static t_receivecanvas_proxy*receivecanvas_proxy_new(t_receivecanvas *x, t_symbol*s) { + t_receivecanvas_proxy*p=NULL; + + if(!x) return p; + + p=(t_receivecanvas_proxy*)pd_new(receivecanvas_proxy_class); + + p->p_sym=s; + if(p->p_sym) { + pd_bind(&p->p_obj.ob_pd, p->p_sym); + } + p->p_parent=x; + p->p_clock=clock_new(p, (t_method)receivecanvas_proxy_free); + + return p; +} + + +/* ------------------------- 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); @@ -52,8 +99,10 @@ static void receivecanvas_anything(t_receivecanvas *x, t_symbol*s, int argc, t_a static void receivecanvas_free(t_receivecanvas *x) { - if(x->x_sym) - pd_unbind(&x->x_obj.ob_pd, x->x_sym); + if(x->x_proxy) { + x->x_proxy->p_parent = NULL; + clock_delay(x->x_proxy->p_clock, 0); + } } static void *receivecanvas_new(t_floatarg f) @@ -69,15 +118,14 @@ static void *receivecanvas_new(t_floatarg f) depth--; } - x->x_sym=NULL; + x->x_proxy=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); + char buf[MAXPDSTRING]; + snprintf(buf, MAXPDSTRING-1, ".x%lx", (t_int)canvas); + buf[MAXPDSTRING-1]=0; + x->x_proxy=receivecanvas_proxy_new(x, gensym(buf)); } outlet_new(&x->x_obj, 0); @@ -89,5 +137,7 @@ 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); + + receivecanvas_proxy_class = class_new(0, 0, 0, sizeof(t_receivecanvas_proxy), CLASS_NOINLET | CLASS_PD, 0); + class_addanything(receivecanvas_proxy_class, receivecanvas_proxy_anything); } -- cgit v1.2.1