grimmdude / MidiPlayerJS

♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
https://grimmdude.com/MidiPlayerJS/
MIT License
357 stars 52 forks source link

Some midis will create an Infinite loop when loading file #33

Closed BopItFreak closed 4 years ago

BopItFreak commented 6 years ago

Some midis, which are valid on other players, seem to create an Infinite loop when loading the file. one of these midis is this: https://cdn.discordapp.com/attachments/360985607209484290/477205561469829121/9934.mid

please fix this.

ghost commented 6 years ago

or at least, when playing that MIDI the program hangs and consumes high CPU. I can connect to the process and run synchronous commands, but anything async never completes. (I am co-reporting this issue)

Vistril commented 6 years ago

It happens for me when you play a song without stopping the player first. Even though I call player.stop() the first thing when 'endOfFile' fires, it still doesn't stop and cpu usage spikes. I tried to use async to fix it but as Lamp said anything with async never completes. So, what gives?

lexcast commented 4 years ago

The bug is here: https://github.com/grimmdude/MidiPlayerJS/blob/master/src/player.js#L428 should be >=:

endOfFile() {
    if (this.isPlaying()) {
        return this.totalTicks - this.tick <= 0;
    }

    return this.bytesProcessed() >= this.buffer.length;
}