TypeScript MIDI file parser forked from jasmid https://github.com/gasman/jasmid
npm install midifile-ts --save
import { read } from "midifile-ts"
const midi = read(data) // { header, tracks }
import { read } from "midifile-ts"
const data = fs.readFileSync("song.mid")
const midi = read(data)
import { read, MidiFile } from "midifile-ts"
const changeFileInput = (
input: HTMLInputElement,
callback: (midi: MidiFile|null) => void
) => {
if (input.files === null || input.files.length === 0) {
return
}
const file = input.files[0]
const reader = new FileReader()
reader.onload = e => {
if (e.target == null) {
callback(null)
return
}
const buf = e.target.result as ArrayBuffer
const midi = read(buf)
callback(midi)
}
reader.readAsArrayBuffer(file)
}