From 61f87704f365a363bf8f4e1168389723f9424b0f Mon Sep 17 00:00:00 2001 From: Josiah Oberholtzer Date: Tue, 16 Jan 2024 17:34:45 -0500 Subject: [PATCH] Maintain WeakSet of PatternPlayers --- supriya/patterns/players.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/supriya/patterns/players.py b/supriya/patterns/players.py index 56431784e..a64b76908 100644 --- a/supriya/patterns/players.py +++ b/supriya/patterns/players.py @@ -14,6 +14,7 @@ cast, ) from uuid import UUID, uuid4 +from weakref import WeakSet from ..clocks import BaseClock, CallbackEvent, Clock, ClockContext, OfflineClock from ..contexts import Bus, Context, ContextObject, Node @@ -29,6 +30,8 @@ class PatternPlayer: Coordinates interactions between a pattern, a clock_context, and a clock. """ + _players: WeakSet["PatternPlayer"] = WeakSet() + def __init__( self, pattern: Pattern, @@ -230,6 +233,7 @@ def play( self._queue.put((float("-inf"), Priority.NONE, (0, 0), None)) self._is_running = True self._is_stopping = False + self._players.add(self) self._clock_event_id = self._clock.cue( self._clock_callback, event_type=3, @@ -250,6 +254,7 @@ def stop(self, quantization: Optional[str] = None) -> None: self._clock.cue( self._stop_callback, event_type=2, quantization=quantization ) + self._players.remove(self) def uuid_to_note_id(self, uuid: UUID, index: Optional[int] = None) -> float: if index is not None: