open-audiovisual
Search GitHub

oav-p5 reference · Loading options

shim#

optionoav-p5
?oav_shim=on | off

Whether oav-p5 replaces navigator.requestMIDIAccess so sketches with their own Web MIDI code also hear the 🎹 and phones: on or off.

With on, a sketch that calls navigator.requestMIDIAccess() itself (WebMidi.js does) gets the real ports and one more input called "OAV Virtual MIDI", which carries whatever the on-screen controller and the phone play. It also works in Safari and on iPad, where there is no Web MIDI: the sketch gets the virtual port alone, so a WebMidi.js sketch still runs there. Programs can play into its output as well (Strudel's .midi('OAV Virtual MIDI')).

off leaves the browser's own requestMIDIAccess alone. Use it when a page already has its own MIDI handling that must not see an extra port.

Type
String
Values
on | off
default
on

Only off turns it off.

Notes

  • Order matters: oav-p5 has to load before the code that asks for MIDI, which is why the loader line goes first. A page that opened MIDI earlier keeps the browser's own answer, and 🩺 says so.
  • Set it before oav-p5 loads. window.OAV_P5 = { shim: … }; above the loader line wins, then ?oav_shim=… on the page address, then ?shim=… on the script's own URL. Values in window.OAV_P5 are turned into text, so write 'off', not false. On OpenProcessing the page address takes ?sketch_oav_shim=… (the project's README says OpenProcessing forwards it to the sketch).

Examples

jsOpenProcessing ↗
window.OAV_P5 = { shim: 'off' };

let names = 'asking…';

function setup() {
  createCanvas(400, 300);
  navigator.requestMIDIAccess().then(
    (access) => { names = [...access.inputs.values()].map((i) => i.name).join(', ') || 'no inputs'; },
    (error) => { names = 'refused: ' + error.name; }
  );
}

function draw() {
  background(20);
  fill(255);
  text('shim: ' + OAVp5.options.shim, 20, 30);
  text('MIDI inputs: ' + names, 20, 60);
}
With the shim off, the sketch gets only the browser's own answer (the real inputs, or a refusal). Delete the first line and "OAV Virtual MIDI" is in the list. The browser may ask you for MIDI permission.

Related

  • OAVp5.input() Sends one MIDI message into oav-p5 by hand, as bytes: the whole sketch reacts as if a controller had sent it.
  • hardware When oav-p5 asks the browser for Web MIDI, which a real controller needs: auto at load, click when the 🎹 panel opens, or off.
  • 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.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.

p5/oav-p5.js, line 127

↑ Back to top · All names