open-audiovisual
Search GitHub

oav-p5 reference · MIDI: knobs, faders, pads, keys

OAVp5.isDown()#

functionoav-p5
OAVp5.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

NameTypeDescription
nNumber | StringThe 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

jsOpenProcessing ↗
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);
}
The background turns green while C, E and G are held together. Hold the mouse down to play the chord. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.

Related

  • noteIsDown() True while the key n (a MIDI number or a name like 'C4') is held down.
  • OAVp5.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.
  • OAVp5.held A 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.

p5/oav-p5.js, line 271

↑ Back to top · All names