open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

beatPhase#

variableoav-p5
beatPhase

Also: OAVp5.drums.beatPhase

How far through the current beat the drum machine is, smoothly from 0 up to just below 1, four times per bar.

A beat is a quarter note (four steps). 1 - beatPhase is biggest right on the beat and shrinks until the next one, so circle(width / 2, height / 2, 60 + (1 - beatPhase) * 80) pulses with the tempo, with no callback needed. drumPhase is the same thing across a whole bar.

Type
Number
Range
0..1

Read fresh each time you look at it. 0 on the beat, close to 1 just before the next one, then 0 again. It is 0 before the machine has played and holds still while it is stopped.

Before it has a value

Start the machine with startDrums(); until it plays, beatPhase is 0.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startDrums('four on floor', 120);
  noStroke();
}

function draw() {
  background(20);
  fill(255, 120, 90);
  circle(width / 2, height / 2, 60 + (1 - beatPhase) * 100);   // biggest on the beat
}
A circle that pulses four times per bar: biggest on each beat, then shrinking until the next one.

Related

  • drumPhase How far through the current bar the drum machine is, smoothly from 0 up to just below 1, as it is heard.
  • drumStep Which of the 16 steps of the bar the drum machine just played, from 0 to 15.
  • 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.
  • beat True for one frame each time the microphone (or the drum machine) hears a beat.

p5/oav-p5.js, line 1476

↑ Back to top · All names