Music Painter / Developer GuideDEVELOPER GUIDE · 1.0.0

Architecture and Data

From source MIDI bytes to a verified score

Version 1.0.0 inlines the UI, worker, synthesizer and built-in scores in a single local HTML file. Playback becomes available only after the physics replay passes.

Main modules

Source FilesResponsibilities and Invariants
midi.mjs / instruments.mjsParse bounded SMF format 0 or 1 with PPQ timing. Merge program changes for each channel across tracks. Bind each note to its program at onset. Tracks, channels and programs identify parts, including parts with the same instrument.
quartet.mjs / examples.mjsGenerate the quartet, octet and older samples from note events. Built-in and imported scores use the same parser.
orchestra-score.mjs / phrase.mjsValidate seats and passages, integrate the tempo map, group simultaneous onsets and read or write versioned projects. These modules run independently of the DOM.
ensemble.mjs / sequence.mjsSearch independently for each seat, divide paths into rooms and collect collisions. The duet and the ensemble use the same result structure.
solver.mjs / physics.js / reverse.mjsReplay physics at fixed 1/120-second steps. Verify collision order, pitches, timing and whether the path is reversible. Preserve the original game wall geometry, scales, octave markings and chord rules.
orchestra.mjs / orchestra-stage.mjsHandle rehearsal state, background tasks, mixer controls, Canvas paths and the score timeline. Separate and shared views project the same data. Balls do not collide with each other.
monitor.mjs / loudness.mjs / eq.mjsRoute every live AudioContext through preamp, ten biquad EQ bands (bypassed while off), the listening volume and analysers. Measure sample peak, RMS, stereo correlation and BS.1770 loudness from K-weighted samples. Offline WAV renders skip the monitor.
hifi.mjs / hifi-draw.mjsRun the Listening Room: move the active stage into a full-screen overlay, drive its transport through a view adapter, and draw the spectrum, meters, vectorscope and EQ graph. Layout, EQ and volume are stored in localStorage.
stage-fx.mjs / duet-room.mjsDraw every stage with one renderer: night backdrop, auto-fit camera, pitch-colored glowing walls, comet trail, hit ripples, sparks and note names, the searching overlay and the solved reveal. Effects are pure functions of playback time, so pause, loop and reverse play redraw exactly.
orchestra-audio.mjs / ensemble-sound.mjs / audio.jsProvide a shared clock, per-seat audio buses and nine synthesized sounds. Playback and WAV export share routing and gain rules.

Timing and data

Internal positions count quarter-note beats from zero. The interface displays that value plus one. A passage [firstBeat,lastBeat) collects only onsets inside the interval. The app integrates the source tempo map in sections. The physics tempo rounds the opening tempo and clamps it to 60-140 BPM. Converted events retain their original times in seconds. Shared lead-in is lead=30/bpm. Total stage duration is the passage duration plus twice the lead-in.

Ensemble Flagship Edition · Offline Release01 / 03
Music Painter / Developer GuideDEVELOPER GUIDE · 1.0.0

Reliability Contracts

Verification error, the audio clock and device latency

Solving and rendering

Each seat splits into rooms at up to 16 onsets and at rests longer than 3 physics beats. The lead-in or run-out of a room is at most half a beat and cannot cross the midpoint between neighboring onsets. Difficult rooms are split further. Long rests have no simulated path. Gaps below 30 ms are checked before splitting. A worker can be canceled and times out after 30 seconds.

event.t is the target time in the score. hitTime is the measured physics collision time. The verification threshold is 12 ms. Once verified, the display calibrates path timing against the collisions and the audio scheduler uses the score times. The reported error measures collision timing. Device latency and the display refresh rate also affect what you hear and see.

State and recovery

ActionImplementation Contract
Change seats or passageInvalidate the layout, stop the worker and close old playback. Worker callbacks check their instance. File reads carry an increasing sequence number so the latest choice wins.
Play, pause or stopAll seats use AudioContext.currentTime. Schedule 180 ms ahead about every 35 ms. Suspend and resume keep scheduled held notes. Stop or leaving the page closes the context.
Live mix and offline renderA seat is audible when unmuted and either there are no solos or it is soloed. Gain changes are smoothed. Export freezes a settings snapshot, renders with OfflineAudioContext, clamps levels and interleaves stereo PCM. Random noise and plucked-string seeds can produce different WAV bytes on each export.
Save or open a projectThe format is echo-painter.ensemble with version=1. source contains name, Base64 MIDI and SHA-256. settings stores seats, first, span, master and loop. Verify the digest, reparse the MIDI and validate seat references and types before replacing the project. The digest detects corruption.

Limits

One to eight seats. A passage may last up to 128 beats or 120 seconds. Limits are 128 onsets and 512 notes per seat, 16 notes per onset and 2,048 notes total. MIDI files can be up to 8 MiB with 256 source tracks and 100,000 notes. Projects can be up to 12 MiB. Over-limit inputs return an error.

The app supplies nine local synthesized sounds. Audio separation, sample libraries, full GM controller support and cross-device latency guarantees are outside its scope. Reverse playback and links to the original game are in the single-track workspace.

Ensemble Flagship Edition · Offline Release02 / 03
Music Painter / Developer GuideDEVELOPER GUIDE · 1.0.0

Build and Verification

Reproduce a release from source

Build commands

Run these commands from the release's source directory. The development setup uses Node 24.15.0, esbuild 0.25.12, Playwright 1.62.1 and Edge on Windows. Installing the development dependencies requires a network connection. The finished app runs offline.

npm install
npm run build
npm test
npm run qa
npm run manuals
npm run release

Use npm.cmd in Windows PowerShell if needed. Printing uses local Edge. Packaging uses the Python 3 standard library. ECHO_ESBUILD and ECHO_PLAYWRIGHT can point to an existing executable and Playwright package. Both A4 PDFs print from the same English HTML guides.

Release checks

  1. Unit tests cover MIDI limits, onset groups, eight-seat timing, replay, invalid inputs, corrupt projects and PCM encoding. The quartet has 45 collisions and 77 notes. The octet has 105 collisions and 153 notes.
  2. A Listening Room check plays the quartet full screen at 1600×900, requires real M, S, I LUFS and peak readings, saves an EQ edit, hides and restores panels and returns each stage to its page. Browser checks exercise single-track forward and reverse playback, the draft editor, the duet and PCM from all nine sounds. Ensemble checks cover downloads, pause and resume, looping, stopping on hide, truly silent WAV output, reopening a project in a new context, selecting from nine tracks, narrow-screen width and zero external requests.
  3. Build, run QA and print the guides before packaging. The manifest records the SHA-256 of each file. Run python package_release.py --verify <zip-path> to check archive members and their digests. To test the extracted app, point ECHO_ARTIFACT_ROOT to the extracted root and run node orchestra-check.cjs.
  4. The localized duet recovery page is in source/recovery. Download Source MIDI gives you the original bytes of the open score. Keep version 1 project read and write coverage when adding project versions, and preserve user files.

Standards referenced — MIDI Association General MIDI Level 1 and Standard MIDI Files. W3C Web Audio API AudioContext and OfflineAudioContext.