def _build_stop_bundle( self, index, synth_uuid, synthdef, timestamp, uuids, ): from supriya.tools import patterntools duration = self['duration'] if duration is None: duration = 1 requests = [] timestamp = timestamp + duration node_ids = sorted(uuids[synth_uuid]) if synthdef.has_gate: for node_id in node_ids: request = requesttools.NodeSetRequest( node_id=node_id, gate=0, ) requests.append(request) else: request = requesttools.NodeFreeRequest(node_ids=node_ids, ) requests.append(request) event_product = patterntools.EventProduct( event=self, index=index, is_stop=True, requests=requests, timestamp=timestamp, uuid=synth_uuid, ) return event_product
def _perform_realtime( self, index=0, server=None, timestamp=0, uuids=None, ): from supriya.tools import patterntools bus_uuid = self.get('uuid') or uuid.uuid4() calculation_rate = self.get('calculation_rate') channel_count = self.get('channel_count') or 1 if not self.get('is_stop'): bus_group = servertools.BusGroup( bus_count=channel_count, calculation_rate=calculation_rate, ) allocator = servertools.Bus._get_allocator( calculation_rate=calculation_rate, server=server, ) bus_id = allocator.allocate(channel_count) uuids[bus_uuid] = { bus_id: bus_group, } else: pass event_product = patterntools.EventProduct( event=self, index=index, is_stop=self.get('is_stop'), requests=[], timestamp=timestamp, uuid=self['uuid'], ) return [event_product]
def _perform_realtime( self, index=0, server=None, timestamp=0, uuids=None, ): from supriya import synthdefs from supriya.tools import patterntools synth_uuid = self.get('uuid') or uuid.uuid4() synthdef = self.get('synthdef', synthdefs.default) do_not_release = self.get('_do_not_release') duration = self['duration'] if duration is None: duration = 1 dictionaries = self._expand(self.settings, synthdef, uuids) first_visit = False if synth_uuid not in uuids: first_visit = True node_ids = { server.node_id_allocator.allocate_node_id(): None for _ in range(len(dictionaries)) } uuids[synth_uuid] = node_ids start_product = self._build_start_bundle( dictionaries, first_visit, index, synth_uuid, synthdef, timestamp, uuids, ) if self.get('duration'): if not do_not_release: stop_product = self._build_stop_bundle( index, synth_uuid, synthdef, timestamp, uuids, ) else: stop_product = patterntools.EventProduct( event=None, index=index, is_stop=True, requests=(), timestamp=timestamp + duration, uuid=None, ) return [start_product, stop_product] else: uuids.pop(synth_uuid) return [start_product]
def _build_start_bundle( self, dictionaries, first_visit, index, synth_uuid, synthdef, timestamp, uuids, ): from supriya.tools import patterntools requests = [] node_ids = uuids[synth_uuid] if first_visit: for node_id, dictionary in zip(node_ids, dictionaries): add_action = dictionary.pop('add_action') target_node = dictionary.pop('target_node') if target_node is None: target_node = 1 synth_kwargs = { key: value for key, value in dictionary.items() if key in synthdef.parameter_names } request = requesttools.SynthNewRequest( add_action=add_action, node_id=node_id, synthdef=synthdef, target_node_id=target_node, **synth_kwargs) requests.append(request) synth = servertools.Synth(synthdef) node_ids[node_id] = synth else: for node_id, dictionary in zip(node_ids, dictionaries): synth_kwargs = { key: value for key, value in dictionary.items() if key in synthdef.parameter_names } request = requesttools.NodeSetRequest(node_id=node_id, **synth_kwargs) requests.append(request) event_product = patterntools.EventProduct( event=self, index=index, is_stop=False, requests=requests, timestamp=timestamp, uuid=synth_uuid, ) return event_product
def _perform_realtime( self, index=0, server=None, timestamp=0, uuids=None, ): # TODO: Should this handle multichannel expansion? from supriya import synthdefs from supriya.tools import patterntools node_uuid = self.get('uuid') or uuid.uuid4() requests = [] synthdef = self.get('synthdef') or synthdefs.default if not self.get('is_stop'): target_node_id = self.get('target_node') if not target_node_id: target_node_id = 1 elif isinstance(target_node_id, uuid.UUID): target_node_id = list(uuids[target_node_id])[0] add_action = self.get('add_action') dictionaries = self._expand( self.settings, synthdef, uuids, realtime=False, synth_parameters_only=True, ) synths = uuids[node_uuid] = {} for dictionary in dictionaries: node_id = server.node_id_allocator.allocate_node_id() synth = servertools.Synth(synthdef, **dictionary) synths[node_id] = synth request = requesttools.SynthNewRequest( add_action=add_action, node_id=node_id, target_node_id=target_node_id, synthdef=synthdef, **dictionary) requests.append(request) else: request = requesttools.NodeFreeRequest(node_ids=sorted( uuids[node_uuid]), ) requests.append(request) event_product = patterntools.EventProduct( event=self, index=index, is_stop=self.get('is_stop'), requests=requests, timestamp=timestamp, uuid=self['uuid'], ) return [event_product]
def _perform_realtime( self, index=0, server=None, timestamp=0, uuids=None, ): from supriya.tools import patterntools node_uuid = self.get('uuid') or uuid.uuid4() requests = [] if not self.get('is_stop'): node_id = server.node_id_allocator.allocate_node_id() uuids[node_uuid] = {node_id: servertools.Group()} target_node_id = self.get('target_node') if not target_node_id: target_node_id = 1 elif isinstance(target_node_id, uuid.UUID): target_node_id = list(uuids[target_node_id])[0] add_action = self.get('add_action') request = requesttools.GroupNewRequest( add_action=add_action, node_id=node_id, target_node_id=target_node_id, ) else: request = requesttools.NodeFreeRequest( node_ids=sorted(uuids[node_uuid]), ) requests.append(request) event_product = patterntools.EventProduct( event=self, index=index, is_stop=self.get('is_stop'), requests=requests, timestamp=timestamp, uuid=self['uuid'], ) return [event_product]