From 054a5f21a97c3a1d5db2ed85e098e98333f72da9 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 17 May 2021 09:00:03 -0400 Subject: [PATCH] Handle various JUCE bus layouts properly (#4562) 1. Handle various JUCE bus layotus properly in isbuseslayoutetc 2. Deal with the consequences at processing time of various disabled inputs and outputs Closes #4462 --- src/surge_synth_juce/SurgeSynthProcessor.cpp | 46 +++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/surge_synth_juce/SurgeSynthProcessor.cpp b/src/surge_synth_juce/SurgeSynthProcessor.cpp index af1d0f3c284..f986af2ed11 100644 --- a/src/surge_synth_juce/SurgeSynthProcessor.cpp +++ b/src/surge_synth_juce/SurgeSynthProcessor.cpp @@ -144,18 +144,27 @@ void SurgeSynthProcessor::releaseResources() bool SurgeSynthProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const { - // the sidechain can take any layout, the main bus needs to be the same on the input and output - return layouts.getMainInputChannelSet() == layouts.getMainOutputChannelSet() && - !layouts.getMainInputChannelSet().isDisabled() && - layouts.getMainInputChannelSet() == AudioChannelSet::stereo(); + auto mocs = layouts.getMainOutputChannelSet(); + auto mics = layouts.getMainInputChannelSet(); + + auto outputValid = (mocs == AudioChannelSet::stereo()) || mocs.isDisabled(); + auto inputValid = (mics == AudioChannelSet::stereo()) || (mics == AudioChannelSet::mono()) || + (mics.isDisabled()); + + /* + * Check the 6 output shape + */ + auto c1 = layouts.getNumChannels(false, 1); + auto c2 = layouts.getNumChannels(false, 2); + auto sceneOut = (c1 == 0 && c2 == 0) || (c1 == 2 && c2 == 2); + + return outputValid && inputValid && sceneOut; } void SurgeSynthProcessor::processBlock(AudioBuffer &buffer, MidiBuffer &midiMessages) { auto fpuguard = Surge::CPUFeatures::FPUStateGuard(); - // FIXME obvioulsy - float thisBPM = 120.0; auto playhead = getPlayHead(); if (playhead) { @@ -217,20 +226,33 @@ void SurgeSynthProcessor::processBlock(AudioBuffer &buffer, MidiBuffer &m } } - auto mainInputOutput = getBusBuffer(buffer, true, 0); + // Make sure we have a main output + auto mb = getBus(false, 0); + if (mb->getNumberOfChannels() != 2 || !mb->isEnabled()) + { + // We have to have a stereo output + return; + } + auto mainOutput = getBusBuffer(buffer, false, 0); + + auto mainInput = getBusBuffer(buffer, true, 0); auto sceneAOutput = getBusBuffer(buffer, false, 1); auto sceneBOutput = getBusBuffer(buffer, false, 2); for (int i = 0; i < buffer.getNumSamples(); i++) { - auto outL = mainInputOutput.getWritePointer(0, i); - auto outR = mainInputOutput.getWritePointer(1, i); + auto outL = mainOutput.getWritePointer(0, i); + auto outR = mainOutput.getWritePointer(1, i); surge->time_data.ppqPos += (double)BLOCK_SIZE * surge->time_data.tempo / (60. * samplerate); - if (blockPos == 0) + if (blockPos == 0 && mainInput.getNumChannels() > 0) { - auto inL = mainInputOutput.getReadPointer(0, i); - auto inR = mainInputOutput.getReadPointer(1, i); + auto inL = mainInput.getReadPointer(0, i); + auto inR = inL; // assume mono + if (mainInput.getNumChannels() > 1) // unless its not + { + inR = mainInput.getReadPointer(1, i); + } surge->process_input = true; memcpy(&(surge->input[0][0]), inL, BLOCK_SIZE * sizeof(float)); memcpy(&(surge->input[1][0]), inR, BLOCK_SIZE * sizeof(float));