Python Mixer API
Mixer is the persistent, scene-based stereo mixer: sends, buses, VCA groups, meters and automation over per-strip stereo blocks. The one-shot mix_stereo(...) and the mixing workflow open the page; Mixing Engine covers routing concepts and Mixing Scene JSON the scene format.
Mixing API
Python also exposes the libsonare mixing engine. Use mix_stereo(...) for one-shot stem rendering, or keep a Mixer built from a scene document (Mixer(scene=...); Mixer.from_json(json, sample_rate=...) takes JSON text) when you need sends, buses, automation, meters, and scene serialization. List the built-in scene presets with mixing_scene_preset_names().
import libsonare as sonare
print(sonare.mixing_scene_preset_names())
scene = sonare.mixing_scene_preset("vocalReverbSend")
offline = sonare.mix_stereo(
[(vocal_l, vocal_r), (music_l, music_r)],
sample_rate=48000,
input_trim_db=[3, 0],
fader_db=[-3, -12],
pan=[0, -0.2],
width=[1, 0.9],
)
with sonare.Mixer(sample_rate=48000, scene=scene, max_block_size=512) as mixer:
print(mixer.scene_warnings()) # non-fatal warnings, such as sends to undeclared buses
print(mixer.latency_samples) # compiled graph latency for dry/wet alignment
block = mixer.process_stereo([vocal_block_l, music_block_l], [vocal_block_r, music_block_r])
meter = mixer.strip_meter(0, tap="postFader")
mixer.schedule_fader_automation(0, 48000 * 8, -6, curve="sCurve")# Render a small stereo mixer scene from per-strip left/right buffers.
def mix_stereo(
strips: Sequence[tuple[Sequence[float], Sequence[float]]],
sample_rate: int,
fader_db: Sequence[float] | None = None,
pan: Sequence[float] | None = None,
pan_mode: Sequence[PanMode] | PanMode = 'balance',
width: Sequence[float] | None = None,
muted: Sequence[bool] | None = None,
input_trim_db: Sequence[float] | None = None,
) -> MixResult: ...
# Return built-in mixer scene preset identifiers.
def mixing_scene_preset_names() -> list[str]: ...mixer.process_stereo(...) returns a MixerStereoResult frozen dataclass with .left and .right (float32 arrays) and .sample_rate (int), mirroring the Node/WASM {left, right, sampleRate} shape. Fewer input channels than strips leave the remaining strips silent; more input channels than strips raise SonareValueError, whose message names the strip count (left_inputs must hold at most 2 inputs, one per strip).
Mixer.set_pan_law(strip, pan_law) and RealtimeEngine.set_strip_pan_law(ref, pan_law) take a PanLaw token exactly: const3Db, const4.5Db, const6Db or linear0Db. Another spelling is a SonareValueError and a number is a TypeError.
See Mixing Engine for routing concepts, scene presets, and real-time notes.
More mixer entry points
| Task | API | Guide |
|---|---|---|
| Fold the true-peak meter's pending window in at the end of a signal | Mixer.flush_meters() | Mixing Engine |
| Read recoverable mixer scene warnings, such as sends to undeclared buses | Mixer.scene_warnings() | Mixing Scene JSON |
The Mixer lifecycle and the signatures of its members follow.
Mixer lifecycle
Mixer(sample_rate=..., scene=None, max_block_size=None) builds an empty mixer, or one from a scene mapping; Mixer.from_json(document, *, sample_rate, max_block_size=None) reads the scene's JSON text. A malformed or refused document raises SonareError with INVALID_FORMAT. An unknown key in the mapping passed as scene= raises SonareValueError and reports its path under scene.. max_block_size bounds the frames of every process and drain call: an omitted value takes the library default and an explicit 0 is refused. Strips are addressed by their index in [0, strip_count) (strip_count is a read-only property) or by their string id (StripRef), and a strip handle is owned by the native mixer, so a strip is only usable while the mixer is open.
close() is safe to call more than once, with closes the mixer on leaving the block, and a mixer that is garbage collected closes itself. Every other call on a closed mixer raises SonareError with INVALID_STATE, and close() invalidates every strip, so do not keep results across it.
Mixer members
Create, serialize and release
# Build a mixer from a scene document, or an empty one when ``scene`` is absent.
def __init__(
self,
*,
sample_rate: int,
scene: MixSceneDocument | None = None,
max_block_size: int | None = None,
) -> None: ...
# Build a mixer from a scene's JSON text, as :meth:`to_json` writes it.
@classmethod
def from_json(
cls,
document: str,
*,
sample_rate: int,
max_block_size: int | None = None,
) -> Mixer: ...
# Non-fatal warnings captured when this mixer was built from scene JSON.
def scene_warnings(self) -> list[str]: ...
# Rebuild the graph while preserving automation position and queued events.
def compile(self) -> None: ...
# Serialize the current scene (strips, buses, sends, connections) as JSON text.
def to_json(self) -> str: ...
# Release the underlying native mixer.
def close(self) -> None: ...
# Return the object itself for ``with`` use.
def __enter__(self) -> Mixer: ...
# Close the object on leaving the ``with`` block; never suppresses exceptions.
def __exit__(self, *_exc: object) -> None: ...Strips, buses and VCA groups
# The largest ``num_samples`` one process call accepts.
@property
def max_block_size(self) -> int: ...
# Return the number of strips in the mixer.
@property
def strip_count(self) -> int: ...
# Add a channel strip to the mixer topology.
def add_strip(
self,
id: str,
*,
enabled: bool = True,
lufs: bool = True,
true_peak: bool = True,
true_peak_oversample: int | None = None,
) -> int: ...
# Add a bus to the mixer topology.
def add_bus(self, id: str, role: MixBusRole = 'aux') -> None: ...
# Remove a bus by id from the mixer topology.
def remove_bus(self, id: str) -> None: ...
# Send a strip or bus into a submix bus, or back to the master.
def set_output_bus(self, source_id: str, bus_id: str) -> None: ...
# Return the number of buses in the mixer topology.
@property
def bus_count(self) -> int: ...
# Add a VCA group with the given id, gain offset, and strip members.
def add_vca_group(
self,
id: str,
gain_db: float = 0.0,
members: Sequence[str] | None = None,
) -> None: ...
# Remove a VCA group by id from the mixer topology.
def remove_vca_group(self, id: str) -> None: ...
# Set an existing VCA group's gain in dB.
def set_vca_group_gain_db(self, id: str, gain_db: float) -> None: ...
# Replace an existing VCA group's strip membership.
def set_vca_group_members(self, id: str, members: Sequence[str]) -> None: ...
# Return the number of VCA groups in the mixer topology.
@property
def vca_group_count(self) -> int: ...
# Return the index of the strip with ``id``.
def strip_by_id(self, id: str) -> int: ...Strip controls and sends
# Set a strip's solo state (takes effect without a recompile).
def set_soloed(self, strip: StripRef, soloed: bool) -> None: ...
# Mark a strip solo-safe so other strips' solo never implied-mutes it.
def set_solo_safe(self, strip: StripRef, solo_safe: bool) -> None: ...
# Invert the polarity of the left and/or right channel of a strip.
def set_polarity_invert(self, strip: StripRef, invert_left: bool, invert_right: bool) -> None: ...
# Set a strip's pan law (a :data:`PanLaw` token such as ``"const3Db"``).
def set_pan_law(self, strip: StripRef, pan_law: PanLaw) -> None: ...
# Set a per-strip channel delay in samples, moving it later than the other strips.
def set_channel_delay_samples(self, strip: StripRef, delay_samples: int) -> None: ...
# Set a strip's direct VCA trim in dB (persisted as the scene's ``vcaOffsetDb``).
def set_vca_offset_db(self, strip: StripRef, offset_db: float) -> None: ...
# Set independent left/right pan positions in [-1, 1] for a strip (dual-pan mode).
def set_dual_pan(self, strip: StripRef, left: float, right: float) -> None: ...
# Set a strip's surround pan position (used when feeding a >2-channel bus).
def set_surround_pan(
self,
strip: StripRef,
*,
azimuth: float = 0.0,
divergence: float = 0.0,
lfe: float = 0.0,
) -> None: ...
# Set a strip's fader gain in dB (takes effect without a recompile).
def set_fader_db(self, strip: StripRef, db: float) -> None: ...
# Set a strip's input trim in dB.
def set_input_trim_db(self, strip: StripRef, db: float) -> None: ...
# Set a strip's pan position.
def set_pan(self, strip: StripRef, pan: float, pan_mode: PanMode | None = None) -> None: ...
# Set a strip's stereo width in [0, 2] (0 mono, 1 unchanged, 2 widest).
def set_width(self, strip: StripRef, width: float) -> None: ...
# Set a strip's mute state (takes effect without a recompile).
def set_muted(self, strip: StripRef, muted: bool) -> None: ...
# Snap a strip's gain smoothers to the values already set on it.
def settle(self, strip: StripRef) -> None: ...
# Add a send from a strip to a bus and return its send index.
def add_send(
self,
strip: StripRef,
send_id: str,
destination_bus_id: str,
send_db: float = 0.0,
timing: SendTiming = 'postFader',
) -> int: ...
# Set the level in dB of an existing send on a strip (by send index).
def set_send_db(self, strip: StripRef, index: int, db: float) -> None: ...
# Remove a strip's send by add-order index.
def remove_send(self, strip: StripRef, index: int) -> None: ...Meters
# Read a per-strip meter snapshot at the given tap point.
def strip_meter(self, strip: StripRef, tap: MeterTap = 'postFader') -> MixMeterSnapshot: ...
# Read the post-insert meter for a compiled bus, including master.
def bus_meter(self, bus_id: str) -> MixMeterSnapshot: ...
# Turn the master-output meter on or off and choose what it measures.
def configure_meter(
self,
enabled: bool = True,
*,
true_peak_oversample: int = 4,
measure_lufs: bool = True,
measure_true_peak: bool = True,
) -> None: ...
# Read the master-output meter.
def meter_snapshot(self) -> MixMeterSnapshot: ...
# Return the blocks in which the strip discarded recursive state.
def strip_non_finite_discard_count(self, strip: StripRef) -> int: ...
# Return the blocks in which the bus discarded recursive state.
def bus_non_finite_discard_count(self, bus_id: str) -> int: ...
# Read up to ``max_points`` of the latest goniometer (vectorscope) data.
def read_goniometer_latest(self, strip: StripRef, max_points: int) -> list[GoniometerPoint]: ...
# Mark the end of the signal for every strip, bus and master meter.
def flush_meters(self) -> None: ...Automation and processing
# Schedule a sample-accurate fader (dB) automation event on a strip.
def schedule_fader_automation(
self,
strip: StripRef,
sample_pos: int,
fader_db: float,
curve: AutomationCurve = 'linear',
) -> None: ...
# Schedule a sample-accurate pan automation event on a strip.
def schedule_pan_automation(
self,
strip: StripRef,
sample_pos: int,
pan: float,
curve: AutomationCurve = 'linear',
) -> None: ...
# Schedule a sample-accurate stereo-width automation event on a strip.
def schedule_width_automation(
self,
strip: StripRef,
sample_pos: int,
width: float,
curve: AutomationCurve = 'linear',
) -> None: ...
# Schedule a sample-accurate send-level (dB) automation event on a strip.
def schedule_send_automation(
self,
strip: StripRef,
send_index: int,
sample_pos: int,
db: float,
curve: AutomationCurve = 'linear',
) -> None: ...
# Schedule a sample-accurate insert-parameter automation event.
def schedule_insert_automation(
self,
strip_index: StripRef,
insert_index: int,
param_id: int,
sample_pos: int,
value: float,
curve: AutomationCurve = 'linear',
) -> None: ...
# Mix one block of per-strip stereo audio into the stereo master.
def process_stereo(
self,
left_inputs: Sequence[Sequence[float]],
right_inputs: Sequence[Sequence[float]],
) -> MixerStereoResult: ...
# Return the longest audible reverb/delay path to the master, in samples.
@property
def tail_samples(self) -> int: ...
# Return the compiled mixer graph's latency in samples.
@property
def latency_samples(self) -> int: ...
# Drain ``num_samples`` of trailing effect-tail audio with no new input.
def drain_tail_stereo(self, num_samples: int) -> MixerStereoResult: ...Result and strip reference
# Stereo master output of :meth:`Mixer.process_stereo`.
@dataclass(frozen=True, slots=True, eq=False)
class MixerStereoResult:
left: npt.NDArray[np.float32]
right: npt.NDArray[np.float32]
sample_rate: int
StripRef = int | strScene presets and the mixing assistant
mixing_scene_preset(name) returns a built-in scene preset as a scene document mapping you can pass to Mixer(scene=...); it raises TypeError for a non-string name and SonareValueError for a name mixing_scene_preset_names() does not list. The scene format is on Mixing Scene JSON.
# Return a built-in mixer scene preset as a scene document mapping.
def mixing_scene_preset(name: str) -> MixSceneDocument: ...mixing_assistant_suggest(tracks, *, sample_rate, ...) analyses a list of MixAssistantTrack and returns a MixAssistantResult: a suggested scene with the reasoning behind it. A track whose audio is degenerate is excluded and reported with usable false and an exclusion_reason instead of failing the call. mixing_assistant_source_class_names() lists the source-class identifiers the assistant can report, and mixing_assistant_source_class_from_name(name) resolves one to its enum value (SonareValueError for a name outside that list). The workflow is on Mixing Assistant.
# Analyse ``tracks`` and return a suggested scene with the reasoning behind it.
def mixing_assistant_suggest(
tracks: Sequence[MixAssistantTrack],
*,
sample_rate: int,
target_track_lufs: float | None = None,
suggestion_strength: float | None = None,
eq_max_cut_db: float | None = None,
mix_bus_headroom_dbtp: float | None = None,
tempo_bpm: float | None = None,
enable_structure: bool | None = None,
enable_gain: bool | None = None,
enable_balance: bool | None = None,
enable_eq: bool | None = None,
enable_dynamics: bool | None = None,
enable_image: bool | None = None,
enable_high_pass: bool | None = None,
n_fft: int | None = None,
hop_length: int | None = None,
) -> MixAssistantResult: ...
# Return the source-class identifiers the assistant can report.
def mixing_assistant_source_class_names() -> list[str]: ...
# Resolve a source-class identifier to its enum value.
def mixing_assistant_source_class_from_name(name: str) -> int: ...