Skip to content

Commit

Permalink
Maintain WeakSet of PatternPlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
josiah-wolf-oberholtzer committed Jan 16, 2024
1 parent eab193a commit 61f8770
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions supriya/patterns/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 61f8770

Please sign in to comment.