From acb8cb769675119551ba6631f5cd601c21339d89 Mon Sep 17 00:00:00 2001 From: monkey-w1n5t0n Date: Mon, 29 Jun 2026 00:15:39 +0200 Subject: [PATCH] feat(manifold): browser-only extra gate-sequence tracks (spare net outputs) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WASM net is fixed at MLP<32,..,126>; MEMLCelium uses the first 56 outputs, so [56..125] are computed-but-unused. Borrow them as extra RatioSeq tracks — native tracks 0-1 read the real rhythm [0..13] (audio-synced), browser-only tracks 2+ read the spare window [56,63,..] → up to 12 tracks total. Firmware stays at 2; no engine reshape. - cv-backend: rhythmBases track->output-base mapping + setRhythmLayout. - useBackendManager: RHYTHM_LAYOUTS keyed by engine (memlcelium = 2 native, 56 params), builds native+spare bases up to the net width. - Outputs UI helper text; spec updated with the real (non-reshape) mechanism. Caveat (documented): one shared net, so RL feedback on the synth also nudges the extra tracks — true independence needs the separate Rhythm MLP (not yet built). --- docs/slp-workshop/SPEC.md | 20 +++++++++++----- manifold/src/backends/cv-backend.ts | 19 ++++++++++++++- manifold/src/backends/useBackendManager.ts | 28 +++++++++++++++++++++- manifold/src/dock/OutputsBackendConfig.tsx | 5 ++-- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/docs/slp-workshop/SPEC.md b/docs/slp-workshop/SPEC.md index 8260917..403aa4b 100644 --- a/docs/slp-workshop/SPEC.md +++ b/docs/slp-workshop/SPEC.md @@ -104,13 +104,21 @@ vary sequence count. ### Browser (Manifold) — dynamic, switchable live -Same three **plus** a fourth, and with **as many ratio sequences as the user wants** -(each gate sequence = its own independent 7-param track; the net reshapes to suit): +Same three **plus** a fourth, and with **more ratio sequences than the firmware's 2**. -- **Continuous & Rhythm (split nets)** — Continuous MLP + a separate Rhythm MLP. - Browser-only (two MLP heads; hardware uses one). `output_size`: shared net = - `continuous + 7 × n_gates` (mind the 126-output WASM cap → ~16 gates max shared); - split net = the Rhythm net is sized independently, so it scales further. +**How extra tracks work (IMPLEMENTED, 2026-06-29).** The browser WASM net is fixed +at `MLP<32,…,126>` — it does **not** reshape per mode. MEMLCelium maps the first +56 outputs (14 rhythm + 42 synth); outputs **[56..125] are computed but unused**. +So the browser borrows them: native tracks 0–1 read the real rhythm at [0..13] +(in sync with the audio); browser-only tracks 2+ read the spare window +[56, 63, …] — **up to 12 tracks total** ((126−56)/7 = 10 extra). The firmware is +untouched (still 2). Caveat: it's ONE shared net, so RL feedback that shapes the +synth also nudges the extra tracks — they are not *independently* trained. (Per- +engine layout lives in `manifold/src/backends/useBackendManager.ts` `RHYTHM_LAYOUTS`.) + +- **Continuous & Rhythm (split nets)** — Continuous MLP + a separate, independently + trained Rhythm MLP. Browser-only, NOT yet built — this is the upgrade that + decouples the extra tracks from the synth (two MLP heads; hardware uses one). The browser mode is implied by the Outputs config (§4), not a separate picker: choosing continuous-count > 0 and gate-sequences = 0 ⇒ Continuous-only; diff --git a/manifold/src/backends/cv-backend.ts b/manifold/src/backends/cv-backend.ts index 68ac695..15bf6ae 100644 --- a/manifold/src/backends/cv-backend.ts +++ b/manifold/src/backends/cv-backend.ts @@ -82,6 +82,13 @@ export class UseqCvBackend implements OutputBackend { private seq = new RatioSeqEngine(); private trackGate = new Uint8Array(MAX_TRACKS); private trackDone = new Uint8Array(MAX_TRACKS); + /** + * track → output base index for the 7-param rhythm slice. The native tracks + * point at the engine's real rhythm params; browser-only extra tracks borrow + * the net's spare outputs (beyond the engine's param count). Empty ⇒ contiguous + * `track*7` fallback. Set by the dock from the active engine's layout. + */ + private rhythmBases: number[] = []; private pendingIdentify: (() => void) | null = null; @@ -136,6 +143,15 @@ export class UseqCvBackend implements OutputBackend { this.seq.setBpm(bpm); } + /** + * Set the rhythm track → output-base mapping (per active engine). Native tracks + * read real rhythm params; browser-only extra tracks read the net's spare + * outputs. Pass `[]` to fall back to contiguous `track*7`. + */ + setRhythmLayout(bases: number[]): void { + this.rhythmBases = bases; + } + /** User-gesture path: pick + open a serial port. Throws if the user cancels. */ async connect(): Promise { if (!this.isAvailable()) { @@ -324,7 +340,8 @@ export class UseqCvBackend implements OutputBackend { private seqGate(track: number, routed: Float32Array): boolean { if (track < 0 || track >= MAX_TRACKS) return false; if (!this.trackDone[track]) { - this.trackGate[track] = this.seq.evalTrack(track, decodeTrack(routed, track * 7)).gate ? 1 : 0; + const base = this.rhythmBases.length ? (this.rhythmBases[track] ?? -1) : track * 7; + this.trackGate[track] = base >= 0 && this.seq.evalTrack(track, decodeTrack(routed, base)).gate ? 1 : 0; this.trackDone[track] = 1; } return this.trackGate[track] === 1; diff --git a/manifold/src/backends/useBackendManager.ts b/manifold/src/backends/useBackendManager.ts index 38076c1..2348009 100644 --- a/manifold/src/backends/useBackendManager.ts +++ b/manifold/src/backends/useBackendManager.ts @@ -21,6 +21,28 @@ import type { BackendContext, BackendStatus, OutputMapping } from './backend'; import type { BackendId, CvSpec, MidiCcSpec, OscSpec, VcvSpec } from '../dock/output-state'; import { defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from '../dock/output-state'; import { BackendManager } from './manager'; +import { modeEngineId } from '../console/model'; + +/** + * Per-engine rhythm layout: how many native RatioSeq tracks the engine has and + * its real param count (where the net's spare outputs begin). Browser-only extra + * gate-sequence tracks borrow those spare outputs (up to the net width). These + * are fixed C++ engine facts (e.g. MEMLCelium: 2 sequences × 7 params at [0..13], + * 56 params total), NOT derivable from manifold's UI-param mock. + */ +const RHYTHM_LAYOUTS: Record = { + memlcelium: { nativeTracks: 2, paramCount: 56 }, // also the slp_workshop engine +}; + +/** Build the track → output-base mapping for an engine (native + spare). */ +function rhythmBasesFor(engineId: string, netOut: number): number[] { + const lay = RHYTHM_LAYOUTS[engineId]; + if (!lay) return []; + const bases: number[] = []; + for (let t = 0; t < lay.nativeTracks; t++) bases.push(t * 7); // native rhythm params + for (let b = lay.paramCount; b + 7 <= netOut; b += 7) bases.push(b); // browser-only spare tracks + return bases; +} export interface MidiSettings { outputId: string | null; @@ -163,7 +185,11 @@ export function useBackendManager( const specs: CvSpec[] = params.map((p, i) => (p.cv as CvSpec | undefined) ?? defaultCvSpec(i)); cv.setCvConfig(specs); cv.setBpm(bpm); - }, [manager, params, bpm]); + // Native rhythm tracks read the engine's real params; browser-only extra + // tracks borrow the net's spare outputs (the firmware stays at its native count). + const netOut = engine?.architecture.outputSize ?? 126; + cv.setRhythmLayout(rhythmBasesFor(modeEngineId(modeId), netOut)); + }, [manager, params, bpm, modeId, engine]); const cvConnect = () => void manager?.cv()?.connect(); const cvIdentify = () => manager?.cv()?.identify(); diff --git a/manifold/src/dock/OutputsBackendConfig.tsx b/manifold/src/dock/OutputsBackendConfig.tsx index 10946ad..e343f3e 100644 --- a/manifold/src/dock/OutputsBackendConfig.tsx +++ b/manifold/src/dock/OutputsBackendConfig.tsx @@ -650,8 +650,9 @@ function CvConfig({ ctx }: { ctx: ConsoleCtx }) { Per-output channel · gate source

- Gate channels run a clock-driven Sequence (RatioSeq, tempo = app BPM) whose 7 params come from rhythm - outputs [track×7…]; or Threshold a continuous output. CV channels carry the mapped value. + Gate channels run a clock-driven Sequence (RatioSeq track, tempo = app BPM) — tracks 0–1 are the + engine's native rhythm; tracks 2+ are browser-only extras on the net's spare outputs (up to ~12 total). Or + Threshold a continuous output. CV channels carry the mapped value.