OAVp5.note#
variableoav-p5OAVp5.note
An array of 128 numbers, one per MIDI key: how hard that key is held, 0 to 1, and 0 when it is up. OAVp5.note[60] is middle C.
Read every key at once, in draw(): OAVp5.note[60] for one key, or a loop over a range to draw a piano roll. It is the array version of noteIsDown(), with the velocity in it. It is not the variable note, which is just the number of the last key pressed. OAVp5.held is the same information as a short list of the keys that are down.
- Type
Array<Number>- Range
128 numbers, 0..1 each
The index is the MIDI note number, 0 to 127. A key that is down holds the velocity of its note-on divided by 127, a key that is up (or never pressed) holds 0. Changes when a message arrives, not once per frame.
Notes
midi.noteis the same array. A note-on with velocity 0 sets the key to 0, like a note-off.
Examples
function setup() {
createCanvas(400, 300);
noStroke();
}
function draw() {
background(20);
for (let n = 36; n < 96; n++) { // five octaves, C2 to B6
const v = OAVp5.note[n];
fill(v > 0 ? color(255, 211, 107) : 60);
rect(20 + (n - 36) * 6, height - 40 - v * 200, 5, 40 + v * 200);
}
}function setup() {
createCanvas(400, 300);
}
function draw() {
background(20);
const v = lag(OAVp5.note[60], 0.05, 0.4); // middle C, softened
circle(width / 2, height / 2, 40 + v * 260);
}Related
OAVp5.heldA list of the MIDI numbers of the keys that are down right now, lowest first.OAVp5.isDown()True while the keyn(a MIDI number or a name like'C4') is held down: the same asnoteIsDown(n).noteIsDown()True while the keyn(a MIDI number or a name like'C4') is held down.noteThe MIDI number (0 to 127) of the last key pressed.velocityHow hard the last key was pressed, from 0 to 1.OAVp5.ccAn array of 128 numbers, one per MIDI controller number: where each control last was, 0 to 1.OAVp5.cc[1]is the mod wheel,OAVp5.cc[64]the sustain pedal.