Exemple #1
0
 def _allocate_buffer_id(self):
     if self.buffer_id is None:
         buffer_id = self.server.buffer_allocator.allocate(1)
         if buffer_id is None:
             ServerObject.free(self)
             raise ValueError
         self._buffer_id = buffer_id
 def _allocate_buffer_id(self):
     if self.buffer_id is None:
         buffer_id = self.server.buffer_allocator.allocate(1)
         if buffer_id is None:
             ServerObject.free(self)
             raise ValueError
         self._buffer_id = buffer_id
Exemple #3
0
    def __init__(self, buffer_count=1):
        import supriya.realtime

        ServerObject.__init__(self)
        self._buffer_id = None
        buffer_count = int(buffer_count)
        assert 0 < buffer_count
        self._buffers = tuple(
            supriya.realtime.Buffer(buffer_group_or_index=self)
            for _ in range(buffer_count))
Exemple #4
0
 def free(self):
     if not self.is_allocated:
         raise supriya.exceptions.BusNotAllocated
     if not self._bus_id_was_set_manually:
         allocator = self._get_allocator(
             calculation_rate=self.calculation_rate, server=self.server)
         allocator.free(self.bus_id)
     self._bus_id = None
     ServerObject.free(self)
     return self
 def _unregister_with_local_server(self):
     node_id = self.node_id
     if self.server is not None:
         if self._node_id in self._server._nodes:
             del self._server._nodes[self._node_id]
         if self.node_id_is_permanent:
             self.server.node_id_allocator.free_permanent_node_id(self.node_id)
     self._node_id = None
     self._node_id_is_permanent = None
     ServerObject.free(self)
     return node_id
Exemple #6
0
    def free(self):
        import supriya.realtime

        if not self.is_allocated:
            raise supriya.exceptions.BusNotAllocated
        allocator = supriya.realtime.Bus._get_allocator(
            calculation_rate=self.calculation_rate, server=self.server)
        allocator.free(self.bus_id)
        self._bus_id = None
        ServerObject.free(self)
        return self
    def __init__(self, buffer_count=1):
        import supriya.realtime

        ServerObject.__init__(self)
        self._buffer_id = None
        buffer_count = int(buffer_count)
        assert 0 < buffer_count
        self._buffers = tuple(
            supriya.realtime.Buffer(buffer_group_or_index=self)
            for _ in range(buffer_count)
        )
Exemple #8
0
 def _unregister_with_local_server(self):
     node_id = self.node_id
     if self.server is not None:
         if self._node_id in self._server._nodes:
             del self._server._nodes[self._node_id]
         if self.node_id_is_permanent:
             self.server.node_id_allocator.free_permanent_node_id(self.node_id)
     self._node_id = None
     self._node_id_is_permanent = None
     ServerObject.free(self)
     return node_id
 def _register_with_local_server(self, server):
     ServerObject.allocate(self, server=server)
     allocator = self.server.buffer_allocator
     buffer_id = allocator.allocate(len(self))
     if buffer_id is None:
         ServerObject.free(self)
         raise ValueError
     self._buffer_id = buffer_id
     for buffer_ in self:
         buffer_._register_with_local_server()
     return buffer_id
 def free(self):
     if not self.is_allocated:
         raise supriya.exceptions.BusNotAllocated
     if not self._bus_id_was_set_manually:
         allocator = self._get_allocator(
             calculation_rate=self.calculation_rate, server=self.server
         )
         allocator.free(self.bus_id)
     self._bus_id = None
     ServerObject.free(self)
     return self
Exemple #11
0
 def _register_with_local_server(self, server):
     ServerObject.allocate(self, server=server)
     allocator = self.server.buffer_allocator
     buffer_id = allocator.allocate(len(self))
     if buffer_id is None:
         ServerObject.free(self)
         raise ValueError
     self._buffer_id = buffer_id
     for buffer_ in self:
         buffer_._register_with_local_server()
     return buffer_id
    def free(self):
        import supriya.realtime

        if not self.is_allocated:
            raise supriya.exceptions.BusNotAllocated
        allocator = supriya.realtime.Bus._get_allocator(
            calculation_rate=self.calculation_rate, server=self.server
        )
        allocator.free(self.bus_id)
        self._bus_id = None
        ServerObject.free(self)
        return self
 def free(self) -> "BufferGroup":
     """
     Frees all buffers in buffer group.
     """
     if not self.is_allocated:
         raise supriya.exceptions.BufferNotAllocated
     for buffer_ in self:
         buffer_.free()
     buffer_id = self.buffer_id
     self._buffer_id = None
     self.server.buffer_allocator.free(buffer_id)
     ServerObject.free(self)
     return self
