MIDI.js icon indicating copy to clipboard operation
MIDI.js copied to clipboard

Midi.js stops playing after a second

Open Ninja-Koala opened this issue 9 years ago • 4 comments

For me, the Online Example at http://mudcu.be/midi-js/ as well as an own simple Example stop playing after a second or so. Other Examples such as the Color Piano or Euphony work fine.

It also depends on the MIDI File played, this works fine for Example.

It doesn't depend on the playing speed.

I'm using Chromium 43.0.2357.125 on Arch Linux It is only behaving that way on my Laptop, my Desktop PC with the same setup (but better CPU) works fine, so it might be some timeout or something.

Ninja-Koala avatar Jun 12 '15 13:06 Ninja-Koala

I'm having the same issue on Mac and Windows, latest version of Chrome. Both WebAudio and AudioTag plugins have this issue.

Loading the plugin is the defaults from the "Basic" example.

This is how I am playing the notes:

//example midi note
e = [144, 52, 109];
switch(e[0]) {
    case 144:
        MIDI.noteOn(0, e[1], e[2], 0);
        break;
    case 128:
        MIDI.noteOff(0, e[1], 0);
        break;
}

thesandlord avatar Jun 22 '15 22:06 thesandlord

I'm debugging this as well. The problem is occurring in the following code (from gasman/jasmid it seems):

if ( midiEvent.event.type == "meta" && midiEvent.event.subtype == "setTempo" ) {
    // tempo change events can occur anywhere in the middle and affect events that follow
    beatsPerMinute = 60000000 / midiEvent.event.microsecondsPerBeat;
} 

The beatsPerMinute (and thus every calculation about how long the file will have to play) results in Infinity due to the midiEvent.event.microsecondsPerBeat being 0. This value is sometimes zero due to this code:

case 0x51:
    event.subtype = 'setTempo';
    if (length != 3) throw "Expected length for setTempo event is 3, got " + length;
    event.microsecondsPerBeat = (
        (stream.readInt8() << 16)
        + (stream.readInt8() << 8)
        + stream.readInt8()
        )
    return event;

Tails avatar Jul 01 '15 12:07 Tails

Could someone please indicate how this problem is solved? For most midi files, playback stops after a second or 2.

Fcasualty avatar Oct 12 '15 18:10 Fcasualty

Have ya tried setting the volume before starting playback?

tjvg91 avatar Jan 20 '16 06:01 tjvg91