open-audiovisual
Search GitHub

oav-p5 reference · Timeline, cues and score

stepStarted()#

eventoav-p5
function stepStarted(step, bar) {}

An event you define: it is called at every one of the 16 steps of the drum machine, with the step and the bar.

Define function stepStarted(step, bar) { … } for something on every step: if (step % 4 === 0) ping = 1; is a pulse on the beat. It is called in the frame where the step is heard, right before draw(), after barStarted() and before the hits of that step. drumStep holds the same number if you would rather read than be called.

Parameters

NameTypeDescription
stepNumberThe step that starts, 0 to 15. Every 4 steps is a beat.
barNumberThe bar it is in, counted from 1.

Notes

  • It is not called while the tab is hidden, so a sketch that adds a particle per step does not burst when you come back.

Examples

jsOpenProcessing ↗
let ping = 0;

function setup() {
  createCanvas(400, 300);
  startDrums('breakbeat', 120);
  noStroke();
}

function stepStarted(step, bar) {
  if (step % 4 === 0) ping = 1;   // on every beat
}

function draw() {
  background(20);
  ping *= 0.9;
  fill(255, 160, 80);
  circle(width / 2, height / 2, 40 + ping * 120);
}
A circle that pulses on every beat (every fourth step) and shrinks back in between.

Related

  • drumStep Which of the 16 steps of the bar the drum machine just played, from 0 to 15.
  • barStarted() An event you define: it is called at the first step of every bar of the drum machine, with the bar number.
  • drumHit() An event you define: it is called for every hit of the drum machine, with the drum that sounded and how hard.
  • cueFired() An event you define: it is called when the bar of a cue declared with cue() has come, with the cue's name and the bar.
  • OAVp5.drums.on() Listens to the drum machine from anywhere: OAVp5.drums.on('hit', fn) calls fn like drumHit does, and returns a function that stops listening.

p5/oav-p5.js, line 1520

↑ Back to top · All names