barStarted()#
eventoav-p5function barStarted(bar) {}
An event you define: it is called at the first step of every bar of the drum machine, with the bar number.
Define function barStarted(bar) { … } to do something once per bar: function barStarted(bar) { drift += 9; }. It is called in the frame where the first step of the bar is heard, right before draw(), and the first call is barStarted(1) when the machine starts. Within a step, cueFired() comes before it and stepStarted() after.
Parameters
| Name | Type | Description |
|---|---|---|
bar | Number | The bar that starts, counted from 1. |
Notes
- While the tab is hidden it is still called once per bar, but nothing is told twice when the tab comes back.
stepStarted()and the hits are not told in that time.
Examples
let shade = 200;
function setup() {
createCanvas(400, 300);
colorMode(HSB, 360, 100, 100);
startDrums('four on floor', 150);
}
function barStarted(bar) {
shade = (shade + 40) % 360; // a new colour every bar
}
function draw() {
background(shade, 60, 80);
fill(0, 0, 100);
textAlign(CENTER, CENTER);
textSize(48);
text(drumBar, 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.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.drumBarWhich bar the drum machine is in, counted from 1 when it started.drumHit()An event you define: it is called for every hit of the drum machine, with the drum that sounded and how hard.OAVp5.drums.on()Listens to the drum machine from anywhere:OAVp5.drums.on('hit', fn)callsfnlikedrumHitdoes, and returns a function that stops listening.