Skip to content

Commit

Permalink
Ran clang-format and black.
Browse files Browse the repository at this point in the history
  • Loading branch information
psobot committed Jan 28, 2022
1 parent d5447c3 commit dd2bb2f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
44 changes: 24 additions & 20 deletions pedalboard/ExternalPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,31 +227,34 @@ template <typename ExternalPluginType> class ExternalPlugin : public Plugin {
}

struct PresetVisitor : public juce::ExtensionsVisitor {
const std::string presetFilePath;

PresetVisitor(const std::string presetFilePath): presetFilePath(presetFilePath) { }

void visitVST3Client(const juce::ExtensionsVisitor::VST3Client& client) override {
juce::File presetFile(presetFilePath);
juce::MemoryBlock presetData;

if (!presetFile.loadFileAsData(presetData)) {
throw std::runtime_error("Failed to read preset file: " + presetFilePath);
}
const std::string presetFilePath;

if (!client.setPreset(presetData)) {
throw std::runtime_error("Plugin returned an error when loading data from preset file: " + presetFilePath);
}
PresetVisitor(const std::string presetFilePath)
: presetFilePath(presetFilePath) {}

void visitVST3Client(
const juce::ExtensionsVisitor::VST3Client &client) override {
juce::File presetFile(presetFilePath);
juce::MemoryBlock presetData;

if (!presetFile.loadFileAsData(presetData)) {
throw std::runtime_error("Failed to read preset file: " +
presetFilePath);
}
};

if (!client.setPreset(presetData)) {
throw std::runtime_error(
"Plugin returned an error when loading data from preset file: " +
presetFilePath);
}
}
};

void loadPresetData(std::string presetFilePath) {
PresetVisitor visitor {presetFilePath};
pluginInstance->getExtensions(visitor);
PresetVisitor visitor{presetFilePath};
pluginInstance->getExtensions(visitor);
}


void reinstantiatePlugin() {
// If we have an existing plugin, save its state and reload its state later:
juce::MemoryBlock savedState;
Expand Down Expand Up @@ -820,8 +823,9 @@ inline void init_external_plugins(py::module &m) {
return ss.str();
})
.def("load_preset",
&ExternalPlugin<juce::VST3PluginFormat>::loadPresetData,
"Load a VST3 preset file in .vstpreset format.", py::arg("preset_file_path"))
&ExternalPlugin<juce::VST3PluginFormat>::loadPresetData,
"Load a VST3 preset file in .vstpreset format.",
py::arg("preset_file_path"))
.def_property_readonly_static(
"installed_plugins",
[](py::object /* cls */) { return findInstalledVSTPluginPaths(); },
Expand Down
24 changes: 13 additions & 11 deletions tests/test_external_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,32 @@ def test_at_least_one_parameter(plugin_filename: str):

assert get_parameters(plugin_filename)


@pytest.mark.parametrize(
"plugin_filename,plugin_preset", [
(plugin,os.path.join(TEST_PRESET_BASE_PATH, plugin+".vstpreset"))
for plugin in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT \
if os.path.isfile(os.path.join(TEST_PRESET_BASE_PATH, plugin+".vstpreset"))
])
"plugin_filename,plugin_preset",
[
(plugin, os.path.join(TEST_PRESET_BASE_PATH, plugin + ".vstpreset"))
for plugin in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT
if os.path.isfile(os.path.join(TEST_PRESET_BASE_PATH, plugin + ".vstpreset"))
],
)
def test_preset_parameters(plugin_filename: str, plugin_preset: str):
# plugin with default params.
plugin = load_test_plugin(plugin_filename)

default_params = {
k: v.raw_value for k, v in plugin.parameters.items() if v.type == float
}

default_params = {k: v.raw_value for k, v in plugin.parameters.items() if v.type == float}

# load preset file
plugin.load_preset(plugin_preset)


for name, default in default_params.items():
actual = getattr(plugin, name)
if math.isnan(actual):
continue
assert actual != default, f"Expected attribute {name} was {actual} supposed to be different from default {default}"
assert (
actual != default
), f"Expected attribute {name} to be different from default ({default}), but was {actual}"


@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)
def test_initial_parameters(plugin_filename: str):
Expand Down

0 comments on commit dd2bb2f

Please sign in to comment.