open-audiovisual
Search GitHub

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

OAVp5.note#

variableoav-p5
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.

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.note is the same array. A note-on with velocity 0 sets the key to 0, like a note-off.

Examples

jsOpenProcessing ↗
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);
  }
}
A bar for each key: it rises while the key is down, higher for a harder press. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.
jsOpenProcessing ↗
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);
}
Middle C (60) swells the circle by how hard it is held, and the circle shrinks back slowly.

Related

  • OAVp5.held A list of the MIDI numbers of the keys that are down right now, lowest first.
  • OAVp5.isDown() True while the key n (a MIDI number or a name like 'C4') is held down: the same as noteIsDown(n).
  • noteIsDown() True while the key n (a MIDI number or a name like 'C4') is held down.
  • note The MIDI number (0 to 127) of the last key pressed.
  • velocity How hard the last key was pressed, from 0 to 1.
  • OAVp5.cc An 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.

p5/oav-p5.js, line 258

↑ Back to top · All names