Skip to content

std/midi

Always in scope — no import required.

MIDI output: tracks, control-change lanes, and port management.

A MIDI track’s CC lane, from track.cc(number). Takes a value, a pattern or a signal via <<, and sends on wherever the track is routed.

fn set_send_rate(hz: Number) -> CcOutput

Set the CC send rate in Hz (default 30). Higher values produce smoother automation but more MIDI traffic.

Example:

track.cc(74).set_send_rate(60) << Sine(0.5).range(0, 127)

Parameters:

  • hz (Number) — send rate in Hz

Returns: CcOutput — the CC output handle, for chaining

MidiOutput: a MIDI output port and channel, a destination for >> — Live’s “MIDI To”. Made by MidiOutput(alias, channel); it can only end a >> chain.

fn MidiOutput(alias: String, channel: Number = NUL) -> MidiOutput

A MIDI output port and channel, as a destination for >> — Live’s “MIDI To”. track >> MidiOutput("synth", 2) sends the track there; a playing pattern, its CC and its input thru move from the next cycle, with no << needed. track >> nowhere sets it back to no output.

Example:

bass >> MidiOutput("synth"), lead >> MidiOutput("daw", 2)

Parameters:

  • alias (String) — output port alias, as a [[midi.outputs]] entry declares it
  • channel (Number) — MIDI channel 1-16 (optional; default 1)

Returns: MidiOutput — the port and channel, to route to with >>

A MIDI track: plays patterns and CC to a hardware or virtual MIDI port. Construct with MidiTrack("name"); choose its output with >>, as in track >> MidiOutput("synth", 2). A new track has no output until then.

fn MidiTrack(name: String) -> MidiTrack

Creates a MIDI track with the given name.

Every track has a name; there is no unnamed track. The name is the track’s identity: asking for a name that already has a live track returns that track, with its output, input, velocity and CC intact. Re-executing the line therefore talks to the same track instead of building a second one. Two tracks need two names.

A new track has no output — Live’s “No Output” — and sends nothing until >> routes it: track >> MidiOutput("synth", 2).

Example:

MidiTrack("bass")

Parameters:

  • name (String) — the track’s name and identity (not empty)

Returns: MidiTrack — the track with that name, created if it does not exist yet

fn set_input(alias: String, channel: Number?) -> MidiTrack

Set the MIDI input port and optional channel.

Example:

track.set_input("keys"), track.set_input("keys", 1)

Parameters:

  • alias (String) — input port alias, as a [[midi.inputs]] entry declares it, or "all" for every input
  • channel (Number) — MIDI channel 1-16 (optional)

Returns: MidiTrack — the track, for chaining

fn set_monitor(mode: String) -> MidiTrack

Set the monitor mode (“auto”, “in”, “off”).

Example:

track.set_monitor("in")

Parameters:

  • mode (String) — monitor mode: “auto”, “in”, or “off”

Returns: MidiTrack — the track, for chaining

fn set_velocity(vel: Number or Signal or Pattern) -> MidiTrack

Set the default velocity for this track.

Example:

track.set_velocity(80) or track.set_velocity([100 60 80 120])

Parameters:

  • vel (Number | Signal | Pattern) — note velocity (0-127), or a signal or pattern read as each note fires

Returns: MidiTrack — the track, for chaining

fn cc(cc_number: Number) -> CcOutput

Get a CC output handle for the given controller number. Use << to assign values, patterns, or signals.

Example:

track.cc(74) << Sine(0.5).range(0, 127)

Parameters:

  • cc_number (Number) — CC controller number (0-127)

Returns: CcOutput — a CC output handle, assignable with <<

fn set_tuning(bend_range: Number?) -> MidiTrack

Enable microtonal pitch bend output. Uses the MIDI default ±2 semitone range (works with any synth).

Example:

track.set_tuning(), track.set_tuning(48)

Parameters:

  • bend_range (Number) — pitch-bend range in semitones (optional; default ±2)

Returns: MidiTrack — the track, for chaining

fn set_mpe(range: Number?, zone_lo: Number?, zone_hi: Number?) -> MidiTrack

Enable MPE (per-note channel allocation) for polyphonic microtonal output.

Example:

track.set_mpe(), track.set_mpe(24), track.set_mpe(48, 2, 9)

Parameters:

  • range (Number) — pitch-bend range in semitones (optional, defaults to 48)
  • zone_lo (Number) — low member channel (optional, defaults to 2)
  • zone_hi (Number) — high member channel (optional, defaults to 16)

Returns: MidiTrack — the track, for chaining

fn set_key(scale: Key or String or Scale, root: Note or Number?) -> MidiTrack

Set a track-level key for degree resolution and auto-quantization. Degrees (^1, ^2, …) resolve from this key without .in_key(), and absolute notes are quantized to the nearest scale tone. Pass a Key value, or a scale name/Scale with a root note.

Example:

