Skip to content

Commit

Permalink
Handle various JUCE bus layouts properly (#4562)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baconpaul authored May 17, 2021
1 parent 5a8d309 commit 054a5f2
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/surge_synth_juce/SurgeSynthProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> &buffer, MidiBuffer &midiMessages)
{
auto fpuguard = Surge::CPUFeatures::FPUStateGuard();

// FIXME obvioulsy
float thisBPM = 120.0;
auto playhead = getPlayHead();
if (playhead)
{
Expand Down Expand Up @@ -217,20 +226,33 @@ void SurgeSynthProcessor::processBlock(AudioBuffer<float> &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));
Expand Down

0 comments on commit 054a5f2

Please sign in to comment.