open-audiovisual
Search GitHub

Documentation

Lab integration (the "lab" field)#

Chapter 22 of 24Source: docs/lab-integration.md

cheyuwu-lab runs sketches in plain <script> pages, so it builds a classic-script bundle of each OAV package it wants. Instead of a hard-coded list, the lab's generator (tools/lab-dev/build-modules.mjs) scans packages/*/package.json and builds every package that declares a "lab" field (an object, or an array when one package yields several modules). No declaration, no module.

keymeaning
moduleoutput name, runtime/modules/<module>.js (lowercase, digits, -)
kind"build" (default, bundle the code) or "declare" (only announce a module the lab implements itself)
filessource files to bundle, relative to packages/; relative imports between them are resolved, JSON imports are inlined
exportsnames exposed on window.OpenAV
wireoptional file (relative to the package dir) run inside the module scope; lab is window.lab. It plugs the package into lab.signals / lab.params
autowireone sentence on what the wiring does (goes into the lab's oav-manifest.json)
remoteTaboptional {id, label, icon, entry}: adds a tab to the phone /remote app
sinceversion or month

Rules: relative imports only, no runtime dependencies, no build step in OAV itself, and no import.meta in files or wire: the lab runs them as one classic script, where it is a SyntaxError that takes the whole module down (the nightly sync stopped on it 2026-11-21…23). A file that needs its own address stays out of files and is import()ed on demand, failing soft in the lab (midi/profiles/imported-list.js → importedUrlOf). tests/lab-declarations.test.js checks it. The generator is idempotent and has a --check mode (exit 3 = OAV has something new to regenerate).

Single source of truth: controllers and inputs live here#

Decided 2026-10-03: every controller and input module the lab uses is written in OAV and reaches the lab only by reference:

  • generated: runtime/modules/<module>.js from a "lab" declaration (header // GENERATED by tools/lab-dev/build-modules.mjs);
  • served as-is: the lab's dev server serves /remote from packages/remote/index.html and /oav/packages/* from this repo.

That covers the message format (relay/signals.js: signalMeta, fileSignal, velocity normalization), the virtual Web MIDI (midi/virtual-access.js), controller profiles and panels (packages/midi), the phone page (感測 · 琴鍵 · 控制台 · MIDI: packages/remote, packages/surface, packages/keys), phone sensors on the run page itself (localSensors, lab module motion), audio, sound, mapping and OSC (the OSC bridge is packages/osc/bridges/osc-bridge.js). To change one, change it here, test it here, push main; the lab regenerates (its nightly tools/oav-sync/sync.sh, or node tools/lab-dev/build-modules.mjs by hand) — never by editing the lab's copy.

The lab is not allowed to grow a second copy. Its gate (node tools/lab-dev/modules-gate.mjs, also a test and the first step of npm run deploy) fails when a runtime/modules/*.js lacks the GENERATED header (a short, reasoned allow-list excepted — empty today) or when runtime/modules/ has a sub-folder (hand-copied packages).

What stays in the lab is the thin host layer — code that must exist before a sketch loads or that only knows the lab's own pages: runtime/lab.js (the lab object, its relay socket, and the few lines that swap navigator.requestMIDIAccess for a lazy loader of the generated midi module), /remote's room picker (runtime/remote-room.js: which lab works are open) and its recording panel (runtime/rec-remote.js: the lab's own capture/record API), and the dev server's relay and routes. A new kind of controller or input never starts there.

↑ Back to top · All chapters