open-audiovisual
Search GitHub

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

OAVp5.held#

variableoav-p5
OAVp5.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.held is 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

jsOpenProcessing ↗
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);
}
Spells the keys held down, lowest first. Click the canvas to hold one more key. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.

Related

  • 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.
  • noteIsPressed True while at least one key is held down.
  • noteIsDown() True while the key n (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'.

p5/oav-p5.js, line 258

↑ Back to top · All names