open-audiovisual
Search GitHub

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

knobMoved()#

eventoav-p5
function knobMoved(n, value) {}

You define this function; oav-p5 calls it whenever a knob moves.

Like mouseMoved() for knobs:

js
function knobMoved(n, value) {
  // knob n is now at value
}

It is called for every step the knob sends, so many times per second while it turns. To read a knob once a frame, use knob1 instead.

Parameters

NameTypeDescription
nNumberWhich knob (1 is the first, as printed on the controller).
valueNumberWhere it is now, 0..1.

Examples

jsOpenProcessing ↗
let last = 'turn a knob';

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

function knobMoved(n, value) {
  last = 'knob ' + n + ': ' + nf(value, 1, 2);
}

function draw() {
  background(20);
  fill(255);
  text(last, width / 2, height / 2);
}
Shows which knob moved and where it is. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.

Related

  • knob1 The position of a controller knob, from 0 to 1: knob1 is the first knob, knob2 the second, up to knob8.
  • faderMoved() You define this function; oav-p5 calls it whenever a fader moves.
  • controlChange() You define this function; oav-p5 calls it for every MIDI control change (a knob, a fader, the mod wheel, the sustain pedal), whether or not the controller is known.

p5/oav-p5.js, line 254

↑ Back to top · All names