OAVp5.sound.state#
variableoav-p5OAVp5.sound.state
Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.
'off' is where it starts and where stopSound() leaves it. startSound() moves it to 'loading' while @openav/sound and Tone.js arrive, to 'waiting' when everything is ready but the browser has not yet had its click, and to 'on' when notes are heard. 'error' means the sound parts could not be loaded (a network, a school firewall or an ad blocker); the message is in OAVp5.sound.error, and calling startSound() again tries once more.
soundIsOn is the same thing reduced to state === 'on'.
- Type
String- Range
off | waiting | loading | on | error
Starts as 'off' and changes whenever the sound moves to another stage.
Examples
function setup() {
createCanvas(400, 300);
startSound('marimba');
textAlign(CENTER, CENTER);
textSize(28);
}
function draw() {
background(20);
const hints = { off: 'off', loading: 'loading…', waiting: 'click to hear', on: 'listening', error: 'failed' };
fill(255);
text(hints[OAVp5.sound.state], width / 2, height / 2);
}Related
soundIsOnWhether notes are being heard right now: true oncestartSound()has finished, false before and after.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.errorThe message of the last thing that went wrong while loading sound, ornullwhen nothing has.OAVp5.sound.statusHow the instrument is loading:{ id, state, progress, error }, withprogressfrom 0 to 1.