Skip to content

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

Normalize sharps and flats in parameter names. (#58)

Peter Sobot6bc6c30947f3
diff --git a/pedalboard/pedalboard.py b/pedalboard/pedalboard.py
index d2c2dbf..d7b792e 100644
--- a/pedalboard/pedalboard.py
+++ b/pedalboard/pedalboard.py
@@ -495,9 +495,16 @@ def to_python_parameter_name(parameter: _AudioProcessorParameter) -> Optional[st
if not parameter.name and not parameter.label:
return None
- name = parameter.name.lower().strip()
+ name = parameter.name
if parameter.label and not parameter.label.startswith(":"):
- name = "{} {}".format(name, parameter.label.lower())
+ name = "{} {}".format(name, parameter.label)
+ return normalize_python_parameter_name(name)
+
+
+def normalize_python_parameter_name(name: str) -> str:
+ name = name.lower().strip()
+ # Special case: some plugins expose parameters with "#"/"β™―" or "b"/"β™­" in their names.
+ name = name.replace("#", "_sharp").replace("β™―", "_sharp").replace("β™­", "_flat")
# Replace all non-alphanumeric characters with underscores
name = [
c if (c.isalpha() or c.isnumeric()) and c.isprintable() and ord(c) < 128 else "_"
diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.py
index 97f34b6..7f1d014 100644
--- a/tests/test_external_plugins.py
+++ b/tests/test_external_plugins.py
@@ -25,7 +25,11 @@ import platform
from glob import glob
from pathlib import Path
-from pedalboard.pedalboard import WrappedBool, strip_common_float_suffixes
+from pedalboard.pedalboard import (
+ WrappedBool,
+ strip_common_float_suffixes,
+ normalize_python_parameter_name,
+)
import pytest
import pedalboard
import numpy as np
@@ -572,3 +576,16 @@ def test_wrapped_bool(value: bool):
def test_wrapped_bool_requires_bool():
with pytest.raises(TypeError):
assert WrappedBool(None)
+
+
+ "_input,expected",
+ [
+ ("C#", "c_sharp"),
+ ("Bβ™­", "b_flat"),
+ ("Azimuth (ΒΊ)", "azimuth"),
+ ("Normal String", "normal_string"),
+ ],
+)
+def test_parameter_name_normalization(_input: str, expected: str):
+ assert normalize_python_parameter_name(_input) == expected