Skylar Dong / The Lab / Creative Coding
Gesture DJ
Two virtual platters, controlled by two bare hands through a webcam. Pinch to put a finger on the record, move in a circle to scratch it. Whatever the platter does, the sound is drawn as grooves around it.
If a hand replaces the platter, what is left of the instrument?
Hold the record still
and the sound
becomes a scar.
Play
Start with the camera to play with your hands, or with a mouse or touch screen. Two synth loops are already on the decks; drop your own audio onto a platter to replace them.
With a camera
- Pinch on a platter
- Touch the record: it holds
- Pinch
- Scratch
- Pinch a slider
- Drag pitch (±12%) or crossfade
- Pinch “Sync to X”
- Match tempo and beat
With a mouse or touch
- Press a platter
- Hold it
- Drag in a circle
- Scratch
- A / B
- Tap on a kick to mark the beat
- Load A / Load B
- Your own audio; set the BPM if it is not in the file name
Thinking
The idea did not start in code. It started at a friend's party, standing in front of a controller I did not know how to name.
The thing at the party
Two large discs side by side, like a pair of CDs, with a laptop app mirroring them on screen. The person using it kept putting a hand on a disc, slowing it, nudging it, until two different songs fell into the same tempo. Then they cut from one to the other. I had no vocabulary for any of this, so the first piece of research was learning what I was looking at.
Why gestures
The brief asked for three things in one sketch: ml5.js as the controller, audio playback, and audio visualization. The obvious combination is a button that triggers a sound and a spectrum that bounces. I wanted the controller to be the same gesture the instrument already demands. A DJ’s hand on a platter is already a gesture. It only lacks the platter.
That is the problem the piece actually works on. A real platter pushes back: it has mass, friction, a surface you feel. A hand in the air has none of that. So the interesting question is not whether pinching can stand in for touching, but what the screen has to do to give some of that resistance back.
Where the visualization came from
I did not want a spectrum. A spectrum has no relationship to the hand. What I wanted was the moment the hand stops the record: the sound disappears, and in that silence something should remain. That became the rule for the whole drawing, described in the next section.
Seeing sound
Three rules, each tied to something the hand does.
Ring colour and thickness follow the low end of the track, so a kick thickens the groove. The platter’s angle is the track’s position, so a full turn is about 1.8 seconds at 33⅓ rpm, the way a real record would run.
Sync
Why it matches the beat for you.
Matching by eye, with a hand, in the air, turned out to be nearly impossible: a hand has no detent to land in. So I added an automatic sync, on the assumption that the point of the piece is the gesture and the rings, not the tedium of aligning.
Sync works in two steps. First tempo: the follower deck’s speed is scaled so its BPM equals the leader’s, trying the straight, half and double readings and taking the closest. Then phase: the gap between the two beats is measured and fed back as a small nudge over a second or two, so it glides into place instead of jumping.
To show the result, the middle of the screen carries a moiré: two fans of spokes, one per deck, drawn so that when the beats align the lines coincide and the figure locks. Off by a little, and the pattern shimmers.
Where it is wrong
Sync is only as good as its BPM. The BPM comes from the file name when it is written there (…_130bpm), and otherwise from a detector that autocorrelates the low-frequency onsets. On clean four-on-the-floor loops it is fine. On a dense synth line it read a 130 BPM track as 80.8, and on syncopated material its guess of where beat one sits can be off by about a sixth of a beat. So the sketch carries two escape hatches: an editable BPM box per deck, and a key (A or B) to tap a kick and mark the beat yourself. I kept the failures visible rather than hide them.
Code
Built in p5.js with ml5.js handPose and the Web Audio API.
A scratch is not a sample being triggered; it is a buffer being read at a signed, changing speed. That cannot be done with a normal audio element, so each deck is an AudioWorklet that reads the track sample by sample with its playback rate as a variable. A rate of 1 is normal, 0 is held, negative is reversed. The hand only has to set the target rate.
process(inputs, outputs) {
for (let i = 0; i < L.length; i++) {
this.rate += (this.target - this.rate) * this.k; // ease toward what the hand asks for
const i0 = Math.floor(this.pos), f = this.pos - i0;
const gain = Math.min(1, Math.abs(this.rate) * 3); // silence when the platter stops
L[i] = (a[i0] * (1 - f) + a[(i0 + 1) % len] * f) * gain;
this.pos = (this.pos + this.rate + len) % len;
}
}
The hand becomes a pointer. Thumb tip and index tip give a pinch (their distance divided by the hand’s size, with two thresholds so it does not flicker). The pinch point’s angular velocity around the platter’s centre becomes the rate. That one choice is why circling feels like scratching and straight lines do not.
function syncDeck(f, l) {
const target = l.bpm * l.tempo;
let tempo = 1, bestGap = Infinity;
for (const m of [1, 0.5, 2]) { // also accept half / double time
const t = (target * m) / f.bpm;
if (Math.abs(t - 1) < bestGap) { bestGap = Math.abs(t - 1); tempo = t; }
}
f.tempo = constrain(tempo, 0.8, 1.2);
const dp = ((l.phase - f.phase + 1.5) % 1) - 0.5; // beat gap, −0.5 … +0.5
f.nudge = dp * (60 / f.bpm); // glide, do not jump
}
Tools
p5.js 1.11 · ml5.js 1 (handPose) · Web Audio (AudioWorklet) · AnalyserNode (FFT 2048)
Known limits
The camera path needs a secure page (https or localhost). The preview’s brightening uses a canvas filter that Safari may ignore, so Chrome is the safe choice. Two hands are tracked; a third is ignored.