Skip to content

MIDI Export

Export your patterns 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");

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 (G4 above) receive the default velocity of 100.

Patterns are exported as Type 0 (single-track) Standard MIDI Files.

ExportedNot exported
Note-on / note-offMIDI CC
PitchPitch bend
VelocityProgram changes
Channel (0–15)Automation
DurationSysEx
Tempo

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 note-ons to prevent overlapping notes. 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

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, and timing but nothing else.

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