From 8f29b2cb8320ef90c6efb6b87d45665899345955 Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 23 Jul 2021 13:25:09 +0100 Subject: [PATCH] VST3: Allow plugins to designate the first input bus as Aux rather than Main To use this feature, derive your AudioProcessor from VST3ClientExtensions and override getPluginHasMainInput() to return false. The main input bus will then be designated as an Aux bus, rather than a Main bus. This is mainly useful for synth plugins like vocoders, which may need a sidechain audio input, but which should replace all audio on the channel with the output of the synth, rather than mixing with the audio input. --- .../VST3/juce_VST3_Wrapper.cpp | 28 +++++++++++++++---- .../utilities/juce_VST3ClientExtensions.h | 8 ++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 88a2f66f8e..570763f107 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -2825,11 +2825,29 @@ public: info.channelCount = bus->getLastEnabledLayout().size(); toString128 (info.name, bus->getName()); - #if JucePlugin_IsSynth - info.busType = (dir == Vst::kInput && index > 0 ? Vst::kAux : Vst::kMain); - #else - info.busType = (index == 0 ? Vst::kMain : Vst::kAux); - #endif + info.busType = [&] + { + const auto isFirstBus = (index == 0); + + if (dir == Vst::kInput) + { + if (isFirstBus) + { + if (auto* extensions = dynamic_cast (pluginInstance)) + return extensions->getPluginHasMainInput() ? Vst::kMain : Vst::kAux; + + return Vst::kMain; + } + + return Vst::kAux; + } + + #if JucePlugin_IsSynth + return Vst::kMain; + #else + return isFirstBus ? Vst::kMain : Vst::kAux; + #endif + }(); #ifdef JucePlugin_PreferredChannelConfigurations info.flags = Vst::BusInfo::kDefaultActive; diff --git a/modules/juce_audio_processors/utilities/juce_VST3ClientExtensions.h b/modules/juce_audio_processors/utilities/juce_VST3ClientExtensions.h index 32afeeb2d6..ffbf0056dc 100644 --- a/modules/juce_audio_processors/utilities/juce_VST3ClientExtensions.h +++ b/modules/juce_audio_processors/utilities/juce_VST3ClientExtensions.h @@ -82,6 +82,14 @@ struct VST3ClientExtensions called - this function may not be called at all! */ virtual void setIHostApplication (Steinberg::FUnknown*) {} + + /** This function will be called to check whether the first input bus + should be designated as "kMain" or "kAux". Return true if the + first bus should be kMain, or false if the bus should be kAux. + + All other input buses will always be designated kAux. + */ + virtual bool getPluginHasMainInput() const { return true; } }; } // namespace juce