26 #include "JuceHeader.h"
103 #define SAFE_MALLOC(ptr, type, len) \
104 ptr = new type[len]; \
105 if ((char *) ptr == NULL) \
106 throw MemoryError("can't allocate buffer")
112 #define SAFE_MATMALLOC(ptr, mtype, num, type, len) \
113 ptr = new mtype[num]; \
114 if ((char *) ptr == NULL) \
115 throw MemoryError("can't allocate buffer"); \
116 for (unsigned i = 0; i < num; i++) { \
117 ptr[i] = new type[len]; \
118 if ((char *) ptr[i] == NULL) \
119 throw MemoryError("can't allocate buffer"); \
125 #define SAFE_STRUCTMALLOC(ptr, mtype, num, type) \
126 ptr = new mtype[num]; \
127 if ((char *) ptr == NULL) \
128 throw MemoryError("can't allocate buffer"); \
129 for (unsigned i = 0; i < num; i++) { \
131 if ((char *) ptr[i] == NULL) \
132 throw MemoryError("can't allocate buffer"); \
137 #define SAFE_FREE(ptr) \
141 #define SAFE_MATFREE(ptr, num) \
142 for (unsigned i = 0; i < num; i++) { \
162 #define kLogWarning 1
172 void logMsg(
const char * format, ...);
173 void logMsg(LogLevel level,
const char* format, ...);
175 void logMsgNN(
const char * format, ...);
176 void logMsgNN(LogLevel level,
const char* format, ...);
181 void vlogMsg(
bool cz, LogLevel level,
const char * format, va_list args);
202 #define C_TIME juce::Time::getMillisecondCounter()
212 float fRandM(
float minV,
float maxV);
213 float fRandR(
float base,
float range);
214 float fRandB(
float base,
float range);
219 int iRandM(
int minV,
int maxV);
220 int iRandB(
int base,
int range);
225 bool coin(
float bias);
270 virtual int evaluate(
void * argument) {
return 0; };
304 virtual void update(
void * arg) = 0;
void logMsg(const char *format,...)
These are the public logging messages.
static unsigned verbosity()
the default logging verbosity
float fRandV(float val)
0 - v (val)
static void setMaxSndFileFrames(unsigned numFrames)
static std::string initFileText(char key)
read/write the init file (typ. ~/.cslrc)
The Model/Observable/Subject class; instances of its subclasses should send themselves, this->changed(some_data); on "relevant" state changes; the code they inherit (from Model) manages updating the list of observer/dependent objects in that they each receive update(some_data); and can access the model-passed data (the model might pass "this").
static void setMaxBufferFrames(unsigned numFrames)
bool sleepMsec(float dur)
static unsigned screenWidth()
current screen width
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
static void setScreenWidth(unsigned numPixels)
static unsigned sndFileFrames()
the default num frames that are cached
static std::string sndFileName()
pick a new sound file name to use based on OUT_SFILE_NAME
static void storeToInitFile(char key, std::string data)
ObserverVector mObservers
the private vector of observers
virtual void update(void *arg)=0
this will be implemented in subclasses.
static unsigned maxSndFileFrames()
the max num frames that can be cached
CSL Observer/Dependent/Monitor class – instances receive update() messages from "models" and handle ...
bool mHasObserverMap
whether there are any observers (for fast checking)
static unsigned numOutChannels()
default number of output channels
static bool stopNow()
flag to stop threads and timers
static unsigned loggingPeriod()
the default logging period
static unsigned maxBufferFrames()
the max num frames that can be requested
unsigned long Timestamp
Timestamp type: we assume that we can get the host's best guess at the IO word clock (normally passed...
static sample framePeriod()
default frame rate
void logURL()
log file/line as a URL
static unsigned screenHeight()
current screen height
void changed(void *argument)
this is what I send to myself to notify my observers; It's not overridden in general. It results in the observers receiving update() calls < override evaluate to filter updates to the observer map
bool mHasObservers
whether there are any observers (for fast checking)
static void setNumOutChannels(unsigned numChannels)
float keyToFreq(unsigned midiKey)
MIDI Conversions.
static float frameRateF()
default frame rate as a float
The CSL system defaults class.
static void setNumInChannels(unsigned numChannels)
static void clearStopNow()
static unsigned blockSize()
the default block size
bool coin()
Answer true or false.
std::map< int, ObserverVector > mObsMap
the private map-by-key of observers
float mPeriod
virtual destructor (don't notify or delete observers in this version)
virtual ~Model()
constructor
float fRandM(float minV, float maxV)
min - max (min/max)
virtual int evaluate(void *argument)
float sample
(could be changed to int, or double)
static void setLoggingPeriod(unsigned loggingPeriod)
float fRandB(float base, float range)
b +- r (base)
static unsigned frameRate()
default frame rate
static void setBlockSize(unsigned blockSize)
LogLevel
Logging functions are standard C functions.
unsigned freqToKey(float frequency)
freqToKey – converts from frequency in Hz to MIDI key #
static unsigned numInChannels()
default number of input channels
float mUpdateTime
when I last updated
int iRandV(int val)
Integer rands.
void vlogMsg(bool cz, LogLevel level, const char *format, va_list args)
static void setSndFileFrames(unsigned numFrames)
static void setFrameRate(unsigned frameRate)
int iRandM(int minV, int maxV)
min - max (min/max)
static void setVerbosity(unsigned verbosity)
void detachObserver(Observer *)
float fRandZ(void)
A variety of useful random-number functions.
void attachObserver(Observer *)
(possibly notify obersvers on my death)
int mKey
key selector (e.g., MIDI chan) I receive update() mesages from my model;
static void setScreenHeight(unsigned numPixels)
float fTimeNow()
system or IO time in seconds
void logMsgNN(const char *format,...)
no-newline versions
bool sleepUsec(float dur)
Misc. global functions in the csl namespace.
std::vector< Observer * > ObserverVector
Forward declaration.
float mPeriod
update rate in sec
Enumeration for log message severity level.
static unsigned outPort()
the default RemoteIO output port
virtual ~Observer()
constructor
float fRand1(void)
-1 - 1 (one)
int iRandB(int base, int range)
b +- r (base)
Timestamp timeNow()
high-accuracy system or IO time in ticks
float fRandR(float base, float range)
b +- (r * b) (range)
static void setDataFolder(std::string dFolder)
typ. "~/Code/CSL/CSL_Data/"
void logLine()
Log the file & line #.
static std::string dataFolder()
the default directory for test data
static void setOutPort(unsigned outPort)