Exemple #14
0
 def free(self) -> "BufferGroup":
     """
     Frees all buffers in buffer group.
     """
     if not self.is_allocated:
         raise supriya.exceptions.BufferNotAllocated
     for buffer_ in self:
         buffer_.free()
     buffer_id = self.buffer_id
     self._buffer_id = None
     self.server.buffer_allocator.free(buffer_id)
     ServerObject.free(self)
     return self
Exemple #15
0
    def allocate(self, server=None):
        import supriya.realtime

        if self.is_allocated:
            raise supriya.exceptions.BusAlreadyAllocated
        ServerObject.allocate(self, server=server)
        allocator = supriya.realtime.Bus._get_allocator(
            calculation_rate=self.calculation_rate, server=self.server)
        bus_id = allocator.allocate(len(self))
        if bus_id is None:
            ServerObject.free(self)
            raise ValueError
        self._bus_id = bus_id
        return self
    def __init__(self, buffer_group_or_index=None):
        import supriya.realtime

        ServerObject.__init__(self)
        buffer_group = None
        buffer_id = None
        self._buffer_id_was_set_manually = False
        if buffer_group_or_index is not None:
            self._buffer_id_was_set_manually = True
            if isinstance(buffer_group_or_index, supriya.realtime.BufferGroup):
                buffer_group = buffer_group_or_index
            elif isinstance(buffer_group_or_index, int):
                buffer_id = int(buffer_group_or_index)
        self._buffer_group = buffer_group
        self._buffer_id = buffer_id
Exemple #17
0
 def free(self) -> "Buffer":
     """
     Frees buffer.
     """
     if not self.is_allocated:
         raise supriya.exceptions.BufferNotAllocated
     buffer_id = self._unregister_with_local_server()
     request = self._unregister_with_remote_server(buffer_id)
     if self.server.is_running:
         request.communicate(server=self.server, sync=False)
     if not self._buffer_id_was_set_manually:
         self.server.buffer_allocator.free(self.buffer_id)
     self._buffer_id = None
     ServerObject.free(self)
     return self
Exemple #18
0
    def __init__(self, buffer_group_or_index=None):
        import supriya.realtime

        ServerObject.__init__(self)
        buffer_group = None
        buffer_id = None
        self._buffer_id_was_set_manually = False
        if buffer_group_or_index is not None:
            self._buffer_id_was_set_manually = True
            if isinstance(buffer_group_or_index, supriya.realtime.BufferGroup):
                buffer_group = buffer_group_or_index
            elif isinstance(buffer_group_or_index, int):
                buffer_id = int(buffer_group_or_index)
        self._buffer_group = buffer_group
        self._buffer_id = buffer_id
 def free(self) -> "Buffer":
     """
     Frees buffer.
     """
     if not self.is_allocated:
         raise supriya.exceptions.BufferNotAllocated
     buffer_id = self._unregister_with_local_server()
     request = self._unregister_with_remote_server(buffer_id)
     if self.server.is_running:
         request.communicate(server=self.server, sync=False)
     if not self._buffer_id_was_set_manually:
         self.server.buffer_allocator.free(self.buffer_id)
     self._buffer_id = None
     ServerObject.free(self)
     return self
    def allocate(self, server=None):
        import supriya.realtime

        if self.is_allocated:
            raise supriya.exceptions.BusAlreadyAllocated
        ServerObject.allocate(self, server=server)
        allocator = supriya.realtime.Bus._get_allocator(
            calculation_rate=self.calculation_rate, server=self.server
        )
        bus_id = allocator.allocate(len(self))
        if bus_id is None:
            ServerObject.free(self)
            raise ValueError
        self._bus_id = bus_id
        return self
Exemple #21
0
 def _register_with_local_server(
     self, node_id=None, node_id_is_permanent=False, server=None
 ):
     id_allocator = server.node_id_allocator
     if node_id is None:
         if node_id_is_permanent:
             node_id = id_allocator.allocate_permanent_node_id()
         else:
             node_id = server.node_id_allocator.allocate_node_id()
     else:
         node_id = int(node_id)
     ServerObject.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
 def _register_with_local_server(
     self, node_id=None, node_id_is_permanent=False, server=None
 ):
     id_allocator = server.node_id_allocator
     if node_id is None:
         if node_id_is_permanent:
             node_id = id_allocator.allocate_permanent_node_id()
         else:
             node_id = server.node_id_allocator.allocate_node_id()
     else:
         node_id = int(node_id)
     ServerObject.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
