MidiPlayerJS icon indicating copy to clipboard operation
MidiPlayerJS copied to clipboard

skipToTick() and co. simply ignores significant intermediate changes

Open atsushieno opened this issue 5 years ago • 2 comments

I have been lurking around the web to find how to implement seek operation in my MIDI player implementation (not in JS) and found that MidiPlayerJS offers skipToTick() feature.

https://github.com/grimmdude/MidiPlayerJS/blob/92f3d5491f1b3378c30305c26992c4d87edefe57/src/player.js#L277

It is cool, but it doesn't make sense if you simply ignore any intermediate MIDI events such as program changes, control changes, pitchbend and so on. They should be processed accordingly. It is most likely that only notes can be simply ignored.

(I'm not a user of your library ATM, but wanted to share my findings.)

atsushieno avatar Jan 22 '19 18:01 atsushieno

Hi @atsushieno,

Thanks for your message. I agree, that approach might not be the best way to go. I think that was an attempt at seek functionality that I couldn't get to work quite properly. I haven't had time lately to tackle again, but would like to when I'm available.

Best of luck to you on getting something similar working in your implementation. Send a link if you got it.

-Garrett

grimmdude avatar Jan 25 '19 03:01 grimmdude

I have my own MIDI player in C# https://github.com/atsushieno/managed-midi/blob/master/lib/base/MidiPlayer.cs - It is designed in very similar mindset to MidiPlayerJS, leaving any platform-specific backend parts to MIDI player "events". (There is a handful of nasty workarounds and known issues, so I wouldn't recommend it as a reference material so far.)

A hacky way to achieve that is to break current play, send "all sound off" (CC 120) and restart from scratch, and skip wait operation for delta time with any MIDI message except for note on/off ones, until it passes beyond the specified ticks.

A decent way is to do above plus preserve "last changed" messages to each MIDI messages and flush the last ones at the end (so that you can skip a lot of pitchbend, expression, and so on). However it may result in unexpected messaging for MIDI player adapters like MidiPlayerJS (for example what if we have a "event-logging player backend", it wouldn't like skipped events).

I only have hacky implementation so far, but it seems to work without glitch.

Just my two cents :-)

atsushieno avatar Jan 25 '19 05:01 atsushieno