Skip to content

Commit

Permalink
Swap UI with no audio; support multiple bus layouts (#34)
Browse files Browse the repository at this point in the history
1. UI with no audio allows swaps properly now
2. Mono input bus laouts work; and more importantly incorrect
   busses no longer crash us
  • Loading branch information
baconpaul authored Apr 25, 2024
1 parent 3fed21c commit 4a0355a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
43 changes: 37 additions & 6 deletions src-juce/AWConsolidatedProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -147,15 +148,45 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &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());
}

Expand Down
10 changes: 9 additions & 1 deletion src-juce/AWConsolidatedProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
~AWConsolidatedAudioProcessor();

//==============================================================================
std::atomic<bool> isPlaying{false};
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
void releaseResources() override;

Expand Down Expand Up @@ -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<bool> refreshUI{false};

Expand Down

0 comments on commit 4a0355a

Please sign in to comment.