Skip to content

Python Realtime Engine API ​

RealtimeEngine is the sample-accurate engine behind live playback and offline renders. This page holds the lifecycle rules and the signatures for construction, transport and timing, clips and parameters, capture, rendering and telemetry; the guide is Realtime Engine. Track lanes, buses, strips and clip page providers are on Python Engine Mixing API, and instruments and live MIDI on Instruments and Live MIDI.

Where each task lives ​

TaskAPIGuide
Schedule MIDI clips into the live engine, sample-accuratelyRealtimeEngine.set_midi_clips([...]) with EngineMidiClipSchedule / EngineMidiEvent, RealtimeEngine.sample_at_ppq(ppq) — ppq is pulses per quarter note, the musical-time unitRealtime Engine
Set per-track cue monitoringRealtimeEngine.set_track_monitor_mode(track_id, mode, render_frame=None) with EngineTrackMonitorMode (off/pfl/afl, exact tokens — PFL listens pre-fader, AFL post-fader); track_id is a track declared through set_track_lanes. process() folds an armed cue into the program output; offline renders, bounces and freezes never include itRealtime Engine
Read wide meters and scopesdrain_meter_telemetry(...) (its records carry the per-channel planes), configure_scope_telemetry(...), drain_scope_telemetry(...)Realtime Engine
Edit the engine's clip set one clip at a timeRealtimeEngine.upsert_clip, remove_clipRealtime Engine
Reset processors, prime a repeat render, read tail and latencyreset_processor_state, prime_offline_parameters, tail_samples, graph_latency_samplesRealtime Engine
Read engine audio as arrays, and size the lane listRealtimeEngine.process (also with with_monitor=True) and render_offline return float32 NumPy arrays (one per channel, in a list), and EngineBounceResult.interleaved is a float32 array. set_track_lanes accepts at most MAX_TRACK_LANES (32) lanes and raises SonareValueError for a longer listRealtime Engine
Mix and automate the engine's tracks liveLane/strip methods plus set_track_sends(track_id, sends), set_track_output_bus(track_id, bus_id), set_bus_insert_param(bus_id, insert_index, name, value), set_bus_insert_bypassed(bus_id, insert_index, bypassed), resolve_strip_insert_automation_id(ref, insert_index, param_name), resolve_bus_insert_automation_id(...), and set_param_smoothing_ms(...)Realtime Engine
Ask whether a sidechain binding would be accepted, and why notRealtimeEngine.can_set_strip_sidechain, can_set_bus_sidechain returning SidechainCheckRealtime Engine
Address fader, pan and width automation by track, bus or masterresolve_strip_automation_id(ref, kind) for a track id or "master", resolve_bus_automation_id ("faderDb", "pan" or, for the master only, "width"). Every resolve_*_automation_id, resolve_instrument_automation_id(destination_id, param_name) included, raises SonareValueError for an unknown track, bus, insert, destination or parameter, or one that is not realtime-safeRealtime Engine

Lifecycle ​

Create ​

RealtimeEngine(sample_rate, max_block_size=None, *, command_capacity=None, telemetry_capacity=None, max_channels=None) builds an engine, and prepare(...) sizes the queues and scratch again with the same arguments. MAX_TRACK_LANES (32) is the most lanes set_track_lanes accepts.

Use ​

Control calls queue a command that the audio side applies at the start of its next block. process() is the block call of a realtime host and returns float32 NumPy arrays, one per channel; render_offline, bounce_offline and freeze_offline render offline, and with prepare and settle_parameters belong off a live audio callback. A command queue or payload ring that is full is an error, not a silent drop.

Release ​

close() is idempotent and the engine works as a context manager (with sonare.RealtimeEngine(48000) as engine:); see Releasing Native Handles. A call after close() raises SonareError with INVALID_STATE.

Errors ​

A call refused for its own argument (an out-of-range value, an unknown or wrong-kind id or name, a malformed patch or strip, a lane list past MAX_TRACK_LANES) raises SonareValueError. State left by earlier calls raises SonareError with INVALID_STATE; a full queue or failed allocation is OUT_OF_MEMORY; a feature compiled out of the build is NOT_SUPPORTED. The full table is Error Contract.

Construction and lifecycle members ​

python
def __init__(
    self,
    sample_rate: int,
    max_block_size: int | None = None,
    *,
    command_capacity: int | None = None,
    telemetry_capacity: int | None = None,
    max_channels: int | None = None,
) -> None: ...

# Release the native engine; idempotent. Any later
def close(self) -> None: ...

# Return the engine for use as a context manager.
def __enter__(self) -> RealtimeEngine: ...

