open-audiovisual
Search GitHub

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

knob1#

variableoav-p5
knob1

Also: knob2 knob3 knob4 knob5 knob6 knob7 knob8

The position of a controller knob, from 0 to 1: knob1 is the first knob, knob2 the second, up to knob8.

Read it in draw() the way you read mouseX: background(knob1 * 255). Knobs are numbered the way they are printed on the controller, so knob 1 is knob 1 on any controller OAV has a profile for: the MiniLab 3's first knob is CC 74, the LPD8's is CC 70. The sketch never needs to know a CC number.

On a controller OAV has no profile for, the first knob you turn becomes knob1, the next one knob2, and so on, in the order you turn them. Past eight, use knob(n).

Type
Number
Range
0..1

Changes when the knob moves, not once per frame; the sketch just reads the latest value. 0 until the knob has been turned.

Before it has a value

Nothing to call. With the default hardware=auto, oav-p5 asks the browser for Web MIDI as soon as it loads, whatever the sketch reads (Chrome, Edge and Firefox have it; Safari and iPad do not: use 🎹 or a phone there). Reading a knob also tells oav-p5 the sketch plays from MIDI, so when Web MIDI is missing or refused a card beside the 🎹 says so; a sketch that uses none of this never sees that card. ?oav_hardware=click waits for the 🎹 panel instead.

Notes

  • A sketch that already has its own knob1 (a let, a function) keeps it, and a card beside the 🎹 says what to read instead (knob(1)).
  • With OP Configurator, knobs also drive the OPC sliders in the order they are declared. A knob the sketch reads itself stays the sketch's: that slider no longer follows it.

Examples

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

function draw() {
  background(knob1 * 255);   // knob 1 sets the brightness
}
Turn knob 1 and the whole canvas goes from black to white. Plug in a controller, or press 🎹 (bottom right) and use the on-screen one.
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  colorMode(HSB, 1);
}

function draw() {
  background(0.65, 0.5, 0.15);
  fill(knob2, 0.8, 1);                        // knob 2: colour
  circle(width / 2, height / 2, 40 + knob1 * 300);   // knob 1: size
}
Two knobs, two jobs: size and colour.

Related

  • knob() Returns the position of knob number n, from 0 to 1: the same as knob1 to knob8, for any n.
  • fader1 The position of a controller fader (slider), from 0 to 1: fader1 is the first fader, up to fader8.
  • pad1 How hard a drum pad is pressed, from 0 to 1: pad1 is the first pad, up to pad16; 0 when it is let go.
  • knobMoved() You define this function; oav-p5 calls it whenever a knob moves.
  • noteIsDown() True while the key n (a MIDI number or a name like 'C4') is held down.

p5/oav-p5.js, line 288

↑ Back to top · All names