Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sdk/drafts/midi-nrpn/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"version": "0.1.1-experimental",
"date": "2026-12-05",
"changes": [
"Add a host-tested NRPN message and per-knob range core.",
"The module is not yet connected to the base or usable on an Octatrack.",
"Check a possible four-field page layout on paper; no page has been built.",
"Prepare resending NRPN selection after playback starts or a project loads."
]
},
{
"version": "0.1.0-experimental",
"date": "2026-12-05",
"changes": [
"Draft design for NRPN on MIDI track controls; not built or tested yet."
]
}
]
30 changes: 30 additions & 0 deletions sdk/drafts/midi-nrpn/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
MIT License

Copyright (c) 2026 huupsel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---

This licence covers this module's own source code and documentation only. It
does not extend to any Elektron Music Machines firmware, which is not
distributed here and remains the property of its copyright holder. Nothing in
this module is endorsed by, supported by, or affiliated with Elektron.
Octatrack and Elektron are trademarks of Elektron Music Machines MAV AB, used
only to identify the hardware this module targets.
89 changes: 89 additions & 0 deletions sdk/drafts/midi-nrpn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# MIDI NRPN

Version 0.1.1-experimental · by @huupsel · a draft, not tested on a unit.

## Overview

A MIDI track's CTRL1 and CTRL2 knobs send only CC 0-127. This module adds NRPN: past CC 127 in a knob's SETUP list comes NRPN, and pressing the knob there opens a small page for the NRPN number (MSB, LSB), value size and maximum. A knob set to NRPN sends and receives that parameter instead of a CC.

**Development draft:** the NRPN core has host tests. It is not connected to the instrument or installable.

## Controls

Per MIDI track and knob (CTRL1 CC1-CC4, CTRL2 CC5-CC10):
- Number: CC 0-127 (stock), then NRPN. Default: stock's.
- NRPN MSB and LSB: 0-127 each. Default 0 and 0.
- Maximum value: set per knob, default 127. Map the Octatrack's 0-127 knob to the parameter's 0-maximum range,
rounding to the nearest value (0-127 for 7-bit format; 0-16383 for 14-bit format);
for example, 128 positions span 0-164 for NRPN 34, so 37 values cannot be selected.
- Value format: choose 7-bit or 14-bit interpretation for the receiving device. The Octatrack knob itself remains 7-bit.

## Usage

Planned: on a MIDI track open CTRL1 SETUP or CTRL2 SETUP, turn a knob's number past CC 127 until it reads NRPN, press the knob for the NRPN page.

### Page fit (paper check)

A candidate page has four columns: `MSB`, `LSB`, `BITS` and `MAX`, with a value under each. Using a 4-pixel
character pitch (as used by the Octatrack Repitch widget), the longest values are `127`, `127`, `14` and `16383`:
12, 12, 8 and 20 pixels. Four 26-pixel cells starting at x=7, 35, 63 and 91 fit inside x=6–121, with gaps between
them; `BITS` is 16 pixels wide. With labels at y=12 and values at y=22, rows up to 7 pixels high also fit the
64-pixel screen without overlapping. This is a calculation, not a rendered page. Whether the agreed text hook can
provide that area, the actual font and spacing, encoder mapping and legibility still need an integrated build and
unit test.

### Messages (planned)

| Message | What the module does |
|---|---|
| Knob turn on an NRPN knob | The core sends CC 99 and 98 for a changed number, then CC 6 for a 7-bit value; 14-bit format splits the scaled value over CC 6 and CC 38. Choose 14-bit for a receiver that commits only on CC 38, even when its range ends at 127. Integration must serialize output and invalidate the selection cache when another sender changes it or a send fails. |
| Incoming CC 99, 98, 6, 38 | The core parses each channel separately: CC 6 yields a 7-bit value, and CC 38 completes a 14-bit value. It maps a matching value to the nearest knob position and clamps values above the configured maximum. The instrument's auto channel, both CC DIRECT CONNECT modes, routing and consumption still need integration and testing. |
| CC 101, 100 (RPN) | Passed through to stock. An incoming RPN select ends a pending NRPN select. |
| Every other CC, note, clock, start, stop, SysEx | Unchanged, as stock. |

