open-audiovisual
Search GitHub

oav-p5 reference · Sound and instruments

OAVp5.sound.status#

objectoav-p5
OAVp5.sound.status

How the instrument is loading: { id, state, progress, error }, with progress from 0 to 1.

It is about the instrument, not about the whole sound: OAVp5.sound.state is the whole sound. Only the piano has files to load, so for every other instrument progress is 1 almost at once. While a sampler loads, OAVp5.sound.instrument is still the one you hear and status.id is the one on its way (at the very first call it may name the electric piano that stands in, and then the piano).

Type
Object
Range
{ id, state: idle | loading | ready | error, progress: 0..1, error }

A new object on every read. id is the instrument the loader is working on, state is 'idle' before anything loads, 'loading', 'ready' or 'error', and progress is the fraction of the files loaded.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startSound('piano');
  noStroke();
}

function draw() {
  background(20);
  const s = OAVp5.sound.status;
  fill(60);
  rect(40, 140, 320, 16);
  fill(120, 220, 140);
  rect(40, 140, 320 * s.progress, 16);
  fill(255);
  text(s.id + ': ' + s.state, 40, 120);
}
A progress bar for the piano samples; it fills within a few seconds and the label changes to "ready".

Related

  • OAVp5.sound.instrument The id of the instrument you hear right now, or null before sound has loaded.
  • OAVp5.sound.state Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.
  • startSound() Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.

p5/oav-p5.js, line 1351

↑ Back to top · All names