Skip to content

Score (NRT)

Non-real-time rendering. A Score is a timestamped OSC bundle sequence handed to the offline engine, producing an audio file without a live audio device.

nanosynth.score

Non-real-time (NRT) score rendering for offline audio synthesis.

Score

A sequence of timestamped OSC bundles for offline (NRT) rendering.

Build a score by adding OSC messages at specific timestamps, then call render() to produce an audio file without real-time audio hardware.

Example::

from nanosynth import Score, SynthDefBuilder, SinOsc, Out

with SynthDefBuilder(freq=440.0) as b:
    Out.ar(bus=0, source=SinOsc.ar(frequency=b["freq"]) * 0.3)
sd = b.build(name="sine")

score = Score()
score.add_synthdef(0.0, sd)
score.add_synth(0.0, "sine", freq=440.0)
score.add(1.0, OscMessage("/n_free", 1000))
score.render("output.wav", sample_rate=44100)

add

add(
    time: float, messages: list[OscMessage] | OscMessage
) -> None

Add OSC message(s) at the given time (seconds).

add_synthdef

add_synthdef(time: float, synthdef: SynthDef) -> None

Add a /d_recv command for a SynthDef at the given time.

add_synth

add_synth(
    time: float,
    name: str,
    node_id: int = -1,
    add_action: int = 0,
    target: int = 0,
    **params: float,
) -> None

Add a /s_new command at the given time.

sort

sort() -> None

Sort entries by time (in-place, stable).

duration

duration() -> float

Return the timestamp of the last entry, or 0.0 if empty.

to_binary

to_binary() -> bytes

Serialize to SC's binary command file format.

Format: repeated [int32 packet_size][OSC bundle datagram]. The bundle timestamp is the raw time in seconds (no NTP epoch).

render

render(
    output_path: str | Path,
    *,
    sample_rate: int = 44100,
    header_format: str = "WAV",
    sample_format: str = "int16",
    input_path: str | Path | None = None,
    output_channels: int = 2,
    input_channels: int = 0,
    options: Options | None = None,
) -> None

Render this score to an audio file (non-real-time).

Writes the binary command file to a temp file, then invokes the embedded scsynth NRT renderer.

Args: output_path: Path for the output audio file. sample_rate: Output sample rate in Hz. header_format: Audio file format ("WAV" or "AIFF"). sample_format: Sample encoding ("int16", "int24", "float"). input_path: Optional input audio file for NRT processing. output_channels: Number of output channels. input_channels: Number of input channels. options: Optional Options for engine configuration overrides.