def __init__(self, name=None): ServerObjectProxy.__init__(self) self._is_paused = False self._name = name self._node_id = None self._node_id_is_permanent = None self._parent = None
def __init__( self, bus_count=1, calculation_rate=None, bus_id=None, ): from supriya.tools import servertools from supriya.tools import synthdeftools BindingTarget.__init__(self) ServerObjectProxy.__init__(self) calculation_rate = synthdeftools.CalculationRate.from_expr( calculation_rate) assert calculation_rate in ( synthdeftools.CalculationRate.AUDIO, synthdeftools.CalculationRate.CONTROL, ) self._calculation_rate = calculation_rate bus_count = int(bus_count) assert 0 < bus_count self._buses = tuple( servertools.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, ugens, name=None, optimize=True, parameter_names=None ): from supriya.tools import synthdeftools from supriya.tools import ugentools ServerObjectProxy.__init__(self) compiler = synthdeftools.SynthDefCompiler self._name = name ugens = copy.deepcopy(ugens) ugens = self._flatten_ugens(ugens) assert all(isinstance(_, ugentools.UGen) for _ in ugens) ugens = self._cleanup_pv_chains(ugens) ugens = self._cleanup_local_bufs(ugens) if optimize: ugens = self._optimize_ugen_graph(ugens) ugens = self._sort_ugens_topologically(ugens) self._ugens = tuple(ugens) self._constants = self._collect_constants(self._ugens) self._control_ugens = self._collect_control_ugens(self._ugens) self._indexed_parameters = self._collect_indexed_parameters( self._control_ugens, parameter_names=parameter_names, ) self._compiled_ugen_graph = compiler.compile_ugen_graph(self)
def _register_with_local_server( self, server=None, ): ServerObjectProxy.allocate(self, server=server) synthdef_name = self.actual_name self.server._synthdefs[synthdef_name] = self
def _allocate_buffer_id(self): if self.buffer_id is None: buffer_id = self.server.buffer_allocator.allocate(1) if buffer_id is None: ServerObjectProxy.free(self) raise ValueError self._buffer_id = buffer_id
def free(self): from supriya.tools import requesttools synthdef_name = self.actual_name del (self.server._synthdefs[synthdef_name]) request = requesttools.SynthDefFreeRequest(synthdef=self, ) if self.server.is_running: request.communicate(server=self.server) ServerObjectProxy.free(self)
def free(self): from supriya.tools import servertools if not self.is_allocated: return allocator = servertools.Bus._get_allocator(calculation_rate=self.calculation_rate, server=self.server) allocator.free(self.bus_id) self._bus_id = None ServerObjectProxy.free(self)
def free(self): from supriya.tools import requesttools synthdef_name = self.actual_name del(self.server._synthdefs[synthdef_name]) request = requesttools.SynthDefFreeRequest( synthdef=self, ) if self.server.is_running: request.communicate(server=self.server) ServerObjectProxy.free(self)
def free(self): from supriya.tools import servertools if not self.is_allocated: return allocator = servertools.Bus._get_allocator( calculation_rate=self.calculation_rate, server=self.server, ) allocator.free(self.bus_id) self._bus_id = None ServerObjectProxy.free(self)
def free(self): if not self.is_allocated: return 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 ServerObjectProxy.free(self)
def _unregister_with_local_server(self): node_id = self.node_id if self.server is not None: 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 ServerObjectProxy.free(self, ) return node_id
def __init__( self, buffer_count=1, ): from supriya.tools import servertools ServerObjectProxy.__init__(self) self._buffer_id = None buffer_count = int(buffer_count) assert 0 < buffer_count self._buffers = tuple( servertools.Buffer(buffer_group_or_index=self) for _ in range(buffer_count))
def __init__( self, buffer_count=1, ): from supriya.tools import servertools ServerObjectProxy.__init__(self) self._buffer_id = None buffer_count = int(buffer_count) assert 0 < buffer_count self._buffers = tuple( servertools.Buffer(buffer_group_or_index=self) for _ in range(buffer_count) )
def free(self): r'''Frees all buffers in buffer group. Returns none. ''' if not self.is_allocated: return for buffer_ in self: buffer_.free() buffer_id = self.buffer_id self._buffer_id = None self.server.buffer_allocator.free(buffer_id) ServerObjectProxy.free(self)
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
def _unregister_with_local_server(self): node_id = self.node_id if self.server is not None: 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 ServerObjectProxy.free( self, ) return node_id
def free(self): """ Frees all buffers in buffer group. Returns none. """ if not self.is_allocated: return for buffer_ in self: buffer_.free() buffer_id = self.buffer_id self._buffer_id = None self.server.buffer_allocator.free(buffer_id) ServerObjectProxy.free(self)
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
def __init__( self, buffer_group_or_index=None, ): from supriya.tools import servertools ServerObjectProxy.__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, servertools.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): r'''Frees buffer. Returns none. ''' if not self.is_allocated: return 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 ServerObjectProxy.free(self)
def free(self): """ Frees buffer. Returns none. """ if not self.is_allocated: return 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 ServerObjectProxy.free(self)
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
def __init__(self, ugens, name=None, optimize=True, parameter_names=None): from supriya.tools import synthdeftools from supriya.tools import ugentools ServerObjectProxy.__init__(self) compiler = synthdeftools.SynthDefCompiler self._name = name ugens = copy.deepcopy(ugens) ugens = self._flatten_ugens(ugens) assert all(isinstance(_, ugentools.UGen) for _ in ugens) ugens = self._cleanup_pv_chains(ugens) ugens = self._cleanup_local_bufs(ugens) if optimize: ugens = self._optimize_ugen_graph(ugens) ugens = self._sort_ugens_topologically(ugens) self._ugens = tuple(ugens) self._constants = self._collect_constants(self._ugens) self._control_ugens = self._collect_control_ugens(self._ugens) self._indexed_parameters = self._collect_indexed_parameters( self._control_ugens, parameter_names=parameter_names, ) self._compiled_ugen_graph = compiler.compile_ugen_graph(self)
def __init__( self, bus_group_or_index=None, calculation_rate=None, ): from supriya.tools import servertools from supriya.tools import synthdeftools BindingTarget.__init__(self) ServerObjectProxy.__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, servertools.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 assert calculation_rate is not None calculation_rate = synthdeftools.CalculationRate.from_expr(calculation_rate) self._calculation_rate = calculation_rate
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
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
def __init__( self, bus_group_or_index=None, calculation_rate=None, ): from supriya.tools import servertools from supriya.tools import synthdeftools BindingTarget.__init__(self) ServerObjectProxy.__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, servertools.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 assert calculation_rate is not None calculation_rate = synthdeftools.CalculationRate.from_expr( calculation_rate) self._calculation_rate = calculation_rate
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
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
def __init__(self, name=None): ServerObjectProxy.__init__(self) TreeNode.__init__(self, name=name) self._is_paused = False self._node_id = None self._node_id_is_permanent = None
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
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