core¶
Core interfaces for interfacting with scsynth-compatible execution contexts.
Context subclasses expose a common interface for realtime and non-realtime synthesis.
- class Completion(context: Context, moment: Moment)¶
Bases:
objectA context manager for collecting requests to be made “on completion” of another request.
Multiple requests made inside a completion are bundled together.
- __call__(request: Request) Request¶
Bundle this completion’s collected requests into the
on_completionargument of the request.
- __enter__() Completion¶
set this completion as the current “request context”.
-
class Context(options: Options | None, name: str | None =
None, **kwargs)¶ Bases:
objectA synthesis execution context.
-
add_buffer(*, channel_count: int | None =
None, channel_indices: list[int] | None =None, file_path: PathLike | None =None, frame_count: int | None =None, starting_frame: int | None =None, on_completion: Callable[[Context], Any] | None =None) Buffer¶ Add a new buffer to the context.
Emit
/b_alloc,/b_allocReador/b_allocReadChannelrequests depending on parameters.- Parameters:
- channel_count: int | None =
None¶ The channel count of the new buffer. Cannot be used when reading from file paths.
- channel_indices: list[int] | None =
None¶ The channels to read from a file when reading from a file.
- file_path: PathLike | None =
None¶ The (optional) file to read from.
- frame_count: int | None =
None¶ The frame count of the new buffer.
- starting_frame: int | None =
None¶ The frame to start reading from when reading from a file.
- on_completion: Callable[[Context], Any] | None =
None¶ A callable with the buffer’s context as the only argument. Permits building an “on completion” argument to this method’s request without an active moment.
- channel_count: int | None =
-
add_buffer_group(*, channel_count: int | None =
None, count: int =1, frame_count: int | None =None) BufferGroup¶ Add a group of new buffers to the context.
Emit
/b_allocrequests.
-
add_bus(calculation_rate: CalculationRate | SupportsInt | str | None =
CalculationRate.CONTROL) Bus¶ Add a new bus to the context.
Emit no requests.
- Parameters:
- calculation_rate: CalculationRate | SupportsInt | str | None =
CalculationRate.CONTROL¶ The calculation rate of the new bus.
- calculation_rate: CalculationRate | SupportsInt | str | None =
-
add_bus_group(calculation_rate: CalculationRate | SupportsInt | str | None =
CalculationRate.CONTROL, count: int =1) BusGroup¶ Add a group of new buses to the context.
Emit no requests.
- Parameters:
- calculation_rate: CalculationRate | SupportsInt | str | None =
CalculationRate.CONTROL¶ The calculation rate of the new bus.
- count: int =
1¶ The number of buses to add.
- calculation_rate: CalculationRate | SupportsInt | str | None =
-
add_group(*, add_action: AddAction | SupportsInt | str | None =
AddAction.ADD_TO_HEAD, target_node: SupportsInt | None =None, parallel: bool =False, permanent: bool =False) Group¶ Add a new group node to the context.
Emit
/g_newor/p_newrequests depending on parameters.- Parameters:
- add_action: AddAction | SupportsInt | str | None =
AddAction.ADD_TO_HEAD¶ The add action to use when placing the new group.
- target_node: SupportsInt | None =
None¶ The node to place the new group relative to.
- parallel: bool =
False¶ Flag for parallel vs non-parallel groups.
- permanent: bool =
False¶ Flag for using a permanent node ID.
- add_action: AddAction | SupportsInt | str | None =
- add_scope_buffer() ScopeBuffer¶
Add a new scope buffer to the context.
-
add_synth(synthdef: SynthDef, *, add_action: AddAction | SupportsInt | str | None =
AddAction.ADD_TO_HEAD, target_node: SupportsInt | None =None, permanent: bool =False, **settings: SupportsFloat | str | Sequence[SupportsFloat | str]) Synth¶ Add a new synth node to the context.
Emit
/s_newrequests.- Parameters:
- synthdef: SynthDef¶
The SynthDef to use for the new synth.
- add_action: AddAction | SupportsInt | str | None =
AddAction.ADD_TO_HEAD¶ The add action to use when placing the new synth.
- target_node: SupportsInt | None =
None¶ The node to place the new synth relative to.
- permanent: bool =
False¶ Flag for using a permanent node ID.
- **settings: SupportsFloat | str | Sequence[SupportsFloat | str]¶
The new synth’s control settings.
-
add_synthdefs(*synthdefs: SynthDef, on_completion: Callable[[Context], Any] | None =
None) Completion¶ Add one or more SynthDefs to the context.
Emit
/d_recvrequests.
-
close_buffer(buffer: Buffer, on_completion: Callable[[Context], Any] | None =
None) Completion¶ Close a buffer.
Emit
/b_closerequests.
- copy_buffer(*, source_buffer: Buffer, target_buffer: Buffer, source_starting_frame: int, target_starting_frame: int, frame_count: int) None¶
Copy a buffer.
Emit
/b_gen <buffer.id_> copy ...requests.- Parameters:
- source_buffer: Buffer¶
The buffer to copy from.
- target_buffer: Buffer¶
The buffer to copy to.
- source_starting_frame: int¶
The frame index in the source buffer to start reading from.
- target_starting_frame: int¶
The frame index in the target buffer to start writing at.
- frame_count: int¶
The number of frames to copy.
- fill_buffer(buffer: Buffer, starting_frame: int, frame_count: int, value: float) None¶
Fill a buffer with a single value.
Emit
/b_fillrequests.
-
fill_bus_range(bus: Bus, count: int, value: float, use_shared_memory: bool =
False) None¶ Fill a contiguous range of buses with a single value.
Emit
/c_fillrequests.
-
free_buffer(buffer: Buffer, on_completion: Callable[[Context], Any] | None =
None) Completion¶ Free a buffer.
Emit
/b_freerequests.Note
Freeing the first buffer of a buffer group will free the IDs of all buffers in the group, but will only issue a
/b_freerequest for the first buffer.
- free_buffer_group(buffer_group: BufferGroup) None¶
Free a buffer grop.
Emit
/b_freerequests.- Parameters:
- buffer_group: BufferGroup¶
The buffer group to free.
- free_bus(bus: Bus) None¶
Free a bus.
Emit no requests.
Note
Freeing the first bus of a bus group will free the IDs of the entire group.
-
free_group_children(group: Group, synths_only: bool =
False) None¶ Free a group’s children.
Emit
/g_deepFreeor/g_freeAllrequests depending on parameters.
-
free_node(node: Node, force: bool =
False) None¶ Free a node.
Emit
/n_freefor groups, for synths without agatecontrol, or whenforceisTrue.Emit
/n_set <node.id_> gate 0for synths withgatecontrols.
- free_scope_buffer(scope_buffer: ScopeBuffer) None¶
Free a scope buffer.
- Parameters:
- scope_buffer: ScopeBuffer¶
The scope buffer to free.
-
generate_buffer(buffer: Buffer, command_name: 'sine1' | 'sine2' | 'sine3' | 'cheby', amplitudes: Sequence[float], frequencies: Sequence[float] | None =
None, phases: Sequence[float] | None =None, as_wavetable: bool =False, should_clear_first: bool =False, should_normalize: bool =False) None¶ Generate a buffer.
Emit
/b_genrequests.- Parameters:
- buffer: Buffer¶
The buffer to generate.
- command_name: 'sine1' | 'sine2' | 'sine3' | 'cheby'¶
The generation command name.
- amplitudes: Sequence[float]¶
A sequence of partial amplitudes.
- frequencies: Sequence[float] | None =
None¶ A sequence of partial frequencies.
- phases: Sequence[float] | None =
None¶ A sequence of partial phases.
- as_wavetable: bool =
False¶ Flag for generating the output in wavetable format.
- should_clear_first: bool =
False¶ Flag for clearing the buffer before generating.
- should_normalize: bool =
False¶ Flag for normalizing the generated output.
-
load_synthdefs(path: PathLike, on_completion: Callable[[Context], Any] | None =
None) Completion¶ Load SynthDefs from a path.
Emit
/d_loadrequests.Warning
At the time of this writing, supernova does not support globbing.
- Parameters:
-
load_synthdefs_directory(path: PathLike, on_completion: Callable[[Context], Any] | None =
None) Completion¶ Load all SynthDefs from a directory.
Emit
/d_loadDirrequests.
- map_node(node: Node, **settings: Bus | str | None) None¶
Map a node’s controls to buses.
Emit
/n_mapand/n_maparequests.
- move_node(node: Node, add_action: AddAction | SupportsInt | str | None, target_node: Node) None¶
Move a node.
Emit
/n_after,/n_before,/g_headand/g_tailrequests depending on parameters.- Parameters:
- node: Node¶
The node to move.
- add_action: AddAction | SupportsInt | str | None¶
The add action to use when moving the node.
- target_node: Node¶
The target node to place the node relative to.
-
normalize_buffer(buffer: Buffer, new_maximum: float =
1.0, as_wavetable: bool =False) None¶ Normalize a buffer.
Emit
/b_gen <buffer.id_> (w)?normalizerequests depending on parameters.
-
order_nodes(target_node: Node, *nodes: Node, add_action: AddAction | SupportsInt | str | None =
None) None¶ Re-order nodes.
Emit
/n_orderrequests.- Parameters:
- target_node: Node¶
The node to re-order the other nodes relative to.
- *nodes: Node¶
The nodes to re-order.
- add_action: AddAction | SupportsInt | str | None =
None¶ The add action to use when re-ordering the nodes.
-
read_buffer(buffer: Buffer, file_path: PathLike, *, buffer_starting_frame: int | None =
None, channel_indices: list[int] | None =None, frame_count: int | None =None, leave_open: bool =False, starting_frame: int | None =None, on_completion: Callable[[Context], Any] | None =None) Completion¶ Read a file into a buffer.
Emit
/b_reador/b_readChannelrequests, depending on parameters.- Parameters:
- buffer: Buffer¶
The buffer to read into.
- file_path: PathLike¶
The file path to read from.
- channel_indices: list[int] | None =
None¶ A list of channel indices to read from when reading from a file.
- frame_count: int | None =
None¶ The number of frames to read.
- leave_open: bool =
False¶ Flag for leaving the file open (e.g. to continue reading via
DiskIn) or close it.- starting_frame: int | None =
None¶ The starting frame in the buffer to begin reading into at.
- on_completion: Callable[[Context], Any] | None =
None¶ A callable with the buffer’s context as the only argument. Permits building an “on completion” argument to this method’s request without an active moment.
- abstractmethod send(message: Sequence | SupportsOsc | str) None¶
Send a message to the execution context.
- Parameters:
- message: Sequence | SupportsOsc | str¶
The message to send.
- set_buffer(buffer: Buffer, index: int, value: float) None¶
set a buffer sample.
Emit
/b_setrequests.
- set_buffer_range(buffer: Buffer, index: int, values: Sequence[float]) None¶
set a buffer sample range.
Emit
/b_setnrequests.
-
set_bus(bus: Bus, value: float, use_shared_memory: bool =
False) None¶ set a control bus to a value.
Emit
/c_setrequests.
-
set_bus_range(bus: Bus, values: Sequence[float], use_shared_memory: bool =
False) None¶ set a range of control buses.
Emit
/c_setnrequests.
- set_node(node: Node, *indexed_settings: tuple[int, SupportsFloat | Sequence[SupportsFloat]], **settings: SupportsFloat | Sequence[SupportsFloat]) None¶
set a node’s controls.
Emit
/n_setrequests.- Parameters:
- node: Node¶
The node whose controls will be set.
- *indexed_settings: tuple[int, SupportsFloat | Sequence[SupportsFloat]]¶
A sequence of control indices to values.
- **settings: SupportsFloat | Sequence[SupportsFloat]¶
A mapping of control names to values.
- set_node_range(node: Node, *indexed_settings: tuple[int, Sequence[SupportsFloat]], **settings: Sequence[SupportsFloat]) None¶
set a range of node controls.
Emit
/n_setnrequests.- Parameters:
- node: Node¶
The node whose controls will be set.
- *indexed_settings: tuple[int, Sequence[SupportsFloat]]¶
A sequence of control indices to values.
- **settings: Sequence[SupportsFloat]¶
A mapping of control names to values.
-
write_buffer(buffer: Buffer, file_path: PathLike, *, frame_count: int | None =
None, header_format: HeaderFormat | SupportsInt | str | None ='aiff', leave_open: bool =False, sample_format: SampleFormat | SupportsInt | str | None ='int24', starting_frame: int | None =None, on_completion: Callable[[Context], Any] | None =None) Completion¶ Write a buffer to disk.
Emit
/b_writerequests.- Parameters:
- buffer: Buffer¶
The buffer to write to disk.
- file_path: PathLike¶
The file path to write into.
- frame_count: int | None =
None¶ The number of frames to write.
- header_format: HeaderFormat | SupportsInt | str | None =
'aiff'¶ The header format to use, e.g.
AIFForWAVE.- leave_open: bool =
False¶ Flag for leaving the file open (e.g. to continue writing via
DiskOut) or close it.- sample_format: SampleFormat | SupportsInt | str | None =
'int24'¶ The sample format to use, e.g.
INT24orFLOAT.- starting_frame: int | None =
None¶ The starting frame in the buffer to start writing from.
- on_completion: Callable[[Context], Any] | None =
None¶ A callable with the buffer’s context as the only argument. Permits building an “on completion” argument to this method’s request without an active moment.
-
zero_buffer(buffer: Buffer, on_completion: Callable[[Context], Any] | None =
None) Completion¶ set a buffer’s contents to zero.
Emit
/b_zerorequests.
- property boot_status : BootStatus¶
Get the server’s boot status.
-
add_buffer(*, channel_count: int | None =