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 send_rate() -> Number

The CC send rate in Hz.

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 >> session.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. Create with session.create_midi_track("name") in fn setup(); look it up with session.midi_track("name"). Choose its output with >>, as in track >> MidiOutput("synth", 2). A new track has no output until then.

Implements: Json, whose json it inherits

fn delete() -> NUL

Deletes the track and disconnects its input and output.

fn set_name(name: String) -> MidiTrack

Changes the track name. Existing handles keep following this track.

Parameters:

  • name (String) — unique track name

Returns: MidiTrack — the track, for chaining

fn set_color(index: Number) -> MidiTrack

Sets the track colour. It shows on the track’s header, clips and Mixer strip.

Parameters:

  • index (Number) — palette index from 0 to 23: 12 bright hues, then the same muted

Returns: MidiTrack — the track, for chaining

fn color() -> Number

The track colour. A new track takes the next free palette colour.

Returns: Number — palette index from 0 to 23

fn name() -> String

The track name.

fn output() -> Dict<String | Number, Any>?

The output port and channel, or NUL for no output.

fn input() -> Dict<String | Number, Any>?

The input port and channel (NUL for all channels), or NUL when unset.

fn monitor() -> Monitor

The input monitoring mode.

fn velocity() -> Number | Signal | Pattern

The configured velocity source; 100 until set_velocity changes it.

fn tuning() -> Number?

The pitch-bend range in semitones, or NUL when disabled.

fn mpe() -> Dict<String | Number, Any>?

The MPE range and member channel bounds, or NUL when disabled.

fn key() -> Key?

The track key, or NUL when unset.

fn set_input(alias: String, channel: Number? = NUL) -> 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: Monitor) -> MidiTrack

Set the monitor mode: whether what is played on the input passes through to the output. Monitor.auto passes it while the track is not playing its own material: the transport is stopped, or it has no pattern.

Example:

track.set_monitor(Monitor.input)

Parameters:

  • mode (Monitor) — when the input passes through

Returns: MidiTrack — the track, for chaining

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

Set the default velocity for this track. A new track plays at 100. A note with its own velocity keeps it.

Example:

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

Parameters:

  • vel (Number | Signal | Pattern) — note velocity (1-127), or a signal or pattern read as each note fires; a value from a signal or pattern is held to 1-127

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? = NUL) -> 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? = NUL, zone_lo: Number? = NUL, zone_hi: Number? = NUL) -> 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 | String | Scale, root: Note? = NUL) -> 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. A change is heard from the next cycle, on a pattern already playing. 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?) — root note (e.g. C4, or a MIDI number such as 60); omit when passing a Key

Returns: MidiTrack — the track, for chaining

fn mute() -> MidiTrack

Mutes the track, like Live’s Track Activator: its notes and CC stop at once, and the notes it holds get their note-offs. MIDI coming in through the track is muted too.

Returns: MidiTrack — the track, for chaining

fn unmute() -> MidiTrack

Unmutes the track. Its pattern is heard again from its next note.

Returns: MidiTrack — the track, for chaining

fn is_muted() -> Boolean

Returns whether the track is muted.

Returns: Boolean — true if the track is muted

fn solo() -> MidiTrack

Solos the track, and only this track: every other solo is released and every other track — audio and MIDI — falls silent, as a plain click on Live’s Solo button.

Returns: MidiTrack — the track, for chaining

fn add_solo() -> MidiTrack

Adds the track to the soloed tracks and keeps the others soloed, as a Cmd-click on Live’s Solo button.

Returns: MidiTrack — the track, for chaining

fn unsolo() -> MidiTrack

Releases the track’s solo. When no track is soloed, every track is heard.

Returns: MidiTrack — the track, for chaining

fn is_soloed() -> Boolean

Returns whether the track is soloed.

Returns: Boolean — true if the track is soloed

How outgoing MIDI is aligned with the audio output.

  • MidiLatency.auto — MIDI is timestamped for the moment the audio reaches the DAC, including plugin delay compensation, so hardware stays in step with what you hear. The default.
  • MidiLatency.manual — Only the per-port trims apply.
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_clock_send() -> Boolean

Whether outgoing MIDI clock is enabled.

fn midi_clock_source() -> String?

The followed input alias, or NUL for the internal clock.

fn midi_connected() -> Dict<String, String>

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_events(limit: Number = 100, port: String? = NUL) -> Array<Dict<String | Number, Any>>

Recent input messages, oldest first, from connected input ports. Reads do not consume messages or wait. At most 2000 messages are retained; the input service publishes within 100 ms. Each entry has port (alias), message (raw MIDI bytes), channel (1-16, or NUL for system messages), and age_ms since hardware receipt. Messages contain up to three bytes; complete SysEx payloads are not retained.

Parameters:

  • limit (Number) — maximum messages, a whole number from 0 to 2000 (default 100)
  • port (String?) — exact input alias filter, or NUL for all inputs
fn midi_input_ports() -> Array<String>

Lists all available MIDI input ports.

Returns: Array — the available input port names as Strings

fn midi_latency() -> MidiLatency

The outgoing MIDI alignment mode.

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_output_ports() -> Array<String>

Lists all available MIDI output ports.

Returns: Array — the available output port names as Strings

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_routing_report() -> NUL

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

Returns: NUL — nothing; prints the routing

fn midi_trace() -> Boolean

Whether MIDI timing trace recording is enabled.

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: turn it on with set_midi_trace(true) for a measurement. Report while the transport still rolls: STOP drains the trace 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: MidiLatency) -> NUL

Sets how outgoing MIDI is aligned with the audio output.

Example:

set_midi_latency(MidiLatency.manual)

Parameters:

  • mode (MidiLatency) — the alignment; MidiLatency.auto is the default

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