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"      // The system default values are defined there
00018 
00019 #include <stdarg.h>         // for va_arg, vaList, etc.
00020 #include <string>
00021 
00022 namespace csl {
00023 
00027 
00028 class CGestalt {                        
00029 
00030 public:                                             // Accessor (getter/setter) methods
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);   // (0 = only fatal errors, 1 = warnings, 
00053                                                     // 2 = most msgs, 3 = include info msgs)
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 dFolder); 
00063     
00064     static bool stopNow();                          
00065     static void setStopNow();
00066     static void clearStopNow();
00067     
00068     static std::string initFileText(char key);      
00069     static void storeToInitFile(char key, std::string data);
00070     
00071     static std::string sndFileName();               
00072 
00073 };
00074 
00079 
00082 
00083 #define SAFE_MALLOC(ptr, type, len)                     \
00084     ptr = new type[len];                                \
00085     if ((char *) ptr == NULL)                           \
00086         throw MemoryError("can't allocate buffer");     \
00087     memset(ptr, 0, len * sizeof(ptr))
00088 
00089 #define SAFE_FREE(ptr)                                  \
00090     if (ptr)                                            \
00091         delete[] ptr
00092 
00097 
00098 #ifdef CSL_ENUMS
00099 typedef enum {                  
00100     kLogInfo,                   
00101     kLogWarning,
00102     kLogError,
00103     kLogFatal
00104 } LogLevel;
00105 #else
00106     #define kLogInfo 0
00107     #define kLogWarning 1
00108     #define kLogError 2
00109     #define kLogFatal 3
00110     typedef int LogLevel;
00111 #endif
00112 
00116 
00117 void logMsg(char * format, ...);            
00118 void logMsg(LogLevel level, char* format, ...);
00119 
00120 void logLine();                             
00121 void logURL();                              
00122 
00123 // These two are private -- for handling var-args
00124 
00125 void vlogMsg(char * format, va_list args);
00126 void vlogMsg(LogLevel level, char * format, va_list args);
00127 
00132 
00135 
00136 bool sleepUsec(float dur);                  
00137 bool sleepMsec(float dur);
00138 bool sleepSec(float dur);
00139 
00140 Timestamp timeNow();                        
00141 float fTimeNow();                           
00142 
00143 
00145 
00146 float fRandZ(void);                         
00147 float fRand1(void);                         
00148 float fRandV(float val);                    
00149 
00150 float fRandM(float minV, float maxV);       
00151 float fRandR(float base, float range);      
00152 float fRandB(float base, float range);      
00153 
00155 
00156 int iRandV(int val);                        
00157 int iRandM(int minV, int maxV);             
00158 int iRandB(int base, int range);            
00159 
00160 // Bool coin-toss rands
00161 
00162 bool coin();                                
00163 bool coin(float bias);                      
00164 
00165 
00166 // MIDI Conversions
00167 
00169 
00170 float keyToFreq(unsigned midiKey);
00171 
00173 
00174 unsigned freqToKey(float frequency);
00175 
00176 
00181 
00182 class Observer;                             
00183 typedef std::vector <Observer *> ObserverVector;
00184 
00194 
00195 class Model {
00196 public:
00197     Model() : mHasObservers(false), mHasObserverMap(false), mUpdateTime(0), mPeriod(0) { }; 
00198     ~Model() { };                           
00199     
00200     void attachObserver(Observer *);        
00201     void detachObserver(Observer *);
00202     
00203     void changed(void * argument);          
00204 
00205 
00206 
00207     virtual int evaluate(void * argument) { return 0; };
00208     
00209 private:
00210     ObserverVector mObservers;              
00211     std::map<int, ObserverVector> mObsMap;  
00212     bool mHasObservers;                     
00213     bool mHasObserverMap;                   
00214     float mUpdateTime;                      
00215     float mPeriod;                          
00216 };
00217 
00230 
00231 class Observer {
00232 public:
00233     Observer() { mPeriod = 0; mKey = 0; };  
00234     virtual ~Observer() { };                
00235 
00236     float mPeriod;                          
00237     int mKey;                               
00238 
00239     virtual void update(void * arg) = 0;    
00240 };
00241 
00242 } // end of namespace
00243 
00244 #endif

Generated on Sat Oct 17 14:12:30 2009 for CSL by  doxygen 1.4.5-20051010