open-audiovisual
Search GitHub

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

note#

variableoav-p5
note

The MIDI number (0 to 127) of the last key pressed.

Middle C is 60, A4 is 69. noteName(note) writes the number as a name (60 → 'C4') and noteFreq(note) as a frequency in Hz. velocity says how hard it was pressed. For every key, not just the last, define notePressed().

Type
Number
Range
0..127

Set when a key goes down and kept after it is released; 0 before any key has been pressed.

Before it has a value

Nothing to call. Web MIDI is asked for at load (see knob1). Unlike a knob, merely reading note does not tell oav-p5 the sketch plays from MIDI: defining notePressed() or reading a knob or pad does, which is what makes a missing or refused Web MIDI show as a card. 🎹 and a phone always work.

Notes

  • A sketch with its own note (a let note, a function) keeps it; read midi.last.note instead. oav-p5 says so in a card the first time.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  textAlign(CENTER, CENTER);
  textSize(64);
}

function draw() {
  background(20);
  fill(255);
  text(noteName(note), width / 2, height / 2);   // the last key, as a name
}
Shows the name of the last key you played. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.

Related

  • velocity How hard the last key was pressed, from 0 to 1.
  • noteIsPressed True while at least one key is held down.
  • notePressed() You define this function; oav-p5 calls it each time a key (or a pad) goes down.
  • noteName() Turns a MIDI number into a note name: noteName(61) is 'C#4'.

p5/oav-p5.js, line 326

↑ Back to top · All names