diff --git a/src-juce/AWConsolidatedProcessor.cpp b/src-juce/AWConsolidatedProcessor.cpp index a553101..02cd09c 100644 --- a/src-juce/AWConsolidatedProcessor.cpp +++ b/src-juce/AWConsolidatedProcessor.cpp @@ -115,19 +115,20 @@ void AWConsolidatedAudioProcessor::prepareToPlay(double sr, int samplesPerBlock) Airwin2RackBase::defaultSampleRate = sr; if (awProcessor) awProcessor->setSampleRate(sr); + isPlaying = true; } void AWConsolidatedAudioProcessor::releaseResources() { - // When playback stops, you can use this as an opportunity to free up any - // spare memory, etc. + isPlaying = false; } bool AWConsolidatedAudioProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const { - bool inputValid = layouts.getMainInputChannelSet() == juce::AudioChannelSet::stereo(); + bool inputValid = (layouts.getMainInputChannelSet() == juce::AudioChannelSet::stereo() || + layouts.getMainInputChannelSet() == juce::AudioChannelSet::mono()); - bool outputValid = layouts.getMainOutputChannelSet() == juce::AudioChannelSet::mono(); + bool outputValid = layouts.getMainOutputChannelSet() == juce::AudioChannelSet::stereo(); return inputValid && outputValid; } @@ -147,15 +148,45 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer &buffer } if (!awProcessor) + { + isPlaying = false; + return; + } + + auto inBus = getBus(true, 0); + auto outBus = getBus(false, 0); + + if (inBus->getNumberOfChannels() == 0 || + outBus->getNumberOfChannels() != 2 || + buffer.getNumChannels() < 2) + { + isPlaying = false; + return; + } + + + const float *inputs[2]; + float *outputs[2]; + inputs[0] = buffer.getReadPointer(0); + inputs[1] = inBus->getNumberOfChannels() == 2 ? buffer.getReadPointer(1) : buffer.getReadPointer(0); + outputs[0] = buffer.getWritePointer(0); + outputs[1] = buffer.getWritePointer(1); + + if (!(inputs[0] && inputs[1] && outputs[0] && outputs[1])) + { + isPlaying = false; return; + } + + isPlaying = true; for (int i = 0; i < nProcessorParams; ++i) { awProcessor->setParameter(i, fxParams[i]->get()); } - awProcessor->processReplacing((float **)buffer.getArrayOfReadPointers(), - (float **)buffer.getArrayOfWritePointers(), + awProcessor->processReplacing((float **)inputs, + (float **)outputs, buffer.getNumSamples()); } diff --git a/src-juce/AWConsolidatedProcessor.h b/src-juce/AWConsolidatedProcessor.h index 7a8dd2a..c24f9da 100644 --- a/src-juce/AWConsolidatedProcessor.h +++ b/src-juce/AWConsolidatedProcessor.h @@ -67,6 +67,7 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor, ~AWConsolidatedAudioProcessor(); //============================================================================== + std::atomic isPlaying{false}; void prepareToPlay(double sampleRate, int samplesPerBlock) override; void releaseResources() override; @@ -118,7 +119,14 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor, awDisplayProcessor = rg.generator(); awDisplayProcessor->setSampleRate(getSampleRate()); } - resetType.push({-1, index, 0.f}); + if (isPlaying) + { + resetType.push({-1, index, 0.f}); + } + else + { + setAWProcessorTo(index, false); + } } std::atomic refreshUI{false};