MIDI Export
Export your patterns 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");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 (G4 above) receive the default velocity of 100.
Output Format
Section titled “Output Format”Patterns are exported as Type 0 (single-track) Standard MIDI Files.
What gets exported
Section titled “What gets exported”| Exported | Not exported |
|---|---|
| Note-on / note-off | MIDI CC |
| Pitch | Pitch bend |
| Velocity | Program changes |
| Channel (0–15) | Automation |
| Duration | SysEx |
| Tempo |
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 note-ons to prevent overlapping notes. 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 |
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, and timing but nothing else.
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