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

tempo bug? #13

Closed Yoshi1229 closed 6 years ago

Yoshi1229 commented 6 years ago

The code worked well with many midis but it plays some a lot slower/faster? midi.zip

at about 20% of the first midi (after parsing) the song went a lot faster and the second midi is played slower than it is using other programs (~41 seconds originally, ~45 seconds with this)

any ideas?

(sorry if my english is bad)

grimmdude commented 6 years ago

Hi @Yoshi1229,

Thanks for your message, while I'm investigating this can you tell me the method you used to generate these files?

-Garrett

grimmdude commented 6 years ago

When I'm looking at the MIDI events in the first track of 77.mid I see a lot of "Set Tempo" events, is this expected?

screen shot 2017-12-24 at 9 36 21 am
Yoshi1229 commented 6 years ago

Hi, The set tempo events are expected, but can you please make the player doesn't play it out right. can you please fix it? Also, is the getSongTime() function affected by these set tempo events?

grimmdude commented 6 years ago

Hi @Yoshi1229,

Regarding 77.mid, I think this file just may be a bit too complex to play efficiently with the player as is. I will keep this file for my reference though and see if I can make changes to optimize playback.

Yes, getSongTime() is currently affected by tempo changes.

-Garrett

Yoshi1229 commented 6 years ago

Thanks

One more question, the 147.mid file does not have a set tempo event. Is it using the tempo of the last loaded file?

grimmdude commented 6 years ago

Hi @Yoshi1229,

If tempo isn't provided in the MIDI file then the player defaults to 120. I just updated to the docs to reflect that:

http://grimmdude.com/MidiPlayerJS/docs/Player.html#setTempo

-Garrett

Yoshi1229 commented 6 years ago

hi When I loaded 147.mid the first time, it played with the tempo 120, but after playing 77.mid then playing it, it played with the tempo 230. Does it default the tempo to 120 every time when I load the file?

grimmdude commented 6 years ago

Hi @Yoshi1229,

Good catch, I've just pushed and published version 2.0.1 which should now reset the default tempo to 120 before a file is loaded.

-Garrett

tjvg91 commented 6 years ago

It's buggy when you try to change the tempo while running the midi.

grimmdude commented 6 years ago

Hi @tjvg91,

Could you elaborate a bit? Are you experiencing issues adjusting the tempo on the demo?

http://grimmdude.com/MidiPlayerJS/

-Garrett

grimmdude commented 6 years ago

@tjvg91,

Note that when changing tempo you'll need to first pause the player. Something like this:

Player.pause().setTempo(130).play();