stopSound()#
functionoav-p5stopSound()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
- It does not touch the drum machine (use
stopDrums()) or the microphone (stopMic()).
Examples
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);
}Related
startSound()Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.soundIsOnWhether notes are being heard right now: true oncestartSound()has finished, false before and after.OAVp5.sound.stateWhere 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.