Update of /cvsroot/pure-data/externals/grill/dynext/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7907/src
Modified Files:
main.cpp
Log Message:
query visibility status
- strip .pd from abstraction filenames
fixes for OSX
- open debug patcher on alt-click
cleanups
fixed several problems with sub-patchers and connecting
documentation
enabled reuse of object names
Index: main.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/dynext/src/main.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** main.cpp 19 Mar 2005 04:57:41 -0000 1.6
--- main.cpp 16 Apr 2005 21:36:30 -0000 1.7
***************
*** 46,50 ****
virtual ~dyn();
! void m_reset();
void m_reload(); // refresh objects/abstractions
void m_newobj(int argc,const t_atom *argv);
--- 46,50 ----
virtual ~dyn();
! void m_reset() { DoExit(); DoInit(); }
void m_reload(); // refresh objects/abstractions
void m_newobj(int argc,const t_atom *argv);
***************
*** 64,88 ****
static const t_symbol *k_obj,*k_msg,*k_text;
! class obj {
public:
! obj(unsigned long i,t_gobj *o): id(i),object(o),nxt(NULL) {}
! void Add(obj *o);
! unsigned long id;
t_gobj *object;
! obj *nxt;
! } *root;
! obj *Find(const t_symbol *n);
t_glist *FindCanvas(const t_symbol *n);
! void Add(const t_symbol *n,t_gobj *o);
t_gobj *New(const t_symbol *kind,int _argc_,const t_atom *_argv_,bool add = true);
- void Delete(t_gobj *o);
void ConnDis(bool conn,int argc,const t_atom *argv);
virtual bool CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv);
virtual bool CbDsp();
--- 64,102 ----
static const t_symbol *k_obj,*k_msg,*k_text;
! class Obj {
public:
! Obj(t_glist *gl,t_gobj *o): glist(gl),object(o) {}
! t_glist *AsGlist() const
! {
! return pd_class(&object->g_pd) == canvas_class?(t_glist *)object:NULL;
! }
! t_glist *glist;
t_gobj *object;
! };
!
! 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); }
t_glist *FindCanvas(const t_symbol *n);
!
! Obj *Remove(const t_symbol *n);
! bool Add(const t_symbol *n,t_glist *gl,t_gobj *o);
t_gobj *New(const t_symbol *kind,int _argc_,const t_atom *_argv_,bool add = true);
void ConnDis(bool conn,int argc,const t_atom *argv);
+ void DoInit();
+ void DoExit();
+ void NewProxies();
+ void DelProxies();
+
virtual bool CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv);
virtual bool CbDsp();
***************
*** 292,296 ****
dyn::dyn(int argc,const t_atom *argv):
- root(NULL),
canvas(NULL),
pxin(NULL),pxout(NULL),
--- 306,309 ----
***************
*** 308,313 ****
m_outlets = GetAInt(argv[3]);
- int i;
-
// --- make a sub-canvas for dyn~ ------
--- 321,324 ----
***************
*** 324,329 ****
canvas_unsetcurrent(canvas);
! // --- create inlet proxies ------
pxin = new proxyin *[s_inlets+m_inlets];
for(i = 0; i < s_inlets+m_inlets; ++i) {
--- 335,377 ----
canvas_unsetcurrent(canvas);
! DoInit();
!
! AddInSignal("Messages (newobj,newmsg,newtext,del,conn,dis)");
! AddInSignal(s_inlets);
! AddInAnything(m_inlets);
! AddOutSignal(s_outlets);
! AddOutAnything(m_outlets);
! }
!
! dyn::~dyn()
! {
! DoExit();
!
! if(canvas) pd_free((t_pd *)canvas);
! }
!
! void dyn::DoInit()
! {
! // add to list of canvases
! groot.insert(canvas,new GObjMap);
!
! NewProxies();
! }
!
! void dyn::DoExit()
! {
! // delete proxies
! DelProxies();
! // remove all objects
! glist_clear(canvas);
! // remove all names
! groot.clear();
! root.clear();
! }
+ void dyn::NewProxies()
+ {
+ // --- create inlet proxies ------
+ int i;
pxin = new proxyin *[s_inlets+m_inlets];
for(i = 0; i < s_inlets+m_inlets; ++i) {
***************
*** 367,399 ****
}
}
-
- AddInSignal("Messages (newobj,newmsg,newtext,del,conn,dis)");
- AddInSignal(s_inlets);
- AddInAnything(m_inlets);
- AddOutSignal(s_outlets);
- AddOutAnything(m_outlets);
}
! dyn::~dyn()
{
! m_reset();
!
! if(canvas) pd_free((t_pd *)canvas);
!
if(pxin) delete[] pxin;
if(pxout) delete[] pxout;
}
-
- void dyn::obj::Add(obj *o) { if(nxt) nxt->Add(o); else nxt = o; }
-
- dyn::obj *dyn::Find(const t_symbol *n)
- {
- unsigned long id = *(unsigned long *)n;
- obj *o;
- for(o = root; o && o->id != id; o = o->nxt) {}
- return o;
- }
-
t_glist *dyn::FindCanvas(const t_symbol *n)
{
--- 415,429 ----
}
}
}
! void dyn::DelProxies()
{
! int i;
! for(i = 0; i < s_inlets+m_inlets; ++i) glist_delete(canvas,(t_gobj *)pxin[i]);
if(pxin) delete[] pxin;
+ for(i = 0; i < s_outlets+m_outlets; ++i) glist_delete(canvas,(t_gobj *)pxout[i]);
if(pxout) delete[] pxout;
}
t_glist *dyn::FindCanvas(const t_symbol *n)
{
***************
*** 401,424 ****
return canvas;
else {
! obj *o = Find(n);
! if(o && pd_class(&o->object->g_pd) == canvas_class)
! return (t_glist *)o->object;
! else
! return NULL;
}
}
- void dyn::Add(const t_symbol *n,t_gobj *ob)
- {
- unsigned long id = *(unsigned long *)n;
- obj *o = new obj(id,ob);
- if(root) root->Add(o); else root = o;
- }
-
- void dyn::Delete(t_gobj *o)
- {
- glist_delete(canvas,o);
- }
-
static t_gobj *GetLast(t_glist *gl)
{
--- 431,440 ----
return canvas;
else {
! Obj *o = Find(n);
! t_glist *gl = o->AsGlist();
! return gl && groot.find(gl)?(t_glist *)o->object:NULL;
}
}
static t_gobj *GetLast(t_glist *gl)
{
***************
*** 434,451 ****
t_gobj *newest = NULL;
const char *err = NULL;
- int argc = 0;
- t_atom *argv = NULL;
const t_symbol *name = NULL,*canv = NULL;
t_glist *glist = NULL;
if(_argc_ >= 4 && CanbeInt(_argv_[0]) && CanbeInt(_argv_[1]) && IsSymbol(_argv_[2]) && IsSymbol(_argv_[3])) {
canv = GetSymbol(_argv_[2]);
name = GetSymbol(_argv_[3]);
! argc = _argc_-2;
! argv = new t_atom[argc];
! SetInt(argv[0],GetAInt(_argv_[0]));
! SetInt(argv[1],GetAInt(_argv_[1]));
! for(int i = 0; i < argc-2; ++i) SetAtom(argv[i+2],_argv_[i+4]);
}
else if(_argc_ >= 3 && IsSymbol(_argv_[0]) && IsSymbol(_argv_[1])) {
--- 450,466 ----
t_gobj *newest = NULL;
const char *err = NULL;
const t_symbol *name = NULL,*canv = NULL;
t_glist *glist = NULL;
+ AtomListStatic<16> args;
+
if(_argc_ >= 4 && CanbeInt(_argv_[0]) && CanbeInt(_argv_[1]) && IsSymbol(_argv_[2]) && IsSymbol(_argv_[3])) {
canv = GetSymbol(_argv_[2]);
name = GetSymbol(_argv_[3]);
! args(_argc_-2);
! SetInt(args[0],GetAInt(_argv_[0]));
! SetInt(args[1],GetAInt(_argv_[1]));
! for(int i = 0; i < _argc_; ++i) SetAtom(args[i+2],_argv_[i+4]);
}
else if(_argc_ >= 3 && IsSymbol(_argv_[0]) && IsSymbol(_argv_[1])) {
***************
*** 453,473 ****
name = GetSymbol(_argv_[1]);
! argc = _argc_;
! argv = new t_atom[argc];
// random position if not given
! SetInt(argv[0],rand()%600);
! SetInt(argv[1],50+rand()%400);
! for(int i = 0; i < argc-2; ++i) SetAtom(argv[i+2],_argv_[i+2]);
}
! if(argv) {
! if(add && (!name || name == sym_dot || Find(name)))
! err = "Object name is already present";
else if(!canv || !(glist = FindCanvas(canv)))
err = "Canvas could not be found";
else {
// convert abstraction filenames
! if(stripext && kind == k_obj && argc >= 3 && IsSymbol(argv[2])) {
! const char *c = GetString(argv[2]);
int l = strlen(c);
// check end of string for .pd file extension
--- 468,487 ----
name = GetSymbol(_argv_[1]);
! args(_argc_);
// random position if not given
! SetInt(args[0],rand()%600);
! SetInt(args[1],50+rand()%400);
! for(int i = 0; i < _argc_-2; ++i) SetAtom(args[i+2],_argv_[i+2]);
}
! if(args.Count()) {
! if(name == sym_dot)
! err = ". cannot be redefined";
else if(!canv || !(glist = FindCanvas(canv)))
err = "Canvas could not be found";
else {
// convert abstraction filenames
! if(stripext && kind == k_obj && args.Count() >= 3 && IsSymbol(args[2])) {
! const char *c = GetString(args[2]);
int l = strlen(c);
// check end of string for .pd file extension
***************
*** 477,481 ****
if(l > sizeof tmp-1) t = new char[l+1];
memcpy(tmp,c,l-3); tmp[l-3] = 0;
! SetString(argv[2],tmp);
if(tmp != t) delete[] t;
}
--- 491,495 ----
if(l > sizeof tmp-1) t = new char[l+1];
memcpy(tmp,c,l-3); tmp[l-3] = 0;
! SetString(args[2],tmp);
if(tmp != t) delete[] t;
}
***************
*** 486,490 ****
t_gobj *last = GetLast(glist);
! pd_typedmess((t_pd *)glist,(t_symbol *)kind,argc,argv);
newest = GetLast(glist);
--- 500,504 ----
t_gobj *last = GetLast(glist);
! pd_typedmess((t_pd *)glist,(t_symbol *)kind,args.Count(),args.Atoms());
newest = GetLast(glist);
***************
*** 510,514 ****
if(newest) {
// add to database
! if(add) Add(name,newest);
// send loadbang (if it is an abstraction)
--- 524,531 ----
if(newest) {
// add to database
! if(add) {
! bool ok = Add(name,glist,newest);
! FLEXT_ASSERT(ok);
! }
// send loadbang (if it is an abstraction)
***************
*** 530,535 ****
canvas_unsetcurrent(glist);
}
-
- delete[] argv;
}
else
--- 547,550 ----
***************
*** 541,555 ****
}
!
! void dyn::m_reset()
{
! obj *o = root;
! while(o) {
! Delete(o->object);
! obj *n = o->nxt;
! delete o;
! o = n;
! }
! root = NULL;
}
--- 556,615 ----
}
! 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;
}
***************
*** 594,609 ****
void dyn::m_del(const t_symbol *n)
{
! unsigned long id = *(unsigned long *)n;
!
! obj *p = NULL,*o = root;
! for(; o && o->id != id; p = o,o = o->nxt) {}
!
! if(o) {
! if(p) p->nxt = o->nxt; else root = o->nxt;
!
! Delete(o->object);
! delete o;
! }
! else
post("%s - del: object not found",thisName());
}
--- 654,663 ----
void dyn::m_del(const t_symbol *n)
{
! Obj *obj = Remove(n);
! if(obj) {
! glist_delete(obj->glist,obj->object);
! delete obj;
! }
! else
post("%s - del: object not found",thisName());
}
***************
*** 645,650 ****
t_text *s_obj,*d_obj;
if(s_n) {
! obj *s_o = Find(s_n);
if(!s_o) {
post("%s - connect: source \"%s\" not found",thisName(),GetString(s_n));
--- 699,705 ----
t_text *s_obj,*d_obj;
+ t_glist *s_cnv,*d_cnv;
if(s_n) {
! Obj *s_o = Find(s_n);
if(!s_o) {
post("%s - connect: source \"%s\" not found",thisName(),GetString(s_n));
***************
*** 652,655 ****
--- 707,711 ----
}
s_obj = (t_text *)s_o->object;
+ s_cnv = s_o->glist;
}
else if(s_x < 0 && s_x >= s_inlets+m_inlets) {
***************
*** 659,667 ****
else {
s_obj = &pxin[s_x]->obj;
s_x = 0; // always 0 for proxy
}
if(d_n) {
! obj *d_o = Find(d_n);
if(!d_o) {
post("%s - connect: destination \"%s\" not found",thisName(),GetString(d_n));
--- 715,724 ----
else {
s_obj = &pxin[s_x]->obj;
+ s_cnv = canvas;
s_x = 0; // always 0 for proxy
}
if(d_n) {
! Obj *d_o = Find(d_n);
if(!d_o) {
post("%s - connect: destination \"%s\" not found",thisName(),GetString(d_n));
***************
*** 669,672 ****
--- 726,730 ----
}
d_obj = (t_text *)d_o->object;
+ d_cnv = d_o->glist;
}
else if(d_x < 0 && d_x >= s_outlets+m_outlets) {
***************
*** 676,694 ****
else {
d_obj = &pxout[d_x]->obj;
d_x = 0; // always 0 for proxy
}
#ifndef NO_VIS
! int s_oix = canvas_getindex(canvas,&s_obj->te_g);
! int d_oix = canvas_getindex(canvas,&d_obj->te_g);
#endif
if(conn) {
! if(!canvas_isconnected(canvas,(t_text *)s_obj,s_x,(t_text *)d_obj,d_x)) {
#ifdef NO_VIS
if(!obj_connect(s_obj, s_x, d_obj, d_x))
post("%s - connect: connection could not be made",thisName());
#else
! canvas_connect(canvas,s_oix,s_x,d_oix,d_x);
#endif
}
--- 734,758 ----
else {
d_obj = &pxout[d_x]->obj;
+ d_cnv = canvas;
d_x = 0; // always 0 for proxy
}
+ if(s_cnv != d_cnv) {
+ post("%s - connect: objects \"%s\" and \"%s\" are not on same canvas",thisName(),GetString(s_n),GetString(d_n));
+ return;
+ }
+
#ifndef NO_VIS
! int s_oix = canvas_getindex(s_cnv,&s_obj->te_g);
! int d_oix = canvas_getindex(d_cnv,&d_obj->te_g);
#endif
if(conn) {
! if(!canvas_isconnected(s_cnv,(t_text *)s_obj,s_x,(t_text *)d_obj,d_x)) {
#ifdef NO_VIS
if(!obj_connect(s_obj, s_x, d_obj, d_x))
post("%s - connect: connection could not be made",thisName());
#else
! canvas_connect(s_cnv,s_oix,s_x,d_oix,d_x);
#endif
}
***************
*** 698,704 ****
obj_disconnect(s_obj, s_x, d_obj, d_x);
#else
! canvas_disconnect(canvas,s_oix,s_x,d_oix,d_x);
#endif
}
}
--- 762,770 ----
obj_disconnect(s_obj, s_x, d_obj, d_x);
#else
! canvas_disconnect(s_cnv,s_oix,s_x,d_oix,d_x);
#endif
}
+
+ // canvas_fixlinesfor(s_cnv,(t_text *)s_x);
}
***************
*** 722,726 ****
post("%s - Syntax: send name message [args]",thisName());
else {
! obj *o = Find(GetSymbol(argv[0]));
if(!o)
post("%s - send: object \"%s\" not found",thisName(),GetString(argv[0]));
--- 788,792 ----
post("%s - Syntax: send name message [args]",thisName());
else {
! Obj *o = Find(GetSymbol(argv[0]));
if(!o)
post("%s - send: object \"%s\" not found",thisName(),GetString(argv[0]));