mesonic.backend package#
Submodules#
mesonic.backend.backend_sc3nb module#
Implementation of the backend using sc3nb.
- class mesonic.backend.backend_sc3nb.BackendSC3NB(**kwargs)[source]#
Bases:
BackendBackend for sc3nb
- create_buffer_manager(context: Context) BufferManagerSC3NB[source]#
Create a BufferManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
BufferManager instance.
- Return type:
- create_record_manager(context: Context) RecordManagerSC3NB[source]#
Create a RecordManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
RecordManager instance.
- Return type:
- create_synth_manager(context: Context) SynthManagerSC3NB[source]#
Create a SynthManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
SynthManger instance.
- Return type:
- register_context(context: Context) None[source]#
Register a context to this Backend.
- Parameters:
context (Context) – Context that should use this backend.
- render_nrt(context: Context, output_path, options: 'ServerOptions' | None = None, **backend_kwargs) None[source]#
Render the provided Context in non-realtime.
- Parameters:
context (Context) – Context to be rendered.
output_path (path like) – Path for the output file.
- property sampling_rate#
Get the native sampling rate of the Backend
- class mesonic.backend.backend_sc3nb.BufferManagerSC3NB(backend: B, context: Context)[source]#
Bases:
BufferManagerBufferManager for sc3nb
- from_data(data, sr, **kwargs) Buffer[source]#
Create a Buffer from the provided data and sampling rate.
- Parameters:
data (Any) – Samples for the Buffer. Typically numpy arrays or other collections.
sr (numeric) – Sampling rate of the Buffer. Type depends on backend.
- Returns:
The created Buffer.
- Return type:
- from_file(path, starting_frame: int = 0, num_frames: int = -1, channels: int | Sequence[int] | None = None, **kwargs) Buffer[source]#
Create a Buffer from a file.
- Parameters:
path (path like) – Path of the file.
starting_frame (int, optional) – Index of the first frame, by default 0
num_frames (int, optional) – Number of frames to be loaded, by default -1
channels (Optional[Union[int, Sequence[int]]], optional) – Specification of the channels to load, by default None - None means all channels. - If a int is provided only that channel will be loaded. - If a Sequence of ints is provided the provided channels will be loaded.
- Returns:
The Buffer loaded from the file.
- Return type:
- class mesonic.backend.backend_sc3nb.EventHandlerSC3NB[source]#
Bases:
EventHandlerA abstract EventHandler as basis sc3nb EventHandlers.
Breaks down the handling of mutliple Events to just single events by using the sc3nb.Bundler.
- backend: BackendSC3NB#
- class mesonic.backend.backend_sc3nb.RecordEventHandlerSC3NB(backend: BackendSC3NB, records: WeakKeyDictionary[Record, Recorder])[source]#
Bases:
EventHandlerSC3NB,RecordEventHandler
- class mesonic.backend.backend_sc3nb.RecordManagerSC3NB(backend: B, context: Context)[source]#
Bases:
RecordManagerRecordManager for sc3nb
- class mesonic.backend.backend_sc3nb.SynthEventHandlerSC3NB(backend: BackendSC3NB, synths: WeakKeyDictionary[Synth, Synth])[source]#
Bases:
EventHandlerSC3NB,SynthEventHandlerSynthEventHandler for sc3nb
- class mesonic.backend.backend_sc3nb.SynthManagerSC3NB(backend: B, context: Context)[source]#
Bases:
SynthManager- add_buffer_synth_def(name, code=None, **kwargs)[source]#
Create a Synth Definition for SynthManager.from_buffer() to the backend.
- Parameters:
name (str) – SynthDef name.
- add_synth_def(name, code=None, **kwargs)[source]#
Create a Synth Definition to the backend.
- Parameters:
name (str) – SynthDef name.
- buffer_synthdefs: Dict[str, str] = {'playbuf': '\n{ |out=0, bufnum={{BUFNUM}}, rate=1, loop=0, pan=0, amp=0.3 |\n var sig = PlayBuf.ar({{NUM_CHANNELS}}, bufnum,\n rate*BufRateScale.kr(bufnum),\n loop: loop,\n doneAction: Done.freeSelf);\n Out.ar(out, Pan2.ar(sig, pan, amp))\n}'}#
- buffer_synthdefs_slots = {'BUFNUM': <function SynthManagerSC3NB.<lambda>>, 'NUM_CHANNELS': <function SynthManagerSC3NB.<lambda>>}#
- from_buffer(buffer: Buffer, synth_name: str = 'playbuf', **synth_kwargs) Synth[source]#
Create a Synth to playback a buffer.
This will provide the Backend with the information needed to create a Synth that can playback the provided Buffer.
- sent_synthdefs = {}#
mesonic.backend.bases module#
Defines backend base classes
This module contains the relevant classes that are needed to implement a backend for mesonic.
- class mesonic.backend.bases.Backend[source]#
Bases:
ABCBase class of the mesonic Backend.
This describes the Backend interface. The Backend should start or connect to the actual backend program. It is also creating the single Managers for the Contexts and stores variables.
- abstract create_buffer_manager(context: Context) BufferManager[source]#
Create a BufferManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
BufferManager instance.
- Return type:
- abstract create_record_manager(context: Context) RecordManager[source]#
Create a RecordManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
RecordManager instance.
- Return type:
- abstract create_synth_manager(context: Context) SynthManager[source]#
Create a SynthManager instance for the provided Context
- Parameters:
context (Context) – Context instance.
- Returns:
SynthManger instance.
- Return type:
- get_context_vars(context: Context) Dict[source]#
Get the stored variables of the provided Context.
- Parameters:
context (Context) – A registered Context of which the variables should be returned.
- Returns:
Stored variables of a context.
- Return type:
Dict
- abstract register_context(context: Context) None[source]#
Register a context to this Backend.
- Parameters:
context (Context) – Context that should use this backend.
- abstract render_nrt(context: Context, output_path, **backend_kwargs)[source]#
Render the provided Context in non-realtime.
- Parameters:
context (Context) – Context to be rendered.
output_path (path like) – Path for the output file.
- abstract property sampling_rate#
Get the native sampling rate of the Backend
- class mesonic.backend.bases.BufferManager(backend: B, context: Context)[source]#
-
Manager for Buffers.
- from_asig(asig: Asig, **kwargs) Buffer[source]#
Create a Buffer from an
pya.Asig- Parameters:
asig (Asig) – The Asig that should be created as Buffer.
- Returns:
The Buffer created from the Asig.
- Return type:
- abstract from_data(data, sr: numeric, **kwargs) Buffer[source]#
Create a Buffer from the provided data and sampling rate.
- Parameters:
data (Any) – Samples for the Buffer. Typically numpy arrays or other collections.
sr (numeric) – Sampling rate of the Buffer. Type depends on backend.
- Returns:
The created Buffer.
- Return type:
- abstract from_file(path, starting_frame: int = 0, num_frames: int = -1, channels: int | Sequence[int] | None = None, **kwargs) Buffer[source]#
Create a Buffer from a file.
- Parameters:
path (path like) – Path of the file.
starting_frame (int, optional) – Index of the first frame, by default 0
num_frames (int, optional) – Number of frames to be loaded, by default -1
channels (Optional[Union[int, Sequence[int]]], optional) – Specification of the channels to load, by default None - None means all channels. - If a int is provided only that channel will be loaded. - If a Sequence of ints is provided the provided channels will be loaded.
- Returns:
The Buffer loaded from the file.
- Return type:
- class mesonic.backend.bases.EventHandler[source]#
Bases:
Generic[E]A generic handler for abitrary Events.
This describes the EventHandler interface. It is used for processing Events at the backend.
The handling of a Event should be quickly done or run in the background using an explicit Thread for example to not stall the processing of multiple events.
- abstract get_etype() type[source]#
Get the type of Event this handler processes.
- Returns:
type of Event this handler processes.
- Return type:
- class mesonic.backend.bases.Manager(backend: B, context: Context)[source]#
Bases:
Generic[B,H]A generic Manager.
This describes the Manager interface. It is used for preparing the Event generating instances and also prepares the
EventHandler. It connects theContextwith the Backend- Parameters:
backend (B) – backend instance that is used.
context (Context) – context instance that is used.
- event_handler: H#
- class mesonic.backend.bases.RecordEventHandler[source]#
Bases:
EventHandler[RecordEvent]A
EventHandlerforRecordEvent.- get_etype() type[source]#
Get the type of Event this handler processes.
- Returns:
type of Event this handler processes.
- Return type:
- class mesonic.backend.bases.RecordManager(backend: B, context: Context)[source]#
Bases:
Manager[B,RecordEventHandler]Manager for Records.
- class mesonic.backend.bases.SynthEventHandler[source]#
Bases:
EventHandler[SynthEvent]A
EventHandlerforSynthEvent.- get_etype() type[source]#
Get the type of Event this handler processes.
- Returns:
type of Event this handler processes.
- Return type:
- class mesonic.backend.bases.SynthManager(backend: B, context: Context)[source]#
Bases:
Manager[B,SynthEventHandler]Manager for Synths.
- abstract add_buffer_synth_def(name, **kwargs)[source]#
Create a Synth Definition for SynthManager.from_buffer() to the backend.
- Parameters:
name (str) – SynthDef name.
- abstract add_synth_def(name, **kwargs)[source]#
Create a Synth Definition to the backend.
- Parameters:
name (str) – SynthDef name.
- abstract create(name: str, track: int = 0, *, mutable: bool = True, **kwargs) Synth[source]#
Create a Synth.
Module contents#
Package that contains all the Backend related modules.
The bases module contains the abstract classes that needs to be implemented by the concrete Backend implementations.
The other modules contains the implementations of the abstract classes from the bases module.
- mesonic.backend.start_backend(backend: str | B | Type[B] = 'sc3nb', **backend_kwargs) Backend[source]#
Start a Backend.
- Parameters:
backend (Union[str, Backend], optional) – Backend to be started, by default “sc3nb”. Typically this takes the name of the backend as string. However it can also allows the user to provide a class or instance of the Backend type.
- Returns:
The started Backend.
- Return type:
- Raises:
ValueError – If the provided backend is not a subclass of the Backend class or if it is the abstract Backend class.
NotImplementedError – If an unknown backend is provided.