Skip to content

Octatrack base: the base keeps the project's SCALE, ROOT and FOLLOW, and modules snap notes through ev_scale_snap - #2415

Draft
timhastie wants to merge 9 commits into
repeat98:base/octatrack-nextfrom
timhastie:shared-scale-base
Draft

timhastie wants to merge 9 commits into
repeat98:base/octatrack-nextfrom
timhastie:shared-scale-base

Conversation

@timhastie

@timhastie timhastie commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

The base now keeps the project's SCALE, ROOT and FOLLOW, and any module can ask it to snap a note with one call, ev_scale_snap(track, pitch). Projects saved with Scale Quantizer or FM Synth keep their scale. Merged with base/octatrack-next after #2352. Draft: published Scale Quantizer and FM Synth are refused on this base until their updates read its state, as agreed on #1145.

Related to #1145.

What was wrong or hard: Scale Quantizer and FM Synth each keep their own 24-scale SCALE, ROOT and FOLLOW, so a module that wants to play in the project's scale has to depend on one of them. You asked for the scale in the base, wired to the saved settings, with one "snap this note for this track" event (#1145, 21 Nov).

What this changes:

  • PROJECT > CONTROL > SEQUENCER shows SCALE (OFF or one of the 52 catalogue scales), ROOT, TRACK and FOLLOW with no module installed. They sit after stock's three rows, before any module's, through the existing SEQUENCER table reader in machine_registry.c.
  • The project saves them as one line, #MODWERK_SCALE=1:scale:root:audio-off:midi-off, through fxmap.c's existing project-file seams (staged while loading, kept only when the load succeeds). Battery RAM keeps them across a power cycle or RAM boot (MWSC, a new base range in battery-ram.json, 0x100f8f40-0x100f8fc8). No new stock site.
  • ev_scale_snap(track, pitch): tracks 0-7 take semitones (64 is the untransposed note), tracks 8-15 MIDI notes. It answers the nearest note in the scale, the lower one on a tie, 0-127, and leaves the note as it is for SCALE OFF, FOLLOW OFF or an out-of-range input. It is a new accessor kind: the base provides it and a module can only call it. The loader and the site refuse anything but a zero raise slot on it.
  • ev_project_new gets a base handler, so PROJECT > NEW and the start of CHANGE or RELOAD reset to OFF, C, every track following, as Scale Quantizer's defaults did.
  • Legacy translation, as you described: the old #SEQUENCER_SCALE, ROOT, AUDIO_SCALE_OFF and MIDI_SCALE_OFF lines go through the shared table from Improvement: a shared scale file for the Octatrack SDK, with its host test #1631 (modwerk_scale_from_quantizer) once at load; a #MODWERK_SCALE line wins. On the first boot without an MWSC record, the base reads Scale Quantizer's and FM Synth's saved bytes the same way.
  • A #MODWERK_SCALE line from a newer version, or a damaged one, is never guessed: that project plays no scale, the SCALE row shows NEWER or BAD, and a save writes the line back as it was (up to 115 characters). Editing SCALE, ROOT or FOLLOW replaces it.
  • Draft limit: machine_admission_runtime.c refuses Scale Quantizer and FM Synth by module id, so every version (FM Synth 0.1.6 included), at PREPARE and SWITCH on a base with ev_scale_snap, because they would play their own scale while the rows show another. Removing them stays allowed, and a saved set that names one restores without it. Before the base ships, their updates have to read the base state (or the base has to cover them by translation), and this guard comes out. Their updates follow as their own pull requests. As I said on this pull request on 4 December, FM Synth 0.1.6 with the detours off is fine to ship with the base; my FM Synth update that reads the base's scale follows it.
  • Shared SDK file: modwerk_scale.s read its table with a 16-bit PC-relative lea. The base places .rodata more than 32 KB from its code (74,096 bytes), so the base could not link it. It now reads a 32-bit PC-relative offset word beside the code. The snap is the same, and it still links anywhere.
  • scale.c and scale_state.c build with -Os (SIZE_OPTIMIZED, beside the base's own list).

Index: ev_scale_snap is 91, the next index after #2352's 69-90 (66-68 are kept for CLYPS). I merged base/octatrack-next (bfe926476) once, as you asked: the merge took #2352's 66-90 entries, so the placeholder tables are gone and no ot_reserved_66..90 is left. Against the base, this branch now adds only hook octatrack/91, which is claimed on the agent board for this pull request.

The merge (7bcb7b0cc, a merge commit, no rebase): conflicts in events.json, unused-hooks.json, site-events.json and the three generated hook files (taken from the base, 91 added, regenerated with events.py --write), in test_runtime_loader.py (the base's 66-68 plus 91), in build_core.py's SIZE_OPTIMIZED (both lists kept) and in battery-ram.json: Output Matrix 0.2.0's MET_REC (0x100f8f30-0x100f8f32) now sits inside the range MWSC had, so MWSC moved past it to 0x100f8f40-0x100f8fc8 (the same 136 bytes). USB Audio's two reconstruction records re-pin the regenerated modwerk_events.h again.

Base size (node scripts/base-size.mjs on the merged head): Octatrack base 0.8.7: 850,956 of 851,712 container bytes, 756 free (largest layout off; MAIN 1,365,375 of 1,572,864). With this change the packed beta base is 854,028 bytes, 2,316 over the flash slot: it takes 3,072. You said you would make the room at the fold, so I have cut nothing.

Build tested: development twin cd84b551 (configuration hash cd84b5510d2f775b39b6086fd423707550df982969e677bc9e62c99f0cd37276; MAIN.raw sha256 9c782a0206c8bcefa85515b5d8d6f59b2ae7de1fb59fbf91b90cc9aa39d5e511, 1,371,342 bytes) of 7bcb7b0cc: build_core.py --dev with the flags octatrack-base.mjs passes for --beta, without the controller rows (docs/OCTATRACK_DRIVING.md). It packs 857,644 bytes, 5,932 over the flash slot; unchanged base/octatrack-next packs 854,188 the same way (2,476 over, 64 over without --stream-channel), so no twin of 0.8.7 builds under the slot today. I built it with only build_core.py's slot refusal lifted, for RAM boots (a RAM boot sends MAIN.raw and writes no flash). Everything else in the build ran as it is. It was never flashed.

Left to the fold, as you asked on #2352: base identity, rebuilt assets and requiredBase. So octatrack-base.test.ts reports the committed base as stale; that is the one test this branch fails.

How I checked it (on 7bcb7b0cc):

  • npm run pr:ready -- --base-branch base/octatrack-next --remote origin --draft: every stage before test passes (prepare, licenses, machines, modules with the Tape Echo gate, elekloader, compat, the three generators, board, lint, typecheck, bundle), and the generators leave the tree clean. Its whole-suite Vitest run was still going after 22 minutes, the zoom-file hang I saw on an unchanged base on 28 November; the only failure it had printed was the stale base. Without the zoom files: 4,252 pass, 1 fail, the stale base. This branch touches no zoom or MIDI file.
  • npm run sdk:check: 880 cases, all pass except the two USB Audio trim tests and test_usb_midi_shared_framer.py, which need ctypes or Unicorn memory hooks, off on my test computer; they fail the same way on an unchanged base/octatrack-next.
  • python3 -B sdk/machines/octatrack/events.py --check and hook_coverage.py: pass.
  • test_runtime_loader.py 26 OK (1 skip, the opt-in private firmware case), all published packages rebuild byte for byte; test_base_scale.py 9 OK (the ColdFire build under Unicorn through the generated accessor included); test_base_scale_state.py, test_shared_scale.py (9), test_machine_events.py (22, the admission guard), test_hook_coverage.py, test_battery_ram.py, elekloader/test_recipe.py (43): all OK.
  • Stock bytes: 16-byte windows of every line this branch adds against the stock OS image, as text and as hex: no hits.
  • The second, independent check from 28 November (the 24-to-52 table, 4,725,864 ColdFire snap answers, 989,423 host checks) covered code this merge did not change; only the record's address moved, and test_base_scale.py checks the record at its new address.

Emulator rehearsal (emulator results, not hardware): ot_emu --dsp with the MKI panel on the twin above, no module installed, a project saved with Scale Quantizer.

Step Result
Boot with Scale Quantizer's saved bytes (BLUES, E) and no MWSC record rows show BLUS, E, AUDIO 1, FOLLOW ON; record written at 0x100f8f40; Output Matrix's 0x100f8f30 untouched
PROJECT > RELOAD of the Scale Quantizer project its lines read: MAJ, C, its FOLLOW OFF tracks kept
SCALE +1, TRACK AUDIO 2, FOLLOW OFF DOR; battery and live value follow
SAVE PROJECT the card holds #MODWERK_SCALE=1:2:0:134:2 in the project and its saved copy
PROJECT > CHANGE to a project without scale lines, then back OFF there; DOR, C, AUDIO 2 OFF again
Power-up DOR, C, AUDIO 2 OFF
A #MODWERK_SCALE=2: line, RELOAD, SAVE PROJECT, power-up NEWER, no scale; the save writes the line back as it was; NEWER again after the power-up
Base 0.8.7 without this change booted on that battery, then this twin again 0.8.7 leaves the record and Scale Quantizer's bytes as they were; DOR, C, AUDIO 2 OFF again
Install Scale Quantizer 0.1.5 refused: loader refusal 3, RUNTIME_CONFLICT (unchanged 0.8.7 twin: accepted)
Install FM Synth 0.1.5 refused: loader refusal 9, RUNTIME_EVENT, as on unchanged 0.8.7 (its sites are #2352's events now)

Tested on a unit: twin cd84b551, MKI, 4 December 2026: tests 1 to 5 and 7 pass (test 3 without its RELOAD and CHANGE steps, which I did not confirm); 6 not run (no caller yet). The unit ran Modwerk base 0.8.5 (ddb56b72) from flash and the twin from RAM, three RAM boots, all clean.

Test Result on the MKI
1. RAM boot the development twin (never a flash) pass: three RAM boots over base 0.8.5, each to the normal screen, no refusals
2. PROJECT > CONTROL > SEQUENCER with no module: SCALE, ROOT, TRACK and FOLLOW show and change pass: the four rows after the stock rows; the encoder changes each; FOLLOW changes only the track TRACK names
3. A project saved with Scale Quantizer: RELOAD and CHANGE show its scale; another one saved, power cycle, rows read pass in part: another scale and root saved (#MODWERK_SCALE=1:6:5:0:2), power cycle, RAM boot: the rows show them. RELOAD and CHANGE not confirmed on the unit (test 5 shows RELOAD reading the line)
4. Scale Quantizer or FM Synth install refused; a saved set that names one reports it missing pass for the installs: Scale Quantizer 0.1.5 refused, loader refusal 3 RUNTIME_CONFLICT; FM Synth 0.1.5 (the site's package) refused, loader refusal 9 RUNTIME_EVENT; the unit kept running and showed only MODWERK CONNECTED. The saved-set case was not run
5. A newer or damaged scale line across a RAM boot pass: a 2: line shows NEWER after RELOAD; SAVE PROJECT writes it back unchanged in project.work and project.strd; after a power cycle and RAM boot, NEWER with no RELOAD. 1:99:0:0:0 shows BAD; a scale set and saved makes a normal 1: line. Editing FOLLOW on a NEWER project turns SCALE to OFF, as documented
6. ev_scale_snap from a real installed caller not run: no module calls it yet
7. RAM boot back to the starting base: modules and Scale Quantizer's settings come back pass: a power cycle starts base 0.8.5 again; it had no modules installed before the run, so there was nothing to restore

Nothing audible changes yet: no module calls ev_scale_snap until a module's update does.

Edge cases

Case Why this change makes it a risk How run Result
Project saved with Scale Quantizer the base now reads its 24-scale lines host: all 25 values × 12 roots, shuffled order; emulator: RELOAD pass (host, emulator)
First boot with Scale Quantizer's or FM Synth's saved bytes the base reads them once without a record host: SCALE 0-26, bad ROOT; emulator: BLUES, E pass
SAVE PROJECT, power cycle, RELOAD new project line and battery record host: every SCALE × ROOT × 6 FOLLOW pairs; emulator: once; MKI: test 3 pass (host, emulator, MKI)
A scale line from a newer base, or damaged it must not be guessed or lost host: 12 kinds of line, across a power cycle and a save; emulator: a newer line through RELOAD, a save and a power-up; MKI: test 5 pass (host, emulator, MKI)
A line longer than 115 characters the record keeps 115 host pass: kept up to 115, dropped at 116, as documented
Corrupted battery record the record is read at boot host: one-bit flips across the record pass: never trusted
The battery record's new address the merge moved MWSC past Output Matrix's MET_REC test_battery_ram.py (no overlap); emulator: the record written at 0x100f8f40 at boot, 0x100f8f30-0x100f8f32 untouched pass
PROJECT > NEW, CHANGE the new base handler resets the scale host: NEW resets; emulator: CHANGE away and back pass (host, emulator)
ev_scale_snap at every track and pitch the new event's answer ColdFire under Unicorn, through the generated accessor pass: 2,048 and 4,725,864 answers
A module trying to replace or subscribe to the accessor the base must stay the provider host: events_test.c, loader, site test pass: refused
Installing Scale Quantizer or FM Synth 0.1.5 the draft guard host: PREPARE, SWITCH and replace refused, removal allowed, other modules allowed; emulator: install of each; MKI: test 4 pass (host, emulator, MKI installs)
Whole-set trial (TEST_PROCEDURE step 7) the guard refuses two packages not run not run: it refuses Scale Quantizer and FM Synth by design until their updates
RAM boot to an older base and back Scale Quantizer's bytes may change in between host: bytes read again when they changed; emulator: 0.8.7 booted between; MKI: test 7 pass (host, emulator); MKI: base 0.8.5 back after a power cycle, no modules installed to compare
Opening a project saved here on an older base it has no #SEQUENCER_ lines reasoning not run: known limit, it starts with SCALE OFF there (below)
Base size 3 KB more code in a full slot npm run octatrack:base -- --beta, base-size.mjs fail: 2,316 bytes over the flash slot; room at the fold, as you said
MKI panel the rows had never run on an MKI emulator with the MKI panel; MKI: test 2 pass (emulator, MKI)

Known limits:

  • A project saved on this base keeps its scale only in the #MODWERK_SCALE line, so an older base opens it with SCALE OFF.
  • The battery record is not tied to the project. After a RAM boot into a base that does not write Scale Quantizer's bytes, a project change there, and a RAM boot back, the rows keep the previous project's scale until RELOAD. Scale Quantizer behaved the same way.

Disclosures:

  • test_shared_scale.py now expects R_68K_PC32 instead of R_68K_PC16, with the modwerk_scale.s change above. Its note-for-note tests are unchanged and pass.
  • USB Audio's two reconstruction records re-pin modwerk_events.h (the hash only; the images are unchanged), first in their own commit and again in the merge. You can drop or regenerate them at the fold.
  • src/engine/elekloader/module-set.ts changes 4 lines (the accessor's raise slot). The Tape Echo gate passed with it.
  • The tested twin was built over the flash slot with that one refusal lifted (Build tested, above).

Who must act: you, at the fold: the room for this change and the base identity. Before release: my Scale Quantizer and FM Synth updates, then the guard comes out.

Guides: the SDK README's shared-scale section, HOOKS.md (generated) and the ot_sequencer_rows and ev_project_new contracts now describe the base's scale. What they lacked: the shared scale read its table with a 16-bit PC-relative lea, which links into a module or a card build but not into the base; the README now says how it reaches the table.

  • Source and media are mine or properly licensed, with authors and full licence texts kept. Nothing comes from Elektron firmware: no extracted code or tables, upgrade files or factory content, and nothing is modelled on another current Elektron product.
  • Screenshots are real captures of the current module UI. Hardware results are what a named person saw on this exact build; emulator results are labelled as emulator results.

…next hook is 91

The registry ends at 65 on base/octatrack-next (28 November 2026). The owner
keeps 66-68 for CLYPS (repeat98#1997) and confirmed repeat98#2352's 69-90 there. These
placeholder tables, shaped as ot_reserved_64, let a hook at 91 follow without
a gap; each is replaced in place when its owner lands, and the whole commit
drops if repeat98#2352 folds first.
…ap (repeat98#1145)

The base owns the project's shared scale (elekloader/scale.c): SEQUENCER rows
SCALE (OFF or one of the 52 catalogue IDs), ROOT, TRACK and FOLLOW before any
module's; a '#MODWERK_SCALE=1:scale:root:audio-off:midi-off' line in
project.work through fxmap.c's seams (staged on the storing pass, in force when
the load succeeds); an 'MWSC' record in battery RAM (0x100f8f28-0x100f8fb0,
battery-ram.json). ev_project_new resets it first ("base" handler in
events.json, events.py).

ev_scale_snap (91, the next free index on 28 November 2026; it follows merge
order) is a base accessor: a module raises it as any raised event and its
raise entry tail-calls modwerk_scale_snap_track(track, pitch), which reads one
word. Audio tracks pass semitone raw (64 the untransposed note), MIDI tracks
MIDI notes; SCALE OFF, FOLLOW OFF or an out-of-range input comes back
unchanged. To the package builder an accessor is a raised call event, so
build.py and every recipe pinning it stay as they were; the loader and the
site refuse a subscription to it.

Saved projects keep their scale: Scale Quantizer's and FM Synth's
'#SEQUENCER_SCALE' lines, and on the first boot their bytes in the stock
settings block, are read once through modwerk_scale_from_quantizer. A
'#MODWERK_SCALE' line this base cannot read (a newer version, or damaged)
plays no scale, shows NEWER or BAD, and is written back as it was.

Draft limit: published Scale Quantizer and FM Synth keep their own 24-scale
state, so a base with ev_scale_snap refuses to install them at PREPARE and
SWITCH (removal allowed) until their updates read the base's (owner, repeat98#1145,
24 November 2026).

Tests: test_scale.c and test_fxmap_scale.c on the host, the ColdFire build
under Unicorn through a module's raise slot, the admission guard, registry
and builder checks (sdk/tests/test_base_scale.py).
… can link it

The base links every .text before every .rodata, so modwerk_scale.s's
16-bit PC-relative lea to its .rodata table spanned 74 KB and the base
link refused it. The code now reads a 32-bit PC-relative offset word
beside it (R_68K_PC32, which the base link, ld and runtime packages all
resolve) and adds it: no absolute reference, the same bytes at any
address, the same snap (test_shared_scale.py's note-for-note runs).
test_scale.c's plain line no longer spells a stock project-file key.
…changed)

The new hooks change the event header both records pin; the packages
rebuild byte for byte (test_runtime_loader's published-package rebuild).
The beta base with the shared scale packed to 851,836 bytes, 124 more than
a flash slot holds. scale.c and scale_state.c now build for size, as the
other files nothing times (SIZE_OPTIMIZED), and the TRACK and ROOT rows'
names lose their pointer tables: 1,141 bytes less code.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks Tim, this is careful work, and it follows what we agreed on #1145.

  1. Hook shape: yes. A base-provided accessor that modules can only call, and never subscribe to or replace, is the right shape for ev_scale_snap. Keep 91 and the placeholder commit until Base: FM engine take hooks for synth and cx-osc (69-90) #2352 merges, then drop the placeholders as you described.
  2. Draft limit: refusing Scale Quantizer 0.1.5 and FM Synth 0.1.5 is fine while this is a draft. It comes out before the base ships, once their updates read the base state.
  3. Base size: I'll make room at the fold, where the identity and assets get rebuilt anyway. You don't need to cut anything here for Base: FM engine take hooks for synth and cx-osc (69-90) #2352.

Next step is yours: run tests 1 to 7 on your MKI on the exact development twin, put the results and the build in the description, then run npm run pr:ready and mark it ready.

repeat98 commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Hi @timhastie, an update from the other side of the base, so you know what to expect.

Where it stands: the hook shape and the draft guard are settled (my 30 November comment). The branch now conflicts with base/octatrack-next, which has moved on to 0.8.6. #2352's FM engine hooks 69 to 90 are about to fold in, so I'd rather you merge once, after that, than twice. Your MKI run stays the next step after the merge.

What I'll need when #2352 is in (I'll ping you here):

  1. Merge base/octatrack-next (merge, don't rebase) and drop the placeholder commit for 66 to 90, as you planned, keeping 91 for ev_scale_snap.
  2. Then the MKI run of tests 1 to 7 on that merged head's development twin, with its build in the description.

One question only you can answer. #2352 moves FM Synth onto the new hooks, and FM Synth 0.1.6 (detours off, the same engine) is set to ship with that base from our side. FM Synth is yours, so:

  • Are you OK with that 0.1.6?
  • Your guard here refuses FM Synth by module id, so it would refuse 0.1.6 as well until FM Synth reads the base's scale. Would you rather put the scale read into that same update, or follow with your own update after it?
Base room

With #2352 the base has 848 container bytes free, and this change needs about 3.5 KB. As I said, I'll make the room at the fold. You don't need to cut anything.


Generated by Claude Code

@timhastie

Copy link
Copy Markdown
Contributor Author

@repeat98, thanks. Yes, FM Synth 0.1.6 with the detours off is fine to ship with that base. I'll follow with my own FM Synth update that reads the base's scale, so it's ready before #2415 leaves draft. Now that #2352 is in, I'll merge base/octatrack-next, drop the 66 to 90 placeholders and keep 91, then run tests 1 to 7 on my MKI and put the results and the build in the description.

repeat98 commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Hi @timhastie, thanks for the merge and the MKI run.

Where it stands: the base's SCALE, ROOT, TRACK and FOLLOW rows, the saved #MODWERK_SCALE line, the battery record and the NEWER/BAD handling all held on your MKI (tests 1 to 5 and 7 on twin cd84b551), and the Scale Quantizer and FM Synth refusals worked as designed. Musically nothing changes yet: no module snaps notes until your updates call ev_scale_snap. That covers what I asked on 3 December.

What's broken: nothing in your change. base/octatrack-next moved again after your merge (#2603, FM take rests), so GitHub shows a conflict. It's only in generated files: runtime_events.h and the modwerk_events.h pin in USB Audio's two reconstruction records. A trial merge resolves with events.py --write and the two re-pinned hashes. Please don't merge again for this. I'll do it when this folds, together with the room and the base identity.

Who acts: you, next. As you said, this stays a draft until your Scale Quantizer and FM Synth updates read the base's scale. One question before you start those, since only you can answer it:

  • When the guard comes out, what keeps a Scale Quantizer 0.1.5 or FM Synth 0.1.6 package that's already on a unit, or named in a saved set, from playing its own scale under the base's rows? Do you want the guard to stay for those versions and admit your new ones, or is something else meant to cover it? The guard compares module ids only (machine_admission_runtime.c), so today it refuses every version, the 0.1.6 that ships with this base included.

Next step: your answer here, then the two updates as their own pull requests, then the guard change on this branch. Nothing has to run on your unit again for that until the guard changes.

Checked on this pass
  • Hook index: ev_scale_snap is 91, directly after Base: FM engine take hooks for synth and cx-osc (69-90) #2352's 90 on base/octatrack-next. No other open pull request names 91, and main stops at 65 (62 ev_frame_deadline, 63 ot_lfo_pmtr_dest), so nothing collides.
  • Room: base/octatrack-next now records base 0.8.7 at 850,944 of 851,712 container bytes after Base: rest unused FM take hooks on the frame path #2603. Your change still needs about 3 KB; I'll make that room at the fold, as I said.
  • Checks: pull requests into base/octatrack-next only run the description check, and it passed on 7bcb7b0cc.

Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants