diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2003-02-11 04:37:35 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2003-02-11 04:37:35 +0000 |
commit | 97926eb08cf74f277e522ffb8c7f985457822de3 (patch) | |
tree | 680b0e4c564057340a0b528ea6468d4e381a907d /externals/grill/flext/source | |
parent | 06f62d1168209ca6b9e2c3c5264c96a0a4c7cc98 (diff) |
""
svn path=/trunk/; revision=388
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r-- | externals/grill/flext/source/flbuf.cpp | 22 | ||||
-rwxr-xr-x | externals/grill/flext/source/fllib.cpp | 2 | ||||
-rwxr-xr-x | externals/grill/flext/source/flprefix.h | 19 | ||||
-rw-r--r-- | externals/grill/flext/source/flstdc.h | 2 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.cpp | 11 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 16 | ||||
-rw-r--r-- | externals/grill/flext/source/flutil.cpp | 36 |
7 files changed, 86 insertions, 22 deletions
diff --git a/externals/grill/flext/source/flbuf.cpp b/externals/grill/flext/source/flbuf.cpp index ebfe2abf..633f0d45 100644 --- a/externals/grill/flext/source/flbuf.cpp +++ b/externals/grill/flext/source/flbuf.cpp @@ -119,6 +119,24 @@ int flext::buffer::Set(const t_symbol *s,bool nameonly) return ret; } +bool flext::buffer::Valid() const +{ + if(sym) { +#if FLEXT_SYS == FLEXT_SYS_PD + int frames1; + t_sample *data1; + return garray_getfloatarray(arr, &frames1, &data1) != 0; +#elif FLEXT_SYS == FLEXT_SYS_MAX + const _buffer *p = (const _buffer *)sym->s_thing; + return p && p->b_valid; +#else +#error +#endif + } + else return false; +} + + bool flext::buffer::Update() { if(!Ok()) return false; @@ -172,7 +190,7 @@ void flext::buffer::Frames(int fr,bool keep) // copy buffer data to tmp storage tmp = new t_sample[sz]; if(tmp) - BlockMoveData(data,tmp,sizeof(t_sample)*sz); + CopySamples(data,tmp,sz); else error("flext::buffer - not enough memory for keeping buffer~ contents"); } @@ -190,7 +208,7 @@ void flext::buffer::Frames(int fr,bool keep) if(tmp) { // copy data back - BlockMoveData(tmp,data,sizeof(t_sample)*sz); + CopySamples(tmp,data,sz); delete[] tmp; } #else diff --git a/externals/grill/flext/source/fllib.cpp b/externals/grill/flext/source/fllib.cpp index 998cbae3..f061c2cb 100755 --- a/externals/grill/flext/source/fllib.cpp +++ b/externals/grill/flext/source/fllib.cpp @@ -19,7 +19,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define ALIASDEL ',' #define ALIASSLASHES ":/\\" -#if FLEXT_OS == FLEXT_OS_MACOS +#if FLEXT_OS == FLEXT_OS_MAC #define ALIASSLASH ':' #elif FLEXT_OS == FLEXT_OS_WIN #if FLEXT_SYS == FLEXT_SYS_PD diff --git a/externals/grill/flext/source/flprefix.h b/externals/grill/flext/source/flprefix.h index ad1d1edb..dce223e7 100755 --- a/externals/grill/flext/source/flprefix.h +++ b/externals/grill/flext/source/flprefix.h @@ -48,14 +48,15 @@ WARRANTIES, see the file, "license.txt," in this distribution. // --- definitions for FLEXT_OS ---------------------- #define FLEXT_OS_UNKNOWN 0 #define FLEXT_OS_WIN 1 -#define FLEXT_OS_MACOS 2 +#define FLEXT_OS_MAC 2 #define FLEXT_OS_LINUX 3 #define FLEXT_OS_IRIX 4 // --- definitions for FLEXT_OS_API --------------------- #define FLEXT_OSAPI_UNKNOWN 0 -#define FLEXT_OSAPI_MAC_CARBON 1 -#define FLEXT_OSAPI_MAC_OSX 2 +#define FLEXT_OSAPI_MAC_CLASSIC 1 +#define FLEXT_OSAPI_MAC_CARBON 2 +#define FLEXT_OSAPI_MAC_OSX 3 // --- definitions for FLEXT_CPU --------------------- #define FLEXT_CPU_UNKNOWN 0 @@ -160,7 +161,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifndef FLEXT_OS #if TARGET_OS_MAC - #define FLEXT_OS FLEXT_OS_MACOS + #define FLEXT_OS FLEXT_OS_MAC #elif TARGET_OS_WIN32 // assume Windows #define FLEXT_OS FLEXT_OS_WIN @@ -205,14 +206,14 @@ WARRANTIES, see the file, "license.txt," in this distribution. #elif defined(__CYGWIN__) || defined(__CYGWIN32__) #define FLEXT_OS FLEXT_OS_WIN #elif defined(__APPLE__) && defined(__MACH__) - #define FLEXT_OS FLEXT_OS_MACOS + #define FLEXT_OS FLEXT_OS_MAC // how about IRIX?? #else #define FLEXT_OS FLEXT_OS_UNKNOWN #endif #endif - #if FLEXT_OS == FLEXT_OS_MACOS + #if FLEXT_OS == FLEXT_OS_MAC #define FLEXT_OSAPI FLEXT_OSAPI_MAC_OSX #else #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN @@ -234,7 +235,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifndef FLEXT_OS #if defined(macintosh) - #define FLEXT_OS FLEXT_OS_MACOS + #define FLEXT_OS FLEXT_OS_MAC #else #define FLEXT_OS FLEXT_OS_UNKNOWN #endif @@ -269,7 +270,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #else #error "Flext SYS/OS combination unknown" #endif -#elif FLEXT_OS == FLEXT_OS_MACOS +#elif FLEXT_OS == FLEXT_OS_MAC // #pragma message("Compiling for MacOS") #if FLEXT_SYS == FLEXT_SYS_PD @@ -288,7 +289,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. // set threading model #ifdef FLEXT_THREADS #undef FLEXT_THREADS - #if FLEXT_OS == FLEXT_OS_MACOS && FLEXT_SYS == FLEXT_SYS_MAX + #if FLEXT_OS == FLEXT_OS_MAC && FLEXT_SYS == FLEXT_SYS_MAX // Max crashes with posix threads (but don't know why...) #define FLEXT_THREADS FLEXT_THR_MP #else diff --git a/externals/grill/flext/source/flstdc.h b/externals/grill/flext/source/flstdc.h index e36ec4e4..873f4243 100644 --- a/externals/grill/flext/source/flstdc.h +++ b/externals/grill/flext/source/flstdc.h @@ -71,7 +71,7 @@ typedef t_clock t_qelem; // Include the relevant Max/MSP header files -#if FLEXT_OS == FLEXT_OS_MACOS +#if FLEXT_OS == FLEXT_OS_MAC #ifndef __MRC__ #define powerc #endif diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index 3c6ab8f3..f3309ab0 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -128,13 +128,22 @@ void flext::GetAString(const t_atom &a,char *buf,int szbuf) #endif } +unsigned long flext::AtomHash(const t_atom &a) +{ +#if FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_PD + return ((unsigned long)a.a_type<<28)^*(unsigned long *)&a.a_w; +#else +#error Not implemented +#endif +} + unsigned int flext::FoldBits(unsigned long h,int bits) { if(!bits) return 0; const int hmax = (1<<bits)-1; unsigned int ret = 0; for(unsigned int i = 0; i < sizeof(h)*8; i += bits) - ret = ret^((h>>i)&hmax); + ret ^= (h>>i)&hmax; return ret; } diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index 66f16dac..497351d2 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -95,6 +95,10 @@ public: */ bool Ok() const { return sym != NULL && data != NULL; } + /*! \brief Check if buffer is valid + */ + bool Valid() const; + /*! \brief Check and update if the buffer has been changed (e.g. resized) */ bool Update(); @@ -167,17 +171,21 @@ public: static t_atom *CopyList(int argc,const t_atom *argv); //! Copy a memory region static void CopyMem(void *dst,const void *src,int bytes); - static void CopySamples(t_sample *dst,const t_sample *src,int cnt) { CopyMem(dst,src,cnt*sizeof(t_sample)); } - //! Zero a memory region + static void CopySamples(t_sample *dst,const t_sample *src,int cnt); + //! Set a memory region static void ZeroMem(void *dst,int bytes); - static void ZeroSamples(t_sample *dst,int cnt) { ZeroMem(dst,cnt*sizeof(t_sample)); } + static void SetSamples(t_sample *dst,int cnt,t_sample s); + static void ZeroSamples(t_sample *dst,int cnt) { SetSamples(dst,cnt,0); } //! Sleep for an amount of time static void Sleep(double s); + //! Get a 32 bit hash value frm an atom + static unsigned long AtomHash(const t_atom &a); + /*! \brief Fold value to a number of bits - \remark Good for hash generation + \remark Good for hash tables */ static unsigned int FoldBits(unsigned long h,int bits); diff --git a/externals/grill/flext/source/flutil.cpp b/externals/grill/flext/source/flutil.cpp index 1b1d929a..9be38cf1 100644 --- a/externals/grill/flext/source/flutil.cpp +++ b/externals/grill/flext/source/flutil.cpp @@ -17,9 +17,9 @@ WARRANTIES, see the file, "license.txt," in this distribution. #if FLEXT_OS == FLEXT_OS_WIN #include <windows.h> -#elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || defined(__GNUC__) +#elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_OSX #include <unistd.h> -#elif FLEXT_OS == FLEXT_OS_MACOS +#elif FLEXT_OS == FLEXT_OS_MAC #include <Timer.h> #include <Threads.h> #endif @@ -34,13 +34,41 @@ void flext::ZeroMem(void *dst,int bytes) memset(dst,0,bytes); } +void flext::CopySamples(t_sample *dst,const t_sample *src,int cnt) +{ + int n = cnt>>3; + cnt -= n<<3; + while(n--) { + dst[0] = src[0]; dst[1] = src[1]; + dst[2] = src[2]; dst[3] = src[3]; + dst[4] = src[4]; dst[5] = src[5]; + dst[6] = src[6]; dst[7] = src[7]; + src += 8,dst += 8; + } + + while(cnt--) *(dst++) = *(src++); +} + +void flext::SetSamples(t_sample *dst,int cnt,t_sample s) +{ + int n = cnt>>3; + cnt -= n<<3; + while(n--) { + dst[0] = dst[1] = dst[2] = dst[3] = dst[4] = dst[5] = dst[6] = dst[7] = s; + dst += 8; + } + + while(cnt--) *(dst++) = s; +} + + void flext::Sleep(double s) { #if FLEXT_OS == FLEXT_OS_WIN ::Sleep((long)(s*1000.)); -#elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || defined(__GNUC__) +#elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_OSX usleep((long)(s*1000000.)); -#elif FLEXT_OS == FLEXT_OS_MACOS +#elif FLEXT_OS == FLEXT_OS_MAC // that's just for OS9! UnsignedWide tick; Microseconds(&tick); |