OAVp5.drums.count#
variableoav-p5OAVp5.drums.count
How many steps the drum machine has played since it started, from 0; -1 before the first one.
It is the single clock the others are cut from: drumBar is floor(count / 16) + 1, drumStep is count % 16, and cue() fires when count reaches the step of its bar. It is handy when you want one number that only grows: a position on a very long timeline, or an index into a list.
- Type
Number- Range
-1, 0, 1, 2 …
Goes up by one at every step and never goes back to 0 at a new bar. It starts again from 0 when the machine is started again.
Before it has a value
Start the machine with startDrums(); it is -1 until the first step has played.
Examples
function setup() {
createCanvas(400, 300);
startDrums('half time', 140);
textAlign(CENTER, CENTER);
textSize(28);
}
function draw() {
background(20);
fill(255);
const n = OAVp5.drums.count;
text('step ' + n + ' = bar ' + (floor(n / 16) + 1) + ', step ' + (n % 16), width / 2, height / 2);
}Related
drumBarWhich bar the drum machine is in, counted from 1 when it started.drumStepWhich of the 16 steps of the bar the drum machine just played, from 0 to 15.cue()Plans something for a bar: at barbarthe functioncueFired(name, bar)is called andcueNamebecomesname; withevery, again every that many bars.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.