# Close the engine on leaving the ``with`` block.
def __exit__(self, *_exc: object) -> None: ...

def prepare(
    self,
    sample_rate: int,
    max_block_size: int | None = None,
    command_capacity: int | None = None,
    telemetry_capacity: int | None = None,
    max_channels: int | None = None,
) -> None: ...

Transport, timing and markers ​

python
# Start the transport; ``render_frame`` is a non-negative integer frame
def play(self, render_frame: int | None = None) -> None: ...

def stop(self, render_frame: int | None = None) -> None: ...

def seek_sample(self, timeline_sample: int, render_frame: int | None = None) -> None: ...

def seek_ppq(self, ppq: float, render_frame: int | None = None) -> None: ...

def settle_parameters(self) -> None: ...

def prime_offline_parameters(self, num_channels: int, block_size: int | None = None) -> None: ...

@property
def max_block_size(self) -> int: ...

@property
def tail_samples(self) -> int: ...

@property
def graph_latency_samples(self) -> float: ...

def flush_control_commands(self) -> None: ...

def settle_insert_parameters(self) -> None: ...

def apply_commands_due_now_preserving_future(self) -> None: ...

def apply_project_timeline(self, timeline: ProjectTimeline) -> None: ...

# Queue a reset at the next block head when ``render_frame`` is None;
def reset_master_loudness_meter(self, render_frame: int | None = None) -> None: ...

# Queue a reset of every lane, bus, master and graph processor state at the
def reset_processor_state(self, render_frame: int | None = None) -> None: ...

def set_tempo(self, bpm: float) -> None: ...

# Set the time signature, e.g. 3/4 as ``numerator`` 3, ``denominator`` 4.
def set_time_signature(self, numerator: int, denominator: int) -> None: ...

def set_tempo_segments(self, segments: Sequence[Mapping[str, float]]) -> None: ...

def set_time_signature_segments(self, segments: Sequence[Mapping[str, float]]) -> None: ...

def sample_at_ppq(self, ppq: float) -> int: ...

def set_loop(self, start_ppq: float, end_ppq: float, enabled: bool = True) -> None: ...

def transport_state(self) -> TransportState: ...

# Replace the whole marker set and return the stored markers in the order given.
def set_markers(
    self,
    markers: Sequence[EngineMarker | EngineMarkerInput],
) -> list[EngineMarker]: ...

def markers(self) -> list[EngineMarker]: ...

# Return the marker with the given ``id``.
def marker(self, id: int) -> EngineMarker: ...

# Move the playhead at the next block head when ``render_frame`` is None;
def seek_marker(self, marker_id: int, render_frame: int | None = None) -> None: ...

# Set the loop region from a start and an end marker id.
def set_loop_from_markers(self, start_marker_id: int, end_marker_id: int) -> None: ...

# Configure the metronome.
def set_metronome(self, config: EngineMetronomeConfig) -> None: ...

# Return the current metronome configuration.
def metronome(self) -> EngineMetronomeConfig: ...

def count_in_end_sample(self, start_sample: int, bars: int) -> int: ...

Clips, parameters and automation ​

python
# Replace the whole audio clip set; a refused clip raises and leaves the published set
def set_clips(self, clips: Sequence[EngineClip]) -> None: ...

def upsert_clip(self, clip: EngineClip) -> None: ...

def remove_clip(self, clip_id: int) -> None: ...

# Number of audio clips currently installed.
@property
def clip_count(self) -> int: ...

# Register an automatable parameter; a duplicate id is refused.
def add_parameter(self, info: ParameterInfo) -> None: ...

def clear_parameters(self) -> None: ...

def parameters(self) -> list[ParameterInfo]: ...

# Return the registered parameter with the given ``id``.
def parameter_info(self, id: int) -> ParameterInfo: ...

def set_parameter(
    self,
    param_id: int,
    value: float,
    render_frame: int | None = None,
    *,
    smoothed: bool = False,
) -> None: ...

def set_param_smoothing_ms(self, smoothing_ms: float) -> None: ...

def set_automation_lane(self, param_id: int, points: Sequence[AutomationPoint]) -> None: ...

# Number of automation lanes currently installed.
@property
def automation_lane_count(self) -> int: ...

# Set the clip-page look-ahead window in timeline frames.
def set_clip_page_prefetch_frames(self, frames: int) -> None: ...

# Clip-page look-ahead window in timeline frames.
@property
def clip_page_prefetch_frames(self) -> int: ...

# Pop the next clip-page request the host should service, or None when none is pending.
def pop_clip_page_request(self) -> ClipPageRequest | None: ...

