open-audiovisual
Search GitHub

oav-p5 reference · Sound and instruments

OAVp5.sound.instrument#

variableoav-p5
OAVp5.sound.instrument

The id of the instrument you hear right now, or null before sound has loaded.

After a first startSound('piano') the piano's samples (about 2 MB) download first, and the electric piano plays meanwhile, so the first key is never silent: instrument says 'epiano' until the piano is ready and 'piano' after. When you switch to the piano from another instrument, that one keeps sounding and instrument names it until the samples are in. How far the loading is, and which instrument it is on, is in OAVp5.sound.status.

Type
String | null

Changes when the instrument changes, which for a sampled instrument is when its samples are in.

Examples

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

function draw() {
  background(20);
  fill(255);
  text(OAVp5.sound.instrument || 'nothing loaded yet', width / 2, height / 2);
}
Shows the instrument you hear: epiano while the piano samples arrive, then piano.

Related

  • startSound() Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.
  • OAVp5.sound.status How the instrument is loading: { id, state, progress, error }, with progress from 0 to 1.
  • OAVp5.sound.state Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.

p5/oav-p5.js, line 1347

↑ Back to top · All names