Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Add support for loading plugin containers (i.e.: WaveShell)

Peter Sobotcdff22dbfee7
diff --git a/.gitmodules b/.gitmodules
index eba99dc..d9b34b0 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,6 @@
[submodule "JUCE"]
path = JUCE
- url = https://github.com/juce-framework/JUCE.git
+ url = https://github.com/psobot/JUCE.git
[submodule "vendors/rubberband"]
path = vendors/rubberband
url = https://github.com/BreakfastQuay/Rubberband.git
diff --git a/JUCE b/JUCE
index ddaa091..f0fc4a1 160000
--- a/JUCE
+++ b/JUCE
@@ -1 +1 @@
-Subproject commit ddaa09110392a4419fecbb6d3022bede89b7e841
+Subproject commit f0fc4a1f67bb6070cfa338cebcddfc7612c4104d
diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.h
index 2e97dd7..84635a9 100644
--- a/pedalboard/ExternalPlugin.h
+++ b/pedalboard/ExternalPlugin.h
@@ -215,7 +215,8 @@ enum class ExternalPluginReloadType {
template <typename ExternalPluginType> class ExternalPlugin : public Plugin {
public:
- ExternalPlugin(std::string &_pathToPluginFile)
+ ExternalPlugin(std::string &_pathToPluginFile,
+ std::optional<std::string> pluginName = {})
: pathToPluginFile(_pathToPluginFile) {
py::gil_scoped_release release;
// Ensure we have a MessageManager, which is required by the VST wrapper
@@ -245,7 +246,45 @@ public:
pluginList.scanAndAddFile(pluginFileStripped, false, typesFound, format);
if (!typesFound.isEmpty()) {
- foundPluginDescription = *typesFound[0];
+ if (typesFound.size() == 1) {
+ foundPluginDescription = *typesFound[0];
+ } else if (typesFound.size() > 1) {
+ std::string errorMessage =
+ "Plugin file " + pathToPluginFile.toStdString() + " contains " +
+ std::to_string(typesFound.size()) + " plugins";
+
+ // Use the provided plugin name to disambiguate:
+ if (pluginName) {
+ for (int i = 0; i < typesFound.size(); i++) {
+ if (typesFound[i]->name.toStdString() == pluginName.value()) {
+ foundPluginDescription = *typesFound[i];
+ break;
+ }
+ }
+
+ if (foundPluginDescription.name.isEmpty()) {
+ errorMessage += ", and the provided plugin_name \"" +
+ pluginName.value() + "\" matched no plugins. ";
+ }
+ } else {
+ errorMessage += ". ";
+ }
+
+ if (foundPluginDescription.name.isEmpty()) {
+ juce::StringArray pluginNames;
+ for (int i = 0; i < typesFound.size(); i++) {
+ pluginNames.add(typesFound[i]->name);
+ }
+
+ errorMessage +=
+ ("To open a specific plugin within this file, pass a "
+ "\"plugin_name\" parameter with one of the following "
+ "values:\n\t\"" +
+ pluginNames.joinIntoString("\"\n\t\"").toStdString() + "\"");
+ throw std::domain_error(errorMessage);
+ }
+ }
+
reinstantiatePlugin();
} else {
#if JUCE_LINUX
@@ -358,6 +397,13 @@ public:
juce::String loadError;
{
+ if (foundPluginDescription.numInputChannels == 0) {
+ throw std::invalid_argument(
+ "Plugin '" + foundPluginDescription.name.toStdString() +
+ "' does not accept audio input. It may be an instrument plug-in "
+ "and not an audio effect processor.");
+ }
+
std::lock_guard<std::mutex> lock(EXTERNAL_PLUGIN_MUTEX);
pluginInstance = pluginFormatManager.createPluginInstance(
foundPluginDescription, ExternalLoadSampleRate,
@@ -374,15 +420,6 @@ public:
auto mainInputBus = pluginInstance->getBus(true, 0);
auto mainOutputBus = pluginInstance->getBus(false, 0);
- if (!mainInputBus) {
- auto exception = std::invalid_argument(
- "Plugin '" + pluginInstance->getName().toStdString() +
- "' does not accept audio input. It may be an instrument plug-in "
- "and not an audio effect processor.");
- pluginInstance.reset();
- throw exception;
- }
-
if (!mainOutputBus) {
auto exception = std::invalid_argument(
"Plugin '" + pluginInstance->getName().toStdString() +
@@ -904,11 +941,12 @@ inline void init_external_plugins(py::module &m) {
"(i.e.: if you're running Linux but trying to open a VST that does not "
"support Linux, this will fail).",
py::dynamic_attr())
- .def(py::init([](std::string &pathToPluginFile) {
- return new ExternalPlugin<juce::VST3PluginFormat>(
- pathToPluginFile);
+ .def(py::init([](std::string &pathToPluginFile,
+ std::optional<std::string> pluginName) {
+ return std::make_unique<ExternalPlugin<juce::VST3PluginFormat>>(
+ pathToPluginFile, pluginName);
}),
- py::arg("path_to_plugin_file"))
+ py::arg("path_to_plugin_file"), py::arg("plugin_name") = py::none())
.def("__repr__",
[](ExternalPlugin<juce::VST3PluginFormat> &plugin) {
std::ostringstream ss;
@@ -929,6 +967,12 @@ inline void init_external_plugins(py::module &m) {
"location on this system. This list may not be exhaustive, and "
"plugins in this list are not guaranteed to be compatible with "
"Pedalboard.")
+ .def_property_readonly(
+ "name",
+ [](ExternalPlugin<juce::VST3PluginFormat> &plugin) {
+ return plugin.getName().toStdString();
+ },
+ "The name of this plugin.")
.def_property_readonly(
"_parameters", &ExternalPlugin<juce::VST3PluginFormat>::getParameters,
py::return_value_policy::reference_internal)
@@ -948,11 +992,13 @@ inline void init_external_plugins(py::module &m) {
"A wrapper around any Apple Audio Unit audio effect plugin. Only "
"available on macOS.",
py::dynamic_attr())
- .def(py::init([](std::string &pathToPluginFile) {
- return new ExternalPlugin<juce::AudioUnitPluginFormat>(
- pathToPluginFile);
+ .def(py::init([](std::string &pathToPluginFile,
+ std::optional<std::string> pluginName) {
+ return std::make_unique<
+ ExternalPlugin<juce::AudioUnitPluginFormat>>(pathToPluginFile,
+ pluginName);
}),
- py::arg("path_to_plugin_file"))
+ py::arg("path_to_plugin_file"), py::arg("plugin_name") = py::none())
.def("__repr__",
[](const ExternalPlugin<juce::AudioUnitPluginFormat> &plugin) {
std::ostringstream ss;
@@ -971,6 +1017,12 @@ inline void init_external_plugins(py::module &m) {
"location on this system. This list may not be exhaustive, and "
"plugins in this list are not guaranteed to be compatible with "
"Pedalboard.")
+ .def_property_readonly(
+ "name",
+ [](ExternalPlugin<juce::AudioUnitPluginFormat> &plugin) {
+ return plugin.getName().toStdString();
+ },
+ "The name of this plugin.")
.def_property_readonly(
"_parameters",
&ExternalPlugin<juce::AudioUnitPluginFormat>::getParameters,
diff --git a/pedalboard/pedalboard.py b/pedalboard/pedalboard.py
index 67e0e7d..e3417a2 100644
--- a/pedalboard/pedalboard.py
+++ b/pedalboard/pedalboard.py
@@ -525,8 +525,15 @@ try:
self,
path_to_plugin_file: str,
parameter_values: Dict[str, Union[str, int, float, bool]] = {},
+ plugin_name: Optional[str] = None,
):
- super().__init__(path_to_plugin_file)
+ if not isinstance(parameter_values, dict):
+ raise TypeError(
+ "Expected a dictionary to be passed to parameter_values, but received a"
+ f" {type(parameter_values).__name__}. (If passing a plugin name, pass"
+ " \"plugin_name=...\" as a keyword argument instead.)"
+ )
+ super().__init__(path_to_plugin_file, plugin_name)
self.__set_initial_parameter_values__(parameter_values)
@@ -542,8 +549,15 @@ try:
self,
path_to_plugin_file: str,
parameter_values: Dict[str, Union[str, int, float, bool]] = {},
+ plugin_name: Optional[str] = None,
):
- super().__init__(path_to_plugin_file)
+ if not isinstance(parameter_values, dict):
+ raise TypeError(
+ "Expected a dictionary to be passed to parameter_values, but received a"
+ f" {type(parameter_values).__name__}. (If passing a plugin name, pass"
+ " \"plugin_name=...\" as a keyword argument instead.)"
+ )
+ super().__init__(path_to_plugin_file, plugin_name)
self.__set_initial_parameter_values__(parameter_values)
diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.py
index 9d66f50..5c62df1 100644
--- a/tests/test_external_plugins.py
+++ b/tests/test_external_plugins.py
@@ -53,6 +53,15 @@ if os.getenv("CIBW_TEST_REQUIRES") or os.getenv("CI"):
f for f in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT if "component" not in f
]
+# Waves is the only known plugin vendor who regularly bundles multiple VSTs/AUs into one file:
+KNOWN_CONTAINER_PLUGIN_NAMES = {"WaveShell"}
+
+AVAILABLE_CONTAINER_PLUGINS_IN_TEST_ENVIRONMENT = [
+ filename
+ for filename in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT
+ if any(container_name in filename for container_name in KNOWN_CONTAINER_PLUGIN_NAMES)
+]
+
def get_parameters(plugin_filename: str):
return load_test_plugin(plugin_filename).parameters
@@ -144,8 +153,15 @@ if os.environ.get("ENABLE_TESTING_WITH_LOCAL_PLUGINS", False):
try:
load_test_plugin(plugin_path)
AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT.append(plugin_path)
- except Exception:
- pass
+ except Exception as e:
+ print(f"Tried to load {plugin_path} for local testing, but failed with: {e}")
+
+ # Even if the plugin failed to load, add it to
+ # the list of known container plugins if necessary:
+ if any(
+ container_name in plugin_path for container_name in KNOWN_CONTAINER_PLUGIN_NAMES
+ ):
+ AVAILABLE_CONTAINER_PLUGINS_IN_TEST_ENVIRONMENT.append(plugin_path)
def plugin_named(*substrings: str) -> Optional[str]:
@@ -675,3 +691,30 @@ def test_show_editor(plugin_filename: str):
except subprocess.TimeoutExpired:
# This is good: the UI was shown, no issues.
pass
+
+
+ not AVAILABLE_CONTAINER_PLUGINS_IN_TEST_ENVIRONMENT,
+ reason="No plugin containers installed in test environment!",
+)
[email protected]("plugin_filename", AVAILABLE_CONTAINER_PLUGINS_IN_TEST_ENVIRONMENT)
+def test_plugin_container_handling(plugin_filename: str):
+ """
+ Some plugins can have multiple sub-plugins within them.
+ As of v0.4.5, Pedalboard requires indicating the specific plugin to open within the container.
+ These plugins will fail by default:
+ """
+ with pytest.raises(ValueError) as e:
+ load_test_plugin(plugin_filename, disable_caching=True)
+ assert plugin_filename in str(e)
+ assert "plugin_name" in str(e)
+
+ # Hackily parse out the plugin names:
+ message = e.value.args[0]
+ plugin_names = [line.strip().strip("\"") for line in message.split("\n")[1:]]
+ assert f"{len(plugin_names)} plugins" in message
+
+ # Try to re-load each of the component plugins here:
+ for plugin_name in plugin_names:
+ plugin = load_test_plugin(plugin_filename, disable_caching=True, plugin_name=plugin_name)
+ assert plugin_name == plugin.name