open-audiovisual
Search GitHub

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

padPressed()#

eventoav-p5
function padPressed(n, velocity) {}

You define this function; oav-p5 calls it each time a drum pad is hit.

js
function padPressed(n, velocity) {
  // pad n was hit
}

When the sketch defines padPressed(), a pad calls it and not notePressed(); without it, a pad calls notePressed() like any key.

Parameters

NameTypeDescription
nNumberWhich pad (1 is the first).
velocityNumberHow hard, 0..1.

Examples

jsOpenProcessing ↗
let hits = [];

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

function padPressed(n, velocity) {
  hits.push({ x: 40 + ((n - 1) % 4) * 105, y: 70 + floor((n - 1) / 4) * 130, r: 20 + velocity * 60 });
}

function draw() {
  background(20, 40);
  fill(255, 90, 31);
  for (const h of hits) { circle(h.x, h.y, h.r); h.r *= 0.95; }
  hits = hits.filter((h) => h.r > 2);
}
Each hit pops a circle where its pad would sit on a 4×2 grid, and it fades away.

Related

  • padReleased() You define this function; oav-p5 calls it each time a drum pad is let go.
  • pad1 How hard a drum pad is pressed, from 0 to 1: pad1 is the first pad, up to pad16; 0 when it is let go.
  • notePressed() You define this function; oav-p5 calls it each time a key (or a pad) goes down.

p5/oav-p5.js, line 254

↑ Back to top · All names