Skip to content

Export & MPE

Export your patterns and tracks to .mid files for use in any DAW or notation software.

midi_export(pattern, cycles) renders the given number of cycles and saves to an automatically generated path:

let melody = [C4 E4 G4 C5];
midi_export(melody, 4);

The file is saved to renders/{project}/{datetime}/export.mid.

midi_export(pattern, cycles, path) saves to the path you specify:

midi_export(melody, 4, "my_melody.mid");

midi_export(track, cycles) exports a MIDI track with its channel, velocity, and CC automation:

let t1 = MidiTrack(1, 100);
t1 << [C2 E2 G2 C3];
t1.cc(74) << Sine(0.25);
midi_export(t1, 4);

The export includes the track’s note events on its assigned channel, plus any CC automation bindings. Velocity modulation (signals and patterns) is baked into per-note velocities.

Pass an array of tracks for a multi-track MIDI file:

let bass = MidiTrack(1, 80);
let lead = MidiTrack(2, 110);
bass << [C2 E2 G2];
lead << [C5 E5 G5 C6];
midi_export(#[bass, lead], 8);

This produces a Type 1 (multi-track) Standard MIDI File with separate tracks for each instrument.

Tracks without a pattern assigned are skipped with a warning.

Tempo is derived from the audio engine’s current CPS (cycles per second):

BPM = CPS × 60 × beats_per_cycle

With the default 4 beats per cycle:

  • CPS 0.5 → 120 BPM
  • CPS 1.0 → 240 BPM

If CPS is zero or negative, the export falls back to 120 BPM.

Notes with explicit velocity preserve it in the export:

midi_export([C4^80 E4^110 G4], 2);

Notes without explicit velocity receive the track’s default velocity, or the result of any velocity signal or pattern bound to the track.

Pattern exports use Type 0 (single-track) Standard MIDI Files. Track exports use Type 1 (multi-track) with a conductor track containing tempo information and one data track per MIDI track.

ExportedNot exported
Note-on / note-offPitch bend
PitchProgram changes
VelocitySysEx
Velocity modulation
Channel (0–15)
Duration
Tempo
CC automation
Track names

All exports use 480 PPQN (pulses per quarter note). With the default 4 beats per cycle, one cycle equals 1920 ticks.

At the same tick position, note-offs are written before CC events, and CC events before note-ons. Every note has a minimum length of 1 tick.

CallDescription
midi_export(pattern, cycles)Export pattern with auto-generated path
midi_export(pattern, cycles, path)Export pattern to custom path
midi_export(track, cycles)Export track (Type 1 SMF with CC)
midi_export(track, cycles, path)Export track to custom path
midi_export(#[tracks], cycles)Export multiple tracks (Type 1 multi-track)
midi_export(#[tracks], cycles, path)Export multiple tracks to custom path

All forms return the file path as a string:

let path = midi_export(melody, 4);
print(path);

Use MIDI export when you need editable note data for a DAW — it captures notes, velocities, CC automation, and timing.

Use audio rendering (render()) when you want a finished .wav file with effects, samples, and mixing applied.