stepStarted()#
eventoav-p5function 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
| Name | Type | Description |
|---|---|---|
step | Number | The step that starts, 0 to 15. Every 4 steps is a beat. |
bar | Number | The 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
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);
}Related
drumStepWhich 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 withcue()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)callsfnlikedrumHitdoes, and returns a function that stops listening.