Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raw_value setter for parameters of external plugins #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pedalboard/_pedalboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ def __getattr__(self, name):
if hasattr(super(), "__getattr__"):
return super().__getattr__(name)
raise AttributeError("'{}' has no attribute '{}'".format(base_type.__name__, name))

def __setattr__(self, name, value):
if name == "_wrapped":
return super().__setattr__(name, value)
wrapped = self._wrapped()
if hasattr(wrapped, name):
return setattr(wrapped, name, value)
if hasattr(super(), "__setattr__"):
return super().__setattr__(name, value)
raise AttributeError("'{}' has no attribute '{}'".format(base_type.__name__, name))

def __dir__(self) -> Iterable[str]:
wrapped = self._wrapped()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_external_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def test_bool_parameter_valdation(plugin_filename: str, parameter_name: str):
def test_float_parameters(plugin_filename: str, parameter_name: str):
plugin = load_test_plugin(plugin_filename)
parameter_value = getattr(plugin, parameter_name)
original_raw_value = parameter_value.raw_value
assert repr(parameter_value) == repr(float(parameter_value))
assert isinstance(parameter_value, float)
# Change the parameter and ensure that it does change:
Expand All @@ -695,6 +696,13 @@ def test_float_parameters(plugin_filename: str, parameter_name: str):
continue
assert math.isclose(new_value, getattr(plugin, parameter_name), abs_tol=epsilon * 2.0)

# Ensure that raw value can be set by resetting parameter to original value
setattr(parameter_value, "raw_value", original_raw_value)
assert math.isclose(
original_raw_value,
getattr(parameter_value, "raw_value"),
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:
assert parameter_value.real == float(parameter_value)
Expand Down