A knob set to a CC number between 0 and 127 behaves exactly as stock.

## Quick tutorial

1. Set it up.
2. Change a control and hear what it does.
3. Get back to where you started.

## Compatibility and limitations

Not known yet. It needs base hooks that do not exist: the CTRL SETUP knob and draw, the outgoing knob value and the incoming CC. They are proposed on the cumulative Octatrack base draft, together with the shared CC-in hook of #2436, so it shares those sites with CC Map and the Midi Mode 2 draft instead of patching them. Its NRPN settings need the base's module-settings storage, because stock clamps the Part's CC bytes to 0-127.

The per-knob maximum and scaled values are implemented in the host-tested core only. Parameters with more than 128
possible values cannot all be selected individually with one 7-bit knob; MIDI receive feedback also rounds them.
The four-field page has only a paper fit check; the page, persistence, send and receive hooks have not been
implemented or tested on the instrument.

The proposed `project.work` format stores each configured knob as a versioned `#MODWERK_NRPN=` comment line with
bank, Part, track, slot, parameter number, size and maximum: for example, `#MODWERK_NRPN=1:0:0:0:0:34:14:164`.
Bank, Part, track and slot are zero-based. The core validates lines and rejects duplicate slots; the integration
must stage the full list and refuse to overwrite a malformed or newer-format project.

The sender's selection cache is per output stream and channel. Integration must serialize each complete packet and
lifecycle event, invoke `nrpn_tx_playback_start` at playback start and `nrpn_tx_project_load` on project load for
every output stream, and invalidate the affected stream on other senders' NRPN/RPN selections or failed sends.
These callbacks are host-tested but not connected to the instrument. Integration must also reset receive state on
Part or project changes so a partial message cannot set a knob in the new context.

## Tests and measurements

See [TESTING.md](TESTING.md).

## Authorship and licences

Your own code under the licence in LICENSE. Name anyone whose work it builds on.

## Screens and audio

None yet.

## Develop

- Hear it: `npm run module:dev -- midi-nrpn` builds it and tries it on your unit over USB; `--watch` does that again on every save.
- Check it: `npm run module:doctor -- --draft midi-nrpn`. Its experimental lines must be green to share the draft; its release lines say what listing it needs.
- Before you write any code: no heavy ColdFire design. Audio work goes on the DSP, and nothing runs every frame that could run less often (docs/module-guides/README.md, Keep the ColdFire cheap). Measure the first build that plays with npm run device:price.
- Before you write ColdFire code: the traps in sdk/octabam/AGENTS.md, and docs/OCTATRACK_API.md for the hooks a module can use.
28 changes: 28 additions & 0 deletions sdk/drafts/midi-nrpn/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Midi Nrpn testing

0.1.1-experimental: the protocol core runs on the host; the Octatrack module is not built.

Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones.

## On the unit

Not tested. No NRPN send, receive, persistence or UI has run on a unit.

## Host

`python3 -B sdk/drafts/midi-nrpn/test_nrpn.py`: passed on the host. Exercises the C core's 7/14-bit messages,
per-channel selection, playback-start and project-load cache resets, RPN cancellation, scaling and project-line
validation. It does not test the
instrument's routing, wire timing, storage integration or panel.

The candidate four-column page was checked by calculation using a 4-pixel character pitch and all permitted field
values. Each fits its 26-pixel cell; this does not verify the actual font, available hook drawing area or legibility.
No NRPN page was rendered or run on a unit.

## Stock flows

Not tested. List the stock flows you compared with and without the module (docs/module-guides/README.md, Leave stock flows alone).

## Performance

Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template coldfire (docs/MODULE_PERFORMANCE.md).
78 changes: 78 additions & 0 deletions sdk/drafts/midi-nrpn/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""<Module name> -- one line on what it changes in the firmware.

