CGestalt.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CSL_Gestalt_H
00015 #define CSL_Gestalt_H
00016
00017 #include "CSL_Types.h"
00018
00019 #include <stdarg.h>
00020 #include <string>
00021
00022 namespace csl {
00023
00027
00028 class CGestalt {
00029
00030 public:
00031
00032 static unsigned frameRate();
00033 static void setFrameRate(unsigned frameRate);
00034 static sample framePeriod();
00035
00036 static unsigned numInChannels();
00037 static void setNumInChannels(unsigned numChannels);
00038
00039 static unsigned numOutChannels();
00040 static void setNumOutChannels(unsigned numChannels);
00041
00042 static unsigned blockSize();
00043 static void setBlockSize(unsigned blockSize);
00044
00045 static unsigned maxBufferFrames();
00046 static void setMaxBufferFrames(unsigned numFrames);
00047
00048 static unsigned maxSndFileFrames();
00049 static void setMaxSndFileFrames(unsigned numFrames);
00050
00051 static unsigned verbosity();
00052 static void setVerbosity(unsigned verbosity);
00053
00054
00055 static unsigned loggingPeriod();
00056 static void setLoggingPeriod(unsigned loggingPeriod);
00057
00058 static unsigned outPort();
00059 static void setOutPort(unsigned outPort);
00060
00061 static std::string dataFolder();
00062 static void setDataFolder(std::string dataFolder);
00063
00064 static bool stopNow();
00065 static void setStopNow();
00066 static void clearStopNow();
00067 };
00068
00073
00074
00075
00076
00077 #define SAFE_MALLOC(ptr, type, len) \
00078 ptr = new type[len]; \
00079 if ((char *) ptr == NULL) \
00080 throw MemoryError("can't allocate buffer"); \
00081 memset(ptr, 0, len * sizeof(ptr))
00082
00083 #define SAFE_FREE(ptr) \
00084 if (ptr) \
00085 delete[] ptr
00086
00091
00092 #ifdef CSL_ENUMS
00093 typedef enum {
00094 kLogInfo,
00095 kLogWarning,
00096 kLogError,
00097 kLogFatal
00098 } LogLevel;
00099 #else
00100 #define kLogInfo 0
00101 #define kLogWarning 1
00102 #define kLogError 2
00103 #define kLogFatal 3
00104 typedef int LogLevel;
00105 #endif
00106
00110
00111 void logMsg(char * format, ...);
00112 void logMsg(LogLevel level, char* format, ...);
00113
00114
00115
00116 void vlogMsg(char * format, va_list args);
00117 void vlogMsg(LogLevel level, char * format, va_list args);
00118
00123
00126
00127 bool sleepUsec(float dur);
00128 bool sleepMsec(float dur);
00129 bool sleepSec(float dur);
00130
00132
00133 float fRand(void);
00134 float fRand2(void);
00135 float fRand3(float minV, float maxV);
00136 float fRand4(float base, float range);
00137 float fRand5(float base, float range);
00138 float fRand6(float val);
00139
00140
00141
00142 float fRandZ(void);
00143 float fRand1(void);
00144 float fRandM(float minV, float maxV);
00145 float fRandR(float base, float range);
00146 float fRandB(float base, float range);
00147 float fRandV(float val);
00148
00149 bool coin();
00150 bool coin(float bias);
00151
00156
00157 class Observer;
00158
00167
00168 class Model {
00169 public:
00170 Model() : mHasObservers(false) { };
00171 ~Model() { };
00172
00173 void attachObserver(Observer *);
00174 void detachObserver(Observer *);
00175
00176 void changed(void * argument);
00177
00178 private:
00179 std::vector <Observer *> mObservers;
00180 bool mHasObservers;
00181 };
00182
00189
00190 class Observer {
00191 public:
00192 Observer() { };
00193 virtual ~Observer() { };
00194
00195
00196 virtual void update(void * arg) = 0;
00197 };
00198
00199 }
00200
00201 #endif