open-audiovisual
Search GitHub

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

knob()#

functionoav-p5
knob(n)

Returns the position of knob number n, from 0 to 1: the same as knob1 to knob8, for any n.

Use it when the number of the knob is a variable: for (let i = 1; i <= 16; i++) bar(i, knob(i));. It also works in a sketch that has its own knob1, which oav-p5 then leaves alone.

Parameters

NameTypeDescription
nNumberWhich knob, counting from 1 (as printed on the controller).

Returns

Number The knob's position, 0..1; 0 until it has been turned.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  noStroke();
}

function draw() {
  background(20);
  fill(255);
  for (let i = 1; i <= 8; i++) {
    rect(i * 44 - 20, height - 20, 30, -10 - knob(i) * 250);   // one bar per knob
  }
}
Eight bars, one per knob. Knobs you have not touched stay at the bottom.

Related

  • knob1 The position of a controller knob, from 0 to 1: knob1 is the first knob, knob2 the second, up to knob8.
  • fader() Returns the position of fader number n, from 0 to 1: the same as fader1 to fader8, for any n.
  • pad() Returns how hard pad number n is pressed, 0 to 1: the same as pad1 to pad16, for any n.

p5/oav-p5.js, line 360

↑ Back to top · All names