diff --git a/pedalboard/_pedalboard.py b/pedalboard/_pedalboard.py index 2453f76f..9d16ddcd 100644 --- a/pedalboard/_pedalboard.py +++ b/pedalboard/_pedalboard.py @@ -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() diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.py index 1dbd110c..70bba8a7 100644 --- a/tests/test_external_plugins.py +++ b/tests/test_external_plugins.py @@ -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: @@ -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)