Inputs#
Every input does one thing: publish signals. With createShow() you switch
inputs on in modules; each one is also a plain class you can use on its own.
The exact names and ranges are in the Signals reference.
| input | package | modules key | default | publishes |
|---|---|---|---|---|
| MIDI hardware | @openav/midi | midi | on (false turns it off) | midi/… |
| on-screen MIDI controllers | @openav/midi | midi: { controllers } | off | midi/<device>/<control> |
| on-screen piano, QWERTY, simulated performer | @openav/keys | keys | on (false removes it) | midi/note/on, midi/note/off |
| drum machine | @openav/drums | drums | off | drum/…, midi/note/on on channel 10 |
| microphone | @openav/audio | audio | off | audio/… |
| chord analysis | @openav/chord | chord | off | chord/… |
| body (camera) | @openav/pose | pose | off | pose/… |
| hands (camera) | @openav/pose | hands | off | hand/… |
| hands (Leap Motion) | @openav/leap | leap | off | leap/… |
| phones and iPads | @openav/remote | remote | off | phone/…, surface/…, midi/note/… |
Sources that need permission or a user gesture (microphone, camera) are created
by createShow() but only start when you click their button in the console's
L1 · Input panel: 🎤 mic, 🖐 hands, 🕺 body.
MIDI#
createShow() creates a Midi engine and calls enable() on startup, so the
browser may ask for MIDI permission when the page opens. Devices can be plugged
in and out during the show; the L1 · Input panel lists them, and unticking
one mutes it without unplugging it.
Every incoming message publishes two families of names:
- legacy (what most worlds use, any channel):
midi/note/onandmidi/note/offpulses,midi/cc/<n>(0..1),midi/bend(−1..1); - per channel:
midi/ch/<ch>/cc/<n>,midi/ch/<ch>/note/<n>(velocity 0..1 while held, 0 on release),midi/ch/<ch>/bend,midi/ch/<ch>/pressure,midi/ch/<ch>/poly/<n>.
A note-on payload is { note, vel, velocity, ch, device }: vel is 0..1,
velocity is the raw 1..127, ch is 1..16, device is the port's slug.
With two or more devices connected, each also publishes under its own slug
so their controls do not collide: midi/<slug>/cc/<n>, midi/<slug>/note/on,
midi/<slug>/note/off, midi/<slug>/bend. The slug comes from the port name
(Arturia MiniLab 3 → arturia-minilab-3; a second identical unit gets -2),
so a device that drops out and comes back keeps its routes. The legacy names
keep publishing too, so a route on midi/cc/74 hears every device.
Clock messages are ignored. Program change, transport and SysEx are not published (SysEx access is never requested).
Using it without createShow():
import { Midi } from '@openav/midi';
const midi = new Midi({ signals }); // options: signals, filterOut = 'IAC', requestAccess
await midi.enable(); // false if the browser has no Web MIDI or permission was denied
midi.devices(); // [{ slug, name, listening }]
midi.setListening('nanokontrol2', false);filterOut is a case-insensitive regular expression on input port names that
are ignored. The default, 'IAC', keeps the macOS IAC bus out, because a show
that sends MIDI out through IAC would otherwise hear itself. See
Troubleshooting if you
want to receive from IAC. MIDI output is described in
Show control.
Known controllers on screen#
modules: { midi: { controllers: { profile: '<profile id>' } } } adds an
on-screen picture of a known controller. Plug that controller in and the picture
switches to it and moves with your hands; without one, play the picture with a
mouse or a finger. Its controls publish midi/<device>/<control> names, and
controllerRoutes() writes the routes that connect them to params. The
MIDI controllers & embedding chapter covers profiles,
learning unknown devices, LED feedback and embedding; the supported devices are
on the controllers page.
On-screen piano, QWERTY and the simulated performer#
@openav/keys is on by default. It mounts a piano above the console with two
checkboxes, keyboard (QWERTY capture) and simulate performance. Options
(modules.keys): base (lowest note, default 48), octaves (default 2),
sim (show the simulate checkbox, default true), capture (show the keyboard
checkbox, default true).
It publishes midi/note/on { note, vel, ch: 0 } and midi/note/off
{ note, ch: 0 }. Note the differences from hardware: ch is 0 and there is
no velocity or device field. A world that only reads note and vel works
with both.
- QWERTY (after ticking keyboard):
A W S E D F T G Y H U J K O L P ;play 17 notes a semitone apart, starting atbase; Z/X move an octave (base stays between 24 and 84); Shift adds 20 to the velocity. While capture is on, the piano claims every letter key (preventDefault); Space, arrows and digits pass through to the console. - The simulated performer (
SimPlayer) plays a pentatonic scale an octave abovebase: mostly steps, sometimes leaps and triads, real rests. From code:show.keys.sim.toggle(true).
import { mountKeys, KeysPiano, SimPlayer, PIANO_KEYMAP } from '@openav/keys';
const keys = mountKeys(el, { signals, base: 48, octaves: 2 }); // → { piano, sim, update(dt), dispose() }
// call keys.update(dt) every frame (it drives the SimPlayer)Drum machine#
modules: { drums: true } adds a 16-step, four-lane sequencer (kick, snare, hat,
clap) with patterns (four on floor, breakbeat, half time, latin,
sparse), a tempo slider (60–180 BPM, default 112), swing and humanized timing.
Tick drum machine to start it. It plays its own synthesized kit (no samples)
and publishes:
drum/kick,drum/snare,drum/hat,drum/clap: pulses{ level };drum/<lane>/env: a 0..1 envelope per lane that decays in about 0.12 s, ready to map straight onto a param;midi/note/on{ note, vel, ch: 10 }with General MIDI notes (kick 36, snare 38, clap 39, closed hat 42).
The shapes match what the microphone's drum detection publishes (audio/kick,
audio/kick/env…), so a world mapped to a kick cannot tell a real bass drum from
the machine. Example 06 routes both to the same params. Options
(modules.drums): engine (another sound engine), autoEnableEngine (default
true: the kit's audio engine is switched on by the first hit, no extra click).
Microphone#
modules: { audio: true } creates an AudioAnalyzer; the microphone starts when
you click 🎤 mic. (Example 06 writes audio: 'mic'; any truthy value works.)
Echo cancellation, noise suppression and auto gain are turned off so the
analysis hears the room as it is.
Published every frame: audio/rms (smoothed loudness), audio/peak,
audio/band/low (20–250 Hz), audio/band/mid (250 Hz–2 kHz),
audio/band/high (2–8 kHz), audio/centroid (brightness), and the pulse
audio/onset { rms } with a 100 ms refractory time. Drum detection splits
transients by band: audio/kick (20–120 Hz), audio/snare (150–800 Hz),
audio/hat (6–14 kHz), each a pulse { level } with a matching …/env
envelope.
import { AudioAnalyzer } from '@openav/audio';
const audio = new AudioAnalyzer({ signals, fftSize: 2048, smooth: 0.7 });
await audio.enableMic(); // or audio.enableElement(videoEl), or someNode.connect(audio.input())
// every frame: audio.update() → also returns { rms, peak, low, mid, high, centroid, onset, kick, snare, hat }Chords#
modules: { chord: true } (or { chord: { window: 80 } }) adds a
ChordDetector and feeds it every midi/note/on and midi/note/off. It groups
notes struck within window milliseconds (default 80) into one gesture and
publishes, per gesture:
chord/consonance(−1..1),chord/count(number of notes),chord/root(lowest MIDI note);chord/event, a pulse carrying the whole analysis:
| field | meaning |
|---|---|
notes, count, root, vel, pcs | sorted notes, how many, the lowest, mean velocity (0..1), pitch classes |
consonance | mean of pairwise interval weights, −1..1 (a single note is 1) |
isConsonant, isDissonant | two or more notes and consonance > 0.25 / < −0.15 |
isTriad | the chord type is major, minor, sus2, sus4, dim or aug |
thirdsFraction | share of adjacent gaps that are 3 or 4 semitones ("genuinely stacked thirds") |
dissonanceLevel | 0 none · 1 mild (a storm warning) · 2 severe (a true cluster) |
chordType | single, major, minor, sus2, sus4, dim, aug, maj7, min7, dom7, halfdim7, maj9, min9, dom9, six, min6, cluster, or chord |
This is not a music-theory library; it is a performance-semantics layer built
for a piece where consonance makes a garden flourish and clusters make it decay
(example 02). detector.analyze(notes, vels) is a pure function you can call
yourself.
Body and hands#
modules: { pose: true } adds a PoseTracker (one body), modules: { hands: true }
a HandTracker (two hands, 21 points each, and a gesture for each). The camera starts when you click
🕺 body or 🖐 hands. Both use MediaPipe Tasks Vision (1.2.3), loaded from
jsDelivr with its model from Google's storage the first time you enable it; the
inference runs on your machine and no video leaves it. The view is mirrored by
default (mirror: true), like a mirror on stage, and y is flipped so 1 means
raised.
- Body:
pose/present,pose/hand/left/x|y,pose/hand/right/x|y(wrists),pose/hand/left/v,pose/hand/right/v(wrist speed),pose/hands/spread,pose/height(nose height: crouch ↔ stand),pose/lean(−1..1). - Hands, per side:
hand/<side>/present,hand/<side>/x|y(palm),hand/<side>/tip/x|y(index fingertip),hand/<side>/thumb/index|middle|ring|pinky(thumb tip to each fingertip, 0 = touching, 1 = wide open),hand/<side>/openness(0 = fist, 1 = all fingers out),hand/<side>/angle(0.5 = fingers up, 0.75 = pointing right),hand/<side>/speed. The first measures,hand/<side>/pinch/index|middleandhand/<side>/spread, stay as they were (an open hand reads about 0.5 on them; example 03 plays them). - A pinch, as an event:
hand/<side>/pinch-startandpinch-end(pulses, with the fingertip's x and y), andhand/<side>/pinched(0/1). Thumb and index must come closer than 0.35 hand sizes with the other three fingers out, so a fist is not a pinch; it ends above 0.56. - Gestures: MediaPipe's seven,
hand/<side>/gesture/fist|open|point|thumb-up|thumb-down|victory|iloveyou(0/1, and a…-startpulse each), andhand/<side>/gesture(0 none, 1–7 in that order). A gesture starts when its score goes above 0.5 and ends below 0.35. - Both hands:
hand/both/present,hand/both/distance(palm to palm),hand/both/x|y(the midpoint),hand/both/angle(0.5 = level).
Every distance is divided by the size of the hand and measured with x × the frame's aspect ratio,
so moving toward the camera or turning the hand sideways does not change a pinch. A closed pinch
reads near 0: use invert: true on the route when closing should raise the value (example 03).
A pulse plays a pulse param through a route, { source: 'hand/right/gesture/victory-start', target: 'turn' },
so a gesture can cue a scene the way a pad does (example 27).
The thresholds were tuned on one performer's hands at a desk, with a TouchDesigner module that uses
the same maths. MediaPipe's gesture scores reached only 0.5–0.82 there, which is why a gesture starts
at 0.5 and not at the 0.7–0.8 many demos use. Another camera, another distance, another room: open
example 27, watch the numbers and retune: createShow({ modules: { hands: { thresholds: { gestureOn: 0.6, pinchOn: 0.3 } } } }),
or show.hands.thresholds.gestureOn = 0.6 while it runs (it takes effect at once).
hands.features has the unmapped values (thumbRaw, opennessRaw, the gesture's score) to tune with.
gestures: false runs the hand landmarker alone, without gestures.
Both trackers draw their skeleton on a 2D context: tracker.skeleton(ctx, w, h).
hands.overlay(ctx, w, h, { video: true }) draws what the hand tracker measures, for tuning or for an
audience: the camera picture, the skeleton, the thumb-to-index line with its value (green while
pinched), the angle, the gesture and its score, and the line between the palms with its distance.
hands.feed(result) sends hands from anywhere (recorded landmarks, another detector, the made-up
pair in example 27) through the same measures and signals.
Leap Motion#
modules: { leap: true } adds a LeapInput. Browsers cannot read the sensor,
so one small bridge per machine does: node packages/leap/bridge/leap-bridge.mjs
(needs Ultraleap Hand Tracking installed; --mock gives two animated hands
without a sensor; bash packages/leap/bridge/install.sh keeps it running at
login on macOS). It serves ws://127.0.0.1:6437 on loopback only. The console's
L1 · Input panel shows which link is missing (bridge, tracking service,
device) and draws the hands; its simulate button turns the mouse into hands.
Signals: per side, leap/hand/<side>/present, x|y|z (palm in the interaction
box, 0..1, y up, z toward you), pinch, grab, roll|pitch|yaw (radians),
speed, fingertips leap/hand/<side>/<finger>/x|y|z; leap/hands,
leap/both/distance, leap/status; pulses pinch-start|pinch-end,
grab-start|grab-end per side and leap/both/pinch-start|pinch-end, with
hysteresis (a pinch starts above 0.86 and ends below 0.5). Joints for drawing
the hand are on leap.hands. The same bridge answers old leap.js sketches on
/v6.json, and serves raw hand lines on /raw (example 12, package README).
Phones and iPads#
modules: { remote: true } lets phones join the show over the relay that
serve.js hosts. Their sensors publish phone/<id>/… (tilt, acceleration,
rotation, knocks, touch, light), mirrored to phone/any/…; the control surface
publishes surface/<page>/<widget>; the phone's piano publishes
midi/note/on|off like a keyboard. The show page itself can read its own motion
sensors on a phone with localSensors(). Everything is in
Phones, relay & surfaces.
Your own input#
An input is anything that calls signals.set() or signals.pulse(). Here is
the pointer as an instrument:
const { signals } = show;
signals.define('pointer/x', { source: 'pointer' }); // continuous, 0..1 by default
signals.define('pointer/y', { source: 'pointer' });
signals.define('pointer/tap', { kind: 'pulse', source: 'pointer' });
addEventListener('pointermove', (e) => {
signals.set('pointer/x', e.clientX / innerWidth);
signals.set('pointer/y', 1 - e.clientY / innerHeight); // 1 = top, like every other y
});
addEventListener('pointerdown', (e) => signals.pulse('pointer/tap', { x: e.clientX, y: e.clientY }));
show.mapper.addRoute({ source: 'pointer/x', target: 'hue', smooth: 0.25 });Name it source first (breath/pressure, weather/wind), declare its range,
and everything downstream (meters, learn, routes, the phone surface) works
without changes.