drumStep#
variableoav-p5drumStepAlso: OAVp5.drums.step
Which of the 16 steps of the bar the drum machine just played, from 0 to 15.
A bar has 16 steps (sixteenth notes) and a beat has 4, so drumStep % 4 === 0 is a beat and drumStep === 0 the start of a bar. At 120 bpm a step lasts 125 ms. Use it to light a cell or pick a frame: fill(i === drumStep ? 255 : 80). If you would rather be called on each step, define stepStarted(). For something that moves smoothly instead of in 16 jumps, use drumPhase.
- Type
Number- Range
0..15
Changes in the frame in which a step is heard, right before draw(). 0 at the start, and it keeps its last value when the machine stops.
Before it has a value
Start the machine with startDrums(). Before that, and when the machine is stopped, the value is 0 or the last one, so check drumsAreOn if the difference matters.
Notes
- A sketch that declares its own variable called
drumStepkeeps it: oav-p5 leaves the name alone and a card says to readOAVp5.drums.stepinstead. While the tab is hidden the clock keeps counting but nothing else is told.
Examples
function setup() {
createCanvas(400, 300);
startDrums('four on floor', 120);
noStroke();
}
function draw() {
background(20);
for (let i = 0; i < 16; i++) {
fill(drumsAreOn && i === drumStep ? 255 : 70);
rect(20 + i * 22, 130, 18, 40); // sixteen cells, the current one lights up
}
}function setup() {
createCanvas(400, 300);
startDrums('breakbeat', 110);
textAlign(CENTER, CENTER);
textSize(18);
}
function draw() {
background(drumStep % 4 === 0 ? 70 : 20); // a flash on every beat
fill(255);
text('step ' + drumStep + ' of 16' + (drumStep === 0 ? ' (bar starts)' : ''), width / 2, height / 2);
}Related
stepStarted()An event you define: it is called at every one of the 16 steps of the drum machine, with the step and the bar.drumBarWhich bar the drum machine is in, counted from 1 when it started.drumPhaseHow far through the current bar the drum machine is, smoothly from 0 up to just below 1, as it is heard.beatPhaseHow far through the current beat the drum machine is, smoothly from 0 up to just below 1, four times per bar.drumsAreOnWhether the drum machine is playing right now.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.