p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

Changing version to 1.11.11 breaks p5.sound

Open sidwellr opened this issue 1 month ago • 8 comments

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:

  1. New sketch
  2. Use Library Management to change version to 1.11.10, ensure p5.sound.js is On
  3. Paste the Snippet (which is the example code from the p5.MonoSynth reference page)
  4. Click Play and click in the "tap to play" box a few times; observe correct behavior of a tone playing
  5. Use Library Management to change version to 1.11.11, ensure p5.sound.js is still On
  6. 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);
}

sidwellr avatar Nov 14 '25 03:11 sidwellr

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! 🙌

Yuvaan1182 avatar Nov 20 '25 15:11 Yuvaan1182

Thanks @sidwellr for opening this issue and @Yuvaan1182 for your interest! I just assigned the issue to @Yuvaan1182!

raclim avatar Dec 05 '25 21:12 raclim

Thanks @raclim for assigning this to me! I’ll start working on it and will post an update once I’ve made progress.

Yuvaan1182 avatar Dec 06 '25 16:12 Yuvaan1182

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 avatar Dec 12 '25 16:12 davepagurek

@davepagurek as far I checked version 1.x are on cloudflare and v2 are on jsdeliver. But the issue is still something else.

Yuvaan1182 avatar Dec 12 '25 18:12 Yuvaan1182

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

davepagurek avatar Dec 13 '25 13:12 davepagurek

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

Yuvaan1182 avatar Dec 13 '25 22:12 Yuvaan1182

Were you interested in making a PR with that change @Yuvaan1182?

davepagurek avatar Dec 15 '25 13:12 davepagurek

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.

davepagurek avatar Dec 17 '25 13:12 davepagurek