open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

drumBpm#

variableoav-p5
drumBpm

Also: OAVp5.drums.bpm

The tempo of the drum machine in beats per minute.

A beat is a quarter note, four steps, so one step lasts 60 / drumBpm / 4 seconds and one bar 240 / drumBpm: at 120 a bar takes 2 seconds. To change the tempo call startDrums(bpm): startDrums(drumBpm + 5) speeds up by five. Writing to drumBpm yourself changes nothing.

startDrums() keeps the tempo between 30 and 300; the slider on the grid goes from 60 to 180.

Type
Number
Range
30..300

112 until you set another one. It follows startDrums() and the tempo slider on the grid.

Notes

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

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startDrums('four on floor', 100);
  textAlign(CENTER, CENTER);
  textSize(32);
}

function keyPressed() {
  if (keyCode === UP_ARROW) startDrums(drumBpm + 5);
  if (keyCode === DOWN_ARROW) startDrums(drumBpm - 5);
}

function draw() {
  background(20);
  fill(255);
  text(round(drumBpm) + ' bpm', width / 2, height / 2);
}
Press the up and down arrow keys to change the tempo by 5; the number shows it.

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.
  • drumPhase How far through the current bar the drum machine is, smoothly from 0 up to just below 1, as it is heard.
  • beatPhase How far through the current beat the drum machine is, smoothly from 0 up to just below 1, four times per bar.
  • drumBar Which bar the drum machine is in, counted from 1 when it started.

p5/oav-p5.js, line 317

↑ Back to top · All names