open-audiovisual
Search GitHub

oav-p5 reference · Sound and instruments

soundIsOn#

variableoav-p5
soundIsOn

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 soundIsOn keeps it: oav-p5 leaves the name alone and a card says to read OAVp5.sound.state === 'on' instead.

Examples

jsOpenProcessing ↗
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);
}
An amber circle until you click, then a green one: that is the moment 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, so startSound() brings it back at once.
  • OAVp5.sound.state Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.
  • micIsOn Whether the microphone is running right now.
  • drumsAreOn Whether the drum machine is playing right now.
  • recordingIsOn Whether a recording is running right now.

p5/oav-p5.js, line 316

↑ Back to top · All names