lastKickTs#
variableoav-p5lastKickTsAlso: lastSnareTs lastHatTs lastBeatTs
When the last kick (snare, hat, beat) came, on the millis() clock: millis() - lastKickTs is how many ms ago.
Set by every hit that calls kickDetected(), snareDetected(), hatDetected() or beatDetected(): the drum machine's, or the microphone's when no drums play. Use it for anything that depends on how long ago: exp(-(millis() - lastKickTs) / 200) is 1 on the kick and fades with a 0.2 s time constant.
- Type
Number
Milliseconds on the same clock as millis(); -Infinity before the first hit, so millis() - lastKickTs is then Infinity. Since oav-p5 0.8.2.
Examples
function setup() {
createCanvas(400, 300);
startDrums('bd*4, hh*8', 100);
noStroke();
}
function draw() {
background(20);
const ago = millis() - lastKickTs; // ms since the last kick
fill(255, 90, 31);
circle(200, 200, 40 + 160 * exp(-ago / 200));
fill(255);
text(isFinite(ago) ? round(ago) + ' ms since the kick' : 'no kick yet', 20, 290);
}Related
kickIsDetectedTrue in the one frame after a kick (snare, hat) is heard, from the drum machine or the microphone, likemouseIsPressedfor a hit.kickDetected()You define these; oav-p5 calls them when the microphone (or the drum machine) hears a kick, a snare or a hat.lastNoteTsWhen the last key went down, on themillis()clock:millis() - lastNoteTsis how many ms ago.