Commit d6a15713 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@189 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 8437bd59
No preview for this file type
......@@ -72,14 +72,21 @@ see flext.h for the documented base classes
Version history:
0.3.0:
- added threaded methods along with a message queue for ToOut* functions
- added threaded methods along with a message queue for ToOut* functions (very unstable for MaxMSP!)
- check/update function for buffer change (resize etc.)
- description text for inlets/outlets (e.g. for MaxMSPs assist function)
- added buffer resize functions flext_base::buffer::Frames(int,bool)
- added some utility functions: Sleep, CopyAtom, CopyList
- added List manipulation classes: AtomList, AtomAnything
- Alias object names (simply specify with FLEXT_NEW*, separated by whitespace)
- float messages - int method is called if there is no float method
- MaxMSP: int messages - float method is called if there is no int method
- fixed type warning for class constructors with int arguments in PD
- fixed severe bug concerning symbol methods
- MaxMSP: use critical sections for message output (for more safety in overdrive mode)
- introduced FLEXT_NEW_DSP* and FLEXT_LIB_DSP* for FLEXT_NEW_TILDE* and FLEXT_LIB_TILDE* (the latter become deprecated)
- all variable argument defs (aka gimme) now have a V instead of G (e.g. FLEXT_NEW_V)
0.2.3:
- restructured files and started usable inline documentation
......@@ -172,6 +179,7 @@ general:
- should we use a namespace?
- where to put flext source/lib in linux: /usr/local/lib,/usr/local/include ?
- clean up headers (eliminate flstdc.h?)
- check that SetupInOut is only called once
bugs:
- PD: problems with timed buffer redrawing (takes a lot of cpu time)
......
......@@ -30,6 +30,7 @@ const char *flext_obj::m_holdname;
flext_obj :: flext_obj()
: x_obj(m_holder)
, m_name(m_holdname)
, init_ok(true)
{
#ifdef PD
m_canvas = canvas_getcurrent();
......@@ -37,10 +38,6 @@ flext_obj :: flext_obj()
m_canvas = (t_patcher *)gensym("#P")->s_thing;
x_obj->curinlet = 0;
#endif
#ifdef FLEXT_THREADS
thrid = pthread_self();
#endif
}
/////////////////////////////////////////////////////////
......
......@@ -125,9 +125,7 @@ class FLEXT_EXT flext_obj
t_class *thisClass() { return (t_class *)(((t_tinyobject *)x_obj)->t_messlist-1); }
#endif
#ifdef FLEXT_THREADS
bool IsSystemThread() const { pthread_t cur = pthread_self(); return pthread_equal(cur,thrid) != 0; }
#endif
void InitProblem() { init_ok = false; }
protected:
......@@ -138,11 +136,9 @@ class FLEXT_EXT flext_obj
//! The canvas (patcher) that the object is in
t_canvas *m_canvas;
#ifdef FLEXT_THREADS
//! The thread that created the object (the system thread)
pthread_t thrid;
#endif
//! Flag for successful object construction
bool init_ok;
public:
......@@ -162,6 +158,9 @@ class FLEXT_EXT flext_obj
static bool check_tilde(const char *objname,const char *setupfun);
#endif
// !check whether construction was successful
bool InitOk() const { return init_ok; }
#ifdef MAXMSP
/*! definitions for MaxMSP external libraries */
......@@ -190,8 +189,8 @@ inline void *operator new(size_t, void *location, void *) { return location; }
public: \
typedef NEW_CLASS thisType; \
static void callb_free(flext_hdr *hdr) \
{ flext_obj *mydata = ((flext_hdr *)hdr)->data; delete mydata; \
((flext_hdr *)hdr)->flext_hdr::~flext_hdr(); } \
{ flext_obj *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); } \
static void callb_setup(t_class *classPtr) \
{ PARENT_CLASS::callb_setup(classPtr); } \
protected: \
......@@ -202,8 +201,8 @@ static NEW_CLASS *thisObject(void *c) { return (NEW_CLASS *)((flext_hdr *)c)->da
public: \
typedef NEW_CLASS thisType; \
static void callb_free(flext_hdr *hdr) \
{ flext_obj *mydata = ((flext_hdr *)hdr)->data; delete mydata; \
((flext_hdr *)hdr)->flext_hdr::~flext_hdr(); } \
{ flext_obj *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); } \
static void callb_setup(t_class *classPtr) \
{ PARENT_CLASS::callb_setup(classPtr); \
NEW_CLASS::SETUPFUN(classPtr); } \
......@@ -213,7 +212,7 @@ static NEW_CLASS *thisObject(void *c) { return (NEW_CLASS *)((flext_hdr *)c)->da
#define REAL_NEW(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST(0,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_NEW_G(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST_G(0,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_NEW_V(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST_V(0,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_NEW_1(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1) REAL_INST_1(0,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1)
#define REAL_NEW_2(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2) REAL_INST_2(0,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2)
#define REAL_NEW_3(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3) REAL_INST_3(0,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3)
......@@ -221,14 +220,14 @@ static NEW_CLASS *thisObject(void *c) { return (NEW_CLASS *)((flext_hdr *)c)->da
#ifdef PD
#define REAL_EXT(NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST(1,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_G(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST_G(1,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_V(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_INST_V(1,NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_1(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1) REAL_INST_1(1,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1)
#define REAL_LIB_2(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2) REAL_INST_2(1,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2)
#define REAL_LIB_3(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3) REAL_INST_3(1,NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3)
#else // MAXMSP
#define REAL_EXT(NEW_CLASS,SETUP_FUNCTION) extern "C" FLEXT_EXT int main() { NEW_CLASS##SETUP_FUNCTION(); return 0; }
#define REAL_LIB(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_NEWLIB(NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_G(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_NEWLIB_G(NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_V(NAME,NEW_CLASS,SETUP_FUNCTION) REAL_NEWLIB_V(NAME,NEW_CLASS,SETUP_FUNCTION)
#define REAL_LIB_1(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1) REAL_NEWLIB_1(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1)
#define REAL_LIB_2(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2) REAL_NEWLIB_2(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2)
#define REAL_LIB_3(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3) REAL_NEWLIB_3(NAME,NEW_CLASS,SETUP_FUNCTION,TYPE1,TYPE2,TYPE3)
......@@ -382,6 +381,7 @@ flext_hdr* class_ ## NEW_CLASS () \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS; \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -408,6 +408,7 @@ flext_hdr* class_ ## NEW_CLASS () \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS; \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -419,17 +420,18 @@ void NEW_CLASS ## SETUP_FUNCTION() \
// ----------------------------------------------------
// one arg
// variable arg list
// ----------------------------------------------------
#define REAL_INST_1(LIB,NAME,NEW_CLASS, SETUP_FUNCTION, TYPE1) \
#define REAL_INST_V(LIB,NAME,NEW_CLASS, SETUP_FUNCTION) \
static t_class * NEW_CLASS ## _class; \
flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1) \
flext_hdr* class_ ## NEW_CLASS (t_symbol *,int argc,t_atom *argv) \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1); \
obj->data = new NEW_CLASS(argc,argv); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -440,45 +442,47 @@ FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
FLEXTTP(TYPE1), \
A_GIMME, \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1)); \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,A_GIMME); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
}
#define REAL_NEWLIB_1(NAME,NEW_CLASS, SETUP_FUNCTION,TYPE1) \
flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1) \
#define REAL_NEWLIB_V(NAME,NEW_CLASS, SETUP_FUNCTION) \
flext_hdr* class_ ## NEW_CLASS (t_symbol *,int argc,t_atom *argv) \
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1)); \
obj->data = new NEW_CLASS(argc,argv); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
{ \
CHECK_TILDE(NAME,#SETUP_FUNCTION); \
flext_obj::libfun_add(NAME,(t_method)(class_ ## NEW_CLASS),&NEW_CLASS::callb_free,FLEXTTP(TYPE1),A_NULL); \
flext_obj::libfun_add(NAME,(t_method)(class_ ## NEW_CLASS),&NEW_CLASS::callb_free,A_GIMME,A_NULL); \
NEW_CLASS::callb_setup(flext_obj::lib_class); \
}
// ----------------------------------------------------
// gimme arg
// one arg
// ----------------------------------------------------
#define REAL_INST_G(LIB,NAME,NEW_CLASS, SETUP_FUNCTION) \
#define REAL_INST_1(LIB,NAME,NEW_CLASS, SETUP_FUNCTION, TYPE1) \
static t_class * NEW_CLASS ## _class; \
flext_hdr* class_ ## NEW_CLASS (t_symbol *s,int argc,t_atom *argv) \
flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1) \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(argc,argv); \
obj->data = new NEW_CLASS((TYPE1)arg1); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -489,29 +493,30 @@ FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
A_GIMME, \
FLEXTTP(TYPE1), \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,A_GIMME); \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1)); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
}
#define REAL_NEWLIB_G(NAME,NEW_CLASS, SETUP_FUNCTION) \
flext_hdr* class_ ## NEW_CLASS (t_symbol *s,int argc,t_atom *argv) \
#define REAL_NEWLIB_1(NAME,NEW_CLASS, SETUP_FUNCTION,TYPE1) \
flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1) \
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(argc,argv); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
{ \
CHECK_TILDE(NAME,#SETUP_FUNCTION); \
flext_obj::libfun_add(NAME,(t_method)(class_ ## NEW_CLASS),&NEW_CLASS::callb_free,A_GIMME,A_NULL); \
flext_obj::libfun_add(NAME,(t_method)(class_ ## NEW_CLASS),&NEW_CLASS::callb_free,FLEXTTP(TYPE1),A_NULL); \
NEW_CLASS::callb_setup(flext_obj::lib_class); \
}
......@@ -528,6 +533,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1, CALLBTP(TYPE2) arg2) \
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1, (TYPE2)arg2); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -555,6 +561,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -577,6 +584,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1,CALLBTP(TYPE2) arg2,CALLBTP(
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1,(TYPE2)arg2,(TYPE3)arg3); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -604,6 +612,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2),ARGCAST(arg3,TYPE3)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -625,6 +634,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1,CALLBTP(TYPE2) arg2,CALLBTP(
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1,(TYPE2)arg2,(TYPE3)arg3,(TYPE4)arg4); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
FLEXT_EXP(LIB) void NEW_CLASS ## SETUP_FUNCTION() \
......@@ -652,6 +662,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
flext_obj::m_holdname = extractname(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2),ARGCAST(arg3,TYPE3),ARGCAST(arg4,TYPE4)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
return(obj); \
} \
void NEW_CLASS ## SETUP_FUNCTION() \
......
......@@ -256,10 +256,10 @@ public:
void AddMethodDef(int inlet,const char *tag); // call virtual function for tag && inlet
void AddMethod(int inlet,const char *tag,methfun fun,metharg tp,...);
void AddMethod(int inlet,void (*m)(flext_base *,int argc,t_atom *argv)) { AddMethod(inlet,"list",(methfun)m,a_gimme,a_null); }
void AddMethod(int inlet,void (*m)(flext_base *,int,t_atom *)) { AddMethod(inlet,"list",(methfun)m,a_gimme,a_null); }
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *)) { AddMethod(inlet,tag,(methfun)m,a_null); } // pure method
void AddMethod(int inlet,void (*m)(flext_base *,t_symbol *s,int argc,t_atom *argv)) { AddMethod(inlet,"anything",(methfun)m,a_xgimme,a_null); } // anything
void AddMethod(int inlet,void (*m)(flext_base *,t_symbol *s)) { AddMethod(inlet,"symbol",(methfun)m,a_symbol,a_null); } // anything
void AddMethod(int inlet,void (*m)(flext_base *,t_symbol *,int,t_atom *)) { AddMethod(inlet,"anything",(methfun)m,a_xgimme,a_null); } // anything
void AddMethod(int inlet,void (*m)(flext_base *,t_symbol *&)) { AddMethod(inlet,"symbol",(methfun)m,a_symbol,a_null); } // single symbol
void AddMethod(int inlet,void (*m)(flext_base *,float &)) { AddMethod(inlet,"float",(methfun)m,a_float,a_null); } // single float
void AddMethod(int inlet,void (*m)(flext_base *,float &,float &)) { AddMethod(inlet,"list",(methfun)m,a_float,a_float,a_null); } // list of 2 floats
void AddMethod(int inlet,void (*m)(flext_base *,float &,float &,float &)) { AddMethod(inlet,"list",(methfun)m,a_float,a_float,a_float,a_null); } // list of 3 floats
......@@ -270,9 +270,9 @@ public:
#endif
void AddMethod(int inlet,void (*m)(flext_base *,int &,int &)) { AddMethod(inlet,"list",(methfun)m,a_int,a_int,a_null); } // list of 2 floats
void AddMethod(int inlet,void (*m)(flext_base *,int &,int &,int &)) { AddMethod(inlet,"list",(methfun)m,a_int,a_int,a_int,a_null); } // list of 3 floats
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,int argc,t_atom *argv)) { AddMethod(inlet,tag,(methfun)m,a_gimme,a_null); } // method+gimme
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,t_symbol *s,int argc,t_atom *argv)) { AddMethod(inlet,tag,(methfun)m,a_xgimme,a_null); } // method+gimme
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,t_symbol *s)) { AddMethod(inlet,tag,(methfun)m,a_symbol,a_null); } // method+symbol
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,int,t_atom *)) { AddMethod(inlet,tag,(methfun)m,a_gimme,a_null); } // method+gimme
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,t_symbol *,int,t_atom *)) { AddMethod(inlet,tag,(methfun)m,a_xgimme,a_null); } // method+gimme
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,t_symbol *&)) { AddMethod(inlet,tag,(methfun)m,a_symbol,a_null); } // method+symbol
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,float &)) { AddMethod(inlet,tag,(methfun)m,a_float,a_null); } // method+float
void AddMethod(int inlet,const char *tag,void (*m)(flext_base *,int &)) { AddMethod(inlet,tag,(methfun)m,a_int,a_null); } // method+int
......@@ -353,6 +353,8 @@ public:
bool ShouldExit() const { return shouldexit; }
bool IsSystemThread() const { pthread_t cur = pthread_self(); return pthread_equal(cur,thrid) != 0; }
void Yield() // yield to other threads (for cooperative multitasking)
#ifndef MAXMSP
{}
......@@ -444,7 +446,7 @@ public:
#ifdef FLEXT_THREADS
class thr_params;
static bool StartThread(void *(*)(thr_params *p),thr_params *p,char *methname);
void PushThread();
bool PushThread();
void PopThread();
#endif
......@@ -526,13 +528,16 @@ private:
#ifdef FLEXT_THREADS
bool shouldexit;
int thrcount;
pthread_t thrid; // the thread that created the object (the system thread)
class qmsg;
qmsg *qhead,*qtail;
t_clock *qclk;
t_qelem *qclk;
ThrMutex qmutex;
#ifdef MAXMSP
t_clock *yclk;
static void YTick(flext_base *th);
#endif
static void QTick(flext_base *th);
......
......@@ -61,7 +61,7 @@ REAL_NEW(NAME,NEW_CLASS, _setup) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with no arguments
#define FLEXT_NEW_TILDE(NAME,NEW_CLASS) \
#define FLEXT_NEW_DSP(NAME,NEW_CLASS) \
REAL_NEW(NAME,NEW_CLASS, _tilde_setup) \
REAL_EXT(NEW_CLASS, _tilde_setup)
......@@ -70,10 +70,32 @@ REAL_EXT(NEW_CLASS, _tilde_setup)
REAL_LIB(NAME,NEW_CLASS, _setup)
//! Implementation of a flext tilde class (part of a library) with no arguments
#define FLEXT_LIB_TILDE(NAME,NEW_CLASS) \
#define FLEXT_LIB_DSP(NAME,NEW_CLASS) \
REAL_LIB(NAME,NEW_CLASS, _tilde_setup)
// VARIABLE ARGUMENT LIST
// ----------------------------------------
//! Implementation of a flext class with a variable argument list
#define FLEXT_NEW_V(NAME,NEW_CLASS) \
REAL_NEW_V(NAME,NEW_CLASS, _setup) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with a variable argument list
#define FLEXT_NEW_DSP_V(NAME,NEW_CLASS) \
REAL_NEW_V(NAME,NEW_CLASS,_tilde_setup) \
REAL_EXT(NEW_CLASS, _tilde_setup)
//! Implementation of a flext class (part of a library) with a variable argument list
#define FLEXT_LIB_V(NAME,NEW_CLASS) \
REAL_LIB_V(NAME,NEW_CLASS, _setup)
//! Implementation of a flext tilde class (part of a library) with a variable argument list
#define FLEXT_LIB_DSP_V(NAME,NEW_CLASS) \
REAL_LIB_V(NAME,NEW_CLASS, _tilde_setup)
// ONE ARGUMENT
// ----------------------------------------
......@@ -83,7 +105,7 @@ REAL_NEW_1(NAME,NEW_CLASS, _setup, TYPE) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with one argument
#define FLEXT_NEW_TILDE_1(NAME,NEW_CLASS, TYPE) \
#define FLEXT_NEW_DSP_1(NAME,NEW_CLASS, TYPE) \
REAL_NEW_1(NAME,NEW_CLASS, _tilde_setup, TYPE) \
REAL_EXT(NEW_CLASS, _tilde_setup)
......@@ -92,32 +114,10 @@ REAL_EXT(NEW_CLASS, _tilde_setup)
REAL_LIB_1(NAME,NEW_CLASS, _setup,TYPE)
//! Implementation of a flext tilde class (part of a library) with one argument
#define FLEXT_LIB_TILDE_1(NAME,NEW_CLASS, TYPE) \
#define FLEXT_LIB_DSP_1(NAME,NEW_CLASS, TYPE) \
REAL_LIB_1(NAME,NEW_CLASS, _tilde_setup, TYPE)
// GIMME ARGUMENT
// ----------------------------------------
//! Implementation of a flext class with a variable argument list
#define FLEXT_NEW_G(NAME,NEW_CLASS) \
REAL_NEW_G(NAME,NEW_CLASS, _setup) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with a variable argument list
#define FLEXT_NEW_TILDE_G(NAME,NEW_CLASS) \
REAL_NEW_G(NAME,NEW_CLASS,_tilde_setup) \
REAL_EXT(NEW_CLASS, _tilde_setup)
//! Implementation of a flext class (part of a library) with a variable argument list
#define FLEXT_LIB_G(NAME,NEW_CLASS) \
REAL_LIB_G(NAME,NEW_CLASS, _setup)
//! Implementation of a flext tilde class (part of a library) with a variable argument list
#define FLEXT_LIB_TILDE_G(NAME,NEW_CLASS) \
REAL_LIB_G(NAME,NEW_CLASS, _tilde_setup)
// TWO ARGUMENTS
// ----------------------------------------
......@@ -127,7 +127,7 @@ REAL_NEW_2(NAME,NEW_CLASS, _setup, TYPE1, TYPE2) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with one argument
#define FLEXT_NEW_TILDE_2(NAME,NEW_CLASS, TYPE1, TYPE2) \
#define FLEXT_NEW_DSP_2(NAME,NEW_CLASS, TYPE1, TYPE2) \
REAL_NEW_2(NAME,NEW_CLASS, _tilde_setup, TYPE1, TYPE2) \
REAL_EXT(NEW_CLASS, _tilde_setup)
......@@ -136,7 +136,7 @@ REAL_EXT(NEW_CLASS, _tilde_setup)
REAL_LIB_2(NAME,NEW_CLASS, _setup, TYPE1, TYPE2)
//! Implementation of a flext tilde class (part of a library) with two arguments
#define FLEXT_LIB_TILDE_2(NAME,NEW_CLASS, TYPE1, TYPE2) \
#define FLEXT_LIB_DSP_2(NAME,NEW_CLASS, TYPE1, TYPE2) \
REAL_LIB_2(NAME,NEW_CLASS, _tilde_setup, TYPE1, TYPE2)
......@@ -149,7 +149,7 @@ REAL_NEW_3(NAME,NEW_CLASS, _setup, TYPE1, TYPE2, TYPE3) \
REAL_EXT(NEW_CLASS, _setup)
//! Implementation of a flext tilde class with three arguments
#define FLEXT_NEW_TILDE_3(NAME,NEW_CLASS, TYPE1, TYPE2, TYPE3) \
#define FLEXT_NEW_DSP_3(NAME,NEW_CLASS, TYPE1, TYPE2, TYPE3) \
REAL_NEW_3(NAME,NEW_CLASS, _tilde_setup, TYPE1, TYPE2, TYPE3) \
REAL_EXT(NEW_CLASS, _tilde_setup)
......@@ -158,10 +158,26 @@ REAL_EXT(NEW_CLASS, _tilde_setup)
REAL_LIB_3(NAME,NEW_CLASS, _setup,TYPE1, TYPE2, TYPE3)
//! Implementation of a flext tilde class (part of a library) with three arguments
#define FLEXT_LIB_TILDE_3(NAME,NEW_CLASS, TYPE1, TYPE2, TYPE3) \
#define FLEXT_LIB_DSP_3(NAME,NEW_CLASS, TYPE1, TYPE2, TYPE3) \
REAL_LIB_3(NAME,NEW_CLASS, _tilde_setup, TYPE1, TYPE2, TYPE3)
// deprecated stuff
// ----------------
#define FLEXT_NEW_TILDE FLEXT_NEW_DSP
#define FLEXT_LIB_TILDE FLEXT_LIB_DSP
#define FLEXT_NEW_TILDE_1 FLEXT_NEW_DSP_1
#define FLEXT_LIB_TILDE_1 FLEXT_LIB_DSP_1
#define FLEXT_NEW_TILDE_2 FLEXT_NEW_DSP_2
#define FLEXT_LIB_TILDE_2 FLEXT_LIB_DSP_2
#define FLEXT_NEW_TILDE_3 FLEXT_NEW_DSP_3
#define FLEXT_LIB_TILDE_3 FLEXT_LIB_DSP_3
#define FLEXT_NEW_G FLEXT_NEW_V
#define FLEXT_NEW_DSP_G FLEXT_NEW_DSP_V
#define FLEXT_LIB_G FLEXT_LIB_V
#define FLEXT_LIB_DSP_G FLEXT_LIB_DSP_V
// MaxMSP doesn't seem to be able to handle more than 3 creation arguments! -> USE GIMME
//@} FLEXT_NEWS
......@@ -229,6 +245,9 @@ static void cb_ ## M_FUN(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3,TP4 &arg4,T
//! 3 int arguments
#define FLEXT_CALLBACK_III(M_FUN) FLEXT_CALLBACK_3(M_FUN,int,int,int)
//! 1 symbol argument
#define FLEXT_CALLBACK_S(M_FUN) FLEXT_CALLBACK_1(M_FUN,t_symptr)
//@} FLEXT_CALLBACKS
......@@ -245,10 +264,12 @@ static void cb_ ## M_FUN(flext_base *c) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
delete p; \
th->M_FUN(); \
th->PopThread(); \
if(ok) { \
th->M_FUN(); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -260,11 +281,13 @@ static void cb_ ## M_FUN(flext_base *c,t_symbol *s,int argc,t_atom *argv) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
t_symbol *s; int argc; t_atom argv; p->get_any(s,argc,argv); \
delete p; \
th->M_FUN(s,argc,argv); \
th->PopThread(); \
if(ok) { \
th->M_FUN(s,argc,argv); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -276,11 +299,13 @@ static void cb_ ## M_FUN(flext_base *c,int argc,t_atom *argv) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
int argc; t_atom argv; p->get_gimme(argc,argv); \
delete p; \
th->M_FUN(argc,argv); \
th->PopThread(); \
if(ok) { \
th->M_FUN(argc,argv); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -292,11 +317,13 @@ static void cb_ ## M_FUN(flext_base *c,int &arg1) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
bool b = p->var[0]; \
delete p; \
th->M_FUN(b); \
th->PopThread(); \
if(ok) { \
th->M_FUN(b); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -309,11 +336,13 @@ static void cb_ ## M_FUN(flext_base *c,TP1 &arg1) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
const TP1 v1 = p->var[0]._ ## TP1; \
delete p; \
th->M_FUN(v1); \
th->PopThread(); \
if(ok) { \
th->M_FUN(v1); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -327,12 +356,14 @@ static void cb_ ## M_FUN(flext_base *c,TP1 &arg1,TP2 &arg2) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
const TP1 v1 = p->var[0]._ ## TP1; \
const TP1 v2 = p->var[1]._ ## TP2; \
delete p; \
th->M_FUN(v1,v2); \
th->PopThread(); \
if(ok) { \
th->M_FUN(v1,v2); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -347,13 +378,15 @@ static void cb_ ## M_FUN(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3) { \
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
const TP1 v1 = p->var[0]._ ## TP1; \
const TP2 v2 = p->var[1]._ ## TP2; \
const TP3 v3 = p->var[2]._ ## TP3; \
delete p; \
th->M_FUN(v1,v2,v3); \
th->PopThread(); \
if(ok) { \
th->M_FUN(v1,v2,v3); \
th->PopThread(); \
} \
return NULL; \
}
......@@ -369,14 +402,16 @@ static void cb_ ## M_FUN(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3,TP4 &arg4)
} \
static void *thr_ ## M_FUN(thr_params *p) { \
thisType *th = static_cast<thisType *>(p->cl); \
th->PushThread(); \
bool ok = th->PushThread(); \
const TP1 v1 = p->var[0]._ ## TP1; \
const TP2 v2 = p->var[1]._ ## TP2; \
const TP3 v3 = p->var[2]._ ## TP3; \
const TP4 v4 = p->var[3]._ ## TP4; \
delete p; \
th->M_FUN(v1,v2,v3,v4); \