cifkao / html-midi-player

🎹 Play and display MIDI files on the web
https://cifkao.github.io/html-midi-player/
BSD 2-Clause "Simplified" License
630 stars 56 forks source link

Support the Sustain pedal #11

Open e7mac opened 3 years ago

e7mac commented 3 years ago

Currently the MIDI Player ignores all signals for the sustain pedal (Midi control signal 64). It'd be great if the player could respect the sustain pedal as piano music without the sustain pedal sounds way poorer.

cifkao commented 3 years ago

This would be best solved in Magenta.js, so you can try creating an issue there.

A workaround here would be to modify the note sequence by extending the durations of notes, similarly to the apply_sustain_control_changes function.

Also note that the Magenta.js SoundFonts have a maximum note duration (2 seconds I think), after that the note is released anyway.

e7mac commented 3 years ago

Thanks for the links! I attempted to create a similar function and found that magenta.js doesn't return the control changes data at all. I opened a PR in magenta.js, adding that data. Once that merges, I can add that function in here.

cifkao commented 3 years ago

OK. You can also consider submitting another PR to magenta to make their player handle the sustain pedal correctly, which would be a cleaner fix I think.

e7mac commented 3 years ago

Makes sense. I'll plan to fix it in the BasePlayer class then.

I'm new to JS so one challenge for me is that I'm not really sure how to run and test the magenta-js codebase locally. Might you have any pointers on that ?

cifkao commented 3 years ago

I'm new to JS so one challenge for me is that I'm not really sure how to run and test the magenta-js codebase locally. Might you have any pointers on that ?

That should be straightforward, just clone the repo, go to the music subdirectory and then follow the readme there (see the Example Commands section). Take a look at the yarn link command for how you can include your local copy of the package in another project (e.g. this package or a test project).

e7mac commented 3 years ago

Thanks! I opened a PR adding a method to the magenta-js project. I still need to figure out where to call that method from. Might you have an opinion on that already?

cifkao commented 3 years ago

Thanks! But unfortunately I don't know if this can just be solved by calling your applySustainControlChanges. There are two ways I can think of and neither of them really works:

So the only way I see is to modify Magenta.js's BasePlayer to actually take control changes into account when scheduling the notes. This is the only proper fix anyway, since anything that we can do here are just workarounds for BasePlayer not handling this. That being said, I know that might be difficult, so I'm also open to other workarounds (maybe something that will still require changes to the Magenta code, but only small ones) if you can think of any.