Update of /cvsroot/pure-data/externals/grill/dynext/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29172/src
Modified Files: main.cpp Log Message: fixed several problems with sub-patchers and connecting enabled reuse of object names introduced attributes for symbol reuse and canvas messages
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/dynext/src/main.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.cpp 16 Apr 2005 21:36:30 -0000 1.7 --- main.cpp 18 Apr 2005 15:08:14 -0000 1.8 *************** *** 77,86 **** };
! typedef TablePtrMapOwned<const t_symbol *,Obj *> ObjMap; ! ObjMap root;
typedef TablePtrMap<Obj *,const t_symbol *> GObjMap; ! typedef TablePtrMapOwned<t_glist *,GObjMap *> GLstMap; ! GLstMap groot;
Obj *Find(const t_symbol *n) { return root.find(n); } --- 77,107 ---- };
! class ObjMap ! :public TablePtrMap<const t_symbol *,Obj *> ! { ! public: ! virtual ~ObjMap() { clear(); } ! ! virtual void clear() ! { ! for(iterator it(*this); it; ++it) delete it.data(); ! TablePtrMap<const t_symbol *,Obj *>::clear(); ! } ! } root;
typedef TablePtrMap<Obj *,const t_symbol *> GObjMap; ! ! class GLstMap ! :public TablePtrMap<t_glist *,GObjMap *> ! { ! public: ! virtual ~GLstMap() { clear(); } ! ! virtual void clear() ! { ! for(iterator it(*this); it; ++it) delete it.data(); ! TablePtrMap<t_glist *,GObjMap *>::clear(); ! } ! } groot;
Obj *Find(const t_symbol *n) { return root.find(n); } *************** *** 114,118 **** t_sample defsig;
! void init(dyn *t);
static void px_exit(proxy *px) { if(px->buf) FreeAligned(px->buf); } --- 135,144 ---- t_sample defsig;
! void init(dyn *t) ! { ! th = t; ! n = 0,buf = NULL; ! defsig = 0; ! }
static void px_exit(proxy *px) { if(px->buf) FreeAligned(px->buf); } *************** *** 172,176 **** int m_inlets,s_inlets,m_outlets,s_outlets; t_canvas *canvas; ! bool stripext;
private: --- 198,202 ---- int m_inlets,s_inlets,m_outlets,s_outlets; t_canvas *canvas; ! bool stripext,canvasmsg,symreuse;
private: *************** *** 190,193 **** --- 216,221 ----
FLEXT_ATTRVAR_B(stripext) + FLEXT_ATTRVAR_B(symreuse) + FLEXT_ATTRVAR_B(canvasmsg)
static const t_symbol *sym_dot,*sym_dynsin,*sym_dynsout,*sym_dynin,*sym_dynout,*sym_dyncanvas; *************** *** 261,264 **** --- 289,294 ---- FLEXT_CADDATTR_VAR(c,"vis",mg_vis,ms_vis); FLEXT_CADDATTR_VAR1(c,"stripext",stripext); + FLEXT_CADDATTR_VAR1(c,"symreuse",symreuse); + FLEXT_CADDATTR_VAR1(c,"canvasmsg",canvasmsg);
// set up symbols *************** *** 308,312 **** canvas(NULL), pxin(NULL),pxout(NULL), ! stripext(false) { if(argc < 4) { --- 338,342 ---- canvas(NULL), pxin(NULL),pxout(NULL), ! stripext(false),symreuse(true),canvasmsg(false) { if(argc < 4) { *************** *** 446,449 **** --- 476,537 ---- }
+ bool dyn::Add(const t_symbol *n,t_glist *gl,t_gobj *o) + { + // remove previous name entry + Obj *prv = Remove(n); + if(prv) delete prv; + + // get canvas map + GObjMap *gm = groot.find(gl); + // if none existing create one + if(!gm) return false; + + // insert object to canvas map + Obj *obj = new Obj(gl,o); + gm->insert(obj,n); + // insert object to object map + root.insert(n,obj); + + t_glist *nl = obj->AsGlist(); + if(nl) { + FLEXT_ASSERT(!groot.find(nl)); + groot.insert(nl,new GObjMap); + } + + return true; + } + + dyn::Obj *dyn::Remove(const t_symbol *n) + { + // see if there's already an object of the same name + Obj *prv = root.remove(n); + if(prv) { + t_glist *pl = prv->glist; + // get canvas map + GObjMap *gm = groot.find(pl); + FLEXT_ASSERT(gm); + // remove object from canvas map + gm->remove(prv); + + // non-NULL if object itself is a glist + t_glist *gl = prv->AsGlist(); + if(gl) { + GObjMap *gm = groot.remove(gl); + // if it's a loaded abstraction it need not be in our list + if(gm) { + // remove all objects in canvas map + for(GObjMap::iterator it(*gm); it; ++it) { + Obj *r = Remove(it.data()); + FLEXT_ASSERT(r); + delete r; + } + // delete canvas map + delete gm; + } + } + } + return prv; + } + t_gobj *dyn::New(const t_symbol *kind,int _argc_,const t_atom *_argv_,bool add) { *************** *** 478,481 **** --- 566,571 ---- if(name == sym_dot) err = ". cannot be redefined"; + else if(!symreuse && root.find(name)) + err = "Name already in use"; else if(!canv || !(glist = FindCanvas(canv))) err = "Canvas could not be found"; *************** *** 556,617 **** }
- dyn::Obj *dyn::Remove(const t_symbol *n) - { - // see if there's already an object of the same name - Obj *prv = root.remove(n); - if(prv) { - t_glist *pl = prv->glist; - // get canvas map - GObjMap *gm = groot.find(pl); - FLEXT_ASSERT(gm); - // remove object from canvas map - gm->erase(prv); - - // non-NULL if object itself is a glist - t_glist *gl = prv->AsGlist(); - if(gl) { - GObjMap *gm = groot.remove(gl); - // if it's a loaded abstraction it need not be in our list - if(gm) { - // remove all objects in canvas map - for(GObjMap::iterator it(*gm); it; ++it) { - Obj *r = Remove(it.data()); - FLEXT_ASSERT(r); - delete r; - } - // delete canvas map - delete gm; - } - } - } - return prv; - } - - bool dyn::Add(const t_symbol *n,t_glist *gl,t_gobj *o) - { - // remove previous name entry - Obj *prv = Remove(n); - if(prv) delete prv; - - // get canvas map - GObjMap *gm = groot.find(gl); - // if none existing create one - if(!gm) return false; - - // insert object to canvas map - Obj *obj = new Obj(gl,o); - gm->insert(obj,n); - // insert object to object map - root.insert(n,obj); - - t_glist *nl = obj->AsGlist(); - if(nl) { - FLEXT_ASSERT(!groot.find(nl)); - groot.insert(nl,new GObjMap); - } - - return true; - } - void dyn::m_reload() { --- 646,649 ---- *************** *** 791,795 **** if(!o) post("%s - send: object "%s" not found",thisName(),GetString(argv[0])); ! else pd_forwardmess((t_pd *)o->object,argc-1,(t_atom *)argv+1); } --- 823,829 ---- if(!o) post("%s - send: object "%s" not found",thisName(),GetString(argv[0])); ! else if(!canvasmsg && o->AsGlist()) ! post("%s - send: object "%s" is an abstraction, please create proxy",thisName(),GetString(argv[0])); ! else pd_forwardmess((t_pd *)o->object,argc-1,(t_atom *)argv+1); } *************** *** 797,807 ****
- void dyn::proxy::init(dyn *t) - { - th = t; - n = 0,buf = NULL; - defsig = 0; - } - void dyn::proxyin::dsp(proxyin *x,t_signal **sp) { --- 831,834 ---- *************** *** 862,864 **** CopySamples(out[i],pxout[i]->buf,n); } - --- 889,890 ----