cifkao / html-midi-player

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

Are there any plan to replace ScriptProcessorNode with AudioWorkletNode? #71

Closed Guseyn closed 1 year ago

cifkao commented 1 year ago

I don't think this library uses ScriptProcessorNode; what makes you think it does?

We rely on Magenta.js, which relies on Tone.js for audio. And it seems that Tone.js hasn't been using ScriptProcessorNode for some time. Can you check if you're using the recommended version of Tone.js (14.7.58)?

Guseyn commented 1 year ago

I am using built version of the library and just include it in <script>. I will attach the console output from your demo page. The same warnings I get in my app. Also, it's a weird bug, but on IPhone14(Chrome) sound does not work, but if I connect headphones or other external output device, sound works perfectly fine.

Screenshot 2023-11-15 at 6 51 42 PM
cifkao commented 1 year ago

OK, you're right, I'm seeing this too. Indeed, it says it's coming from Defaults.ts in Tone.js. And although I don't see ScriptProcessorNode anywhere in Tone.js, it turns out Tone.js uses standardized-audio-context "for maximum browser compatibility", which in turn uses ScriptProcessorNode to define its own AudioWorklet implementation...

So if this is breaking your app, what you could try is forking Tone.js, modifying it so that it uses native AudioContext instead of standardized-audio-context, and then using that instead.

Note that html-midi-player is not tightly bundled with Tone.js; they are just combined on-the-fly on jsDelivr, so you can just edit the URL https://cdn.jsdelivr.net/combine/npm/tone@14.7.58,npm/@magenta/music@1.23.1/es6/core.js,npm/focus-visible@5,npm/html-midi-player@1.5.0 to remove Tone.js from the bundle.

About iPhone, see #28, #32, #64. unmute-ios-audio might be the solution, but I'm not able to test it as I don't own an iOS device.

Guseyn commented 1 year ago

@cifkao thank you for iPhone solution, I will try it. It does not necessarily break my app, I just thought it would be nice to replace deprecated things. I will try to update to AudioContext when I have more time. I also wanted to thank you for the work. Please let me know, how can I donate if you accept donations (you can send an email with details to guseyn@guseyn.com).