예제 #1
0
 def _register_with_local_server(
     self,
     server=None,
     ):
     ServerObjectProxy.allocate(self, server=server)
     synthdef_name = self.actual_name
     self.server._synthdefs[synthdef_name] = self
예제 #2
0
파일: SynthDef.py 프로젝트: lisongx/supriya
 def _register_with_local_server(
     self,
     server=None,
 ):
     ServerObjectProxy.allocate(self, server=server)
     synthdef_name = self.actual_name
     self.server._synthdefs[synthdef_name] = self
예제 #3
0
 def _register_with_local_server(self, server):
     ServerObjectProxy.allocate(
         self,
         server=server,
     )
     allocator = self.server.buffer_allocator
     buffer_id = allocator.allocate(len(self))
     if buffer_id is None:
         ServerObjectProxy.free(self)
         raise ValueError
     self._buffer_id = buffer_id
     for buffer_ in self:
         buffer_._register_with_local_server()
     return buffer_id
예제 #4
0
 def _register_with_local_server(self, server):
     ServerObjectProxy.allocate(
         self,
         server=server,
         )
     allocator = self.server.buffer_allocator
     buffer_id = allocator.allocate(len(self))
     if buffer_id is None:
         ServerObjectProxy.free(self)
         raise ValueError
     self._buffer_id = buffer_id
     for buffer_ in self:
         buffer_._register_with_local_server()
     return buffer_id
예제 #5
0
    def allocate(self, server=None, sync=False):
        from supriya.tools import servertools

        if self.is_allocated:
            return
        ServerObjectProxy.allocate(self, server=server)
        allocator = servertools.Bus._get_allocator(calculation_rate=self.calculation_rate, server=self.server)
        bus_id = allocator.allocate(len(self))
        if bus_id is None:
            ServerObjectProxy.free(self)
            raise ValueError
        self._bus_id = bus_id
        if sync:
            self.server.sync()
        return self
예제 #6
0
 def allocate(
     self,
     server=None,
     sync=False,
     ):
     from supriya.tools import servertools
     if self.is_allocated:
         return
     ServerObjectProxy.allocate(self, server=server)
     allocator = servertools.Bus._get_allocator(
         calculation_rate=self.calculation_rate,
         server=self.server,
         )
     bus_id = allocator.allocate(len(self))
     if bus_id is None:
         ServerObjectProxy.free(self)
         raise ValueError
     self._bus_id = bus_id
     if sync:
         self.server.sync()
     return self
예제 #7
0
파일: Node.py 프로젝트: digideskio/supriya
 def _register_with_local_server(
     self,
     node_id_is_permanent=False,
     server=None,
     ):
     if server is None or not server.is_running:
         raise ValueError(self)
     if self.server is not None or self in server._nodes:
         return
     id_allocator = server.node_id_allocator
     if node_id_is_permanent:
         node_id = id_allocator.allocate_permanent_node_id()
     else:
         node_id = server.node_id_allocator.allocate_node_id()
     if node_id is None:
         raise ValueError(self)
     elif node_id in server._nodes:
         raise ValueError(self)
     ServerObjectProxy.allocate(self, server=server)
     self._node_id = node_id
     self._node_id_is_permanent = bool(node_id_is_permanent)
     self._server._nodes[self._node_id] = self
     return node_id
예제 #8
0
 def _register_with_local_server(
     self,
     node_id_is_permanent=False,
     server=None,
 ):
     if server is None or not server.is_running:
         raise ValueError(self)
     if self.server is not None or self in server._nodes:
         return
     id_allocator = server.node_id_allocator
     if node_id_is_permanent:
         node_id = id_allocator.allocate_permanent_node_id()
     else:
         node_id = server.node_id_allocator.allocate_node_id()
     if node_id is None:
         raise ValueError(self)
     elif node_id in server._nodes:
         raise ValueError(self)
     ServerObjectProxy.allocate(self, server=server)
     self._node_id = node_id
     self._node_id_is_permanent = bool(node_id_is_permanent)
     self._server._nodes[self._node_id] = self
     return node_id
