drumsAreOn#
variableoav-p5drumsAreOn
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
drumsAreOnkeeps it: oav-p5 leaves the name alone and a card says to readOAVp5.drums.state === 'on'instead.
Examples
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);
}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.drumStepWhich of the 16 steps of the bar the drum machine just played, from 0 to 15.soundIsOnWhether notes are being heard right now: true oncestartSound()has finished, false before and after.micIsOnWhether the microphone is running right now.recordingIsOnWhether a recording is running right now.