Skip to content

Latest commit

 

History

History
345 lines (281 loc) · 68.4 KB

cpp-port.md

File metadata and controls

345 lines (281 loc) · 68.4 KB

Porting XMP's core and the Live interface to C++

Decided by the owner on 2026-11-12: XMP's core moves to C++, shared by the browser (as WebAssembly) and the MPC Live (native), and the Live gets a full XMP interface on its own screen. The browser's interface stays in TypeScript (HTML and DOM).

Why

  • One implementation of the project model, sequencing and sound for both, so the Live plays the same projects the browser makes.
  • Speed where it matters: the sound engine is about 3.5× faster in C++ and the performance window about 5.8×. Editing and loading projects are not time-critical; in the browser the gain there is consistency, not speed.

Rules for the C++

  • Headers in native/include/xmp/: each port has a parity test against the TypeScript it replaces, kept as a reference until the port has been in use for a while.
  • One toolchain: the same headers build with the pinned Zig for WebAssembly and with the system or ARM compiler natively. The WebAssembly build has the C library only, no C++ standard library, so the core uses XMP's own small containers (base.hpp) and JSON (json.hpp) instead of std::.
  • Real-time code (anything the audio thread calls) never allocates, locks or does I/O. The project model may allocate; it is never touched by the audio thread.
  • Bounded input: every project and module input keeps the limits the TypeScript schemas enforce, with the same accept and reject decisions and the same messages for XMP's own checks.

Phases

# Phase State
0 Engine, sequencer, transport, performance controls, parameter values done (see engine.md)
0 The Live plays through the engine (live_engine.hpp) done
1 Base library: containers, strings, bounded JSON reader and writer with JavaScript's number formatting (base.hpp, json.hpp) done
2 Project model: validation of every version (1 to 7), migration to 7, canonical JSON (project.hpp, project_schema.hpp) done; typed view with phase 3
3 Editing and the typed view (project_edit.hpp); parameter edits move to phase 4 done
4 Machines and the parameter registry (machines.hpp, parameters.hpp); SDK machines: definitions only done
5 Sequencer, transport and controls reading the C++ project (play.hpp, performance.hpp) done
6 Rendering and exchange (files.hpp, voices.hpp, render.hpp); recording takes stay in the browser for now done
7 The Live session opens full XMP projects from the stick and plays them (portable.hpp, live_player.hpp) done
8 The Live interface in C++, a ground-up clip-first design (live-ux.md): Clips, Play, Steps, Song, Sample and Mix views, hardware first (live_ui.hpp) done: every view, per-track kits (format 7)
9 Retire the TypeScript references and move the browser's remaining callers to the C++ core done for the engine originals; see part 6 notes

Each phase ends with its parity tests, the native tests, the full browser suites and, for phases 7 and 8, the Live emulator.

Phase 1 notes (2026-11-12)

  • base.hpp: Vec and Str on malloc, with their own placement new and move (the WebAssembly toolchain has no C++ headers at all).
  • json.hpp: reading and writing as JSON.parse and JSON.stringify do: key order (array-index keys first), shortest number text, escapes, lone surrogates (kept as WTF-8).
  • tests/parity/json-parity.test.ts compares it with JavaScript on 3,000 random documents (compact and indented), 20,000 random numbers (including random bit patterns, subnormals and the extremes) and 38 malformed or edge-case inputs. Output is byte-identical and the accept and reject decisions match. It also builds for WebAssembly (about 59 KB with printf and strtod) and gives the same output there.
  • Found by the test: Node 24's JSON.parse can return the wrong name for a property whose name is a lone surrogate, after it has parsed other documents (a V8 key-cache bug). The C++ is correct. The test keeps such keys out of the comparison.

Phase 2 notes (2026-11-13)

  • What it does: project::open(text) does what the TypeScript's parseProject and openProject do:

    • the import preflight;
    • the JSON;
    • the schemas of versions 1 to 6;
    • every check of XMP's own (references, budgets, sequences, performance, mix, effects, machine state bounds, the built-in machines' states);
    • migration to version 6.

    The result is the canonical version 6 document. Its JSON.stringify is byte-identical to the TypeScript's.

  • The schemas are built from a small checker (project_schema.hpp) with zod 4's semantics:

    • strict objects;
    • the schema's key order, with extended fields keeping their place;
    • safe integers and finite numbers;
    • records that drop __proto__, as zod does;
    • string lengths in code points. Zod 4 counts a surrogate pair once, unlike JavaScript's .length.
  • Decisions are identical. Messages from the preflight, the version check and XMP's own checks use the TypeScript's words. For structural problems the C++ names the first problem (for example project.tracks[5].name: text out of bounds or malformed), where zod lists every issue as JSON.

  • Checks:

    • tests/parity/project-parity.test.ts runs 240 random rich projects (40 in each of versions 1 to 6) and 3,000 random mutations of them (missing and extra keys, wrong types, values at and beyond every limit, broken references, duplicates, real __proto__ keys), plus the preflight and version rules.
    • Five deliberate faults in the C++ each fail it: a dropped check, a name limit off by one, two keys swapped, a wrong migration default, and keeping __proto__.
    • native/tests/project_test.cpp builds it natively with strict warnings.
    • It builds for WebAssembly (176 KB, with -fno-threadsafe-statics) and opens the demo project identically there.
  • Not yet:

    • The browser still opens projects with the TypeScript. Switching it would change the structural messages users see, so it waits for phase 9.
    • The typed C++ view of a project (structs for tracks, clips and so on) comes with phase 3, which edits it.
    • Opening the 11 MB demo projects takes about 0.4 s each natively. Number parsing and formatting and the generic value tree can be made faster.

