mic#
optionoav-p5?oav_mic=auto | click | off
Who may turn the microphone on: auto (the first read of micLevel and friends), click (only 🎤 or startMic()) or off (nobody).
With auto, the first time a sketch reads micLevel, bass, mid, treble or beat, oav-p5 asks the browser for the microphone. With click, reading them does nothing: the microphone starts only when someone presses 🎤 in the 🎹 panel or the sketch calls startMic(), so the permission prompt arrives when you choose. With off, nothing opens the microphone, not even startMic(), which resolves false.
off is a promise to the page: a gallery piece that must never listen can say so. click is for pieces where a permission prompt out of nowhere would be rude, or where the sound only matters after an intro. The values of the microphone stay 0 while it is off.
- Type
String- Values
auto | click | off- default
auto
Anything else means auto.
Notes
- Set it before oav-p5 loads.
window.OAV_P5 = { mic: … };above the loader line wins, then?oav_mic=…on the page address, then?mic=…on the script's own URL. Values inwindow.OAV_P5are turned into text, so write'off', notfalse. On OpenProcessing the page address takes?sketch_oav_mic=…(the project's README says OpenProcessing forwards it to the sketch).
Examples
window.OAV_P5 = { mic: 'click' };
function setup() {
createCanvas(400, 300);
}
function mousePressed() {
startMic(); // now the browser asks
}
function draw() {
background(20);
circle(width / 2, height / 2, 50 + micLevel * 300); // reading micLevel no longer asks
fill(255);
text('microphone: ' + OAVp5.mic.state + ' (click the canvas to start it)', 20, 30);
}window.OAV_P5 = { mic: 'off' };
let answer = 'click the canvas to try';
function setup() {
createCanvas(400, 300);
}
function mousePressed() {
startMic().then((ok) => { answer = 'startMic() resolved ' + ok; });
}
function draw() {
background(20);
fill(255);
text('microphone: ' + OAVp5.mic.state, 20, 30);
text(answer, 20, 60); // startMic() resolved false
}To be confirmed
Not tried on openprocessing.org itself: that ?sketch_oav_mic=click on the page address reaches the sketch.
Related
micLevelHow loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).startMic()Turns the microphone on and returns a promise that says whether it worked.stopMic()Turns the microphone off and sets every microphone value back to 0.OAVp5.mic.stateWhere the microphone is:'off','asking','on','denied'or'unavailable'.micIsOnWhether the microphone is running right now.