The names a p5 sketch uses with oav-p5, on one page: shout into the microphone, hit the drum machine, play the keys, and make the numbers nice to use. Click a name for its full entry. It prints on one landscape A4.
The full API reference → oav-p5 0.8.4
start: one line
Paste it as the first line of the sketch (OpenProcessing or the p5 editor). A 🎹 appears in a corner: it has loaded.
document.head.prepend(Object.assign(document.createElement('script'), { src: 'https://openaudiovisual.com/p5/oav-p5.js' }));then a sketch looks like this
function setup() {
createCanvas(400, 300);
startDrums('four on floor'); // only if you want drums
}
function draw() {
background(20);
circle(200, 150, 40 + micLevel * 300);
}
function kickDetected(level) { // oav-p5 calls it
// a kick: do something
}Use the names inside setup(), draw() or a function oav-p5 calls. On the top line of the file they do not exist yet.
shout: the microphone
micLevelhow loud, 0 (quiet room) to 1 (shouting)bass mid treblelow / middle / high sound, each 0 to 1beattrue on the frame a beat is heardmicIsOnis the microphone working?micSensitivity(2)twice as sensitive (too quiet? try 3)startMic() stopMic()turn it on / off yourself
you write these, oav-p5 calls them
beatDetected(level)a beat: the sound jumpskickDetected(level)a kick in the low end (also snareDetected, hatDetected)
hit: the drum machine
startDrums('four on floor', 120)a 16-step drum machine appears, at 120 BPMstartDrums('bd*4, ~ sd, hh*8')or write the rhythm in one linestopDrums()stop it, put the card awaydrumStepwhich step just played, 0 to 15drumBarwhich bar, the first is 1drumPhase beatPhase0 → 1 smoothly, once a bar / once a beatdrumBpm drumsAreOnthe tempo / is it playing?kickIsDetected snareIsDetectedtrue in the frame of a hit: lag(kickIsDetected, 0, 0.3) fades itmillis() - lastKickTsms since the last kick (lastSnareTs, lastHatTs, lastBeatTs)frameCount - lastKickFrameCountframes since the last kick: 0 in its own frame
you write these, oav-p5 calls them
drumHit(lane, velocity)every hit: which drum, how hardbarStarted(bar)the first step of every barstepStarted(step, bar)every one of the 16 steps
a timeline in bars
cue(5, 'bloom', 12)at bar 5, then every 12 bars, call cueFiredcueFired(name, bar)you write it: change the scene herecueNamethe last cue that fireddrawRhythm(x, y, w, h, 'circle')the rhythm on the canvas ('grid', 'circle', 'spiral'): it is in your recording
a rhythm in one line
bd sd bd sdspaces share the bar out evenly (bd kick, sd snare, hh hat)hh*8eight timesbd ~ bd ~~ is a rest[bd bd] sd[ ] squeezes two into one placebd*4, ~ sda comma plays them at the same timebd(3,8)3 hits spread over 8 steps<bd sd>one each bar, taking turns
play: keys and knobs
notethe last key, a MIDI number 0 to 127 (60 is C4)velocityhow hard, 0 to 1millis() - lastNoteTsms since a key went downnoteIsDown(60) noteIsDown('C4')is that key held down?knob1 … knob8a knob, 0 to 1: read it like mouseXfader1 … pad1 …faders 0 to 1, pads (how hard, 0 when let go)
you write these, oav-p5 calls them
notePressed(note, velocity)a key goes downnoteReleased(note)a key comes upknobMoved(n, value)a knob turnspadPressed(n, velocity)a pad is hit
No keyboard? 🎹 on the page is one, 📱 turns your phone into one.
sound and note names
startSound('piano')the keys you play are heard (click the page once first)stopSound() soundIsOnsilence / is it on?noteName(61)→ 'C#4'noteNumber('C4')→ 60noteFreq('A4')→ 440 (hertz)
make numbers nice to use
lag(micLevel, 0.03, 0.4)follow, not jump: 0.03 s up, 0.4 s down (Lag CHOP)env('kick', 0.01, 0.3)jumps to 1 on each kick, sinks back in 0.3 s (Trigger CHOP)speed(TWO_PI)adds up every second: rotate() once a secondspring(knob1, 100, 6)overshoots and bounces, like a springtrail(micLevel, 3)the last 3 seconds, as a listdrawTrail(list, x, y, w, h)draw that list as a linecount('kick', 4)count: 0, 1, 2, 3, 0, …scope(value, 'name')a little scope in the corner, to look at a number
Put them in draw(), not inside an if.
record and check
startRecording() stopRecording()a video of the canvas with its sound (or 🎹 → ⏺)recordingIsOnrecording now?recordingSaved(info)the file is savedOAVp5.version'0.8.4': the line has loadedOAVp5.check()🩺 a card that says what works: screenshot it when you ask for help
No sound? Click the page once: browsers stay quiet until you do. Something else? 🎹 → 🩺, and send the screenshot.