open-audiovisual
Search GitHub

oav-p5 reference · Timeline, cues and score

barStarted()#

eventoav-p5
function 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

NameTypeDescription
barNumberThe 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

jsOpenProcessing ↗
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);
}
The background changes colour at the start of every bar, while the number counts the bars.

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 with cue() has come, with the cue's name and the bar.
  • drumBar Which 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) calls fn like drumHit does, and returns a function that stops listening.

p5/oav-p5.js, line 1519

↑ Back to top · All names