Changing version to 1.11.11 breaks p5.sound
p5.js version
1.11.11
What is your operating system?
Linux
Web browser and version
Brave 1.83.112
Actual Behavior
TypeError: p5.MonoSynth is not a constructor
Expected Behavior
Play a sound when the box is clicked
Steps to reproduce
Steps:
- New sketch
- Use Library Management to change version to 1.11.10, ensure p5.sound.js is On
- Paste the Snippet (which is the example code from the p5.MonoSynth reference page)
- Click Play and click in the "tap to play" box a few times; observe correct behavior of a tone playing
- Use Library Management to change version to 1.11.11, ensure p5.sound.js is still On
- Click Play and observe error message
Note that a new sketch will start with version 1.11.11, and it will work fine. It's only when changing to a different version and back to 1.11.11 that doesn't work.
Snippet:
let monoSynth;
function setup() {
let cnv = createCanvas(100, 100);
cnv.mousePressed(playSynth);
background(220);
textAlign(CENTER);
text('tap to play', width/2, height/2);
monoSynth = new p5.MonoSynth();
}
function playSynth() {
userStartAudio();
let note = random(['Fb4', 'G4']);
// note velocity (volume, from 0 to 1)
let velocity = random();
// time from now (in seconds)
let time = 0;
// note duration (in seconds)
let dur = 1/6;
monoSynth.play(note, velocity, time, dur);
}
Hi! I was able to successfully reproduce this issue in my local environment (using the released branch). Just sharing this in case it helps with verification.
Whenever the issue is reviewed and confirmed, I’d be happy to take it on — just let me know! 🙌
Thanks @sidwellr for opening this issue and @Yuvaan1182 for your interest! I just assigned the issue to @Yuvaan1182!
Thanks @raclim for assigning this to me! I’ll start working on it and will post an update once I’ve made progress.
It looks like jsdelivr works https://cdn.jsdelivr.net/npm/[email protected]/lib/addons/p5.sound.min.js but cloudflare's CDN does not: https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/addons/p5.sound.min.js
At one point we started switching to jsdelivr because of other cloudflare CDN issues such as being slow to update. I think the p5.sound URL is still on cloudflare though. Possibly worth finishing that up here and making it use jsdelivr too?
@davepagurek as far I checked version 1.x are on cloudflare and v2 are on jsdeliver. But the issue is still something else.
It works for me if I manually update your index.html to use a jsdelivr URL for both 1.x and 2.x, so I think updating all URLs to use the same jsdelivr CDN may be all that's required.
I think that would mean updating this line to use jsdelivr to match the others in the file: https://github.com/processing/p5.js-web-editor/blob/develop/common%2Fp5URLs.js#L2
Yes, I actually currently only 1.11.11 is giving 404 for cloudflare for the version's before it was working fine and your solution is perfectly fine using the new jsdelivr cdn will work perfectly fine. @davepagurek
Were you interested in making a PR with that change @Yuvaan1182?
Apologies for jumping the queue on this @raclim, I put up #3758 since we've been seeing more reports of this issue across p5 channels, so we figured it was worth patching quickly.