From caa631ca682f238bff1ca68ce319c07bc8bc8c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Forment?= Date: Sun, 23 Jun 2024 22:12:05 +0200 Subject: [PATCH] Fix: arbitrary callable functions for midi send The midi sender allows for arbitrary callable functions as parameters. However, the resolved callables were added to the pattern that ends up being passed to the method in charge of triggering midi notes, causing an error. This fix makes it possible to use any arbitrary callable while dropping the result: it cannot be used meaningfully to alter the midi message. --- sardine_core/fish_bowl.py | 4 +--- sardine_core/handlers/midi.py | 10 +++++++--- sardine_core/handlers/superdirt.py | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sardine_core/fish_bowl.py b/sardine_core/fish_bowl.py index ba0ef8c0..eeff929f 100644 --- a/sardine_core/fish_bowl.py +++ b/sardine_core/fish_bowl.py @@ -77,9 +77,7 @@ def __repr__(self) -> str: status = ( "playing" if running and not paused - else "paused" - if running and paused - else "stopped" + else "paused" if running and paused else "stopped" ) return "<{} {} clock={!r}>".format( diff --git a/sardine_core/handlers/midi.py b/sardine_core/handlers/midi.py index 3bfd2549..992da835 100644 --- a/sardine_core/handlers/midi.py +++ b/sardine_core/handlers/midi.py @@ -201,7 +201,11 @@ def all_notes_off(self): ) async def send_midi_note( - self, note: int, channel: int, velocity: int, duration: float + self, + note: int, + channel: int, + velocity: int, + duration: float, ) -> None: """ Function in charge of handling MIDI note sending. This also includes various @@ -640,8 +644,8 @@ def send( } # Evaluate all potential callables - for key, value in rest_of_pattern.items(): - pattern[key] = _resolve_if_callable(value) + for _, value in rest_of_pattern.items(): + _resolve_if_callable(value) pattern = {**self._defaults, **pattern} deadline = self.env.clock.shifted_time diff --git a/sardine_core/handlers/superdirt.py b/sardine_core/handlers/superdirt.py index 079bac85..4e577540 100644 --- a/sardine_core/handlers/superdirt.py +++ b/sardine_core/handlers/superdirt.py @@ -159,11 +159,13 @@ def rename_keys(initial_dictionary: dict, aliases: dict) -> dict: @alias_param(name="rate", alias="r") def send( self, - sound: Optional[StringElement | List[StringElement]] - | Callable[ - [], - Optional[StringElement | List[StringElement]], - ], + sound: ( + Optional[StringElement | List[StringElement]] + | Callable[ + [], + Optional[StringElement | List[StringElement]], + ] + ), orbit: NumericElement | Callable[[], NumericElement] = 0, iterator: Number | Callable[[], Number] = 0, divisor: NumericElement | Callable[[], NumericElement] = 1,