jazz-soft / JZZ-midi-SMF

Standard MIDI Files: read / write / play
MIT License
40 stars 5 forks source link

Can't load any midis. #16

Closed ar065 closed 3 years ago

ar065 commented 3 years ago

Here is an example with 0.mid:

/workspace/nodejs-midiplayer/node_modules/jzz/javascript/JZZ.js:1605
  function _throw(x) { throw RangeError('Bad MIDI value: ' + x); }
                             ^

RangeError: Bad MIDI value: MThd`MTrk>ÿ
4-Byte VLQÿhttps://jazz-soft.netÿKThis file has 4-byte VLQ delta times. Technically, it's a valid MIDI file.
ÿYou must hear a C-Major scale.`<@`>@`@@`A@`C@`E@`G@`H@ÿ
Thank you!ÿ/

Another example with a different midi:

/workspace/nodejs-midiplayer/node_modules/jzz/javascript/JZZ.js:1605
  function _throw(x) { throw RangeError('Bad MIDI value: ' + x); }
                             ^

RangeError: Bad MIDI value: MThdàMTrk,WÿÿYúÿQ¢_°yÀ°d

Theres more after that RangeError, but its just a bunch of midi data. I loaded the midi just like the examples have shown, with fs.

jazz-soft commented 3 years ago

Thanks for the notice! Could you please attach these MIDI files?

ar065 commented 3 years ago

Thanks for the notice! Could you please attach these MIDI files?

I'm not sure if I should have made an issue on JZZ or here, since JZZ is throwing the issue. Maybe the midi is loading but on the first event JZZ throws an error? Just speculation

0.mid is in the test folder, the second midi is bad apple: Bad Apple.zip

jazz-soft commented 3 years ago

Strange... I don't see any issues when I open 0.mid during the "npm test". Can it be that your copy is corrupted? I'll take a look at your other file.

ar065 commented 3 years ago

I re-installed and still have the same issue, im testing on windows next to see if that changes anything

jazz-soft commented 3 years ago

Which OS are you on? Does npm test work for you?

ar065 commented 3 years ago

Which OS are you on? Does npm test work for you?

yarn run test (Since I use yarn) works for me.

I was on linux. I tested on windows and had the same result, am I doing this correctly?:

const JZZ = require("jzz");
require("jzz-midi-smf")(JZZ);

fs.readFile("./midis/0.mid", "binary", (err, data) => {
    if (err) console.log(err);

    let smf = new JZZ.MIDI.smf(data);
    let midiPlayer = smf.player();

    midiPlayer.connect(output);
    midiPlayer.play();
});
jazz-soft commented 3 years ago

Change let smf = new JZZ.MIDI.smf(data); to let smf = new JZZ.MIDI.SMF(data); ;)

ar065 commented 3 years ago

VsCode said it was "smf" 🤦 Also can't believe I didn't notice that lol

jazz-soft commented 3 years ago

Yes, I've just realized I have functions with similar names... Need to think what to do about that...