@property
def clip_page_request_overflow_count(self) -> int: ...

@property
def warp_stretch_overflow_count(self) -> int: ...

def set_warp_voice_capacity(self, voices: int) -> None: ...

def warp_voice_capacity(self) -> int: ...

Capture, graph, rendering and telemetry ​

configure_capture sets the buffer, source, record offset and punch window. Set the dry input monitor separately with set_input_monitor(EngineInputMonitorInput(...)). capture_status() reports dropped_frames, the number of frames discarded since the last capture reset.

python
# Configure capture as a whole; an omitted setting takes its default.
def configure_capture(
    self,
    *,
    capacity_frames: int,
    num_channels: int = 2,
    source: EngineCaptureSource = 'output',
    record_offset_samples: int = 0,
    punch: CapturePunch | None = None,
) -> None: ...

# Turn the dry input monitor on or off at ``monitor.gain``.
def set_input_monitor(self, monitor: EngineInputMonitor | EngineInputMonitorInput) -> None: ...

# Return the dry input monitor, both fields from one write.
def input_monitor(self) -> EngineInputMonitor: ...

# Arm (or disarm) recording into the capture buffer.
def arm_capture(self, armed: bool = True) -> None: ...

# Reset the capture state.
def reset_capture(self) -> None: ...

# Return the current capture state.
def capture_status(self) -> EngineCaptureStatus: ...

# Return the captured audio, one array per channel.
def captured_audio(self) -> list[np.ndarray]: ...

# Install the engine processing graph from ``spec``.
def set_graph(self, spec: EngineGraphSpec) -> None: ...

# Number of nodes in the installed graph.
@property
def graph_node_count(self) -> int: ...

# Number of connections in the installed graph.
@property
def graph_connection_count(self) -> int: ...

# Render one block and return the processed channel copies; inputs are not modified.
@overload
def process(
    self,
    channels: PlanarChannels,
    *,
    with_monitor: Literal[False] = False,
) -> list[np.ndarray]: ...
# Render one block and return the program planes and the monitor planes.
@overload
def process(
    self,
    channels: PlanarChannels,
    *,
    with_monitor: Literal[True],
) -> EngineProcessWithMonitorResult: ...
@overload
def process(
    self,
    channels: PlanarChannels,
    *,
    with_monitor: bool,
) -> list[np.ndarray] | EngineProcessWithMonitorResult: ...

# Render one offline span from the current transport position; ``block_size`` None is the
def render_offline(
    self,
    channels: PlanarChannels,
    *,
    block_size: int | None = None,
    finalize: bool = True,
) -> list[np.ndarray]: ...

# End a chunked offline render, releasing held notes and flushing delay lines; required
def finish_offline_render(self) -> None: ...

# Render the whole span in one call and return the interleaved mix.
def bounce_offline(self, options: EngineBounceOptions) -> EngineBounceResult: ...

# Render the source layer over the span and install it as the only clip.
def freeze_offline(self, options: EngineFreezeOptions) -> EngineFreezeResult: ...

# Drain up to ``max_records`` engine telemetry records; the rest stay queued.
def drain_telemetry(self, max_records: int = 1024) -> list[EngineTelemetry]: ...

# Drain meter records with one measurement per plane and no right value for mono.
def drain_meter_telemetry(self, max_records: int = 1024) -> list[MeterTelemetryRecord]: ...

# Return per-insert gain reduction in dB (<= 0) for a meter target's strip.
def meter_target_insert_gain_reduction(self, target_id: int) -> np.ndarray: ...

# Enable scope telemetry and return the applied band count.
def configure_scope_telemetry(self, interval_frames: int, band_count: int) -> int: ...

# Drain up to ``max_records`` scope telemetry records.
def drain_scope_telemetry(self, max_records: int = 1024) -> list[ScopeTelemetryRecord]: ...

Build and host information ​

abi_version() returns the aggregate C ABI version, which folds every subsystem ABI number into one 32-bit value so a prebuilt binding can detect an incompatible native library. capability_catalog() returns the loaded library's complete processor and preset catalog (Capability Catalog); a parameter bound or default is None where the processor publishes no descriptor. system_info() returns the host the library runs on as a dict with cpu (logical_cores, physical_cores), memory (total_gb, available_gb) and parallel (enabled, workers, strategy); a fact the platform cannot report is absent.

python
# Return the aggregate libsonare C ABI version.
def abi_version() -> int: ...

# Return the loaded library's complete processor and preset catalog.
def capability_catalog() -> CapabilityCatalog: ...

# Return the host this library runs on: CPU cores, memory and parallelism.
def system_info() -> dict[str, Any]: ...