Beispiel #1
0
 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
Beispiel #2
0
 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)
Beispiel #3
0
 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]
Beispiel #4
0
 def free(self):
     from supriya.tools import requesttools
     self._set_parent(None)
     server = self.server
     if self.node_id is not None and server.is_running:
         node_id = self._unregister_with_local_server()
         node_free_request = requesttools.NodeFreeRequest(
             node_ids=(node_id, ), )
         node_free_request.communicate(
             server=server,
             sync=False,
         )
     return self
Beispiel #5
0
 def __call__(self, execution_time, scheduled_time, communicate=True):
     if self._iterator is None:
         self._iterator = self._iterate_outer(
             pattern=self._pattern,
             server=self._server,
             timestamp=scheduled_time,
             uuids=self._uuids,
         )
     event_products, delta = next(self._iterator)
     node_free_ids, requests = set(), []
     for event_product in event_products:
         if not event_product.event:
             continue
         for request in event_product.requests:
             if isinstance(request, requesttools.NodeFreeRequest):
                 node_free_ids.update(request.node_ids)
             else:
                 requests.append(request)
         if event_product.is_stop:
             proxies = self._uuids[event_product.uuid]
             for proxy_id, proxy in proxies.items():
                 if isinstance(proxy, (
                         servertools.Bus,
                         servertools.BusGroup,
                 )):
                     allocator = servertools.Bus._get_allocator(
                         calculation_rate=proxy.calculation_rate,
                         server=self._server,
                     )
                     allocator.free(proxy_id)
             self._uuids.pop(event_product.uuid)
     if node_free_ids:
         node_free_ids = sorted(node_free_ids)
         request = requesttools.NodeFreeRequest(node_ids=node_free_ids)
         requests.append(request)
     consolidated_bundle = requesttools.RequestBundle(
         timestamp=scheduled_time,
         contents=requests,
     )
     if communicate:
         osc_bundle = consolidated_bundle.to_osc_bundle()
         osc_bundle = new(
             osc_bundle,
             timestamp=osc_bundle.timestamp + self._server.latency,
         )
         self._server.send_message(osc_bundle)
         return delta
     return consolidated_bundle, delta
Beispiel #6
0
    def _set_allocated(self, expr, start, stop):
        from supriya.tools import requesttools
        from supriya.tools import servertools

        old_nodes = self._children[start:stop]
        self._children.__delitem__(slice(start, stop))
        for old_node in old_nodes:
            old_node._set_parent(None)
        for child in expr:
            if child in self and self.index(child) < start:
                start -= 1
            child._set_parent(self)
        self._children.__setitem__(slice(start, start), expr)

        new_nodes, paused_nodes, requests, synthdefs = \
            self._collect_requests_and_synthdefs(expr, start)
        self._allocate_synthdefs(synthdefs)

        old_node_ids = []
        for old_node in old_nodes:
            if old_node in new_nodes:
                continue
            old_node_id = old_node._unregister_with_local_server()
            old_node._set_parent(None)
            old_node_ids.append(old_node_id)
            #if isinstance(old_node, servertools.Group):
            #    for old_node_child in Group._iterate_children(old_node):
            #        old_node_child._unregister_with_local_server()
        if old_node_ids:
            node_free_request = requesttools.NodeFreeRequest(
                node_ids=old_node_ids, )
            requests.insert(0, node_free_request)

        if paused_nodes:
            pairs = sorted((node.node_id, False) for node in paused_nodes)
            request = requesttools.NodeRunRequest(
                node_id_run_flag_pairs=pairs, )
            requests.append(request)

        message_bundler = servertools.MessageBundler(
            server=self.server,
            sync=True,
        )
        message_bundler.add_messages(requests)
        message_bundler.send_messages()
Beispiel #7
0
 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]
Beispiel #8
0
 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