diff --git a/changelog/2026-11-29-octatrack-post-fx-cc-hooks-design.md b/changelog/2026-11-29-octatrack-post-fx-cc-hooks-design.md new file mode 100644 index 0000000000..d049dc66f4 --- /dev/null +++ b/changelog/2026-11-29-octatrack-post-fx-cc-hooks-design.md @@ -0,0 +1,2 @@ +Documented the design of a shared post-FX2 DSP site (site 2 as a chain) and a shared MIDI CC-in hook for the Octatrack base, with the owner's decisions and the hook's planned subscribers. +This is a design only; the base, its hooks and every module are unchanged. diff --git a/docs/OCTATRACK_POST_FX_AND_CC_HOOKS.md b/docs/OCTATRACK_POST_FX_AND_CC_HOOKS.md new file mode 100644 index 0000000000..8ef73b6c56 --- /dev/null +++ b/docs/OCTATRACK_POST_FX_AND_CC_HOOKS.md @@ -0,0 +1,157 @@ +# A shared post-FX2 DSP site and a shared CC-in hook (design) + +Status, 3 December 2026: a design for the Octatrack's cumulative base, proposed on 29 November and decided by the +owner on 30 November ([decisions](#decisions)). Nothing is built. No figure here has been measured on a unit or in +the emulator; the DSP costs are static instruction counts, marked as such. + +## Why + +A per-track 12 dB/oct low-pass and high-pass after FX2 on every track, so players keep both FX slots, two knobs +and two MIDI CCs. The owner ruled on the agent board (thread `006db2f4`): the filter is a module, +its sites are base work and come first. Two base pieces, each shared by more than one module: + +1. **A per-track DSP site after FX2.** The only point there today, site 2 `dsp_track_commit`, is exclusive and held + by Sidechain Compressor's MON commit (`moncommit`). A second module cannot patch it. +2. **A shared CC-in hook.** CC Map patches the stock CC handler's entry today (`cave_runtime.py`'s `CC_ENTRY`, + 0x4000e79c, 8 bytes), so a second module that reads incoming CCs cannot. + +The filter is the first subscriber of both. Its module pull request follows once the base carries them, and +builds and runs as the only module chosen. + +The returning pre-FX processor chain (#2248, site0) stays as it is: it runs before FX1 and its owner keeps it +pre-FX (thread `bb517593`). This proposal does not touch it. + +## 1. Site 2 becomes a chain + +Site 5 `dsp_track_source` became a chain for Analog BD and BlackPyramids (#1098). Site 2 can follow the same pattern +rather than a new site beside it. + +**Why site 2 and not a new site.** It already runs where the filter needs to: "the dispatcher, per track per block, +after both FX procs", on both cores (A P:$0050e, B P:$00303), with its guard and a register contract that Sidechain +Compressor's MON commit already keeps. A second post-FX2 site would need its own payloads, guard and order against site 2 checked +anyway (thread `bb517593`), and two hooks a few instructions apart would raise the question of which runs first in +every pairing. One chain answers that in its order. + +**What the chain looks like** (`sdk/machines/octatrack/dsp-sites.json`, the same index, `kind` changes): + +```json +{"index": 2, "name": "dsp_track_commit", "features": [, 1], "label": "moncommit", + "A": "0x0050e", "B": "0x00303", "words": 2, "guardSha256": "9dad4262…", + "when": "the dispatcher, per track per block, after both FX procs: X:$0000-$001F hold the track's 16 stereo pairs (L, R), X:$420 the track", + "clobbers": ["a", "b", "x0", "x1", "y1", "r1", "n1", "r3"], "kind": "chain", + "contract": "the base's stub replays the displaced instruction (move x:>$206,r0) once, then calls each enabled feature's engine in `features` order (bsr). An engine reads and writes the track's block in place and returns (rts); it keeps r0, y0, r2 and n2."} +``` + +- **Index and guard are unchanged**, so packages built against site 2 keep their meaning. Only its `kind` and its + feature list change. +- **The base replays the displaced instruction.** Today `moncommit` begins with `move x:>$206,r0` itself; its + `scmonbody` entry already exists for a composed hook ("the caller must have replayed the displaced x:$206 load + first"). The chain calls `scmonbody`, so Sidechain's DSP source changes only in which label the stub calls. That + still makes this a Sidechain base input change: it is resident (`resident_dsp.py`), and the base is rebuilt. +- **Registers.** The contract is the one `moncommit` already keeps: `a, b, x0, x1, y1, r1, n1, r3` may be clobbered; + `r0` carries `x:$206` for the stock dispatcher; `y0`, `r2` and `n2` are never touched ("r2/n2 broke transport, S59", + `patch_sc_dsp3.asm`). Every engine in the chain keeps the same. +- **Order.** The filter first, MON last (owner, 30 November). MON swaps the track's audio for the stashed key while + a player listens to the side-chain key; with the filter before it, MON still plays the key as it is, unfiltered, + which is what MON is for. The opposite order would filter the key monitor. +- **No subscriber, no cost.** With neither feature enabled the stub replays the instruction and returns, as the + dormant stub does today. + +### The filter's DSP cost (static estimate, to be measured) + +A topology-preserving (trapezoidal) state-variable filter per pole pair, coefficients computed on the ColdFire only +when a knob or CC moves (the light place: an edit), never per frame. The DSP reads three or four coefficient words a +track a block. + +| Work | Instructions a sample, static count | Note | +| --- | --- | --- | +| LP, one channel | about 12 | 5 multiply-accumulates, 2 state updates, moves partly parallel | +| HP, one channel | about 14 | the LP's core plus `x - k·band - low` | +| Both, stereo, one track | about 52 | | +| Both, stereo, a core's four tracks | about 208 | the worst case: every track with both filters engaged | +| A track with both knobs at rest | a few a block | LP fully open and HP fully closed skip the track: the default | + +So the cost grows with the filters a player turns. The owner asked to measure this early ("8 filters +must fit the frame admission"), so the first build is a development twin that admits the filter without a charge, +as `--measure-voices` does for machine voices, and reads both cores' meters (`stats`) on: + +1. a Part with NONE in every FX slot, filters at rest; +2. the same Part, both filters engaged on all eight tracks; +3. the same, with the heaviest stock FX pairing the base admits (Analog BD beside SPRING REV), to find what is left. + +Its price is then charged like the key bus's tap (`cost`, 7/4 of an emulator figure until a hardware figure exists), +per engaged track, on the track's core. If eight engaged tracks do not fit, the plan falls back in this order: a +cheaper Chamberlin SVF (about 7 a channel, stable only below about fs/6, which the knob range then caps), then a +mono filter on the sum of a mono track, then a cap on engaged tracks a core. + +**DSP memory.** About 8 state words and 8 coefficient words a track, 64 words a core, in Y, claimed in +`dsp-sites.json`'s `regions` beside the feature's bit. The exact range is for the ledger review: it must meet no FX +buffer and no other region. + +## 2. `ev_midi_cc`: a call hook at the stock CC handler + +```json +{"event": "ev_midi_cc", "index": , "site": "0x4000e79c", "length": 8, + "guard": "715d7b1903ad498a152a612ab010424dac3376a75a2bac2c2d898dd767190b42", + "prototype": "unsigned f(const uint8_t *msg)", + "when": "an incoming MIDI Control Change reaches the stock CC handler, before stock reads it; msg = {status, cc, value}", + "context": "the MIDI task: short, no firmware call that can block", + "contract": "0 passes the message on; 1 takes it: no later handler and not stock sees it. A handler takes only the CC numbers it owns, on the channels its tracks listen to, and checks AUDIO CC IN itself.", + "order": "lower first, then module id. 10-29: modules that take CC numbers stock ignores; 40-69: modules that only observe and pass."} +``` + +- **Site.** The stock handler's entry, 8 bytes, the guard `cave_runtime.py` already pins for CC Map's runtime + package. The dispatch vector at 0x400d64a0 stays stock, so a card build that repoints it (CC Map's native build, + the Octakit bridge) is unaffected. +- **Who patches it today.** CC Map (`CC_ENTRY`). Until it subscribes, the pair goes in `compatibility.json` as + `pending-migration` with `until` its next version. CC Map's handler then becomes the subscriber that takes CC + 62-73, and passes everything else, as it tail-calls stock now. +- **Shared helper.** Each subscriber needs the channel-to-track map CC Map rebuilds (`MAPBUILD`, 0x40001854). The + base computes it once per message and passes it beside `msg`, or exports `mw_midi_channel_tracks(channel)`, so no + two modules call the stock builder for one message. Proposed: the second, so the prototype stays one argument. +- **CC numbers.** Not the hook's business: each module owns its numbers and lists them in its README. A clash is a + UI claim (`midi:cc:`), which the gate compares like key gestures. Proposed as a follow-up to `uiClaims`. The + filter's two numbers are chosen with its module, outside CC Map's 62-73 and stock's. +- **Subscribers.** The hook serves several modules, each taking only its own numbers: + 1. the post-FX2 filter, its two CC numbers; + 2. MIDI NRPN on a MIDI track's CTRL knobs ([#2540](https://github.com/repeat98/modwerk/pull/2540)), which reuses this + hook rather than adding its own and takes CC 99, 98, 6 and 38 only while an NRPN knob is set; + 3. CC Map, once it moves onto the hook: CC 62-73. + +## 3. Where the filter keeps its values + +Per-track LP and HP are a project's sound, not an instrument-wide choice, so `ot_settings` (a choice for the whole +instrument) is not the place. Following [a module owns what it saves](module-guides/README.md#cross-compatibility): +`#` lines in the project's `project.work`, read at `ev_project_load` and written at `ev_project_write`. Part-level +values (a Part per sound) would need bytes inside a stock Part record and the stock-feature test that comes with +them: not proposed. The two controls are reached by CC and, on the unit, through the module's own settings rows +before any page behind a stock key, as the owner asked. + +## Decisions + +The owner's answers ([#2436](https://github.com/repeat98/modwerk/pull/2436), 30 November 2026): + +1. **Site 2 becomes a chain**, the way site 5 became one: same index and guard, only its `kind` and feature list + change. No separate post-FX2 site. +2. **The filter first, MON last**, so MON keeps playing the key as it is. +3. **`ev_midi_cc` at the stock CC handler's entry, with `mw_midi_channel_tracks` exported.** Its index is the next + free hook index, claimed on the agent board before the entry is written (66 to 91 were held on 30 November). +4. **`midi:cc:` as a UI claim kind**, as its own small pull request to the gate after the hook is in. +5. **Per-project storage in `project.work`**, with no Part-level values. + +## What comes next + +Before the code commits: + +- **The authors' OK**, linked in the pull request: Zac Kyoti for Sidechain Compressor's stub label change, and + Sam Banks for moving CC Map onto `ev_midi_cc`. +- **The hook index**, claimed on the agent board. + +Then, each as its own commit against `base/octatrack-next`: + +1. **The measuring twin first.** A development twin that admits the filter without a charge, and the three runs + [above](#the-filters-dsp-cost-static-estimate-to-be-measured) on a unit. Their figures go in the pull request + before the filter gets a price or anything is promoted. +2. The entries in `dsp-sites.json` and `events.json`, the base's chain stub and CC dispatcher, Sidechain's stub label, + and the `pending-migration` row for CC Map. +3. After the hook is in: the `midi:cc:` claim kind in the gate, as its own pull request. diff --git a/docs/README.md b/docs/README.md index 3d736814df..55d4f18406 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,6 +65,7 @@ Every document in `docs/`, one line each. [AGENTS.md](../AGENTS.md) says which t - [STARTUP_ANIMATION.md](STARTUP_ANIMATION.md): the docking startup animation. - [OCTABAM_INFRASTRUCTURE.md](OCTABAM_INFRASTRUCTURE.md): pinned backports of octabam's infrastructure. - [PRIVATE_RUNTIME_CAVES.md](PRIVATE_RUNTIME_CAVES.md): private cave packages for CC Map and Recorder Loop Fix. +- [OCTATRACK_POST_FX_AND_CC_HOOKS.md](OCTATRACK_POST_FX_AND_CC_HOOKS.md): design, decided by the owner: site 2 as a shared post-FX2 chain and an `ev_midi_cc` hook, with a per-track filter as first subscriber and MIDI NRPN (#2540) as the hook's second. ## Other machines and research