47 #define WRITE_TO_FILE // support file recording
59 if (thr->isThreadRunning())
62 if (this->threadShouldExit())
64 if ( ! thr->isThreadRunning()) {
70 thr->signalThreadShouldExit();
72 comp->playing =
false;
73 const juce::MessageManagerLock mmLock;
74 if (comp->isTimerRunning())
91 playThread(0), loopThread(0), amplValue(1.0f),
92 loop(false), recrding(false), playing(false), displayMode(true), changed(false) {
107 CGestalt::numOutChannels(),
110 if (
error.isNotEmpty())
111 juce::AlertWindow::showMessageBox (juce::AlertWindow::WarningIcon,
113 "Couldn't open an output device!\n\n" +
error);
119 #ifdef READ_IO_PROPS // overwrite the system frame rate and block size from the
121 theIO =
new csl::IO(sRate, bufSize, -1, -1,
122 CGestalt::numInChannels(), CGestalt::numOutChannels());
123 #else // reset the HW frame rate & block size to the CSL definition
124 juce::AudioDeviceManager::AudioDeviceSetup setup;
126 setup.bufferSize = CGestalt::blockSize();
127 setup.sampleRate = CGestalt::frameRate();
130 theIO =
new csl::IO(CGestalt::frameRate(), CGestalt::blockSize(), -1, -1,
131 CGestalt::numInChannels(), CGestalt::numOutChannels());
169 int totalNumInputChannels,
170 float** outputChannelData,
171 int totalNumOutputChannels,
174 for (
unsigned i = 0; i < totalNumOutputChannels; i++)
175 memset(outputChannelData[i], 0, numSamples *
sizeof(
float));
179 if (CGestalt::stopNow())
185 for (
unsigned i = 0; i < totalNumOutputChannels; i++)
193 for (
unsigned i = 0; i < totalNumInputChannels; i++)
201 for (
unsigned i = 0; i < totalNumOutputChannels; i++) {
202 float * sampPtr = outputChannelData[i];
204 for (
unsigned j = 0; j < numSamples; j++)
214 memcpy(sPtr, outputChannelData[0], (numSamples *
sizeof(
csl::sample)));
216 memcpy(sPtr, outputChannelData[1], (numSamples *
sizeof(
csl::sample)));
235 string outName = CGestalt::sndFileName();
237 logMsg(
"Write %5.3f sec (%d ksamp) to file \"%s\"\n",
239 SoundFile * ioFile =
new SoundFile(outName);
241 ioFile->writeBuffer(*gFileBuffer);
245 if ( ! gFileBuffer) {
271 const juce::MessageManagerLock mmLock;
274 juce::String msgS(msg);
275 gCPULabel->setText(msgS, juce::sendNotification);
283 CGestalt::clearStopNow();
292 this->startTimer(1000);
297 CGestalt::setStopNow();
308 CGestalt::clearStopNow();
326 addAndMakeVisible (
playButton =
new juce::TextButton (
"playNote"));
330 addAndMakeVisible (
quitButton =
new juce::TextButton (
"quitAction"));
334 addAndMakeVisible (
prefsButton =
new juce::TextButton (
"new button"));
338 addAndMakeVisible (
cpuLabel =
new juce::Label(
"new label",
"0.0%"));
339 cpuLabel->setFont (juce::Font (juce::Font::getDefaultSansSerifFontName(), 15.0000f, juce::Font::bold));
340 cpuLabel->setJustificationType (juce::Justification::centredRight);
341 cpuLabel->setEditable (
false,
false,
false);
342 cpuLabel->setColour (juce::TextEditor::textColourId, juce::Colours::black);
343 cpuLabel->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x0));
346 VUMeterL->setName (
"new component");
349 VUMeterR->setName (
"new component");
354 amplitudeSlider->setTextBoxStyle (juce::Slider::NoTextBox,
true, 80, 20);
357 addAndMakeVisible (
loopButton =
new juce::ToggleButton (
"new toggle button"));
361 addAndMakeVisible (
recordButton =
new juce::ToggleButton (
"new toggle button"));
392 int totalNumInputChannels,
393 float** outputChannelData,
394 int totalNumOutputChannels,
398 outputChannelData, totalNumOutputChannels, numSamples);
402 outputChannelData, totalNumOutputChannels, numSamples);
404 outputChannelData, totalNumOutputChannels, numSamples);
411 playButton->setBounds (336, getHeight() - 39, 136, 32);
412 quitButton->setBounds (getWidth() - 8 - 176, 8, 176, 32);
414 cpuLabel->setBounds (getWidth() - 64, getHeight() - 35, 56, 24);
415 VUMeterL->
setBounds (25, 48, 15, juce::roundFloatToInt ((proportionOfHeight (0.3400f)) * 1.0000f));
416 VUMeterR->
setBounds (24, proportionOfHeight (0.5000f), 15, juce::roundFloatToInt ((proportionOfHeight (0.3400f)) * 1.0000f));
418 loopButton->setBounds ((336) + 144, getHeight() - 11 - 24, 64, 24);
419 recordButton->setBounds ((getWidth() - 8 - 176) + -2 - 72, 37 - 24, 72, 24);
443 juce::JUCEApplication::quit();
469 CGestalt::numInChannels(), CGestalt::numInChannels(),
470 CGestalt::numOutChannels(), CGestalt::numOutChannels(),
474 audioSettingsComp.setSize (500, 400);
475 juce::DialogWindow::showModalDialog (
"Audio Settings",
478 juce::Colours::azure,
void logMsg(const char *format,...)
These are the public logging messages.
juce::TextButton * quitButton
#define kSoundFileFormatAIFF
#define SAMPS_TO_WRITE
record 30 seconds by default
void *(* ThreadFunc)(void *)
This is the CSL_AbstComponent JUCE wrapper for the CSL demos.
juce::ToggleButton * loopButton
unsigned mNumFrames
num frames used in each buffer
void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
bool sleepMsec(float dur)
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
virtual void comboBoxChanged(juce::ComboBox *comboBoxThatHasChanged)
static bool stopNow()
flag to stop threads and timers
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
virtual void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
GThread takes a CSL test function and runs it.
void freeBuffers()
fcn to free them
void setSize(unsigned numChannels, unsigned numFrames)
static void clearStopNow()
juce_UseDebuggingNewOperator juce::AudioDeviceManager mAudioDeviceManager
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
void VoidFcnPtrN(void)
the truly void fcn pointer
float sample
(could be changed to int, or double)
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
virtual void buttonClicked(juce::Button *buttonThatWasClicked)
void setChannel(unsigned channel)
virtual void audioDeviceStopped()
void setBounds(int x, int y, int width, int height)
virtual void sliderValueChanged(juce::Slider *sliderThatWasMoved)
virtual void audioDeviceAboutToStart(juce::AudioIODevice *device)
juce::Slider * amplitudeSlider
juce::AudioDeviceManager * gAudioDeviceManager
juce::ToggleButton * recordButton
virtual void timerCallback()
juce::TextButton * prefsButton
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
void allocateBuffers()
fcn to malloc storage buffers
virtual void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
juce::TextButton * playButton
Buttons, sliders and meters.
void error(int num, const char *m, const char *path)
virtual void startStop(csl::VoidFcnPtrN *fcn)
Base class of CSL exceptions (written upper-case). Has a string message.
virtual void recordOnOff()