Exemple #23
0
 def allocate(self, server=None, sync=False):
     if self.bus_group is not None:
         return
     if self.is_allocated:
         raise supriya.exceptions.BusAlreadyAllocated
     ServerObject.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:
             ServerObject.free(self)
             raise ValueError
         self._bus_id = bus_id
     if sync:
         self.server.sync()
     return self
 def allocate(self, server=None, sync=False):
     if self.bus_group is not None:
         return
     if self.is_allocated:
         raise supriya.exceptions.BusAlreadyAllocated
     ServerObject.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:
             ServerObject.free(self)
             raise ValueError
         self._bus_id = bus_id
     if sync:
         self.server.sync()
     return self
    def __init__(
        self, bus_count=1, calculation_rate=CalculationRate.CONTROL, bus_id=None
    ):
        import supriya.realtime

        ServerObject.__init__(self)
        calculation_rate = CalculationRate.from_expr(calculation_rate)
        assert calculation_rate in (CalculationRate.AUDIO, CalculationRate.CONTROL)
        self._calculation_rate = calculation_rate
        bus_count = int(bus_count)
        assert 0 < bus_count
        self._buses = tuple(
            supriya.realtime.Bus(
                bus_group_or_index=self, calculation_rate=self.calculation_rate
            )
            for _ in range(bus_count)
        )
        assert isinstance(bus_id, (type(None), int))
        self._bus_id = bus_id
Exemple #26
0
    def __init__(self,
                 bus_count=1,
                 calculation_rate=CalculationRate.CONTROL,
                 *,
                 bus_id=None):
        import supriya.realtime

        ServerObject.__init__(self)
        calculation_rate = CalculationRate.from_expr(calculation_rate)
        assert calculation_rate in (CalculationRate.AUDIO,
                                    CalculationRate.CONTROL)
        self._calculation_rate = calculation_rate
        bus_count = int(bus_count)
        assert 0 < bus_count
        self._buses = tuple(
            supriya.realtime.Bus(bus_group_or_index=self,
                                 calculation_rate=self.calculation_rate)
            for _ in range(bus_count))
        assert isinstance(bus_id, (type(None), int))
        self._bus_id = bus_id
    def __init__(
        self, bus_group_or_index=None, calculation_rate=CalculationRate.CONTROL
    ):
        import supriya.realtime

        ServerObject.__init__(self)
        bus_group = None
        bus_id = None
        self._bus_id_was_set_manually = False
        if bus_group_or_index is not None:
            self._bus_id_was_set_manually = True
            if isinstance(bus_group_or_index, supriya.realtime.BusGroup):
                bus_group = bus_group_or_index
            elif isinstance(bus_group_or_index, int):
                bus_id = int(bus_group_or_index)
        self._bus_group = bus_group
        self._bus_id = bus_id
        if calculation_rate is None:
            calculation_rate = "control"
        calculation_rate = CalculationRate.from_expr(calculation_rate)
        assert calculation_rate in (CalculationRate.AUDIO, CalculationRate.CONTROL)
        self._calculation_rate = calculation_rate
Exemple #28
0
    def __init__(self,
                 bus_group_or_index=None,
                 calculation_rate=CalculationRate.CONTROL):
        import supriya.realtime

        ServerObject.__init__(self)
        bus_group = None
        bus_id = None
        self._bus_id_was_set_manually = False
        if bus_group_or_index is not None:
            self._bus_id_was_set_manually = True
            if isinstance(bus_group_or_index, supriya.realtime.BusGroup):
                bus_group = bus_group_or_index
            elif isinstance(bus_group_or_index, int):
                bus_id = int(bus_group_or_index)
        self._bus_group = bus_group
        self._bus_id = bus_id
        if calculation_rate is None:
            calculation_rate = "control"
        calculation_rate = CalculationRate.from_expr(calculation_rate)
        assert calculation_rate in (CalculationRate.AUDIO,
                                    CalculationRate.CONTROL)
        self._calculation_rate = calculation_rate
    def allocate(self, channel_count=1, frame_count=1, server=None, sync=True):
        """
        Allocates buffer on `server`.

        ::

            >>> server = supriya.Server.default().boot()
            >>> buffer_one = supriya.realtime.Buffer().allocate()
            >>> buffer_one.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=0, frame_count=1, channel_count=1, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_two = supriya.realtime.Buffer().allocate(
            ...     frame_count=16,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=1, frame_count=16, channel_count=1, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_three = supriya.realtime.Buffer().allocate(
            ...     channel_count=2,
            ...     frame_count=32,
            ...     )
            >>> buffer_three.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=2, frame_count=32, channel_count=2, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_three.allocate()
            Traceback (most recent call last):
            ...
            supriya.exceptions.BufferAlreadyAllocated

        ::

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

        Returns buffer.
        """
        if self.is_allocated:
            raise supriya.exceptions.BufferAlreadyAllocated
        try:
            ServerObject.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 Exception:
            self.free()
        return self
    def allocate_from_file(
        self,
        file_path,
        channel_indices=None,
        callback=None,
        frame_count=None,
        server=None,
        starting_frame=None,
        sync=True,
    ):
        """
        Allocates buffer on `server` with contents read from `file_path`.

        ::

            >>> server = supriya.Server.default().boot()
            >>> buffer_one = supriya.realtime.Buffer().allocate_from_file(
            ...     supriya.system.Assets['audio/pulse_44100sr_16bit_octo.wav'],
            ...     )
            >>> buffer_one.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=0, frame_count=8, channel_count=8, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_two = supriya.realtime.Buffer().allocate_from_file(
            ...     supriya.system.Assets['audio/pulse_44100sr_16bit_octo.wav'],
            ...     channel_indices=(3, 4),
            ...     frame_count=4,
            ...     starting_frame=1,
            ...     sync=True,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                items=(
                    Item(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_two.allocate()
            Traceback (most recent call last):
            ...
            supriya.exceptions.BufferAlreadyAllocated

        ::

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

        Returns buffer.
        """
        if self.is_allocated:
            raise supriya.exceptions.BufferAlreadyAllocated
        try:
            ServerObject.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 Exception:
            ServerObject.allocate(self, server=server)
        return self
