Skip to content

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

Download third-party VSTs for testing on GitHub Actions. (#30)

Peter Sobot9bfd4d160fc8
diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml
index 8188e39..73a4863 100644
--- a/.github/workflows/all.yml
+++ b/.github/workflows/all.yml
@@ -90,6 +90,11 @@ jobs:
if: runner.os == 'Windows'
- name: Build pedalboard locally
run: python setup.py install
+ - name: Install VSTs for testing
+ env:
+ GCS_ASSET_BUCKET_NAME: ${{ secrets.GCS_ASSET_BUCKET_NAME }}
+ GCS_READER_SERVICE_ACCOUNT_KEY: ${{ secrets.GCS_READER_SERVICE_ACCOUNT_KEY }}
+ run: python ./tests/download_test_plugins.py
- name: Run tests
if: matrix.os != 'ubuntu-latest' || matrix.python-version != '3.6'
run: pytest -v --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard
diff --git a/pedalboard/pedalboard.py b/pedalboard/pedalboard.py
index fbe94b3..21067dc 100644
--- a/pedalboard/pedalboard.py
+++ b/pedalboard/pedalboard.py
@@ -140,12 +140,20 @@ class Pedalboard(collections.MutableSequence):
__call__ = process
-FLOAT_SUFFIXES_TO_IGNORE = "x%*,."
+FLOAT_SUFFIXES_TO_IGNORE = set(["x", "%", "*", ",", ".", "hz"])
+
+
+def strip_common_float_suffixes(s: str) -> str:
+ value = s.lower()
+ for suffix in FLOAT_SUFFIXES_TO_IGNORE:
+ if suffix in value:
+ value = value[: -len(suffix)]
+ return value
def looks_like_float(s: str) -> bool:
try:
- float(s.rstrip(FLOAT_SUFFIXES_TO_IGNORE))
+ float(strip_common_float_suffixes(s))
return True
except ValueError:
return False
@@ -238,6 +246,12 @@ FloatWithParameter = wrap_type(float)
BooleanWithParameter = wrap_type(WrappedBool)
+# Some plugins, on some platforms (TAL Reverb 3 on Ubuntu, so far) seem to
+# expose every possible MIDI CC value as a separate parameter
+# (i.e.: MIDI CC [0-16]|[0-128], resulting in 2,048 parameters).
+# This hugely delays load times and adds complexity to the interface.
+PARAMETER_NAME_SUBSTRINGS_TO_IGNORE = {"MIDI CC "}
+
TRUE_BOOLEANS = {"on", "yes", "true", "enabled"}
@@ -288,14 +302,11 @@ class AudioProcessorParameter(object):
self.max_value = None
self.step_size = None
self.approximate_step_size = None
- self.valid_values = list(self.ranges.values())
self.type = str
if all(looks_like_float(v) for v in self.ranges.values()):
self.type = float
- self.ranges = {
- k: float(v.rstrip(FLOAT_SUFFIXES_TO_IGNORE)) for k, v in self.ranges.items()
- }
+ self.ranges = {k: float(strip_common_float_suffixes(v)) for k, v in self.ranges.items()}
self.min_value = min(self.ranges.values())
self.max_value = max(self.ranges.values())
@@ -309,15 +320,14 @@ class AudioProcessorParameter(object):
self.approximate_step_size = sum(first_derivative_steps) / len(
first_derivative_steps
)
- elif len(self.valid_values) == 2 and (
- TRUE_BOOLEANS & {v.lower() for v in self.valid_values}
- ):
+ elif len(self.ranges) == 2 and (TRUE_BOOLEANS & {v.lower() for v in self.ranges.values()}):
self.type = bool
self.ranges = {k: v.lower() in TRUE_BOOLEANS for k, v in self.ranges.items()}
self.min_value = False
self.max_value = True
self.step_size = 1
+ self.valid_values = list(self.ranges.values())
self.range = self.min_value, self.max_value, self.step_size
self._value_to_raw_value_ranges = {value: _range for _range, value in self.ranges.items()}
@@ -528,6 +538,10 @@ class ExternalPlugin(object):
parameters = {}
for cpp_parameter in self._parameters:
+ if any(
+ [substr in cpp_parameter.name for substr in PARAMETER_NAME_SUBSTRINGS_TO_IGNORE]
+ ):
+ continue
if cpp_parameter.name not in self.__python_parameter_cache__:
self.__python_parameter_cache__[cpp_parameter.name] = AudioProcessorParameter(
self, cpp_parameter.name
@@ -573,7 +587,7 @@ class ExternalPlugin(object):
string_value = parameter.string_value
if parameter.type is float:
return FloatWithParameter(
- float(string_value.rstrip(FLOAT_SUFFIXES_TO_IGNORE)), wrapped=parameter
+ float(strip_common_float_suffixes(string_value)), wrapped=parameter
)
elif parameter.type is bool:
return BooleanWithParameter(parameter.raw_value >= 0.5, wrapped=parameter)
diff --git a/test-requirements.txt b/test-requirements.txt
index 8606dd8..52f2345 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -12,3 +12,5 @@ interrogate
numpy
sox
tensorflow==2.5.0
+google-cloud-storage
+tqdm
\ No newline at end of file
diff --git a/tests/download_test_plugins.py b/tests/download_test_plugins.py
new file mode 100644
index 0000000..c245313
--- /dev/null
+++ b/tests/download_test_plugins.py
@@ -0,0 +1,46 @@
+"""
+This script is intended to run on GitHub Actions to download plugin files
+that we can't embed in the repository itself, but we still want to use for
+testing purposes.
+"""
+
+import os
+import json
+from tqdm import tqdm
+import platform
+from google.cloud import storage
+from google.oauth2 import service_account
+
+
+def main():
+ GCS_ASSET_BUCKET_NAME = os.environ.get("GCS_ASSET_BUCKET_NAME")
+ if not GCS_ASSET_BUCKET_NAME:
+ raise ValueError("Missing GCS_ASSET_BUCKET_NAME environment variable!")
+
+ GCS_READER_SERVICE_ACCOUNT_KEY = os.environ.get("GCS_READER_SERVICE_ACCOUNT_KEY")
+ if not GCS_READER_SERVICE_ACCOUNT_KEY:
+ raise ValueError("Missing GCS_READER_SERVICE_ACCOUNT_KEY environment variable!")
+
+ json_acct_info = json.loads(GCS_READER_SERVICE_ACCOUNT_KEY)
+ credentials = service_account.Credentials.from_service_account_info(json_acct_info)
+ client = storage.Client(credentials=credentials)
+
+ target_filepath = os.path.join(".", "tests", "plugins", platform.system())
+ bucket = client.bucket(GCS_ASSET_BUCKET_NAME)
+ prefix = f"test-plugins/{platform.system()}"
+
+ # Manually iterate here instead of just calling gsutil on the command line as
+ # GSUtil on Windows is not 100% guaranteed to install properly on GitHub Actions.
+ print("Downloading test plugin files from Google Cloud Storage...")
+ for blob in tqdm(list(bucket.list_blobs(prefix=prefix))):
+ local_path = os.path.join(target_filepath, blob.name.replace(prefix + "/", ""))
+ if local_path.endswith("/"):
+ os.makedirs(local_path, exist_ok=True)
+ else:
+ os.makedirs(os.path.dirname(local_path), exist_ok=True)
+ blob.download_to_filename(local_path)
+ print("Done!")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.py
index 8aa0e3e..3d1b45e 100644
--- a/tests/test_external_plugins.py
+++ b/tests/test_external_plugins.py
@@ -74,13 +74,16 @@ def load_test_plugin(plugin_filename: str, disable_caching: bool = False, *args,
key: getattr(plugin, key) for key in plugin.parameters.keys()
}
- # Reset default parameters when loading:
+ # Try to reset default parameters when loading:
plugin = TEST_PLUGIN_CACHE[key]
for name in plugin.parameters.keys():
- setattr(plugin, name, TEST_PLUGIN_ORIGINAL_PARAMETER_CACHE[key][name])
+ try:
+ setattr(plugin, name, TEST_PLUGIN_ORIGINAL_PARAMETER_CACHE[key][name])
+ except ValueError:
+ pass
- # Throw some silence in and force a reset:
- plugin.process(np.zeros((44100, 2)), 44100, reset=True)
+ # Force a reset:
+ plugin.reset()
return plugin
@@ -294,13 +297,20 @@ def test_float_parameters(plugin_filename: str, parameter_name: str):
assert repr(parameter_value) == repr(float(parameter_value))
assert isinstance(parameter_value, float)
# Change the parameter and ensure that it does change:
- _min, _max, _ = parameter_value.range
- step_size = parameter_value.step_size or parameter_value.approximate_step_size
- for new_value in np.arange(_min, _max, step_size):
+ new_values = parameter_value.valid_values
+
+ if parameter_value.step_size is not None:
+ _min, _max, _ = parameter_value.range
+ step_size = parameter_value.step_size
+ new_values = np.arange(_min, _max, step_size)
+
+ epsilon = parameter_value.step_size or parameter_value.approximate_step_size or 0.001
+
+ for new_value in new_values:
setattr(plugin, parameter_name, new_value)
if math.isnan(getattr(plugin, parameter_name)):
continue
- assert math.isclose(new_value, getattr(plugin, parameter_name), abs_tol=step_size * 2)
+ assert math.isclose(new_value, getattr(plugin, parameter_name), abs_tol=epsilon * 2.0)
# Ensure that if we access an attribute that we're not adding to the value,
# we fall back to the underlying type (float) or we raise an exception if not:
@@ -407,7 +417,11 @@ def test_plugin_parameters_persist_between_calls(plugin_filename: str):
random_value = random.choice(parameter.valid_values)
else:
random_value = None
- if random_value is not None:
+ if (
+ random_value is not None
+ and "bypass" not in name.lower()
+ and "preset" not in name.lower()
+ ):
setattr(plugin, name, random_value)
expected_values = {}