nfroidure / midifile

A MIDI file parser/writer using ArrayBuffers
http://karaoke.insertafter.com
MIT License
199 stars 30 forks source link

midi file unsupported (apparently) #29

Closed binyamin closed 5 years ago

binyamin commented 5 years ago

Issue

I'm a gentledev i:

Expected behavior

The console logs the result of midiFile.header.getFormat();

Actual behavior

The console returns an error: Uncaught (in promise) Error: Invalid MIDIFileTrack (0xe) : MTrk prefix not found

Steps to reproduce the behavior

Clone or download the repository here and run npm start.

Debugging informations

mk-pmb commented 5 years ago

Please try and make a minimal example to isolate the problem. I've skimmed index.js but couldn't find any MIDI related code. Edit: When you use buffers for MIDI file data, please print their first 64 bytes, and verify those are the bytes you expect.

binyamin commented 5 years ago

Look at /src/main.js That's where my code is.

mk-pmb commented 5 years ago

Have you verified the first 64 buffer bytes?

binyamin commented 5 years ago

Not sure what I'm looking for. I used a vs code plugin to view the midi file, and it's in hexadecimal.

00000000: 4d54 6864 0000 0006 0001 0002 01ef bfbd
00000010: 4d54 726b 0000 10ef bfbd 00ef bfbd 5804
...

For the array buffer, am I looking at the int8, int16, or int32? When I convert the hex to decimal, none of the options match up to the first number.

binyamin commented 5 years ago

Somehow, it's working now. Thanks!

mk-pmb commented 5 years ago

It was most probably a problem with your buffer handling then. I'd suggest studying more basics when you have a bit of time for it.

Not sure what I'm looking for.

Well, the error message said:

MTrk prefix not found

So take a look at your first 64 bytes of your MIDI in a reasonable hex editor that also shows an opportunistic ASCII interpretation, then the same in your buffer (e.g. console.trace(encodeURI(myBuffer.slice(0, 64).toString('binary')));) and maybe you can spot the MTrk prefix. (The encodeURI is to protect your terminal from control characters.)

Edit:

For the array buffer, am I looking at the int8, int16, or int32?

uint8 probably, i.e. bytes.