cueFired()#
eventoav-p5function 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
| Name | Type | Description |
|---|---|---|
name | Any | The name you gave to cue(). |
bar | Number | The 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
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);
}Related
cue()Plans something for a bar: at barbarthe functioncueFired(name, bar)is called andcueNamebecomesname; withevery, again every that many bars.cueNameThe 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)callsfnlikedrumHitdoes, and returns a function that stops listening.