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 _collect_stop_requests(self): from supriya.tools import nonrealtimetools requests = [] gated_node_ids = [] freed_node_ids = [] for _, proxy_ids in self._uuids.items(): for proxy_id, proxy in proxy_ids.items(): if not isinstance(proxy, servertools.Node): continue if (isinstance(proxy, nonrealtimetools.Synth) and proxy.synthdef.has_gate): gated_node_ids.append(proxy_id) else: freed_node_ids.append(proxy_id) if freed_node_ids: request = requesttools.NodeFreeRequest( node_ids=sorted(freed_node_ids), ) requests.append(request) for node_id in sorted(gated_node_ids): request = requesttools.NodeSetRequest( node_id=node_id, gate=0, ) requests.append(request) if not requests: return return requesttools.RequestBundle(contents=requests)
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 _collect_node_set_requests(self, id_mapping, node_settings): from supriya.tools import nonrealtimetools requests = [] bus_prototype = ( nonrealtimetools.Bus, nonrealtimetools.BusGroup, type(None), ) buffer_prototype = ( nonrealtimetools.Buffer, nonrealtimetools.BufferGroup, ) for node, settings in node_settings.items(): node_id = id_mapping[node] a_settings = {} c_settings = {} n_settings = {} for key, value in settings.items(): if isinstance(value, bus_prototype): if value is None: c_settings[key] = -1 elif value.calculation_rate == servertools.CalculationRate.CONTROL: c_settings[key] = id_mapping[value] else: a_settings[key] = id_mapping[value] else: if isinstance(value, buffer_prototype): value = id_mapping[value] n_settings[key] = value if n_settings: request = requesttools.NodeSetRequest(node_id=node_id, **n_settings) requests.append(request) if a_settings: request = requesttools.NodeMapToAudioBusRequest( node_id=node_id, **a_settings) requests.append(request) if c_settings: request = requesttools.NodeMapToControlBusRequest( node_id=node_id, **c_settings) requests.append(request) # separate out floats, control buses and audio buses return requests
def _set(self, **settings): from supriya.tools import requesttools from supriya.tools import servertools from supriya.tools import synthdeftools n_set_settings = {} n_map_settings = {} n_mapa_settings = {} for control_name, value in settings.items(): control = self[control_name] if isinstance(value, (int, float)): n_set_settings[control_name] = value control._set_to_number(value) elif isinstance(value, servertools.Bus): if value.calculation_rate == synthdeftools.CalculationRate.CONTROL: n_map_settings[control_name] = value else: n_mapa_settings[control_name] = value control._map_to_bus(value) elif value is None: n_map_settings[control_name] = -1 control._unmap() else: raise ValueError(value) messages = [] if self.client.is_allocated: if n_set_settings: request = requesttools.NodeSetRequest(self.node_id, **n_set_settings) message = request.to_osc_message() messages.append(message) if n_map_settings: request = requesttools.NodeMapToControlBusRequest( self.node_id, **n_map_settings) message = request.to_osc_message() messages.append(message) if n_mapa_settings: request = requesttools.NodeMapToAudioBusRequest( self.node_id, **n_mapa_settings) message = request.to_osc_message() messages.append(message) return tuple(messages)
def set(self, expr): from supriya.tools import requesttools from supriya.tools import servertools from supriya.tools import synthdeftools if isinstance(expr, servertools.Bus): self._map_to_bus(expr) if expr.calculation_rate == synthdeftools.CalculationRate.CONTROL: request = requesttools.NodeMapToControlBusRequest( self.node, **{self.name: self._value}) else: request = requesttools.NodeMapToAudioBusRequest( self.node, **{self.name: self._value}) elif expr is None: self._unmap() request = requesttools.NodeMapToControlBusRequest( self.node, **{self.name: -1}) else: self._set_to_number(expr) request = requesttools.NodeSetRequest(self.node, **{self.name: self._value}) if self.node.is_allocated: request.communicate(server=self.node.server)
def set(self, expr): from supriya.tools import requesttools from supriya.tools import servertools from supriya.tools import synthdeftools if isinstance(expr, servertools.Bus): if expr.calculation_rate == synthdeftools.CalculationRate.CONTROL: request = requesttools.NodeMapToControlBusRequest( self.node, **{self.name: expr} ) else: request = requesttools.NodeMapToAudioBusRequest( self.node, **{self.name: expr} ) else: expr = float(expr) request = requesttools.NodeSetRequest( self.node, **{self.name: expr} ) if self.node.is_allocated: request.communicate(server=self.node.server)
def _collect_node_free_requests(self, id_mapping, stop_nodes): requests = [] if stop_nodes: free_ids, gate_ids = [], [] for node in stop_nodes: node_id = id_mapping[node] if hasattr(node, 'synthdef') and \ 'gate' in node.synthdef.parameter_names: gate_ids.append(node_id) elif node.duration: free_ids.append(node_id) free_ids.sort() gate_ids.sort() if free_ids: request = requesttools.NodeFreeRequest(node_ids=free_ids) requests.append(request) if gate_ids: for node_id in gate_ids: request = requesttools.NodeSetRequest( node_id=node_id, gate=0, ) requests.append(request) return requests