OAVp5.connectHardware()#
functionoav-p5OAVp5.connectHardware()
Asks the browser for Web MIDI now, and returns a promise that says whether a real controller can be heard.
It does what ?oav_hardware=auto does at load, at a moment you pick: from a button, after an intro, or when hardware is click or off. It works whatever the option says. After a refusal you can call it again to retry, but browsers usually remember a refusal and answer at once, so the way out is the lock icon left of the address.
Before you call it
A browser with Web MIDI (Chrome, Edge, Firefox), on https or localhost. Some browsers want a click first: call it from mousePressed() or a button handler if setup() is too early. Safari and iPad have none: the promise resolves false and OAVp5.hardware is 'unavailable'.
Returns
Promise<Boolean> Resolves to true once the browser has allowed Web MIDI (with or without a device plugged in), and to false if it refused or there is no Web MIDI in this browser. Calling it again while it is asking, or after it said yes, gives the same answer.
Examples
window.OAV_P5 = { hardware: 'click' }; // do not ask at load
let answer = 'click the canvas to ask for Web MIDI';
function setup() {
createCanvas(400, 300);
}
function mousePressed() {
OAVp5.connectHardware().then((ok) => { answer = ok ? 'Web MIDI allowed' : 'no Web MIDI for this page'; });
}
function draw() {
background(20);
fill(255);
text(answer, 20, 30);
text('state: ' + OAVp5.hardware, 20, 60);
}Related
OAVp5.hardwareWhere Web MIDI stands:'off','asking','connected','waiting','denied'or'unavailable'.OAVp5.devicesThe names of the MIDI controllers plugged in, as the browser reports them: an array of text, empty when there is none.hardwareWhen oav-p5 asks the browser for Web MIDI, which a real controller needs:autoat load,clickwhen the 🎹 panel opens, oroff.