Browse Source

AudioProcessorGraph: Fix MIDI channel bug and graph execution modification

MIDI only plugins are no longer provided valid audio buffers
Graph nodes are only executed when they have active connections
pull/22/head
Oli 3 years ago
parent
commit
b918fd3159
3 changed files with 21 additions and 2 deletions
  1. +1
    -1
      examples/Plugins/ArpeggiatorPluginDemo.h
  2. +10
    -1
      modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp
  3. +10
    -0
      modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h

+ 1
- 1
examples/Plugins/ArpeggiatorPluginDemo.h View File

@@ -79,7 +79,7 @@ public:
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midi) override
{
// the audio buffer in a midi effect will have zero channels!
// A pure MIDI plugin shouldn't be provided any audio data
jassert (buffer.getNumChannels() == 0);
// however we use the buffer to get timing information


+ 10
- 1
modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp View File

@@ -268,7 +268,16 @@ private:
for (int i = 0; i < totalChans; ++i)
audioChannels[i] = c.audioBuffers[audioChannelsToUse.getUnchecked (i)];
AudioBuffer<FloatType> buffer (audioChannels, totalChans, c.numSamples);
auto numAudioChannels = [this]
{
if (const auto* proc = node->getProcessor())
if (proc->getTotalNumInputChannels() == 0 && proc->getTotalNumOutputChannels() == 0)
return 0;
return totalChans;
}();
AudioBuffer<FloatType> buffer (audioChannels, numAudioChannels, c.numSamples);
const ScopedLock lock (processor.getCallbackLock());


+ 10
- 0
modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h View File

@@ -155,17 +155,27 @@ public:
void prepare (double newSampleRate, int newBlockSize, AudioProcessorGraph*, ProcessingPrecision);
void unprepare();
bool hasNoConnections() const noexcept { return inputs.isEmpty() && outputs.isEmpty(); }
template <typename Sample>
void processBlock (AudioBuffer<Sample>& audio, MidiBuffer& midi)
{
if (hasNoConnections())
return;
const ScopedLock lock (processorLock);
processor->processBlock (audio, midi);
}
template <typename Sample>
void processBlockBypassed (AudioBuffer<Sample>& audio, MidiBuffer& midi)
{
if (hasNoConnections())
return;
const ScopedLock lock (processorLock);
processor->processBlockBypassed (audio, midi);
}


Loading…
Cancel
Save