OAVp5.held#
variableoav-p5OAVp5.held
A list of the MIDI numbers of the keys that are down right now, lowest first.
The short version of OAVp5.note: only the keys that are down, so OAVp5.held.length is how many, OAVp5.held[0] is the lowest and OAVp5.held.map((n) => noteName(n)) spells the chord. noteIsPressed is OAVp5.held.length > 0.
- Type
Array<Number>
Empty when nothing is held. A key is added when its note-on arrives and removed at its note-off, and the list is kept sorted from low to high.
Notes
midi.heldis the same array. Read it, do not change it. It is the same array object every time, so copy it ([...OAVp5.held]) if you want to keep a moment of it.
Examples
function setup() {
createCanvas(400, 300);
textAlign(CENTER, CENTER);
textSize(40);
}
function mousePressed() { OAVp5.play(60 + floor(random(12)), 0.8); } // no keys? click
function draw() {
background(20);
fill(255);
text(OAVp5.held.map((n) => noteName(n)).join(' ') || 'play a chord', width / 2, height / 2);
}Related
OAVp5.noteAn 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.noteIsPressedTrue while at least one key is held down.noteIsDown()True while the keyn(a MIDI number or a name like'C4') is held down.noteName()Turns a MIDI number into a note name:noteName(61)is'C#4'.