THE SKELETON OF A COLDFIRE MODULE: code the build links and places for
you, reached from stock code by detours you name by SYMBOL.
`npm run module:new` made this draft under sdk/drafts/. It builds as it is:
`npm run module:dev -- <id>` tries it on your unit over USB, and
`npm run module:doctor -- --draft <id>` checks it.

sdk/octatrack/modules/repitch/ is a finished one (one linked unit, detours,
pokes); sdk/octatrack/modules/quantizer/ another (units built from the
author's source, kept under upstream/). sdk/octabam/docs/remixer/MODULES.md
"Declaring a ColdFire module" is the guide; sdk/octabam/docs/remixer/PLACEMENT.md
says where the bytes go; docs/OCTATRACK_API.md lists the hooks.

Say what the module is, which stock routines it changes, what is measured
and what is inferred. Delete every comment below once answered.
"""

from remix.schema import Category, Proof, Gate, Detour, Kind, Linked, Module, Poke
from remix.stock_guard import stock_guard

MODULE = Module(
# `name` MUST equal the directory name. `key` is the build identifier and
# appears in the build report, which other tools parse -- so it is API.
name="midi-nrpn",
key="MIDI NRPN",
kind=Kind.CF_PATCH, # no DSP code, no chooser row
doc="One line, shown in the build report.",
category=Category.TRACK, author="huupsel", author_url="https://github.com/huupsel",
proof=Proof.UNTESTED, proof_note="Development scaffold; no module behavior has been verified.",

# ---- the code: GNU-as units, linked by the build ----------------------
# ORDER IS LINK ORDER: a unit may reference symbols of units before it.
# `dram=True` puts the unit in the platform runtime (linked with every
# other DRAM unit in the remix, appended behind the loader, depacked at
# boot into the platform's 10 MB reserve at the bottom of the audio
# page arena -- where anything bigger than a few hundred bytes
# belongs; the unit gives up 10 MB of sample memory). `dram=False` places
# it in one of the OS image's free zero runs (~8 KB, shared by everyone)
# for code that must be ROM-resident. Sources are `.s` for m68k-elf-as;
# `cpu="5407"` and "5475" encode this ISA subset identically.
linked=(
Linked("unit", "modules/midi-nrpn/unit.s", dram=True),
# Building from someone else's repository? Add it as a submodule
# under modules/<name>/upstream and point `source` into it; the
# sources stay theirs and an update is a submodule bump.
# `reference=(addr, sha256)` re-links the unit at the AUTHOR'S own
# address on every build and compares, so a drift from the bytes
# they ratified fails loudly.
),

# ---- how stock code reaches it: detours, wired by symbol --------------
# `site` is a stock instruction; `expect` its bytes (whole instructions,
# asserted before anything is written -- a site that has moved stops
# the build). `kind`: "jmp" for a stub that replays what it displaced
# and jumps on (the common case), "jsr" for a callable that returns,
# "lea" to rewrite a six-byte `lea abs.l,An`'s operand. `pad_to` nops
# the rest of a displaced span longer than six bytes.
detours=(
# Detour(0x400xxxxx, stock_guard(0x400xxxxx, 8, "<sha256>"), "unit", "my_hook",
# "what this hook is for", kind="jsr", pad_to=None),
),

# ---- plain asserted rewrites ------------------------------------------
pokes=(
# Poke(0x400xxxxx, expect=stock_guard(0x400xxxxx, 2, "<sha256>"),
# write=bytes.fromhex("6012"), note="bne -> bra: never re-apply"),
),

gates=(Gate("modules/midi-nrpn/verify.py", remix_arg=False),),

# A stock pointer array that needs more entries: TableGrow relocates it
# into free space with your symbols appended and repoints every
# reference.
# tables=(TableGrow("...", old=0x400xxxxx, count=16,
# symbols=(("unit", "my_row"),),
# refs=((0x400xxxxx, 0x400xxxxx),)),),
)
Loading
Loading