padPressed()#
eventoav-p5function padPressed(n, velocity) {}
You define this function; oav-p5 calls it each time a drum pad is hit.
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
| Name | Type | Description |
|---|---|---|
n | Number | Which pad (1 is the first). |
velocity | Number | How hard, 0..1. |
Examples
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);
}Related
padReleased()You define this function; oav-p5 calls it each time a drum pad is let go.pad1How hard a drum pad is pressed, from 0 to 1:pad1is the first pad, up topad16; 0 when it is let go.notePressed()You define this function; oav-p5 calls it each time a key (or a pad) goes down.