note#
variableoav-p5note
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(alet note, a function) keeps it; readmidi.last.noteinstead. oav-p5 says so in a card the first time.
Examples
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
}Related
velocityHow hard the last key was pressed, from 0 to 1.noteIsPressedTrue 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'.