open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

lastKickTs#

variableoav-p5
lastKickTs

Also: 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

jsOpenProcessing ↗
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);
}
The circle swells on each kick and shrinks back; the line says how many ms ago the kick was.

Related

  • kickIsDetected True in the one frame after a kick (snare, hat) is heard, from the drum machine or the microphone, like mouseIsPressed for 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.
  • lastNoteTs When the last key went down, on the millis() clock: millis() - lastNoteTs is how many ms ago.

p5/oav-p5.js, line 330

↑ Back to top · All names