open-audiovisual
Search GitHub

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

noteOff()#

eventoav-p5
function noteOff(note, channel) {}

You define this function; oav-p5 calls it for every MIDI note-off, with the key and the channel.

The partner of noteOn():

js
function noteOff(note, channel) {
  // a key or pad came up
}

It is called for a note-off message and also for a note-on with velocity 0, which many keyboards send instead. There is no velocity: oav-p5 does not pass the release velocity.

For one incoming message the order is: midiMessage(), then the specific one (noteOn(), controlChange(), pitchBend()), then the friendly one (padPressed(), knobMoved(), notePressed() and their partners).

Before it has a value

Defining the function is enough. oav-p5 asks the browser for Web MIDI when it loads (the default, ?oav_hardware=auto), and a sketch that defines it also gets a card if Web MIDI is missing or blocked. Keys from 🎹, a phone, OAVp5.input() and other programs reach it too. OAVp5.on('noteOff', fn) does the same without defining a global function, and returns a function that stops it.

Parameters

NameTypeDescription
noteNumberThe MIDI number of the key that came up, 0 to 127.
channelNumberThe MIDI channel, 1 to 16.

Notes

  • An error inside it does not stop the music: the next message is still handled, and the message shows in the console and on a card beside the 🎹, with the file and line.

Examples

jsOpenProcessing ↗
const down = {};
let held = 'play a key and let it go';

function setup() {
  createCanvas(400, 300);
  textAlign(CENTER, CENTER);
  textSize(24);
}

function noteOn(note) { down[note] = millis(); }

function noteOff(note) {
  if (down[note] !== undefined) {
    held = noteName(note) + ' was held ' + round(millis() - down[note]) + ' ms';
    delete down[note];
  }
}

function draw() {
  background(20);
  fill(255);
  text(held, width / 2, height / 2);
}
Pairs each noteOn() with its noteOff() and says how long the key was held. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.

Related

  • noteOn() You define this function; oav-p5 calls it for every MIDI note-on, with the key, how hard and the channel.
  • noteReleased() You define this function; oav-p5 calls it each time a key (or a pad) is let go.
  • padReleased() You define this function; oav-p5 calls it each time a drum pad is let go.
  • midiMessage() You define this function; oav-p5 calls it for every MIDI message it receives, with the raw bytes and where they came from.
  • OAVp5.on() Listens to a MIDI event by name without defining a global function, and returns a function that stops listening.

p5/oav-p5.js, line 255

↑ Back to top · All names