Exemple #31
0
 def __init__(self, name=None, node_id_is_permanent=False):
     ServerObject.__init__(self)
     UniqueTreeNode.__init__(self, name=name)
     self._is_paused = False
     self._node_id = None
     self._node_id_is_permanent = bool(node_id_is_permanent)
 def __init__(self, name=None, node_id_is_permanent=False):
     ServerObject.__init__(self)
     UniqueTreeNode.__init__(self, name=name)
     self._is_paused = False
     self._node_id = None
     self._node_id_is_permanent = bool(node_id_is_permanent)
Exemple #33
0
    def allocate(self, channel_count=1, frame_count=1, server=None, sync=True):
        """
        Allocates buffer on `server`.

        ::

            >>> server = supriya.Server.default().boot()
            >>> buffer_one = supriya.realtime.Buffer().allocate()
            >>> buffer_one.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=0, frame_count=1, channel_count=1, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_two = supriya.realtime.Buffer().allocate(
            ...     frame_count=16,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=1, frame_count=16, channel_count=1, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_three = supriya.realtime.Buffer().allocate(
            ...     channel_count=2,
            ...     frame_count=32,
            ...     )
            >>> buffer_three.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=2, frame_count=32, channel_count=2, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_three.allocate()
            Traceback (most recent call last):
            ...
            supriya.exceptions.BufferAlreadyAllocated

        ::

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

        Returns buffer.
        """
        if self.is_allocated:
            raise supriya.exceptions.BufferAlreadyAllocated
        try:
            ServerObject.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 Exception:
            self.free()
        return self
Exemple #34
0
    def allocate_from_file(
        self,
        file_path,
        channel_indices=None,
        callback=None,
        frame_count=None,
        server=None,
        starting_frame=None,
        sync=True,
    ):
        """
        Allocates buffer on `server` with contents read from `file_path`.

        ::

            >>> server = supriya.Server.default().boot()
            >>> buffer_one = supriya.realtime.Buffer().allocate_from_file(
            ...     supriya.system.Assets['audio/pulse_44100sr_16bit_octo.wav'],
            ...     )
            >>> buffer_one.query()
            BufferInfoResponse(
                items=(
                    Item(buffer_id=0, frame_count=8, channel_count=8, sample_rate=44100.0),
                    ),
                )

        ::

            >>> buffer_two = supriya.realtime.Buffer().allocate_from_file(
            ...     supriya.system.Assets['audio/pulse_44100sr_16bit_octo.wav'],
            ...     channel_indices=(3, 4),
            ...     frame_count=4,
            ...     starting_frame=1,
            ...     sync=True,
            ...     )
            >>> buffer_two.query()
            BufferInfoResponse(
                items=(
                    Item(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_two.allocate()
            Traceback (most recent call last):
            ...
            supriya.exceptions.BufferAlreadyAllocated

        ::

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

        Returns buffer.
        """
        if self.is_allocated:
            raise supriya.exceptions.BufferAlreadyAllocated
        try:
            ServerObject.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 Exception:
            ServerObject.allocate(self, server=server)
        return self