diff --git a/changelog/2026-11-24-digitakt-ii-chord-recording.md b/changelog/2026-11-24-digitakt-ii-chord-recording.md new file mode 100644 index 0000000000..178460f6de --- /dev/null +++ b/changelog/2026-11-24-digitakt-ii-chord-recording.md @@ -0,0 +1 @@ +Digitakt II base: chords recorded across linked voices. Live recording on a lead track (SETTINGS > VOICES above 1) now records each note of a chord as a step on the track that plays it, so a recorded chord plays back as a chord and each note can be edited like any step. A note the instrument starts playing a moment before the recording sees it is recorded on the track playing it, not skipped. While linked, the voice tracks take a copy of the lead's sound and of its track's TRIG page defaults, length, swing and speed, kept up to date a part at a time, so their own steps sound exactly like the lead; when the setting returns to 1 they get their own sound, machine and TRIG page settings back (kept in memory while linked: a project saved while linked keeps the copies). Notes from the keys and MIDI fill the group from the lead up whatever the pattern plays there, and the pattern's notes of the lead never land on a voice track with steps of its own. Checked in the emulator and, as reported by the author, on a unit (OS 1.17, Morpha on the lead): chords recorded with the pattern running land on every linked track, sound like the lead and edit like any step. diff --git a/changelog/2026-11-25-digitakt-ii-voices-fixes.md b/changelog/2026-11-25-digitakt-ii-voices-fixes.md new file mode 100644 index 0000000000..8da194ed4c --- /dev/null +++ b/changelog/2026-11-25-digitakt-ii-voices-fixes.md @@ -0,0 +1 @@ +Digitakt II base: linked voices fixes. The SETTINGS > VOICES row now names the track you are on every time SETTINGS opens (it kept the track that was on when the menu was first built, so it could read T9 on any track), and it has an icon like the other SETTINGS rows, with the count beside it. A chord note from the keys or MIDI on a voice track now always plays the lead's sound: after the unit had forgotten which sound a track last loaded (a kit change, a sound lock), it could load the voice's own unedited sound with the lead's machine. When VOICES is lowered while notes ring or fade, a track that leaves the group keeps the lead's machine and ends its note there until it plays a note of its own, which brings back its own sound: before, its note's release could cut the lead's next note short, and its own machine could take over the fading note and play the lead's sample (a kick heard on the first hit). The lead's track level (the LEVEL knob and the mixer) now sets the whole group's volume, and a track that leaves the group gets its own level back. With every track at 1 nothing changes. diff --git a/docs/verification/2026-11-24-digitakt-ii-linked-voices-base.md b/docs/verification/2026-11-24-digitakt-ii-linked-voices-base.md index 83c319499c..8eff5bbba5 100644 --- a/docs/verification/2026-11-24-digitakt-ii-linked-voices-base.md +++ b/docs/verification/2026-11-24-digitakt-ii-linked-voices-base.md @@ -24,7 +24,18 @@ Emulator (coupled ColdFire and sound chip, from a ready point saved with each im `npm run test:procedure` was not run for this base: the Digitakt II steps it would add (USB link, soak, price) do not exist yet, as for `a3ced45e`. -Not checked on a unit: MIDI chords, sequencer trigs on a lead, a stock machine as the lead, muted voices. +Release checks on the same image `27dfadf8`, reported by @Claptom-music, 25 November 2026: + +| Case | Result | +|---|---| +| Sequencer trigs on a linked lead (Morpha, track 1, VOICES 3) | pass | +| A stock SAMPLE lead (one-shot, track 5, VOICES 3) | sound pass; the row read `T9 VOICES` on every track (label bug) | +| A muted voice track | pass; a muted lead still sounds from the keys, not yet compared with stock (open) | +| MIDI chords | partial: received, but the audio sounds odd, maybe from track 1's own trigs (open, recording to come) | +| Changing VOICES while playing | no crash; lowering VOICES to 1, the lead's first note played without its own sound, as a plain kick (ungroup bug) | +| Two different machine modules at once | not run | + +The label and ungroup bugs are fixed in the base after this one (`changelog/2026-11-25-digitakt-ii-voices-fixes.md`, `VOICES.md`). ## Pinned for the browser builder diff --git a/docs/verification/2026-11-30-digitakt-ii-voices-chord-recording-base.md b/docs/verification/2026-11-30-digitakt-ii-voices-chord-recording-base.md new file mode 100644 index 0000000000..d06c24b7c5 --- /dev/null +++ b/docs/verification/2026-11-30-digitakt-ii-voices-chord-recording-base.md @@ -0,0 +1,31 @@ +# Digitakt II base 1c2c2016: linked-voices fixes, shared level, chord recording, restored sounds + +The Digitakt II Modwerk base (OS 1.17) this pull request's source builds: **1c2c2016**. The release step (the binding, the vendored package and the pin) is not part of it: it is done once, on the combined build of the next release (owner, 30 November 2026), so `base-binding.json` still names `948be0c4`. It is `base/digitakt-ii-next` with the hold-back of chord recording (`e18ca55eb`) reverted, plus #2204 and the restore of a voice track's own sound. Over `948be0c4` it adds: + +- the linked-voices fixes of #2204: the VOICES row's icon and a label that follows the track, voice tracks that always load the lead's sound, and former voices that keep the lead's machine until their own note (`VOICES.md`, Which sound a voice loads, Leaving a group); +- the lead's track level shared with its voices (#2204); +- chord recording (#2138): live recording puts each chord note on the track that plays it, and voice tracks' own steps play with a copy of the lead's sound; +- a voice track's own sound, machine and pattern-track settings kept while linked and put back at VOICES 1. + +Built by `machine:base -- digitakt-ii --write` with the reviewed toolchain (GCC 16.2.0, binutils 2.47, Elekloader kit `3b31ef3`): 18,852 bytes `.run`, 30,732 bytes `.bss` (17.7 KB of it the kept sounds), 48 sites (the live-record site `0x40048fb2` added). + +## Checks + +On a unit (hands and ears, @Claptom-music's Digitakt II, OS 1.17, over USB), reported by the tester. Both images carry this base byte for byte with the Morpha module (an added machine) on the lead: + +| Image | Result | +|---|---| +| `b8cff950` | Pass: VOICES 3 with Morpha leading, chords, VOICES 1: tracks 2 and 3 return to their own machines and sounds. Chord recording, the shared level and POS as before. | +| `2b4850e1` (with Morpha's later POS fixes) | All pass: POS through a stereo sample, built-in waves, chords with VOICES 3 and back to 1 (own machines and sounds), the shared level, live chord recording. | + +The same parts on earlier images of this work: the #2204 fixes on `b6ee842b` (all pass) and the shared level on `094b8a09` (pass); chord recording on `800a4a6f` (all pass). The records are in `VOICES.md`. + +Emulator (coupled ColdFire and sound chip, panel probe): every track at 1 plays the first note identical sample for sample to `27dfadf8`'s; a chord held while VOICES drops ends on every track; after VOICES 3, 1, 3 the voices hold the lead's values; tracks 2 and 3's machine type bytes go 0, 9 (linked), 0 (back at 1); a chord with the lead's LEVEL at 0 is silent. + +Not checked on a unit: MIDI chords (sounded odd on `27dfadf8`, a recording is to come), a muted lead played from the keys against stock, two machine modules at once, a project saved while tracks are linked (keeps the copies, by design). + +`npm run test:procedure` was not run: the Digitakt II steps it would add (USB link, soak, price) do not exist yet, as for `948be0c4`. + +## Release + +None here. Once #2204, this, #2445 and #2446 are on `base/digitakt-ii-next`, the combined base is recorded once by `machine:base -- digitakt-ii --write`, vendored and pinned, and its exact image runs one unit round. diff --git a/sdk/machines/digitakt-ii/elekloader/base.json b/sdk/machines/digitakt-ii/elekloader/base.json index cf361633d5..1475cdb942 100644 --- a/sdk/machines/digitakt-ii/elekloader/base.json +++ b/sdk/machines/digitakt-ii/elekloader/base.json @@ -52,6 +52,7 @@ "../modwerk/machines-entry.s", "../modwerk/voices.c", "../modwerk/voices-entry.s", + "../modwerk/voices-record-entry.s", "../modwerk/fw-bindings.s" ], "subscribe": [ @@ -114,6 +115,13 @@ "op": "jsr", "target": "core_voice_event_entry" }, + { + "addr": "0x40048fb2", + "len": 6, + "stockSha256": "ed5086557423e0a010a460981e782edce14c7e9c57265e741ebacc985a1d8aa3", + "op": "jsr", + "target": "core_voice_record_entry" + }, { "addr": "0x40066df2", "len": 6, diff --git a/sdk/machines/digitakt-ii/elekloader/modwerk/VOICES.md b/sdk/machines/digitakt-ii/elekloader/modwerk/VOICES.md index 489742de56..874df8f96e 100644 --- a/sdk/machines/digitakt-ii/elekloader/modwerk/VOICES.md +++ b/sdk/machines/digitakt-ii/elekloader/modwerk/VOICES.md @@ -4,11 +4,14 @@ A lead track plays its notes on the tracks after it, so notes overlap instead of ## What the musician does -SETTINGS shows a row named after the track you are on, `T1 VOICES` to `T16 VOICES`, from 1 (stock) to 8. LEFT and RIGHT change it. With 3 on track 1, tracks 1, 2 and 3 form a group: each new note track 1 plays goes to the first of them, from the lead on, that holds no note, so the lead takes a chord's first note (the trig keys send a chord from the lowest note up); with all three busy, to the next one in turn. +SETTINGS shows a row named after the track you are on, `T1 VOICES` to `T16 VOICES`, from 1 (stock) to 8: its icon in the stock rows' icon place, the count, then the label. LEFT and RIGHT change it. With 3 on track 1, tracks 1, 2 and 3 form a group: each new note track 1 plays from the keys or MIDI goes to the first of them, from the lead on, that holds no note from the keys or MIDI, so the lead takes a chord's first note (the trig keys send a chord from the lowest note up) whatever the pattern plays there; with all three busy, to the next one in turn. The pattern's notes of the lead play on the lead, or, while it holds a note, on a voice track with no steps of its own. -- The voice tracks belong to the lead while linked: they play the lead's sound with its machine, with each trig's own locks, and follow knob turns made on the lead. Their own trigs are silent while linked (the base sends their notes to no track), so their own machine never sounds between or after the lead's notes. Their own sounds, trigs and pages are not changed: back at 1 they play as before. -- A muted lead plays nothing. A muted voice track is skipped. +- The voice tracks belong to the lead while linked: their sound in the kit becomes a copy of the lead's (machine, filter, amp, effects, everything) and their track's TRIG page defaults, length, swing and speed the lead's, kept up to date while linked; they follow knob turns made on the lead. Their own steps play and their own key presses are silent. Back at 1 they get their own sound, machine and settings back (kept in memory while linked: a project saved while linked keeps the copies). +- Live recording on the lead puts each note on the track that plays it: a chord records as one step on each of its tracks. +- A muted lead's notes are dropped where they reach the base (on a unit a muted lead still sounds from the keys: see Open). A muted voice track is skipped. +- The lead's track level (LEVEL, the mixer) is the group's: the voices take it each frame (`0x80003340 + 2 t`, the level the sound chip gets; the kit keeps each track's own at `+0x14 + 2 t`), and a track that leaves the group gets its own back. Emulator (Morpha, VOICES 3, track 1's LEVEL at 0, a three-key chord): silent, where the build without it still played tracks 2 and 3; the same chord with LEVEL untouched plays both voices. On a unit (Claptom-music, 26 November 2026, image `094b8a09` with chord recording and Morpha): the chord follows the lead's LEVEL and its mixer volume, and tracks 2 and 3 return to their own levels at VOICES 1; passed again on `2b4850e1`. - A track that is already a voice of an earlier lead leads nothing, and a group ends at track 16. +- Lowering VOICES while notes ring: a track that leaves the group keeps the lead's machine, and the note it holds ends there with the lead's sound, until it plays a note of its own, which loads its own sound. - The setting is the project's: saved with it (project archive tag `VOC1`), reset to 1 everywhere by a project saved without it. The DT2 sequencer keeps one note per trig, so a pattern cannot hold a chord on one track; linking gives overlapping tails from the sequencer and chords from the keys and MIDI. @@ -33,7 +36,23 @@ Because the record names its sound, a note moved to another track plays the lead **Knobs.** The per-track parameter targets are 71 int16 a track from `0x80003362` (142 bytes a track; the smoother at `0x400d9406` follows them each frame from `0x80003340`). A note-on loads the note's sound and locks into its track's targets. Once a frame, before the transfer, `core_voice_frame` compares the lead's targets with the last frame's and copies the values that changed to its voice tracks. In a frame where a sequencer note stayed on the lead, it only takes the lead's new values, so a trig lock on the lead does not spread to the voices; notes from the keys or MIDI carry no locks and never hold a turn back. As a safety net, each frame one voice track of the group that holds no note is copied from the lead in full, so the next note there starts from the lead's settings. Found on a unit (Morpha, build `e6ffc45b`): while chords were played and knobs turned, later chord notes no longer sounded like the lead; the frames skipped for every lead note had swallowed turns. -**Sound chip.** The machine wire's per-track types (`machine-frame.c`) give a voice track its lead's type for as long as it is linked, so an added machine's player plays every note its lead sends there, and the track's own machine never takes over its voices mid-note. A voice track's own note records go to track 16 (none) at the same entry. +**Live recording.** The sequencer records a live note with `0x40048fb2` (arguments on the stack: sequencer, track, note, velocity, a flag, step, …; it looks up the track's object with `0x4003f304` and writes the step through `0x40059988` and `0x400597c8`). Found with a write watch on pattern 0 while a tap was recorded: the step word at `pattern + 0x6a5 * track + 2 * step` (here `0x11`, then `0x391`), then the step's bytes 0x100, 0x180, … 0x400 further; the frame chain from `0x400597c8` led back through `0x400599ba` and `0x40048fb2` to the event handler at `0x40031a60`. The routine runs about 40,000 instructions before the frame plays the note (the held-note tables were written after the step). The base's jsr replaces its first 6 bytes (`linkw %fp,#-68; moveq #15,%d0`, SHA-256 `ed508655…`); `core_voice_record` changes the track argument of a lead's note to the group track it will play on (as `pick` chooses, skipping tracks other recorded notes have taken) and leaves a pending entry that `core_voice_event` uses to send the note there. When the frame plays a note from the keys or MIDI before the routine has seen it (no pending entry), it marks the track it chose as holding a fresh note of that pitch, and the routine records the note there. Any other note the group already holds (the keys sending a held note again) is not recorded (track 16: the routine returns at once). Each chord note therefore lands as an ordinary step on its own track, editable like any step. + +A linked voice track's own steps play while it is linked: a sequencer note-on on a voice track keeps its track. To make them sound like the lead, the base copies the lead's sound in the kit (`0x426532ec + 0x450 * track`, 0x450 bytes) and its pattern track's settings (`+0x480` to `+0x48f`: the TRIG page defaults the note record's constructor at `0x400d6d24` falls back on when a step sets none, then length, swing and speed) to each voice track, in full when linking, then one voice a frame and a sixth of the sound at a time (only the words that differ are written), so the frame interrupt stays short. Pointing the step's note record at the lead's sound (`+0x3c`) was tried first and is not enough: on a unit the recorded chord notes played louder, unfiltered and without envelope; in the emulator a voice track's own note played 9 dB over the lead's and held flat, still 9 dB over with the sound copied but not the track's settings, and at the lead's level with its decay with both (rms 0.045 against 0.043). Its own key presses still go to no track. + +On the unit (`11fa7318`, the record hook with the pointed sound, the pattern running): of four linked tracks only tracks 1 and 3 recorded, and the sound went wrong while recording. In the emulator the sequencer plays only its first step, so neither could be reproduced; the fill order above (live notes ignore what the pattern plays on a track) and the pattern notes' rule (never on a voice track with steps of its own) answer the likely cause, pattern notes taking track 2. + +On the unit (`f83435c3`, those two rules and the copied sound and settings, the pattern running, reported by the author): recorded notes sounded like the lead, but some of the linked tracks again recorded nothing, and changing pages on a linked track lagged (up to about a second) while the pattern ran, not on the lead. The likely cause of the missing notes: the recording routine skipped a note the frame had already played, taking it for the keys sending a held note again; the fresh marks above record it instead. The lag's cause is not confirmed: the idle copy now compares a sixth of a sound a frame instead of all of it, and writes a track's targets only where they differ. Neither could be reproduced in the emulator, whose sequencer stops after its first step, but one emulator run recorded a chord's second note after the frame had played it (held-note tables written before the step), on the track playing it. With both changes (`800a4a6f`, table below) the author reported every linked track recording its note and no lag. + +Emulator (track 1 leading 3, rotating test build): REC + PLAY, three taps of trig key 1: the first recorded on track 1 and played there, the second on track 2, the third on track 3 (step words `0x391`, held-note source 2 on the same track). Playback of recorded steps could not be checked: after STOP and PLAY the emulator's sequencer played only its first step. Every track at 1: the project's pattern and the default note as before. + +**Sound chip.** The machine wire's per-track types (`machine-frame.c`) give a voice track its lead's type for as long as it is linked, so an added machine's player plays every note its lead sends there, and the track's own machine never takes over its voices mid-note. A voice track's own key presses go to track 16 (none) at the same entry; its own steps keep their track. + +**Which sound a voice loads.** The frame's note handling (from `0x4002e4fa`) loads a track's sound in full (`0x4002d438`: its 71 targets and its sound-chip row) only when the sound the note names (`+0x40`, `+0x3c`, or the kit's track sound, `[0x80004704] + 0x34 + 0x450 * track`, when both are 0) differs from the one it last loaded, kept per track at `0x8000470c`; otherwise it copies only the edited values. A sequencer note names its sound; a note from the keys or MIDI names none, which means the track's own. So a key note moved to a voice track whose pointer stock had cleared (it clears all sixteen when the kit's track sounds move, and one after a sound lock) loaded the voice's own, unedited sound, played with the lead's machine. `core_voice_event` therefore names the lead's sound in such a note-on, and the voice loads the lead's sound whenever it last loaded another. + +**Leaving a group.** A track `regroup` takes out of a group is its lead's former voice until it plays a note of its own. `core_voice_lead` keeps the lead's machine there, so a note ringing or fading on it is not handed to its own machine's player midway (with Morpha leading, SAMPLE took over a fading voice and played the lead's sample slot, the kick used as Morpha's wavetable, as a plain kick). A note-off that names the lead for a note a former voice still holds (`0x47db4310`, `0x47db4560`) goes to that voice: it would otherwise end the lead's note of the same source and pitch, or nothing, leaving the voice's note held. The former voice's own note-on clears its pointer at `0x8000470c` (stock's way to force a full load), so that note loads its own sound, and from then on it is its own track again. + +**The row.** SETTINGS builds its rows once, so the label is rewritten each time the menu asks for it (`core_voice_row_label` in `voices-entry.s`, then core's `core_value_label`). The row is core's value row (`core_addrow`, `rows.c`) with its own draw: the icon at x + 0..8, two rows above the label's text like the stock icons (`fw_fillrect` counts the row's lines upward), and the count right-aligned at x + 19. ## Checked @@ -56,8 +75,38 @@ On a unit (reported by the author, 23 November 2026), Digitakt II OS 1.17 with t | `063eea9a` (voices rotating, a voice track's own machine between borrowed notes) | Chords from the keys: each note and each key release moved to another track, each sounding a different wave; letting go of the second key of a two-key chord left a note sounding that jumped to the first key's pitch. Save, load another project and come back: the track kept its settings. | | `e6ffc45b` (voice tracks reserved for the lead, filled from the lead, copied at linking; held pitch from the keys dropped) | Chords play; after a while of playing and turning knobs, later chord notes no longer had the lead's settings. | | `27dfadf8` (turns copied with key and MIDI notes, idle voices copied in full) | Chords with VOICES 3-4 and knobs turned while playing: every chord note keeps the lead's settings. | +| `800a4a6f` (chord recording: voice tracks copy the lead's sound and settings a part at a time, fresh marks) | Chords from the keys recorded with the pattern running and VOICES 3-4: every linked track got its note, and the recorded notes sound like the lead. Page changes on a linked track while the pattern runs: no lag. A recorded note on a voice track edits like any step. Recorded timing fine with quantize on. Live chords, knobs and Morpha's FOLD as before. | +| `b8cff950` (with the fixes of #2204 and a voice's own sound and pattern settings kept while linked and put back when it leaves) | VOICES 3 with Morpha leading, chords, then VOICES 1: tracks 2 and 3 return to their own machines and sounds (before: they stayed Morpha copies). Chord recording, the shared level and POS passed again; also on `2b4850e1`. Emulator (panel probe): the machine type bytes of tracks 2 and 3 went 0, 9 (linked), 0 (back at 1); the build without it left 9. | + +The kept sound is in memory only: a project saved while tracks are linked keeps the copies, and another kit or project loaded while linked puts nothing back. + +Release checks of base `948be0c4` on image `27dfadf8` (that base with Morpha), reported by Claptom-music, 25 November 2026: + +| Case | Reported | +| --- | --- | +| Sequencer trigs on a linked lead (Morpha on track 1, VOICES 3) | Pass. | +| A stock SAMPLE lead (one-shot, track 5, VOICES 3) | Sound pass. The row read `T9 VOICES` whatever track was on: SETTINGS builds its rows once, so the label kept the track that was on then. Fixed in this base (the label is rewritten each time the menu asks for it). | +| A muted voice track | Pass. A muted lead still sounds when played from the keys; not yet compared with stock (a muted track at 1 played from the keys), so open. | +| MIDI chords | Partial: the unit receives them but the audio sounds odd, possibly because of track 1's own trigs. Open; the tester will send a recording. | +| Changing VOICES while playing | No crash. Lowering VOICES to 1 while playing (a kick sample), the lead's first note played without its own sound (AMP and the rest), as a plain kick; then fine. | +| Two different machine modules at once | Not run. | + +A first fix, base `f702c908` (image `e0244b16`: label, icon, note-offs to the voice that holds the note, a leaving voice's pointer cleared at once and its lead's machine kept only while it held a note), reported by Claptom-music, 25 November 2026: the label follows the track and the icon is right (asked: two dots as eyes over the note head); a held chord when VOICES drops ends properly; a former voice plays its own sound; earlier checks still pass. Failed: with Morpha on track 1, lowering to 1 still played the kick on the first hit, and the sub sometimes went missing. New: at random, the synth played with none of its edits. The emulator showed the cause of the last: after VOICES 3, 1 and 3 again, a chord note on track 2 loaded track 2's own sound (the pointer the first fix cleared). Both are addressed above (Which sound a voice loads, Leaving a group). + +Emulator checks of base `2ead25d6` (image `b6ee842b`, the same Morpha package), 25 November 2026: + +| Check | `27dfadf8` / `e0244b16` | `2ead25d6` | +| --- | --- | --- | +| SETTINGS on tracks 1, 5, 16 and 5 again, then 1, 9 and 6 (ColdFire panel probe) | `T1 VOICES` every time (`27dfadf8`) | as `e0244b16`: `T1`, `T5`, `T16`, `T5` (its count 3 kept), `T1`, `T9`, `T6`; the icon at x 42-50, rows 53-61, the stock icons' box, the count's digit from x 58 | +| VOICES 3 on track 1, a three-key chord held, VOICES to 1 while held, the keys let go (panel probe, held-note words `0x47db4310`) | tracks 2 and 3 still hold their notes after the release (`27dfadf8`) | every note ends | +| VOICES 3, a chord, VOICES 1, VOICES 3, a chord (the default kit's sounds differ in one value per track) | track 2 loaded its own sound (`e0244b16`) | tracks 2 and 3 hold the lead's values and its sound's pointer | +| Then track 2 played from the keys on its own | | it loads its own sound (its value and pointer) | +| VOICES 3 with Morpha on track 1, the chord held, VOICES 1, the keys let go (coupled, 50 ms RMS) | the former voice's note stops at once around the release, no tail (`27dfadf8`) | both notes ring until the release (RMS 0.063), then fade together with the lead's release (0.047, 0.034, 0.025 in 0.25 s windows, against one note's 0.031, 0.023, 0.017) | +| Every track at 1, the same script (coupled) | `27dfadf8` | the first note identical sample for sample; the level identical in every 50 ms window of the run (the second key lands a few milliseconds apart in the two runs, so the mix after it is not compared sample for sample) | + +The emulator's sequencer stops after a pattern's first step, so the kick pattern of the report was not replayed. -Not checked yet: sequencer trigs on a linked lead on a unit, MIDI chords, muted voices, a stock machine (SAMPLE) as the lead on a unit. +On a unit: Claptom-music tested image `b6ee842b` (base `2ead25d6` with Morpha) on a Digitakt II, OS 1.17, over USB, 25 November 2026, with the steps above (icon, the kick when lowering VOICES while playing, edits kept after VOICES 3, 1, 3, a held chord when VOICES drops, a former voice played on its own), and reported it ready for review; no case was reported failing. ## Open @@ -65,4 +114,7 @@ Not checked yet: sequencer trigs on a linked lead on a unit, MIDI chords, muted - A knob turned on the lead overrides a voice's trig lock on that parameter while the voice's note plays. - The setting is per project, not per kit or pattern. - Chords from the trig keys in chromatic mode are not checked: in the emulator a second key held with the first added no note on either build. -- Changing VOICES while notes play regroups at once (routing pauses while the groups change); a note-off that then finds no owner stays on the lead. +- Changing VOICES while notes play regroups at once (routing pauses while the groups change). A note-off for a note no track of the group or waiting track holds stays on the lead. +- A muted lead played from the keys sounds on a unit (`27dfadf8`); whether stock does the same for a muted track is not yet checked. +- MIDI chords sound odd on a unit (`27dfadf8`), maybe from track 1's own trigs; a recording is to come. +- Two machine modules at once are not run on a unit. diff --git a/sdk/machines/digitakt-ii/elekloader/modwerk/voices-entry.s b/sdk/machines/digitakt-ii/elekloader/modwerk/voices-entry.s index 3bad021438..bd91c48e17 100644 --- a/sdk/machines/digitakt-ii/elekloader/modwerk/voices-entry.s +++ b/sdk/machines/digitakt-ii/elekloader/modwerk/voices-entry.s @@ -22,4 +22,15 @@ core_voice_event_entry: tst.l %a0 rts +/* SETTINGS > VOICES: the row's label, a std::function returning a std::string built at a0 (core-dt2 rows.s, + * core_value_label). It rewrites the label for the track on now, then lets core's routine build the string from it + * with the same a0 and stack. */ + .globl core_voice_row_label + +core_voice_row_label: + move.l %a0,-(%sp) + jsr core_voice_label_update + movea.l (%sp)+,%a0 + jmp core_value_label + .section .note.GNU-stack,"",@progbits diff --git a/sdk/machines/digitakt-ii/elekloader/modwerk/voices-record-entry.s b/sdk/machines/digitakt-ii/elekloader/modwerk/voices-record-entry.s new file mode 100644 index 0000000000..122df832cb --- /dev/null +++ b/sdk/machines/digitakt-ii/elekloader/modwerk/voices-record-entry.s @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Linked voices, live recording (OS 1.17): the sequencer's live-record routine at 0x40048fb2 takes (sequencer, track, + * note, velocity, flag, step, ...) on the stack and records the note on that track's step. Its first 6 bytes + * (linkw %fp,#-68; moveq #15,%d0) become the base's jsr: voices.c may change the track argument to the voice track the + * note will play on, then this replays the two instructions on the caller's stack, as stock ran them, and resumes at + * 0x40048fb8. Scratch registers d0, d1, a0 and a1 carry nothing into the routine (its arguments are on the stack). */ + .text + .even + .globl core_voice_record_entry + +core_voice_record_entry: + lea -16(%sp),%sp + movem.l %d0-%d1/%a0-%a1,(%sp) + pea 24(%sp) /* the arguments: our return address and the caller's lie in between */ + jsr core_voice_record + addq.l #4,%sp + movem.l (%sp),%d0-%d1/%a0-%a1 + lea 16(%sp),%sp + movea.l (%sp)+,%a0 /* back to 0x40048fb8, with the stack as the caller left it */ + link.w %fp,#-68 + moveq #15,%d0 + jmp (%a0) + + .section .note.GNU-stack,"",@progbits diff --git a/sdk/machines/digitakt-ii/elekloader/modwerk/voices.c b/sdk/machines/digitakt-ii/elekloader/modwerk/voices.c index a81d448935..12f2e8a27c 100644 --- a/sdk/machines/digitakt-ii/elekloader/modwerk/voices.c +++ b/sdk/machines/digitakt-ii/elekloader/modwerk/voices.c @@ -6,12 +6,23 @@ * sequencer trigs, the keyboard and MIDI alike. The base looks at each record as the frame takes it * (core_voice_event_entry, at 0x4002dff4) and moves a lead's note-on to the next free track of its group, and a * note-off to the track that holds that note. The record already names the lead's sound (+0x3c, or a sound lock's), - * so the voice track plays the lead's sound with that trig's own locks; nothing in the kit changes. + * so the voice track plays the lead's sound with that trig's own locks. * - * While linked, a voice track belongs to its lead: it plays only the notes its lead sends, always with the lead's - * machine (machine-frame.c sends the sound chip the lead's type for it), and its own notes (its trigs) go to no - * track, so its own machine and sample never sound over, between or after its lead's notes. Its own sound and - * pattern stay as they are and play again once VOICES puts it back on its own. + * While linked, a voice track belongs to its lead: its sound in the kit is a copy of the lead's (machine, filter, amp, + * effects, everything), kept up to date each frame and saved with the kit, and it plays the notes its lead sends, + * always with the lead's machine (machine-frame.c sends the sound chip the lead's type for it). Its own steps play + * too, so chords recorded across the group play back as recorded with the lead's sound; its own key presses go to no + * track. It keeps the copied sound once VOICES puts it back on its own. (Pointing a step's note record at the lead's + * sound instead was tried: part of a note's settings come from its own track, so it played louder and unfiltered.) + * + * Notes from the keys and MIDI fill the group from the lead up (the first note on the lead, the next on the next + * track), whatever the pattern plays there; the pattern's notes of the lead play on the lead, or, while it holds a + * note, on a voice track with no steps of its own, so they never land on recorded chord notes. + * + * Live recording: the sequencer's live-record routine (0x40048fb2, core_voice_record_entry) records a lead's note + * from the keys or MIDI on the track that will play it, so each note of a chord lands as an ordinary step on its own + * track (editable afterwards like any step). The routine runs before the frame plays the note, so it picks the track + * and leaves a pending entry; the frame then sends that note to the same track. * * Record fields used (read from the sequencer's constructor at 0x400d6d24 and the frame's note handling from * 0x4002e1b2): +0x00 kind (0 and 1 take the note path), +0x04 1 for a note-on, +0x10 the track, +0x14 the note's @@ -19,14 +30,29 @@ * +0x2c the pattern track. Stock keeps, per track, the source and pitch of the note it holds (0x47db4310 and * 0x47db4560); a note-off ends the note only where both match, so the base sends it to that track. * + * The lead's track level (LEVEL, the mixer) is the group's too: each frame the voices' levels (0x80003340, one int16 a + * track, which the stock smoother follows like the targets) are set to the lead's, and a track that leaves the group + * gets its own from the kit again. + * * Knob turns on the lead reach its voices: once a frame, before the transfer, the base compares the lead's 71 * parameter targets (int16 from 0x80003362, 142 bytes a track, which the stock smoother at 0x400d9406 follows) with * the last frame's and copies the values that changed to each voice track. A frame in which a sequencer note started * on the lead itself only takes the lead's new values (its trig locks) without copying them, and each frame one voice * track holding no note is copied from the lead in full. * + * Stock loads a track's sound in full only when the sound a note names (+0x3c; a note from the keys or MIDI names + * none, which means the track's own) differs from the one the track last loaded (0x8000470c, one pointer a track). + * A note-on the base moves to a voice track names the lead's sound, so the voice loads the lead's sound whenever it + * last loaded another (its own, after stock forgot what it loaded), never its own. + * + * A track that leaves a group (VOICES lowered, or its lead's group moved) stays its lead's former voice until it plays + * a note of its own: it keeps the lead's machine, so a note still ringing or fading there is not handed to another + * machine's player midway, and a note-off naming the lead for a note it still holds goes to it. Its own note forgets + * the sound it last loaded, so that note loads its own sound in full. + * * The setting is the project's (core_project_archive, tag VOC1), saved with the project and reset by a project - * saved without it. With every track at 1 nothing here changes a note. Emulator-checked only; see VOICES.md. + * saved without it. With every track at 1 nothing here changes a note. VOICES.md records what was checked in the + * emulator and on a unit. */ #include #include "mk2/core.h" @@ -39,29 +65,198 @@ enum { PATTERN_TRACK_VIEW = 0x30, NONE = 0xff, SEQUENCER = 1, /* a record's source (+0x14) for the sequencer's notes */ + SOUND_STRIDE = 0x450, + SOUND_WORDS = SOUND_STRIDE / 4, + PENDING = 8, /* recorded notes the frame has not played yet */ + PENDING_FRAMES = 64, /* after which a pending entry is dropped (the frame plays it within a few) */ + FRESH_FRAMES = 64, /* how long a note the frame played first waits for live recording */ + SOUND_SLICES = 6, /* the idle copy compares a voice's sound with the lead's a sixth at a time */ + SLICE_WORDS = SOUND_WORDS / SOUND_SLICES, + TRACK_STRIDE = 0x6a5, /* a pattern's track data; its step words first, two bytes a step */ + STEPS = 128, + TRACK_SETTINGS = 0x480, /* a pattern track's settings after its steps */ + TRACK_SETTINGS_BYTES = 16, }; +#define KIT_SOUNDS 0x426532ecu /* the kit's track sounds (a record's +0x3c without a sound lock), SOUND_STRIDE apart */ +#define CURRENT_PATTERN (*(const volatile uint32_t *)0x4316501cu) + #define TARGETS ((volatile int16_t *)0x80003362u) /* track t's value j at [VALUES * t + j] */ #define NOTE_SOURCE ((const volatile uint32_t *)0x47db4310u) /* the source of the note each track holds, 0 none */ #define NOTE_PITCH ((const volatile int32_t *)0x47db4560u) /* its pitch, -1 none */ #define MUTES (*(const volatile uint32_t *)0x8000467cu) #define MUTES_OVERRIDE (*(const volatile uint32_t *)0x80004680u) /* nonzero: the inverse of the mutes in force */ +/* The sound each track last loaded in full (vector-191 handler, 0x4002e53e); 0 makes its next note load its own. */ +#define LOADED_SOUND ((volatile uint32_t *)0x8000470cu) +/* The kit's track sounds: track t's at this + 0x34 + 0x450 * t (what a note naming none loads, 0x4002e522). Its + * track levels (the LEVEL knob, the mixer) are int16 at this + 0x14 + 2 t. */ +#define TRACK_SOUNDS (*(const volatile uint32_t *)0x80004704u) +/* Each track's level as the sound chip gets it, int16 (just before the parameter targets; emulator: the LEVEL knob on + * tracks 1 and 4 changed 0x80003340 and 0x80003346 with the kit's +0x14 and +0x1a). */ +#define LEVELS ((volatile int16_t *)0x80003340u) +#define KIT_LEVELS ((const volatile int16_t *)(TRACK_SOUNDS + 0x14u)) static uint8_t voices[TRACKS]; /* the project's setting, 0 or 1 for a track that plays only its own notes */ -static uint8_t lead_of[TRACKS]; /* each track's lead, NONE outside a group */ +static uint8_t lead_of[TRACKS] = { [0 ... TRACKS - 1] = NONE }; /* each track's lead, NONE outside a group */ +static volatile uint8_t former_of[TRACKS] = { [0 ... TRACKS - 1] = NONE }; /* a track that left a group and has not + * played a note of its own: its lead */ +static volatile uint8_t formers; /* nonzero while a former_of entry may be set */ + +/* A voice track's own sound and pattern settings from before it joined its group, put back when it leaves: its + * machine, sample, filter and the rest, so VOICES back at 1 gives back the track it was. Kept in memory only, with the + * kit (core_kit_on) and pattern they came from; a project load or another kit drops them. */ +static uint32_t own_sound[TRACKS][SOUND_WORDS]; +static uint8_t own_settings[TRACKS][TRACK_SETTINGS_BYTES]; +static int16_t own_kit[TRACKS] = { [0 ... TRACKS - 1] = -1 }; /* -1: nothing kept */ +static uint32_t own_pattern[TRACKS]; static uint8_t next_voice[TRACKS]; /* per lead: where the search for a free voice starts */ static uint8_t sync_next[TRACKS]; /* per lead: the voice track the idle copy looks at next */ +static uint8_t sync_slice[TRACKS]; /* per lead: the part of the sound the idle copy compares */ static volatile uint16_t absorb; /* leads whose own note set its targets this frame */ static volatile uint16_t leads; /* leads with a group; written last by regroup */ static int16_t last[TRACKS][VALUES]; +/* A note the live-record routine put on a track of its group, for the frame to play there. The task writes an entry + * and sets `used` last; the frame interrupt clears it when it plays the note or the entry ages out. */ +static struct { + volatile uint8_t used; + uint8_t lead; + uint8_t track; + int8_t pitch; + uint16_t age; +} pending[PENDING]; + +/* Per track: a note from the keys or MIDI the frame put there without a pending entry, so before live recording saw + * it (on a unit with the pattern running the frame can come first). Its recording then lands on this track. The frame + * interrupt writes it; the task clears it when it records the note. */ +static struct { + volatile uint8_t age; /* frames since the note started, 0 for none */ + int8_t pitch; +} fresh[TRACKS]; + +static int reserved(unsigned int track) +{ + for (unsigned int k = 0; k < PENDING; ++k) { + if (pending[k].used && pending[k].track == track) { + return 1; + } + } + return 0; +} + +/* Words `first` to `end` of a track's sound in the kit made a copy of another's, a word at a time and only where they + * differ. Its own function, indexed, so the compiler does not reuse a post-incremented address register in one + * instruction (sdk/runtime/m68k_codegen.py refuses that). */ +static __attribute__((noinline)) void copy_sound(unsigned int to, unsigned int from, unsigned int first, + unsigned int end) +{ + volatile uint32_t *const d = (volatile uint32_t *)(KIT_SOUNDS + SOUND_STRIDE * to); + const volatile uint32_t *const s = (const volatile uint32_t *)(KIT_SOUNDS + SOUND_STRIDE * from); + for (unsigned int k = first; k < end; ++k) { + const uint32_t w = s[k]; + if (d[k] != w) { + d[k] = w; + } + } +} + +/* A track's settings in the current pattern made the lead's: the TRIG page defaults its steps fall back on (the note + * record's constructor at 0x400d6d24 reads them from +0x480 to +0x48b when a step sets no value of its own), then its + * length, swing and speed (+0x48c to +0x48f), so the voice's own steps play as the lead's would and stay in time with + * them. Without this a recorded chord note on a voice track took that track's own defaults (emulator: 9 dB louder and + * no envelope). */ +static void copy_track_settings(unsigned int to, unsigned int from) +{ + const uint32_t pattern = CURRENT_PATTERN; + if (!pattern) { + return; + } + volatile uint8_t *const d = (volatile uint8_t *)(pattern + TRACK_STRIDE * to + TRACK_SETTINGS); + const volatile uint8_t *const s = (const volatile uint8_t *)(pattern + TRACK_STRIDE * from + TRACK_SETTINGS); + for (unsigned int k = 0; k < TRACK_SETTINGS_BYTES; ++k) { + const uint8_t b = s[k]; + if (d[k] != b) { + d[k] = b; + } + } +} + +/* Whether a track has steps of its own in the current pattern (a trig on any step). */ +static int has_steps(unsigned int track) +{ + const uint32_t pattern = CURRENT_PATTERN; + if (!pattern) { + return 0; + } + const volatile uint8_t *const trigs = (const volatile uint8_t *)(pattern + TRACK_STRIDE * track); + for (unsigned int s = 0; s < STEPS; ++s) { + if (trigs[2 * s + 1] & 5u) { + return 1; + } + } + return 0; +} + +/* Words of a track's sound copied between the kit and its kept copy. Its own function, indexed (see copy_sound). */ +static __attribute__((noinline)) void move_words(volatile uint32_t *to, const volatile uint32_t *from, unsigned int n) +{ + for (unsigned int k = 0; k < n; ++k) { + to[k] = from[k]; + } +} + +static __attribute__((noinline)) void move_bytes(volatile uint8_t *to, const volatile uint8_t *from, unsigned int n) +{ + for (unsigned int k = 0; k < n; ++k) { + to[k] = from[k]; + } +} + +/* Keep a track's own sound and settings as it joins a group (once: a kept copy stays until it is put back). */ +static void keep_own(unsigned int track, int kit) +{ + if (own_kit[track] == kit) { + return; + } + move_words(own_sound[track], (const volatile uint32_t *)(KIT_SOUNDS + SOUND_STRIDE * track), SOUND_WORDS); + const uint32_t pattern = CURRENT_PATTERN; + own_pattern[track] = pattern; + if (pattern) { + move_bytes(own_settings[track], (const volatile uint8_t *)(pattern + TRACK_STRIDE * track + TRACK_SETTINGS), + TRACK_SETTINGS_BYTES); + } + own_kit[track] = (int16_t)kit; +} + +/* Put back a track's own sound and settings as it leaves its group, if they came from the kit (and pattern) on now; + * its next note then loads that sound in full. */ +static void restore_own(unsigned int track, int kit) +{ + if (own_kit[track] < 0) { + return; + } + if (own_kit[track] == kit) { + move_words((volatile uint32_t *)(KIT_SOUNDS + SOUND_STRIDE * track), own_sound[track], SOUND_WORDS); + const uint32_t pattern = CURRENT_PATTERN; + if (pattern && pattern == own_pattern[track]) { + move_bytes((volatile uint8_t *)(pattern + TRACK_STRIDE * track + TRACK_SETTINGS), own_settings[track], + TRACK_SETTINGS_BYTES); + } + LOADED_SOUND[track] = 0; + } + own_kit[track] = -1; +} + static void regroup(void) { uint16_t found = 0; + uint8_t was[TRACKS]; + const int kit = core_kit_on(); /* The frame interrupt reads the groups: route nothing while they change (the menu and a project load run in * tasks), and publish the leads last. */ leads = 0; for (unsigned int t = 0; t < TRACKS; ++t) { + was[t] = lead_of[t]; lead_of[t] = NONE; } /* A track that is already another lead's voice leads nothing; a group ends at track 16. */ @@ -80,8 +275,16 @@ static void regroup(void) } found |= (uint16_t)(1u << lead); next_voice[lead] = (uint8_t)lead; - /* The voices start as exact copies of the lead (every parameter, its sample slot included), so each note of - * a chord sounds alike whichever track plays it; later turns on the lead follow in core_voice_frame. */ + /* The voices start as exact copies of the lead, their sounds in the kit and their parameter targets (every + * parameter, its sample slot included), so each note of a chord sounds alike whichever track plays it; later + * turns on the lead follow in core_voice_frame. */ + for (unsigned int v = lead + 1; v < t; ++v) { + if (kit >= 0) { + keep_own(v, kit); + } + copy_sound(v, lead, 0, SOUND_WORDS); + copy_track_settings(v, lead); + } for (unsigned int j = 0; j < VALUES; ++j) { const int16_t value = TARGETS[VALUES * lead + j]; last[lead][j] = value; @@ -90,21 +293,42 @@ static void regroup(void) } } } + /* A voice track back on its own stays its lead's former voice until it plays a note of its own (core_voice_event, + * core_voice_lead); a track in a group now is no one's former voice. */ + for (unsigned int t = 0; t < TRACKS; ++t) { + const unsigned int lead = was[t]; + if (lead_of[t] != NONE && lead_of[t] != t) { + former_of[t] = NONE; + } else if (lead != NONE && lead != t) { + former_of[t] = (uint8_t)lead; + formers = 1; + LEVELS[t] = KIT_LEVELS[t]; /* its own level again (core_voice_frame gave it the lead's) */ + restore_own(t, kit); /* and its own sound and settings */ + } + } leads = found; } -/* The track a note-on of `lead` goes to: the first track of the group from the lead on that holds no note and is not - * muted, so the lead takes the first note of a chord (the trig keys and most MIDI senders send a chord's notes from - * the lowest up) and each next track the next; with every track busy, the next one in turn that is not muted, which - * ends its note as stock ends a track's note for a new one. */ -static unsigned int pick(unsigned int lead, uint32_t mutes) +static unsigned int group_size(unsigned int lead) { unsigned int size = 0; while (lead + size < TRACKS && lead_of[lead + size] == lead) { ++size; } + return size; +} + +/* The track a note-on of `lead` from the keys or MIDI goes to: the first track of the group from the lead on that holds + * no note from the keys or MIDI (a pattern note there gives way), is not taken by a note just recorded and is not + * muted, so the lead takes the first note of a chord (the trig keys and most MIDI senders send a chord's notes from the + * lowest up) and each next track the next; with every track busy, the next one in turn that is not muted, which ends + * its note as stock ends a track's note for a new one. */ +static unsigned int pick(unsigned int lead, uint32_t mutes) +{ + const unsigned int size = group_size(lead); for (unsigned int t = lead; t < lead + size; ++t) { - if (!((mutes >> t) & 1u) && !NOTE_SOURCE[t]) { + const uint32_t held = NOTE_SOURCE[t]; + if (!((mutes >> t) & 1u) && (!held || held == SEQUENCER) && !reserved(t)) { return t; } } @@ -119,6 +343,23 @@ static unsigned int pick(unsigned int lead, uint32_t mutes) return lead; } +/* The track a pattern note of `lead` goes to: the lead, or, while the lead holds a note, the first free voice track + * with no steps of its own (recorded chord notes there keep their track to themselves), so a long note rings on; with + * none, the lead, which ends its note as stock does. */ +static unsigned int pick_pattern(unsigned int lead, uint32_t mutes) +{ + if (!NOTE_SOURCE[lead]) { + return lead; + } + const unsigned int size = group_size(lead); + for (unsigned int t = lead + 1; t < lead + size; ++t) { + if (!((mutes >> t) & 1u) && !NOTE_SOURCE[t] && !reserved(t) && !has_steps(t)) { + return t; + } + } + return lead; +} + /* The pitch a record's note-off names, read as the frame's note-off path compares it with the held pitch * (0x4002e670): byte 2 of the trig's lock row, or of the record's own row (+0x24) when it has none. */ static int32_t record_pitch(const uint8_t *record) @@ -128,18 +369,48 @@ static int32_t record_pitch(const uint8_t *record) return (int8_t)lock[2]; } +/* Former voices (regroup): a note-on of a former voice's own makes it its own track again, loading its own sound in + * full; a note-off of `track` for a note a former voice of it still holds goes there (the older note ends first, as it + * would on one track). Nonzero: the record is routed. */ +static int former(uint8_t *record, unsigned int track) +{ + if (*(const uint32_t *)(record + 4) == 1u) { + if (former_of[track] != NONE) { + former_of[track] = NONE; + LOADED_SOUND[track] = 0; + } + return 0; + } + const uint32_t source = *(const uint32_t *)(record + 0x14); + const int32_t pitch = record_pitch(record); + for (unsigned int t = 0; t < TRACKS; ++t) { + if (former_of[t] == track && NOTE_SOURCE[t] == source && NOTE_PITCH[t] == pitch) { + *(uint32_t *)(record + 0x10) = t; + return 1; + } + } + return 0; +} + void core_voice_event(uint8_t *record) { - if (!leads || *(const uint32_t *)record > 1u) { + if (!(leads || formers) || *(const uint32_t *)record > 1u) { return; } const uint32_t lead = *(const uint32_t *)(record + 0x10); if (lead >= TRACKS) { return; } + if (formers && former(record, lead)) { + return; + } if (!((leads >> lead) & 1u)) { - /* A linked voice track's own note (its trigs): to no track (16), so only its lead's notes play there. */ - if (lead_of[lead] != NONE) { + if (lead_of[lead] == NONE) { + return; + } + /* A linked voice track's own steps (chord notes recorded there) play as they are: its sound is the lead's + * copy. Its own key presses go to no track (16). */ + if (*(const uint32_t *)(record + 0x14) != SEQUENCER) { *(uint32_t *)(record + 0x10) = TRACKS; } return; @@ -154,6 +425,7 @@ void core_voice_event(uint8_t *record) * In a group that note is still ringing on its own track, so a note-on from the keys or MIDI (any source but * the sequencer, whose repeated notes should ring over) for a pitch a track of the group holds goes nowhere. */ const uint32_t source = *(const uint32_t *)(record + 0x14); + to = NONE; if (source != SEQUENCER) { const int32_t pitch = record_pitch(record); for (unsigned int t = lead; t < TRACKS && lead_of[t] == lead; ++t) { @@ -162,8 +434,24 @@ void core_voice_event(uint8_t *record) return; } } + /* A note live recording has just put on a track of the group plays on that track. */ + for (unsigned int k = 0; k < PENDING; ++k) { + if (pending[k].used && pending[k].lead == lead && pending[k].pitch == pitch) { + to = pending[k].track; + pending[k].used = 0; + break; + } + } + if (to == NONE) { + /* Not recorded yet: if live recording sees it later, it records it on the track it plays on. */ + to = pick(lead, mutes); + fresh[to].pitch = (int8_t)pitch; + fresh[to].age = 1; + } + } + if (to == NONE) { + to = pick_pattern(lead, mutes); } - to = pick(lead, mutes); } else { const uint32_t source = *(const uint32_t *)(record + 0x14); const int32_t pitch = record_pitch(record); @@ -183,15 +471,72 @@ void core_voice_event(uint8_t *record) } } else { *(uint32_t *)(record + 0x10) = to; + /* A note-on from the keys or MIDI names no sound, which would load the voice's own: name the lead's. */ + if (*(const uint32_t *)(record + 4) == 1u && !*(const uint32_t *)(record + 0x3c)) { + *(uint32_t *)(record + 0x3c) = TRACK_SOUNDS + 0x34u + SOUND_STRIDE * lead; + } + } +} + +/* Live recording of a lead's note (core_voice_record_entry, the live-record routine at 0x40048fb2): args points at + * its arguments (sequencer, track, note, velocity, flag, step, ...). The note is recorded on the track of the group it + * will play on, chosen as the frame will choose it, and a pending entry tells the frame so. A note the frame has + * already played (a fresh entry) is recorded on the track playing it. Any other note the group already holds (the keys + * sending a held note again) is not recorded (track 16: the routine returns at once). */ +void core_voice_record(uint32_t *args) +{ + const uint32_t lead = args[1]; + if (!leads || lead >= TRACKS || !((leads >> lead) & 1u)) { + return; + } + const int32_t pitch = (int32_t)args[2]; + for (unsigned int t = lead; t < TRACKS && lead_of[t] == lead; ++t) { + if (fresh[t].age && fresh[t].pitch == pitch) { + fresh[t].age = 0; + args[1] = t; + return; + } + } + for (unsigned int t = lead; t < TRACKS && lead_of[t] == lead; ++t) { + if (NOTE_SOURCE[t] && NOTE_SOURCE[t] != SEQUENCER && NOTE_PITCH[t] == pitch) { + args[1] = TRACKS; + return; + } + } + unsigned int free = PENDING; + for (unsigned int k = 0; k < PENDING; ++k) { + if (!pending[k].used) { + free = k; + } else if (pending[k].lead == lead && pending[k].pitch == pitch) { + args[1] = TRACKS; /* recorded already, not played yet */ + return; + } + } + const uint32_t mutes = MUTES_OVERRIDE ? ~MUTES_OVERRIDE : MUTES; + if ((mutes >> lead) & 1u) { + return; /* a muted lead plays nothing: record as stock does */ + } + const unsigned int to = pick(lead, mutes); + args[1] = to; + if (free < PENDING) { + pending[free].lead = (uint8_t)lead; + pending[free].track = (uint8_t)to; + pending[free].pitch = (int8_t)pitch; + pending[free].age = 0; + pending[free].used = 1; } } -/* A whole track's targets from a lead's last values. Its own function, indexed, so the compiler does not reuse a - * post-incremented address register in one instruction (sdk/runtime/m68k_codegen.py refuses that). */ +/* A whole track's targets from a lead's last values, writing only those that differ. Its own function, indexed, so + * the compiler does not reuse a post-incremented address register in one instruction (sdk/runtime/m68k_codegen.py + * refuses that). */ static __attribute__((noinline)) void copy_values(volatile int16_t *to, const volatile int16_t *from) { for (unsigned int j = 0; j < VALUES; ++j) { - to[j] = from[j]; + const int16_t value = from[j]; + if (to[j] != value) { + to[j] = value; + } } } @@ -199,6 +544,23 @@ void core_voice_frame(void) { const uint16_t taken = absorb; absorb = 0; + if (formers) { + unsigned int any = 0; + for (unsigned int t = 0; t < TRACKS; ++t) { + any |= former_of[t] != NONE; + } + formers = (uint8_t)any; + } + for (unsigned int k = 0; k < PENDING; ++k) { + if (pending[k].used && ++pending[k].age > PENDING_FRAMES) { + pending[k].used = 0; + } + } + for (unsigned int t = 0; t < TRACKS; ++t) { + if (fresh[t].age && ++fresh[t].age > FRESH_FRAMES) { + fresh[t].age = 0; + } + } for (unsigned int lead = 0; lead < TRACKS; ++lead) { if (!((leads >> lead) & 1u)) { continue; @@ -226,22 +588,55 @@ void core_voice_frame(void) while (end < TRACKS && lead_of[end] == lead) { ++end; } + /* The lead's level (its LEVEL knob, the mixer) is the group's: not one of the 71 targets, so copied here. */ + const int16_t level = LEVELS[lead]; + for (unsigned int t = lead + 1; t < end; ++t) { + if (LEVELS[t] != level) { + LEVELS[t] = level; + } + } unsigned int v = sync_next[lead]; if (v <= lead || v >= end) { v = lead + 1; } - sync_next[lead] = (uint8_t)(v + 1 < end ? v + 1 : lead + 1); - if (v < end && !NOTE_SOURCE[v]) { - copy_values(TARGETS + VALUES * v, last[lead]); + unsigned int slice = sync_slice[lead]; + if (slice >= SOUND_SLICES) { + slice = 0; + } + if (v + 1 < end) { + sync_next[lead] = (uint8_t)(v + 1); + } else { + /* Every voice had this part of its sound compared: the next part from the first voice on. */ + sync_next[lead] = (uint8_t)(lead + 1); + sync_slice[lead] = (uint8_t)((slice + 1) % SOUND_SLICES); + } + if (v < end) { + /* The voice's sound in the kit and its pattern track's settings follow the lead's (its own steps load them + * when they play). A sixth of the sound a frame, so a change reaches every voice within a few dozen + * frames and the frame interrupt stays short. (On a unit with the whole sound compared every frame, page + * changes on a linked track grew slow while the pattern ran; with a sixth a frame, not.) */ + copy_sound(v, lead, SLICE_WORDS * slice, SLICE_WORDS * (slice + 1)); + copy_track_settings(v, lead); + if (!NOTE_SOURCE[v]) { + copy_values(TARGETS + VALUES * v, last[lead]); + } } } } -/* The track whose machine a track plays: its lead while it is linked, else itself (machine-frame.c sends that track's - * machine type for the sound chip's player dispatch). */ +/* The track whose machine a track plays: its lead while it is linked, and as its lead's former voice until it plays a + * note of its own, else itself (machine-frame.c sends that track's machine type for the sound chip's player + * dispatch). */ unsigned int core_voice_lead(unsigned int track) { - return track < TRACKS && lead_of[track] != NONE ? lead_of[track] : track; + if (track >= TRACKS) { + return track; + } + if (lead_of[track] != NONE) { + return lead_of[track]; + } + const unsigned int lead = former_of[track]; + return lead != NONE ? lead : track; } /* ---- SETTINGS > VOICES ------------------------------------------------------------------------------------------ */ @@ -253,13 +648,24 @@ static unsigned int active_track(void) return track < TRACKS ? track : 0; } +/* The row is core's value row (core-dt2 rows.c) with an icon and a label that follows the track. Like core_addvalue's, + * it draws the count right-aligned at the row's x + 19 with the menus' value font, and only LEFT and RIGHT change it. + * A SETTINGS row has its 9x9 icon at x + 0..8, two rows above its label's text, and the label from x + 12 (panel probe + * of the stock rows), so the label starts with spaces and the count sits between the icon and the label's text. */ +extern void core_addrow(void *menu, const void *const row[4], void *payload); +extern void core_voice_row_label(void); /* voices-entry.s: refreshes the label, then core's core_value_label */ +extern uintptr_t fw_op_new(uint32_t bytes); +extern int fw_textbox(void *bmp, const void *font, int x, int y, int align, int deco, const char *tmpl, + const char *fmt, ...); +extern const char fw_font_menu[]; + static const char *const counts[MAX_VOICES] = { "1", "2", "3", "4", "5", "6", "7", "8" }; -/* core_addvalue draws the value right-aligned at the row's x + 19, where PERSONALIZE leaves room for it. A SETTINGS - * row has its icon there and the label after it (panel probe: the value landed on the label's second character), so - * the label starts with spaces and the value takes the icon's place. */ #define LABEL_INDENT 3 static char label[16] = " T1 VOICES"; +/* The icon, rows top to bottom, bit c lit at x + c. */ +static const uint16_t icon[9] = { 0x080, 0x180, 0x080, 0x08a, 0x0e0, 0x06e, 0x011, 0x011, 0x00e }; + static uint32_t get_voices(void) { const unsigned int v = voices[active_track()]; @@ -276,7 +682,13 @@ static void set_voices(uint32_t value) static const core_value_t voices_row = { label, counts, MAX_VOICES, get_voices, set_voices }; -void core_voice_settings(void *menu) +typedef struct { + const core_value_t *row; /* first: core_value_label reads the label through it */ + void *menu; +} cell_t; + +/* Called for the row's label each time the menu asks for it: the track on now. */ +void core_voice_label_update(void) { const unsigned int track = active_track() + 1u; unsigned int i = LABEL_INDENT + 1u; @@ -291,7 +703,68 @@ void core_voice_settings(void *menu) label[i++] = rest[k]; } label[i] = 0; - core_addvalue(menu, &voices_row); +} + +static void row_select(cell_t **storage) +{ + (void)storage; /* YES does nothing */ +} + +static void row_draw(cell_t **storage, void *item, void *bmp, int x, int y) +{ + (void)storage; + (void)item; + for (int r = 0; r < 9; ++r) { + const unsigned int bits = icon[r]; + int c = 0; + while (c < 9) { + if (!((bits >> c) & 1u)) { + ++c; + continue; + } + const int from = c; + while (c < 9 && ((bits >> c) & 1u)) { + ++c; + } + fw_fillrect(bmp, x + from, y + 8 - r, x + c - 1, y + 8 - r, 1); /* fw_fillrect counts rows upward */ + } + } + const uint32_t v = get_voices(); + if (v < MAX_VOICES) { + fw_textbox(bmp, fw_font_menu, x + 19, y + 2, 2, 0, 0, counts[v]); + } +} + +static void row_change(cell_t **storage, void *item, int delta) +{ + cell_t *c = *storage; + (void)item; + int v = (int)get_voices() + delta; + if (v < 0) { + v = 0; + } + if (v >= MAX_VOICES) { + v = MAX_VOICES - 1; + } + if ((uint32_t)v != get_voices()) { + set_voices((uint32_t)v); + } + fw_invalidate((char *)c->menu + 0x38); +} + +void core_voice_settings(void *menu) +{ + static const void *const callbacks[4] = { + (const void *)core_voice_row_label, (const void *)row_select, (const void *)row_draw, (const void *)row_change, + }; + cell_t *c = (cell_t *)fw_op_new(sizeof *c); + if (!c) { + return; + } + c->row = &voices_row; + c->menu = menu; + core_voice_label_update(); + core_addrow(menu, callbacks, c); } /* ---- the project's setting ---------------------------------------------------------------------------------------- */ @@ -310,6 +783,12 @@ static void load_voices(const void *data) #ifdef MODWERK_VOICES_TEST voices[0] = MODWERK_VOICES_TEST; /* emulator test images only: track 1 leads from the first load */ #endif + /* Another project: the groups start anew and nothing kept from the last one is put back into this one's kit. */ + leads = 0; + for (unsigned int t = 0; t < TRACKS; ++t) { + lead_of[t] = NONE; + own_kit[t] = -1; + } regroup(); }