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

Get duration of event #52

Closed tjvg91 closed 4 years ago

tjvg91 commented 4 years ago

Is there any way to get the event duration? Using webaudiofont for the sounds but can't pass a duration to it.

grimmdude commented 4 years ago

Hi @tjvg91,

I don't think so currently, it does seem like something that would be useful though. Right now you just have to watch for Note on and corresponding Note off events for a given note.

tjvg91 commented 4 years ago

So how do I know how long a certain soundfont will play the event?

tjvg91 commented 4 years ago

Any updates about this?

grimmdude commented 4 years ago

Hi @tjvg91,

The player currently fires on/off events which you can use for duration. I will take a look at adding a duration attribute to the events as soon as I have some time. PRs always welcome!

-Garrett

Andrew-J-Larson commented 4 years ago

Duration could be pretty handy, especially if it accounts for "Note on" events with velocity of 0

grimmdude commented 4 years ago

I'm not sure about including duration in Note on events. It sorta goes against the streaming event behavior of the library. I think it would require a fair amount of refactoring to implement this type of lookahead functionality.

I'm gonna table for now, I think programs that use this should be able to use the Note off events (and Note on events with velocity 0) to determine how long a note should sound.

-Garrett