open-audiovisual
Search GitHub

oav-p5 reference · MIDI: knobs, faders, pads, keys

lastNoteTs#

variableoav-p5
lastNoteTs

When the last key went down, on the millis() clock: millis() - lastNoteTs is how many ms ago.

Any key counts: a MIDI keyboard, the 🎹 on screen, a phone. Releasing a key does not change it.

Type
Number

Milliseconds on the same clock as millis(), set with note and velocity; -Infinity before any key. Since oav-p5 0.8.2.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  noStroke();
}

function draw() {
  background(20);
  const ago = millis() - lastNoteTs;    // ms since a key went down
  fill(255, 200 * exp(-ago / 400) + 30);
  circle(200, 150, 60 + 160 * exp(-ago / 400));
}
Each key you press (on 🎹 too) makes the circle bright and big, then it dims.

Related

  • note The MIDI number (0 to 127) of the last key pressed.
  • velocity How hard the last key was pressed, from 0 to 1.
  • notePressed() You define this function; oav-p5 calls it each time a key (or a pad) goes down.
  • lastKickTs When the last kick (snare, hat, beat) came, on the millis() clock: millis() - lastKickTs is how many ms ago.

p5/oav-p5.js, line 330

↑ Back to top · All names