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 _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 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 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 _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
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 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
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
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