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
674 changes: 674 additions & 0 deletions sdk/digitakt/modules/shift-loop/LICENSE

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions sdk/digitakt/modules/shift-loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Shift Loop

A looping shift register for the Digitakt mk1. As the playhead leaves a step, the register shifts and writes that step's note, and if you like its trig and velocity, for the next pass. Lock the loop you like, let it drift a little, or let it change completely. The idea comes from Music Thing Modular's Turing Machine; the code is original.

By ivanfrency (@ivanfrency) · GPL-3.0-or-later · Digitakt OS 1.54 · version `0.1.0-experimental` · **emulator-tested only, not yet run on a unit**

**Status: experimental.** It has not run on a unit yet, so it is not in the library; the hardware test in [TESTING.md](TESTING.md) comes first.

## Overview

- **A register per track.** Each of the 16 tracks can run its own register of 2 to 16 bits. With MUT at 0 it repeats after LEN shifts, so the melody loops.
- **Mutation.** MUT is the chance that a bit flips as it comes round: 0 locks the loop, 50 is all chance, 100 inverts the register every pass, which doubles the loop.
- **Notes.** The register, read as a number, picks a note in the chosen SCALE, up to RANGE scale notes above the track's own NOTE. Change the track's NOTE to transpose the whole loop.
- **Rhythm.** GATE OFF leaves your trigs and changes only their notes. GATE 1–127 lets the register add and remove trigs: the higher, the more steps play.
- **Timing is the Digitakt's own.** Shift Loop keeps no clock. It reads each track's playhead from the sequencer and writes ordinary step data one step behind it, so the loop follows the tempo, the track's length and speed, and swing.

## Controls

The page shows the track (T1–T8 audio, M1–M8 MIDI) and its length, the register as a row of boxes (the newest bit on the right) and the eight controls.

| Knob | Control | Range | What it does |
| --- | --- | --- | --- |
| A | LEN | 2–16 | Register length in bits |
| B | MUT | 0–100 | The chance a bit flips as it comes round |
| C | SCALE | CHROM, MAJOR, MINOR, DORIAN, MIXO, MAJPEN, MINPEN | The notes allowed |
| D | RANGE | 0–24 | Scale notes above the track's NOTE |
| E | GATE | OFF, 1–127 | OFF keeps your trigs; otherwise how many steps the register lets play |
| F | VEL | 0–127 | How far velocities spread around the track's VEL; 0 leaves them |
| G | DIV | 1, 2, 4 | Shift every 1, 2 or 4 steps |
| H | ON | OFF, ON | Follow the register on this track |

| Key | On the page |
| --- | --- |
| LFO, twice | Opens the page on the active track (from any page); a second double press closes it. FUNC + LFO stays the stock compressor shortcut |
| SETTINGS > SHIFT LOOP | Opens the page too |
| YES | A new random register |
| LEFT / RIGHT | Shift back once / shift on once |
| NO | Closes the page; tracks that are ON keep following |
| PLAY, STOP | As usual |

## Usage

Shift Loop edits the active audio track. It writes into the pattern while it plays, one step behind the playhead, so what you hear is always ordinary trigs and notes.

### Where to find it

- Press LFO twice quickly. The first press shows the stock LFO page; the second opens Shift Loop.
- Or open SETTINGS, select SHIFT LOOP and press YES.

### Quick tutorial: a melody that repeats and drifts

1. Put trigs on an audio track, then press LFO twice quickly to open Shift Loop.
2. Turn H to ON and press PLAY: from the next step on, each step's note follows the register.
3. Turn B (MUT) up a little to let the melody drift, back to 0 to lock the loop you like.
4. Turn E (GATE) up to let the register choose the trigs too; NO closes the page.

## Compatibility and limitations

Requires core 4.4 on OS 1.54. It takes a double press on LFO and the SETTINGS row SHIFT LOOP.

