open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

drumsAreOn#

variableoav-p5
drumsAreOn

Whether the drum machine is playing right now.

Use it to tell "the drums are not running" from "the drums are at step 0": drumStep is 0 in both cases. if (drumsAreOn) { … } is also the right guard before you read drumPhase. It changes only when the machine starts or stops, and reading it never starts anything.

For the reason behind a false read OAVp5.drums.state: 'loading' while the module arrives, 'stopped' when the grid is up but not playing, 'error' when it could not load.

Type
Boolean

True while the machine plays, false at the start, after stopDrums(), after an error and while the grid's own checkbox is unticked.

Before it has a value

It becomes true after startDrums() (or 🥁 in the 🎹 panel) has loaded the machine, usually within a fraction of a second.

Notes

  • A sketch that declares its own variable called drumsAreOn keeps it: oav-p5 leaves the name alone and a card says to read OAVp5.drums.state === 'on' instead.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startDrums('half time', 100);
  textAlign(CENTER, CENTER);
}

function draw() {
  background(20);
  fill(drumsAreOn ? color(120, 220, 140) : color(220, 160, 60));
  circle(width / 2, height / 2, 80);
  fill(255);
  text(drumsAreOn ? 'drums are on' : 'drums are not running', width / 2, height - 40);
}
An amber circle for a moment while the machine loads, then green.

To be confirmed

After stopDrums() and a second startDrums() it stayed false while the machine played again (Chromium, oav-p5 0.8.0). Not confirmed whether that is intended.

Related

  • startDrums() Starts a drum machine: a 16-step grid on the page that plays a preset, your own grid or one line of rhythm, and counts the bars for your sketch.
  • stopDrums() Stops the drum machine and hides its card.
  • drumStep Which of the 16 steps of the bar the drum machine just played, from 0 to 15.
  • soundIsOn Whether notes are being heard right now: true once startSound() has finished, false before and after.
  • micIsOn Whether the microphone is running right now.
  • recordingIsOn Whether a recording is running right now.

p5/oav-p5.js, line 316

↑ Back to top · All names