open-audiovisual
Search GitHub

oav-p5 reference · Timeline, cues and score

cueFired()#

eventoav-p5
function cueFired(name, bar) {}

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.

Define function cueFired(name, bar) { … } and it is called at the step where a cue is due, before barStarted(), stepStarted() and the hits of that step. A good place to change a scene: function cueFired(name) { look = SCENES[name]; }. If you only need the latest name, read cueName in draw() instead.

Parameters

NameTypeDescription
nameAnyThe name you gave to cue().
barNumberThe bar the cue fired in, counted from 1. For a cue in the middle of a bar (4.5) it is the whole bar it falls in (4).

Notes

  • Cues keep firing while the tab is hidden, so the scene is right when you come back. Several cues on one step call it once each, in the order they were declared.

Examples

jsOpenProcessing ↗
let scene = '-';
let when = 0;

function setup() {
  createCanvas(400, 300);
  startDrums('four on floor', 150);
  cue(1, 'intro');
  cue(3, 'verse', 4);
  cue(5, 'chorus', 4);
  textAlign(CENTER, CENTER);
  textSize(32);
}

function cueFired(name, bar) {
  scene = name + ' (bar ' + bar + ')';
  when = millis();
}

function draw() {
  background(20 + max(0, 1 - (millis() - when) / 400) * 120);   // a flash on every cue
  fill(255);
  text(scene, width / 2, height / 2);
}
The screen flashes and names the scene each time a cue fires: intro once, then verse and chorus take turns.

Related

  • cue() Plans something for a bar: at bar bar the function cueFired(name, bar) is called and cueName becomes name; with every, again every that many bars.
  • cueName The name of the last cue that fired, or an empty string before the first one.
  • barStarted() An event you define: it is called at the first step of every bar of the drum machine, with the bar number.
  • 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.
  • 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 1516

↑ Back to top · All names