예제 #9
0
파일: Bus.py 프로젝트: lisongx/supriya
 def allocate(
     self,
     server=None,
     sync=False,
     ):
     if self.bus_group is not None:
         return
     if self.is_allocated:
         return
     ServerObjectProxy.allocate(self, server=server)
     if self.bus_id is None:
         allocator = self._get_allocator(
             calculation_rate=self.calculation_rate,
             server=self.server,
             )
         bus_id = allocator.allocate(1)
         if bus_id is None:
             ServerObjectProxy.free(self)
             raise ValueError
         self._bus_id = bus_id
     if sync:
         self.server.sync()
     return self
예제 #10
0
    def allocate_from_file(
        self,
        file_path,
        channel_indices=None,
        completion_message=None,
        frame_count=None,
        server=None,
        starting_frame=None,
        sync=True,
        ):
        r'''Allocates buffer on `server` with contents read from `file_path`.

        ::

            >>> buffer_one = servertools.Buffer().allocate_from_file(
            ...     systemtools.Assets['pulse_44100sr_16bit_octo.wav'],
            ...     )
            >>> buffer_one.query()
            BufferInfoResponse(
                buffer_id=0,
                frame_count=8,
                channel_count=8,
                sample_rate=44100.0
                )

        ::

            >>> buffer_two = servertools.Buffer().allocate_from_file(
            ...     systemtools.Assets['pulse_44100sr_16bit_octo.wav'],
            ...     channel_indices=(3, 4),
            ...     frame_count=4,
            ...     starting_frame=1,
            ...     sync=True,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                buffer_id=1,
                frame_count=4,
                channel_count=2,
                sample_rate=44100.0
                )

        ::

            >>> for frame_id in range(buffer_two.frame_count):
            ...     buffer_two.get_frame(frame_id).as_dict()
            ...
            OrderedDict([(0, (0.0, 0.0))])
            OrderedDict([(2, (0.0, 0.0))])
            OrderedDict([(4, (0.999969482421875, 0.0))])
            OrderedDict([(6, (0.0, 0.999969482421875))])

        ::

            >>> buffer_one.free()
            >>> buffer_two.free()

        Returns buffer.
        '''
        if self.buffer_group is not None:
            return
        if self.is_allocated:
            return
        try:
            ServerObjectProxy.allocate(
                self,
                server=server,
                )
            self._allocate_buffer_id()
            self._register_with_local_server()
            request = self._register_with_remote_server(
                frame_count=frame_count,
                channel_indices=channel_indices,
                file_path=file_path,
                starting_frame=starting_frame,
                )
            request.communicate(
                server=self.server,
                sync=sync,
                )
        except:
            ServerObjectProxy.allocate(self, server=server)
        return self
예제 #11
0
    def allocate(
        self,
        channel_count=1,
        frame_count=1,
        server=None,
        sync=True,
        ):
        r'''Allocates buffer on `server`.

        ::

            >>> buffer_one = servertools.Buffer().allocate()
            >>> buffer_one.query()
            BufferInfoResponse(
                buffer_id=0,
                frame_count=1,
                channel_count=1,
                sample_rate=44100.0
                )

        ::

            >>> buffer_two = servertools.Buffer().allocate(
            ...     frame_count=16,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                buffer_id=1,
                frame_count=16,
                channel_count=1,
                sample_rate=44100.0
                )

        ::

            >>> buffer_three = servertools.Buffer().allocate(
            ...     channel_count=2,
            ...     frame_count=32,
            ...     )
            >>> buffer_three.query()
            BufferInfoResponse(
                buffer_id=2,
                frame_count=32,
                channel_count=2,
                sample_rate=44100.0
                )

        ::

            >>> buffer_one.free()
            >>> buffer_two.free()
            >>> buffer_three.free()

        Returns buffer.
        '''
        if self.buffer_group is not None:
            return
        if self.is_allocated:
            return
        try:
            ServerObjectProxy.allocate(
                self,
                server=server,
                )
            channel_count = int(channel_count)
            frame_count = int(frame_count)
            assert 0 < channel_count
            assert 0 < frame_count
            self._allocate_buffer_id()
            self._register_with_local_server()
            request = self._register_with_remote_server(
                channel_count=channel_count,
                frame_count=frame_count,
                )
            request.communicate(
                server=self.server,
                sync=sync,
                )
        except:
            self.free()
        return self