- **It writes into the pattern.** Notes, and with GATE trigs and velocities, are ordinary step data. Saving the project saves them as they are; turn H off to keep a loop. GATE removes trigs, with their locks, where the register says rest.
- Its settings are not saved: after a power cycle every track starts OFF.
- Only the pattern that plays is written. While another one is queued or being edited, Shift Loop waits.
- With Euclidean on the same track, keep GATE OFF: Euclidean moves trigs itself.
- Per-step Note Accumulator adds its steps on top of Shift Loop's notes.

### Changes to stock flows

- **LFO, twice:** opens Shift Loop. The first press shows the LFO page as stock does; FUNC + LFO still opens the compressor. digidice uses a double press on TRIG the same way.

## Tests and measurements

Emulator only so far: see [TESTING.md](TESTING.md) for what was run, what was not, and the hardware test plan. Load on a unit is not measured yet.

## Authorship and licences

Design and code by ivanfrency, with Claude Code. GPL-3.0-or-later: see [LICENSE](LICENSE). The looping shift register with a flip chance is the idea behind Music Thing Modular's Turing Machine (Tom Whitwell); no code, artwork or name from it is used. Built on [elekloader](https://github.com/irpina/elekloader)'s core and SDK and tested in [digiemu](https://github.com/irpina/digiemu), both by irpina. The pattern writers come from [pattern-write.md](../../research/pattern-write.md); the playhead is mapped in [RESEARCH.md](RESEARCH.md). Screens show Elektron's interface solely to document the modification. No Elektron firmware is included.

## Screens and audio

These captures show the **OS 1.54 build with core 4.4 and Shift Loop alone**, booted in the pinned digiemu with firmware-native drawing. See [capture provenance](media/capture.json) for hashes and panel inputs. There is no audio recording yet.

![The Shift Loop page after a double press on LFO: the register as sixteen boxes and the eight controls.](media/page-open.png)

![Track 1 ON, MUT 0, GATE 30.](media/page-on.png)
35 changes: 35 additions & 0 deletions sdk/digitakt/modules/shift-loop/RESEARCH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Each track's playhead (Digitakt mk1, OS 1.54)

Shift Loop writes a step after the playhead has left it, so it needs to know which step each track plays now. No Modwerk module read this before.

**Status:** static analysis of the stock OS 1.54 MAIN image (SHA-256 of the `.syx` `f78ba80f…3e3cf6`, as in [machine.json](../../../machines/digitakt/machine.json)), then checked in digiemu (see [TESTING.md](TESTING.md)). Nothing here has run on a unit. Confidence: **H** read in the code, **M** strong inference, **E** confirmed in the emulator.

## The sequencer's per-track arrays

The level-2 sequencer interrupt steps each of the 16 tracks (0–7 audio, 8–15 MIDI) in one loop (`0x40070a98`–`0x40070ba0`, H):

| Address | Type | What | Conf. |
| --- | --- | --- | --- |
| `0x4199ebbc` | u32[16] | 1 while the track runs | H |
| `0x4199ec0c` | s8[16] | ticks into the current step; the step ends at the count `0x4018ed20[speed]` gives | H |
| `0x4199ec1c` | u8[16] | **the step playing now**: set from the next-step byte when a step starts | H |
| `0x4199ebfc` | u8[16] | the next step; wraps to 0 at the track's length (`track + 0x388`), or at the pattern's length (`pattern + 0x54`) when the scale mode is per pattern | H |
| `0x4199ec71` | s8[16] | the track's speed index (`track + 0x38b`, or the pattern's at `pattern + 0x1ec5a`) | H |
| `0x4199ec2c` | u32 | transport: 1 while playing (digiemu's `transport_state`) | H |
| `0x4199ec38` | u32 | the playing pattern's data; track t at `+ t * 0x38f` | H |

On each wrap the interrupt calls `0x400eaf66(track)` (H; what it does is not mapped).

The PLAY routine (`0x4006e816`–`0x4006e8fe`) seeds `0x4199ebfc` from a saved per-track step at `0x4199ed0b` and the same wrap rule (H).

## Reading it from a mod

The bytes are written by the interrupt and read by Shift Loop from `ev_tick` (the UI's 30 Hz check). A byte read is atomic, so no lock is needed for it. At a 30 Hz tick a fast track can move more than one step between two ticks; Shift Loop handles every step it missed, in order.

Before writing, Shift Loop compares the edited pattern's track data (`OS_PATTERN`, `OS_PTRACK`, vtable slot 10: [pattern-write.md](../../research/pattern-write.md)) with `0x4199ec38 + t * 0x38f`, and writes only when they are the same, so a queued pattern or one being edited is left alone.

## Still to check on a unit

1. `0x4199ec1c[t]` follows the playhead on a unit at track speeds other than 1x and with per-track lengths.
2. Swing and micro timing do not move the step byte early or late enough to matter for a write one step behind.
3. OS 1.53 is not mapped.
51 changes: 51 additions & 0 deletions sdk/digitakt/modules/shift-loop/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Shift Loop: testing

**Emulator only. Nothing here has run on a Digitakt.** Until it has, Shift Loop stays experimental and out of the library.

## What was run

| | |
| --- | --- |
| Stock OS | Digitakt mk1 OS 1.54, SHA-256 `f78ba80f…3e3cf6` (as in machine.json), kept outside the repository |
| Build | `node scripts/link-image.mjs` with `core-4.4-os1.54.elemod` and `--module digitakt:shift-loop` (Shift Loop alone) |
| Emulator | digiemu revision `c1b5735` with its six pinned Unicorn patches; `emu.session.Session(..., audio=True, hle=False)`, so the audio callback drives the sequencer's tick |
| Project | the emulator's default project (pattern A01 "SUBAQUATIC"), track 1 at 1x, 16 steps |

The firmware, the builds, the emulator's cards and snapshots stay on the developer's computer.

## Host tests

`cc -std=c99 -Wall -Wextra -Werror -I src tests/test_engine.c src/engine.c` passes: at MUT 0 the register repeats after LEN shifts for every length 2–16; at MUT 100 it is inverted after LEN shifts and back after 2 × LEN; an unshift undoes a shift; the register never leaves its length; DIV shifts every 1, 2 or 4 steps; every note is in the scale and within RANGE; GATE 127 plays every step; velocities stay in 1–127; notes clamp at 127.

## Emulator results (6 December 2026)

Build with SHA-256 `0837ab4d…bef81` (the drawing of the register boxes changed after it; the screenshots are from the next build, `be654ea4…448a8f`).

1. **Opening.** Two presses of LFO 140 ms apart open the page on track 1. The page stays open while its knobs turn.
2. **The playhead.** With PLAY, `0x4199ec1c[0]` read every 400 ms: 1, 4, 7, 9, 12, 14, 1, 4, 6, 9, 12, 14, 1, 3, 6; `0x4199ebfc[0]` was each time the step after it, wrapping at 16. The transport word `0x4199ec2c` read 1 throughout.
3. **Writes, GATE OFF, MUT 0, MINPEN, RANGE 8.** Track 1's trigs were on steps 4, 5, 7, 8, 12, 13, 14 and 15 (indexes 3, 4, 6, 7, 11–14). After 6 s their NOTE bytes read 72, 65, 63, 65, 75, 70, 60, 63: the track's NOTE (60) plus 12, 5, 3, 5, 15, 10, 0, 3, all in the minor pentatonic. Steps without a trig were left as they were.
4. **A locked loop.** At MUT 0, two further 2 s passes left all sixteen NOTE bytes the same as after the first.

## Not shown

- Anything on a unit: timing against the audio, the UI task's CPU time, and whether a note written one step behind is always heard on the next pass.
- GATE on (adding and removing trigs), VEL, DIV 2 and 4, MUT above 0 while playing, LEN below 16.
- Track speeds other than 1x, per-track lengths, swing, tempo changes, pattern changes and queued patterns.
- MIDI tracks.
- SETTINGS > SHIFT LOOP (the row is built; it was not opened in the emulator).
- Saving and reloading a project after Shift Loop wrote into it.
- A double press on LFO on the stock OS, compared with this build.
- Beside other mods (Euclidean, Per-step Note Accumulator, digidice).

## Hardware test plan

On a Digitakt mk1 with OS 1.54, flashed with a private build:

1. Four trigs on track 1, open Shift Loop (LFO twice), ON, MUT 0, PLAY: the notes change on the second pass, then repeat.
2. MUT 20: notes change now and then; MUT 0 again: the loop stays.
3. GATE 64: trigs appear and disappear; GATE OFF: the trigs as they are stay.
4. Track speed 2x and 1/2x, track length 7 (per-track scale), swing 60 %: no note is late or doubled.
5. Pattern change at the loop point and a queued pattern: the next pattern is not written until it plays.
6. A MIDI track to an external synth.
7. Save, power-cycle and reload: the pattern keeps its notes; Shift Loop starts OFF.
8. SETTINGS > SHIFT LOOP opens the page; FUNC + LFO still opens the compressor.
22 changes: 22 additions & 0 deletions sdk/digitakt/modules/shift-loop/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"schemaVersion": 1,
"sources": ["src/main.c", "src/engine.c", "src/settings.s"],
"defsym": {},
"cflags": [],
"weak": [],
"subscribe": [
{ "event": "ev_key", "fn": "shift_loop_key", "order": 50 },
{ "event": "ev_enc", "fn": "shift_loop_enc", "order": 50 },
{ "event": "ev_tick", "fn": "shift_loop_tick", "order": 50 },
{ "event": "ev_draw", "fn": "shift_loop_draw", "order": 90 },
{ "event": "ev_settings", "fn": "shift_loop_settings", "order": 50 }
],
"contribute": [],
"collections": {},
"copied": [],
"regions": [],
"claims": ["ui:double LFO", "settings:SHIFT LOOP"],
"requires": [],
"derive": null,
"releases": { "1.54": { "defsym": {}, "cflags": [], "sites": [] } }
}
7 changes: 7 additions & 0 deletions sdk/digitakt/modules/shift-loop/media/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Digi UI documentation captures

The Modwerk contributor dedicates their original capture contribution to the public domain under CC0-1.0. This declaration covers the act of capture and accompanying original captions, not the depicted firmware interface.

Elektron retains rights in its underlying interface and firmware. Module interface additions retain their author’s terms in [../LICENSE](../LICENSE). No firmware, extracted stock code, raw memory/framebuffer data, card images or audio samples are included. The images are unmodified firmware-rendered pixels at integer scale.

Manifest identifier: `LicenseRef-Digi-UI-Documentation`. Capture identity and inputs: [capture.json](capture.json).
15 changes: 15 additions & 0 deletions sdk/digitakt/modules/shift-loop/media/capture-plan.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
wait 1500
tap LFO 60 80
tap LFO 60 600
snap page-open
turn H 1
turn B -20
turn E 40
wait 400
snap page-on
tap PLAY 100 50
wait 4000
snap page-playing
tap STOP 100 300
tap NO 100 600
snap page-closed
133 changes: 133 additions & 0 deletions sdk/digitakt/modules/shift-loop/media/capture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"schemaVersion": 1,
"machine": "digitakt",
"moduleId": "shift-loop",
"moduleVersion": "0.1.0-experimental",
"capturedAt": "2026-12-06",
"firmware": "1.54",
"imageSha256": "be654ea49b3f6c26f9ffec2d52468f45e1df0a0f4c7191e1380f74ebce448a8f",
"stockSha256": "f78ba80fa7b1da5fb0e1ff61ad61e9e71aafe79f4364fc49679f3651353e3cf6",
"source": {
"repository": "https://github.com/repeat98/modwerk",
"revision": "uncommitted working tree, branch module/shift-loop",
"path": "sdk/digitakt/modules/shift-loop"
},
"build": {
"modules": [
{
"id": "core",
"version": "4.4"
},
{
"id": "shift-loop",
"version": "0.1.0-experimental"
}
],
"linker": "Modwerk's scripts/link-image.mjs with vendor/elekloader/catalog/core-4.4-os1.54.elemod",
"outputVersion": "SL03",
"verified": true
},
"emulator": {
"repository": "https://github.com/irpina/digiemu",
"revision": "c1b5735835923e328f8b4950d6ba927875e5b669",
"unicorn": {
"version": "2.1.4",
"patches": {
"unicorn-2.1.4-m68k-digikit-accel.patch": "7048704a068cb074b93b751df4b1a73fd8972c1c0cc27e30774c4c2771ec2b5c",
"unicorn-2.1.4-m68k-digikit-speed.patch": "9560613223502656e82adc1ecc36d5d8486995bed13ea8ddad168f8c4558a799",
"unicorn-2.1.4-m68k-emac-mac-load.patch": "ac128dd6836997de55e0d2ad70d7a2978639168090f552c5634da50fddc70bfe",
"unicorn-2.1.4-m68k-emac-modes.patch": "5fc44429ea913c5256c34a6e9c93ab90f727f120b4f12922a8f35a952fd1dace",
"unicorn-2.1.4-m68k-fast-mem.patch": "7f79332f318352cbd8055386dbf5149efc801d0663ae2450e33f9f39fed53374",
"unicorn-2.1.4-m68k-hook-ccr-sync.patch": "56de71acf2adbd5ca2f448095478e65e49fd79d378aeb5b5e4217d2c90f52f4e"
},
"librarySha256": "16a46d878c641e7645c53292f15718ffd44b9836b22d9d323badad89a791e9f6"
},
"python": "3.12.16",
"platform": "Darwin x86_64",
"hle": false,
"audioRecording": false,
"cycleTiming": false,
"framebuffer": "firmware front LCD buffer at panel_diff flush",
"scale": 6,
"frameSelection": "Most populated actual LCD frame within the final 250 ms after the latest panel action; 6x integer scaling."
},
"setup": {
"project": "Disposable first-boot A01 (the emulator's default project), track 1. Core 4.4 and Shift Loop only.",
"fixture": "No sample fixture required.",
"sandbox": "Private temporary output only."
},
"inputs": [
[
1500.0,
"press 23"
],
[
1560.0,
"release 23"
],
[
1647.574,
"press 23"
],
[
1714.243,
"release 23"
],
[
2314.261,
"turn 8 +4"
],
[
2464.265,
"turn 2 -80"
],
[
2614.269,
"turn 5 +127"
],
[
2614.269,
"turn 5 +33"
],
[
3164.285,
"press 10"
],
[
3264.288,
"release 10"
],
[
7314.406,
"press 11"
],
[
7414.409,
"release 11"
],
[
7714.418,
"press 13"
],
[
7814.421,
"release 13"
]
],
"captures": [
{
"path": "media/page-open.png",
"sha256": "b0a61a3c40f247e7fc0bb354ffd28a5e304dadc334c5d48220ef16f60763ae95",
"atMs": 2099.9997863247863,
"requestedAtMs": 2314.2608974358973,
"plan": "wait 1500\ntap LFO 60 80\ntap LFO 60 600\nsnap page-open\nturn H 1\nturn B -20\nturn E 40\nwait 400\nsnap page-on\ntap PLAY 100 50\nwait 4000\nsnap page-playing\ntap STOP 100 300\ntap NO 100 600\nsnap page-closed\n"
},
{
"path": "media/page-on.png",
"sha256": "d4fc1354f3c435e22b13ab2cf097393b6c11f8ffd345d8dd221d362a019e7813",
"atMs": 2920.0002136752137,
"requestedAtMs": 3164.2852564102564,
"plan": "wait 1500\ntap LFO 60 80\ntap LFO 60 600\nsnap page-open\nturn H 1\nturn B -20\nturn E 40\nwait 400\nsnap page-on\ntap PLAY 100 50\nwait 4000\nsnap page-playing\ntap STOP 100 300\ntap NO 100 600\nsnap page-closed\n"
}
]
}
Binary file added sdk/digitakt/modules/shift-loop/media/page-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading