Python Instrument Types
The records that configure instruments and the string tokens their fields take, as used by Project.bounce and RealtimeEngine.set_synth_instrument. The instrument tasks, SynthPatch rules and live MIDI signatures are on Python Instruments and Live MIDI API.
Instrument records and tokens
The records that configure instruments for Project.bounce and RealtimeEngine.set_synth_instrument, and the string tokens their fields take.
Records
# A host-supplied instrument driven during :meth:`Project.bounce`.
class ExternalInstrument(Protocol):
# Add ``num_frames`` of audio into the planar ``(channels, num_frames)`` float32 array (already zero-filled).
def render(self, channels: np.ndarray, num_frames: int) -> None: ...
# Host-supplied PCM the NativeSynth sample engine plays.
class SampleBank:
def __init__(self) -> None: ...
# Release the native bank (idempotent).
def close(self) -> None: ...
# Return the object itself for ``with`` use.
def __enter__(self) -> SampleBank: ...
# Close the object on leaving the ``with`` block; never suppresses exceptions.
def __exit__(self, *_exc: object) -> None: ...
# Copy mono float frames into the bank and return the new sample's index.
def add_sample(
self,
data: Sequence[float] | np.ndarray,
*,
root_key: int | None = None,
fine_tune_cents: float = 0.0,
source_rate: float | None = None,
loop_start: int = 0,
loop_end: int = 0,
loop_mode: SampleDescLoopMode = 'none',
) -> int: ...
# Append a key/velocity rectangle to keymap set ``set_index``.
def add_zone(
self,
set_index: int,
*,
sample_index: int,
key_lo: int = 0,
key_hi: int | None = None,
vel_lo: int | None = None,
vel_hi: int | None = None,
tune_cents: float = 0.0,
gain: float = 1.0,
pan_units: float = 0.0,
) -> None: ...
# Samples added so far.
@property
def sample_count(self) -> int: ...
# Keymap sets the bank has (one past the highest index used).
@property
def set_count(self) -> int: ...
# Patch for the built-in polyphonic oscillator synth (see :meth:`Project.bounce`).
@dataclass(frozen=True)
class BuiltinSynthConfig:
waveform: SynthWaveform = 'sine'
gain: float | None = None
attack_ms: float | None = None
decay_ms: float | None = None
sustain: float | None = None
release_ms: float | None = None
polyphony: int | None = None
# Patch for the SoundFont (SF2) player (see :meth:`Project.bounce`).
@dataclass(frozen=True)
class Sf2InstrumentConfig:
gain: float | None = None
polyphony: int | None = None
prefer_model_for_modeled_families: bool = False
clear_bank_rig: bool = False
gs_efx_realization: GsEfxRealization = 'modern'
# One :meth:`Project.sound_font_manifest` entry: a (channel, bank, program) combination the arrangement plays, with the backend it resolves to (a :data:`SourceBackend` token) and the resolved SF2 preset name (GS fallback included; empty for the synth fallback).
@dataclass(frozen=True)
class Sf2ProgramStatus:
channel: int
bank: int
program: int
backend: SourceBackend
preset_name: str
# Versioned NativeSynth patch (see :meth:`Project.bounce` and :meth:`RealtimeEngine.set_synth_instrument`).
@dataclass(frozen=True)
class SynthPatch:
preset: str | None = None
engine_mode: SynthEngineMode = 'default'
waveform: SynthOscWaveform = 'default'
unison: int | None = None
detune_cents: float | None = None
drift_cents: float | None = None
drive: float | None = None
filter_model: SynthFilterModel = 'default'
filter_output: SynthFilterOutput = 'default'
cutoff_hz: float | None = None
hp_cutoff_hz: float | None = None
sample_hold_hz: float | None = None
bit_depth: float | None = None
pitch_offset_cents: float | None = None
resonance_q: float | None = None
key_track: float | None = None
env_to_cutoff_cents: float | None = None
vel_to_cutoff_cents: float | None = None
amp_attack_ms: float | None = None
amp_decay_ms: float | None = None
amp_sustain: float | None = None
amp_release_ms: float | None = None
filter_attack_ms: float | None = None
filter_decay_ms: float | None = None
filter_sustain: float | None = None
filter_release_ms: float | None = None
lfo_rate_hz: float | None = None
lfo_to_pitch_cents: float | None = None
lfo_shape: SynthLfoShape = 'default'
lfo2_rate_hz: float | None = None
glide_ms: float | None = None
body: SynthBodyType = 'default'
body_mix: float | None = None
stereo_spread: float | None = None
retrigger: SynthRetrigger = 'default'
mod_routings: tuple[SynthModRouting, ...] | None = None
gain: float | None = None
polyphony: int | None = None
bus_drive: float | None = None
sample_set: int | None = None
sample_level: float | None = None
sample_loop: SampleLoopMode = 'default'
sample_start_offset: float | None = None
sample_key_track: SampleKeyTrack = 'default'
sample_bank: SampleBank | None = None
use_gm_programs: bool | None = None
engine_params: Mapping[str, float] | None = None
drift_rate_hz: float | None = None
amp_delay_ms: float | None = None
amp_hold_ms: float | None = None
filter_delay_ms: float | None = None
filter_hold_ms: float | None = None
one_shot: bool | None = None
# One NativeSynth mod-matrix routing (see :class:`SynthPatch`).
@dataclass(frozen=True)
class SynthModRouting:
source: SynthModSource
destination: SynthModDestination
depth: float
# One numeric or boolean synth parameter as the catalog functions describe it.
@dataclass(frozen=True)
class SynthParamInfo:
name: str
type: Literal['number', 'boolean']
default: float | bool
unit: MasteringInsertParamUnit
integer: bool = False
min: float | None = None
max: float | None = None
active_when: tuple[tuple[SynthParamCondition, ...], ...] | None = None
# One condition another patch field must meet, as one of the conditions of an alternative in :attr:`SynthParamInfo.active_when`.
@dataclass(frozen=True)
class SynthParamCondition:
key: str
scope: Literal['engine', 'patch']
relation: Literal['eq', 'ne', 'gt', 'ge', 'lt', 'le']
value: float | bool | strSynthPatchEnumParamInfo describes a closed-set patch parameter and lists its accepted values in catalog order. SynthPatchParamInfo is the union of the numeric, boolean and enum patch parameter records.
# One closed-set field in :func:`synth_patch_param_info`.
@dataclass(frozen=True)
class SynthPatchEnumParamInfo:
name: str
type: Literal['enum']
values: tuple[str, ...]
default: str
SynthPatchParamInfo: TypeAlias = SynthParamInfo | SynthPatchEnumParamInfoProjectInstrument is the stored instrument configuration; its kind determines which patch or config fields apply. ProjectDestinationInstrument adds the project destination id when reading a stored binding. When passed to Project.set_destination_instrument, a kind that does not match patch or config raises TypeError; an unpersistable patch is reported as NotSupported.
# Instrument and optional bank/program bound to one project destination.
@dataclass(frozen=True)
class ProjectInstrument:
kind: ProjectInstrumentKind
patch: SynthPatch | None = None
config: BuiltinSynthConfig | Sf2InstrumentConfig | None = None
sound_font_uri: str | None = None
use_gm_programs: bool | None = None
bank_msb: int | None = None
bank_lsb: int | None = None
program: int | None = None
# A stored instrument and the MIDI destination it serves.
@dataclass(frozen=True, kw_only=True)
class ProjectDestinationInstrument(ProjectInstrument):
destination_id: int
kind: ProjectInstrumentKind
patch: SynthPatch | None = None
config: BuiltinSynthConfig | Sf2InstrumentConfig | None = None
sound_font_uri: str | None = None
use_gm_programs: bool | None = None
bank_msb: int | None = None
bank_lsb: int | None = None
program: int | None = NoneTokens
GsEfxRealization: TypeAlias = Literal['modern', 'classic']
SourceBackend: TypeAlias = Literal['synth', 'sf2']
SynthEngineMode = Literal['default', 'subtractive', 'fm', 'karplusStrong', 'modal', 'additive', 'percussion', 'piano', 'pipeOrgan', 'bowedString', 'reed', 'brass', 'flute', 'pluckedString', 'vocal', 'freeReed', 'harpsichord', 'sample', 'singing']
SynthOscWaveform = Literal['default', 'sine', 'saw', 'square', 'triangle', 'noise']
SynthWaveform = Literal['sine', 'saw', 'sawtooth', 'square', 'triangle']
SynthFilterModel = Literal['default', 'svf', 'transistorLadder', 'diodeLadder', 'sallenKey', 'svf4Pole']
SynthFilterOutput = Literal['default', 'lowPass', 'bandPass', 'highPass']
SynthBodyType = Literal['default', 'none', 'guitar', 'violin', 'woodTube', 'brassBell', 'vocal']
SampleLoopMode = Literal['default', 'none', 'continuous', 'keyDown']
SampleKeyTrack = Literal['default', 'on', 'off']
SynthRetrigger = Literal['default', 'free', 'note']
SynthLfoShape = Literal['default', 'triangle', 'sine', 'random']
SampleDescLoopMode = Literal['none', 'continuous', 'keyDown']
SynthModSource = Literal['none', 'ampEnv', 'filterEnv', 'lfo1', 'lfo2', 'velocity', 'keyTrack', 'modWheel', 'random', 'breath', 'aftertouch', 'expressionCc', 'pitchBend']
SynthModDestination = Literal['none', 'pitchCents', 'cutoffCents', 'ampGain', 'panUnits', 'resonanceQ', 'vibratoDepthCents', 'filterEnvDepth', 'lfo1RateScale', 'excitationForce', 'excitationPosition', 'excitationBrightness', 'spectrumMorph']
ControllerInput = Literal['controlChange', 'channelPressure', 'polyPressure', 'pitchBend', 'velocity']
ControllerAxis = Literal['none', 'excitation', 'position', 'brightness', 'morph', 'loudness', 'pitchCents', 'vibratoDepth']
Articulation = Literal['poly', 'monoRetrigger', 'monoLegato']
MpeDimension = Literal['bend', 'pressure', 'timbre']
NoteTracking = Literal['last', 'lowest', 'highest', 'all']
PartRigMode = Literal['bank', 'none', 'chain']
PART_RIG_ALL_PARTS = 255
PART_RIG_MODES: tuple[str, ...] = get_args(PartRigMode)