Skip to content

Commit

Permalink
Fix: arbitrary callable functions for midi send
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bubobubobubobubo committed Jun 23, 2024
1 parent 670bd0b commit caa631c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 1 addition & 3 deletions sardine_core/fish_bowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions sardine_core/handlers/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions sardine_core/handlers/superdirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit caa631c

Please sign in to comment.