notePressed()#
eventoav-p5function notePressed(note, velocity) {}
You define this function; oav-p5 calls it each time a key (or a pad) goes down.
Declare it the way you declare keyPressed():
function notePressed(note, velocity) {
// a key went down
}It is called once per key, with the key and how hard. A pad also calls it, unless the sketch defines padPressed().
Before it has a value
Defining it is enough: oav-p5 calls it from every source, and if Web MIDI is missing or refused it says so in a card beside the 🎹 (Web MIDI itself is asked for at load, see knob1). Keys from 🎹 and from a phone call it too.
Parameters
| Name | Type | Description |
|---|---|---|
note | Number | The MIDI number of the key (60 is middle C). noteName(note) turns it into a name. |
velocity | Number | How hard, 0..1. |
Notes
- An error inside it does not stop the music: the next key still plays, and the message shows in the console and on a card beside the 🎹, with the file and line.
Examples
function setup() {
createCanvas(400, 300);
background(20);
noStroke();
}
function notePressed(note, velocity) {
fill(random(255), random(255), random(255), 200);
circle(map(note, 36, 96, 20, width - 20), height / 2, 10 + velocity * 120);
}Related
noteReleased()You define this function; oav-p5 calls it each time a key (or a pad) is let go.padPressed()You define this function; oav-p5 calls it each time a drum pad is hit.noteOn()You define this function; oav-p5 calls it for every MIDI note-on, with the key, how hard and the channel.noteThe MIDI number (0 to 127) of the last key pressed.noteName()Turns a MIDI number into a note name:noteName(61)is'C#4'.