open-audiovisual
Search GitHub

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

OAVp5.input()#

functionoav-p5
OAVp5.input(bytes, [source], [device])

Sends one MIDI message into oav-p5 by hand, as bytes: the whole sketch reacts as if a controller had sent it.

It is the door every input goes through, and you can knock on it yourself: a sketch can test itself without a controller, drive itself from a timer, or take messages from a WebSocket or another library. The sketch cannot tell the difference: knob1, notePressed(), OAVp5.note, the sound if startSound() is on and the drum cues all react. OAVp5.play() is the friendlier way to send a note.

Parameters

NameTypeDescription
bytesArray<Number>One message, [status, data1, data2]: [0x90, 60, 100] is a note-on for key 60 with velocity 100 on channel 1, [0xB0, 74, 127] a control change, [0xE0, 0, 64] a pitch bend in the middle. The status byte sets the kind (top half) and the channel (bottom half). Only the first three numbers are read, and the data bytes are held to 0 to 127. System messages are not for this: the clock bytes (0xF8, 0xFA, 0xFB, 0xFC, 0xF2) go to OAVp5.clock, and anything else from 0xF0 up is ignored.
sourceStringA label for where it came from, which shows up as OAVp5.last.source and as the second argument of midiMessage(). Any text. 'hardware' and 'virtual-out' are taken as those real sources and are not repeated to a sketch's own Web MIDI code. optional default 'screen'
deviceStringA profile id such as 'akai-lpd8': the numbering of knob1, pad1 … follows that controller for this message. Left out, it is the controller on the on-screen panel. optional

Notes

  • midi.input(…) is the same function. It returns nothing. A message with a source other than 'screen' also lights the keys of the on-screen controller if it is open.

Examples

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

function mousePressed() {
  OAVp5.input([0x90, 60 + floor(random(12)), 100]);   // a note-on, as a key would send it
}

function notePressed(note, velocity) {
  background(20);
  fill(255);
  text(noteName(note) + ' (sent by hand)', width / 2, height / 2);
}
Click the canvas: the sketch hears a note-on exactly as if you had played a key, and names it.
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function mouseDragged() {
  OAVp5.input([0xB0, 74, constrain(round(mouseX / width * 127), 0, 127)]);   // CC 74 is knob 1 on a MiniLab 3
}

function draw() {
  background(20);
  circle(width / 2, height / 2, 40 + knob1 * 300);
}
Drag the mouse across the canvas: it sends CC 74, which is knob 1, and the circle follows.
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  OAVp5.input([0xB0, 70, 127], 'test', 'akai-lpd8');   // CC 70 is knob 1 on an LPD8
}

function draw() {
  background(20);
  fill(255);
  text('knob1 = ' + knob1 + ' (from the LPD8 numbering)', 20, 30);
  text('last: ' + OAVp5.last.control + ' from ' + OAVp5.last.source, 20, 60);
}
The third argument says which controller the message comes from, so CC 70 is knob 1 here, whatever profile the panel shows.

Related

  • OAVp5.play() Plays a key as if a controller did: midi.play(60, 0.8) presses middle C, midi.play(60, 0) lets it go.
  • OAVp5.last The latest note, control change or pitch bend that arrived: its type, number, value, channel, where it came from and which control it is. null before any.
  • OAVp5.on() Listens to a MIDI event by name without defining a global function, and returns a function that stops listening.
  • midiMessage() You define this function; oav-p5 calls it for every MIDI message it receives, with the raw bytes and where they came from.
  • noteOn() You define this function; oav-p5 calls it for every MIDI note-on, with the key, how hard and the channel.
  • 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 273

↑ Back to top · All names