From 62530f3fc55d3dc1c12bcd3b88f0922c15cd82e5 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 30 Dec 2002 04:32:19 +0000 Subject: "" svn path=/trunk/; revision=310 --- externals/grill/flext/source/flattr.cpp | 23 ++++++++------ externals/grill/flext/source/flbase.cpp | 42 ++---------------------- externals/grill/flext/source/flbase.h | 35 +++----------------- externals/grill/flext/source/flclass.h | 45 +++++++++++++++++++------- externals/grill/flext/source/fldefs.h | 28 ++++++++-------- externals/grill/flext/source/fldsp.h | 12 ++++++- externals/grill/flext/source/flext.cpp | 37 ++++++++++++++++++---- externals/grill/flext/source/flmsg.cpp | 2 +- externals/grill/flext/source/flout.cpp | 38 ++++++++++++++++++++-- externals/grill/flext/source/flsndobj.h | 2 +- externals/grill/flext/source/flstdc.h | 6 ++++ externals/grill/flext/source/flsupport.cpp | 42 ++++++++++++++++++++++++ externals/grill/flext/source/flsupport.h | 51 ++++++++++++++++++++++++------ externals/grill/flext/source/flutil.cpp | 7 ++-- externals/grill/flext/source/flxlet.cpp | 18 ++++++++--- 15 files changed, 254 insertions(+), 134 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flattr.cpp b/externals/grill/flext/source/flattr.cpp index 5612ab33..c6e88fe5 100644 --- a/externals/grill/flext/source/flattr.cpp +++ b/externals/grill/flext/source/flattr.cpp @@ -21,9 +21,9 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define STD #endif -flext_base::attritem::attritem(const t_symbol *t,metharg tp,methfun f,bool g): +flext_base::attritem::attritem(const t_symbol *t,metharg tp,methfun f,int fl): item(t,0,NULL),argtp(tp), - fun(f),isget(g) + fun(f),flags(fl) { } @@ -57,7 +57,7 @@ void flext_base::AddAttrib(itemarr *aa,itemarr *ma,const char *attr,metharg tp,m // if(sfun) // if commented out, there will be a warning at run-time (more user-friendly) { - attritem *a = new attritem(asym,tp,sfun,false); + attritem *a = new attritem(asym,tp,sfun,attritem::afl_bothexist|attritem::afl_set); aa->Add(a); // bind attribute to a method @@ -68,7 +68,7 @@ void flext_base::AddAttrib(itemarr *aa,itemarr *ma,const char *attr,metharg tp,m // if(gfun) // if commented out, there will be a warning at run-time (more user-friendly) { - attritem *a = new attritem(asym,tp,gfun,true); + attritem *a = new attritem(asym,tp,gfun,attritem::afl_bothexist|attritem::afl_get); aa->Add(a); static char tmp[256] = "get"; @@ -124,17 +124,22 @@ bool flext_base::ListAttrib() int ccnt = clattrhead?clattrhead->Count():0; AtomList la(ccnt+cnt); - for(int i = 0,ix = 0; i <= 1; ++i) { + int ix = 0; + for(int i = 0; i <= 1; ++i) { itemarr *a = i?attrhead:clattrhead; if(a) { for(int ai = 0; ai < a->Size(); ++ai) { for(item *l = a->Item(ai); l; l = l->nxt) - SetSymbol(la[ix++],l->tag); + { + attritem *a = (attritem *)l; + if(!a->BothExist() || a->IsGet()) + SetSymbol(la[ix++],a->tag); + } } } } - ToOutAnything(outattr,MakeSymbol("attributes"),la.Count(),la.Atoms()); + ToOutAnything(outattr,MakeSymbol("attributes"),ix,la.Atoms()); return true; } else @@ -145,10 +150,10 @@ bool flext_base::SetAttrib(const t_symbol *tag,int argc,const t_atom *argv) { // search for matching attribute attritem *a = (attritem *)attrhead->Find(tag); - while(a && (a->tag != tag || a->inlet != 0 || a->isget)) a = (attritem *)a->nxt; + while(a && (a->tag != tag || a->inlet != 0 || a->IsGet())) a = (attritem *)a->nxt; if(!a) { a = (attritem *)clattrhead->Find(tag); - while(a && (a->tag != tag || a->inlet != 0 || a->isget)) a = (attritem *)a->nxt; + while(a && (a->tag != tag || a->inlet != 0 || a->IsGet())) a = (attritem *)a->nxt; } if(a) diff --git a/externals/grill/flext/source/flbase.cpp b/externals/grill/flext/source/flbase.cpp index 3b43c1fe..9840bfc2 100644 --- a/externals/grill/flext/source/flbase.cpp +++ b/externals/grill/flext/source/flbase.cpp @@ -31,6 +31,8 @@ int flext_obj::m_holdaargc = 0; const t_atom *flext_obj::m_holdaargv = NULL; bool flext_obj::process_attributes = false; +void flext_obj::ProcessAttributes(bool attr) { process_attributes = attr; } + ///////////////////////////////////////////////////////// // Constructor // @@ -79,46 +81,6 @@ void flext_obj::DefineHelp(t_class *c,const char *ref,const char *dir,bool addti } -///////////////////////////////////////////////////////// -// overloaded new/delete memory allocation methods -// -///////////////////////////////////////////////////////// - -void *flext_obj::operator new(size_t bytes) -{ - bytes += sizeof(size_t); - char *blk = (char *)getbytes(bytes); - *(size_t *)blk = bytes; - return blk+sizeof(size_t); -} - -void flext_obj::operator delete(void *blk) -{ - char *ori = (char *)blk-sizeof(size_t); - size_t bytes = *(size_t *)ori; - freebytes(ori,bytes); -} - -void *flext_obj::NewAligned(size_t bytes,int bitalign) -{ - const size_t ovh = sizeof(size_t)+sizeof(char *); - const unsigned long alignovh = bitalign/8-1; - bytes += ovh+alignovh; - char *blk = (char *)getbytes(bytes); - char *ablk = reinterpret_cast((reinterpret_cast(blk)+ovh+alignovh) & ~alignovh); - *(char **)(ablk-sizeof(size_t)-sizeof(char *)) = blk; - *(size_t *)(ablk-sizeof(size_t)) = bytes; - return ablk; -} - -void flext_obj::FreeAligned(void *blk) -{ - char *ori = *(char **)((char *)blk-sizeof(size_t)-sizeof(char *)); - size_t bytes = *(size_t *)((char *)blk-sizeof(size_t)); - freebytes(ori,bytes); -} - - diff --git a/externals/grill/flext/source/flbase.h b/externals/grill/flext/source/flbase.h index 96a89d30..8b8577ea 100644 --- a/externals/grill/flext/source/flbase.h +++ b/externals/grill/flext/source/flbase.h @@ -20,7 +20,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flstdc.h" #include "flsupport.h" -class FLEXT_EXT flext_obj; +class FLEXT_SHARE flext_obj; // ---------------------------------------------------------------------------- /*! \brief The obligatory PD or Max/MSP object header @@ -32,7 +32,7 @@ class FLEXT_EXT flext_obj; */ // ---------------------------------------------------------------------------- -struct FLEXT_EXT flext_hdr +struct FLEXT_SHARE flext_hdr { /*! \defgroup FLEXT_OBJHEADER Actual PD or Max/MSP object \internal @@ -85,7 +85,7 @@ struct FLEXT_EXT flext_hdr */ // ---------------------------------------------------------------------------- -class FLEXT_EXT flext_obj: +class FLEXT_SHARE flext_obj: public flext { public: @@ -113,7 +113,7 @@ class FLEXT_EXT flext_obj: /*! \brief Enable/disable attribute procession (default = false) \note Use that in the static class setup function (also library setup function) */ - static void ProcessAttributes(bool attr) { process_attributes = attr; } + static void ProcessAttributes(bool attr); //{ process_attributes = attr; } //! Virtual function called at creation time (but after the constructor) // this also guarantees that there are no instances of flext_obj @@ -134,7 +134,7 @@ class FLEXT_EXT flext_obj: */ //! Get the object's canvas - t_canvas *thisCanvas() { return(m_canvas); } + t_canvas *thisCanvas() { return m_canvas; } //! Get the PD or Max/MSP object t_sigobj *thisHdr() { return &x_obj->obj; } @@ -155,31 +155,6 @@ class FLEXT_EXT flext_obj: //! @} FLEXT_O_INFO -// --- memory ------------------------------------------------------- - - /*! \defgroup FLEXT_O_MEMORY Memory allocation functions - @{ - */ - - /*! Overloaded new memory allocation method - \warning Max/MSP (or MacOS) allows only 16K in overdrive mode! - */ - void *operator new(size_t bytes); - //! Overloaded delete method - void operator delete(void *blk); - - #ifndef __MRC__ // doesn't allow new[] overloading?! - void *operator new[](size_t bytes) { return operator new(bytes); } - void operator delete[](void *blk) { operator delete(blk); } - #endif - - //! Get an aligned memory block - static void *NewAligned(size_t bytes,int bitalign = 128); - //! Free an aligned memory block - static void FreeAligned(void *blk); - - //! @} FLEXT_O_MEMORY - // --- help ------------------------------------------------------- /*! \defgroup FLEXT_O_HELP Help/assistance functionality diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h index b0376ed3..208a37fd 100644 --- a/externals/grill/flext/source/flclass.h +++ b/externals/grill/flext/source/flclass.h @@ -40,7 +40,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. */ -class FLEXT_EXT flext_base: +class FLEXT_SHARE flext_base: public flext_obj { FLEXT_HEADER_S(flext_base,flext_obj,Setup) @@ -307,7 +307,7 @@ public: typedef bool (*methfun)(flext_base *c); - /*! \defgroup FLEXT_C_ADDMETHOD Method handling + /*! \defgroup FLEXT_C_ADDMETHOD Method handling (object scope) \internal @{ */ @@ -342,6 +342,16 @@ public: void AddMethod(int inlet,const char *tag,bool (*m)(flext_base *,float &)) { AddMethod(ThMeths(),inlet,tag,(methfun)m,a_float,a_null); } // method+float void AddMethod(int inlet,const char *tag,bool (*m)(flext_base *,int &)) { AddMethod(ThMeths(),inlet,tag,(methfun)m,a_int,a_null); } // method+int + //! Set Max/MSP style of distributing list elements over (message) inlets + void SetDist(bool d = true) { distmsgs = d; } + +//! @} FLEXT_C_ADDMETHOD + + /*! \defgroup FLEXT_C_CADDMETHOD Method handling (class scope) + \internal + @{ + */ + static void AddMethod(t_class *c,int inlet,bool (*m)(flext_base *,int,t_atom *)) { AddMethod(ClMeths(c),inlet,"list",(methfun)m,a_list,a_null); } static void AddMethod(t_class *c,int inlet,bool (*m)(flext_base *,int,const t_atom *)) { AddMethod(ClMeths(c),inlet,"list",(methfun)m,a_list,a_null); } static void AddMethod(t_class *c,int inlet,const char *tag,bool (*m)(flext_base *)) { AddMethod(ClMeths(c),inlet,tag,(methfun)m,a_null); } // pure method @@ -370,11 +380,7 @@ public: static void AddMethod(t_class *c,int inlet,const char *tag,bool (*m)(flext_base *,float &)) { AddMethod(ClMeths(c),inlet,tag,(methfun)m,a_float,a_null); } // method+float static void AddMethod(t_class *c,int inlet,const char *tag,bool (*m)(flext_base *,int &)) { AddMethod(ClMeths(c),inlet,tag,(methfun)m,a_int,a_null); } // method+int - - //! Set Max/MSP style of distributing list elements over (message) inlets - void SetDist(bool d = true) { distmsgs = d; } - -//! @} FLEXT_C_ADDMETHOD +//! @} FLEXT_C_CADDMETHOD // --- bind/unbind --------------------------------------- @@ -461,7 +467,7 @@ protected: xlet *nxt; }; - /*! \defgroup FLEXT_C_ATTR Attribute handling methods + /*! \defgroup FLEXT_C_ATTR Attribute handling methods (object scope) @{ */ @@ -472,6 +478,12 @@ protected: void AddAttrib(const char *attr,bool (*get)(flext_base *,AtomList *&),bool (*set)(flext_base *,AtomList *&)) { AddAttrib(attr,a_LIST,(methfun)get,(methfun)set); } void AddAttrib(const char *attr,bool (*get)(flext_base *,AtomAnything *&),bool (*set)(flext_base *,AtomAnything *&)) { AddAttrib(attr,a_ANY,(methfun)get,(methfun)set); } +//! @} FLEXT_C_ATTR + + /*! \defgroup FLEXT_C_CATTR Attribute handling methods (class scope) + @{ + */ + static void AddAttrib(t_class *c,const char *attr,bool (*get)(flext_base *,float &),bool (*set)(flext_base *,float &)) { AddAttrib(c,attr,a_float,(methfun)get,(methfun)set); } static void AddAttrib(t_class *c,const char *attr,bool (*get)(flext_base *,int &),bool (*set)(flext_base *,int &)) { AddAttrib(c,attr,a_int,(methfun)get,(methfun)set); } static void AddAttrib(t_class *c,const char *attr,bool (*get)(flext_base *,const t_symbol *&),bool (*set)(flext_base *,const t_symbol *&)) { AddAttrib(c,attr,a_symbol,(methfun)get,(methfun)set); } @@ -479,7 +491,7 @@ protected: static void AddAttrib(t_class *c,const char *attr,bool (*get)(flext_base *,AtomList *&),bool (*set)(flext_base *,AtomList *&)) { AddAttrib(c,attr,a_LIST,(methfun)get,(methfun)set); } static void AddAttrib(t_class *c,const char *attr,bool (*get)(flext_base *,AtomAnything *&),bool (*set)(flext_base *,AtomAnything *&)) { AddAttrib(c,attr,a_ANY,(methfun)get,(methfun)set); } -//! @} FLEXT_C_ATTR +//! @} FLEXT_C_CATTR /*! \addtogroup FLEXT_C_INOUT @{ @@ -570,10 +582,19 @@ protected: class attritem: public item { public: - attritem(const t_symbol *tag,metharg tp,methfun fun,bool get); + attritem(const t_symbol *tag,metharg tp,methfun fun,int flags); ~attritem(); - bool isget; + enum { + afl_getset = 0x01, afl_get = 0x00, afl_set = 0x01, + afl_bothexist = 0x02 + }; + + bool IsGet() const { return (flags&afl_getset) == afl_get; } + bool IsSet() const { return (flags&afl_getset) == afl_set; } + bool BothExist() const { return (flags&afl_bothexist) != 0; } + + int flags; metharg argtp; methfun fun; }; @@ -719,6 +740,8 @@ private: static void cb_loadbang(t_class *c); #if FLEXT_SYS == FLEXT_SYS_MAX + char **indesc,**outdesc; + static void cb_assist(t_class *c,void *b,long msg,long arg,char *s); #endif }; diff --git a/externals/grill/flext/source/fldefs.h b/externals/grill/flext/source/fldefs.h index 49f44366..66c56123 100644 --- a/externals/grill/flext/source/fldefs.h +++ b/externals/grill/flext/source/fldefs.h @@ -671,20 +671,10 @@ FLEXT_THREAD_1(M_FUN,t_symptr) \ AddMethod(CL,IX,"bang",FLEXT_CALL_PRE(M_FUN)) -//! Add a handler for a method with no arguments +//! Add a handler for a method with either no, list or anything arguments #define FLEXT_CADDMETHOD(CL,IX,M_FUN) \ AddMethod(CL,IX,FLEXT_CALL_PRE(M_FUN)) -//! Add a handler for a method with a (variable argument) list -#define FLEXT_CADDMETHOD_V(CL,IX,M_FUN) \ -\ -AddMethod(CL,IX,FLEXT_CALL_PRE(M_FUN)) - -//! Add a handler for a method with an anything argument -#define FLEXT_CADDMETHOD_A(CL,IX,M_FUN) \ -\ -AddMethod(CL,IX,FLEXT_CALL_PRE(M_FUN)) - //! Add a a handler for a method with implicit arguments #define FLEXT_CADDMETHOD_(CL,IX,M_TAG,M_FUN) \ \ @@ -777,21 +767,29 @@ SetDist(true) \ AddMethod(IX,"bang",FLEXT_CALL_PRE(M_FUN)) -//! Add a handler for a method with no arguments +//! Add a handler for a method with either no, list or anything arguments #define FLEXT_ADDMETHOD(IX,M_FUN) \ AddMethod(IX,FLEXT_CALL_PRE(M_FUN)) -//! Add a handler for a method with a (variable argument) list +#if 0 +// FLEXT_ADDMETHOD_V and FLEXT_ADDMETHOD_A definitions obscure that _ indicates the usage of a message tag + +/*! \brief Add a handler for a method with a (variable argument) list + \note This is already covered by FLEXT_ADDMETHOD, but here for the sake of clarity +*/ #define FLEXT_ADDMETHOD_V(IX,M_FUN) \ \ AddMethod(IX,FLEXT_CALL_PRE(M_FUN)) -//! Add a handler for a method with an anything argument +/*! \brief Add a handler for a method with an anything argument + \note This is already covered by FLEXT_ADDMETHOD, but here for the sake of clarity +*/ #define FLEXT_ADDMETHOD_A(IX,M_FUN) \ \ AddMethod(IX,FLEXT_CALL_PRE(M_FUN)) +#endif -//! Add a a handler for a method with implicit arguments +//! Add a a handler for a tagged method with implicit arguments #define FLEXT_ADDMETHOD_(IX,M_TAG,M_FUN) \ \ AddMethod(IX,M_TAG,FLEXT_CALL_PRE(M_FUN)) diff --git a/externals/grill/flext/source/fldsp.h b/externals/grill/flext/source/fldsp.h index 4926d873..6299544a 100644 --- a/externals/grill/flext/source/fldsp.h +++ b/externals/grill/flext/source/fldsp.h @@ -24,7 +24,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. /*! \brief Flext dsp enabled base object */ -class FLEXT_EXT flext_dsp: +class FLEXT_SHARE flext_dsp: public flext_base { FLEXT_HEADER_S(flext_dsp,flext_base,Setup) @@ -105,11 +105,21 @@ public: */ void AddInSignal(int m = 1) { AddInlet(xlet::tp_sig,m); } + /*! \brief Add signal inlet (with description) + \param desc Description of inlet + */ + void AddInSignal(const char *desc) { AddInlet(xlet::tp_sig,1,desc); } + /*! \brief Add signal outlet(s) \param m Number of inlets to add */ void AddOutSignal(int m = 1) { AddOutlet(xlet::tp_sig,m); } + /*! \brief Add signal outlet (with description) + \param desc Description of outlet + */ + void AddOutSignal(const char *desc) { AddOutlet(xlet::tp_sig,1,desc); } + //! @} //! @} diff --git a/externals/grill/flext/source/flext.cpp b/externals/grill/flext/source/flext.cpp index 5ffaaae4..08e4cdd1 100644 --- a/externals/grill/flext/source/flext.cpp +++ b/externals/grill/flext/source/flext.cpp @@ -14,7 +14,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flext.h" #include "flinternal.h" - +#include // === flext_base ============================================ @@ -30,6 +30,9 @@ flext_base::flext_base(): methhead(new itemarr),attrhead(new itemarr), //attrcnt(0), clmethhead(ClMeths(thisClass())),clattrhead(ClAttrs(thisClass())), inlets(NULL) +#if FLEXT_SYS == FLEXT_SYS_MAX + ,indesc(NULL),outdesc(NULL) +#endif { LOG1("%s - flext logging is on",thisName()); @@ -71,6 +74,15 @@ flext_base::~flext_base() } #if FLEXT_SYS == FLEXT_SYS_MAX + if(indesc) { + for(int i = 0; i < incnt; ++i) if(indesc[i]) delete[] indesc[i]; + delete[] indesc; + } + if(outdesc) { + for(int i = 0; i < outcnt; ++i) if(outdesc[i]) delete[] outdesc[i]; + delete[] outdesc; + } + // if(insigs) dsp_free(thisHdr()); if(insigs) dsp_freebox(thisHdr()); #endif @@ -81,7 +93,7 @@ flext_base::~flext_base() It creates the inlets and outlets and the message and attribute lists. \note You can override it in your own class, but be sure to call it, \note otherwise no inlets/outlets will be created - \mote All inlet, outlets, method and attribute declarations must be made before a call to Init! + \note All inlet, outlets, method and attribute declarations must be made before a call to Init! \remark Creation of inlets/outlets can't be done upon declaration, as Max/MSP needs creation \remark in reverse. */ @@ -135,9 +147,6 @@ void flext_base::Setup(t_class *c) void flext_base::cb_help(t_class *c) { thisObject(c)->m_help(); } void flext_base::cb_loadbang(t_class *c) { thisObject(c)->m_loadbang(); } -#if FLEXT_SYS == FLEXT_SYS_MAX -void flext_base::cb_assist(t_class *c,void * /*b*/,long msg,long arg,char *s) { thisObject(c)->m_assist(msg,arg,s); } -#endif void flext_base::m_help() { @@ -147,6 +156,20 @@ void flext_base::m_help() void flext_base::m_loadbang() {} -void flext_base::m_assist(long /*msg*/,long /*arg*/,char * /*s*/) {} - +#if FLEXT_SYS == FLEXT_SYS_MAX +void flext_base::cb_assist(t_class *c,void * /*b*/,long msg,long arg,char *s) { thisObject(c)->m_assist(msg,arg,s); } +#endif +void flext_base::m_assist(long msg,long arg,char *s) +{ +#if FLEXT_SYS == FLEXT_SYS_MAX + switch(msg) { + case 1: //ASSIST_INLET: + strcpy(s,arg < incnt && indesc[arg]?indesc[arg]:""); + break; + case 2: //ASSIST_OUTLET: + strcpy(s,arg < outcnt && outdesc[arg]?outdesc[arg]:""); + break; + } +#endif +} diff --git a/externals/grill/flext/source/flmsg.cpp b/externals/grill/flext/source/flmsg.cpp index a1c049d2..57f21d03 100755 --- a/externals/grill/flext/source/flmsg.cpp +++ b/externals/grill/flext/source/flmsg.cpp @@ -81,7 +81,7 @@ bool flext_base::TryMethTag(const methitem *m,int inlet,const t_symbol *t,int ar if(m->attr) { // attributes are treated differently - if(m->attr->isget) + if(m->attr->IsGet()) return GetAttrib(m->attr); else return SetAttrib(m->attr,argc,argv); diff --git a/externals/grill/flext/source/flout.cpp b/externals/grill/flext/source/flout.cpp index e8341e9e..2ad12597 100644 --- a/externals/grill/flext/source/flout.cpp +++ b/externals/grill/flext/source/flout.cpp @@ -14,7 +14,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flext.h" #include "flinternal.h" - +#include #ifndef FLEXT_THREADS void flext_base::ToOutBang(outlet *o) const { CRITON(); outlet_bang((t_outlet *)o); CRITOFF(); } @@ -50,6 +50,22 @@ bool flext_base::InitInlets() xlet::type *list = new xlet::type[incnt]; int i; for(xi = inlist,i = 0; xi; xi = xi->nxt,++i) list[i] = xi->tp; + +#if FLEXT_SYS == FLEXT_SYS_MAX + // copy inlet descriptions + indesc = new char *[incnt]; + for(xi = inlist,i = 0; xi; xi = xi->nxt,++i) { + int l = xi->desc?strlen(xi->desc):0; + if(l) { + indesc[i] = new char[l+1]; + memcpy(indesc[i],xi->desc,l); + indesc[i][l] = 0; + } + else + indesc[i] = NULL; + } +#endif + delete inlist; inlist = NULL; inlets = new px_object *[incnt]; @@ -174,7 +190,7 @@ bool flext_base::InitInlets() } } - incnt = cnt; +// incnt = cnt; if(insigs) // dsp_setup(thisHdr(),insigs); // signal inlets @@ -216,6 +232,22 @@ bool flext_base::InitOutlets() xlet::type *list = new xlet::type[outcnt]; int i; for(xi = outlist,i = 0; xi; xi = xi->nxt,++i) list[i] = xi->tp; + +#if FLEXT_SYS == FLEXT_SYS_MAX + // copy outlet descriptions + outdesc = new char *[outcnt]; + for(xi = outlist,i = 0; xi; xi = xi->nxt,++i) { + int l = xi->desc?strlen(xi->desc):0; + if(l) { + outdesc[i] = new char[l+1]; + memcpy(outdesc[i],xi->desc,l); + outdesc[i][l] = 0; + } + else + outdesc[i] = NULL; + } +#endif + delete outlist; outlist = NULL; outlets = new outlet *[outcnt]; @@ -256,7 +288,7 @@ bool flext_base::InitOutlets() #endif } } - + delete[] list; } diff --git a/externals/grill/flext/source/flsndobj.h b/externals/grill/flext/source/flsndobj.h index c56ba07b..fde0d177 100644 --- a/externals/grill/flext/source/flsndobj.h +++ b/externals/grill/flext/source/flsndobj.h @@ -18,7 +18,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #undef NOPTHREAD -class flext_sndobj: +class FLEXT_SHARE flext_sndobj: public flext_dsp { FLEXT_HEADER(flext_sndobj,flext_dsp) diff --git a/externals/grill/flext/source/flstdc.h b/externals/grill/flext/source/flstdc.h index adf28b0d..44252c3f 100644 --- a/externals/grill/flext/source/flstdc.h +++ b/externals/grill/flext/source/flstdc.h @@ -162,8 +162,14 @@ typedef void t_binbuf; /* Set the right calling convention (and exporting) for the OS */ #ifdef _MSC_VER + #ifdef FLEXT_SHARED + #define FLEXT_SHARE __declspec(dllexport) + #else + #define FLEXT_SHARE + #endif #define FLEXT_EXT __declspec(dllexport) #else // other OS's + #define FLEXT_SHARE #define FLEXT_EXT #endif diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index cd57dfd8..827896e3 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -48,6 +48,48 @@ void flext::Setup() #endif } + +///////////////////////////////////////////////////////// +// overloaded new/delete memory allocation methods +// +///////////////////////////////////////////////////////// + +void *flext::operator new(size_t bytes) +{ + bytes += sizeof(size_t); + char *blk = (char *)getbytes(bytes); + *(size_t *)blk = bytes; + return blk+sizeof(size_t); +} + +void flext::operator delete(void *blk) +{ + char *ori = (char *)blk-sizeof(size_t); + size_t bytes = *(size_t *)ori; + freebytes(ori,bytes); +} + +void *flext::NewAligned(size_t bytes,int bitalign) +{ + const size_t ovh = sizeof(size_t)+sizeof(char *); + const unsigned long alignovh = bitalign/8-1; + bytes += ovh+alignovh; + char *blk = (char *)getbytes(bytes); + char *ablk = reinterpret_cast((reinterpret_cast(blk)+ovh+alignovh) & ~alignovh); + *(char **)(ablk-sizeof(size_t)-sizeof(char *)) = blk; + *(size_t *)(ablk-sizeof(size_t)) = bytes; + return ablk; +} + +void flext::FreeAligned(void *blk) +{ + char *ori = *(char **)((char *)blk-sizeof(size_t)-sizeof(char *)); + size_t bytes = *(size_t *)((char *)blk-sizeof(size_t)); + freebytes(ori,bytes); +} + +// ------------------------------------------ + void flext::GetAString(const t_atom &a,char *buf,int szbuf) { #if FLEXT_SYS == FLEXT_SYS_PD diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index 6eef5bd5..470b73ca 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -17,14 +17,47 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flstdc.h" -class FLEXT_EXT flext_base; - -class FLEXT_EXT flext { +class FLEXT_SHARE flext_base; + +/*! \brief Flext support class + A number of methods (most are static functions) are defined here for convenience. + This class doesn't define any data members, hence it can be inherited to all + classes (not only PD objects) to profit from the cross-platform functionality. + Examples are the overloaded memory allocation, atom and atom list functions, + thread functions and classes, the sample buffer class and others. +*/ +class FLEXT_SHARE flext { /*! \defgroup FLEXT_SUPPORT Flext support class @{ */ public: + +// --- memory ------------------------------------------------------- + + /*! \defgroup FLEXT_S_MEMORY Memory allocation functions + @{ + */ + + /*! Overloaded new memory allocation method + \warning Max/MSP (or MacOS) allows only 16K in overdrive mode! + */ + void *operator new(size_t bytes); + //! Overloaded delete method + void operator delete(void *blk); + + #ifndef __MRC__ // doesn't allow new[] overloading?! + void *operator new[](size_t bytes) { return operator new(bytes); } + void operator delete[](void *blk) { operator delete(blk); } + #endif + + //! Get an aligned memory block + static void *NewAligned(size_t bytes,int bitalign = 128); + //! Free an aligned memory block + static void FreeAligned(void *blk); + + //! @} FLEXT_S_MEMORY + // --- buffer/array stuff ----------------------------------------- /*! \defgroup FLEXT_S_BUFFER Buffer handling @@ -32,7 +65,7 @@ public: */ //! Class for platform independent buffer handling - class buffer + class FLEXT_SHARE buffer { public: /*! \brief Construct buffer. @@ -122,7 +155,7 @@ public: //! Zero a memory region static void ZeroMem(void *dst,int bytes); //! Sleep for an amount of time - static void Sleep(float s); + static void Sleep(double s); //! @} FLEXT_S_UTIL @@ -277,7 +310,7 @@ public: // --- atom list stuff ------------------------------------------- //! Class representing a list of atoms - class AtomList + class FLEXT_SHARE AtomList { public: //! Construct list @@ -337,7 +370,7 @@ public: //! Class representing an "anything" - class AtomAnything: + class FLEXT_SHARE AtomAnything: public AtomList { public: @@ -551,7 +584,7 @@ public: /*! \brief Thread mutex \sa pthreads documentation */ - class FLEXT_EXT ThrMutex + class FLEXT_SHARE ThrMutex #if FLEXT_THREADS == FLEXT_THR_POSIX { public: @@ -605,7 +638,7 @@ public: /*! \brief Thread conditional \sa pthreads documentation */ - class FLEXT_EXT ThrCond + class FLEXT_SHARE ThrCond #if FLEXT_THREADS == FLEXT_THR_POSIX :public ThrMutex { diff --git a/externals/grill/flext/source/flutil.cpp b/externals/grill/flext/source/flutil.cpp index 2a65aaf6..ea11b458 100644 --- a/externals/grill/flext/source/flutil.cpp +++ b/externals/grill/flext/source/flutil.cpp @@ -34,13 +34,14 @@ void flext::ZeroMem(void *dst,int bytes) memset(dst,0,bytes); } -void flext::Sleep(float s) +void flext::Sleep(double s) { #if FLEXT_OS == FLEXT_OS_WIN - ::Sleep((long)(s*1000)); + ::Sleep((long)(s*1000.)); #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || defined(__GNUC__) - usleep((long)(s*1000000)); + usleep((long)(s*1000000.)); #elif FLEXT_OS == FLEXT_OS_MACOS + // that's just for OS9! UnsignedWide tick; Microseconds(&tick); double target = tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo+s*1.e6; diff --git a/externals/grill/flext/source/flxlet.cpp b/externals/grill/flext/source/flxlet.cpp index 2804bae3..e47a92e3 100755 --- a/externals/grill/flext/source/flxlet.cpp +++ b/externals/grill/flext/source/flxlet.cpp @@ -23,8 +23,9 @@ flext_base::xlet::xlet(type t,const char *d): { if(d) { int ln = strlen(d); - desc = new char[ln]; - strncpy(desc,d,ln); + desc = new char[ln+1]; + memcpy(desc,d,ln); + desc[ln] = 0; } else desc = NULL; } @@ -45,9 +46,18 @@ void flext_base::AddXlet(xlet::type tp,int mult,const char *desc,xlet *&root) } } -void flext_base::DescXlet(int ix,const char *desc,xlet *&root) +void flext_base::DescXlet(int ix,const char *d,xlet *&root) { - post("%s - sorry, not implemented",thisName()); + xlet *xi = root; + for(int i = 0; xi && i < ix; xi = xi->nxt,++i) {} + + if(xi) { + if(xi->desc) delete[] xi->desc; + int ln = strlen(d); + xi->desc = new char[ln+1]; + memcpy(xi->desc,d,ln); + xi->desc[ln] = 0; + } } unsigned long flext_base::XletCode(xlet::type tp,...) -- cgit v1.2.1