track.set_key(Key(C4, "minor")) or track.set_key("minor", C4)

Parameters:

  • scale (Key | String | Scale) — a Key value, or a scale name/Scale value
  • root (Note | Number) — root note (e.g. C4 or a MIDI number); omit when passing a Key

Returns: MidiTrack — the track, for chaining

fn midi_clock_report() -> NUL

Print MIDI clock status: source, BPM, transport state, and PLL diagnostics.

Example:

midi_clock_report()

Returns: NUL — nothing; prints the status

fn midi_connected() -> Dict

Checks the current MIDI connection status.

Returns: Dict — {alias: port_name} for every connected output port; empty when none is connected

fn midi_disconnect(alias: String) -> NUL

Disconnects a MIDI output port. Tracks routed to it keep their output, and are heard again once reload_preferences() reconnects it.

Example:

midi_disconnect("synth")

Parameters:

  • alias (String) — output port alias, as a [[midi.outputs]] entry declares it

Returns: NUL — nothing

fn midi_input_disconnect(alias: String) -> NUL

Disconnects a MIDI input port by alias.

Example:

midi_input_disconnect("kb")

Parameters:

  • alias (String) — input port alias, as a [[midi.inputs]] entry declares it

Returns: NUL — nothing

fn midi_input_ports() -> Array

Lists all available MIDI input ports.

Returns: Array — the available input port names as Strings

fn midi_latency_report() -> NUL

Print the MIDI output alignment report. Shows where the automatic offset comes from — audio buffer, device latency, plugin delay compensation — and what each port ends up with after its trims.

Example:

midi_latency_report()

Returns: NUL — nothing; prints the report

fn midi_port_clock(alias: String) -> Boolean

Returns whether a MIDI output port is opted in to receiving clock. Set by send_clock in the port’s [[midi.outputs]] entry.

Example:

midi_port_clock("cv")

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry

Returns: Boolean — true if the port receives clock

fn midi_port_clock_trim(alias: String) -> Number

Returns a MIDI output port’s clock-only trim in milliseconds. Set by clock_trim_ms in the port’s [[midi.outputs]] entry, and added to midi_port_trim for clock and transport messages only.

Example:

midi_port_clock_trim("cv")

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry

Returns: Number — the current clock trim in milliseconds

fn midi_port_trim(alias: String) -> Number

Returns a MIDI output port’s timing trim in milliseconds. Set by trim_ms in the port’s [[midi.outputs]] entry, and applied to notes and clock alike, on top of the automatic alignment.

Example:

midi_port_trim("cv")

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry

Returns: Number — the current trim in milliseconds

fn midi_ports() -> Array

Lists all available MIDI output ports.

Returns: Array — the available output port names as Strings

fn midi_routing_report() -> NUL

Displays the current MIDI routing: connected output/input ports and active slots.

Returns: NUL — nothing; prints the routing

fn midi_trace_report() -> NUL

Print the MIDI timing trace: clock tick spacing, note dispatch, phase errors. Prints and clears what has been captured so far; recording continues. A bench instrument, off by default — recording takes a lock on the audio thread, so turn it on with set_midi_trace(true) for a measurement and off again. Report while the transport still rolls: STOP drains the buffer to stderr.

Example:

midi_trace_report()

Returns: NUL — nothing; prints the trace

fn set_midi_clock_send(enabled: Boolean) -> NUL

Enable/disable MIDI clock output (master mode). Sends 24 PPQ clock ticks plus Start/Continue/Stop to every output port whose [[midi.outputs]] entry says send_clock = true. This is the master switch; ports opt in separately.

Example:

set_midi_clock_send(true)

Parameters:

  • enabled (Boolean) — true to enable, false to disable

Returns: NUL — nothing

fn set_midi_clock_source(alias: String = NUL) -> NUL

Sets where the tempo and transport come from: an external MIDI clock on an input port (follower mode), or resonon’s own clock.

Example:

set_midi_clock_source("daw"), set_midi_clock_source()

Parameters:

  • alias (String) — input port alias to follow, as a [[midi.inputs]] entry declares it; omit for resonon’s own clock

Returns: NUL — nothing

fn set_midi_latency(mode: String) -> NUL

Sets how outgoing MIDI is aligned with the audio output. "auto" (the default) timestamps MIDI for the moment the audio reaches the DAC, including plugin delay compensation, so hardware stays in step with what you hear. "manual" disables that and leaves only the per-port trims.

Example:

set_midi_latency("manual")

Parameters:

  • mode (String) — "auto" or "manual"

Returns: NUL — nothing

fn set_midi_trace(on: Boolean) -> NUL

Start or stop the MIDI timing trace. true clears the buffer and begins recording; false stops and prints what was captured.

Example:

set_midi_trace(true), set_midi_trace(false)

Parameters:

  • on (Boolean) — true to start recording, false to stop and report

Returns: NUL — nothing