diff --git a/changelog/2026-12-02-octatrack-midi-ctrl-hooks-design.md b/changelog/2026-12-02-octatrack-midi-ctrl-hooks-design.md new file mode 100644 index 0000000000..583baff63d --- /dev/null +++ b/changelog/2026-12-02-octatrack-midi-ctrl-hooks-design.md @@ -0,0 +1 @@ +Octatrack: a design for NRPN on a MIDI track's CTRL knobs. It proposes the base hooks first; nothing is built and nothing changes on the unit. diff --git a/docs/OCTATRACK_MIDI_CTRL_HOOKS.md b/docs/OCTATRACK_MIDI_CTRL_HOOKS.md new file mode 100644 index 0000000000..4d7d852888 --- /dev/null +++ b/docs/OCTATRACK_MIDI_CTRL_HOOKS.md @@ -0,0 +1,131 @@ +# MIDI track CTRL SETUP hooks and NRPN (design, for owner review) + +Status, 5 December 2026: the owner agreed to the proposed hooks and confirmed that the unit traces below answer the +checks required for this design. The proposed hooks and module are not built. The addresses were first identified by +static readings of the 1.40C image, including [MIDI_TRACKS.md](../sdk/octabam/docs/MIDI_TRACKS.md); the unit traces +confirm the specific encoder and press callbacks described below, not every address or route. Entries, lengths and +guards in `events.json` need a real OS file (CI has no firmware). + +## Why + +A MIDI track's CTRL1 and CTRL2 pages send CC 0-127 only. The first module, **MIDI NRPN** (draft #2538), adds NRPN +to those knobs: past CC 127 in a knob's SETUP list the value reads `NRPN`, and pressing the knob there opens a page for +the NRPN number (MSB, LSB) and the value size (7 or 14 bit). A knob set to NRPN sends and receives that parameter. + +Stock offers no way to do this without patching its sites, and those sites are shared with other work: CC Map patches +the CC handler, and the Midi Mode 2 draft (`sdk/drafts/midi-cc-slots`) reuses CTRL1 SETUP's hidden bytes. Brain-style +modules that rename CTRL knobs reach the same page. So the sites belong in the base, and the NRPN module is the first +subscriber. It builds and works as the only module chosen. + +## What is proposed + +| Hook | Kind | Stock site | When | Why the base, not the module | +| --- | --- | --- | --- | --- | +| `ev_midi_cc` | call | 0x4000e79c (proposed in #2436) | an incoming CC reaches stock's CC handler | NRPN is the second subscriber after the post-FX2 filter: it **reuses** #2436's hook and adds none | +| `ev_ctrl_setup_knob` | take | candidates 0x4003a7f4 (CTRL1) and 0x4003a700 (CTRL2), reached by encoder turns on the unit; hook placement and writer route still need confirmation | an encoder turns on CTRL1 or CTRL2 SETUP, before the writer's `cc <= 127` check | stock clamps at 127, so the number cannot go on without taking the turn | +| `ev_ctrl_setup_text` | take | the value-name lookups 0x4003fb32 (CTRL1 draw 0x4003f9ac) and 0x4003f60c (CTRL2 draw 0x4003f490) | SETUP is about to print a slot's value text (the CC name table 0x400be882, `%.8s`) | the row must read `NRPN` and, on its page, the MSB, LSB and size | +| `ev_ctrl_setup_press` | take | candidates 0x4003fc44 (CTRL1) and 0x4003f71c (CTRL2), reached by presses on the unit; hook placement still needs confirmation | a knob is pressed on CTRL1 or CTRL2 SETUP | opens the NRPN page; stock's press on SETUP does nothing the module needs to keep | +| `ev_ctrl_value_send` | take | 0x4009eec8 (sends one page-1 value: `t`, `flat` 18 PB, 19 AT, 20-29 CC, `value`, `force`) | stock is about to send a MIDI track's knob value | one site covers a knob turn, an LFO, a p-lock and a scene, so an NRPN knob sends the same way in each | + +The three SETUP hooks follow the precedent of `ev_arp_setup_knob` and `ev_arp_setup_text`: a take hook that gives one +subscriber the turn or the draw, with `claims` limited to the slot it owns, and that replays stock for everything else. +Their prototypes mirror those two, with the slot (0-9) and the track as arguments. The order bands: 10-29 for a module +that owns a slot's number, 40-69 for one that only observes. + +## Sites found in the 1.40C image (2 December 2026) + +The static reading used `m68k-elf-objdump -m m68k:cfv4e` on the main OS section, with +`address = 0x40000400 + file offset`. The later unit traces confirm the callbacks specifically identified below. + +- **The page.** CTRL1 SETUP is a window. 0x40059620 builds it (or jumps to its destroy function when it exists) and + keeps it at 0x400bc9ba; its descriptor holds the destroy function 0x400567e0 and the draw 0x4003f9ac. CTRL2 has the + same layout: build 0x4005948c, destroy 0x400567b8, draw 0x4003f490 (its window address is not read yet). +- **MIDI-learn candidates.** The four records at 0x400bc6ec use 0x4004ad80, and the six at 0x400bc9e6 use + 0x4004acf8. On event 1, these set the learn index to 0-3 and 4-9 respectively and open an edit overlay through + 0x4006d57c; both call the CTRL1 redraw. This is a static reading, not a unit trace of the event that reaches them. +- **Correction: 0x4004ae08.** An earlier revision called this the CTRL value writer. It writes NOTE SETUP, redraws + through 0x40036548 and sends bank and program changes. The CTRL writers and the CTRL2 row callback are instead + listed in [MIDI_TRACKS.md](../sdk/octabam/docs/MIDI_TRACKS.md): 0x4003fd34, 0x4003f80c and + 0x4003f71c. The unit traces below locate encoder and press callbacks, but do not establish the full route to the writers. + +## Sites already in use + +- **0x4004ae08.** Midi Mode 2 detours this NOTE SETUP writer for its track-name editor. Leave its existing detour + alone unless a shared NOTE SETUP hook is separately designed; do not attach the CTRL hook here on the assumption + that it writes CTRL values. Confirm the actual shared sites and migration with its author before implementation. +- **0x4009eec8.** Midi Mode 2 calls this emitter, and MIDI Scenes calls it when a scene value changes. Neither call + needs changing if the base owns the entry. A take for an NRPN-configured track and slot translates MIDI Scenes' + value to NRPN instead of sending its stock CC; all other sends continue through stock. Verify both modules together + on a unit before release, including a scene with and without an NRPN assignment. + +## How NRPN uses them + +- **Storage.** Stock clamps every Part byte of a MIDI track to its page's range, so an NRPN number cannot live there. + The module keeps a sparse list in the project's `project.work` (`ev_project_load`, `ev_project_write`), keyed by + bank, Part, track and slot, with the MSB, LSB and size. The stock CC byte of an NRPN knob holds 127, so with the + module removed the knob falls back to a plain CC 127 and nothing breaks. A list entry marks the knob as NRPN. +- **Sending.** At `ev_ctrl_value_send` the module takes a value on an NRPN knob and sends CC 99 and CC 98 (only when + the number differs from the last one sent on that channel), then CC 6 and, in 14 bit, CC 38, through stock's send + primitive 0x40010bc8. Everything else returns to stock. +- **14 bit.** The knob's value is one byte (0-127), so 14 bit gives the full parameter range, not finer steps: the + module sends `value * 16383 / 127`. Finer steps would need the encoder's own resolution, which this does not propose. +- **Receiving.** At `ev_midi_cc` the module handles CC 99, 98, 6 and 38 for configured NRPN knobs, accounting for + the project's auto channel and both CC DIRECT CONNECT modes, rather than matching only the track's output channel. + Preserve stock handling for unrelated messages and mappings. A complete NRPN sets the knob's value through the + page-1 writer 0x40054cd8 (`8 + t`, `20 + slot`), which calls 0x4009eec8; the module marks that write so + `ev_ctrl_value_send` does not send it straight back out. The exact routing and consumption rules still need design + and testing for both modes. +- **RPN and the rest.** CC 101 and 100 pass to stock, and an RPN select ends a pending NRPN select. Notes, clock, + start, stop and SysEx are not touched. + +## Owner's decisions and required checks + +The owner agreed to the four SETUP and send hooks, conditional on confirming the sites on the unit before claiming +any hook index. Add them after the FM hooks (#2352) and scale hooks (#2415), with guards and NRPN as first subscriber. +Draw the NRPN page through `ev_ctrl_setup_text`, store settings per Part in `project.work`, and use the scaled 7-bit +knob for the full 14-bit range. + +**Incoming CC, MKII, 3 December 2026.** On temporary development base +`ebc820ab7123f0ef4f9f59c36f9703009e2454ae676f866dab5a1c890462bfde`, with no modules loaded, MIDI track 1's +enabled CC1 was assigned CC7, its output channel was 1, and the project's auto channel was 11. With CC DIRECT +CONNECT enabled, channel 11 CC7 values 23, 96, 0 and 127 moved the knob to those values; channel 1 CC7 did not +move it from 107. With CC DIRECT CONNECT disabled, channel 11 CC7 did not move the knob, but CC36 values 96 and +32 did. This checks one knob, not all tracks or slots. Each message advanced the MIDI receive FIFO by three bytes; +as a separate positive control, channel 1 CC16 moved audio track 1's pitch with AUDIO CC IN enabled. The project's +direct-connect setting was restored, and the test Part matched its original bytes before restarting. The release base +does not permit the same memory check after restarting. The receive design must account for the auto channel and both +direct-connect modes; matching only the MIDI track's output channel would miss this observed input. + +**Row trace, MKII, 4 December 2026.** On the same development base, a private, unkept probe +(`081b84b43ed1c76c99bdf883862c70c9856f3d8b55cfd50ba3d5a80c53faf8f4`) counted candidate entries and replayed the +displaced instructions. With no other modules loaded, pressing each CTRL1 SETUP CC1-4 knob advanced the counter at +0x4003fc44 by two per press; pressing each CTRL2 SETUP CC5-10 knob advanced 0x4003f71c by two. During those presses, +0x4004acf8, 0x4004ad80, 0x4003fd34, 0x4003f80c and 0x4004ae08 did not count. Turning each of those ten encoders +changed the displayed setup values but did not advance any of the seven counters. These observations identify the +tested press callbacks, not the encoder's route or every possible event. The probe rolled back without a logged crash, +stall, freeze or skipped track. The test Part matched its original bytes before restarting; after restart the installed +base reported zero saved and live modules. + +**Encoder trace, MKII, 4 December 2026.** On the same development base, an expanded private, unkept probe +(`2ef58b0be602d572fec90e38307f60e2ddf671627622b022b39c59a694b2bf63`) counted nine candidate entries, with no +other modules loaded. One turn of each CTRL1 SETUP encoder C-F advanced 0x4003a7f4 once; one turn of each CTRL2 +encoder A-F advanced 0x4003a700 once. Each corresponding press again advanced 0x4003fc44 or 0x4003f71c twice. +The counters at 0x4004acf8, 0x4004ad80, 0x4003fd34, 0x4003f80c and 0x4004ae08 stayed at zero during these actions; +that does not rule out other contexts. Static disassembly indicates that the two encoder routines stage and clamp +values; the counters alone do not prove their full route to the writers. The trial was deliberately interrupted and +reported a clean rollback, with no logged crash, stall, freeze or skipped track. The test Part matched its original +bytes before restarting; the installed base then reported zero saved and live modules. + +An earlier expanded-probe attempt ended prematurely after USB suspension and could not confirm rollback. After a +restart, the installed base and empty set were verified. The successful retry kept the Mac awake, but does not prove +what caused the interruption. + +## What comes next + +After the FM and scale hooks: check the MIDI-learn siblings, the exact take point before the clamp and the route from +the encoder callbacks to the writers while adding the guarded entries to `events.json`. Regenerate with +`python3 -B sdk/machines/octatrack/events.py --write` and give each hook its subscriber in the MIDI NRPN module +(so `test_hook_coverage.py` passes). MIDI LEARN on an NRPN knob writes a plain CC number through the stock writers; +decide whether the module drops or keeps that knob's NRPN entry, and test the chosen behavior. Test the first +subscriber on a unit, including send, receive and removing the module while an NRPN knob is set. CC Map moves to +`ev_midi_cc` as #2436 describes. diff --git a/docs/README.md b/docs/README.md index 55d4f18406..095083416c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,6 +48,7 @@ Every document in `docs/`, one line each. [AGENTS.md](../AGENTS.md) says which t - [OCTATRACK_HARDWARE_TRAPS.md](OCTATRACK_HARDWARE_TRAPS.md): what fails on a real unit: the base, the USB link, RAM boot, the DSP loader. - [OCTATRACK_LFO_PMTR_EXTENSION.md](OCTATRACK_LFO_PMTR_EXTENSION.md): base-owned audio LFO SETUP destinations past stock 0–29 (`ot_lfo_pmtr_dest`). +- [OCTATRACK_MIDI_CTRL_HOOKS.md](OCTATRACK_MIDI_CTRL_HOOKS.md): proposed hooks on a MIDI track's CTRL SETUP and knob send, for NRPN (design). - [OCTATRACK_CARD_WRITES.md](OCTATRACK_CARD_WRITES.md): cold starts, card-write interrupts and every path that writes the card. - [OCTATRACK_TWO_SLOT_BASE.md](OCTATRACK_TWO_SLOT_BASE.md): base updates a power cut can't brick: two slots, a boot stub, the update on the unit's screen. - [OCTATRACK_DRIVING.md](OCTATRACK_DRIVING.md): working a unit over USB from an agent.