23 #if C74_MAX_SDK_VERSION >= 0x0610
48 static void post(
const char *fmt,...);
50 static void error(
const char *fmt,...);
58 #ifdef FLEXT_NOGLOBALNEW
59 #error FLEXT_NOGLOBALNEW is deprecated, define FLEXT_USE_CMEM instead
60 #define FLEXT_USE_CMEM
64 inline void *
operator new(
size_t bytes) { return ::operator
new(bytes); }
65 inline void operator delete(
void *blk) { ::operator
delete(blk); }
67 inline void *
operator new[](
size_t bytes) { return ::operator
new[](bytes); }
68 inline void operator delete[](
void *blk) { ::operator
delete[](blk); }
70 static bool MemCheck(
void *) {
return true; }
76 void *
operator new(
size_t bytes);
78 void operator delete(
void *blk);
81 inline void *
operator new[](
size_t bytes) {
return operator new(bytes); }
82 inline void operator delete[](
void *blk) {
operator delete(blk); }
86 static bool MemCheck(
void *blk);
88 static bool MemCheck(
void *) {
return true; }
94 inline void *
operator new(size_t,
void *p) {
return p; }
95 inline void operator delete(
void *,
void *) {}
97 inline void *
operator new[](size_t,
void *p) {
return p; }
98 inline void operator delete[](
void *,
void *) {}
103 static void *NewAligned(
size_t bytes,
int bitalign = 128);
106 static T *NewAligned(
size_t times,
int bitalign = 128) {
return static_cast<T *
>(NewAligned(times*
sizeof(T),bitalign)); }
108 static void FreeAligned(
void *blk);
110 static bool IsAligned(
void *ptr,
int bitalign = 128) {
111 return (
reinterpret_cast<size_t>(ptr)&(bitalign-1)) == 0;
117 #ifdef FLEXT_USE_CMEM
126 #if !defined(_MSC_VER) && !defined(__BORLANDC__)
127 #if __cpp_noexcept_function_type
128 # define NEWTHROW noexcept(false)
129 # define DELTHROW noexcept(true)
131 # define NEWTHROW throw(std::bad_alloc)
132 # define DELTHROW throw()
140 void *
operator new(
size_t bytes)
NEWTHROW;
141 void operator delete(
void *blk)
DELTHROW;
186 static int Version();
189 static const char *VersionStr();
195 typedef t_float Float;
197 typedef t_sample Sample;
198 typedef const t_symbol *Symbol;
214 #if FLEXT_SYS == FLEXT_SYS_PD
216 #elif FLEXT_SYS == FLEXT_SYS_MAX
219 #error Not implemented
224 #if FLEXT_SYS == FLEXT_SYS_PD
225 # if PD_MINOR_VERSION >= 41
227 # define FLEXT_PD_ARRAYGRAB garray_getfloatwords
228 # define FLEXT_ARRAYTYPE t_word
229 # define FLEXT_GETSAMPLE(x) ((x).w_float)
230 # define _FLEXT_NEED_SAMPLE_CONV 1
234 # define FLEXT_PD_ARRAYGRAB garray_getfloatarray
235 # define FLEXT_ARRAYTYPE t_sample
236 # define FLEXT_GETSAMPLE(x) (x)
237 # define _FLEXT_NEED_SAMPLE_CONV 0
240 #elif FLEXT_SYS == FLEXT_SYS_MAX
241 # define FLEXT_ARRAYTYPE float
242 # define FLEXT_GETSAMPLE(x) (x)
243 # define _FLEXT_NEED_SAMPLE_CONV 0
249 Element(FLEXT_ARRAYTYPE s): el(s) {}
250 operator FLEXT_ARRAYTYPE &() {
return el; }
251 operator FLEXT_ARRAYTYPE ()
const {
return el; }
252 #if _FLEXT_NEED_SAMPLE_CONV
253 Element(t_sample s) { FLEXT_GETSAMPLE(el) = s; }
254 operator t_sample &() {
return FLEXT_GETSAMPLE(el); }
255 operator t_sample ()
const {
return FLEXT_GETSAMPLE(el); }
266 buffer(
const t_symbol *s = NULL,
bool delayed =
false);
277 #if FLEXT_SYS == FLEXT_SYS_PD
289 #if FLEXT_SYS == FLEXT_SYS_PD
291 #elif FLEXT_SYS == FLEXT_SYS_MAX
292 const t_buffer *p = (
const t_buffer *)sym->s_thing;
293 return p && p->b_valid;
295 #error not implemented
314 void Unlock(lock_t prv);
320 int Set(
const t_symbol *s = NULL,
bool nameonly =
false);
325 void Dirty(
bool refr =
false);
333 bool IsDirty()
const;
336 const t_symbol *Symbol()
const {
return sym; }
339 const char *Name()
const {
return sym?GetString(sym):
""; }
344 Element *Data() {
return data; }
346 const Element *Data()
const {
return data; }
349 int Channels()
const {
return chns; }
351 int Frames()
const {
return frames; }
353 void Frames(
int fr,
bool keep =
false,
bool zero =
true);
356 inline Element operator [](
int index)
const {
return data[index]; }
359 inline Element &operator [](
int index) {
return data[index]; }
362 void SetRefrIntv(
float intv);
368 Locker(buffer &b): buf(b),lock(b.Lock()) {}
369 ~Locker() { buf.Unlock(lock); }
384 #if FLEXT_SYS == FLEXT_SYS_PD
400 static void cb_tick(buffer *b);
401 #elif FLEXT_SYS == FLEXT_SYS_MAX
417 static void CopyAtom(t_atom *dst,
const t_atom *src) { *dst = *src; }
420 static void CopyAtoms(
int cnt,t_atom *dst,
const t_atom *src);
423 static bool PrintAtom(
const t_atom &a,
char *buf,
size_t bufsz);
428 static const char *ScanAtom(t_atom &a,
const char *buf);
431 static t_atom *CopyList(
int argc,
const t_atom *argv);
434 static bool PrintList(
int argc,
const t_atom *argv,
char *buf,
size_t bufsz);
441 static int ScanList(
int argc,t_atom *argv,
const char *buf);
444 static void CopyMem(
void *dst,
const void *src,
int bytes);
446 static void CopySamples(t_sample *dst,
const t_sample *src,
int cnt);
447 template<
typename T>
static void CopySamples(T *dst,
const T *src,
int cnt) { CopyMem(dst,src,
sizeof(*src)*cnt); }
449 static void ZeroMem(
void *dst,
int bytes);
451 static void SetSamples(t_sample *dst,
int cnt,t_sample s);
452 template<
typename T>
static void SetSamples(T *dst,
int cnt,t_sample s) {
for(
int i = 0; i < cnt; ++i) dst[i] = s; }
454 static void ZeroSamples(t_sample *dst,
int cnt) { SetSamples(dst,cnt,0); }
455 template<
typename T>
static void ZeroSamples(T *dst,
int cnt) { ZeroMem(dst,
sizeof(*dst)*cnt); }
459 static unsigned long AtomHash(
const t_atom &a);
470 static const t_symbol *sym__;
472 static const t_symbol *sym_float;
474 static const t_symbol *sym_symbol;
476 static const t_symbol *sym_bang;
478 static const t_symbol *sym_list;
480 static const t_symbol *sym_anything;
485 static const t_symbol *sym_int;
490 static const t_symbol *sym_pointer;
493 static const t_symbol *sym_signal;
496 static const t_symbol *MakeSymbol(
const t_symbol *s) {
return s; }
499 static const t_symbol *MakeSymbol(
const char *s) { return ::gensym(
const_cast<char *
>(s)); }
501 static const char *GetString(
const t_symbol *s) {
return s->s_name; }
503 static const char *GetAString(
const t_symbol *s,
const char *def = NULL) {
return s?GetString(s):def; }
508 static void SetAtom(t_atom &a,
const t_atom &b) { CopyAtom(&a,&b); }
510 static int CmpAtom(
const t_atom &a,
const t_atom &b);
515 static int GetType(
const t_atom &a) {
return a.a_type; }
518 static bool IsNothing(
const t_atom &a) {
return a.a_type == A_NULL; }
520 static void SetNothing(t_atom &a) { a.a_type = A_NULL; }
523 static bool IsFloat(
const t_atom &a) {
return a.a_type == A_FLOAT; }
526 static bool CanbeFloat(
const t_atom &a) {
return IsFloat(a) || IsInt(a); }
529 static float GetFloat(
const t_atom &a) {
return a.a_w.w_float; }
531 static void SetFloat(t_atom &a,
float v) { a.a_type = A_FLOAT; a.a_w.w_float = v; }
534 static bool IsSymbol(
const t_atom &a) {
return a.a_type == A_SYMBOL; }
536 #if FLEXT_SYS == FLEXT_SYS_PD
538 static const t_symbol *GetSymbol(
const t_atom &a) {
return const_cast<const t_symbol *
>(a.a_w.w_symbol); }
540 static void SetSymbol(t_atom &a,
const t_symbol *s) { a.a_type = A_SYMBOL; a.a_w.w_symbol =
const_cast<t_symbol *
>(s); }
541 #elif FLEXT_SYS == FLEXT_SYS_MAX
543 static const t_symbol *GetSymbol(
const t_atom &a) {
return const_cast<const t_symbol *
>(a.a_w.w_sym); }
545 static void SetSymbol(t_atom &a,
const t_symbol *s) { a.a_type = A_SYMBOL; a.a_w.w_sym =
const_cast<t_symbol *
>(s); }
550 static const t_symbol *GetASymbol(
const t_atom &a,
const t_symbol *def = NULL) {
return IsSymbol(a)?GetSymbol(a):def; }
553 static bool IsString(
const t_atom &a) {
return IsSymbol(a); }
555 static const char *GetString(
const t_atom &a) {
const t_symbol *s = GetSymbol(a);
return s?GetString(s):NULL; }
557 static const char *GetAString(
const t_atom &a,
const char *def = NULL) {
return IsSymbol(a)?GetAString(GetSymbol(a),def):def; }
559 static void GetAString(
const t_atom &a,
char *buf,
size_t szbuf);
561 static void SetString(t_atom &a,
const char *c) { SetSymbol(a,MakeSymbol(c)); }
564 static bool CanbeInt(
const t_atom &a) {
return IsFloat(a) || IsInt(a); }
566 #if FLEXT_SYS == FLEXT_SYS_PD
568 static float GetAFloat(
const t_atom &a,
float def = 0) {
return IsFloat(a)?GetFloat(a):def; }
571 static bool IsInt(
const t_atom &) {
return false; }
573 static int GetInt(
const t_atom &a) {
return (
int)GetFloat(a); }
575 static int GetAInt(
const t_atom &a,
int def = 0) {
return (
int)GetAFloat(a,(
float)def); }
577 static void SetInt(t_atom &a,
int v) { a.a_type = A_FLOAT; a.a_w.w_float = (float)v; }
579 #ifndef FLEXT_COMPATIBLE
581 static bool IsPointer(
const t_atom &a) {
return a.a_type == A_POINTER; }
583 static bool CanbePointer(
const t_atom &a) {
return IsPointer(a); }
585 static t_gpointer *GetPointer(
const t_atom &a) {
return a.a_w.w_gpointer; }
587 static t_gpointer *GetAPointer(
const t_atom &a,t_gpointer *def = NULL) {
return IsPointer(a)?GetPointer(a):def; }
589 static void SetPointer(t_atom &a,t_gpointer *p) { a.a_type = A_POINTER; a.a_w.w_gpointer = (t_gpointer *)p; }
592 #elif FLEXT_SYS == FLEXT_SYS_MAX
594 static float GetAFloat(
const t_atom &a,
float def = 0) {
return IsFloat(a)?GetFloat(a):(IsInt(a)?GetInt(a):def); }
597 static bool IsInt(
const t_atom &a) {
return a.a_type == A_INT; }
599 static int GetInt(
const t_atom &a) {
return a.a_w.w_long; }
601 static int GetAInt(
const t_atom &a,
int def = 0) {
return IsInt(a)?GetInt(a):(IsFloat(a)?(int)GetFloat(a):def); }
603 static void SetInt(t_atom &a,
int v) { a.a_type = A_INT; a.a_w.w_long = v; }
605 #error "Platform not supported"
611 static void SetBool(t_atom &a,
bool v) { SetInt(a,v?1:0); }
613 static bool CanbeBool(
const t_atom &a) {
return CanbeInt(a); }
615 static bool GetABool(
const t_atom &a) {
return GetAInt(a) != 0; }
617 static bool GetBool(
const t_atom &a) {
return GetInt(a) != 0; }
627 AtomList(): cnt(0),lst(NULL) {}
629 explicit AtomList(
int argc,
const t_atom *argv = NULL): cnt(0),lst(NULL) { operator()(argc,argv); }
631 AtomList(
const AtomList &a): cnt(0),lst(NULL) { operator =(a); }
636 AtomList &Clear() {
return operator()(); }
639 AtomList &Set(
int argc,
const t_atom *argv,
int offs = 0,
bool resize =
false);
641 int Get(t_atom *argv,
int mxsz = -1)
const;
644 AtomList &operator()(
int argc = 0,
const t_atom *argv = NULL) {
return Set(argc,argv,0,
true); }
646 AtomList &operator =(
const AtomList &a) {
return operator()(a.Count(),a.Atoms()); }
649 int Compare(
const AtomList &a)
const;
651 bool operator <(
const AtomList &a)
const {
return Compare(a) < 0; }
652 bool operator <=(
const AtomList &a)
const {
return Compare(a) <= 0; }
653 bool operator >(
const AtomList &a)
const {
return Compare(a) > 0; }
654 bool operator >=(
const AtomList &a)
const {
return Compare(a) >= 0; }
655 bool operator ==(
const AtomList &a)
const {
return Compare(a) == 0; }
656 bool operator !=(
const AtomList &a)
const {
return Compare(a) != 0; }
659 int Count()
const {
return cnt; }
661 t_atom &operator [](
int ix) {
return lst[ix]; }
663 const t_atom &operator [](
int ix)
const {
return lst[ix]; }
666 t_atom *Atoms() {
return lst; }
668 const t_atom *Atoms()
const {
return lst; }
671 AtomList &Append(
int argc,
const t_atom *argv = NULL)
680 AtomList &Prepend(
int argc,
const t_atom *argv = NULL)
683 Alloc(c+argc,0,c,argc);
689 AtomList &Append(
const t_atom &a) {
return Append(1,&a); }
691 AtomList &Append(
const AtomList &a) {
return Append(a.Count(),a.Atoms()); }
693 AtomList &Prepend(
const t_atom &a) {
return Prepend(1,&a); }
695 AtomList &Prepend(
const AtomList &a) {
return Prepend(a.Count(),a.Atoms()); }
698 void GetPart(
int offs,
int len,AtomList &ret)
const;
700 AtomList &Part(
int offs,
int len) { GetPart(offs,len,*
this);
return *
this; }
703 bool Print(
char *buffer,
int buflen)
const {
return flext::PrintList(Count(),Atoms(),buffer,buflen); }
708 int Scan(
const char *buffer) {
return flext::ScanList(Count(),Atoms(),buffer); }
711 virtual void Alloc(
int sz,
int keepix = -1,
int keeplen = -1,
int keepto = 0);
722 explicit AtomListStaticBase(
int pc,t_atom *dt): precnt(pc),predata(dt) {}
723 virtual ~AtomListStaticBase();
724 virtual void Alloc(
int sz,
int keepix = -1,
int keeplen = -1,
int keepto = 0);
727 AtomListStaticBase &operator =(
const AtomList &a) { AtomList::operator =(a);
return *
this; }
728 AtomListStaticBase &operator =(
const AtomListStaticBase &a) { AtomList::operator =(a);
return *
this; }
731 t_atom *
const predata;
736 :
public AtomListStaticBase
740 explicit AtomListStatic(): AtomListStaticBase(PRE,pre) {}
742 explicit AtomListStatic(
int argc,
const t_atom *argv = NULL): AtomListStaticBase(PRE,pre) { AtomList::operator()(argc,argv); }
744 explicit AtomListStatic(
const AtomList &a): AtomListStaticBase(PRE,pre) { operator =(a); }
747 AtomListStatic &operator =(
const AtomList &a) { AtomListStaticBase::operator =(a);
return *
this; }
748 AtomListStatic &operator =(
const AtomListStatic &a) { AtomListStaticBase::operator =(a);
return *
this; }
758 explicit AtomAnything(): hdr(NULL) {}
761 explicit AtomAnything(
const t_symbol *h,
int argc = 0,
const t_atom *argv = NULL)
762 : AtomList(argc,argv),hdr(h?h:sym__)
766 explicit AtomAnything(
const char *h,
int argc = 0,
const t_atom *argv = NULL)
767 : AtomList(argc,argv),hdr(MakeSymbol(h))
771 AtomAnything(
const AtomAnything &a)
772 : AtomList(a),hdr(a.hdr)
776 AtomAnything &Clear() {
return operator()(); }
779 const t_symbol *Header()
const {
return hdr; }
782 void Header(
const t_symbol *h) { hdr = h; }
785 AtomAnything &operator()(
const t_symbol *h = NULL,
int argc = 0,
const t_atom *argv = NULL)
787 hdr = h; AtomList::operator()(argc,argv);
792 AtomAnything &operator =(
const AtomAnything &a) {
return operator()(a.Header(),a.Count(),a.Atoms()); }
802 #pragma optimize("p",off)
804 static t_atom *SetDouble(t_atom *dbl,
double d)
806 float f =
static_cast<float>(d);
807 float r =
static_cast<float>(d-f);
813 #pragma optimize("p",on)
816 static double GetDouble(
int argc,
const t_atom *argv)
818 double d = argc >= 1?GetAFloat(argv[0]):0;
819 return argc >= 2?d+GetAFloat(argv[1]):d;
822 static AtomList &SetDouble(AtomList &l,
double d) { SetDouble(l(2).Atoms(),d);
return l; }
824 static double GetDouble(
const AtomList &l) {
return GetDouble(l.Count(),l.Atoms()); }
838 static MsgBundle *MsgNew();
841 static void MsgFree(MsgBundle *mb);
844 static void ToSysMsg(MsgBundle *mb);
847 static void ToOutMsg(MsgBundle *mb);
850 static void ToQueueMsg(MsgBundle *mb);
859 static bool Forward(
const t_symbol *sym,
const t_symbol *s,
int argc,
const t_atom *argv);
860 static bool Forward(
const t_symbol *sym,
const AtomAnything &args) {
return Forward(sym,args.Header(),args.Count(),args.Atoms()); }
861 static bool Forward(
const char *sym,
const AtomAnything &args) {
return Forward(MakeSymbol(sym),args.Header(),args.Count(),args.Atoms()); }
862 static bool Forward(
const t_symbol *sym,
int argc,
const t_atom *argv) {
return Forward(sym,sym_list,argc,argv); }
863 static bool Forward(
const t_symbol *sym,
const AtomList &args) {
return Forward(sym,args.Count(),args.Atoms()); }
864 static bool Forward(
const char *sym,
const AtomList &args) {
return Forward(MakeSymbol(sym),args.Count(),args.Atoms()); }
866 static bool SysForward(
const t_symbol *sym,
const t_symbol *s,
int argc,
const t_atom *argv);
867 static bool SysForward(
const t_symbol *sym,
const AtomAnything &args) {
return SysForward(sym,args.Header(),args.Count(),args.Atoms()); }
868 static bool SysForward(
const char *sym,
const AtomAnything &args) {
return SysForward(MakeSymbol(sym),args.Header(),args.Count(),args.Atoms()); }
869 static bool SysForward(
const t_symbol *sym,
int argc,
const t_atom *argv) {
return SysForward(sym,sym_list,argc,argv); }
870 static bool SysForward(
const t_symbol *sym,
const AtomList &args) {
return SysForward(sym,args.Count(),args.Atoms()); }
871 static bool SysForward(
const char *sym,
const AtomList &args) {
return SysForward(MakeSymbol(sym),args.Count(),args.Atoms()); }
873 static bool QueueForward(
const t_symbol *sym,
const t_symbol *s,
int argc,
const t_atom *argv);
874 static bool QueueForward(
const t_symbol *sym,
const AtomAnything &args) {
return QueueForward(sym,args.Header(),args.Count(),args.Atoms()); }
875 static bool QueueForward(
const char *sym,
const AtomAnything &args) {
return QueueForward(MakeSymbol(sym),args.Header(),args.Count(),args.Atoms()); }
876 static bool QueueForward(
const t_symbol *sym,
int argc,
const t_atom *argv) {
return QueueForward(sym,sym_list,argc,argv); }
877 static bool QueueForward(
const t_symbol *sym,
const AtomList &args) {
return QueueForward(sym,args.Count(),args.Atoms()); }
878 static bool QueueForward(
const char *sym,
const AtomList &args) {
return QueueForward(MakeSymbol(sym),args.Count(),args.Atoms()); }
880 static bool MsgForward(MsgBundle *mb,
const t_symbol *sym,
const t_symbol *s,
int argc,
const t_atom *argv);
881 static bool MsgForward(MsgBundle *mb,
const t_symbol *sym,
const AtomAnything &args) {
return MsgForward(mb,sym,args.Header(),args.Count(),args.Atoms()); }
882 static bool MsgForward(MsgBundle *mb,
const char *sym,
const AtomAnything &args) {
return MsgForward(mb,MakeSymbol(sym),args.Header(),args.Count(),args.Atoms()); }
883 static bool MsgForward(MsgBundle *mb,
const t_symbol *sym,
int argc,
const t_atom *argv) {
return MsgForward(mb,sym,sym_list,argc,argv); }
884 static bool MsgForward(MsgBundle *mb,
const t_symbol *sym,
const AtomList &args) {
return MsgForward(mb,sym,args.Count(),args.Atoms()); }
885 static bool MsgForward(MsgBundle *mb,
const char *sym,
const AtomList &args) {
return MsgForward(mb,MakeSymbol(sym),args.Count(),args.Atoms()); }
897 #if FLEXT_SYS == FLEXT_SYS_PD
898 #if PD_MINOR_VERSION >= 38 || (PD_MINOR_VERSION >= 37 && defined(PD_DEVEL_VERSION))
899 static void Lock() { sys_lock(); }
900 static void Unlock() { sys_unlock(); }
903 static void Lock() {}
904 static void Unlock() {}
906 #elif FLEXT_SYS == FLEXT_SYS_MAX
908 static void Lock() { critical_enter(0); }
909 static void Unlock() { critical_exit(0); }
922 static bool IsThreadRegistered();
924 static bool IsThreadRegistered() {
return false; }
930 # if FLEXT_THREADS == FLEXT_THR_MP
931 typedef MPTaskID thrid_t;
932 # elif FLEXT_THREADS == FLEXT_THR_POSIX
933 typedef pthread_t thrid_t;
934 # elif FLEXT_THREADS == FLEXT_THR_WIN32
935 typedef DWORD thrid_t;
937 # error Threading model not supported
942 static thrid_t GetThreadId() {
943 #if FLEXT_THREADS == FLEXT_THR_POSIX
944 return pthread_self();
945 #elif FLEXT_THREADS == FLEXT_THR_MP
946 return MPCurrentTaskID();
947 #elif FLEXT_THREADS == FLEXT_THR_WIN32
948 return GetCurrentThreadId();
956 static thrid_t GetSysThreadId() {
return thrid; }
959 static bool ShouldExit();
962 static bool IsThread(thrid_t t,thrid_t ref = GetThreadId()) {
963 #if FLEXT_THREADS == FLEXT_THR_POSIX
964 return pthread_equal(ref,t) != 0;
978 thr_params(
int n = 1): cl(NULL),var(new _data[n]) {}
979 ~thr_params() {
delete[] var; }
981 void set_any(
const t_symbol *s,
int argc,
const t_atom *argv) { var[0]._any =
new AtomAnything(s,argc,argv); }
982 void set_list(
int argc,
const t_atom *argv) { var[0]._list =
new AtomList(argc,argv); }
998 static thrid_t thrhelpid;
999 static thrid_t thrmsgid;
1000 static void ThrHelper(
void *);
1003 static thrid_t thrid;
1006 static bool StartHelper();
1013 static void ThrYield() {
1014 #if FLEXT_THREADS == FLEXT_THR_POSIX
1017 #elif FLEXT_THREADS == FLEXT_THR_MP
1019 #elif FLEXT_THREADS == FLEXT_THR_WIN32
1028 static bool IsThreadPreemptive(thrid_t t = GetThreadId()) {
1029 #if FLEXT_THREADS == FLEXT_THR_POSIX || FLEXT_THREADS == FLEXT_THR_WIN32
1031 #elif FLEXT_THREADS == FLEXT_THR_MP
1032 return MPTaskIsPreemptive(t);
1041 static bool RelPriority(
int dp,thrid_t ref = GetSysThreadId(),thrid_t thr = GetThreadId());
1045 static int GetPriority(thrid_t thr = GetThreadId());
1049 static bool SetPriority(
int p,thrid_t thr = GetThreadId());
1056 #if FLEXT_THREADS == FLEXT_THR_POSIX
1060 ThrMutex() { pthread_mutex_init(&mutex,NULL); }
1062 ~ThrMutex() { pthread_mutex_destroy(&mutex); }
1065 bool Lock() {
return pthread_mutex_lock(&mutex) == 0; }
1071 bool TryLock() {
return pthread_mutex_trylock(&mutex) == 0; }
1073 bool Unlock() {
return pthread_mutex_unlock(&mutex) == 0; }
1076 pthread_mutex_t mutex;
1079 #elif FLEXT_THREADS == FLEXT_THR_WIN32
1083 ThrMutex() { ::InitializeCriticalSection(&mutex); }
1085 ~ThrMutex() { ::DeleteCriticalSection(&mutex); }
1088 bool Lock() { ::EnterCriticalSection(&mutex);
return true; }
1094 bool TryLock() { return ::TryEnterCriticalSection(&mutex) != 0; }
1096 bool Unlock() { ::LeaveCriticalSection(&mutex);
return true; }
1099 CRITICAL_SECTION mutex;
1101 #elif FLEXT_THREADS == FLEXT_THR_MP
1105 ThrMutex() { MPCreateCriticalRegion(&crit); }
1107 ~ThrMutex() { MPDeleteCriticalRegion(crit); }
1110 bool Lock() {
return MPEnterCriticalRegion(crit,kDurationForever) == noErr; }
1114 bool TryLock() {
return MPEnterCriticalRegion(crit,kDurationImmediate) == noErr; }
1116 bool Unlock() {
return MPExitCriticalRegion(crit) == noErr; }
1119 MPCriticalRegionID crit;
1122 #error "Not implemented"
1134 ThrCond() { pthread_cond_init(&cond,NULL); }
1136 ~ThrCond() { pthread_cond_destroy(&cond); }
1147 bool TimedWait(
double ftime);
1150 bool Signal() {
return pthread_cond_signal(&cond) == 0; }
1153 pthread_cond_t cond;
1155 #elif FLEXT_THREADS == FLEXT_THR_WIN32
1159 ThrCond() { cond = CreateEvent(NULL,FALSE,FALSE,NULL); }
1161 ~ThrCond() { CloseHandle(cond); }
1164 bool Wait() {
return WaitForSingleObject(cond,INFINITE) == WAIT_OBJECT_0; }
1172 bool TimedWait(
double ftime) {
return WaitForSingleObject(cond,(LONG)(ftime*1000)) == WAIT_OBJECT_0; }
1175 bool Signal() {
return SetEvent(cond) != 0; }
1180 #elif FLEXT_THREADS == FLEXT_THR_MP
1184 ThrCond() { MPCreateEvent(&ev); }
1186 ~ThrCond() { MPDeleteEvent(ev); }
1189 bool Wait() {
return MPWaitForEvent(ev,NULL,kDurationForever) == noErr; }
1194 bool TimedWait(
double tm) {
return MPWaitForEvent(ev,NULL,tm*kDurationMicrosecond*1.e6) == noErr; }
1197 bool Signal() {
return MPSetEvent(ev,1) == noErr; }
1203 #error "Not implemented"
1212 static bool PushThread();
1218 static void PopThread();
1226 static bool LaunchThread(
void (*meth)(thr_params *p),thr_params *params = NULL);
1235 static bool StopThread(
void (*meth)(thr_params *p),thr_params *params = NULL,
bool wait =
false);
1239 static void RegisterThread(thrid_t
id = GetThreadId());
1242 static void UnregisterThread(thrid_t
id = GetThreadId());
1264 static double GetTime()
1266 #if FLEXT_SYS == FLEXT_SYS_PD
1267 return clock_gettimesince(0)*0.001;
1268 #elif FLEXT_SYS == FLEXT_SYS_MAX
1270 clock_getftime(&tm);
1273 #error Not implemented
1280 static double GetTimeGrain()
1282 #if FLEXT_SYS == FLEXT_SYS_PD
1284 #elif FLEXT_SYS == FLEXT_SYS_MAX
1287 #error Not implemented
1293 static double GetOSTime();
1299 static void Sleep(
double s);
1308 Timer(
bool queued =
false);
1312 void SetCallback(
void (*cb)(
void *data)) { clss = NULL,cback = cb; }
1319 bool At(
double time,
void *data = NULL,
bool dopast =
true);
1321 bool Delay(
double time,
void *data = NULL);
1323 bool Periodic(
double time,
void *data = NULL);
1325 bool Now(
void *data = NULL) {
return Delay(0,data); }
1328 virtual void Work();
1331 static void callback(Timer *tmr);
1333 #if FLEXT_SYS == FLEXT_SYS_PD
1335 #elif FLEXT_SYS == FLEXT_SYS_MAX
1336 static void queuefun(Timer *tmr);
1340 #error Not implemented
1344 void (*cback)(
void *data);
1353 static bool InDSP() {
return indsp; }
1370 static unsigned long GetSIMDCapabilities();
1373 static void MulSamples(t_sample *dst,
const t_sample *src,t_sample mul,
int cnt);
1374 static void MulSamples(t_sample *dst,
const t_sample *src,
const t_sample *mul,
int cnt);
1375 static void AddSamples(t_sample *dst,
const t_sample *src,t_sample add,
int cnt);
1376 static void AddSamples(t_sample *dst,
const t_sample *src,
const t_sample *add,
int cnt);
1377 static void ScaleSamples(t_sample *dst,
const t_sample *src,t_sample mul,t_sample add,
int cnt);
1378 static void ScaleSamples(t_sample *dst,
const t_sample *src,t_sample mul,
const t_sample *add,
int cnt);
1379 static void ScaleSamples(t_sample *dst,
const t_sample *src,
const t_sample *mul,
const t_sample *add,
int cnt);
1388 friend class flext_obj;
1391 static void Setup();
1393 static bool chktilde(
const char *objname);
1395 static unsigned long simdcaps;
1397 static const t_symbol *sym_attributes;
1398 static const t_symbol *sym_methods;
1400 #if FLEXT_SYS == FLEXT_SYS_MAX
1401 static const t_symbol *sym_buffer;
1402 static const t_symbol *sym_size;
1403 static const t_symbol *sym_dirty;
1412 inline bool operator ==(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) == 0; }
1413 inline bool operator !=(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) != 0; }
1414 inline bool operator <(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) < 0; }
1415 inline bool operator <=(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) <= 0; }
1416 inline bool operator >(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) > 0; }
1417 inline bool operator >=(
const t_atom &a,
const t_atom &b) {
return flext::CmpAtom(a,b) >= 0; }
#define FLEXT_THR_POSIX
Definition: flprefix.h:80
#define FLEXT_SHARE
Definition: flprefix.h:425
#define FLEXT_THREADS
Definition: flprefix.h:379
#define FLEXT_TEMPLATE
Definition: flprefix.h:462
Definitions to unite Max/MSP and PD notions.
#define FLEXT_ASSERT(b)
Definition: flstdc.h:316
t_symbol * t_symptr
Definition: flstdc.h:255
bool operator!=(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1413
bool operator==(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1412
bool operator>(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1416
bool operator<=(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1415
bool operator>=(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1417
bool operator<(const t_atom &a, const t_atom &b)
Definition: flsupport.h:1414
#define DELTHROW
Definition: flsupport.h:132
#define NEWTHROW
Definition: flsupport.h:131
typedef FLEXT_TEMPINST(FLEXT_SHARE FLEXT_CLASSDEF(flext_root)) flext_root
FLEXT_TEMPLATE class FLEXT_SHARE FLEXT_CLASSDEF(flext_root)