CSL  6.0
CGestalt.cpp
Go to the documentation of this file.
1 ///
2 /// CGestalt.cpp -- the gestalt class implementation.
3 ///
4 /// The MVC Observer/Subject or dependency pattern classes are also here.
5 //
6 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
7 //
8 
9 #include "CGestalt.h"
10 #include <stdio.h>
11 #include <stdlib.h> // for malloc
12 #include <string.h>
13 #include <math.h>
14 
15 using namespace csl; // this is the namespace, dummy!
16 using namespace std;
17 
18 #ifdef WIN32
19 #include <crtdbg.h>
20 #endif
21 
22 //using namespace juce;
23 
24 ////// These are the system default values //////
25 ///
26 /// The actual start-up values are defined in CSL_Types.h
27 ///
28 
29 static unsigned mNumInChannels = 2; ///< stereo inputs by default
30 static unsigned mNumOutChannels = 2; ///< stereo outputs
31 
32 static unsigned mFrameRate = CSL_mFrameRate; ///< default sample rate (tested up to 96000)
33 static float mFrameRateF = (float) CSL_mFrameRate; ///< default sample rate (tested up to 96000)
34 static csl::sample mFramePeriod = 1.0f / mFrameRateF; ///< 1 / default sample rate
35 static unsigned mBlockSize = CSL_mBlockSize; ///< typical block size (can be as small as 128 in real usage)
36 static unsigned mMaxBufferFrames = CSL_mMaxBufferFrames; ///< max block size (set large for zooming scopes)
37 static unsigned mSndFileFrames = CSL_mSndFileFrames; ///< max block size (set large for zooming scopes)
38 static unsigned mMaxSndFileFrames = CSL_mMaxSndFileFrames; ///< max block size (set large for zooming scopes)
39 
40 static unsigned mVerbosity = CSL_mVerbosity; ///< very verbose
41 static unsigned mLoggingPeriod = CSL_mLoggingPeriod; ///< log CPU every 15 sec
42 static unsigned mOutPort = CSL_mOutPort; ///< RFS output port
43 static string mDataFolder = CSL_DATA_DIR; ///< User's CSL data folder ()
44 static bool mStopNow = false; ///< flag to stop threads and timers
45 
46 static unsigned sScreenWidth; ///< screen width is global (so you can reference it without including this file)
47 static unsigned sScreenHeight; ///< screen height is global
48 
49 /// CGestalt Accessors for system constants
50 
51 unsigned CGestalt::frameRate() { return mFrameRate; }
52 float CGestalt::frameRateF() { return mFrameRateF; }
57 unsigned CGestalt::blockSize() { return mBlockSize; }
60 unsigned CGestalt::verbosity() { return mVerbosity; }
62 unsigned CGestalt::outPort() { return mOutPort; }
63 
64 bool CGestalt::stopNow() { return mStopNow; }
65 
66 unsigned CGestalt::screenWidth() { return sScreenWidth; } ///< current screen width
67 unsigned CGestalt::screenHeight() { return sScreenHeight; } ///< current screen height
68 
69 // handle dataFolder paths relative to "~"
70 
72  if ((mDataFolder.size() > 0) && (mDataFolder[0] == '~')) { // find '~' in folder name
73  string ans(getenv("HOME")); // UNIX code here
74  if (mDataFolder.size() > 1)
75  ans = ans + mDataFolder.substr(1);
76  return ans;
77  } else
78  return mDataFolder; // else answer mDataFolder
79 }
80 
81 void CGestalt::setFrameRate(unsigned sampleRate) {
82  mFrameRate = sampleRate;
83  mFrameRateF = (float) sampleRate;
84  mFramePeriod = 1.0f / mFrameRateF;
85 }
86 
87 // General setters
88 
89 void CGestalt::setMaxBufferFrames(unsigned numFrames) { mMaxBufferFrames = numFrames; }
90 void CGestalt::setMaxSndFileFrames(unsigned numFrames) { mMaxSndFileFrames = numFrames; }
91 void CGestalt::setSndFileFrames(unsigned numFrames) { mSndFileFrames = numFrames; }
92 void CGestalt::setBlockSize(unsigned blockSize) { mBlockSize = blockSize; }
93 void CGestalt::setNumInChannels(unsigned numChannels) { mNumInChannels = numChannels; }
94 void CGestalt::setNumOutChannels(unsigned numChannels) { mNumOutChannels = numChannels; }
95 void CGestalt::setVerbosity(unsigned verb) { mVerbosity = verb; }
96 void CGestalt::setLoggingPeriod(unsigned valInSecs) { mLoggingPeriod = valInSecs; }
97 void CGestalt::setOutPort(unsigned numChannels) { mOutPort = numChannels; }
98 void CGestalt::setDataFolder(std::string dataFolder) { mDataFolder = dataFolder; }
99 
100 void CGestalt::setStopNow() { mStopNow = true; }
101 void CGestalt::clearStopNow() { mStopNow = false; }
102 
103 void CGestalt::setScreenWidth(unsigned numPixels) { sScreenWidth = numPixels; }
104 void CGestalt::setScreenHeight(unsigned numPixels) { sScreenHeight = numPixels; }
105 
106 // get init file name
107 
108 string initFileName() {
109  string nam(CSL_INIT_FILE);
110  if (nam[0] == '~') {
111  string ans(getenv("HOME")); // UNIX code here
112  if (nam.size() > 1)
113  ans = ans + nam.substr(1);
114  return ans;
115  } else
116  return (string(CSL_INIT_FILE));
117 }
118 
119 ///< read/write the init file (typ. ~/.cslrc)
120 /// The reader takes a char key, as in
121 /// string initMsg(CGestalt::initFileText('T'));
122 /// which looks for a line starting with "T " in the file and returns the part after the "T "
123 /// The write function takes a key and a string to store.
124 ///
125 
126 string CGestalt::initFileText(char key) {
127  FILE * inp = fopen(initFileName().c_str(), "r");
128  if ( ! inp)
129  return string("");
130  char init[CSL_LINE_LEN];
131  while ( ! feof(inp)) { // loop through input file
132  if(fgets(init, CSL_LINE_LEN, inp) != NULL) { // Read a line
133  if (init[0] == key) { // if the key matches, return it
134  char * str = &init[2];
135  return string((const char *)str);
136  }
137  }
138  }
139  fclose(inp);
140  return string("");
141 }
142 
143 // Store a string at a key in the init file
144 
145 void CGestalt::storeToInitFile(char key, string data) {
146 // logMsg("Store init %c -> %s", key, data.c_str());
147  char rcStr[CSL_STR_LEN];
148  char * rcLin = rcStr;
149  char * cr;
150  size_t len;
151  string iNam = initFileName();
152  FILE * inp = fopen(iNam.c_str(), "r+"); // open file
153  if (inp) {
154  len = fread(rcStr, 1, CSL_STR_LEN, inp);// read whole file
155  rewind(inp); // seek back to start
156  } else { // if file not there
157  inp = fopen(iNam.c_str(), "w");
158  len = 0;
159  }
160  fprintf(inp, "%c %s\n", key, data.c_str()); // write key line
161  while (rcLin < (rcStr + len)) {
162  cr = strchr(rcLin, '\n'); // find CR
163  if (cr)
164  *cr = 0; // set it to 0
165  if (rcLin[0] != key) // copy non-matching lines
166  fprintf(inp, "%s", rcLin);
167  if (cr)
168  rcLin = cr + 1;
169  else
170  rcLin += strlen(rcLin);
171  }
172  fclose(inp);
173 }
174 
175 // Handle file recording and output
176 
177 #define cheapPrintf(val) \
178  if (val < 10) \
179  *xpos = '0'; \
180  else \
181  *xpos = '0' + (val / 10); \
182  *(xpos+1) = '0' + (val % 10)
183 
184 // create a new temp file name
185 
187  char fsnam[CSL_NAME_LEN]; // temp file name
188  FILE * dFile = NULL; // temp file ptr
189  // create out file name
190  sprintf(fsnam, "%s%s", CGestalt::dataFolder().c_str(), OUT_SFILE_NAME);
191  char * xpos = strstr(fsnam, "XX"); // find XX in the template
192  int cnt = 0;
193  if (xpos) { // if found, replace it with a number
194  do {
195  cheapPrintf(cnt); // pick next file name
196  dFile = fopen(fsnam, "r"); // try to read file
197  if (dFile != NULL) { // if it's there
198  fclose(dFile); // close it and increment counter
199  cnt++;
200  }
201  } while (dFile); // as long as you find files
202  } else {
203  logMsg("Write to file \"%s\" filename not recognized", fsnam);
204  }
205  return string(fsnam);
206 }
207 
208 // Logging functions
209 
210 #pragma mark Logging
211 
212 ///
213 /// Logging code: if verbosity
214 ///
215 
216 // macro to process messasges that start with \n
217 
218 #if 1
219 #define SWALLOW_CR()
220 #else
221 #define SWALLOW_CR() \
222  if (format[0] == '\n') { \
223  fprintf(stderr, "\n"); \
224  format[0] = ' '; \
225  }
226 #endif
227 
228 // Stream-based logging for RoCoCo -- for handling var-args
229 
230 #ifdef RoCoCo
231 extern MemoryOutputStream * gLogStream;
232 #endif
233 
234 void csl::vlogMsg(bool cz, LogLevel level, const char * format, va_list args) {
235  switch (level) {
236  case kLogInfo:
237  if (mVerbosity < 3) return;
238  case kLogWarning:
239  if (mVerbosity < 2) return;
240  case kLogError:
241  if (mVerbosity < 1) return;
242  case kLogFatal: /* no-op */ ;
243  }
244  char message[CSL_LINE_LEN];
245  vsprintf(message, format, args);
246  unsigned len = (unsigned) strlen(message);
247  if (cz)
248  sprintf(message + len++, "\n");
249 #ifdef RoCoCo
250  gLogStream->write(message, len);
251 #endif
252  fprintf(stderr, message);
253  fflush(stderr);
254  if (level == kLogFatal)
255  exit(1);
256 }
257 
258 /*
259 void csl::vlogMsg(bool cz, LogLevel level, const char * format, va_list args) {
260  switch(level) {
261  case kLogInfo:
262  if (mVerbosity < 3) return;
263  SWALLOW_CR()
264  fprintf(stderr, CSL_LOG_PREFIX);
265  break;
266  case kLogWarning:
267  if (mVerbosity < 2) return;
268  SWALLOW_CR()
269  fprintf(stderr, "%s%s", CSL_LOG_PREFIX, "Warning: ");
270  break;
271  case kLogError:
272  if (mVerbosity < 1) return;
273  SWALLOW_CR()
274  fprintf(stderr, "%s%s", CSL_LOG_PREFIX, "Error: ");
275  break;
276  case kLogFatal:
277  SWALLOW_CR()
278  fprintf(stderr, "%s%s", CSL_LOG_PREFIX, "FATAL ERROR: ");
279  break;
280  }
281  vfprintf(stderr, format, args);
282  if (cz)
283  fprintf(stderr, "\n");
284  fflush(stderr);
285  if (level == kLogFatal)
286  exit(1);
287 }
288 */
289 
290 // detailed calls
291 
292 void csl::logMsg(const char * format, ...) {
293  va_list args;
294  va_start(args, format);
295  vlogMsg(true, kLogInfo, format, args);
296  va_end(args);
297 }
298 
299 void csl::logMsgNN(const char * format, ...) {
300  va_list args;
301  va_start(args, format);
302  vlogMsg(false, kLogInfo, format, args);
303  va_end(args);
304 }
305 
306 void csl::logMsg(LogLevel level, const char * format, ...) {
307  va_list args;
308  va_start(args, format);
309  vlogMsg(true, level, format, args);
310  va_end(args);
311 }
312 
313 void csl::logMsgNN(LogLevel level, const char * format, ...) {
314  va_list args;
315  va_start(args, format);
316  vlogMsg(false, level, format, args);
317  va_end(args);
318 }
319 
320 ///< Log the file & line #
321 
322 void csl::logLine() {
323  // ToDo
324 }
325 
326 ///< log file/line as a URL
327 
328 void csl::logURL() {
329  // ToDo
330 }
331 
332 #include <unistd.h> // for usleep
333 
334 //#ifndef WIN32
335 ///
336 /// Global Sleep functions that work for windows and mac/unix.
337 /// Note the use of the global flag gStopNow, which interrupts timers.
338 
339 #pragma mark Misc
340 
341 #define TIMER_INTERVAL 0.25f // loop time in sec to check stopNow flag in sleep timers
342 
343 // sleep for microseconds
344 
345 bool csl::sleepUsec(float dur_in_usec) {
346  if (dur_in_usec <= 0.0) return false;
347  int interval;
348  int periods = (int) ((dur_in_usec / 1000000.0f) / TIMER_INTERVAL);
349  if (periods < 1) {
350  interval = (int) dur_in_usec;
351  periods = 1;
352  } else {
353  interval = (int) (TIMER_INTERVAL * 1000000.0f); // or dur_in_usec / periods;
354  }
355  int count = periods;
356  while (count && ( ! CGestalt::stopNow())) { // timers count short loops of 0.25 sec or so
357  usleep(interval); // micro-sleep
358  count--;
359  } // check global flag in timer loop
360  if (CGestalt::stopNow()) return true;
361  if ((interval * periods) < dur_in_usec) // sleep for remainder interval
362  usleep((int)(dur_in_usec - (interval * periods)));
363  if (CGestalt::stopNow()) {
364 // CGestalt::clearStopNow(); // should a timer clear the flag?
365  return true;
366  }
367  return false; // false means AOK termination
368 }
369 
370 // sleep for milliseconds
371 
372 bool csl::sleepMsec(float dur_in_msec) {
373  if (dur_in_msec <= 0.0) return false;
374  return sleepUsec(dur_in_msec * 1000.0f);
375 }
376 
377 // sleep for seconds
378 
379 bool csl::sleepSec(float dur_in_sec) {
380  if (dur_in_sec <= 0.0) return false;
381  return sleepUsec(dur_in_sec * 1000000.0f);
382 }
383 
384 // current system or IO time in ticks
385 
387 #ifdef USE_JUCE
388  return juce::Time::getHighResolutionTicks();
389 #else
390  struct timeval tv;
391  gettimeofday(&tv, NULL);
392  return ((Timestamp) tv.tv_sec * 1000) + ((Timestamp) tv.tv_usec / 1000);
393 #endif
394 }
395 
396 // current system or IO time in seconds
397 
398 float csl::fTimeNow() {
399 #ifdef USE_JUCE
400  return (float) juce::Time::highResolutionTicksToSeconds(juce::Time::getHighResolutionTicks());
401 #else
402  struct timeval tv;
403  gettimeofday(&tv, NULL);
404  return (float) tv.tv_sec + ((float) tv.tv_usec / 1000000.0f);
405 #endif
406 }
407 
408 //#endif
409 
410 //// Randoms
411 
412 // Answer a random as a float in the range 0 - 1
413 
414 float csl::fRandZ(void) {
415  return((float) rand() / (float) RAND_MAX);
416 }
417 
418 // Answer a random as a float in the range -1 - +1
419 
420 float csl::fRand1(void) {
421  return ((csl::fRandZ() * 2.0f) - 1.0f);
422 }
423 
424 // Answer a random as a float in the range min - max
425 
426 float csl::fRandM(float minV, float maxV) {
427  return (minV + (fRandZ() * (maxV - minV)));
428 }
429 
430 // Answer a random as a float in the range base +- (range * base)
431 
432 float csl::fRandR(float base, float range) {
433  return (base + (fRandZ() * range * base));
434 }
435 
436 // Answer a random as a float in the range base +- range
437 
438 float csl::fRandB(float base, float range) {
439  return (base + (fRand1() * range));
440 }
441 
442 // Answer a random as a float in the range 0 - val
443 
444 float csl::fRandV(float val) {
445  return (csl::fRandZ() * val);
446 }
447 
448 // Integer float fcns
449 
450 // Answer a random as an int in the range 0 - val
451 
452 int csl::iRandV(int val) {
453  return (int)fRandV((float) val);
454 }
455 
456 // Answer a random as an int in the range min - max
457 
458 int csl::iRandM(int minV, int maxV) {
459  return (int)fRandM((float) minV, (float) maxV);
460 }
461 
462 // Answer a random as an int in the range base +- range
463 
464 int csl::iRandB(int base, int range) {
465  return (int)fRandB((float) base, (float) range);
466 }
467 
468 // Answer true or false
469 
470 bool csl::coin() {
471  return (csl::fRandZ() > 0.5f);
472 }
473 
474 // Answer true or false with a bias (1 = always true)
475 
476 bool csl::coin(float bias) {
477  return (csl::fRandZ() < bias);
478 }
479 
480 /// keyToFreq -- converts from MIDI key numbers (1 - 127) to frequency in Hz.
481 // 8.17579891564371 Hz is a very low C = MIDI note 0
482 
483 float csl::keyToFreq(unsigned midiKey) {
484  return (8.17579891564371f * powf(2.0f, (midiKey / 12.0f)));
485 }
486 
487 /// freqToKey -- converts from frequency in Hz to MIDI key #
488 /// 8.17579891564371 Hz is MIDI key 0
489 
490 unsigned csl::freqToKey(float frequency) {
491  return (unsigned) (12.0f * log2f(frequency / 8.17579891564371f));
492 }
493 
494 //
495 // MVC Observable pattern implementations
496 //
497 
498 #pragma mark MVC
499 
500 // attach/remove observers from models
501 
503  mObservers.push_back(o);
504  mHasObservers = true;
505 // mUpdateTime = fTimeNow();
506  if (o->mPeriod != 0) { // if the observer has an update period
507  mPeriod = o->mPeriod;
508  }
509  if (o->mKey != 0) { // if the observer has an update filter key
510  mHasObserverMap = true;
511  mObsMap[o->mKey].push_back(o);
512  }
513 #ifdef CSL_DEBUG
514  logMsg("Model::attachObserver %x", o);
515 #endif
516 }
517 
519  unsigned count = mObservers.size();
520  int i;
521  for (i = 0; i < count; i++)
522  if (mObservers[i] == o)
523  break;
524  if (i < count)
525  mObservers.erase(mObservers.begin() + i);
526  if (mObservers.size() == 0)
527  mHasObservers = false;
528 // if (o->mKey != 0) { // if the observer has an update filter key
529 // mObsMap[o->mKey].delete(o);
530 // }
531 #ifdef CSL_DEBUG
532  logMsg("Model::detachObserver");
533 #endif
534 }
535 
536 // This is the (simple) body of the main notification method;
537 // send this->changed(* any_object) from within model messages
538 // that want to trigger the observers
539 
540 void Model::changed(void * argument) {
541  if ( ! mHasObservers) // speed hack
542  return;
543  ObserverVector::iterator pos; // iterate over my observers
544 #ifdef CSL_DEBUG
545  logMsg("Model::update %d", mObservers.size());
546 #endif
547  //float nowt = fTimeNow();
548  //if (nowt > (mUpdateTime + mPeriod)) {
549  //mUpdateTime = nowt;
550  if (mHasObserverMap) {
551  int key = this->evaluate(argument);
552  ObserverVector obs = mObsMap[key];
553  for (pos = obs.begin(); pos != obs.end(); ++pos)
554  (* pos)->update(argument);
555  } else {
556  for (pos = mObservers.begin(); pos != mObservers.end(); ++pos)
557  (* pos)->update(argument);
558  }
559  //}
560 }
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
static unsigned verbosity()
the default logging verbosity
Definition: CGestalt.cpp:60
float fRandV(float val)
0 - v (val)
Definition: CGestalt.cpp:444
static void setMaxSndFileFrames(unsigned numFrames)
Definition: CGestalt.cpp:90
static std::string initFileText(char key)
read/write the init file (typ. ~/.cslrc)
Definition: CGestalt.cpp:126
static void setMaxBufferFrames(unsigned numFrames)
Definition: CGestalt.cpp:89
#define CSL_mSndFileFrames
default file cache size = 20 MFrames (~ 2 min)
Definition: CSL_Types.h:101
static unsigned mFrameRate
default sample rate (tested up to 96000)
Definition: CGestalt.cpp:32
bool sleepMsec(float dur)
Definition: CGestalt.cpp:372
static unsigned screenWidth()
current screen width
Definition: CGestalt.cpp:66
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
static void setScreenWidth(unsigned numPixels)
Definition: CGestalt.cpp:103
static unsigned sndFileFrames()
the default num frames that are cached
Definition: CGestalt.cpp:55
static std::string sndFileName()
pick a new sound file name to use based on OUT_SFILE_NAME
Definition: CGestalt.cpp:186
static void storeToInitFile(char key, std::string data)
Definition: CGestalt.cpp:145
static unsigned maxSndFileFrames()
the max num frames that can be cached
Definition: CGestalt.cpp:56
CSL Observer/Dependent/Monitor class – instances receive update() messages from "models" and handle ...
Definition: CGestalt.h:296
#define CSL_mVerbosity
very verbose logging
Definition: CSL_Types.h:110
static bool mStopNow
flag to stop threads and timers
Definition: CGestalt.cpp:44
#define cheapPrintf(val)
Definition: CGestalt.cpp:177
static unsigned mOutPort
RFS output port.
Definition: CGestalt.cpp:42
static unsigned numOutChannels()
default number of output channels
Definition: CGestalt.cpp:59
static bool stopNow()
flag to stop threads and timers
Definition: CGestalt.cpp:64
static unsigned loggingPeriod()
the default logging period
Definition: CGestalt.cpp:61
static unsigned maxBufferFrames()
the max num frames that can be requested
Definition: CGestalt.cpp:54
unsigned long Timestamp
Timestamp type: we assume that we can get the host's best guess at the IO word clock (normally passed...
Definition: CSL_Types.h:261
static sample framePeriod()
default frame rate
Definition: CGestalt.cpp:53
void logURL()
log file/line as a URL
Definition: CGestalt.cpp:328
static unsigned screenHeight()
current screen height
Definition: CGestalt.cpp:67
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
Definition: CGestalt.cpp:540
static void setNumOutChannels(unsigned numChannels)
Definition: CGestalt.cpp:94
float keyToFreq(unsigned midiKey)
MIDI Conversions.
Definition: CGestalt.cpp:483
static unsigned mBlockSize
typical block size (can be as small as 128 in real usage)
Definition: CGestalt.cpp:35
static float frameRateF()
default frame rate as a float
Definition: CGestalt.cpp:52
static void setNumInChannels(unsigned numChannels)
Definition: CGestalt.cpp:93
#define CSL_mFrameRate
default sample rate (tested up to 96000)
Definition: CSL_Types.h:91
#define CSL_mMaxSndFileFrames
max file cache size = 64 MB (set to a large value)
Definition: CSL_Types.h:102
static void clearStopNow()
Definition: CGestalt.cpp:101
#define CSL_mLoggingPeriod
log CPU usage every N sec
Definition: CSL_Types.h:111
static unsigned sScreenHeight
screen height is global
Definition: CGestalt.cpp:47
static unsigned mSndFileFrames
max block size (set large for zooming scopes)
Definition: CGestalt.cpp:37
#define CSL_NAME_LEN
default string length
Definition: CSL_Types.h:121
static unsigned blockSize()
the default block size
Definition: CGestalt.cpp:57
bool coin()
Answer true or false.
Definition: CGestalt.cpp:470
#define CSL_mMaxBufferFrames
max block size (set large for zooming scopes)
Definition: CSL_Types.h:100
float mPeriod
virtual destructor (don't notify or delete observers in this version)
Definition: CGestalt.h:299
#define CSL_LINE_LEN
default line length
Definition: CSL_Types.h:122
float fRandM(float minV, float maxV)
min - max (min/max)
Definition: CGestalt.cpp:426
#define TIMER_INTERVAL
Global Sleep functions that work for windows and mac/unix. Note the use of the global flag gStopNow...
Definition: CGestalt.cpp:341
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
static void setLoggingPeriod(unsigned loggingPeriod)
Definition: CGestalt.cpp:96
float fRandB(float base, float range)
b +- r (base)
Definition: CGestalt.cpp:438
static unsigned sScreenWidth
screen width is global (so you can reference it without including this file)
Definition: CGestalt.cpp:46
static unsigned frameRate()
default frame rate
Definition: CGestalt.cpp:51
static void setBlockSize(unsigned blockSize)
Definition: CGestalt.cpp:92
LogLevel
Logging functions are standard C functions.
Definition: CGestalt.h:154
string initFileName()
read/write the init file (typ. ~/.cslrc) The reader takes a char key, as in string initMsg(CGestalt::...
Definition: CGestalt.cpp:108
unsigned freqToKey(float frequency)
freqToKey – converts from frequency in Hz to MIDI key #
Definition: CGestalt.cpp:490
static unsigned numInChannels()
default number of input channels
Definition: CGestalt.cpp:58
static string mDataFolder
User's CSL data folder ()
Definition: CGestalt.cpp:43
int iRandV(int val)
Integer rands.
Definition: CGestalt.cpp:452
void vlogMsg(bool cz, LogLevel level, const char *format, va_list args)
Definition: CGestalt.cpp:234
static void setSndFileFrames(unsigned numFrames)
Definition: CGestalt.cpp:91
static void setFrameRate(unsigned frameRate)
Definition: CGestalt.cpp:81
bool sleepSec(float dur)
Definition: CGestalt.cpp:379
static unsigned len
Definition: fft_N.c:39
static csl::sample mFramePeriod
1 / default sample rate
Definition: CGestalt.cpp:34
static unsigned mNumInChannels
The actual start-up values are defined in CSL_Types.h.
Definition: CGestalt.cpp:29
int iRandM(int minV, int maxV)
min - max (min/max)
Definition: CGestalt.cpp:458
static void setVerbosity(unsigned verbosity)
Definition: CGestalt.cpp:95
static float mFrameRateF
default sample rate (tested up to 96000)
Definition: CGestalt.cpp:33
void detachObserver(Observer *)
Definition: CGestalt.cpp:518
float fRandZ(void)
A variety of useful random-number functions.
Definition: CGestalt.cpp:414
void attachObserver(Observer *)
(possibly notify obersvers on my death)
Definition: CGestalt.cpp:502
#define CSL_STR_LEN
default long string length
Definition: CSL_Types.h:123
int mKey
key selector (e.g., MIDI chan) I receive update() mesages from my model;
Definition: CGestalt.h:302
static void setScreenHeight(unsigned numPixels)
Definition: CGestalt.cpp:104
float fTimeNow()
system or IO time in seconds
Definition: CGestalt.cpp:398
void logMsgNN(const char *format,...)
no-newline versions
Definition: CGestalt.cpp:299
bool sleepUsec(float dur)
Misc. global functions in the csl namespace.
Definition: CGestalt.cpp:345
#define CSL_mOutPort
RFS output port.
Definition: CSL_Types.h:116
static unsigned mVerbosity
very verbose
Definition: CGestalt.cpp:40
#define CSL_INIT_FILE
where to store the CSL init file
Definition: CSL_Types.h:136
std::vector< Observer * > ObserverVector
Forward declaration.
Definition: CGestalt.h:245
Enumeration for log message severity level.
Definition: CGestalt.h:155
static unsigned outPort()
the default RemoteIO output port
Definition: CGestalt.cpp:62
float fRand1(void)
-1 - 1 (one)
Definition: CGestalt.cpp:420
static void setStopNow()
Definition: CGestalt.cpp:100
int iRandB(int base, int range)
b +- r (base)
Definition: CGestalt.cpp:464
static unsigned mMaxBufferFrames
max block size (set large for zooming scopes)
Definition: CGestalt.cpp:36
static unsigned mLoggingPeriod
log CPU every 15 sec
Definition: CGestalt.cpp:41
Timestamp timeNow()
high-accuracy system or IO time in ticks
Definition: CGestalt.cpp:386
#define CSL_DATA_DIR
folder where the CSL data can be found
Definition: CSL_Types.h:135
static unsigned mNumOutChannels
stereo outputs
Definition: CGestalt.cpp:30
#define CSL_mBlockSize
normal hosts
Definition: CSL_Types.h:99
float fRandR(float base, float range)
b +- (r * b) (range)
Definition: CGestalt.cpp:432
#define OUT_SFILE_NAME
csl output file name temlpate
Definition: CSL_Types.h:126
static void setDataFolder(std::string dFolder)
typ. "~/Code/CSL/CSL_Data/"
Definition: CGestalt.cpp:98
static unsigned mMaxSndFileFrames
max block size (set large for zooming scopes)
Definition: CGestalt.cpp:38
void logLine()
Log the file & line #.
Definition: CGestalt.cpp:322
static std::string dataFolder()
the default directory for test data
Definition: CGestalt.cpp:71
static void setOutPort(unsigned outPort)
Definition: CGestalt.cpp:97