From 024d3c3124a806a9860869aa7afd43d22134bc52 Mon Sep 17 00:00:00 2001 From: Marek Miller Date: Thu, 27 Oct 2022 22:58:01 +0200 Subject: [PATCH] Add parallel=False flag to Group() --- supriya/realtime/nodes.py | 37 ++++++++++++++++++++++++++++++------- supriya/realtime/servers.py | 8 ++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/supriya/realtime/nodes.py b/supriya/realtime/nodes.py index 799e5639c..541731623 100644 --- a/supriya/realtime/nodes.py +++ b/supriya/realtime/nodes.py @@ -288,7 +288,11 @@ def _unregister_with_local_server(self): ### PUBLIC METHODS ### - def add_group(self, add_action: Optional[AddActionLike] = None) -> "Group": + def add_group( + self, + add_action: Optional[AddActionLike] = None, + parallel: bool = False + ) -> "Group": """ Add a group relative to this node via ``add_action``. @@ -315,7 +319,7 @@ def add_group(self, add_action: Optional[AddActionLike] = None) -> "Group": add_action = AddAction.from_expr(add_action) if add_action not in self._valid_add_actions: raise ValueError("Invalid add action: {add_action}") - group = Group() + group = Group(parallel=parallel) group.allocate(add_action=add_action, target_node=self) return group @@ -544,10 +548,17 @@ class Group(Node, UniqueTreeList): ### INITIALIZER ### - def __init__(self, children=None, name=None, node_id_is_permanent=False): + def __init__( + self, + children=None, + name=None, + node_id_is_permanent=False, + parallel: bool = False, + ): self._control_interface = GroupInterface(client=self) Node.__init__(self, name=name, node_id_is_permanent=node_id_is_permanent) UniqueTreeList.__init__(self, children=children, name=name) + self._parallel = parallel ### SPECIAL METHODS ### @@ -664,9 +675,13 @@ def _collect_requests_and_synthdefs(self, expr, server, start=0): requests.append(request) else: if isinstance(node, Group): - request = supriya.commands.GroupNewRequest( + if node.parallel: + request_method = supriya.commands.ParallelGroupNewRequest + else: + request_method = supriya.commands.GroupNewRequest + request = request_method( items=[ - supriya.commands.GroupNewRequest.Item( + request_method.Item( add_action=add_action, node_id=node, target_node_id=target_node, @@ -759,9 +774,13 @@ def allocate( self._node_id_is_permanent = bool(node_id_is_permanent) target_node = Node._expr_as_target(target_node) server = target_node.server - group_new_request = supriya.commands.GroupNewRequest( + if self._parallel: + request_method = supriya.commands.ParallelGroupNewRequest + else: + request_method = supriya.commands.GroupNewRequest + group_new_request = request_method( items=[ - supriya.commands.GroupNewRequest.Item( + request_method.Item( add_action=AddAction.from_expr(add_action), node_id=self, target_node_id=target_node.node_id, @@ -794,6 +813,10 @@ def prepend(self, expr: Node) -> None: def controls(self) -> GroupInterface: return self._control_interface + @property + def parallel(self) -> bool: + return self._parallel + class Synth(Node): """ diff --git a/supriya/realtime/servers.py b/supriya/realtime/servers.py index d11940e3c..5e36791f1 100644 --- a/supriya/realtime/servers.py +++ b/supriya/realtime/servers.py @@ -964,7 +964,11 @@ def add_bus_group( bus_group.allocate(server=self) return bus_group - def add_group(self, add_action: Optional[AddActionLike] = None) -> Group: + def add_group( + self, + add_action: Optional[AddActionLike] = None, + parallel: bool = False + ) -> Group: """ Add a group relative to the default group via ``add_action``. @@ -986,7 +990,7 @@ def add_group(self, add_action: Optional[AddActionLike] = None) -> Group: """ if self.default_group is None: raise ServerOffline - return self.default_group.add_group(add_action=add_action) + return self.default_group.add_group(add_action=add_action, parallel=parallel) def add_synth( self, synthdef=None, add_action: Optional[AddActionLike] = None, **kwargs