diff --git a/changelog/2026-12-06-digitakt-playhead-research.md b/changelog/2026-12-06-digitakt-playhead-research.md new file mode 100644 index 0000000000..73680ba1f6 --- /dev/null +++ b/changelog/2026-12-06-digitakt-playhead-research.md @@ -0,0 +1 @@ +Digitakt SDK: [playhead.md](../sdk/digitakt/research/playhead.md) maps, for OS 1.54, where the sequencer keeps the step each track plays now, the next step, the transport and the playing pattern, checked in digiemu, so a mod can react to the playhead or write a step after it has played. diff --git a/sdk/digitakt/research/pattern-write.md b/sdk/digitakt/research/pattern-write.md index 061394bc50..cbf5543960 100644 --- a/sdk/digitakt/research/pattern-write.md +++ b/sdk/digitakt/research/pattern-write.md @@ -23,6 +23,7 @@ The MAIN image loads at `0x40000400`. Every routine takes its arguments on the s - NOTE, VEL, LEN, micro timing and condition are plain per-step arrays, not p-locks, so a generator does not use up the pattern's p-lock capacity (H). - No mutex protects pattern data. The stock UI writes it from the UI task, and so can a mod from `ev_tick` or `ev_key` (M). Do not call the setters from `ev_render_in` or `ev_render_out`: notifying allocates memory and takes queue mutexes (H for what they call). - A stock undo snapshot can be taken before writing (H for the code). +- Which step each track plays now, to write a step after it has played, is in [playhead.md](playhead.md). - digislicer already calls `NOTESET` and `LOCKSET` from the UI task on 1.53 and 1.54 ([os154.h](../modules/digislicer/src/os154.h)), which is precedent for this approach. ## Reaching a track diff --git a/sdk/digitakt/research/playhead.md b/sdk/digitakt/research/playhead.md new file mode 100644 index 0000000000..a563c1b4e3 --- /dev/null +++ b/sdk/digitakt/research/playhead.md @@ -0,0 +1,42 @@ +# Each track's playhead (Digitakt mk1, OS 1.54) + +Where the sequencer keeps the step each track plays now, for a mod that reacts to the playhead or writes a step after it has played (a shift-register or generative sequencer, a follow-the-playhead display). Writing the step data itself is in [pattern-write.md](pattern-write.md). + +**Status:** static analysis of the stock OS 1.54 MAIN image (the `.syx` whose SHA-256 is in [machine.json](../../machines/digitakt/machine.json)), then checked in digiemu. Nothing here has run on a unit. Confidence: **H** read in the code, **E** confirmed in the emulator. OS 1.53 is not mapped. + +## The sequencer's per-track arrays + +The level-2 sequencer interrupt steps the 16 tracks (0–7 audio, 8–15 MIDI) in one loop (`0x40070a98`–`0x40070ba0`, H). Each array has one entry per track: + +| 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, E | +| `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, E | +| `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, E | +| `0x4199ec38` | u32 | the playing pattern's data; track t at `+ t * 0x38f` | H, E | + +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). + +## Emulator results + +digiemu `c1b5735` with `Session(..., audio=True)`: without the audio callback the sequencer's tick does not advance and the playhead stays at 0. Default project (A01), track 1 at 1x, 16 steps, PLAY, read every 400 ms: + +- `0x4199ec1c[0]`: 1, 4, 7, 9, 12, 14, 1, 4, 6, 9, 12, 14, 1, 3, 6 (E). +- `0x4199ebfc[0]` was each time the step after it, wrapping at 16 (E). +- `0x4199ec2c` read 1 throughout (E). +- `0x4199ec38 + 0 * 0x38f` was the same address as the edited pattern's track 1 data ([Reaching a track](pattern-write.md#reaching-a-track)), and NOTE bytes written there were played (E). + +## Reading it from a mod + +- The interrupt writes these bytes; a mod reads them from `ev_tick` (the UI's 30 Hz check). A byte read is atomic, so no lock is needed. +- At 30 Hz a fast track can move more than one step between two ticks. Handle every step passed since the last tick, in order, wrapping at the track's length. +- Before writing into the pattern that plays, compare the edited pattern's track data with `0x4199ec38 + t * 0x38f`, and write only when they are the same: a queued pattern, or one being edited, is then 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.