Hello! I am making a plugin host based on the HostPluginDemo, which comes without audio implemented by default.
My host will only use stereo input and stereo output.
Audio input is currently not working and producing noise.
Some plugins output only in the Right channel and the Left is muted.
Plugins that have more than 2 in/outs crash the application, hiting this jassert:
Type* getWritePointer (int channelNumber) noexcept
{
jassert (isPositiveAndBelow (channelNumber, numChannels));
isClear = false;
return channels[channelNumber];
}
The code for audio is as follows:
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midimessages) override
{
if (inner)
{
inner->processBlock(newbuffer, midimessages);
for (size_t c = 0; c < 2; c++)
{
auto destchannelindex = getChannelIndexInProcessBlockBuffer(false, 0, c);
auto* readpointer = newbuffer.getReadPointer(c);
buffer.copyFrom(destchannelindex, 0, readpointer, buffer.getNumSamples());
buffer.applyGain(gain);
}
}
else {
buffer.clear();
midimessages.clear();
}
}
void setNewPlugin (const PluginDescription& pd, EditorStyle where, const MemoryBlock& mb = {})
{
const ScopedLock sl (innerMutex);
const auto callback = [this, where, mb] (std::unique_ptr<AudioPluginInstance> instance, const String& error)
{ if (inner != nullptr)
{
inner->setRateAndBufferSizeDetails(getSampleRate(), getBlockSize());
inner->prepareToPlay(getSampleRate(), getBlockSize());
}
if (error.isNotEmpty())
{
NativeMessageBox::showMessageBoxAsync (MessageBoxIconType::WarningIcon,
"Plugin Load Failed",
error,
nullptr,
nullptr);
return;
}
inner = std::move (instance);
editorStyle = where;
if (inner != nullptr && ! mb.isEmpty())
inner->setStateInformation (mb.getData(), (int) mb.getSize());
auto busesLayout = getBusesLayout();
if (inner->checkBusesLayoutSupported(busesLayout))
inner->setBusesLayout(busesLayout);
else
{
// fallback
busesLayout.inputBuses.clear();
busesLayout.outputBuses.clear();
if (inner->checkBusesLayoutSupported(busesLayout))
inner->setBusesLayout(busesLayout);
}
if (inner != nullptr)
{
inner->setRateAndBufferSizeDetails(getSampleRate(), getBlockSize());
inner->prepareToPlay(getSampleRate(), getBlockSize());
}
NullCheckedInvocation::invoke (pluginChanged);
};
pluginFormatManager.createPluginInstanceAsync (pd, getSampleRate(), getBlockSize(), callback);
}
void prepareToPlay (double sr, int bs) override
{
const ScopedLock sl (innerMutex);
newbuffer.setSize(2, bs, false, true);
active = true;
if (inner != nullptr)
{
inner->setRateAndBufferSizeDetails (sr, bs);
inner->prepareToPlay (sr, bs);
}
}