OAVp5.isDown()#
functionoav-p5OAVp5.isDown(n)
True while the key n (a MIDI number or a name like 'C4') is held down: the same as noteIsDown(n).
It is noteIsDown() under the OAVp5 name, for a sketch that cannot use the plain one: OAVp5.isDown('C4'). A name that is not a note stops the sketch with a card that says how to write one.
Parameters
| Name | Type | Description |
|---|---|---|
n | Number | String | The key: a MIDI number (60) or a note name ('C4', 'c#4', 'Db3'). |
Returns
Boolean True if that key is down right now.
Notes
midi.isDown(…)is the same function.
Examples
function setup() {
createCanvas(400, 300);
textAlign(CENTER, CENTER);
textSize(32);
}
function mousePressed() { for (const n of ['C4', 'E4', 'G4']) OAVp5.play(n, 0.8); } // no keys? click for a chord
function mouseReleased() { for (const n of ['C4', 'E4', 'G4']) OAVp5.play(n, 0); }
function draw() {
const chord = OAVp5.isDown('C4') && OAVp5.isDown('E4') && OAVp5.isDown('G4');
background(chord ? color(60, 100, 40) : 20);
fill(255);
text(chord ? 'C major' : 'hold C4 + E4 + G4', width / 2, height / 2);
}Related
noteIsDown()True while the keyn(a MIDI number or a name like'C4') is held down.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.OAVp5.heldA list of the MIDI numbers of the keys that are down right now, lowest first.noteNumber()Turns a note name like'C4'into its MIDI number, 0 to 127.