open-audiovisual
Search GitHub

oav-p5 reference · Sound and instruments

stopSound()#

functionoav-p5
stopSound()

Also: OAVp5.sound.stop

Turns sound off and lets every ringing note go; the instrument stays loaded, so startSound() brings it back at once.

It releases every note that is ringing, sets soundIsOn to false and OAVp5.sound.state to 'off'. Notes you play afterwards are not heard (the sketch's notePressed() is still called). Tone.js and the instrument stay loaded: startSound() afterwards is on again at once, without a new download and without waiting for another click.

It also works while sound is still loading or waiting for the first click: the pending startSound() then resolves to false.

Returns

Promise<Boolean> A promise that is already resolved to false, the new state of the sound.

Notes

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startSound('synth/pluck');
  textAlign(CENTER, CENTER);
}

function keyPressed() {
  if (key === 's') {
    if (soundIsOn) stopSound(); else startSound();
  }
}

function draw() {
  background(soundIsOn ? 40 : 100);
  fill(255);
  text('press s: sound is ' + (soundIsOn ? 'on' : 'off'), width / 2, height / 2);
}
Press s to switch sound off and on; the background is dark while sound is on.

Related

  • startSound() Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.
  • soundIsOn Whether notes are being heard right now: true once startSound() has finished, false before and after.
  • OAVp5.sound.state Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.
  • stopDrums() Stops the drum machine and hides its card.
  • stopMic() Turns the microphone off and sets every microphone value back to 0.

p5/oav-p5.js, line 1443

↑ Back to top · All names