processing / p5.sound.js

GNU Lesser General Public License v2.1
6 stars 1 forks source link

getContext() throws error on OpenProcessing #32

Closed davepagurek closed 3 weeks ago

davepagurek commented 1 month ago

OP has this code in its sketch runner to enable audio: image

It's calling window.getAudioContext, presumably because this was ok in the previous sound library, but just as a heads up, it's causing errors now.

The change to fix this may not need to be in this repo, but I thought I'd raise the issue since it might need some discussion to figure out how OpenProcessing should handle this new version of the library.

cc @msawired

davepagurek commented 1 month ago

as a workaround on OP, right now I'm adding window.getAudioContext = undefined to my setup.

msawired commented 1 month ago

Thanks for tagging me, @davepagurek. GetAudioContext is a native function, no? Surprised that it is causing an error. What is the error you see? Do you have any examples I can check?

davepagurek commented 1 month ago

ah if that's a native function then that's probably the issue, it's also defined by this library in p5.prototype, which then gets added to the window in global mode.

It at least used to be a method in the earlier p5 sound library, but it maybe used to get set up earlier or something like that: https://p5js.org/reference/p5/getAudioContext/

davepagurek commented 1 month ago

I've been testing here https://openprocessing.org/sketch/2338010, commenting the line in setup that sets it back to undefined should get it to trigger again

msawired commented 1 month ago

sorry, my bad, it is not a native function. Yes, I am using P5js getAudioContext to follow any updates on the context and update the volume icon accordingly. Browsers usually mute the sketches on load, so need a way to show users that the sketch is muted. On line 14554, I see that getAudioContext is being set (albeit, with debugger), but gets stuck somewhere. I removed the debugger and returned the getContext() directly here. No errors, but the returned audioContext doesn't seem to be used. Maybe the tone.js is using its own audiocontext?
https://openprocessing.org/sketch/2340238

msawired commented 1 month ago

Yes, fixed it here: https://beta.openprocessing.org/sketch/2340238 I also added support to capture Tonejs context mute/suspended state. Weird that it doesn't have suspend() function. But now it also works with the mute icon on OpenProcessing.

davepagurek commented 3 weeks ago

Thanks Sinan!