Update of /cvsroot/pure-data/externals/grill/flext/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26961/source
Modified Files:
flclass.h flmsg.cpp flqueue.cpp flsupport.h flthr.cpp
flutil.cpp
Log Message:
changed initialization functions accordingly
small fix
slimmed object data structures
digest one-element list messages as single atoms
made flext::Forward threadsafe
small fixes
simplified message analysis
Index: flutil.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flutil.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** flutil.cpp 26 Jan 2005 05:02:05 -0000 1.16
--- flutil.cpp 7 Jun 2005 14:13:50 -0000 1.17
***************
*** 47,64 ****
#endif
}
-
-
- bool flext::Forward(const t_symbol *recv,const t_symbol *s,int argc,const t_atom *argv)
- {
- void *cl = recv->s_thing;
- if(!cl) return false;
-
- #if FLEXT_SYS == FLEXT_SYS_PD
- pd_typedmess((t_class **)cl,(t_symbol *)s,argc,(t_atom *)argv);
- #elif FLEXT_SYS == FLEXT_SYS_MAX
- typedmess(recv->s_thing,(t_symbol *)s,argc,(t_atom *)argv);
- #else
- #error Not implemented
- #endif
- return true;
- }
--- 47,48 ----
Index: flthr.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flthr.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** flthr.cpp 13 Mar 2005 04:56:40 -0000 1.29
--- flthr.cpp 7 Jun 2005 14:13:49 -0000 1.30
***************
*** 626,630 ****
#endif
tm.tv_nsec = tmb.millitm*1000000;
! tm.tv_sec = tmb.time;
#else // POSIX
#if 0 // find out when the following is defined
--- 626,630 ----
#endif
tm.tv_nsec = tmb.millitm*1000000;
! tm.tv_sec = (long)tmb.time;
#else // POSIX
#if 0 // find out when the following is defined
Index: flsupport.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.h,v
retrieving revision 1.89
retrieving revision 1.90
diff -C2 -d -r1.89 -r1.90
*** flsupport.h 18 Apr 2005 22:05:53 -0000 1.89
--- flsupport.h 7 Jun 2005 14:13:49 -0000 1.90
***************
*** 682,686 ****
//! Set list by another AtomList
! AtomListStatic &operator =(const AtomListStatic &a) { AtomList::operator =(a); return *this; }
protected:
t_atom pre[PRE];
--- 682,686 ----
//! Set list by another AtomList
! AtomListStatic &operator =(const AtomList &a) { AtomList::operator =(a); return *this; }
protected:
t_atom pre[PRE];
***************
*** 743,755 ****
//! Send a message to a symbol (bound to an object)
! static bool Forward(const t_symbol *sym,const t_symbol *s,int argc,const t_atom *argv);
! static bool Forward(const t_symbol *sym,AtomAnything &args) { return Forward(sym,args.Header(),args.Count(),args.Atoms()); }
! static bool Forward(const char *sym,AtomAnything &args) { return Forward(MakeSymbol(sym),args.Header(),args.Count(),args.Atoms()); }
! static bool Forward(const t_symbol *sym,int argc,const t_atom *argv) { return Forward(sym,sym_list,argc,argv); }
! static bool Forward(const t_symbol *sym,AtomList &args) { return Forward(sym,args.Count(),args.Atoms()); }
! static bool Forward(const char *sym,AtomList &args) { return Forward(MakeSymbol(sym),args.Count(),args.Atoms()); }
//! @} FLEXT_S_MSG
--- 743,755 ----
//! Send a message to a symbol (bound to an object)
! static bool Forward(const t_symbol *sym,const t_symbol *s,int argc,const t_atom *argv,bool forcedirect = false);
! static bool Forward(const t_symbol *sym,const AtomAnything &args,bool forcedirect = false) { return Forward(sym,args.Header(),args.Count(),args.Atoms(),forcedirect); }
! static bool Forward(const char *sym,const AtomAnything &args,bool forcedirect = false) { return Forward(MakeSymbol(sym),args.Header(),args.Count(),args.Atoms(),forcedirect); }
! static bool Forward(const t_symbol *sym,int argc,const t_atom *argv,bool forcedirect = false) { return Forward(sym,sym_list,argc,argv,forcedirect); }
! static bool Forward(const t_symbol *sym,const AtomList &args,bool forcedirect = false) { return Forward(sym,args.Count(),args.Atoms(),forcedirect); }
! static bool Forward(const char *sym,const AtomList &args,bool forcedirect = false) { return Forward(MakeSymbol(sym),args.Count(),args.Atoms(),forcedirect); }
//! @} FLEXT_S_MSG
Index: flqueue.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flqueue.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** flqueue.cpp 25 Apr 2005 12:50:35 -0000 1.32
--- flqueue.cpp 7 Jun 2005 14:13:43 -0000 1.33
***************
*** 50,67 ****
}
// \note PD sys lock must already be held by caller
inline void Send() const
{
! if(out < 0)
! // message to self
! th->CbMethodHandler(-1-out,msg.Header(),msg.Count(),msg.Atoms());
else
! // message to outlet
! th->ToSysAnything(out,msg.Header(),msg.Count(),msg.Atoms());
}
private:
flext_base *th;
! int out;
AtomAnything msg;
};
--- 50,82 ----
}
+ inline qmsg &Set(const t_symbol *r,const t_symbol *s,int ac,const t_atom *av)
+ {
+ th = NULL;
+ recv = r;
+ msg(s,ac,av);
+ return *this;
+ }
+
// \note PD sys lock must already be held by caller
inline void Send() const
{
! if(th) {
! if(out < 0)
! // message to self
! th->CbMethodHandler(-1-out,msg.Header(),msg.Count(),msg.Atoms());
! else
! // message to outlet
! th->ToSysAnything(out,msg.Header(),msg.Count(),msg.Atoms());
! }
else
! flext::Forward(recv,msg,true);
}
private:
flext_base *th;
! union {
! int out;
! const t_symbol *recv;
! };
AtomAnything msg;
};
***************
*** 87,90 ****
--- 102,114 ----
}
+ inline void Push(const t_symbol *r,const t_symbol *s,int ac,const t_atom *av)
+ {
+ qmsg *m = QueueFifo::New();
+ FLEXT_ASSERT(m);
+ m->Set(r,s,ac,av);
+ Put(m);
+ Trigger();
+ }
+
inline void Push(flext_base *th,int o) // bang
{
***************
*** 337,338 ****
--- 361,383 ----
queue.Push(const_cast<flext_base *>(this),o,s,argc,argv);
}
+
+
+ bool flext::Forward(const t_symbol *recv,const t_symbol *s,int argc,const t_atom *argv,bool direct)
+ {
+ if(direct || IsSystemThread()) {
+ void *cl = recv->s_thing;
+ if(!cl) return false;
+
+ #if FLEXT_SYS == FLEXT_SYS_PD
+ pd_typedmess((t_class **)cl,(t_symbol *)s,argc,(t_atom *)argv);
+ #elif FLEXT_SYS == FLEXT_SYS_MAX
+ typedmess(recv->s_thing,(t_symbol *)s,argc,(t_atom *)argv);
+ #else
+ #error Not implemented
+ #endif
+ }
+ else
+ // send over queue
+ queue.Push(recv,s,argc,argv);
+ return true;
+ }
Index: flmsg.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flmsg.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** flmsg.cpp 23 May 2005 16:52:45 -0000 1.16
--- flmsg.cpp 7 Jun 2005 14:13:43 -0000 1.17
***************
*** 15,75 ****
#include "flext.h"
- bool flext_base::CallMeth(const MethItem &m,int argc,const t_atom *argv)
- {
- bool ret = false;
- int ix;
- t_any aargs[FLEXT_MAXMETHARGS];
- bool ok = true;
- for(ix = 0; ix < argc && ok; ++ix) {
- switch(m.args[ix]) {
- case a_float: {
- if(IsFloat(argv[ix])) aargs[ix].ft = GetFloat(argv[ix]);
- else if(IsInt(argv[ix])) aargs[ix].ft = (float)GetInt(argv[ix]);
- else ok = false;
-
- if(ok) FLEXT_LOG2("int arg %i = %f",ix,aargs[ix].ft);
- break;
- }
- case a_int: {
- if(IsFloat(argv[ix])) aargs[ix].it = (int)GetFloat(argv[ix]);
- else if(IsInt(argv[ix])) aargs[ix].it = GetInt(argv[ix]);
- else ok = false;
-
- if(ok) FLEXT_LOG2("float arg %i = %i",ix,aargs[ix].it);
- break;
- }
- case a_symbol: {
- if(IsSymbol(argv[ix])) aargs[ix].st = GetSymbol(argv[ix]);
- else ok = false;
-
- if(ok) FLEXT_LOG2("symbol arg %i = %s",ix,GetString(aargs[ix].st));
- break;
- }
- #if FLEXT_SYS == FLEXT_SYS_PD
- case a_pointer: {
- if(IsPointer(argv[ix])) aargs[ix].pt = (t_gpointer *)GetPointer(argv[ix]);
- else ok = false;
- break;
- }
- #endif
- default:
- error("Argument type illegal");
- ok = false;
- }
- }
-
- if(ok && ix == argc) {
- switch(argc) {
- case 0: ret = ((methfun_0)m.fun)(this); break;
- case 1: ret = ((methfun_1)m.fun)(this,aargs[0]); break;
- case 2: ret = ((methfun_2)m.fun)(this,aargs[0],aargs[1]); break;
- case 3: ret = ((methfun_3)m.fun)(this,aargs[0],aargs[1],aargs[2]); break;
- case 4: ret = ((methfun_4)m.fun)(this,aargs[0],aargs[1],aargs[2],aargs[3]); break;
- case 5: ret = ((methfun_5)m.fun)(this,aargs[0],aargs[1],aargs[2],aargs[3],aargs[4]); break;
- }
- }
-
- return ret;
- }
bool flext_base::TryMethTag(Item *lst,const t_symbol *tag,int argc,const t_atom *argv)
--- 15,18 ----
***************
*** 90,102 ****
else {
if(m->argc == 1) {
! // try list
! if(m->args[0] == a_list && ((methfun_V)m->fun)(this,argc,const_cast<t_atom *>(argv))) return true;
!
! // try anything
! if(m->args[0] == a_any && ((methfun_A)m->fun)(this,tag,argc,const_cast<t_atom *>(argv))) return true;
}
// try matching number of args
! if(argc == m->argc && CallMeth(*m,argc,argv)) return true;
}
}
--- 33,102 ----
else {
if(m->argc == 1) {
! if(m->args[0] == a_list) {
! // try list
! if(((methfun_V)m->fun)(this,argc,const_cast<t_atom *>(argv))) return true;
! }
! else if(m->args[0] == a_any) {
! // try anything
! if(((methfun_A)m->fun)(this,tag,argc,const_cast<t_atom *>(argv))) return true;
! }
}
// try matching number of args
! if(m->argc == argc) {
! int ix;
! t_any aargs[FLEXT_MAXMETHARGS];
! bool ok = true;
! for(ix = 0; ix < argc && ok; ++ix) {
! switch(m->args[ix]) {
! case a_float: {
! if(IsFloat(argv[ix])) aargs[ix].ft = GetFloat(argv[ix]);
! else if(IsInt(argv[ix])) aargs[ix].ft = (float)GetInt(argv[ix]);
! else ok = false;
!
! if(ok) FLEXT_LOG2("int arg %i = %f",ix,aargs[ix].ft);
! break;
! }
! case a_int: {
! if(IsFloat(argv[ix])) aargs[ix].it = (int)GetFloat(argv[ix]);
! else if(IsInt(argv[ix])) aargs[ix].it = GetInt(argv[ix]);
! else ok = false;
!
! if(ok) FLEXT_LOG2("float arg %i = %i",ix,aargs[ix].it);
! break;
! }
! case a_symbol: {
! if(IsSymbol(argv[ix])) aargs[ix].st = GetSymbol(argv[ix]);
! else ok = false;
!
! if(ok) FLEXT_LOG2("symbol arg %i = %s",ix,GetString(aargs[ix].st));
! break;
! }
! #if FLEXT_SYS == FLEXT_SYS_PD
! case a_pointer: {
! if(IsPointer(argv[ix])) aargs[ix].pt = (t_gpointer *)GetPointer(argv[ix]);
! else ok = false;
! break;
! }
! #endif
! default:
! error("Argument type illegal");
! ok = false;
! }
! }
!
! if(ok && ix == argc) {
! switch(argc) {
! case 0: return ((methfun_0)m->fun)(this);
! case 1: return ((methfun_1)m->fun)(this,aargs[0]);
! case 2: return ((methfun_2)m->fun)(this,aargs[0],aargs[1]);
! case 3: return ((methfun_3)m->fun)(this,aargs[0],aargs[1],aargs[2]);
! case 4: return ((methfun_4)m->fun)(this,aargs[0],aargs[1],aargs[2],aargs[3]);
! case 5: return ((methfun_5)m->fun)(this,aargs[0],aargs[1],aargs[2],aargs[3],aargs[4]);
! default:
! FLEXT_ASSERT(false);
! }
! }
! }
}
}
***************
*** 104,107 ****
--- 104,108 ----
}
+ /*
bool flext_base::TryMethSym(Item *lst,const t_symbol *s)
{
***************
*** 118,121 ****
--- 119,123 ----
return false;
}
+ */
bool flext_base::TryMethAny(Item *lst,const t_symbol *s,int argc,const t_atom *argv)
***************
*** 144,160 ****
if((lst = methhead.FindList(s,inlet)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
if((lst = clmethhead->FindList(s,inlet)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
!
! // if no list args, then search for pure symbol
! if(!argc) {
! if((lst = methhead.FindList(sym_symbol,inlet)) != NULL && TryMethSym(lst,s)) return true;
! if((lst = clmethhead->FindList(sym_symbol,inlet)) != NULL && TryMethSym(lst,s)) return true;
! }
!
! // otherwise search for anything
if((lst = methhead.FindList(sym_anything,inlet)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
if((lst = clmethhead->FindList(sym_anything,inlet)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
// if nothing found try any inlet
! return inlet >= 0 && FindMeth(-1,s,argc,argv);
}
--- 146,170 ----
if((lst = methhead.FindList(s,inlet)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
if((lst = clmethhead->FindList(s,inlet)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
!
! // if nothing found try any inlet
! if((lst = methhead.FindList(s,-1)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
! if((lst = clmethhead->FindList(s,-1)) != NULL && TryMethTag(lst,s,argc,argv)) return true;
!
! return false;
! }
!
! bool flext_base::FindMethAny(int inlet,const t_symbol *s,int argc,const t_atom *argv)
! {
! Item *lst;
! ItemCont *clmethhead = ClMeths(thisClassId());
!
if((lst = methhead.FindList(sym_anything,inlet)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
if((lst = clmethhead->FindList(sym_anything,inlet)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
// if nothing found try any inlet
! if((lst = methhead.FindList(sym_anything,-1)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
! if((lst = clmethhead->FindList(sym_anything,-1)) != NULL && TryMethAny(lst,s,argc,argv)) return true;
!
! return false;
}
***************
*** 165,168 ****
--- 175,179 ----
{
static bool trap = false;
+ bool ret;
curtag = s;
***************
*** 170,234 ****
// post("methodmain inlet:%i args:%i symbol:%s",inlet,argc,s?GetString(s):"");
- bool ret = FindMeth(inlet,s,argc,argv);
- if(ret) goto end;
-
try {
!
! #if FLEXT_SYS == FLEXT_SYS_MAX
! // If float message is not explicitly handled: try int handler instead
! if(argc == 1 && s == sym_float && !trap) {
! t_atom fl;
! SetInt(fl,GetAInt(argv[0]));
! trap = true;
! ret = CbMethodHandler(inlet,sym_int,1,&fl);
! trap = false;
! }
! if(ret) goto end;
!
! // If int message is not explicitly handled: try float handler instead
! if(argc == 1 && s == sym_int && !trap) {
! t_atom fl;
! SetFloat(fl,GetAFloat(argv[0]));
! trap = true;
! ret = CbMethodHandler(inlet,sym_float,1,&fl);
! trap = false;
! }
if(ret) goto end;
- #endif
-
- // If float or int message is not explicitly handled: try list handler instead
- if(!trap && argc == 1 && (s == sym_float || s == sym_symbol
- #if FLEXT_SYS == FLEXT_SYS_MAX
- || s == sym_int
- #endif
- )) {
- t_atom list;
- if(s == sym_float)
- SetFloat(list,GetFloat(argv[0]));
- #if FLEXT_SYS == FLEXT_SYS_MAX
- else if(s == sym_int)
- SetInt(list,GetInt(argv[0]));
- #endif
- else if(s == sym_symbol)
- SetSymbol(list,GetSymbol(argv[0]));
! trap = true;
! ret = CbMethodHandler(inlet,sym_list,1,&list);
! trap = false;
}
! if(ret) goto end;
!
! // If symbol message (pure anything without args) is not explicitly handled: try list handler instead
! if(!trap && argc == 0) {
! t_atom list;
! SetSymbol(list,s);
! trap = true;
! ret = CbMethodHandler(inlet,sym_list,1,&list);
! trap = false;
}
- if(ret) goto end;
// if distmsgs is switched on then distribute list elements over inlets (Max/MSP behavior)
! if(DoDist() && !trap && inlet == 0 && s == sym_list && insigs <= 1) {
int i = incnt;
if(i > argc) i = argc;
--- 181,248 ----
// post("methodmain inlet:%i args:%i symbol:%s",inlet,argc,s?GetString(s):"");
try {
! ret = FindMeth(inlet,s,argc,argv);
if(ret) goto end;
! if(argc == 1) {
! if(s == sym_list) {
! // for 1-element lists try the single atom (this is the format output by [route])
! if(IsFloat(argv[0]))
! ret = FindMeth(inlet,sym_float,1,argv);
! else if(IsInt(argv[0]))
! ret = FindMeth(inlet,sym_int,1,argv);
! else if(IsSymbol(argv[0]))
! ret = FindMeth(inlet,sym_symbol,1,argv);
! else if(IsPointer(argv[0]))
! ret = FindMeth(inlet,sym_pointer,1,argv);
! if(ret) goto end;
! }
! else {
! if(s == sym_float) {
! #if FLEXT_SYS == FLEXT_SYS_MAX
! t_atom at;
! // If float message is not explicitly handled: try int handler instead
! SetInt(at,(int)GetFloat(argv[0]));
! ret = FindMeth(inlet,sym_int,1,&at);
! if(ret) goto end;
! #endif
! // If not explicitly handled: try list handler instead
! ret = FindMeth(inlet,sym_list,1,argv);
! if(ret) goto end;
! }
! #if FLEXT_SYS == FLEXT_SYS_MAX
! else if(s == sym_int) {
! t_atom at;
! // If int message is not explicitly handled: try float handler instead
! SetFloat(at,(float)GetInt(argv[0]));
! ret = FindMeth(inlet,sym_float,1,&at);
! if(ret) goto end;
! // If not explicitly handled: try list handler instead
! ret = FindMeth(inlet,sym_list,1,argv);
! if(ret) goto end;
! }
! #endif
! else if(s == sym_symbol) {
! ret = FindMeth(inlet,sym_list,1,argv);
! if(ret) goto end;
! }
! #if FLEXT_SYS == FLEXT_SYS_PD
! else if(s == sym_pointer) {
! ret = FindMeth(inlet,sym_list,1,argv);
! if(ret) goto end;
! }
! #endif
! }
}
! else if(argc == 0) {
! // If symbol message (pure anything without args) is not explicitly handled: try list handler instead
! t_atom at;
! SetSymbol(at,s);
! ret = FindMeth(inlet,sym_list,1,&at);
! if(ret) goto end;
}
// if distmsgs is switched on then distribute list elements over inlets (Max/MSP behavior)
! if(DoDist() && inlet == 0 && s == sym_list && insigs <= 1 && !trap) {
int i = incnt;
if(i > argc) i = argc;
***************
*** 238,255 ****
else if(IsInt(argv[i])) sym = sym_int;
else if(IsSymbol(argv[i])) sym = sym_symbol;
- #if FLEXT_SYS == FLEXT_SYS_PD
else if(IsPointer(argv[i])) sym = sym_pointer; // can pointer atoms occur here?
! #endif
if(sym) {
trap = true;
! CbMethodHandler(i,sym,1,argv+i);
trap = false;
}
}
! ret = true;
}
! if(!ret && !trap) ret = CbMethodResort(inlet,s,argc,argv);
}
catch(std::exception &x) {
--- 252,270 ----
else if(IsInt(argv[i])) sym = sym_int;
else if(IsSymbol(argv[i])) sym = sym_symbol;
else if(IsPointer(argv[i])) sym = sym_pointer; // can pointer atoms occur here?
!
if(sym) {
trap = true;
! CbMethodHandler(i,sym,1,argv+i);
trap = false;
}
}
! goto end;
}
! ret = FindMethAny(inlet,s,argc,argv);
!
! if(!ret) ret = CbMethodResort(inlet,s,argc,argv);
}
catch(std::exception &x) {
Index: flclass.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flclass.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** flclass.h 24 May 2005 09:48:20 -0000 1.59
--- flclass.h 7 Jun 2005 14:13:43 -0000 1.60
***************
*** 868,873 ****
mutable ItemCont *bindhead;
- bool CallMeth(const MethItem &m,int argc,const t_atom *argv);
bool FindMeth(int inlet,const t_symbol *s,int argc,const t_atom *argv);
bool TryMethTag(Item *lst,const t_symbol *tag,int argc,const t_atom *argv);
bool TryMethSym(Item *lst,const t_symbol *s);
--- 868,873 ----
mutable ItemCont *bindhead;
bool FindMeth(int inlet,const t_symbol *s,int argc,const t_atom *argv);
+ bool FindMethAny(int inlet,const t_symbol *s,int argc,const t_atom *argv);
bool TryMethTag(Item *lst,const t_symbol *tag,int argc,const t_atom *argv);
bool TryMethSym(Item *lst,const t_symbol *s);