π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Handle plugin parameter value parsing better for plugins that expose Hz/kHz values.
Peter Sobot21c32620b346
diff --git a/pedalboard/pedalboard.py b/pedalboard/pedalboard.pyindex c502c6c..403fd5e 100644--- a/pedalboard/pedalboard.py+++ b/pedalboard/pedalboard.py@@ -46,11 +46,21 @@ FLOAT_SUFFIXES_TO_IGNORE = set(["x", "%", "*", ",", ".", "hz"])def strip_common_float_suffixes(s: str) -> str:- value = s.lower().strip()+ s = s.strip()++ # Handle certain plugins that report "Hz" and "kHz" suffixes:+ if s.lower().endswith("khz") and len(s) > 3:+ try:+ s = str(float(s[:-3]) * 1000)+ except ValueError:+ pass+for suffix in FLOAT_SUFFIXES_TO_IGNORE:- if value[-len(suffix) :] == suffix:- value = value[: -len(suffix)].strip()- return value+ if suffix == "hz" and "khz" in s.lower():+ continue+ if s[-len(suffix) :].lower() == suffix.lower():+ s = s[: -len(suffix)].strip()+ return sdef looks_like_float(s: str) -> bool:diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.pyindex b85d2fe..42ef97d 100644--- a/tests/test_external_plugins.py+++ b/tests/test_external_plugins.py@@ -186,6 +186,8 @@ def test_at_least_one_plugin_is_available_for_testing():("12%", "12"),("123 Hz", "123"),("123.45 Hz", "123.45"),+ ("123.45 kHz", "123450.0"),+ ("kHz", "kHz"),],)def test_strip_common_float_suffixes(value, expected):