1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

VST3: Avoid requesting channel layouts that cannot be represented as SpeakerArrangements

This commit is contained in:
reuk 2023-01-11 20:09:50 +00:00
parent 6bd31bab35
commit 4b222427f9
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
4 changed files with 155 additions and 85 deletions

View file

@ -3051,7 +3051,9 @@ public:
info.mediaType = Vst::kAudio;
info.direction = dir;
info.channelCount = bus->getLastEnabledLayout().size();
jassert (info.channelCount == Steinberg::Vst::SpeakerArr::getChannelCount (getVst3SpeakerArrangement (bus->getLastEnabledLayout())));
[[maybe_unused]] const auto lastEnabledVst3Layout = getVst3SpeakerArrangement (bus->getLastEnabledLayout());
jassert (lastEnabledVst3Layout.has_value() && info.channelCount == Steinberg::Vst::SpeakerArr::getChannelCount (*lastEnabledVst3Layout));
toString128 (info.name, bus->getName());
info.busType = [&]
@ -3288,19 +3290,42 @@ public:
// see the following documentation to understand the correct way to react to this callback
// https://steinbergmedia.github.io/vst3_doc/vstinterfaces/classSteinberg_1_1Vst_1_1IAudioProcessor.html#ad3bc7bac3fd3b194122669be2a1ecc42
const auto requestedLayout = [&]
const auto toLayoutsArray = [] (auto begin, auto end) -> std::optional<Array<AudioChannelSet>>
{
auto result = pluginInstance->getBusesLayout();
Array<AudioChannelSet> result;
for (int i = 0; i < numIns; ++i)
result.getChannelSet (true, i) = getChannelSetForSpeakerArrangement (inputs[i]);
for (auto it = begin; it != end; ++it)
{
const auto set = getChannelSetForSpeakerArrangement (*it);
for (int i = 0; i < numOuts; ++i)
result.getChannelSet (false, i) = getChannelSetForSpeakerArrangement (outputs[i]);
if (! set.has_value())
return {};
result.add (*set);
}
return result;
};
const auto optionalRequestedLayout = [&]() -> std::optional<AudioProcessor::BusesLayout>
{
const auto ins = toLayoutsArray (inputs, inputs + numIns);
const auto outs = toLayoutsArray (outputs, outputs + numOuts);
if (! ins.has_value() || ! outs.has_value())
return {};
AudioProcessor::BusesLayout result;
result.inputBuses = *ins;
result.outputBuses = *outs;
return result;
}();
if (! optionalRequestedLayout.has_value())
return kResultFalse;
const auto& requestedLayout = *optionalRequestedLayout;
#ifdef JucePlugin_PreferredChannelConfigurations
short configs[][2] = { JucePlugin_PreferredChannelConfigurations };
if (! AudioProcessor::containsLayout (requestedLayout, configs))
@ -3339,8 +3364,14 @@ public:
{
if (auto* bus = pluginInstance->getBus (dir == Vst::kInput, index))
{
arr = getVst3SpeakerArrangement (bus->getLastEnabledLayout());
return kResultTrue;
if (const auto arrangement = getVst3SpeakerArrangement (bus->getLastEnabledLayout()))
{
arr = *arrangement;
return kResultTrue;
}
// There's a bus here, but we can't represent its layout in terms of VST3 speakers!
jassertfalse;
}
return kResultFalse;