Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle various JUCE bus layouts properly #4562

Merged
merged 1 commit into from
May 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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