Phase 3 notes (2026-11-13)

  • Edits ported (project_edit.hpp), each the C++ twin of a TypeScript function:
    • toggleStep and expandSong;
    • the sequence edits (editSequence, appendNotes, quantizeNotes, resizeClip, duplicateClip);
    • the performance (editPerformance, editChain, deleteTrack);
    • editMix and setMidiDestination;
    • samples (manualSlices, installSample) and drum kits (applyDrumKit, with its kit checks).
  • The rule: like the TypeScript, every edit except toggleStep checks the whole project again (phase 2's canonical), so an edit can't leave a project the browser would refuse. The generic edits (edit_sequence, edit_performance, edit_mix) take a C++ function that changes the document, as the TypeScript ones take a callback.
  • Text cuts (name.slice(0, 30)) are in UTF-16 units, as in JavaScript. Cutting a surrogate pair keeps its high surrogate alone, as JavaScript does.
  • The typed view (edit::view::Project, Track, Clip, Step, Scene) reads the document in place, so the document stays the single source and its canonical order is never lost.
  • Checks:
    • tests/parity/project-edit-parity.test.ts applies 24 random sequences of 60 edits to random projects, mostly well-formed and sometimes aimed at missing targets or invalid values. After every edit both implementations succeed or fail together and produce byte-identical projects. The TypeScript's own messages (not zod's) are identical. Every edit is exercised both ways (expandSong can't fail on a valid project).
    • Six deliberate faults each fail it: a default velocity, the copy-name cut, a missed scene clean-up, the quantize rounding, a track name and a choke default. The first version of the test missed two of them, until the generator had long clip names and mostly valid notes.
    • native/tests/project_edit_test.cpp builds natively.
    • In WebAssembly (214 KB) a chain of five edits gives the same project as the TypeScript.
  • Moved to phase 4: setParameter and clearParameterSource need the parameter registry and the machine definitions.
  • Edits in the browser's interface: some edits are written inside the interface code (apps/studio) on a cloned project. The Live interface (phase 8) will use the C++ edits above and add its own where needed.

Phase 4 notes (2026-11-13)

  • Machines (machines.hpp):
    • the registry of machines.ts, with the pad sampler, the subtractive synth and the MIDI track;
    • their automatable parameters, defaults and state checks;
    • get, which returns a machine only for its own version and base (an absent machine is the pad sampler);
    • instantiate.
  • SDK machines are JavaScript. Their definitions can be added (machines().add) so the registry lists their parameters as the browser does, but their own state checks run only in JavaScript. On the Live there are none yet.
  • Parameters (parameters.hpp):
    • parameterRegistry: master, the mix's pan, sends and effect parameters, track gains and machine parameters, in the TypeScript's order with the same names, defaults and steps;
    • parameterSources, resolveParameter, parameterValue and machineParameter;
    • setParameter, which snaps discrete machine parameters (MIDI channel) to their step and mirrors a base into the master gain, the track volume or the machine state, and clearParameterSource;
    • smoothParameter, parameterSmoothingMs and advanceParameter.
  • Checks:
    • tests/parity/parameters-parity.test.ts runs 20 random projects, some with an SDK-style machine, and over 5,000 queries and edits: the registry, sources, values, machine parameters, instantiate, smoothing and random parameter edits. Everything is identical (the TypeScript's own messages included), except smoothing, where the C library's exp may differ from JavaScript's in the last bit (within 1e-12).
    • Six deliberate faults each fail it. The discrete-step rounding was caught only after edits were biased toward machine parameters.
    • native/tests/parameters_test.cpp builds natively.
    • In WebAssembly (228 KB), the registry, every value and an edit match the demo project.
  • Not yet: the browser, and the C++ sequencer's binding, still build the registry in TypeScript. Phase 5 has the C++ sequencer, transport and controls read the C++ project directly.

Phase 5 notes (2026-11-13)

  • The sequencer on the C++ project (play.hpp): the layout the TypeScript binding built (UTF-16 IDs, tracks, step and sequence notes, parameter sources, lanes, locks and modulation), now built from the document. On top of it: notesInWindow, timeline, eventsAtStep, parameterFrame, and the parameter table the performance window uses.

  • The performance on the C++ project (performance.hpp):

    • Performance, the C++ PerformanceTransport: scene and song mode, launches, clip changes, stop, live mute, solo and macro overrides, project and chain edits while playing, snapshots and releases;
    • performance_controls, performance_values (the evaluator) and performance_window.

    Everything a player needs to step through a project, with no TypeScript.

  • One behaviour change: in the TypeScript too, simultaneous notes in a performance window are now ordered by plain code-unit ID instead of localeCompare, as the sequencer already orders them. Locale collation can't be reproduced outside a JavaScript runtime.

  • Checks:

    • tests/parity/play-parity.test.ts runs 24 random projects and about 4,000 queries (over 5,000 notes). Answers are byte-identical, except an LFO's sin in parameter frames (within 1e-12, as the sequencer parity test allows).
    • tests/parity/performance-play-parity.test.ts runs 16 random performances with MIDI routing, solos, macros, events, tempo maps, live controls, chain edits and clock jumps: about 2,500 operations, mostly window steps.
    • Eight deliberate faults each fail one of them (note pitch, note IDs, MIDI routing, window positions, tie order, song position, silenced gains, the silence check). Two were caught only after the generator added MIDI routing and long clock jumps.
    • native/tests/performance_test.cpp builds natively.
    • In WebAssembly (353 KB, with a 1 MB stack), 32 windows of the demo project match the TypeScript exactly.
  • Next (phase 6): rendering and exchange. The browser still calls the TypeScript versions; phase 9 moves it.

Phase 6 notes (2026-11-13)

  • Files (files.hpp):
    • WAV: encoding 16-bit mono or stereo; decoding PCM16/24/32 and float32, mono or stereo, mixed to mono, with every check of decodeSampleWav;
    • Standard MIDI Files: encodeMidi and decodeMidi, including running status, velocity-0 note-offs, ignored events and the tempo map;
    • exchangePlan (the MIDI of a scene or a finite song, played through the performance) and importMidiClip.
  • The engine from a project (voices.hpp): prepareInstruments and editedPcm, and the VoiceRack binding: tracks, pads, synth patches, routes, the mixer and its effects, parameter indices, and checked commands. SDK machines (JavaScript) are silent here.
  • Renders (render.hpp): renderPerformance, renderSequence, renderInstrumentScene, the original pad-sampler renderer (prepareScene with renderPlan), renderProjectScene and renderExchange.
  • Two TypeScript fixes found by the port:
    • renderSequence sorted with an inconsistent comparator (two notes on one frame each sorted after the other), so the order depended on V8's sort. It now orders parameter changes before notes at the same frame, and otherwise keeps timeline order.
    • The JSON writer missed a rare case (decimal ties such as 2⁻²⁴, which JavaScript writes as 5.960464477539063e-8). The JSON test now includes powers of two and dyadic fractions.
  • Checks:
    • tests/parity/files-parity.test.ts runs 400 WAV encodes, 400 decodes of random layouts (including invalid and damaged ones), and hand-made and damaged MIDI files. It also builds export plans in scene and song mode and imports clips. Bytes, documents, projects and messages are identical.
    • tests/parity/render-parity.test.ts runs every renderer on random projects: performances in scene and song mode, sequences, instrument scenes, the pad-sampler renderer, whole-scene WAVs and MIDI-with-audio exports. Audio matches within 1e-5 (16-bit WAVs within one step). Note traces, transitions, MIDI events and files, snapshots and WAV headers are identical.
    • Six faults in the file code each fail the tests, and six of eight in the renders. The other two can't change the output: a mix strip's default pan (the parameter's base value always overrides it) and the order of gates and parameters at the same frame (they don't interact). Three faults were caught only after the tests gained hand-made MIDI files without a tempo, automation points between quarter steps, and an instrument render with a tail.
    • native/tests/render_test.cpp builds natively.
  • Not yet: recording takes (TakeRecorder, the input path) waits for the owner's decision on the Live's audio inputs (live-ux.md).

Phase 7 notes (2026-11-13)

  • Opening the browser's files (portable.hpp): importPortable in C++.
    • It opens plain projects, version 1 bundles (project.xmp.json) and version 2 songs (.xmpsong, with packaged float32 or float64 audio in base64 chunks).
    • It verifies SHA-256 as the browser does: each sample's hash, and the song's canonical project hash.
    • A song saved without its samples is refused, with the browser's message naming the missing samples (the Live has no sample library yet).
  • Playing in real time (live_player.hpp):
    • ProjectPlayer (main thread) steps the performance 100 ms ahead of the audio clock and turns each window into numeric commands.
    • ProjectSound (audio thread) applies them on their exact frames through the engine's allocation-free calls.
    • Stop cancels everything already scheduled and releases every voice; effect tails decay, as in the browser.
  • In the session (live_session.cpp):
    • With xmp/project.xmpsong or xmp/project.xmp.json on the stick, the session opens it at start-up and prepares its sound before the audio thread starts.
    • Play and Stop play the project's song (when it has a chain) or its first scene.
    • The project mixes with the session's own sound, so the pads still play the kit over it.
    • The Live interface (phase 8) replaces this minimal control.
  • Checks:
    • tests/parity/portable-parity.test.ts opens 240 files, intact and damaged: altered audio, hashes, base64 and versions, extra keys, renamed samples, foreign assets. Projects, refusals and XMP's own messages match the TypeScript's. Four deliberate faults each fail it.
    • native/tests/live_player_test.cpp plays a song from the top, the same song resumed from its saved position, and a scene through the real-time player, in 256-frame blocks. The output is identical, sample for sample, to render_performance offline. Stop cancels a queued note and releases every voice. Three of four deliberate faults fail it; the fourth only shortens the render blocks, which can't change the output. The clock fault was caught only once a resumed song was tested.
    • The session image builds with the Live's ARM compiler (-Werror). The emulator's new project run opens the browser's demo song from the stick, plays it with Play and stops it with Stop, with no xruns or dropped commands, sound on outputs 1–2 only, and within −12 dBFS. Nothing else in the emulator regressed.
  • Not yet:
    • choosing among several projects on the stick (phase 8's Browse);
    • saving the project back;
    • MIDI out from MIDI tracks (authorization 5);
    • a song saved without its samples (it needs a sample library on the stick).

Phase 8 notes, part 1 (2026-11-13)

  • The button map is complete. The codes from the owner's session 4 match, code for code, the MPC button numbers the open MPC mapper publishes (references/repos/mpc-livexplore-libs/src/tkgl_midimapper.h). So every printed label now has its code: Shift 31, Menu 7B, Main 34, Undo 43, Copy 7A, + 36, – 37, Tap Tempo 35, Note Repeat 0B, Full Level 27, 16 Level 28, Erase 09, and the transport row. They are recorded in os/live-mk1/hardware.json (controller.map.labels). Only the data wheel's press (6F) has not been pressed in a session yet.
  • The interface (live_ui.hpp) is pure: the session passes in controller events and what the player is doing, and gets back actions. It draws to a Canvas, which on the Mac is a memory buffer. native/tools/live_ui_preview.cpp draws a project's screen to an image.
    • Clips (home): the eight tracks by up to sixteen scenes, and on the pads a 4×4 window of it (the selected track's four tracks by four scenes, the first at the top). Playing clips are emerald with a progress bar; a launch waiting for the bar blinks gold, a track about to stop blinks ruby.
    • Play: the pads play the selected track. A kit plays its 16 pads; a synth plays notes from C3, with – and + changing the octave. Full Level fixes the velocity.
    • Menu: hold it and press a pad to choose a view (the top row: Clips, Play, Steps, Song; the next: Sample, Mix). A tap returns to the previous view. Views not built yet say so in the header.
  • Behaviour decided while building (open to the owner's changes):
    • A clip pad while stopped plays that clip alone (the performance's selection). While playing it launches on the next bar; pressing the clip that plays stops its track at the bar, and so does an empty slot.
    • Play plays the song when the project has a scene chain, otherwise the selected scene. Play Start plays the selected scene. Stop stops; Stop while stopped silences every voice.
    • The data wheel moves the selected scene; its press launches that scene.
  • The player gained launches (launch_clip, launch_scene, on the next bar), audible_step (the step being heard, from the frames the steps were scheduled on), and live notes from the pads (ProjectSound::play_live and release_live, a new note_off command). The performance reports waiting launches (queued, queued_scene).
  • In the session: with a project on the stick, the interface takes over the pads, buttons, data wheel, touchscreen and screen; the header keeps the five status lights, including the bridge light authorization 3 requires. Without a project the pattern screen works as before.
  • Checks:
    • native/tests/live_ui_test.cpp: the board read from a project, the button map, every Clips and Play action, launches and live notes through the real player, and the drawing on a memory canvas. Ten deliberate faults all fail it.
    • The emulator's project run now opens Night Shift and plays it with the controls (see PROJECT_SCRIPT in tools/live-mk1/session-vm.mjs), and checks the screen.

Phase 8 notes, part 2 (2026-11-13)

  • Steps (16 Level, or Menu + pad 15): the pads are sixteen steps of the selected clip, steps 1–4 on the top row, for one kit pad or one synth note. A pad turns its step on or off; Shift + pad chooses the pad or note to edit (the last one played in the Play view is chosen too); Erase + pad clears that pad's or note's steps. The data wheel pages through a 32- or 64-step clip. The step being heard is ringed in emerald.
  • Edits (live_edit.hpp) change one clip of the open project in place. The browser's toggleStep copies the whole project, and a project's samples are megabytes of numbers, too slow to copy for every press on the Live. The results match the browser's: a kit step as toggleStep makes it (velocity 0.8, probability 1); a synth step with its own note, on a pad number free at that step, so a chord keeps the one-pad-per-step rule. Turning a synth note off also removes a sequence note of that pitch starting on that step.
  • Undo and redo (Undo, Shift + Undo): each edit keeps the clip as it was, 64 deep.
  • While playing, the player takes the edited clip from its next window (ProjectPlayer::replace_clip, Performance::replace_clip); the clip's id and length must not change, so the transport's tables still hold.
  • Saving: two seconds after the last edit, once the music has stopped, the project is written to the stick as xmp/project.xmpsong (and at the end of the session), in the browser's own song format: portable::save_song is the C++ port of exportSong, byte for byte (tests/parity/portable-parity.test.ts), with the audio as base64 float32 chunks. It takes 37 ms on the Mac for Night Shift; the first version wrote every sample as a JSON number (project.xmp.json, 5 MB), which took 2.6 s on the Mac and about 94 s in the emulator, where it stalled the controls for seconds at a time. A low-priority thread still makes the file from a copy, so the controls and screen never wait. The first save of a session keeps the song it replaces as project.previous.xmpsong. When both project.xmpsong and project.xmp.json are on the stick, the newer opens.
  • Checks:
    • native/tests/live_ui_test.cpp now also covers the Steps view, every edit, undo and redo (and their bound), the edited project reopening, an edit made while playing (the sound is unchanged before the edited step and changes from it), and the Steps drawing. Of twelve deliberate faults, eleven fail it; the twelfth skips the player's own copy of the clip, which it never reads for notes (the performance's copy is the one played), so it can't change the output.
    • The emulator's project run edits a step of Night Shift's bass in the Steps view, undoes and redoes it, and checks that the saved project.xmpsong opens in the browser's core with the step.
    • Emulator result (run session-vm-yXFdjN): every interface check passes (Play, Stop, a clip alone, a launch at the bar, Shift + Main, the wheel's scene launch, the step edit, undo, redo, the save, and the saved file reopening with the edit), with sound on outputs 1–2 only, under −12 dBFS, and no dropped commands. Two checks fail:
      • screenShowsClips: the emulator's screenshot is QEMU's 640×480 default display, not the Live's framebuffer, so every screen check in every run fails the same way (it did before phase 8 too). The screen is checked by the native drawing tests and live_ui_preview instead.
      • noXruns: 7 xruns, none while music played (the captured audio has no gaps). They fall in the silent stretch while the 5 MB project was saved (84 s under the emulator), most likely because QEMU runs all four emulated cores on one host thread, so the saving thread takes time from the audio core; on the Live the audio core is a separate, isolated core. The session now logs each xrun with whether it was playing or saving, so a real session will show where any happen.

Phase 8 notes, part 3 (2026-11-14)

  • Rec records a take into the selected empty slot of a kit or synth track, and opens the Play view so the pads play that track. Stopped, it starts the slot's scene and its first bar counts in; playing, the take starts on the next bar. A hit up to half a step before the take is its first step. Rec again ends the take: its clip is one, two or four bars (16, 32 or 64 steps), pressing up to half a step late doesn't add a bar, and a take ends by itself after four bars. Stop ends it too. The new clip ("Take N", an id no clip in the project has) goes into the slot and plays from the next bar.
  • Overdub records onto the clip the selected track plays: each hit lands where it was played in the loop, a kit hit at once, a synth note when it is let go (with its length). Overdub again, or the clip stopping, ends it.
  • Quantizing: hits go to the nearest step; one just before the end lands on step 1. A kit hit on a step its pad already has keeps the louder velocity; a synth note of a pitch already on that step plays once. Synth notes keep their length in quarter steps (at least a quarter).
  • Undo takes back a whole take (the clip and the slot), and an overdub pass from its first hit. A take or its undo changes the project's clips and scenes, so the player takes the whole project (ProjectPlayer::set_project) and keeps playing where it is.
  • The player keeps a lean copy: the project without its samples' audio, which playback never reads (only ProjectSound and the offline renders do). Starting to play, a take and an undo copy kilobytes instead of megabytes. Playback is still identical to the offline render, sample for sample.
  • Checks: native/tests/live_ui_test.cpp adds take lengths, quantizing, new clips and their undo, the whole Rec and Overdub flow (count-in, early hits, held notes, the late press, the four-bar limit, Stop, a press on the bar line, an overdub hit before its clip's start), the player taking a take while playing, and the REC display. Seventeen deliberate faults all fail it. The emulator's project run records a one-bar take on Night Shift's lead from stopped, overdubs a note onto it and checks the saved project.
  • Emulator (2026-11-14): every Rec check passed except overdubbed. The save of the Steps edit was still writing (the 94 s noted under part 2) and stalled the controls for seconds, so Rec was handled 2.3 s late and the take had not started when Overdub was pressed. Saving now writes the song format (see part 2's saving note), which takes milliseconds.

Phase 8 notes, part 4 (2026-11-14)

  • The Q-Link knobs (B0 10–13, relative like the data wheel; touch notes 54–57). In the Steps view they edit the selected step, the last step pad pressed, for the pad or note being edited: velocity and chance (the step's probability) in 1% clicks, a synth note's length in quarter steps (a kit has none), and Move, which takes the step one step later or earlier per four clicks, wrapping round the clip (a synth note takes a free pad on its new step; a step won't land where its pad or note already is). Steps have no timing offset in project format 6, so Move works in whole steps. In every other view, and in Steps after the Q-Link button, they are the selected track's level, pan and sends 1 and 2, in 1% clicks. A track gets a mixer strip when one is first turned, and a parameter assignment that mirrors the value keeps its base equal to it, as in the browser.
  • On screen: touching or turning a knob shows its name and value in the header, large, while it is touched and for a second and a half after. The selected step has a gold outline.
  • Undo: one turn of one knob on one thing is one change. A level, pan or send change keeps the track, its strip and the parameter assignments; undo puts them back, including removing a strip the knob made.
  • While playing: a step edit reaches the player as the clip (replace_clip). Level, pan and sends reach it with the whole lean project (set_project), at most every 40 ms while a knob turns, and are heard from the next window, up to 100 ms later.
  • Checks: native/tests/live_ui_test.cpp adds the knob actions (a step first, one change per turn, Move's four clicks, Q-Link, touch and its display), each step and track edit with its limits and undo, the edited project still opening, and a level turned to 0% silencing a playing synth from the next window. Twenty-two deliberate faults all fail it. The emulator's project run turns the lead's level and pan and checks the saved project.
  • Emulator (2026-11-14, session-vm-W89IDi): every interface check passed: Play, Stop, launches, Steps, undo and redo, saving, Rec, Overdub, the take and the knobs in the saved project. A save took 0.9 s under the emulator. Still failing as before: the screen checks (QEMU's 640×480 display), the start-up and identity checks, the bridge checks, and noXruns: 72 xruns while playing, 38 of them before the first save or knob turn, against 5 and 12 in the same stretch of the two runs before. The pads and sequencer sessions had none, and the tracks session hit the known missing-audio-card flake. Nothing new runs in that stretch, so it looks like emulator timing; a session on the Live will show.
  • Next: Song, Mix, then Sample and per-track kits (project format 7). A metronome for the count-in is in future.md.

Phase 8 notes, part 5: the Song view (2026-11-14)

  • Song (Menu + pad 16) shows the performance's scene chain. Its pads are the scenes (1–4 on the top row): a pad adds its scene after the selected block (song-N, one repeat). The data wheel selects a block; its press, or Play, plays the song from that block (the song's position set to the block's start, in a lean copy, started with resume); Play Start plays from the top; Erase + wheel press removes the block. A touch selects a block.
  • Knobs: repeats (1–16, three clicks a repeat), Move (the block earlier or later, four clicks a place; the selection follows), End (stop or loop) and Scene (the block's scene, wrapping). One turn is one change for undo; the clicks a turn saves up carry on until another knob or another thing is turned (the first version lost them when the value was not on screen, so a slow turn changed nothing).
  • Undo covers every song edit (the performance is kept whole). A song edit forgets where the song was stopped, since that position may name a block that moved or went.
  • While playing, a song edit reaches the player with the lean project (set_project); the playing block is marked from the performance's current occurrence (Performance::occurrence).
  • Checks: live_ui_test adds the Song controls, the chain edits and their limits, undo, a valid project after editing, playing from a block, and removing the playing block while it plays; 22 deliberate faults all fail it. The emulator's project run (session-vm-PnZWht) adds Drop as block 2 of Night Shift's song, gives it two repeats, plays from it and checks the saved song: every Song check passed.

Phase 8 notes, part 6: the web Device view's look (2026-11-14)

  • The owner asked for the Live's screen to look like the web Device view (apps/studio/src/device), which lays its screen out at the Live's own 1280×800. The Live now draws the same layout with the same CSS sizes and colours: a 72 px header (back arrow, the project's name over the page's name with the selected track in gold, the status lights, the position and tempo in a monospaced gold, the state), the page, a 58 px status line (a message, else what the controls do) and a 94 px Q-Link strip that always shows the four knobs' names and current values (the one turned last is lit).
  • Pages: Clips is the web's 4×4 of cards for the four tracks and four scenes the pads stand for (caption "PAD 13 · Intro", the clip's name in bold, "4 beats · 14 notes"; filled cards in the emerald gradient, empty slots dashed, the focused one ringed in gold, a playing clip with its progress, launches blinking). Play is the web's sound matrix, Steps its eight-column gold step buttons, Song its chain list, and the page menu its card grid.
  • Text: Inter for the interface and JetBrains Mono for the gold numbers (the web asks for Inter, and draws numbers in the system's monospace font), both under the SIL Open Font Licence, approved by the owner on 2026-11-14. tools/fonts.mjs downloads them once into references/archives/fonts (git-ignored), refuses them unless their SHA-256 matches, and turns them into antialiased glyphs at the CSS's sizes and weights with stb_truetype (public domain or MIT, also pinned), with every kerning pair from the fonts' GPOS tables (stb_truetype misses the extension lookups Inter keeps its letter pairs in). The atlas (build/fonts/xmp_font_atlas.hpp, about 340 KB of coverage) is compiled into the session; nothing is committed, and the Live never parses a font. The two licences go into the session image at /usr/share/xmp/fonts.
  • Drawing (live_text.hpp): an off-screen 1280×800 picture with antialiased text, rounded boxes with borders and vertical gradients, rings and dashed borders. The interface still repaints only regions whose contents changed, and only those regions are copied to the framebuffer.
  • Checks: live_ui_test samples the drawing where the CSS fixes the colour exactly (a card's gradient, the gold focus ring, a dashed border's gap, the header's gold line, the step buttons' gold, the playhead's ring, the strip), and checks the text layer (sizes, the monospaced face, kerning, ellipsis, UTF-8) and the strip's values in each mode. Nineteen deliberate faults in the drawing all fail it. live_ui_preview draws any project as the Live would show it. The emulator's project run with the new drawing (session-vm-ONZv6D) passed every interface check; as before, only the screen checks (QEMU's 640×480 display) and noXruns (29, in the project session) failed, and the sequencer session lost its audio card (the known QEMU flake).
  • On the Live (owner, 2026-11-14): "looks sick". The owner's session (session-014) ran the new screen on the Live itself with no xruns, and every touch (Edit focused clip, the back arrow, clip launches) reached the interface.

Phase 8 notes, part 7: the Mix view (2026-11-14)

  • Mix (Menu + pad 10) shows eight channel strips in the web view's style: each track's level as a bar and a number, its pan and two sends, and mute (M, ruby when on) and solo (S, gold) buttons; the selected track is ringed in gold, and a track a solo silences is dimmed.
  • Pads: the top two rows select tracks 1–4 and 5–8; the two rows below mute them; Shift + one of those solos. Touching M or S does the same, and touching a strip selects it. The knobs are the selected track's level, pan and sends (part 4).
  • Mute and solo are the performance's saved mutes and solos, so they play and save with the project: a track is muted by its own muted or a saved mute, and unmuting clears both. Undo takes back each press (the track, its mixer strip, its parameter mirrors and the performance are kept together). While playing, the player takes the change with the lean project and it is heard from the next window.
  • Checks: live_ui_test adds the Mix pads, touch, the drawing of mute, solo, the selection and the level bar, the edits and their undo (including a track's own mute), a valid project after editing, and a muted synth (and a solo of the drums) going quiet while playing. Sixteen deliberate faults all fail it. The emulator's project run mutes Night Shift's drums and solos its bass and checks the saved project.
  • Next: Sample, with per-track kits (project format 7).

Phase 8 notes, part 8: the piano roll, and buttons for navigation (2026-11-14)

  • The owner asked for fewer navigation buttons on screen, using the Live's own buttons instead, and for a melodic clip editor for synth and MIDI tracks alongside the drum step editor.
  • Navigation: the header's back arrow and the Clips page's "Edit focused clip" button are gone; Main, Shift + Main, 16 Level and Menu move between pages, and the status line says which does what. Touch stays for what is on the page: clips, pads, steps, notes, song blocks, track strips, mute and solo.
  • The piano roll: Steps on a synth or MIDI track shows twelve pitches by the page's sixteen steps, with the note names at the left (C rows, the edited row and the edges labelled; black keys darker). Each note is a gold bar as long as it lasts, brighter the harder it plays (the browser's sequence notes with a gold rather than a bright edge); the note being edited has its row lit, the selected note an ivory ring, the playhead an emerald line, and notes above or below the view are counted ("▲ 2 higher").
  • Editing: the pads are the edited note's sixteen steps, as before; − and + move the edited note a semitone (Shift: an octave) and the roll follows it (one row at a time, or centring after a jump); touching the roll turns that pitch on or off on that step and selects it, so the knobs (velocity, chance, length, move) edit it. The wheel pages through 16, 32 or 64 steps.
  • MIDI tracks are edited by pitch like synths, each entry with its own note. An entry without one plays its pad's root note (play.hpp's rule for MIDI), not a synth's 48 + pad: the edits now keep "edited by pitch" (synth or MIDI) apart from that default.
  • Checks: live_ui_test adds the roll's notes (step entries, sequence notes and their lengths), MIDI clips and their default note, pitch navigation and how the roll follows it, touch on the roll, MIDI pads in Steps, and the roll's drawing (a note's bar, the lit row, the selected note's ring, the playhead); fifteen deliberate faults all fail it. The emulator's project run opens the roll on Night Shift's bass in Groove, raises the note and adds one on step 1, and checks the saved project.

Phase 8 notes, part 9: a kit of its own for each track, project format 7 (2026-11-14)

  • The format: a track may hold its own 16 pads (track.pads, the same pad shape as the project's). Tracks without one play the project's pads, as every track did before, so versions 1 to 6 migrate by changing nothing but the version: every older project opens and sounds the same. The samples stay one pool shared by every kit, now up to 128 samples (bundles and song files too), still within the one-million-frame budget. The checks of a kit: 16 pads, unique ids, samples that exist, slices inside them.
  • Both cores, in step: the TypeScript and the C++ read a track's pads wherever a pad's root note, mode or sound is needed (sequencing, MIDI export, renders), and the sample edits (install, slices, recording plans, drum kits) take an optional track and edit its kit. New edits ownKit (a copy of the pads the track plays, sharing their samples) and shareKit (back to the project's pads, dropping samples nothing plays). The engine's rack holds the project's pads and each kit (144 slots) with a pad base per track; a MIDI track routed to a kit plays that kit's pads.
  • The browser: the Device view's Track page gives a track its own kit or returns it to the shared one; sounds and kits loaded go to the selected track's kit when it has one. Advanced Studio's pads, sample tools and drum kit panel follow the selected track.
  • The Live: its player needed no change (it plays through the same engine). The interface keeps pad names and root notes per track.
  • Checks: the project, edit, render and playback parity suites run on fixtures where some tracks have kits and sounds of their own; tests/kits.test.ts checks migration, own kits, edits that leave other kits alone, a MIDI track routed into a kit, and refused kits; the Live's interface test checks per-track pads. The own-kit switch was tried in the browser's Device view.

Phase 8 notes, part 10: the Sample view (2026-11-14)

  • Sample (Menu + pad 9) records from the Live's inputs under AGENTS.md authorization 7: the "MPC Live Audio" card the session already plays through (the same identity rules), opened for capture only between REC and the end of the take, and only while the music is stopped. A capture thread copies the input, mixed to mono, into a ring allocated before it starts; the main thread feeds a recorder (live_sample.hpp) that waits for the first sound (about −34 dBFS, keeping 10 ms from before it) and stops at ten seconds, a project sample's limit. The take is trimmed (5 ms around the sound) and normalized, and stays in memory; it reaches the stick only inside the project when kept.
  • Editing: the knobs are start, end, tune and level, and with Shift fade in, fade out, reverse and slices (− and + set the slices too). The pads choose the pad it goes to and play the edited take (an audition mixed into the output at −12 dB, through the limiter). The wheel keeps it: on the selected kit track's pad, or sliced across that many pads. A track that plays the shared kit gets its own first, so no other track's sounds change, and one Undo takes everything back (the history keeps the whole project, which costs little since documents share their unchanged parts). Erase + wheel forgets the take.
  • Screen: the destination and the take's state in the toolbar, an input meter, the waveform with what is kept bright, the start and end in gold and the slices between, and the edits in words; the Q-Link strip shows the knobs' current values (SAMPLE, or SAMPLE + with Shift).
  • Also fixed: the Live's 32-bit ARM build had broken with phase 9 part 2: the number reader multiplied with a 128-bit integer type the ARM compiler lacks. It now uses a portable 64×64 multiply where there is none (checked against 128-bit products on a million random pairs).
  • Checks: live_ui_test adds the recorder (waiting, pre-roll, stop), trimming and normalizing, the edits (start, end, reverse, an octave up, fade, level), the controls (REC, pads, knobs with and without Shift, keeping, a synth track refused), keeping (the track's own kit, slices, the shared pads untouched, a valid project, undo) and the drawing of the start marker. The emulator's project run (session-vm-3ByQNc) opens the Sample view and presses REC twice; the emulator's twin card has no inputs, so the session reports that it cannot open them and carries on. Its other results match the earlier runs: only the screen checks (QEMU's 640×480 display), noXruns, and the pads and bridge sessions' known timing checks failed, and the tracks session's audio card did not appear (the known QEMU flake). Recording itself has not run on the Live yet: it needs the new image on the stick.

Phase 8 notes, part 11: capturing a jam as the song (2026-11-15)

  • Capture (Song view, REC): the first of the "clip-first performance" items in future.md. Armed, it starts with the music; each frame the interface compares the clips each track is heard playing, and every change (a scene launched from Clips, one track's clip launched or stopped) starts a new part. Stopping the music, or REC in the Song view, ends it; the header shows CAPTURE meanwhile.
  • Writing the song (live_edit.hpp song_capture): each part becomes a block of the scene whose clips are exactly those heard; a combination no scene holds becomes a new scene ("Jam 1", "Jam 2"…, within the 16-scene limit). Its repeats are how long it played divided by the scene's length, rounded, at least one; a run of more than 16 becomes several blocks, and parts in a row on the same scene merge. The blocks go after the selected block (or start an empty song), within the 64-block limit, and one Undo restores the song and the scenes.
  • Checks: live_ui_test drives a jam through the interface (Verse twice, Break twice, then the groove alone) and checks the parts, the blocks, the new Jam scene, a valid project and the undo, and that nothing is captured without music or while the song plays. The emulator's project run arms capture, plays a scene, launches the next at the bar and stops.

Phase 8 notes, part 12: fixes from the owner's first playtest (2026-11-15)

  • From the owner's session on the Live (session-015: 15 minutes, no xruns or errors, −12 dBFS peak): six notes, all now built.
  • One playing clip lit per track: scenes may share a clip, and the Clips view lit every slot holding the playing clip. The interface now remembers the slot each track's clip was launched from (a scene or song start resets it to the scene's) and lights only that one; pressing another slot holding the same clip launches from there instead of stopping the track.
  • Menu: a tap without choosing a page leaves you on your page (it used to swap to the previous one). The pages are in two labelled rows: TRACK (with the track's name: Play, Steps, Sample and the new Sound) on the top pads, PROJECT (Clips, Song, Mix, Browse) below.
  • Q-Link pages: the button cycles named knob pages (Shift: back): STEP, NEW STEPS, TRACK and SOUND in Steps; TRACK and SOUND elsewhere. NEW STEPS sets the velocity, chance and (synth) length that new steps get, so every step entered after setting 50% gets 50%. SOUND sets the machine's parameters through the project's parameter assignments, shown in their own units (a synth's tone in Hz, its times in ms), one undo step per turn.
  • The Sound page: the selected track's sound: a synth's eight presets on the top pads (with the bottom pads playing it), a kit's 16 pads by name. A preset sets the machine's state and clears the knobs' assignments for it, in one undo step.
  • Sounds reach the Live's engine: the engine was prepared once, when the project opened, so a changed sound (a preset's oscillator) would never have been heard. ProjectSound::reload builds a new engine on the main thread and hands it over through the command queue at the next audio block; the old one is freed on the main thread. The session reloads after a sound change or an undo while the music is stopped (at most every 150 ms), or when it stops; sounding notes stop at the hand-over, which is why it waits for the music to stop. The main thread keeps its own pointer to the engine for lookups, so the two threads never share one.
  • Checks: live_ui_test adds shared clips (the lit slot, launching a copy, a scene start), the Menu rows, the Sound page's pads and knobs, presets (the synth's state, refused on a kit, undo), a SOUND knob (10% more tone, shown in Hz) and new steps at 50%. live_ui_preview draws the new Menu and the Sound page for synths and kits. The emulator's project run chooses a preset on the bass and checks the engine reloads.

Phase 8 notes, part 13: the knobs' panel on the right (2026-11-15)

  • The owner asked for the four knob cells to sit beside the Live's Q-Link knobs instead of along the bottom of the screen. They are now a 140 px column down the right edge (narrowed from a first 200 px at the owner's request), under the header, with Q1 at the top as the knobs lie; each cell shows the page, the knob's name and its value, large when all four values on the page fit (four characters or fewer), else all in the smaller monospaced face. The status line runs along the bottom of the page, which is 1140 px wide (the header still spans the screen) and 94 px taller than before.
  • Every page lays itself out from the narrower width: the Clips cards, the Play pads, the Steps buttons, the piano roll (59 px steps), the Song list, the Mix strips, the Menu, Sample, Sound and Browse. live_ui_preview drew each of them with Night Shift to check that nothing overlaps or is cut.
  • Checks: live_ui_test checks the panel's place and drawing and the status line's; every other drawing and touch check passes with the new layout.

Phase 9 notes, part 1: project files through the C++ core (2026-11-14)

  • The project module: project_wasm.cpp builds with the other WebAssembly modules (npm run engine:wasm, 255 KB, one random_get import) into packages/core/src/generated/xmp-project-wasm.ts. A project lives in WebAssembly memory by handle. It crosses to JavaScript as compact JSON with each sample's pcm empty, plus each sample's audio as a Float64 array, so no sample is written or parsed as JSON text on the way. project-io.ts wraps it: openProject (importPortable), saveSong (exportSong, packaged or referenced) and saveBundle (exportPortable).
  • Songs saved without their samples: the C++ song import takes a sample library (portable::Library). Opening reports the samples it lacks; JavaScript asks its resolver (the browser's sample store, or WAV files the user locates) and hands their audio over; the second open checks each one's rate, length and hash as the TypeScript does, with the same messages and the same MissingSongAssetsError.
  • The browser now uses it for every project file it opens (ProjectSession.open, so the Device view, Advanced Studio and song files), for saving songs, and for its autosave. The autosave is now a song with its samples packaged instead of a legacy bundle: faster both ways, and older autosaves still open. "Save legacy copy" stays on the TypeScript for now (see below).
  • Speed (Night Shift, a 1.3 MB song with 16 samples, Node on the Mac): opening it takes 267 ms in WebAssembly against 396 ms in the TypeScript, and saving it 184 ms against 182 ms. Getting there needed two fixes in the C++ core, which help the Live as well. The schema check wrote a location string for every array item ("samples[3].pcm[51234]") before checking it, about a million allocations for Night Shift; arrays of numbers are now checked in a tight loop, and the location is written only for an item that fails. That took migrate from 622 ms to 59 ms and opening Night Shift natively from 1.4 s to 0.31 s. The base64 decoder also looks characters up by table instead of strchr.
  • Still slow, and next: reading and writing samples as JSON numbers. Opening a legacy bundle takes 1.4 s in WebAssembly against 0.6 s in the TypeScript, and writing one 42 s against 0.4 s. The C++ number reader and writer (strtod and the shortest-digits search in json.hpp) are far slower than V8's under WebAssembly. Part 2 brings an exact fast reader (Eisel–Lemire) and a shortest-digits writer (Ryu-style), then moves "Save legacy copy" over.
  • Checks: tests/project-io.test.ts runs in the normal suite. It opens 108 files (projects, bundles, packaged and referenced songs, intact and damaged) through both the WebAssembly and the TypeScript, and requires the same projects, the same refusals and the same messages where they are XMP's own. It saves byte-identical songs (packaged and referenced) and bundles, refuses an invalid project, and opens a referenced song from a library: complete, partly missing, and with wrong audio. Nine deliberate faults all fail it; one more (leaving the empty pcm key out of the lean JSON) is harmless, since the key comes back in the same place. The portable, project and edit parity suites still pass after the schema checker change.
  • Checked in the browser: an edit in the Device view autosaves as a version 2 song written by the WebAssembly, and a reload reopens it through the WebAssembly with the edit kept.

Phase 9 notes, part 2: fast exact numbers (2026-11-14)

  • numbers.hpp: Grisu3 for writing (V8's own fast path for Number.prototype.toString; the exact search takes the 0.5% of numbers it cannot be sure of, as V8 takes them to its bignum) and Eisel–Lemire for reading (decimals of up to 19 significant digits, correctly rounded; strtod for longer). Both are written from the papers. Their tables (powers of ten to 64 bits, powers of five to 128) are worked out once at start-up with exact big-integer arithmetic instead of being typed in.
  • Checked: 12 million numbers written (random bit patterns, float32 samples, decimals, powers of two from the subnormals to the top, powers of ten and their neighbours) gave the exact search's text every time, and 36 million texts read (shortest, 17-digit and 13-digit forms of each) gave strtod's double every time. The JSON parity suite against JavaScript (3,000 documents, 20,000 numbers including subnormals and extremes) and every other parity suite still pass.
  • The writer now formats a number into a small buffer and appends it, instead of making a string per number. Natively, writing Night Shift with its samples as JSON numbers (5 MB) takes 54 ms (2.6 s before this part).
  • Speed in WebAssembly (Night Shift, Node on a quiet Mac, TypeScript / WebAssembly): opening the song 217 / 137 ms, saving it 119 / 88 ms, opening a legacy bundle 329 / 325 ms, saving one 291 / 405 ms (42.6 s before this part). "Save legacy copy", the last caller of the TypeScript's file code in the browser, now uses the WebAssembly too.
  • Shared contents (json.hpp): an array's or object's contents are now shared between copies of a value until one of them changes it (copy on write, with an atomic count, since the Live's saver reads a copy on another thread). Copying a project costs almost nothing however much audio it holds, an edit copies only the path it changes, and the schema check keeps a valid number array as it is. Natively, opening Night Shift went from 311 ms to 69 ms and a full check (migrate) from 52 ms to 5 ms. The rule that comes with it: a reference from a non-const accessor must not be kept across a copy of the value (or anything holding it) and then written through. All parity suites, the native suite and the interface test under AddressSanitizer pass.

Phase 9 notes, part 3: edits and parameters through the C++ core (2026-11-14)

  • commands.hpp maps packages/core's edit and parameter functions to their C++ ports by JSON command: every edit the browser's interface uses (toggleStep, expandSong, appendNotes, quantizeNotes, resizeClip, duplicateClip, editChain, deleteTrack, setMidiDestination, manualSlices, installSample, applyDrumKit), setParameter and clearParameterSource, and the parameter registry, values, sources and smoothing. editMix, editPerformance and editSequence take a change: the browser applies it to a copy of the mix, performance or sequence, and the core puts the result in place and checks the project, as ProjectSchema.parse does.
  • edits.ts gives the browser each function with the TypeScript's name, arguments and result. Projects stay in WebAssembly: each Project the core produces keeps a handle to its document, so the next edit starts there and nothing is sent again; a new project's samples reuse the previous audio arrays when the edit left them alone (the core reports which share). Machines the browser registers (the SDK examples) are passed to the core before its next call. The apps (and the tests, through tests/setup-core.ts) load the core once at start; every call after that is synchronous.
  • The browser's interface now edits through it: Advanced Studio, the Device view and their panels (mix, performance, instruments, sequencer, parameters, drum kits). The audio worklet and the audio scheduler still use the TypeScript parameter functions; they move with playback (part 4).
  • Speed (Night Shift, 16 samples): toggleStep 37.4 ms in the TypeScript, 1.6 ms through the core; setParameter 88.9 ms against 3.8 ms; parameterValue 0.11 against 0.09 ms. The TypeScript edits check every sample value again; the core's copy-on-write documents share the audio and its checker keeps a valid array as it is. The first edit of a project object the core has not seen (a project built in JavaScript) sends its audio once (54 ms).
  • Checks: tests/edits.test.ts applies 16 random sequences of 50 edits (the generator now shared with the edit parity suite in tests/edit-ops.ts) through the TypeScript and the core: the same projects byte for byte, the same refusals, and the same messages where they are XMP's own. It compares the parameter registry, every value and smoothing time, and setParameter on six projects, and checks that two edits of Night Shift copy no sample audio. All 335 tests pass; in the browser, a step edit in the Device view and in Advanced Studio goes through the core and autosaves.

Phase 9 notes, part 4a: files and rendering through the C++ core (2026-11-14)

  • The WebAssembly module now also carries the file formats and the renderer (files.hpp, render.hpp and what they use: the performance, the voices and the rack): 842 KB, from 442 KB. Binary results (audio, WAV and MIDI files) come back as blobs read straight from WebAssembly memory; the rest as JSON.
  • edits.ts adds decodeSampleWav, encodeWav, encodeMidi, decodeMidi, exchangePlan, importMidiClip (an edit, so its project keeps a handle and its samples' audio), renderPerformance, renderProjectScene, renderInstrumentScene and renderExchange, with the TypeScript's arguments. renderPerformance and renderExchange return the TypeScript's fields except commands (the scheduled commands themselves), which no caller uses; renderInstrumentScene returns its mono audio and MIDI events, which is what the instrument panel resamples.
  • The browser now uses them for every sample it loads (Advanced Studio, the instrument panel, song relinking, the Device view's library), for take downloads, MIDI export, MIDI import and clip import, WAV exports and scene renders.
  • Checks: tests/media.test.ts reads 300 random WAV files (valid, odd and damaged; the generator now shared with the files parity suite in tests/media-fixtures.ts) and writes 40, plans, writes, reads (intact and cut short) and imports MIDI for 24 projects and modes, and renders four projects as a song, a scene, an instrument scene and an exchange: the same bytes, audio and refusals as the TypeScript. All 338 tests pass, and both pages load in the browser.

Phase 9 notes, part 4b: playback through the C++ core (2026-11-14)

  • The browser's audio scheduler now plays projects through the C++ performance (play::Performance, the same one the Live plays with) in WebAssembly. edits.ts gives it PerformanceTransport with the TypeScript class's members (start, queueScene, queueClip, cancelLaunch, stop, control, advance, snapshot, setProject, and the scene, mode, step, offsets, slots, queued launches and overrides), and performanceWindow, performanceCommands, performanceValues and performanceControls. A window comes back with its scheduled commands (the C++ render::performance_commands), so it crosses once. The C++ performance now also reports the step a queued launch lands on.
  • Checks: tests/playback.test.ts runs ten random performances (starts in both modes, scene and clip launches, cancels, stops, live mutes and solos, chain edits while playing, values, controls, snapshots and over 500 windows) through the TypeScript transport and the core, comparing every result and the whole state after every command. All 339 tests pass.
  • Not checked in the browser: hearing playback. The browser pane was hidden, and the app stops playback in a hidden tab; the pages load and edit through the core without errors.
  • Projects with neither a performance nor a mix (the demo song both pages start with) play through the core too: timeline, eventsAtStep and parameterFrame are commands, and the scheduler's parameter reads (parameterValue, parameterSmoothingMs) go through it. tests/playback.test.ts compares them on eight such projects, the demo among them. All 340 tests pass.
  • Still in TypeScript at run time: small helpers the interface calls synchronously and often (tempo and groove arithmetic, sceneLength, hasSequence, MIDI destinations, mix effect lists), the instrument preparation the audio worklet receives (prepareInstruments), recording takes (by design, see the phase 9 plan), and the schemas the interface validates its inputs with.

Phase 9 notes, part 5: where the TypeScript stands (2026-11-14)

  • Steps 1–4 are done. The browser opens and saves every project file, makes every project edit, reads and sets every parameter, reads and writes WAV and MIDI files, renders, and plays (both with and without a performance or mix) through the C++ core in WebAssembly. The sequencer panel's parameter frames moved with this note.
  • Still TypeScript at run time, by design: recording takes (TakeRecorder, NoteTake, AutomationTake, PerformanceTake, NoteRepeat), the SDK's machine registry (plugin machines are JavaScript), Web MIDI routing, ProjectSession (the interface's undo history), the audio worklet's VoiceRack (itself a wrapper of the C++ engine's WebAssembly) and the instrument palette it is sent (prepareInstruments), the demo song, the schemas the interface checks form input with, and small helpers it calls synchronously and often (groove, swing and tempo arithmetic, sceneLength, clipFor, MIDI destinations, effect defaults, hashSample for relinking).
  • Step 5, deleting the TypeScript copies of what moved, has not been done. The plan sets it for "once the browser has run on C++ for a while": until then, the TypeScript copies are what the parity suites and the new tests/project-io, edits, media and playback tests compare the C++ against, and deleting them first means recording golden expectations so those tests keep checking something. The copies are no longer called by the browser.
  • Known slowdown, deferred by the owner: playback windows through the core take 5.6 ms against the TypeScript's 1.4 ms (transport getters 14 µs against 0.2 µs). It is a to-do in future.md.

Phase 9 notes, part 6: the engine originals retired (2026-11-14)

  • Retired: the original TypeScript engine rack (reference-rack.ts), sequencer (reference-sequencer.ts), transport (reference-transport.ts) and performance controls (reference-controls.ts). Nothing but their parity tests reached them since the browser moved to the C++ engines.
  • Golden expectations: before deleting them, their five tests ran once more comparing the C++ (as WebAssembly, so the same bits on every machine) with the originals, and recorded a SHA-256 fingerprint of every C++ result while they matched (tests/golden.ts, tests/golden.json): 14 fingerprints over the engine's audio, MIDI, voice counts and meters; the sequencer's groove, notes, timelines, step events and parameter frames; the transport's results and state after every operation; and the controls' and parameter values' results. The tests now drive the same random scripts and require the same fingerprints. The engine's audio is rounded to 1e-6 first, since the SDK's example machines run in JavaScript, whose Math may change in the last bit between Node versions. XMP_GOLDEN=record rewrites them, for a deliberate change only.
  • Then the renderers and file code (same day): exchange.ts, offline.ts, sequence-render.ts and performance-render.ts are gone too. Their last callers, the command-line tools (export-project, the lab agent, the demo song), the guest OS and the acceptance steps, now use the WebAssembly core (edits.ts), which gained prepareScene (the scene plan the native song renderer reads), renderSequence, renderScenePlan, a full renderInstrumentScene result (its notes, refusals and WAV) and each render's command count. saveExport moved to export-sink.ts. The native parity suites for files and renders now compare the native C++ build with the WebAssembly one (same source, two compilers); tests/media.test.ts, tests/playback.test.ts (the scheduled commands) and the new tests/renders.test.ts check fingerprints recorded while the core matched the TypeScript. Renders return their scheduled commands again (the acceptance steps replay them into the worklet). bdd:test passes on the core. The first bdd:implemented run found three failures from this change (a version check still expecting 6, and two steps reading the commands), now fixed but not yet rerun; its other three failures (npm run check in a clean checkout missing artifacts/demo/night-shift.xmpsong, and an SDK build that saw sources change mid-run) need a separate look.
  • Then the mixer (same day): mix-dsp.ts, the original TypeScript mixer and effects, is gone. The engine's WebAssembly now also gives JavaScript the C++ engine's own effects and mixers as standalone objects, and mixer.ts wraps them with the old API (EffectProcessor, StereoMixer, panGains). tests/mix.test.ts and the mix acceptance steps run on it. Before the deletion, tests/mixer.test.ts compared the two on 60 random effects (every kind, sync, bypass, automated values, a clear midway) and 24 random mixes (pans, sends, inserts, returns, tempo changes, meters, the clock): every sample within 1e-9. It now checks the fingerprints recorded then.
  • Still TypeScript: the project schemas and helpers in index.ts, the instrument palette (instruments.ts, which the audio worklet uses), the performance and sequencer helpers the interface calls synchronously (performance.ts, sequencer.ts), recording takes, and the schemas the interface checks input with.