73 string ans(getenv(
"HOME"));
111 string ans(getenv(
"HOME"));
113 ans = ans + nam.substr(1);
131 while ( ! feof(inp)) {
133 if (init[0] == key) {
134 char * str = &init[2];
135 return string((
const char *)str);
148 char * rcLin = rcStr;
152 FILE * inp = fopen(iNam.c_str(),
"r+");
157 inp = fopen(iNam.c_str(),
"w");
160 fprintf(inp,
"%c %s\n", key, data.c_str());
161 while (rcLin < (rcStr + len)) {
162 cr = strchr(rcLin,
'\n');
166 fprintf(inp,
"%s", rcLin);
170 rcLin += strlen(rcLin);
177 #define cheapPrintf(val) \
181 *xpos = '0' + (val / 10); \
182 *(xpos+1) = '0' + (val % 10)
191 char * xpos = strstr(fsnam,
"XX");
196 dFile = fopen(fsnam,
"r");
203 logMsg(
"Write to file \"%s\" filename not recognized", fsnam);
205 return string(fsnam);
221 #define SWALLOW_CR() \
222 if (format[0] == '\n') { \
223 fprintf(stderr, "\n"); \
231 extern MemoryOutputStream * gLogStream;
245 vsprintf(message, format, args);
246 unsigned len = (unsigned) strlen(message);
248 sprintf(message + len++,
"\n");
250 gLogStream->write(message, len);
252 fprintf(stderr, message);
294 va_start(args, format);
301 va_start(args, format);
308 va_start(args, format);
309 vlogMsg(
true, level, format, args);
315 va_start(args, format);
316 vlogMsg(
false, level, format, args);
341 #define TIMER_INTERVAL 0.25f // loop time in sec to check stopNow flag in sleep timers
346 if (dur_in_usec <= 0.0)
return false;
348 int periods = (int) ((dur_in_usec / 1000000.0f) /
TIMER_INTERVAL);
350 interval = (int) dur_in_usec;
361 if ((interval * periods) < dur_in_usec)
362 usleep((
int)(dur_in_usec - (interval * periods)));
373 if (dur_in_msec <= 0.0)
return false;
380 if (dur_in_sec <= 0.0)
return false;
381 return sleepUsec(dur_in_sec * 1000000.0f);
388 return juce::Time::getHighResolutionTicks();
391 gettimeofday(&tv, NULL);
400 return (
float) juce::Time::highResolutionTicksToSeconds(juce::Time::getHighResolutionTicks());
403 gettimeofday(&tv, NULL);
404 return (
float) tv.tv_sec + ((float) tv.tv_usec / 1000000.0f);
415 return((
float) rand() / (
float) RAND_MAX);
427 return (minV + (
fRandZ() * (maxV - minV)));
433 return (base + (
fRandZ() * range * base));
439 return (base + (
fRand1() * range));
453 return (
int)
fRandV((
float) val);
459 return (
int)
fRandM((
float) minV, (
float) maxV);
465 return (
int)
fRandB((
float) base, (
float) range);
484 return (8.17579891564371f * powf(2.0f, (midiKey / 12.0f)));
491 return (
unsigned) (12.0f * log2f(frequency / 8.17579891564371f));
503 mObservers.push_back(o);
504 mHasObservers =
true;
510 mHasObserverMap =
true;
511 mObsMap[o->
mKey].push_back(o);
514 logMsg(
"Model::attachObserver %x", o);
519 unsigned count = mObservers.size();
521 for (i = 0; i < count; i++)
522 if (mObservers[i] == o)
525 mObservers.erase(mObservers.begin() + i);
526 if (mObservers.size() == 0)
527 mHasObservers =
false;
532 logMsg(
"Model::detachObserver");
541 if ( ! mHasObservers)
543 ObserverVector::iterator pos;
545 logMsg(
"Model::update %d", mObservers.size());
550 if (mHasObserverMap) {
551 int key = this->evaluate(argument);
553 for (pos = obs.begin(); pos != obs.end(); ++pos)
554 (* pos)->update(argument);
556 for (pos = mObservers.begin(); pos != mObservers.end(); ++pos)
557 (* pos)->update(argument);
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)
static void setMaxBufferFrames(unsigned numFrames)
#define CSL_mSndFileFrames
default file cache size = 20 MFrames (~ 2 min)
static unsigned mFrameRate
default sample rate (tested up to 96000)
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)
static unsigned maxSndFileFrames()
the max num frames that can be cached
CSL Observer/Dependent/Monitor class – instances receive update() messages from "models" and handle ...
#define CSL_mVerbosity
very verbose logging
static bool mStopNow
flag to stop threads and timers
static unsigned mOutPort
RFS output port.
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
static void setNumOutChannels(unsigned numChannels)
float keyToFreq(unsigned midiKey)
MIDI Conversions.
static unsigned mBlockSize
typical block size (can be as small as 128 in real usage)
static float frameRateF()
default frame rate as a float
static void setNumInChannels(unsigned numChannels)
#define CSL_mFrameRate
default sample rate (tested up to 96000)
#define CSL_mMaxSndFileFrames
max file cache size = 64 MB (set to a large value)
static void clearStopNow()
#define CSL_mLoggingPeriod
log CPU usage every N sec
static unsigned sScreenHeight
screen height is global
static unsigned mSndFileFrames
max block size (set large for zooming scopes)
#define CSL_NAME_LEN
default string length
static unsigned blockSize()
the default block size
bool coin()
Answer true or false.
#define CSL_mMaxBufferFrames
max block size (set large for zooming scopes)
float mPeriod
virtual destructor (don't notify or delete observers in this version)
#define CSL_LINE_LEN
default line length
float fRandM(float minV, float maxV)
min - max (min/max)
#define TIMER_INTERVAL
Global Sleep functions that work for windows and mac/unix. Note the use of the global flag gStopNow...
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 sScreenWidth
screen width is global (so you can reference it without including this file)
static unsigned frameRate()
default frame rate
static void setBlockSize(unsigned blockSize)
LogLevel
Logging functions are standard C functions.
string initFileName()
read/write the init file (typ. ~/.cslrc) The reader takes a char key, as in string initMsg(CGestalt::...
unsigned freqToKey(float frequency)
freqToKey – converts from frequency in Hz to MIDI key #
static unsigned numInChannels()
default number of input channels
static string mDataFolder
User's CSL data folder ()
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)
static csl::sample mFramePeriod
1 / default sample rate
static unsigned mNumInChannels
The actual start-up values are defined in CSL_Types.h.
int iRandM(int minV, int maxV)
min - max (min/max)
static void setVerbosity(unsigned verbosity)
static float mFrameRateF
default sample rate (tested up to 96000)
void detachObserver(Observer *)
float fRandZ(void)
A variety of useful random-number functions.
void attachObserver(Observer *)
(possibly notify obersvers on my death)
#define CSL_STR_LEN
default long string length
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.
#define CSL_mOutPort
RFS output port.
static unsigned mVerbosity
very verbose
#define CSL_INIT_FILE
where to store the CSL init file
std::vector< Observer * > ObserverVector
Forward declaration.
Enumeration for log message severity level.
static unsigned outPort()
the default RemoteIO output port
float fRand1(void)
-1 - 1 (one)
int iRandB(int base, int range)
b +- r (base)
static unsigned mMaxBufferFrames
max block size (set large for zooming scopes)
static unsigned mLoggingPeriod
log CPU every 15 sec
Timestamp timeNow()
high-accuracy system or IO time in ticks
#define CSL_DATA_DIR
folder where the CSL data can be found
static unsigned mNumOutChannels
stereo outputs
#define CSL_mBlockSize
normal hosts
float fRandR(float base, float range)
b +- (r * b) (range)
#define OUT_SFILE_NAME
csl output file name temlpate
static void setDataFolder(std::string dFolder)
typ. "~/Code/CSL/CSL_Data/"
static unsigned mMaxSndFileFrames
max block size (set large for zooming scopes)
void logLine()
Log the file & line #.
static std::string dataFolder()
the default directory for test data
static void setOutPort(unsigned outPort)