Skip to content

Commit

Permalink
parameters.abc += Parameter
Browse files Browse the repository at this point in the history
In 56c7480 I already added an abstract base class for the
parameter type. But in 1bd0c31 this class was removed again.
There was a discussion in #11 if it makes sense
to have an empty class.

Nowadays we can assume that it *does* make sense to do so:

- after the introduction of 'MutwoObject' all parameters should inherit
  from this: by using a common parent class this necessity can be
  simplified and be more reliable

- for type hints, in case we really do only accept mutwo parameters (and
  not any object as it's often ok too), we can use the 'abc.Parameter'
  class. In mutwo.core < 2.0.0 we used to have
  'core_constants.ParameterType', but this rather made the situation
  more complicated. By simply using either 'typing.Any' or 'abc.Parameter'
  it's clear what is expected
  • Loading branch information
levinericzimmermann committed Nov 21, 2023
1 parent 64e33e0 commit c711348
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions mutwo/core_parameters/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from mutwo import core_utilities

__all__ = (
"Parameter",
"SingleValueParameter",
"SingleNumberParameter",
"ParameterWithEnvelope",
Expand All @@ -40,7 +41,16 @@
)


class ParameterWithEnvelope(core_utilities.MutwoObject, abc.ABC):
class Parameter(core_utilities.MutwoObject, abc.ABC):
"""A Parameter is the base class for all mutwo parameters
It can be useful as a type hint for any code where a parameter
object is expected. This isn't necessarily at many places,
as mostly any object can be assigned as a parameter to an event.
"""


class ParameterWithEnvelope(Parameter):
"""Abstract base class for all parameters with an envelope."""

def __init__(self, envelope: core_events.RelativeEnvelope):
Expand Down Expand Up @@ -75,7 +85,7 @@ def resolve_envelope(
return self.envelope.resolve(duration, self, resolve_envelope_class)


class SingleValueParameter(core_utilities.MutwoObject, abc.ABC):
class SingleValueParameter(Parameter):
"""Abstract base class for all parameters which are defined by one value.
Classes which inherit from this base class have
Expand Down Expand Up @@ -318,7 +328,7 @@ def duration(self, duration: core_constants.Real):
DurationOrReal = Duration | core_constants.Real


class TempoPoint(core_utilities.MutwoObject, abc.ABC):
class TempoPoint(Parameter):
"""Represent the active tempo at a specific moment in time.
If the user wants to define a `TempoPoint` class, the abstract
Expand Down

0 comments on commit c711348

Please sign in to comment.