soundIsOn#
variableoav-p5soundIsOn
Whether notes are being heard right now: true once startSound() has finished, false before and after.
Read it in draw() like mouseIsPressed: if (!soundIsOn) text('click to hear', 20, 30);. It changes only when the state of the sound changes, not every frame. Reading it never starts anything (unlike micLevel), so it is safe to check anywhere.
false does not mean startSound() was never called. To tell "loading" from "waiting for the click" from "failed", read OAVp5.sound.state, and OAVp5.sound.error for the reason of a failure.
- Type
Boolean
True only while OAVp5.sound.state is 'on'. It is false at the start, while sound waits for a click, while it loads, after stopSound() and after an error.
Before it has a value
It becomes true only after startSound() (or 🔊 in the 🎹 panel, or ?oav_sound=piano), and after the click the browser wants.
Notes
- A sketch that already declares its own variable called
soundIsOnkeeps it: oav-p5 leaves the name alone and a card says to readOAVp5.sound.state === 'on'instead.
Examples
function setup() {
createCanvas(400, 300);
startSound('organ');
}
function draw() {
background(20);
fill(soundIsOn ? color(120, 220, 140) : color(220, 160, 60));
circle(width / 2, height / 2, 80);
fill(255);
textAlign(CENTER);
text(soundIsOn ? 'sound is on' : 'click the canvas to turn sound on', width / 2, height - 40);
}soundIsOn turns true.Related
startSound()Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.stopSound()Turns sound off and lets every ringing note go; the instrument stays loaded, sostartSound()brings it back at once.OAVp5.sound.stateWhere sound is:'off','waiting'(for a click),'loading','on'or'error'.micIsOnWhether the microphone is running right now.drumsAreOnWhether the drum machine is playing right now.recordingIsOnWhether a recording is running right now.