MIDI files (.mid, .midi)
A Standard MIDI File opens as its header facts, a table of tracks and the first 200 notes, before anyone downloads it.
- Page: the file page shows format, track count, time division (ticks per quarter or SMPTE), tempo in BPM and length; a track table (name, channels, notes, events); and the first 200 notes by time (tick, track, channel, note name, velocity). No script, nothing is played.
- Terminal: opening a
.midin the workspace (src/tui/screens/workspace_facts.ts,factsView) shows the track table with the tempo in its first header;sflips to the source. Same gate as the page. - MCP:
read_fileon a.midor.midicarriesabout: { kind: "midi", format, ppq?, bpm, seconds?, tracks, notes, says }, with the first 20 notes as[tick, track, channel, key, velocity]; no new tool, ceilings intest/mcp-size.test.tsuntouched. - Gate: the name must end
.midor.midiand the first bytes must beMThd, and the file must be at most 5 MB; past that, or when it does not parse (no header, a cut-short header, a zero time division), the page keeps the source view with one line saying why. - Hostile input: every read is checked against the bytes left in its chunk and every event consumes at least one byte, so a lying length cannot spin the walk; a chunk length past the file is clamped and reported. At most 256 tracks and 2,000,000 events are walked, 200 notes kept per track. Every track name and text is escaped.
- Left out: playback, a piano roll, lyrics and markers, key and time signatures beyond the header, RIFF-wrapped (
.rmi) files. - Code:
src/web/render/midi.ts, kindmidiinkinds.ts, registered inrenderers.ts; testtest/midi-render.test.ts, sample intest/fuzz-renderers.test.ts.