FFTSenderUGenInternal::FFTSenderUGenInternal(UGen const& input, FFTEngine::FFTModes mode, FFTEngine const& fft, const int overlap, const int firstBin, const int numBins) throw() : UGenInternal(NumInputs), mode_(mode), fftEngine(fft), fftSize(fftEngine.size()), fftSizeHalved(fftSize / 2), overlap_(overlap < 1 ? 1 : overlap), firstBin_(firstBin < fftSizeHalved ? firstBin : fftSizeHalved), maxNumBins(fftSizeHalved - firstBin_ + 1), numBins_(numBins ? (numBins < maxNumBins ? numBins : maxNumBins) : maxNumBins), inputBuffer(Buffer::newClear(fftSize, input.getNumChannels(), true)), outputBuffer(Buffer::newClear(fftSize, input.getNumChannels(), true)), bufferIndex(0) { ugen_assert(overlap == overlap_); // should be > 0 ugen_assert(firstBin == firstBin_); // should be in range // ugen_assert(numBins == numBins_); // should be in range inputs[Input] = input; }
LoopPointsUGenInternal::LoopPointsUGenInternal(Buffer const& buffer, UGen const& rate, UGen const& start, UGen const& end, UGen const& loop, UGen const& startAtZero, UGen const& playToEnd, const UGen::DoneAction doneAction, MetaData const& metaDataToUse) throw() : UGenInternal(NumInputs), b(buffer), currentValue((startAtZero.getValue() >= 0.5f) ? 0.f : start.getValue() * b.size()), lastLoop(false), doneAction_(doneAction), shouldDeleteValue(doneAction_ == UGen::DeleteWhenDone), metaData(metaDataToUse), prevValue((rate.getValue() >= 0.f) ? currentValue - 1.f : b.size()) { inputs[Rate] = rate; inputs[Start] = start; inputs[End] = end; inputs[Loop] = loop; inputs[StartAtZero] = startAtZero; inputs[PlayToEnd] = playToEnd; }
BEGIN_UGEN_NAMESPACE #include "ugen_DiskOut.h" #include "../ugen_JuceUtility.h" DiskOutUGenInternal::DiskOutUGenInternal(File const& file, UGen const& input, bool overwriteExisitingFile, int bitDepth) throw() : ProxyOwnerUGenInternal(NumInputs, input.getNumChannels()-1), audioFormatWriter(0), bufferData(0), numInputChannels(input.getNumChannels()) { ugen_assert(bitDepth >= 16); inputs[Input] = input; bufferData = new float*[numInputChannels]; memset(bufferData, 0, numInputChannels * sizeof(float*)); File outputFile(file); if(outputFile.getFileExtension().isEmpty()) outputFile = outputFile.withFileExtension("wav"); if(overwriteExisitingFile == true && outputFile.exists()) outputFile.deleteFile(); else if(outputFile.exists()) { ugen_assertfalse; return; } if(outputFile.hasFileExtension(".wav")) { WavAudioFormat wavAudioFormat; FileOutputStream* fileOutputStream = outputFile.createOutputStream(); if(fileOutputStream) audioFormatWriter = wavAudioFormat.createWriterFor(fileOutputStream, UGen::getSampleRate(), numInputChannels, bitDepth, 0, 0); } else if(outputFile.hasFileExtension(".aif") || outputFile.hasFileExtension(".aiff")) { AiffAudioFormat aiffAudioFormat; FileOutputStream* fileOutputStream = outputFile.createOutputStream(); if(fileOutputStream) audioFormatWriter = aiffAudioFormat.createWriterFor(fileOutputStream, UGen::getSampleRate(), numInputChannels, bitDepth, 0, 0); } }
void draw() { ofFill(); ofSetColor(255, amp.getValue() * 255); ofCircle(pos.x, pos.y, amp.getValue() * 100); ofNoFill(); ofSetColor(255); ofCircle(pos.x, pos.y, amp.getValue() * 80); }
BufferSenderUGenInternal::BufferSenderUGenInternal(UGen const& input, UGen const& duration) throw() : UGenInternal(NumInputs), audioBuffer(Buffer::withSize((int)(UGen::getSampleRate()), input.getNumChannels(), true)), bufferIndex(0), audioBufferSizeUsed(0), samplesProcessed(0) { inputs[Input] = input; inputs[Duration] = duration; audioBufferSizeUsed = max(1, (int)(duration.getValue() * UGen::getSampleRate() + 0.5)); }
HPF::HPF(UGen const& input, UGen const& freq) throw() { int numChannels = 1; numChannels = input.getNumChannels() > numChannels ? input.getNumChannels() : numChannels; numChannels = freq.getNumChannels() > numChannels ? freq.getNumChannels() : numChannels; initInternal(numChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new HPFUGenInternal(input, freq); } }
BAllPass::BAllPass(UGen const& input, UGen const& freq, UGen const& rq) throw() { UGen inputs[] = { input, freq, rq }; const int numInputChannels = findMaxInputChannels(numElementsInArray(inputs), inputs); initInternal(numInputChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { BEQBaseUGenInternal* filter = new BAllPassUGenInternal(input, freq, rq); filter->calculateCoeffs(freq.getValue(i), rq.getValue(i), 1.f); filter->initValue(input.getValue(i)); internalUGens[i] = filter; } }
MulAdd::MulAdd(UGen const& input, UGen const& mul, UGen const& add) throw() { UGen inputs[] = { input, mul, add }; const int numInputChannels = findMaxInputChannels(numElementsInArray(inputs), inputs); ugen_assert(numInputChannels > 0); initInternal(numInputChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new MulAddUGenInternal(input, mul, add); internalUGens[i]->initValue(input.getValue(i) * mul.getValue(i) + add.getValue(i)); } }
RecordBuf::RecordBuf(UGen const& input, Buffer const& buffer, UGen const& recLevel, UGen const& preLevel, UGen const& loop, const UGen::DoneAction doneAction) throw() { ugen_assert(buffer.size() > 0); ugen_assert(buffer.getNumChannels() > 0); const int numChannels = ugen::max(buffer.getNumChannels(), input.getNumChannels()); initInternal(numChannels); generateFromProxyOwner(new RecordBufUGenInternal(input, buffer, recLevel, preLevel, loop.mix(), doneAction)); }
UGen UGenPlugin::constructGraph(UGen const& input) { UGen wet = getMappedParameterControl(UGenInterface::Parameters::Wet).lag(); UGen dry = getMappedParameterControl(UGenInterface::Parameters::Dry).lag(); plug = Plug::AR(UGen::emptyChannels(getNumOutputChannels())); if(irBuffer.isNull()) plug.setSource(inputUGen); else plug.setSource(getConv()); return (plug * wet.dbamp() + input * dry.dbamp()); }
BHiShelf::BHiShelf(UGen const& input, UGen const& freq, UGen const& rs, UGen const& gain) throw() { UGen inputs[] = { input, freq, rs, gain }; const int numInputChannels = findMaxInputChannels(numElementsInArray(inputs), inputs); initInternal(numInputChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { BEQBaseUGenInternal* filter = new BHiShelfUGenInternal(input, freq, rs, gain); filter->calculateCoeffs(freq.getValue(i), rs.getValue(i), gain.getValue(i)); filter->initValue(input.getValue(i) * gain.getValue(i)); internalUGens[i] = filter; } }
SAH::SAH(UGen const& input, UGen const& trig) throw() { UGen inputs[] = { input, trig }; const int numInputChannels = findMaxInputChannels(numElementsInArray(inputs), inputs); initInternal(numInputChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new SAHUGenInternal(input, trig); if(trig.getValue(i) <= 0.f) internalUGens[i]->initValue(0.f); else internalUGens[i]->initValue(input.getValue(i)); } }
ToggleFF::ToggleFF(UGen const& trig) throw() { initInternal(trig.getNumChannels()); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new ToggleFFUGenInternal(trig); } }
FSinOsc::FSinOsc(UGen const& freq) throw() { initInternal(freq.getNumChannels()); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new FSinOscUGenInternal(freq, 0.f, i); } }
BEGIN_UGEN_NAMESPACE #include "../core/ugen_UGenArray.h" #include "../buffers/ugen_Buffer.h" #include "ugen_UnaryOpUGens.h" UnaryOpUGenInternal::UnaryOpUGenInternal(UGen const& operand, const int channel) throw() : UGenInternal(NumInputs) { if(channel < 0) inputs[Operand] = operand; else { int numChannels = operand.getNumChannels(); UGenInternal* internal = operand.getInternalUGen(channel % numChannels); inputs[Operand] = UGen(internal->getChannelInternal(channel), channel); } }
Correlation::Correlation(UGen const& inputA, UGen const& inputB, const int length, const int initialDelay) throw() { const int lengthChecked = ugen::clip(length, 1, 2044); const int numInputChannels = ugen::max(inputA.getNumChannels(), inputB.getNumChannels()); initInternal(numInputChannels); for(int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new CorrelationUGenInternal(inputA, inputB, lengthChecked, initialDelay); } }
Trig::Trig(UGen const& input) throw() { initInternal(input.getNumChannels()); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new TrigUGenInternal(input); } }
BlockDelay::BlockDelay(UGen const& input) throw() { int numChannels = input.getNumChannels(); initInternal(numChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new BlockDelayUGenInternal(input); } }
SinOsc::SinOsc(UGen const& freq, Buffer const& initialPhase) throw() { int numChannels = ugen::max(freq.getNumChannels(), initialPhase.size()); initInternal(numChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new TableOscUGenInternal(freq, initialPhase.wrapAt(i), Buffer::getTableSine8192()); } }
LagUD::LagUD(UGen const& input, UGen const& lagTimeUp, UGen const& lagTimeDown) throw() { UGen inputs[] = { input, lagTimeUp, lagTimeDown }; const int numInputChannels = findMaxInputChannels(numElementsInArray(inputs), inputs); initInternal(numInputChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new LagUDUGenInternal(input, lagTimeUp, lagTimeDown); internalUGens[i]->initValue(input.getValue(i)); } }
bool VoicerBaseUGenInternal::sendMidiNote(const int midiChannel, const int midiNote, const int velocity) throw() { const int userData = createUserData(midiChannel, midiNote); ugen_assert(userData != UGen::defaultUserData); ugen_assert(velocity >= 0); if(velocity > 0) { if(numVoices_ > 0) { const int voicesUsed = countNonstealingVoices(); if(voicesUsed >= numVoices_) { UGen stealee = chooseStealee(); if(stealee.isNotNull()) { stealee.userData = stealingUserData; stealee.steal(forcedSteal_); } } } // stop double notes, AU lab was sending two ons but only one off // stealNote(midiChannel, midiNote, false, true); // let's only do this in the Juce version.. UGen newEvent = spawnEvent(*this, currentEventIndex++, midiChannel, midiNote, velocity); if(newEvent.isNotNull()) { newEvent.userData = userData; events.add(newEvent); } } else { UGen releasee = chooseReleasee(midiChannel, midiNote); if(releasee.isNotNull()) { //releasee.userData = UGen::defaultUserData; // need to rethink why I really wanted to do this releasee.release(); } } return true; }
BEGIN_UGEN_NAMESPACE #include "ugen_JuceMultiSlider.h" MultiSliderUGenInternal::MultiSliderUGenInternal(UGen const& input, MultiSlider *_sliders) throw() : ProxyOwnerUGenInternal(NumInputs, input.getNumChannels()-1), sliders(_sliders->attachToMultiSliderUGenInternal() ? _sliders : 0), values(sliders && input.getNumChannels() ? new double[input.getNumChannels()] : 0) { inputs[Input] = input; if(values) memset(values, 0, input.getNumChannels() * sizeof(double)); if(sliders)// && sliders->isValidComponent()) { sliders->getInterceptsMouseClicks(oldClick, oldChildClick); sliders->setInterceptsMouseClicks(false, false); sliders->setNumSliders(input.getNumChannels()); for(int i = 0; i < input.getNumChannels(); i++) { values[i] = sliders->getSlider(i)->getValue(); } startTimer(40); } }
TableOsc::TableOsc(Buffer const& table, UGen const& freq, Buffer const& initialPhase) throw() { // could check here that the table is padded appropriately and use a less efficient version if not int numChannels = ugen::max(freq.getNumChannels(), initialPhase.size()); initInternal(numChannels); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new TableOscUGenInternal(freq, initialPhase.wrapAt(i), table); } }
karplusUGen::karplusUGen(UGen const& input, const float minFreq, UGen const& fundamental, UGen const& decayTime, UGen const& cutoff) throw() { initInternal(input.getNumChannels()); for(unsigned int i = 0; i < numInternalUGens; i++) { internalUGens[i] = new karplusUGenInternal(input, minFreq, fundamental, decayTime, cutoff); } }
BEGIN_UGEN_NAMESPACE #include "ugen_iPhoneAudioFileDiskOut.h" #include "ugen_NSUtilities.h" DiskOutUGenInternal::DiskOutUGenInternal(AudioFileID audioFile, AudioStreamBasicDescription const& format, UGen const& input) throw() : ProxyOwnerUGenInternal(NumInputs, input.getNumChannels() - 1), audioFile_(audioFile), numChannels(input.getNumChannels()), currentPacket(0), allocatedBlockSize(0), allocatedBlockSizeInBytes(0), audioData(0), bytesPerFrame(format.mBytesPerFrame) { inputs[Input] = input; if(audioFile_) { allocatedBlockSize = UGen::getEstimatedBlockSize(); allocatedBlockSizeInBytes = allocatedBlockSize * bytesPerFrame; audioData = malloc(allocatedBlockSizeInBytes + 4); // pad a little for 24 bit } }
RecordBufUGenInternal::RecordBufUGenInternal(UGen const& input, Buffer const& buffer, UGen const& recLevel, UGen const& preLevel, UGen const& loop, const UGen::DoneAction doneAction) throw() : ProxyOwnerUGenInternal(NumInputs, ugen::max(buffer.getNumChannels(), input.getNumChannels()) - 1), buffer_(buffer), bufferPos(0), doneAction_(doneAction), shouldDeleteValue(doneAction_ == UGen::DeleteWhenDone) { inputs[Input] = input; inputs[RecLevel] = recLevel; inputs[PreLevel] = preLevel; inputs[Loop] = loop; }
FFTMagnitudeSelection::FFTMagnitudeSelection(UGen const& input, FFTEngine const& fft, const int overlap, IntArray const& bins) throw() { int overlapChecked = Bits::isPowerOf2(overlap) ? overlap : Bits::nextPowerOf2(overlap); ugen_assert(overlap != overlapChecked); // should be power of 2 FFTMagnitudeSelectionUGenInternal *fftMag = new FFTMagnitudeSelectionUGenInternal(input.mix(), fft, overlapChecked, bins); initInternal(fftMag->getNumBins()); generateFromProxyOwner(fftMag); }
MySynth() { pos.x = ofGetMouseX(); pos.y = ofGetMouseY(); float freq = ofMap(pos.x, 0, ofGetHeight(), 0, 2000); float pan = ofMap(pos.y, 0, ofGetWidth(), -1, 1); Env env = Env::perc(0.5, 1.5, 0.3, EnvCurve::Sine); envgen = EnvGen::AR(env); envgen.addDoneActionReceiver(this); amp = SinOsc::AR(ofRandom(4.0), 0, 0.5, 0.5) * envgen; Out( Pan2::AR(SinOsc::AR(freq) * amp, pan) ); }
bool DiskOut::initWithAudioFileAiff32(const char *audioFilePath, UGen const& input, bool overwriteExisitingFile) throw() { Text path; // this needs to be here so it doesn't get garbage collected too early if(audioFilePath[0] != '/') { path = NSUtilities::pathInDirectory(NSUtilities::Documents, audioFilePath); audioFilePath = path.getArray(); } CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)audioFilePath, strlen(audioFilePath), false); AudioStreamBasicDescription format; const int numChannels = input.getNumChannels(); format.mChannelsPerFrame = numChannels; format.mSampleRate = UGen::getSampleRate(); format.mFormatID = kAudioFormatLinearPCM; format.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; format.mBitsPerChannel = 32; format.mBytesPerFrame = format.mChannelsPerFrame * format.mBitsPerChannel / 8; format.mFramesPerPacket = 1; format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket; AudioFileID audioFile; OSStatus status = AudioFileCreateWithURL(fileURL, kAudioFileAIFFType, &format, overwriteExisitingFile ? kAudioFileFlags_EraseFile : 0, &audioFile); if(status != noErr) return false; initInternal(numChannels); generateFromProxyOwner(new DiskOutUGenInternalAiff32(audioFile, format, input)); return true; }
void DiskOut::initWithJuceFile(File const& file, UGen const& input, bool overwriteExisitingFile, int bitDepth) throw() { DiskOutUGenInternal* internal; if(file.isDirectory()) { internal = new DiskOutUGenInternal(file.getChildFile(getFileNameWithTimeIdentifier("DiskOut")), input, overwriteExisitingFile, bitDepth); } else { internal = new DiskOutUGenInternal(file, input, overwriteExisitingFile, bitDepth); } initInternal(input.getNumChannels()); generateFromProxyOwner(internal); }