Export MIDI
Hand the score to a DAW so a producer can layer a professional sampler on top. Drive an external hardware synth from a rendered .mid. Ship rehearsal tracks to a music-notation tool that speaks MIDI. alphaTab writes Standard MIDI File 1.0 output from any loaded score โ tempo map, time signatures, program changes, note on/off with expression and pitch bend all come out of the same MidiFileGenerator that drives the built-in synth.
Browser one-linerโ
On Web, AlphaTabApi.downloadMidi(format?) builds the file and triggers a browser download in a single call:
import * as alphaTab from '@coderline/alphatab';
const container = document.querySelector('#alphaTab');
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
});
api.scoreLoaded.on(() => {
api.downloadMidi();
});
The download uses <score.title>.mid as the filename, falling back to File.mid when the score has no title.
Programmatic pipelineโ
For server-side rendering, .NET, Android, or any flow where you want the bytes without a download, build the pipeline yourself:
import * as alphaTab from '@coderline/alphatab';
const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
});
api.scoreLoaded.on(() => {
const midiFile = new alphaTab.midi.MidiFile();
midiFile.format = alphaTab.midi.MidiFileFormat.MultiTrack;
const handler = new alphaTab.midi.AlphaSynthMidiFileHandler(midiFile, true);
const generator = new alphaTab.midi.MidiFileGenerator(
api.score,
api.settings,
handler
);
generator.generate();
const bytes = midiFile.toBinary();
// bytes is a Uint8Array holding a valid SMF 1.0 file
});
getAlphaTabContainer() is the platform-specific render target. bytes is a Uint8Array on every runtime. Persist it, ship it over the network, or hand it to a native audio subsystem.
Two file formatsโ
MidiFileFormat picks the container layout SMF 1.0 defines:
SingleTrackMultiChannel(SMF Type 0) โ every event in one merged track, tracks distinguished by MIDI channel. Compact and the default fordownloadMidi().MultiTrack(SMF Type 1) โ one MIDI track per alphaTab track, all sharing a common time base. Preserves per-track structure when you import the file into a DAW.
Pick MultiTrack when the target opens the file in a multi-track editor. Pick SingleTrackMultiChannel for simple playback tools that expect Type 0.
SMF 1.0 caveatsโ
Standard MIDI File 1.0 has no per-note pitch bend. Where the score assigns independent bends to notes on the same channel โ two simultaneous strings bending at different rates, vibrato layered on top of a whole-step bend โ the exporter merges them into a single channel-wide pitch-bend curve. The audible result approximates the notation; the fine detail available in alphaTab's own synth does not survive the export.
The generator also reads settings.notation.transpositionPitches when emitting events. If you export for playback in an external tool that applies its own transposition, disable that step:
generator.applyTranspositionPitches = false;
generator.generate();
Where to look nextโ
- Export audio to WAV โ render synthesized audio instead of MIDI events.
- MIDI event stream โ subscribe to the same events at play time instead of writing them to a file.
AlphaTabApi.downloadMidiin the API reference.MidiFile,MidiFileGenerator, andMidiFileFormatin the API reference.