예제 #12
0
    def allocate_from_file(
        self,
        file_path,
        channel_indices=None,
        completion_message=None,
        frame_count=None,
        server=None,
        starting_frame=None,
        sync=True,
    ):
        """
        Allocates buffer on `server` with contents read from `file_path`.

        ::

            >>> buffer_one = servertools.Buffer().allocate_from_file(
            ...     systemtools.Assets['pulse_44100sr_16bit_octo.wav'],
            ...     )
            >>> buffer_one.query()
            BufferInfoResponse(
                buffer_id=0,
                frame_count=8,
                channel_count=8,
                sample_rate=44100.0
                )

        ::

            >>> buffer_two = servertools.Buffer().allocate_from_file(
            ...     systemtools.Assets['pulse_44100sr_16bit_octo.wav'],
            ...     channel_indices=(3, 4),
            ...     frame_count=4,
            ...     starting_frame=1,
            ...     sync=True,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                buffer_id=1,
                frame_count=4,
                channel_count=2,
                sample_rate=44100.0
                )

        ::

            >>> for frame_id in range(buffer_two.frame_count):
            ...     buffer_two.get_frame(frame_id).as_dict()
            ...
            OrderedDict([(0, (0.0, 0.0))])
            OrderedDict([(2, (0.0, 0.0))])
            OrderedDict([(4, (0.999969482421875, 0.0))])
            OrderedDict([(6, (0.0, 0.999969482421875))])

        ::

            >>> buffer_one.free()
            >>> buffer_two.free()

        Returns buffer.
        """
        if self.buffer_group is not None:
            return
        if self.is_allocated:
            return
        try:
            ServerObjectProxy.allocate(
                self,
                server=server,
            )
            self._allocate_buffer_id()
            self._register_with_local_server()
            request = self._register_with_remote_server(
                frame_count=frame_count,
                channel_indices=channel_indices,
                file_path=file_path,
                starting_frame=starting_frame,
            )
            request.communicate(
                server=self.server,
                sync=sync,
            )
        except:
            ServerObjectProxy.allocate(self, server=server)
        return self
예제 #13
0
    def allocate(
        self,
        channel_count=1,
        frame_count=1,
        server=None,
        sync=True,
    ):
        """
        Allocates buffer on `server`.

        ::

            >>> buffer_one = servertools.Buffer().allocate()
            >>> buffer_one.query()
            BufferInfoResponse(
                buffer_id=0,
                frame_count=1,
                channel_count=1,
                sample_rate=44100.0
                )

        ::

            >>> buffer_two = servertools.Buffer().allocate(
            ...     frame_count=16,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                buffer_id=1,
                frame_count=16,
                channel_count=1,
                sample_rate=44100.0
                )

        ::

            >>> buffer_three = servertools.Buffer().allocate(
            ...     channel_count=2,
            ...     frame_count=32,
            ...     )
            >>> buffer_three.query()
            BufferInfoResponse(
                buffer_id=2,
                frame_count=32,
                channel_count=2,
                sample_rate=44100.0
                )

        ::

            >>> buffer_one.free()
            >>> buffer_two.free()
            >>> buffer_three.free()

        Returns buffer.
        """
        if self.buffer_group is not None:
            return
        if self.is_allocated:
            return
        try:
            ServerObjectProxy.allocate(
                self,
                server=server,
            )
            channel_count = int(channel_count)
            frame_count = int(frame_count)
            assert 0 < channel_count
            assert 0 < frame_count
            self._allocate_buffer_id()
            self._register_with_local_server()
            request = self._register_with_remote_server(
                channel_count=channel_count,
                frame_count=frame_count,
            )
            request.communicate(
                server=self.server,
                sync=sync,
            )
        except:
            self.free()
        return self