From edab184352cd14788a37c76dce147ac19f7464b4 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Fri, 19 Sep 2003 12:19:32 +0000 Subject: *** empty log message *** svn path=/trunk/externals/miXed/; revision=1011 --- shared/common/port.c | 143 +++++++++++++++++++++++---------------- shared/unstable/Makefile.sources | 3 +- shared/unstable/forky.c | 15 ++-- shared/unstable/forky.h | 2 +- shared/unstable/fragile.c | 2 + shared/unstable/fringe.c | 98 +++++++++++++++++++++++++++ shared/unstable/fringe.h | 10 +++ 7 files changed, 210 insertions(+), 63 deletions(-) create mode 100644 shared/unstable/fringe.c create mode 100644 shared/unstable/fringe.h (limited to 'shared') diff --git a/shared/common/port.c b/shared/common/port.c index 65cf59f..556af8f 100644 --- a/shared/common/port.c +++ b/shared/common/port.c @@ -2,10 +2,10 @@ * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ -/* FIXME inlet/outlet vs inlet~/outlet~ */ /* LATER think about abstractions */ /* LATER sort out escaping rules (also revisit binport.c) */ /* LATER quoting */ +/* LATER rethink inlet/inlet~ case */ #ifdef UNIX #include @@ -19,6 +19,7 @@ #include "g_canvas.h" #include "unstable/forky.h" #include "unstable/fragile.h" +#include "unstable/fringe.h" #include "common/loud.h" #include "common/grow.h" #include "common/binport.h" @@ -44,6 +45,7 @@ typedef struct _port t_binbuf *x_oldbb; t_binbuf *x_newbb; int x_nobj; + int x_withbogus; int x_inatoms; t_atom *x_inmess; int x_outsize; @@ -58,6 +60,8 @@ typedef struct _port static t_symbol *portps_bogus; static t_symbol *portps_cleanup; +static t_symbol *portps_inlet; +static t_symbol *portps_outlet; static t_float port_floatarg(t_port *x, int ndx) { @@ -118,7 +122,7 @@ static void port_setxy(t_port *x, int ndx, t_atom *ap) SETFLOAT(ap, f); } -static void import_addclassname(t_binbuf *bb, char *outname, t_atom *inatom) +static void import_addclassname(t_port *x, char *outname, t_atom *inatom) { t_atom at; if (outname) @@ -129,15 +133,18 @@ static void import_addclassname(t_binbuf *bb, char *outname, t_atom *inatom) t_symbol *insym = inatom->a_w.w_symbol; if (insym != &s_bang && insym != &s_float && insym != &s_symbol && insym != &s_list && - zgetfn(&pd_objectmaker, insym) == 0) + (insym == portps_inlet || insym == portps_outlet || + zgetfn(&pd_objectmaker, insym) == 0)) + { + x->x_withbogus = 1; SETSYMBOL(&at, portps_bogus); - binbuf_add(bb, 1, &at); + binbuf_add(x->x_newbb, 1, &at); } SETSYMBOL(&at, insym); } else at = *inatom; - binbuf_add(bb, 1, &at); + binbuf_add(x->x_newbb, 1, &at); } static int import_obj(t_port *x, char *name) @@ -146,7 +153,7 @@ static int import_obj(t_port *x, char *name) binbuf_addv(x->x_newbb, "ssff", gensym("#X"), gensym("obj"), port_xarg(x, ndx), port_yarg(x, ndx + 1)); - import_addclassname(x->x_newbb, name, &x->x_inmess[ndx == 2 ? 6 : 2]); + import_addclassname(x, name, &x->x_inmess[ndx == 2 ? 6 : 2]); binbuf_addsemi(x->x_newbb); x->x_nobj++; return (PORT_NEXT); @@ -163,7 +170,7 @@ static int import_objarg(t_port *x, char *name) SETSYMBOL(out, gensym("obj")); out++; port_setxy(x, ndx, out); binbuf_add(x->x_newbb, 4, x->x_outmess); - import_addclassname(x->x_newbb, name, &x->x_inmess[ndx == 2 ? 6 : 2]); + import_addclassname(x, name, &x->x_inmess[ndx == 2 ? 6 : 2]); out = x->x_outmess; for (ndx = 7; ndx < x->x_inatoms; ndx++) *out++ = *in++; @@ -204,6 +211,8 @@ static int imaction_vpatcher(t_port *x, char *arg) static int imaction_patcher(t_port *x, char *arg) { + binbuf_addv(x->x_newbb, "ss;", portps_cleanup, portps_cleanup); + x->x_withbogus = 0; binbuf_addv(x->x_newbb, "ssffss;", gensym("#X"), gensym("restore"), port_xarg(x, 2), port_yarg(x, 3), @@ -238,7 +247,7 @@ static int imaction_scope(t_port *x, char *name) xpix = (int)out++->a_w.w_float; ypix = (int)out->a_w.w_float; binbuf_add(x->x_newbb, 4, x->x_outmess); - import_addclassname(x->x_newbb, name, &x->x_inmess[2]); + import_addclassname(x, name, &x->x_inmess[2]); out = x->x_outmess; port_setxy(x, 5, out); out++->a_w.w_float -= xpix; @@ -305,16 +314,22 @@ static int imaction_message(t_port *x, char *arg) return (PORT_NEXT); } -/* FIXME this is no longer true */ -static int imaction_inlet(t_port *x, char *arg) +static int imaction_io(t_port *x, char *arg) { - return (import_obj(x, (port_floatarg(x, 5) ? "inlet~" : "inlet"))); -} - -/* FIXME this is no longer true */ -static int imaction_outlet(t_port *x, char *arg) -{ - return (import_obj(x, (port_floatarg(x, 5) ? "outlet~" : "outlet"))); + binbuf_addv(x->x_newbb, "ssff", + gensym("#X"), gensym("obj"), + port_xarg(x, 2), port_yarg(x, 3)); + if (x->x_inmess[1].a_w.w_symbol == portps_inlet || + x->x_inmess[1].a_w.w_symbol == portps_outlet) + { + t_atom at; + SETSYMBOL(&at, portps_bogus); + binbuf_add(x->x_newbb, 1, &at); + } + binbuf_add(x->x_newbb, 1, &x->x_inmess[1]); + binbuf_addsemi(x->x_newbb); + x->x_nobj++; + return (PORT_NEXT); } static int imaction_number(t_port *x, char *arg) @@ -421,10 +436,10 @@ static t_portslot imslots__P[] = { "message", imaction_message, 0, 0, 0 }, { "newobj", import_objarg, 0, &imnode_newobj, 0 }, { "newex", import_objarg, 0, &imnode_newex, 0 }, - { "inlet", imaction_inlet, 0, 0, 0 }, - { "inlet~", imaction_inlet, 0, 0, 0 }, - { "outlet", imaction_outlet, 0, 0, 0 }, - { "outlet~", imaction_outlet, 0, 0, 0 }, + { "inlet", imaction_io, 0, 0, 0 }, + { "inlet~", imaction_io, 0, 0, 0 }, + { "outlet", imaction_io, 0, 0, 0 }, + { "outlet~", imaction_io, 0, 0, 0 }, { "number", imaction_number, 0, 0, 0 }, { "flonum", imaction_number, 0, 0, 0 }, { "button", import_obj, "bng", 0, 0 }, @@ -503,8 +518,8 @@ static void port_dochecksetup(t_portnode *node) } } -#define BOGUS_NINLETS 15 -#define BOGUS_NOUTLETS 16 +#define BOGUS_NINLETS 23 +#define BOGUS_NOUTLETS 24 typedef struct _bogus { @@ -587,12 +602,7 @@ static void bogus_cleanup(t_bogus *x) #ifdef PORT_DEBUG post("%d outlets deleted", i); #endif - if (x->x_glist->gl_editor) /* FIXME what is the right condition? */ - { - t_rtext *rt; - if (rt = glist_findrtext(x->x_glist, t)) - rtext_retext(rt); - } + glist_retext(x->x_glist, t); } else bug("bogus_cleanup"); x->x_glist = 0; @@ -617,17 +627,13 @@ static void *bogus_new(t_symbol *s, int ac, t_atom *av) if (av->a_type == A_SYMBOL) { t_pd *z; - typedmess(&pd_objectmaker, av->a_w.w_symbol, ac - 1, av + 1); - if (z = pd_newest()) + if (z = forky_newobject(av->a_w.w_symbol, ac - 1, av + 1)) { - if (pd_checkobject(z)) - { - t_bogushook *y = (t_bogushook *)pd_new(bogushook_class); - y->x_who = z; - y->x_glist = glist; - pd_bind((t_pd *)y, portps_cleanup); - y->x_clock = clock_new(y, (t_method)bogushook_tick); - } + t_bogushook *y = (t_bogushook *)pd_new(bogushook_class); + y->x_who = z; + y->x_glist = glist; + pd_bind((t_pd *)y, portps_cleanup); + y->x_clock = clock_new(y, (t_method)bogushook_tick); #ifdef PORT_DEBUG post("reclaiming %s", av->a_w.w_symbol->s_name); #endif @@ -655,22 +661,42 @@ static void bogushook_cleanup(t_bogushook *x) { t_text *t = (t_text *)x->x_who; int ac = binbuf_getnatom(t->te_binbuf); - if (ac) + if (ac > 1) { + int dorecreate = 0; t_atom *av = binbuf_getvec(t->te_binbuf); t_binbuf *bb = binbuf_new(); #ifdef PORT_DEBUG startpost("hook-adjusting"); binbuf_print(t->te_binbuf); #endif - binbuf_add(bb, ac - 1, av + 1); - binbuf_free(t->te_binbuf); - t->te_binbuf = bb; - if (x->x_glist->gl_editor) /* FIXME what is the right condition? */ + ac--; av++; + if (av->a_type == A_SYMBOL) + { + if (av->a_w.w_symbol == portps_outlet) + { + if (forky_hasfeeders((t_object *)x->x_who, x->x_glist, + 0, &s_signal)) + { + t_atom at; + SETSYMBOL(&at, gensym("outlet~")); + binbuf_add(bb, 1, &at); + ac--; av++; + dorecreate = 1; + } + } + else if (av->a_w.w_symbol == portps_inlet) + { + /* LATER */ + } + } + if (ac) binbuf_add(bb, ac, av); + if (dorecreate) gobj_recreate(x->x_glist, (t_gobj *)t, bb); + else { - t_rtext *rt; - if (rt = glist_findrtext(x->x_glist, t)) - rtext_retext(rt); + binbuf_free(t->te_binbuf); + t->te_binbuf = bb; + glist_retext(x->x_glist, t); } } else bug("bogushook_cleanup"); @@ -697,6 +723,8 @@ static void port_checksetup(void) portps_bogus = gensym("_port.bogus"); portps_cleanup = gensym("_port.cleanup"); + portps_inlet = gensym("inlet"); + portps_outlet = gensym("outlet"); if (zgetfn(&pd_objectmaker, portps_bogus) == 0) { @@ -720,6 +748,7 @@ static t_port *port_new(void) { t_port *x = (t_port *)getbytes(sizeof(*x)); x->x_oldbb = binbuf_new(); + x->x_withbogus = 0; x->x_outsize = PORT_INISIZE; x->x_outatoms = 0; x->x_outmess = x->x_outini; @@ -731,6 +760,16 @@ static t_port *port_new(void) static void port_free(t_port *x) { + if (portps_cleanup->s_thing) + { + /* clean up toplevel glist */ + typedmess(portps_cleanup->s_thing, portps_cleanup, 0, 0); + /* LATER unbind all bogus objects, and destroy all bogushooks + by traversing the portps_cleanup's bindlist, instead of + using per-object clocks. Need to have bindlist traversal + in Pd API first... Otherwise, consider fragilizing this + (and fragilizing grab too). */ + } if (x->x_outmess != x->x_outini) freebytes(x->x_outmess, x->x_outsize * sizeof(*x->x_outmess)); if (x->x_stack != x->x_stackini) @@ -859,16 +898,6 @@ void import_max(char *fn, char *dir) while ((stackp != s__X.s_thing) && (stackp = s__X.s_thing)) vmess(stackp, gensym("pop"), "i", 1); - if (portps_cleanup->s_thing) - { - typedmess(portps_cleanup->s_thing, portps_cleanup, 0, 0); - /* LATER unbind all bogus objects, and destroy all bogushooks - by traversing the portps_cleanup's bindlist, instead of - using per-object clocks. Need to have bindlist traversal - in Pd API first... Otherwise, consider fragilizing this - (and fragilizing grab too). */ - } - #if 0 /* LATER */ pd_doloadbang(); #endif diff --git a/shared/unstable/Makefile.sources b/shared/unstable/Makefile.sources index 4636701..56f9969 100644 --- a/shared/unstable/Makefile.sources +++ b/shared/unstable/Makefile.sources @@ -1,4 +1,5 @@ OTHER_SOURCES = \ -fragile.c \ forky.c \ +fragile.c \ +fringe.c \ loader.c diff --git a/shared/unstable/forky.c b/shared/unstable/forky.c index 100f0af..2e17253 100644 --- a/shared/unstable/forky.c +++ b/shared/unstable/forky.c @@ -2,6 +2,8 @@ * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ +/* Put here compilation conditionals supporting older Pd versions. */ + #include "m_pd.h" #include "g_canvas.h" #include "shared.h" @@ -10,14 +12,19 @@ #if FORKY_VERSION < 37 /* need this for t_class::c_wb field access */ #include "unstable/pd_imp.h" +#endif -t_pd *pd_newest(void) +//#define FORKY_DEBUG + +t_pd *forky_newobject(t_symbol *s, int ac, t_atom *av) { +#if FORKY_VERSION >= 37 + typedmess(&pd_objectmaker, s, ac, av); + return (pd_newest()); +#else return (0); -} #endif - -#define FORKY_DEBUG +} void forky_setsavefn(t_class *c, t_forkysavefn fn) { diff --git a/shared/unstable/forky.h b/shared/unstable/forky.h index a32f8d6..bf59783 100644 --- a/shared/unstable/forky.h +++ b/shared/unstable/forky.h @@ -17,12 +17,12 @@ #define FORKY_WIDGETPADDING #else #define FORKY_WIDGETPADDING 0,0 -t_pd *pd_newest(void); #endif typedef void (*t_forkysavefn)(t_gobj *x, t_binbuf *bb); typedef void (*t_forkypropertiesfn)(t_gobj *x, t_glist *gl); +t_pd *forky_newobject(t_symbol *s, int ac, t_atom *av); void forky_setsavefn(t_class *c, t_forkysavefn fn); void forky_setpropertiesfn(t_class *c, t_forkypropertiesfn fn); int forky_hasfeeders(t_object *x, t_glist *glist, int inno, t_symbol *outsym); diff --git a/shared/unstable/fragile.c b/shared/unstable/fragile.c index a5c9584..2c9e8e3 100644 --- a/shared/unstable/fragile.c +++ b/shared/unstable/fragile.c @@ -2,6 +2,8 @@ * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ +/* Put here bits and pieces likely to break with any new Pd version. */ + #include #include "m_pd.h" #include "unstable/pd_imp.h" diff --git a/shared/unstable/fringe.c b/shared/unstable/fringe.c new file mode 100644 index 0000000..cf29ec6 --- /dev/null +++ b/shared/unstable/fringe.c @@ -0,0 +1,98 @@ +/* Copyright (c) 1997-2003 Miller Puckette, krzYszcz, and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +/* Put here calls which are likely to (and should) make into Pd API some day. */ + +#include "m_pd.h" +#include "g_canvas.h" +#include "unstable/forky.h" +#include "unstable/fringe.h" + +static int gobj_getindex(t_glist *gl, t_gobj *ob) +{ + t_gobj *ob1; + int ndx; + for (ob1 = gl->gl_list, ndx = 0; ob1 && ob1 != ob; ob1 = ob1->g_next) + ndx++; + return (ndx); +} + +static void gobj_totail(t_glist *gl, t_gobj *ob) +{ + if (ob->g_next) + { + t_gobj *ob1; + if (ob == gl->gl_list) ob1 = gl->gl_list = ob->g_next; + else + { + for (ob1 = gl->gl_list; ob1; ob1 = ob1->g_next) + if (ob1->g_next == ob) + break; + if (!ob1) + { + bug("gobj_totail"); + return; + } + ob1->g_next = ob->g_next; + ob1 = ob1->g_next; + } + while (ob1->g_next) ob1 = ob1->g_next; + ob1->g_next = ob; + ob->g_next = 0; + } +} + +static void gobj_stowconnections(t_glist *gl, t_gobj *ob, t_binbuf *bb) +{ + t_linetraverser lt; + t_outconnect *oc; + binbuf_clear(bb); + linetraverser_start(<, gl); + while (oc = linetraverser_next(<)) + { + if ((t_gobj *)lt.tr_ob == ob || (t_gobj *)lt.tr_ob2 == ob) + binbuf_addv(bb, "ssiiii;", + gensym("#X"), gensym("connect"), + gobj_getindex(gl, (t_gobj *)lt.tr_ob), lt.tr_outno, + gobj_getindex(gl, (t_gobj *)lt.tr_ob2), lt.tr_inno); + } +#if 0 + post("packed connections:"); + binbuf_print(bb); +#endif +} + +static void gobj_restoreconnections(t_glist *gl, t_binbuf *bb) +{ + pd_bind((t_pd *)gl, gensym("#X")); + binbuf_eval(bb, 0, 0, 0); + pd_unbind((t_pd *)gl, gensym("#X")); +} + +void gobj_recreate(t_glist *gl, t_gobj *ob, t_binbuf *bb) +{ + /* LATER revisit all gobj calls, and sort out the gop case */ + t_text *newt; + int xpix = ((t_text *)ob)->te_xpix, ypix = ((t_text *)ob)->te_ypix; + t_binbuf *bb1 = binbuf_new(); + int ac = binbuf_getnatom(bb); + t_atom *av = binbuf_getvec(bb); + canvas_setcurrent(gl); + gobj_totail(gl, ob); + gobj_stowconnections(gl, ob, bb1); + glist_delete(gl, ob); + if (newt = (t_text *)forky_newobject(av->a_w.w_symbol, ac - 1, av + 1)) + { + newt->te_binbuf = bb; + newt->te_xpix = xpix; + newt->te_ypix = ypix; + newt->te_width = 0; + newt->te_type = T_OBJECT; + glist_add(gl, (t_gobj *)newt); + gobj_restoreconnections(gl, bb1); + } + else bug("gobj_recreate"); + binbuf_free(bb1); + canvas_unsetcurrent(gl); +} diff --git a/shared/unstable/fringe.h b/shared/unstable/fringe.h new file mode 100644 index 0000000..0768183 --- /dev/null +++ b/shared/unstable/fringe.h @@ -0,0 +1,10 @@ +/* Copyright (c) 1997-2003 Miller Puckette, krzYszcz, and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#ifndef __FRINGE_H__ +#define __FRINGE_H__ + +void gobj_recreate(t_glist *gl, t_gobj *ob, t_binbuf *bb); + +#endif -- cgit v1.2.1