sound#
optionoav-p5?oav_sound=click | off | an instrument id
Whether notes are heard: click (only after startSound() or 🔊), off (never), or an instrument id that starts at the first click.
With click, nothing makes a sound until the sketch calls startSound() or someone presses 🔊 in the 🎹 panel. With an instrument id, every key, pad, the on-screen controller and a phone are heard from the first click on the page, with no code at all, so any MIDI sketch becomes playable by adding the option to the page address: ?oav_sound=piano. off is a promise to the page: nothing sounds, startSound() resolves false and the 🔊 button is hidden.
Browsers let a page play sound only after a click, and a MIDI key is not a click, so the first sound waits for one: a card says "sound is ready but silent" until then.
- Type
String- Values
click | off | an instrument id- default
click
An instrument id such as piano, organ, strings, harp or music-box. on and auto start the default instrument (the piano). An id that does not exist plays the default synth (synth/pad) and the console lists the ids that exist.
Notes
- Set it before oav-p5 loads.
window.OAV_P5 = { sound: … };above the loader line wins, then?oav_sound=…on the page address, then?sound=…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_sound=…(the project's README says OpenProcessing forwards it to the sketch).
Examples
window.OAV_P5 = { sound: 'organ' };
function setup() {
createCanvas(400, 300);
}
function mousePressed() {
OAVp5.play(60 + floor(random(12)), 0.8); // a key, as a controller would play it
}
function draw() {
background(20);
fill(255);
text('sound: ' + OAVp5.sound.state + ' (' + OAVp5.sound.instrument + ')', 20, 30);
text('click the canvas to play a note', 20, 60);
}window.OAV_P5 = { sound: 'off' };
let answer = 'click the canvas to try';
function setup() {
createCanvas(400, 300);
}
function mousePressed() {
startSound().then((ok) => { answer = 'startSound() resolved ' + ok; });
}
function draw() {
background(20);
fill(255);
text('sound: ' + OAVp5.sound.state, 20, 30);
text(answer, 20, 60); // startSound() resolved false
}Related
startSound()Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.stopSound()Turns sound off and lets every ringing note go; the instrument stays loaded, sostartSound()brings it back at once.soundIsOnWhether notes are being heard right now: true oncestartSound()has finished, false before and after.toneWhere Tone.js, the sound engine behindstartSound(), is loaded from: an ES module address. Empty means jsDelivr.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.