Skip to content

Commit

Permalink
Add parallel=False flag to Group()
Browse files Browse the repository at this point in the history
  • Loading branch information
mira-merkell committed Nov 8, 2022
1 parent 4fe5e30 commit 024d3c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
37 changes: 30 additions & 7 deletions supriya/realtime/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -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

Expand Down Expand Up @@ -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 ###

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down
8 changes: 6 additions & 2 deletions supriya/realtime/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -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
Expand Down

0 comments on commit 024d3c3

Please sign in to comment.