open-audiovisual
Search GitHub

oav-p5 reference · Sound and instruments

OAVp5.sound#

objectoav-p5
OAVp5.sound

The object behind the sound names: the state, the instrument, the error, the loading progress and the loaded parts of @openav/sound.

OAVp5.sound (also reachable as midi.sound) is what startSound(), stopSound() and soundIsOn are built on. Read state to know where sound is, instrument for what you hear, status for the loading progress and error for a failure. start(id) and stop() are the same as the two global functions. shell, engine and module hand you the loaded @openav/sound parts for the rare case that you need them.

Notes

  • For a sketch the global names are enough. This object is for tools, the console and debugging: OAVp5.sound.state is the first thing to look at when nothing is heard.

Examples

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

function draw() {
  background(20);
  fill(255);
  const s = OAVp5.sound;
  text('state: ' + s.state, 20, 30);
  text('instrument: ' + s.instrument, 20, 60);
  text('error: ' + s.error, 20, 90);
}
Three lines of the sound object: the state goes from "loading" or "waiting" to "on" after the first click.

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.
  • soundIsOn Whether notes are being heard right now: true once startSound() has finished, false before and after.
  • OAVp5.sound.state Where sound is: 'off', 'waiting' (for a click), 'loading', 'on' or 'error'.
  • OAVp5.sound.status How the instrument is loading: { id, state, progress, error }, with progress from 0 to 1.
  • OAVp5.drums The object behind the drum names: the state of the machine, its counters, the line of rhythm, its history and the loaded machine.
  • OAVp5.record The object behind the recording names: the state, the time, the last file, the formats this browser can write and the screenshot function.

p5/oav-p5.js, line 1354

↑ Back to top · All names