Export & MPE
Export your patterns and tracks to .mid files for use in any DAW or notation software.
Exporting a Pattern
Section titled “Exporting a Pattern”Auto-generated path
Section titled “Auto-generated path”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.
Custom path
Section titled “Custom path”midi_export(pattern, cycles, path) saves to the path you specify:
midi_export(melody, 4, "my_melody.mid");Exporting a Track
Section titled “Exporting a Track”Single track
Section titled “Single track”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.
Multiple tracks
Section titled “Multiple tracks”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_cycleWith 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.
Velocity
Section titled “Velocity”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.
Output Format
Section titled “Output Format”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.
What gets exported
Section titled “What gets exported”| Exported | Not exported |
|---|---|
| Note-on / note-off | Pitch bend |
| Pitch | Program changes |
| Velocity | SysEx |
| Velocity modulation | |
| Channel (0–15) | |
| Duration | |
| Tempo | |
| CC automation | |
| Track names |
Timing resolution
Section titled “Timing resolution”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.
Function Signatures
Section titled “Function Signatures”| Call | Description |
|---|---|
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);MIDI Export vs Audio Render
Section titled “MIDI Export vs Audio Render”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.
See Also
Section titled “See Also”- MIDI Tracks — real-time MIDI output
- Pattern Basics — building patterns to export
- Audio Rendering — exporting audio files