Skip to content

std/midi

Always in scope — no import required.

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

fn 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).send_rate(60) << Sine(0.5).range(0, 127)

Parameters:

  • hz (Number) — send rate in Hz

Returns: CcOutput — the CC output handle, for chaining

A MIDI track: routes a pattern to a hardware or virtual MIDI port. Construct with MidiTrack(channel); connect a port with .output(alias).

fn MidiTrack(channel: Number, velocity: Number = NUL, port_alias: String = NUL, name: String = NUL) -> MidiTrack

Creates a MIDI track on the given channel.

Example:

MidiTrack(1), MidiTrack(1, 100, "daw")

Parameters:

  • channel (Number) — MIDI channel 1-16
  • velocity (Number) — note velocity 0-127
  • port_alias (String) — output port alias (for multi-port setups)
  • name (String) — track name for logging

Returns: MidiTrack — the new MIDI track

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

Set the MIDI output port and optional channel.

Example:

track.output("synth"), track.output("synth", 2)

Parameters:

  • alias (String) — output port alias
  • channel (Number) — MIDI channel 1-16 (optional)

Returns: MidiTrack — the track, for chaining

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

Set the MIDI input port and optional channel.

Example:

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

Parameters:

  • alias (String) — input port alias
  • channel (Number) — MIDI channel 1-16 (optional)

Returns: MidiTrack — the track, for chaining

fn monitor(mode: String) -> MidiTrack

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

Example:

track.monitor("on")

Parameters:

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

Returns: MidiTrack — the track, for chaining

fn velocity(vel: Number) -> MidiTrack

Set the default velocity for this track.

Example:

track.velocity(80)

Parameters:

  • vel (Number) — default note velocity (0-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 tuning(bend_range: Number?) -> MidiTrack

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

Example:

track.tuning(), track.tuning(48)

Parameters:

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

Returns: MidiTrack — the track, for chaining

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

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

Example:

track.mpe(), track.mpe(24), track.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 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.key(Key(C4, "minor")) or track.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_follow(source: String or Boolean) -> Boolean

Enable/disable MIDI clock follow (follower mode). When enabled, resonon syncs tempo and transport to an external MIDI clock source.

Example:

midi_clock_follow("daw"), midi_clock_follow(false)

Parameters:

  • source (String | Boolean) — input port alias to follow, or false to disable

Returns: Boolean — true when enabled, false when disabled

fn midi_clock_send(enabled: Boolean) -> Boolean

Enable/disable MIDI clock output (master mode). Sends 24 PPQ clock ticks plus Start/Continue/Stop to every output port that has opted in with midi_port_clock. This is the master switch; ports opt in separately.

Example:

midi_clock_send(true)

Parameters:

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

Returns: Boolean — the resulting enabled state

fn midi_clock_status() -> NUL

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

Example:

midi_clock_status()

Returns: NUL — nothing; prints the status

fn midi_connected() -> Boolean or String or Dict

Checks the current MIDI connection status.

Returns: Boolean | String | Dict — false if no ports connected, the port name String if one default port is connected, or a {alias: port_name} Dict for multiple ports

fn midi_disconnect() -> NUL
fn midi_disconnect(alias: String) -> NUL

Disconnects the MIDI output port with the given alias.

Example:

midi_disconnect("synth")

Parameters:

  • alias (String) — port alias to disconnect

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) — the alias used when connecting

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() -> NUL
fn midi_latency(mode: String) -> String

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:

midi_latency("manual")

Parameters:

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

Returns: String — the mode just set

fn midi_port_clock(alias: String) -> Boolean
fn midi_port_clock(alias: String, enabled: Boolean) -> Boolean

Opts a MIDI output port in or out of receiving clock.

Example:

midi_port_clock("daw", false)

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry
  • enabled (Boolean) — true to send clock to this port, false to stop

Returns: Boolean — the resulting opt-in state

fn midi_port_clock_trim(alias: String) -> Number
fn midi_port_clock_trim(alias: String, ms: Number) -> Number

Sets a MIDI output port’s clock-only trim in milliseconds. Added on top of midi_port_trim, and applied only to clock and transport messages. For gear whose clock input settles differently from its note input.

Example:

midi_port_clock_trim("cv", -2.5)

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry
  • ms (Number) — trim in milliseconds, within ±500

Returns: Number — the trim value just set

fn midi_port_trim(alias: String) -> Number
fn midi_port_trim(alias: String, ms: Number) -> Number

Sets a MIDI output port’s timing trim in milliseconds. Applies to notes and clock alike. Use it to correct one device that responds late or early — positive sends later, negative earlier. Alignment with the audio output is already automatic; this is the per-device correction on top.

Example:

midi_port_trim("cv", -2.5)

Parameters:

  • alias (String) — port alias, from its [[midi.outputs]] entry
  • ms (Number) — trim in milliseconds, within ±500

Returns: Number — the trim value just set

fn midi_ports() -> Array

Lists all available MIDI output ports.

Returns: Array — the available output port names as Strings

fn midi_routing() -> NUL

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

Returns: NUL — nothing; prints the routing

fn midi_trace() -> NUL
fn midi_trace(on: Boolean) -> Boolean

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

Example:

midi_trace(true)

Parameters:

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

Returns: Boolean — whether the trace is now recording