예제 #1
0
파일: Synth.py 프로젝트: kureta/supriya
 def to_request(self, action, id_mapping, **synth_kwargs):
     from supriya.tools import nonrealtimetools
     source_id = id_mapping[action.source]
     target_id = id_mapping[action.target]
     add_action = action.action
     bus_prototype = (
         nonrealtimetools.Bus,
         nonrealtimetools.BusGroup,
     )
     buffer_prototype = (
         nonrealtimetools.Buffer,
         nonrealtimetools.BufferGroup,
     )
     nonmapping_keys = ['out']
     for key, value in synth_kwargs.items():
         if isinstance(value, bus_prototype):
             bus_id = id_mapping[value]
             if key not in nonmapping_keys:
                 value = value.get_map_symbol(bus_id)
             else:
                 value = bus_id
             synth_kwargs[key] = value
         elif isinstance(value, buffer_prototype):
             synth_kwargs[key] = id_mapping[value]
     request = requesttools.SynthNewRequest(
         add_action=add_action,
         node_id=source_id,
         synthdef=self.synthdef.anonymous_name,
         target_node_id=target_id,
         **synth_kwargs)
     return request
예제 #2
0
파일: NoteEvent.py 프로젝트: kureta/supriya
 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
예제 #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]
예제 #4
0
파일: Synth.py 프로젝트: lisongx/supriya
 def allocate(
     self,
     add_action=None,
     node_id_is_permanent=False,
     sync=True,
     target_node=None,
     **kwargs
     ):
     from supriya.tools import requesttools
     from supriya.tools import servertools
     if self.is_allocated:
         return
     add_action, node_id, target_node_id = Node.allocate(
         self,
         add_action=add_action,
         node_id_is_permanent=node_id_is_permanent,
         target_node=target_node,
         )
     if not self.synthdef.is_allocated:
         self.synthdef.allocate()
     self.controls._set(**kwargs)
     requests = []
     settings, map_requests = self.controls._make_synth_new_settings()
     synth_request = requesttools.SynthNewRequest(
         add_action=add_action,
         node_id=node_id,
         synthdef=self.synthdef,
         target_node_id=target_node_id,
         **settings
         )
     requests.append(synth_request)
     requests.extend(map_requests)
     if self.is_paused:
         pause_request = requesttools.NodeRunRequest(
             [(self.node_id, False)])
         requests.append(pause_request)
     if 1 < len(requests):
         message_bundler = servertools.MessageBundler(
             server=self.server,
             sync=True,
             )
         message_bundler.add_messages(requests)
         message_bundler.add_synchronizing_request(synth_request)
         message_bundler.send_messages()
     else:
         synth_request.communicate(
             server=self.server,
             sync=True,
             )
     return self
예제 #5
0
파일: Group.py 프로젝트: lisongx/supriya
 def _collect_requests_and_synthdefs(self, expr, start=0):
     from supriya.tools import requesttools
     from supriya.tools import servertools
     nodes = set()
     paused_nodes = set()
     synthdefs = set()
     requests = []
     iterator = Group._iterate_setitem_expr(self, expr, start)
     for node, target_node, add_action in iterator:
         nodes.add(node)
         if node.is_allocated:
             if add_action == servertools.AddAction.ADD_TO_HEAD:
                 request = requesttools.GroupHeadRequest(
                     node_id_pairs=requesttools.NodeIdPair(
                         node_id=node,
                         target_node_id=target_node,
                     ), )
             else:
                 request = requesttools.NodeAfterRequest(
                     node_id_pairs=requesttools.NodeIdPair(
                         node_id=node,
                         target_node_id=target_node,
                     ), )
             requests.append(request)
         else:
             node._register_with_local_server(server=self.server)
             if isinstance(node, servertools.Group):
                 request = requesttools.GroupNewRequest(
                     add_action=add_action,
                     node_id=node,
                     target_node_id=target_node,
                 )
                 requests.append(request)
             else:
                 if not node.synthdef.is_allocated:
                     synthdefs.add(node.synthdef)
                 settings, map_requests = \
                     node.controls._make_synth_new_settings()
                 request = requesttools.SynthNewRequest(
                     add_action=add_action,
                     node_id=node,
                     synthdef=node.synthdef,
                     target_node_id=target_node,
                     **settings)
                 requests.append(request)
                 requests.extend(map_requests)
             if node.is_paused:
                 paused_nodes.add(node)
     return nodes, paused_nodes, requests, synthdefs