From 2c73955e0e4f9e86a36b355e7262ba593ee1cbc6 Mon Sep 17 00:00:00 2001 From: Levin Eric Zimmermann Date: Wed, 20 Mar 2024 19:33:36 +0100 Subject: [PATCH] events: Drop 'RelativeEnvelope' This event has been added in https://github.com/mutwo-org/mutwo.core/commit/9f601a85ceb2adfe42d23bb5a8371981f9f113d1 in order to support glissandi (introduced few commits later in https://github.com/mutwo-org/mutwo.core/commit/df609dcf1900b3543908239b56af88e38d965f23). With recent patch https://github.com/mutwo-org/mutwo.core/commit/05a919c93d8ba9ce69a8a3328d45d4144c7ea296 that aims to unify the way how continuous/dynamic parameters are treated, we would also no longer need 'RelativeEnvelope' for glissandi (once 'mutwo.music' has been adjusted to 'mutwo.core >= 2.0.0'), because glissandi would be described by absolute points. Now, even if we later on re-introduce generic relative parameters, we may not necessarily need a 'RelativeEnvelope' class as this only provides the small '.resolve' method that perhaps could also be re-written in a better way. --- mutwo/core_events/envelopes.py | 54 +-------------------------------- tests/events/envelopes_tests.py | 18 ----------- 2 files changed, 1 insertion(+), 71 deletions(-) diff --git a/mutwo/core_events/envelopes.py b/mutwo/core_events/envelopes.py index e359cdb6..2aa5ccc0 100644 --- a/mutwo/core_events/envelopes.py +++ b/mutwo/core_events/envelopes.py @@ -32,7 +32,7 @@ from mutwo import core_utilities -__all__ = ("Envelope", "RelativeEnvelope") +__all__ = ("Envelope",) T = typing.TypeVar("T", bound=core_events.abc.Event) @@ -745,55 +745,3 @@ def add(s, value): add(s, v) return segment_tuple - - -class RelativeEnvelope(Envelope, typing.Generic[T]): - """Envelope with relative durations and values / parameters. - - :param *args: Argument of :class:`Envelope`. - :param base_parameter_and_relative_parameter_to_absolute_parameter: A function", - which runs when the :func:`resolve` is called. It expects the base parameter", - and the relative parameter (which is extracted from the envelope events)", - and should return an absolute parameter.", - :param **kwargs: Keyword arguments of :class:`Envelope`. - - The :class:`RelativeEnvelope` adds the :func:`resolve` method to the base - class :class:`Envelope`.", - """ - - def __init__( - self, - *args, - base_parameter_and_relative_parameter_to_absolute_parameter: typing.Callable[ - [typing.Any, typing.Any], - typing.Any, - ], - **kwargs, - ): - self.base_parameter_and_relative_parameter_to_absolute_parameter = ( - base_parameter_and_relative_parameter_to_absolute_parameter - ) - super().__init__(*args, **kwargs) - - def resolve( - self, - duration: "core_parameters.abc.Duration.Type", - base_parameter: typing.Any, - resolve_envelope_class: type[Envelope] = Envelope, - ) -> Envelope: - dur = core_parameters.abc.Duration.from_any(duration) - plist = [] - try: - fact = dur / self.duration - except ZeroDivisionError: - fact = core_parameters.DirectDuration(0) - for abst, e in zip(self.absolute_time_tuple, self): - rel_param = self.event_to_parameter(e) - new_param = ( - self.base_parameter_and_relative_parameter_to_absolute_parameter( - base_parameter, rel_param - ) - ) - p = (abst * fact, new_param, self.event_to_curve_shape(e)) - plist.append(p) - return resolve_envelope_class(plist) diff --git a/tests/events/envelopes_tests.py b/tests/events/envelopes_tests.py index 8081acac..9e67060f 100644 --- a/tests/events/envelopes_tests.py +++ b/tests/events/envelopes_tests.py @@ -352,23 +352,5 @@ def test_extend_until(self): ) -class RelativeEnvelopeTest(unittest.TestCase): - def setUp(cls): - cls.envelope = core_events.RelativeEnvelope( - [ - [0, 0], - [5, 5], - [10, 10], - ], - base_parameter_and_relative_parameter_to_absolute_parameter=lambda base_parameter, relative_parameter: base_parameter - + relative_parameter, - ) - - def test_resolve(self): - resolved_envelope = self.envelope.resolve(duration=1, base_parameter=100) - self.assertEqual(resolved_envelope.duration, core_parameters.DirectDuration(1)) - self.assertEqual(resolved_envelope.value_tuple, (100, 105, 110)) - - if __name__ == "__main__": unittest.main()