Skip to content

Commit

Permalink
Sketch mixers
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-wolf-oberholtzer committed Nov 20, 2024
1 parent 98bf6de commit 8e1b497
Show file tree
Hide file tree
Showing 21 changed files with 3,910 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ addopts = [
"-rf",
"-vv",
]
asyncio_default_fixture_loop_scope = "function"
doctest_optionflags = [
"ELLIPSIS"
]
Expand Down
3 changes: 2 additions & 1 deletion supriya/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Synth,
)
from .nonrealtime import Score
from .realtime import AsyncServer, BaseServer, Server
from .realtime import AsyncServer, BaseServer, Server, ServerLifecycleEvent

__all__ = [
"AsyncServer",
Expand All @@ -29,5 +29,6 @@
"Node",
"Score",
"Server",
"ServerLifecycleEvent",
"Synth",
]
31 changes: 31 additions & 0 deletions supriya/contexts/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,21 @@ def free(self):
"""
self.context.free_bus_group(self)

def get(
self, sync: bool = True
) -> Union[Awaitable[Optional[Sequence[float]]], Optional[Sequence[float]]]:
"""
Get the control bus group's values.
Emit ``/c_getn`` requests.
:param sync: If true, communicate the request immediately. Otherwise bundle it
with the current request context.
"""
return cast(Union["AsyncServer", "Server"], self.context).get_bus_range(
bus=self[0], count=len(self), sync=sync
)

def map_symbol(self) -> str:
"""
Get the bus group's map symbol.
Expand All @@ -578,6 +593,22 @@ def map_symbol(self) -> str:
return f"c{self.id_}"
raise InvalidCalculationRate

def set(self, values: Union[float, Sequence[float]]) -> None:
"""
Set a range of control buses.
Emit ``/c_setn`` or ``/c_fill`` requests.
:param values: The values to write. If a float is passed, use that as a fill.
"""
if isinstance(values, float):
if len(self) == 1:
self.context.set_bus(bus=self[0], value=values)
else:
self.context.fill_bus_range(bus=self[0], count=len(self), value=values)
else:
self.context.set_bus_range(bus=self[0], values=values)


@dataclasses.dataclass(frozen=True)
class Node(ContextObject):
Expand Down
10 changes: 9 additions & 1 deletion supriya/contexts/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from collections.abc import Sequence as SequenceABC
from typing import (
TYPE_CHECKING,
Any,
Callable,
Coroutine,
Dict,
Iterable,
List,
Expand Down Expand Up @@ -357,7 +359,7 @@ def _validate_moment_timestamp(self, seconds: Optional[float]) -> None:
def on(
self,
event: Union[ServerLifecycleEvent, Iterable[ServerLifecycleEvent]],
callback: Callable[[ServerLifecycleEvent], None],
callback: Callable[[ServerLifecycleEvent], Optional[Coroutine[Any, Any, None]]],
) -> None:
if isinstance(event, ServerLifecycleEvent):
events_ = [event]
Expand Down Expand Up @@ -554,6 +556,9 @@ def _lifecycle(self, owned=True) -> None:

def _on_lifecycle_event(self, event: ServerLifecycleEvent) -> None:
for callback in self._lifecycle_event_callbacks.get(event, []):
logger.info(
self._log_prefix() + f"lifecycle event: {event.name} {callback}"
)
callback(event)

def _setup_notifications(self) -> None:
Expand Down Expand Up @@ -1105,6 +1110,9 @@ async def _lifecycle(self, owned=True) -> None:

async def _on_lifecycle_event(self, event: ServerLifecycleEvent) -> None:
for callback in self._lifecycle_event_callbacks.get(event, []):
logger.info(
self._log_prefix() + f"lifecycle event: {event.name} {callback}"
)
if asyncio.iscoroutine(result := callback(event)):
await result

Expand Down
6 changes: 4 additions & 2 deletions supriya/contexts/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ def from_string(cls, string) -> "QueryTreeGroup":
node_pattern = re.compile(r"^\s*(\d+) (\S+)$")
control_pattern = re.compile(r"\w+: \S+")
lines = string.splitlines()
if not lines[0].startswith("NODE TREE"):
raise ValueError
while not lines[0].startswith("NODE TREE"):
lines.pop(0)
if not lines:
raise ValueError(string)
stack: List[QueryTreeGroup] = [
QueryTreeGroup(node_id=int(lines.pop(0).rpartition(" ")[-1]))
]
Expand Down
3 changes: 3 additions & 0 deletions supriya/mixers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .sessions import Session

__all__ = ["Session"]
Loading

0 comments on commit 8e1b497

Please sign in to comment.