Skip to content

Commit

Permalink
Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-wolf-oberholtzer committed Nov 20, 2024
1 parent 3577d5d commit 4e48f17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
17 changes: 12 additions & 5 deletions supriya/mixers/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,21 @@ def _activate(self) -> None:
self._is_active = True

async def _allocate_deep(self, *, context: AsyncServer) -> None:
if self.session is None:
raise RuntimeError
fifo: List[Tuple[Component, int]] = []
synthdefs: Set[SynthDef] = set()
current_synthdefs = self.session._synthdefs[context]
desired_synthdefs: Set[SynthDef] = set()
for component in self._walk():
fifo.append((component, 0))
synthdefs.update(component._get_synthdefs())
for synthdef in sorted(synthdefs, key=lambda x: x.effective_name):
context.add_synthdefs(synthdef)
await context.sync()
desired_synthdefs.update(component._get_synthdefs())
if required_synthdefs := sorted(
desired_synthdefs - current_synthdefs, key=lambda x: x.effective_name
):
for synthdef in required_synthdefs:
context.add_synthdefs(synthdef)
await context.sync()
current_synthdefs.update(required_synthdefs)
while fifo:
component, attempts = fifo.pop(0)
if attempts > 2:
Expand Down
5 changes: 4 additions & 1 deletion supriya/mixers/sessions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import logging
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional, Set

from ..clocks import AsyncClock
from ..contexts import AsyncServer
from ..enums import BootStatus
from ..osc import find_free_port
from ..ugens import SynthDef
from .components import Component

if TYPE_CHECKING:
Expand Down Expand Up @@ -41,6 +42,7 @@ def __init__(self) -> None:
self._mixers: Dict[Mixer, AsyncServer] = {}
self._quit_future: Optional[asyncio.Future] = None
self._status = BootStatus.OFFLINE
self._synthdefs: Dict[AsyncServer, Set[SynthDef]] = {}
# add initial context and mixer
self._contexts[(context := self._add_context())] = [mixer := Mixer(parent=self)]
self._mixers[mixer] = context
Expand All @@ -61,6 +63,7 @@ def __str__(self) -> str:
def _add_context(self) -> AsyncServer:
context = AsyncServer()
self._contexts[context] = []
self._synthdefs[context] = set()
return context

def _delete_mixer(self, mixer) -> None:
Expand Down
3 changes: 3 additions & 0 deletions tests/mixers/test_Track.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from supriya import OscBundle, OscMessage
from supriya.mixers import Session
from supriya.mixers.mixers import Mixer
from supriya.mixers.synthdefs import DEVICE_DC_TESTER_2
from supriya.mixers.tracks import Track, TrackContainer
from supriya.typing import DEFAULT, Default

Expand Down Expand Up @@ -48,6 +49,8 @@ async def test_Track_activate(
[
(
[
OscMessage("/d_recv", DEVICE_DC_TESTER_2.compile()),
OscMessage("/sync", 2),
OscBundle(
contents=(
OscMessage("/g_new", 1014, 1, 1008),
Expand Down

0 comments on commit 4e48f17

Please sign in to comment.