diff --git a/DUALCORE.md b/DUALCORE.md
index cf43d96..67db903 100644
--- a/DUALCORE.md
+++ b/DUALCORE.md
@@ -72,6 +72,30 @@ timeouts, core 1's stack) and a worst-case pattern are the next thing to collect
Later, outside the dual-core series: reverb and delay settings that change per song section (after shifl's
song fragments), as a separate patch set.
+## SLOOP 2.8.3: a unit whose second core misreads
+
+A report on SLOOP 2.8.1 (2 CORES, a backup over USB, the heaviest USB load the FM-1 sees): core 1 read its job's
+function wrong (03380D04 instead of `cpu1_units_job`), called it and faulted. The crash screen then ran on core 1,
+and `fm1_reboot` held core 1 first: it held itself, and the red screen stayed until a power cycle. Some FM-1 units
+misread words on core 1 when both cores are busy (fm1-x0x issues 10 and 21).
+
+2.8.3 brings X0X's hardening of `hal/fm1_cpu1.h` (commits 20353c9, 33ed62b, ed35a45):
+
+- **A check word on every job** (`fn ^ arg ^ job * 0x9E3779B1`, written before the job): core 1 runs a job only
+ when it matches, and keeps the jobs it finished in a register. A wrong one is counted (`mb.bad`) and refused,
+ and core 0 holds core 1 at the first one: the block is rendered on core 0, and SLOOP goes on with one core.
+- **The mailbox on cache lines of its own**: each core writes its own 64-byte line.
+- **A fault on core 1** writes the crash record (EMU = 000000C1 marks it) and stops there. Core 0's
+ `fm1_cpu1_wait` times out after 8 ms, holds core 1, and goes on with one core.
+- **One core until power-off** (a flag in `.noinit.c1bar`, after the other `.noinit` objects: `app.ld`). It is set
+ when core 1 is given up, or when core 0 crashes while core 1 runs. ABOUT then says 1 CORE.
+- **Core 1 held first thing at boot** (`fm1_cstart`), before the RAM it might still read is cleared.
+- **Core 1's own stack limit** in its EMU bank, as Melodee sets it.
+- **Console**: `cpu1_gave_up` (1 wrong job, 2 late, 3 barred), `cpu1_bad`, `cpu1_bad_fn`. The crash screen's C1
+ line adds BAD n.
+
+If it keeps happening on a unit: HOME menu > SYSTEM > 2ND CORE = OFF, then power off and on.
+
## Testing on the Mac first
The render reaches core 1 only through `cpu1.h`'s three calls, and the host tests have their own
diff --git a/GUIDE.md b/GUIDE.md
index 031d95d..4f16d67 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -1,6 +1,6 @@
-# SLOOP 2.8.1 — The Complete Guide
+# SLOOP 2.8.3 — The Complete Guide
Everything SLOOP does, every button, every combination, every page, in one place. This guide is written to be read from the top the first time, then used as a reference: the [cheat sheet](#26-cheat-sheet) at the end has every combination on one page.
@@ -139,7 +139,7 @@ Everything from 2.7 is unchanged and still here. Projects, autosaves and backups
Every function button has two lives:
- **Tap** it: its **pages** open (sound design, settings), as on any FM-1 firmware. Tap it again: the next page of that button. **SELECT** also walks the pages of that button, both ways. Each button remembers the last page you used.
-- **Hold** it: a **layer**. While it is held, the 16 white keys and KNOB 1–4 do something else, and after 0.14 s the screen shows the 16 keys as 16 tiles (four rows of four: keys 1–4, 5–8, 9–12, 13–16) and the knobs as dials. Let go: back to playing.
+- **Hold** it: a **layer**. While it is held, the 16 white keys and KNOB 1–4 do something else, and after 0.35 s (2.8.3; 0.14 s before: a quick tap flashed it), or at once when you use a key or knob, the screen shows the 16 keys as 16 tiles (four rows of four: keys 1–4, 5–8, 9–12, 13–16) and the knobs as dials. Let go: back to playing.
The layers are **FX** (punch-in effects), **EDIT** (erase), **ARP** (note repeat), **SEQ** (steps), **SEL** (key and chords), **GLO** (mix) and **SAVE** (song). ENV and LFO have no layer: they only open pages.
@@ -238,7 +238,7 @@ The FM-1's keys have no velocity: on the drum track every hit has one of four **
- **Levels:** GHOST, SOFT, NORM, HARD (hold OCT− / OCT+ while you hit). Softer hits are darker as well as quieter.
- **Ratchets:** a hit can repeat x1–x4 inside its step (ARP rolls record them; SEQ + step + KNOB 3 sets them).
- **Choke:** the closed hat and the pedal hat cut the open hat.
-- **6 drum voices**, separate from the synths' 8.
+- **6 drum voices**, separate from the synths' 8. (2.8.3) When all six sound, a hit takes the voice of its own sound if it still rings (a hi-hat cuts the last hi-hat, as on a drum machine), else the oldest voice, the kick last: on a busy beat the kick no longer drops out.
### Kits
@@ -293,7 +293,7 @@ While the song plays in song mode, the grid's hit and level knobs wait (*STOP TH
## 8. Recording
-SLOOP records live and layers every pass on top of the last (overdub). Notes go to the nearest step **as you heard it**: the ~12 ms between a key and its sound are taken back, so what you play on the beat lands on the beat. Chords are kept on the synth tracks whose VOICE is POLY (up to 4 notes a step; a MONO, LEGATO or UNISON sound, as most basses and leads, plays and records one note at a time); held notes become ties. (2.7.1) On a POLY track each held note goes on until its own key is let go, even while other notes start and end over it: hold a note, play others on top, and it keeps sounding in the pattern (up to 4 at once). (2.7.2) On a MONO, LEGATO or UNISON track, a note played while the one before is still held is recorded **legato** and plays back as you played it: with LEGATO the sound goes on into the new note without a new attack (it glides only with GLIDE or a SLIDE), where before the sequencer ended the note and started the next one again. It works from the FM-1's keys and from a MIDI controller alike. Let go of the second note while the first is still held: the pattern does not go back to the first one (the live sound does). The TRACKS page draws one mark a step; the NOTES page shows a chord's notes one by one (*2/3*…).
+SLOOP records live and layers every pass on top of the last (overdub). Notes go to the nearest step **as you heard it**: the ~12 ms between a key and its sound are taken back, so what you play on the beat lands on the beat. Chords are kept on the synth tracks whose VOICE is POLY (up to 4 notes a step; a MONO, LEGATO or UNISON sound, as most basses and leads, plays and records one note at a time); held notes become ties. (2.7.1) On a POLY track each held note goes on until its own key is let go, even while other notes start and end over it: hold a note, play others on top, and it keeps sounding in the pattern (up to 4 at once). (2.7.2) On a MONO, LEGATO or UNISON track, a note played while the one before is still held is recorded **legato** and plays back as you played it: with LEGATO the sound goes on into the new note without a new attack (it glides only with GLIDE or a SLIDE), where before the sequencer ended the note and started the next one again. It works from the FM-1's keys and from a MIDI controller alike. Let go of the second note while the first is still held: the pattern does not go back to the first one (the live sound does). (2.8.3) Recording on a MONO or LEGATO sound (track 1's 808 BOOM is one), the screen says *MONO: SET VOICE POLY* the first time you play a key over a held one: to hold a note under others, set VOICE to POLY (EDIT → VOICE page, VCE) or record on a POLY sound. (2.8.3) On a POLY track a note you hold is never cut nor restarted by the pattern while you hold it, and it goes on through the steps that already have notes (an overdub over a melody), up to 4 notes a step. The TRACKS page draws one mark a step; the NOTES page shows a chord's notes one by one (*2/3*…).
**Over held notes (2.7).** On a POLY track, a note you record while held notes of the pattern ring (a pad tied over the bar) no longer cuts them: they go on under it, and your note ends where you let it go. Up to 4 notes sound at once on a track (a fifth makes the oldest held one end there). Entering steps by hand (SEQ + key) still replaces what plays, so a long note can be cut on purpose. On SLOOP 2.6 such a pattern plays the held notes again where a note was laid over them.
@@ -309,6 +309,8 @@ SLOOP records live and layers every pass on top of the last (overdub). Notes go
REC again while armed disarms it (*REC OFF*). In **song mode**, REC waits until the song is stopped (*STOP THE SONG FIRST*), and arming REC switches back to loop mode.
+(2.8.3) A free take keeps what you held, too: on a POLY track a note held while you play others over it goes on under them when the loop closes (up to 4 notes a step), where it used to stop at the next note.
+
While recording, the REC light is solid and the track shows a red *rec*. **Turn ALGORITHM** while recording and the take moves to the next track without stopping.
### The REC screen (armed, before the first note)
@@ -483,7 +485,7 @@ There are three ways to enter steps:
| **keys** | the keys pressed together become the step under edit (POLY: up to 4 notes; MONO, LEG and UNI: the last one); in chord mode a key writes its whole chord, CHORD+ changes included; let go of all keys and it moves on to the next step (2.7.1: MENU → SEQ → **STEP ADVANCE OFF**: it stays, and the next keys write the same step again, for a chord tried twice) · **a MIDI keyboard** too (2.6): the notes it plays together on the selected track (the track its channel plays, GLO → MIDI) become the step, as they sound; on another track's channel, stopped, the screen says *MIDI PLAYS TRACK n* (and when you record: see REC) |
| KNOB 1 **NOTE** | goes from note to note: a chord's notes one by one, then the next step (the empty ones too, to put a note there); the TIEs of a note are its length, not stops |
| KNOB 2 **PITCH** | that note's pitch (a chord's others stay); an empty step gets your last note |
-| KNOB 3 **LEN** | how many steps the note lasts: longer turns the steps after it into TIEs (it stops at the next step that has notes, and at the pattern's end: *NOTE AHEAD*, *END OF PATTERN*), shorter turns its last TIEs back into RESTs |
+| KNOB 3 **LEN** | how many steps the note lasts: longer turns the steps after it into TIEs, shorter turns its last TIEs back into RESTs. (2.8.3) On a POLY track it goes on **under the notes after it**: a long bass under a melody, each note keeping its own length (up to 4 notes a step: *STEP FULL: 4 NOTES*). It stops at the pattern's end (*END OF PATTERN*), at the same pitch played again or a step with ratchets or a slide (*NOTE AHEAD*), and on a MONO, LEGATO or UNISON sound, which plays one note at a time (*MONO: SET VOICE POLY*: VOICE page, VCE = POLY) |
| KNOB 4 **FORCE** | **GHOST**, **SOFT**, **NORM**, **HARD**, then **ACC** (the accent: the step's, for its whole chord) |
| **PRESETS** | the zoom: 8, 16 (as it opens), 32 or 64 steps on the screen (the page with the note under edit) |
| **EDIT (tap)** | deletes the note under edit (a chord keeps its others; its last note takes the step and its TIEs) |
@@ -693,7 +695,7 @@ Tap a button to open its first page (or the last one you used); **tap it again**
| Button | Page | KNOB 1 | KNOB 2 | KNOB 3 | KNOB 4 |
| --- | --- | --- | --- | --- | --- |
-| **ENV** | **ENV** | ATK attack | DEC decay | SUS sustain | REL release |
+| **ENV** | **ENV** | ATK attack (2.8.3: on SAMPLE and SLICE every note starts with it, also a sample played again while its voice still sounds) | DEC decay | SUS sustain | REL release |
| | **ENV DEST** | FLT: envelope → brightness (±) | PIT: envelope → pitch (±, the 808 punch) | SHP: envelope → the engine's shape (±) | ESYNC (2.6): OFF / ON, ATK DEC REL as note values |
| **LFO** | **LFO** | RATE (Hz) | WAVE: SIN, TRI, SAW, SQR, S&H | PHS phase | FADE (fade-in time) |
| | **LFO 2** (2.6) | SYNC: OFF, 4BAR, 2BAR, 1BAR, 1/2, 1/4, 1/8, 8T, 1/16, 16T, 1/32 | TRIG: NOTE / FREE | POL: BI / UNI | — |
@@ -925,7 +927,7 @@ The visualiser sees the mix **as if MASTER were all the way up**: with MASTER tu
| **LIGHTS** | **LIGHTS**: OFF, LOW, MID, HIGH | **KEYS**: OFF, C KEYS, WHITE KEYS, ALL KEYS | **NOTES**: OFF / ON | — |
| **AUDIO** | **SPEAKER LOWCUT**: ON cuts the lows the small speaker cannot play (~110 Hz) | **USB AUDIO**: MASTER / FULL | **USB RATE** (2.7): AUTO / 44.1 KHZ / 48 KHZ (takes effect at the next start) | **FILTER RESO** (2.7.2): the resonance of the per-track filter, 0 (clean, as before) … 10 |
| **SEQ** (2.7.1) | **STEP ADVANCE**: ON (the default) the NOTES page moves on when you let go of the keys; OFF it stays, so a chord you missed is played again on the same step (KNOB 1 moves the cursor) | **DRUM PREVIEW**: OFF (the default) a drum sound picked with a knob (DRUMS screen, SEQ layer) is not heard, quiet for live; ON you hear it, as up to 2.7 | — | — |
-| **SYSTEM** | **2ND CORE** (2.7): **ON** (the default) / OFF. ON, the sound is computed on both of the FM-1's cores: about twice the room before the CPU runs out (many voices, INSERT effects on several tracks), the same sound. ON takes effect at the next power-on; ABOUT then says *2 CORES* (*1 CORE*: the second core did not answer and SLOOP runs on one, as before). OFF: one core, as in 2.6 | **HARDWARE CALIBRATION** (the knob selects it, OCT+ opens it) | **MIDI LEARN CLEAR** (2.6): how many CCs are learned; OCT+ forgets them all | **ABOUT**, the version (the knob selects it, OCT+ opens it) |
+| **SYSTEM** | **2ND CORE** (2.7): **ON** (the default) / OFF. ON, the sound is computed on both of the FM-1's cores: about twice the room before the CPU runs out (many voices, INSERT effects on several tracks), the same sound. ON takes effect at the next power-on; ABOUT then says *2 CORES* (*1 CORE*: the second core did not answer and SLOOP runs on one, as before). OFF: one core, as in 2.6. (2.8.3) On some FM-1s the second core can misread a word under heavy load (a backup over USB): it checks every job before running it and refuses a wrong one, and SLOOP then goes on with one core until the next power-off (ABOUT: *1 CORE*) instead of crashing; if a crash happens while both cores run, the next start is on one core too, until you power off. If it keeps happening on your FM-1, set 2ND CORE to OFF | **HARDWARE CALIBRATION** (the knob selects it, OCT+ opens it) | **MIDI LEARN CLEAR** (2.6): how many CCs are learned; OCT+ forgets them all | **ABOUT**, the version (the knob selects it, OCT+ opens it) |
**The knobs (2.7).** A slow turn is fine tuning, one value a detent. Turn faster and the value sweeps wider, progressively (x2 up to x16 on the widest values); turning back to correct is always one value a detent, and lists of names never jump. MENU → SCREEN → KNOB ACCEL OFF keeps one value a detent everywhere. **LEVEL and PAN glide** over about 3 ms instead of stepping at each detent, on every track and the drums: no zipper on a held note. Both after JIANT FM by juanjiant-bit.
diff --git a/README.md b/README.md
index 3ae1ef3..81aebcd 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ Free and open source (GPL-3.0), based on
-# SLOOP 2.8.1
+# SLOOP 2.8.3
**A live groovebox firmware for the M-VAVE FM-1 — for any style.** Four tracks — three synths and a drum machine with 16 sounds on the white keys — twelve synthesis engines (six-operator FM with DX7 patches, and now physical models and noise), 153 sounds, 37 drum kits (808, 909, trap, phonk, house, techno, UK garage, jungle, amapiano, reggaeton, synthwave, chiptune, ambient, jazz…), your own samples, ghost notes and ratchets, parameter locks, micro timing and fills, note repeat, one-key chords, 27 punch-in effects, a vinyl / sidechain / DJ-filter master, and a teenage-engineering-style screen that always shows what your hands can do next. No factory patterns, nothing to load: everything you hear, you play.
SLOOP is free and open source (GPL-3.0), based on [Felucca](https://github.com/hugelton/Felucca) by Leo Kuroshita / Hügelton Instruments.
-> **Status:** 2.8.1, running on the FM-1. Still a beta: install at your own risk, and please report what you find (GitHub issues).
+> **Status:** 2.8.3, running on the FM-1. Still a beta: install at your own risk, and please report what you find (GitHub issues).
+
+> **2.8.3:** hold a note under others. On a POLY track, a note you hold while you play others over it keeps sounding while you record and when you play it back, in a free take too (it used to restart and cut out), it goes on through steps that already have notes when you overdub, and in SEQ → NOTES its LEN now runs on under the notes after it (a long bass under a melody) instead of stopping at *NOTE AHEAD*. On a MONO or LEGATO sound (track 1's 808 BOOM), the screen says *MONO: SET VOICE POLY*. MIDI in: a burst too fast to keep no longer leaves a note stuck. A quick tap on a button no longer flashes its layer page: a layer shows after 0.35 s held (0.14 s before), or at once when you use a key or knob. Drums: on a busy beat the kick (and the other hits) no longer drop out: a drum sound hit again takes its own voice before another's, and the kick is taken last. Samples (SAMPLE, SLICE): a sample played again on a voice still sounding (the same chop again on POLY, every note on MONO, LEGATO or UNISON) now starts from silence with its ATK; it used to start at the level the voice had, with a click, and ATK did nothing. The second core: on some FM-1s it can misread a word under heavy USB traffic (a backup over USB); it now checks every job before running it and refuses a wrong one, and SLOOP goes on with one core until the next power-off instead of crashing (a fault on the second core used to leave the crash screen until a power cycle).
> **2.8.1:** the per-step note sheet (hold **OCT+**) is now a strip along the bottom of the screen instead of a box over the sequencer, so the piano roll and the drum grid stay fully visible; and it reopens on the row you last used, for a quick MOVE.
@@ -225,7 +227,7 @@ The four dials at the bottom of the screen show what KNOB 1–4 do now. White al
## The panel: tap, hold, layers
-Every function button has two lives. **Tap** it (press and let go, touching nothing else): its pages open, as on any FM-1 firmware. **Hold** it: a **layer** — the 16 white keys and KNOB 1–4 change job while it is held, and after 0.14 s the screen shows the 16 keys as tiles and the knobs as dials. Let go: back to playing.
+Every function button has two lives. **Tap** it (press and let go, touching nothing else): its pages open, as on any FM-1 firmware. **Hold** it: a **layer** — the 16 white keys and KNOB 1–4 change job while it is held, and after 0.35 s (or at once when you use a key or knob) the screen shows the 16 keys as tiles and the knobs as dials. Let go: back to playing.
The tiles are four rows of four, keys 1–4, 5–8, 9–12, 13–16. To find them without looking at the screen, the first key of each row (1, 5, 9, 13) glows dimly while a layer is held, and on the drum track; the keys at full light are what is on.
diff --git a/build-sloop.ps1 b/build-sloop.ps1
index 2578538..96aac8d 100644
--- a/build-sloop.ps1
+++ b/build-sloop.ps1
@@ -1,17 +1,17 @@
-# SLOOP 2.8.1: build the firmware, then open the browser installer.
+# SLOOP 2.8.3: build the firmware, then open the browser installer.
# Uses the dependencies already prepared (WSL MinUI-Build, JieLi toolchain, SDK files in build/deps/ac79).
# SLICE stays out (FELUCCA_SLICE=0): with its built-in BREAK the image does not fit the app slot.
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
Write-Host ""
-Write-Host " S L O O P 2.8.1" -ForegroundColor White
+Write-Host " S L O O P 2.8.3" -ForegroundColor White
Write-Host " ---- ---- ---- ----" -ForegroundColor DarkGray
Write-Host "== Building the firmware (WSL MinUI-Build)" -ForegroundColor Cyan
Remove-Item Env:FELUCCA_SLICE -ErrorAction SilentlyContinue
python tools/build_windows.py --distro MinUI-Build --toolchain /root/fm1-codex-deps/jieli/toolchain --sdk build/deps/ac79 --slice 0
if ($LASTEXITCODE -ne 0) { throw "The build failed" }
Write-Host "== Making the installer site" -ForegroundColor Cyan
-python web/make_site.py build/felucca.fwsc 2.8.1 build/sloop-site
+python web/make_site.py build/felucca.fwsc 2.8.3 build/sloop-site
if ($LASTEXITCODE -ne 0) { throw "make_site failed" }
Write-Host ""
Write-Host "Installer: http://localhost:8766/webapp/installer/ (Chrome or Edge, FM-1 on USB)" -ForegroundColor Green
diff --git a/docs/firmware/sloop-2.8.1.fwsc b/docs/firmware/sloop-2.8.1.fwsc
deleted file mode 100644
index bd5724c..0000000
Binary files a/docs/firmware/sloop-2.8.1.fwsc and /dev/null differ
diff --git a/docs/firmware/sloop-2.8.3.fwsc b/docs/firmware/sloop-2.8.3.fwsc
new file mode 100644
index 0000000..de21c9e
Binary files /dev/null and b/docs/firmware/sloop-2.8.3.fwsc differ
diff --git a/docs/webapp/editor/index.html b/docs/webapp/editor/index.html
index e36dacd..12c6c2f 100644
--- a/docs/webapp/editor/index.html
+++ b/docs/webapp/editor/index.html
@@ -890,7 +890,7 @@
-
+
diff --git a/docs/webapp/editor/sloop-preview.wasm b/docs/webapp/editor/sloop-preview.wasm
index 0723478..88069fd 100644
Binary files a/docs/webapp/editor/sloop-preview.wasm and b/docs/webapp/editor/sloop-preview.wasm differ
diff --git a/docs/webapp/installer/index.html b/docs/webapp/installer/index.html
index ff291e7..3973c24 100644
--- a/docs/webapp/installer/index.html
+++ b/docs/webapp/installer/index.html
@@ -90,7 +90,7 @@
-
+
@@ -536,7 +536,7 @@ const sayK = (k, arg = "") => { lastKey = k; lastArg = arg; $("status").textCont
const say = (txt) => { lastKey = null; $("status").textContent = txt; };
const log = (t) => { $("log").textContent += t + "\n"; };
let image = null;
-const meta = {"version": "2.8.1", "product": "FM-1_900", "pkg": "../../firmware/sloop-2.8.1.fwsc", "sha256": "64c9dfa7e75312debeae01a7c96e4ad3801eaffff9c81cb76ece9c48daf0501d"};
+const meta = {"version": "2.8.3", "product": "FM-1_900", "pkg": "../../firmware/sloop-2.8.3.fwsc", "sha256": "5444afd3c69c409352e1aed35a56205f13f11e60790de146593c4618a43f3528"};
let writing = false;
const lockAll = (on) => {
diff --git a/docs/webapp/sw.js b/docs/webapp/sw.js
index fcd7fc6..a61737e 100644
--- a/docs/webapp/sw.js
+++ b/docs/webapp/sw.js
@@ -4,9 +4,9 @@
// https, so Web MIDI asks as usual (a downloaded file on Android opens as content://, where Chrome refuses MIDI).
// Online the network always wins (the page as published, never an old one); the copy is only the fallback.
// A new site (any file changed) is a new sw.js: the new copy replaces the old one.
-const STAMP = "2.8.1-e3a0ddc85a5a"; // version + a hash of the files
+const STAMP = "2.8.3-ab5e64e912da"; // version + a hash of the files
const CACHE = "sloop-site-" + STAMP;
-const FILES = ["../firmware/sloop-2.8.1.fwsc", "editor/", "editor/FUKIAI-LICENSE.txt", "editor/fukiai.ttf", "editor/preview-worklet.js", "editor/preview.js", "editor/sloop-preview.wasm", "icon-192.png", "icon-512.png", "icon-maskable-512.png", "installer/", "sloop.webmanifest"]; // relative to this file
+const FILES = ["../firmware/sloop-2.8.3.fwsc", "editor/", "editor/FUKIAI-LICENSE.txt", "editor/fukiai.ttf", "editor/preview-worklet.js", "editor/preview.js", "editor/sloop-preview.wasm", "icon-192.png", "icon-512.png", "icon-maskable-512.png", "installer/", "sloop.webmanifest"]; // relative to this file
const KEEP = new Set(FILES.map((f) => new URL(f, self.location).href));
const key = (url) => { // the copy's name of a request: no query, index.html = the folder
diff --git a/firmware/app.ld b/firmware/app.ld
index d9bfd02..389398c 100644
--- a/firmware/app.ld
+++ b/firmware/app.ld
@@ -34,7 +34,8 @@ SECTIONS
_data_load = LOADADDR(.data);
.bss (NOLOAD) : { _bss_start = .; *(.bss*) *(.sbss*) *(COMMON) . = ALIGN(4); _bss_end = .; } > RAM
.pool (NOLOAD) : { _pool_start = .; *(.pool*) . = ALIGN(4); _pool_end = .; } > POOL
- .noinit (NOLOAD) : { *(.noinit*) } > NOINIT
+ /* (SLOOP 2.8.3) .noinit.c1bar (fm1_cpu1.h, one core until power-off) after the others: none of them moves */
+ .noinit (NOLOAD) : { *(.noinit) *(.noinit.*) } > NOINIT
_guard0 = 0x01C74000; _ustack_lo = 0x01C74100; _ustack_top = 0x01C7A000;
_guard1 = 0x01C7A000; _sstack_lo = 0x01C7A100; _sstack_top = 0x01C7C000;
/DISCARD/ : { *(.comment) *(.note*) }
diff --git a/firmware/hal/fm1_cpu1.S b/firmware/hal/fm1_cpu1.S
index d1fe008..b85c360 100644
--- a/firmware/hal/fm1_cpu1.S
+++ b/firmware/hal/fm1_cpu1.S
@@ -30,4 +30,5 @@ _c1_ustack: /* after rti the core runs on this one: the render's (filled with
_c1_ustack_top:
_c1_sstack: /* exceptions only (no interrupts on this core) */
.space 256
+ .globl _c1_sstack_top
_c1_sstack_top:
diff --git a/firmware/hal/fm1_cpu1.h b/firmware/hal/fm1_cpu1.h
index 7c2a00d..a6a6363 100644
--- a/firmware/hal/fm1_cpu1.h
+++ b/firmware/hal/fm1_cpu1.h
@@ -1,7 +1,14 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Charles Vestal: from X0X (github.com/charlesvestal/fm1-x0x, commit 00bff73),
* after Melodee's dual-core audio by Kerem Kilic (github.com/keremimo/melodee). Brought into SLOOP
- * unchanged but for this notice (the SLOOP dualcore branch, github.com/andrerezemini/sloop-lab). */
+ * unchanged but for this notice (the SLOOP dualcore branch, github.com/andrerezemini/sloop-lab).
+ * SLOOP 2.8.3: X0X's hardening brought in (its commits 20353c9, 33ed62b, ed35a45: the check word, a
+ * wrong job refused, one core until power-off after it was given up, core 1's own stack guard), but
+ * for fm1_cpu1_hold (SLOOP 2.7.1: fm1_sys.h's fm1_cpu1_halt, the bus-invalid traps off around the hold)
+ * and the bar's section (.noinit.c1bar: placed after the other .noinit objects, app.ld, so none of
+ * them moves). A FM-1 report (a backup over USB, SLOOP 2.8.1, 2 CORES): core 1 read its job's
+ * function wrong (03380D04 for cpu1_units_job), jumped there and faulted; the crash screen then ran on
+ * core 1, and fm1_reboot held core 1 first: it held itself, the red screen stayed until a power cycle. */
/* The AC79's second core (docs/plans/2026-10-04-dual-core-and-clock.md), with what Melodee's
* dual-core audio (github.com/keremimo/melodee, GPL-3.0) found on the device.
*
@@ -11,8 +18,17 @@
* PC limits refuse, so they are open until it has reported in from fm1_c1_main. Hold is bit 1
* set, then bit 3 cleared.
*
- * Work: one job at a time, a function and an argument; core 0 hands it over (c1_job) and waits
- * for it (c1_done), single writer each way, csync around each (the cores share the caches).
+ * Work: one job at a time, a function and an argument; core 0 hands it over (mb.job) and waits
+ * for it (mb.done), single writer each way, csync around each (the cores share the caches).
+ *
+ * Units that cannot run it (fm1-x0x#10, measured by Jangada, github.com/zednaked/jangada): on some
+ * FM-1s core 1 reads words that are not in RAM (0x00200000 where core 0 reads 0), idle now and then,
+ * often under load. So core 1 runs only the next job, and only when its check word (the function,
+ * the argument and the job's number, written before the job) matches; the jobs it finished stay in a
+ * register (Melodee's, keremimo/melodee#21: a stale function read as the next job fails the check).
+ * Anything else it counts (mb.bad) and leaves, and core 0 holds it at the first one (fm1_cpu1_wait):
+ * one core from then on. The mailbox keeps each core's writes on cache lines of their own
+ * (Jangada's layout).
*
* Flash: the waiting loop is in RAM (.c1_text), so an idle core 1 never fetches from the flash;
* it works only for the audio interrupt, which waits for it before it returns, and core 0 turns
@@ -26,32 +42,77 @@
#define FM1_C1_SYNC() __asm__ volatile("csync" ::: "memory")
extern void fm1_c1_entry(void);
-extern uint32_t _c1_ustack[];
+extern uint32_t _c1_ustack[], _c1_sstack_top[];
#define FM1_C1_STACK_WORDS (2816u / 4u)
#define FM1_C1_MARK 0x43314D4Bu /* "C1MK": how deep core 1's stack has gone */
-static volatile uint32_t fm1_c1_alive, fm1_c1_job, fm1_c1_done, fm1_c1_arg;
+typedef struct {
+ volatile uint32_t job, arg; /* core 0: job + 1 hands fn(arg) over */
+ void (*volatile fn)(uint32_t);
+ volatile uint32_t check; /* FM1_C1_CHECK of fn, arg and job */
+ uint32_t pad0[12];
+ volatile uint32_t alive, done; /* core 1: started; the last job it finished */
+ volatile uint32_t bad, bad_job, bad_done, bad_fn; /* jobs it would not run: how many, the last one */
+ uint32_t pad1[10];
+} fm1_c1_mb_t;
+static fm1_c1_mb_t fm1_c1_mb __attribute__((aligned(64)));
volatile uint32_t fm1_c1_trace; /* breadcrumbs (fm1_cpu1.S, fm1_c1_main) */
-static void (*volatile fm1_c1_fn)(uint32_t);
static uint8_t fm1_c1_on; /* started and answering: core 0 may hand it work */
+#define FM1_C1_CHECK(fn, arg, job) ((uint32_t)(uintptr_t)(fn) ^ (arg) ^ (job) * 0x9E3779B1u)
+static uint8_t fm1_c1_gave_up; /* 1 = it read a wrong job, 2 = it did not finish one, 3 = barred */
+/* one core until power-off (after Melodee 1.0.2): set when core 1 is given up or core 0 crashes beside it;
+ * .noinit survives a warm reset, power-off clears it. Not static: see fm1_crash (fm1_irq.h) */
+#define FM1_C1_BAR_MAGIC 0x43314241u /* "C1BA" */
+struct { uint32_t magic, barred; } fm1_c1_bar __attribute__((section(".noinit.c1bar"))); /* (SLOOP: app.ld) */
+static void fm1_cpu1_bar(void) { fm1_c1_bar.magic = FM1_C1_BAR_MAGIC; fm1_c1_bar.barred = 1; }
void fm1_c1_main(void);
void __attribute__((section(".c1_text"), noreturn, used)) fm1_c1_main(void)
{
+ /* its own guards, as Melodee sets them (its fm1_core1_main): a stack limit in core 1's EMU bank
+ * (core 0's is at 0x1EEF0D0) over both its stacks less the lowest 256 bytes, and EMU_CON bit 2
+ * and bits 16..20 off, bit 3 (the stack limit) on */
+ uint32_t lo = (uint32_t)(uintptr_t)_c1_ustack + 256u, hi = (uint32_t)(uintptr_t)_c1_sstack_top - 1u;
+ uint32_t done, last_bad = 0xFFFFFFFFu;
+ *(volatile uint32_t *)0x1EEF2D8u = hi;
+ *(volatile uint32_t *)0x1EEF2DCu = lo;
+ *(volatile uint32_t *)0x1EEF2E0u = hi;
+ *(volatile uint32_t *)0x1EEF2E4u = lo;
+ *(volatile uint32_t *)0x1EEF2D0u = (*(volatile uint32_t *)0x1EEF2D0u & ~((1u << 2) | (0x1Fu << 16))) | (1u << 3);
fm1_c1_trace = 0xC1000002;
- fm1_c1_alive = 1;
+ done = fm1_c1_mb.done;
+ fm1_c1_mb.alive = 1;
FM1_C1_SYNC();
for (;;) {
- uint32_t j = fm1_c1_job;
+ uint32_t j = fm1_c1_mb.job;
FM1_C1_SYNC();
- if (j != fm1_c1_done) {
- fm1_c1_fn(fm1_c1_arg); /* the work itself runs from the flash */
+ if (j == done)
+ continue;
+ if (j == done + 1u) {
+ void (*fn)(uint32_t) = fm1_c1_mb.fn;
+ uint32_t arg = fm1_c1_mb.arg;
+ if (fn && fm1_c1_mb.check == FM1_C1_CHECK(fn, arg, j)) {
+ fn(arg); /* the work itself runs from the flash */
+ done = j;
+ FM1_C1_SYNC();
+ fm1_c1_mb.done = j;
+ FM1_C1_SYNC();
+ continue;
+ }
+ fm1_c1_mb.bad_fn = (uint32_t)(uintptr_t)fn;
+ }
+ if (j != last_bad) { /* each wrong value once (it stays until core 0 holds it) */
+ last_bad = j;
+ fm1_c1_mb.bad_job = j;
+ fm1_c1_mb.bad_done = done;
FM1_C1_SYNC();
- fm1_c1_done = j;
+ fm1_c1_mb.bad++;
FM1_C1_SYNC();
}
}
}
+/* hold core 1 (SLOOP: fm1_sys.h's fm1_cpu1_halt, registers only; main.c fm1_cstart also holds it first thing at
+ * boot, before the RAM it may still be reading is cleared, after a reset that did not hold it) */
static void fm1_cpu1_hold(void)
{
fm1_cpu1_halt(); /* (2.7.1, fm1_sys.h) the bus-invalid traps off around the hold */
@@ -67,11 +128,17 @@ static int fm1_cpu1_start(void)
if (fm1_c1_on)
return 0;
fm1_cpu1_hold();
+ if (fm1_c1_bar.magic == FM1_C1_BAR_MAGIC && fm1_c1_bar.barred == 1u) {
+ fm1_c1_gave_up = 3;
+ return -1;
+ }
for (i = 0; i < FM1_C1_STACK_WORDS; i++)
_c1_ustack[i] = FM1_C1_MARK;
- fm1_c1_alive = 0;
+ fm1_c1_mb.alive = 0;
fm1_c1_trace = 0;
- fm1_c1_done = fm1_c1_job;
+ fm1_c1_mb.done = fm1_c1_mb.job;
+ fm1_c1_mb.fn = 0;
+ FM1_C1_SYNC();
for (i = 0; i < 32u; i++) /* its interrupt bank: all off (core 0's is at 0x1EEF100) */
*(volatile uint32_t *)(0x1EEF300u + 4u * i) = 0;
*(volatile uint32_t *)0x01C7FFF8u = (uint32_t)(uintptr_t)&fm1_c1_entry;
@@ -81,10 +148,10 @@ static int fm1_cpu1_start(void)
FM1_C1_CON |= 0x8u;
FM1_C1_CON &= ~0x2u;
t0 = FM1_C1_T4;
- while (!fm1_c1_alive && FM1_C1_T4 - t0 < 24000u * 20u) /* 20 ms */
+ while (!fm1_c1_mb.alive && FM1_C1_T4 - t0 < 24000u * 20u) /* 20 ms */
FM1_C1_SYNC();
FM1_C1_CLK = saved;
- if (!fm1_c1_alive) {
+ if (!fm1_c1_mb.alive) {
fm1_cpu1_hold();
return -1;
}
@@ -95,26 +162,38 @@ static int fm1_cpu1_start(void)
/* hand core 1 a job: 1 = it took it (fm1_cpu1_wait before touching what it works on) */
static inline int fm1_cpu1_run(void (*fn)(uint32_t), uint32_t arg)
{
+ uint32_t job;
if (!fm1_c1_on)
return 0;
- fm1_c1_fn = fn;
- fm1_c1_arg = arg;
+ job = fm1_c1_mb.job + 1u;
+ fm1_c1_mb.fn = fn;
+ fm1_c1_mb.arg = arg;
+ fm1_c1_mb.check = FM1_C1_CHECK(fn, arg, job);
FM1_C1_SYNC();
- fm1_c1_job = fm1_c1_job + 1u;
+ fm1_c1_mb.job = job;
FM1_C1_SYNC();
return 1;
}
-/* 0 = done; -1 = it did not finish in time: core 1 is held from now on (the caller does the work) */
+/* 0 = done; -1 = it read a wrong job or did not finish in time: core 1 is held from now on (the
+ * caller does the work) */
static inline int fm1_cpu1_wait(void)
{
uint32_t t0 = FM1_C1_T4;
for (;;) {
FM1_C1_SYNC();
- if (fm1_c1_done == fm1_c1_job)
- return 0;
- if (FM1_C1_T4 - t0 > 24000u * 8u) { /* 8 ms: far past any stretch */
+ if (fm1_c1_mb.bad) { /* a unit that cannot run it: one core */
fm1_cpu1_hold();
+ fm1_cpu1_bar();
+ fm1_c1_gave_up = 1;
+ return -1;
+ }
+ if (fm1_c1_mb.done == fm1_c1_mb.job)
+ return 0;
+ if (FM1_C1_T4 - t0 > 24000u * 8u) { /* 8 ms: far past any stretch (or it faulted) */
+ fm1_cpu1_hold();
+ fm1_cpu1_bar();
+ fm1_c1_gave_up = 2;
return -1;
}
}
diff --git a/firmware/hal/fm1_irq.h b/firmware/hal/fm1_irq.h
index 774a3cb..6dbcc3e 100644
--- a/firmware/hal/fm1_irq.h
+++ b/firmware/hal/fm1_irq.h
@@ -91,11 +91,33 @@ static void fm1_irq_enable_all(void)
/* called from fm1_fatal_common (fm1_vec.S) with the saved frame:
* f[0..15] r0..r15, f[16] reti, f[17] rete, f[18] retx, f[19] stub+6,
* f[20] psr, f[21] icfg, f[22] usp, f[23] ssp, f[24] sp, f[25] interrupted rets */
+extern uint32_t _c1_ustack[], _c1_sstack_top[]; /* fm1_cpu1.S (SLOOP 2.8.3, from X0X 20353c9) */
void fm1_fault_c(uint32_t *f)
{
static volatile uint32_t in_fault;
- uint32_t i, count = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.count : 0;
- uint32_t early = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.early : 0;
+ uint32_t i, count, early;
+ if (f[24] >= (uint32_t)(uintptr_t)_c1_ustack && f[24] <= (uint32_t)(uintptr_t)_c1_sstack_top) {
+ /* the second core faulted (fm1_cpu1.h) and this runs on it: the record only, then it stops here.
+ * The screen and the reset would be core 1's, and fm1_reboot holds core 1 first: it would hold
+ * itself and the FM-1 would freeze. Core 0 gives it up when its job does not come back
+ * (fm1_cpu1_wait) and goes on with one core. (Jangada, fm1-x0x#10) */
+ fm1_crash.count = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.count + 1u : 1u;
+ fm1_crash.magic = FM1_CRASH_MAGIC;
+ fm1_crash.vec = (f[19] - (uint32_t)(uintptr_t)fm1_fatal_stubs) / 6u - 1u;
+ fm1_crash.pc = f[16];
+ fm1_crash.rets = f[25];
+ fm1_crash.sp = f[24];
+ fm1_crash.psr = f[20];
+ fm1_crash.dbg = FM1_DBG_MSG;
+ fm1_crash.emu = 0xC1u; /* (SLOOP: the record's mark that core 1 faulted; fm1_crash_t keeps its
+ * size, so nothing after it in .noinit moves) */
+ fm1_crash.uptime_ms = *(volatile uint32_t *)0x10804u / 24000u;
+ __asm__ volatile("csync" ::: "memory");
+ for (;;)
+ ;
+ }
+ count = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.count : 0;
+ early = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.early : 0;
fm1_irq_off();
if (in_fault++) /* fault while reporting: reset at once */
*(volatile uint32_t *)0x10000u |= 1u << 4;
diff --git a/firmware/src/console.c b/firmware/src/console.c
index dacdec4..fbf54ab 100644
--- a/firmware/src/console.c
+++ b/firmware/src/console.c
@@ -181,6 +181,9 @@ static void con_status(void)
con_kv("cpu1", (int32_t)cpu1_state); /* 1 did not start, 2 self-test failed, 3 running (cpu1.c) */
con_kx("cpu1_trace", fm1_c1_trace);
con_kv("cpu1_timeouts", (int32_t)cpu1_timeouts);
+ con_kv("cpu1_gave_up", (int32_t)fm1_c1_gave_up); /* (2.8.3) 1 a wrong job read, 2 one late, 3 barred till power-off */
+ con_kv("cpu1_bad", (int32_t)fm1_c1_mb.bad); /* jobs core 1 read wrong and refused (fm1_cpu1.h) */
+ con_kx("cpu1_bad_fn", fm1_c1_mb.bad_fn);
con_kv("cpu1_units", cpu1_units); /* the render units it gets: -1 its share, else a mask (fx.c) */
con_kv("cpu1_busy_pct", (int32_t)(cpu1_busy_q8 * 100u / 256u)); /* its time in the render, of a half (fx.c) */
con_kv("cpu1_wait_pct", (int32_t)(cpu1_wait_q8 * 100u / 256u)); /* core 0's time waiting for it */
diff --git a/firmware/src/core.h b/firmware/src/core.h
index b204f0e..e6b875c 100644
--- a/firmware/src/core.h
+++ b/firmware/src/core.h
@@ -114,7 +114,9 @@ typedef struct {
uint8_t stage; /* env: 0 off, 1 attack, 2 decay/sustain, 3 release, 4 fading out (given up) */
uint8_t kill; /* stage 4: blocks of the fade left */
uint8_t pitch_frac; /* the glide between 1/16 semitones: pitch_cur + pitch_frac / 256 */
+ uint8_t pend; /* (2.8.3) VP_*: a sample's note waiting for its voice's fade (voice.c voice_start) */
int16_t penv; /* the pitch envelope (ENV > PIT): Q15, a fast fall from the note's start */
+ uint8_t pend_note, pend_vel; /* (2.8.3) that note (in the padding: voice_t keeps its size) */
int32_t env; /* Q24 */
int32_t env_out; /* last control-rate amplitude, Q15 */
int32_t pitch16, pitch_cur; /* 1/16 semitone, with glide */
@@ -292,6 +294,7 @@ typedef struct track {
uint8_t rh_last; /* the last of them; rh_bak: what it held (an early release puts it back) */
uint32_t rh_last_abs; /* (its step of the transport grid) */
step_t rh_bak;
+ step_t rh_put; /* (2.8.3) what the hold wrote into rh_last (an early release puts rh_bak back only over it) */
uint8_t rh_end; /* (2.7.1) one of them let go, others still held: the next step, only those go on */
uint8_t rh_rs; /* (2.7.1) rh_start is such a step (rh_last, rh_last_abs: it) */
uint8_t rh_offn, rh_off[4]; /* (2.7.1) the ones let go since the hold's last NOTE step (they end there) */
diff --git a/firmware/src/drums.c b/firmware/src/drums.c
index cb1a593..2a9b1ad 100644
--- a/firmware/src/drums.c
+++ b/firmware/src/drums.c
@@ -219,6 +219,30 @@ static void click_render(int32_t *ml, int32_t *mr, uint32_t n)
click.env = 0; /* (-72 dB: done, about 100 ms) */
}
+/* (2.8.3) the voice for a drum hit: a free voice; all busy, the sound's own voice if it still sounds (it starts over,
+ * as on a drum machine: a 16th hi-hat no longer takes every voice with its own tails); else the oldest, a kick last.
+ * Up to 2.8.2 the oldest went whatever it was: on a busy beat (16th hats, ride, crash, snare and clap) the kick lost its
+ * voice after a step or two and was cut, or not heard at all (a tester's report, "Heads Will Roll") */
+static voice_t *drum_pick(uint32_t note)
+{
+ voice_t *v = 0;
+ uint32_t i, best = 0xFFFFFFFFu;
+ for (i = 0; i < NDRUM; i++)
+ if (!drums.v[i].active)
+ return &drums.v[i];
+ for (i = 0; i < NDRUM; i++)
+ if (drums.v[i].note == note)
+ return &drums.v[i];
+ for (i = 0; i < NDRUM; i++) { /* the oldest that is not a kick; all kicks: the oldest */
+ uint32_t kick = drums.v[i].note == 35u || drums.v[i].note == 36u;
+ uint32_t key = (kick ? 0x80000000u : 0u) | (drums.v[i].age & 0x7FFFFFFFu);
+ if (key < best) {
+ best = key;
+ v = &drums.v[i];
+ }
+ }
+ return v ? v : &drums.v[0];
+}
/* a synthesised voice: note on the 16 sounds snd (a factory kit, SYN1..4), the oldest voice stolen */
static void __attribute__((noinline)) drum_synth_on(uint32_t note, uint32_t vel, uint32_t kit, const dsnd_t *snd, uint32_t crush,
int tweak)
@@ -231,14 +255,7 @@ static void __attribute__((noinline)) drum_synth_on(uint32_t note, uint32_t vel,
drums.v[i].active = 0;
drums.tail += drums.v[i].s[7];
}
- for (i = 0; i < NDRUM; i++) {
- if (!drums.v[i].active) {
- v = &drums.v[i];
- break;
- }
- if (drums.v[i].age < v->age)
- v = &drums.v[i];
- }
+ v = drum_pick(note);
if (v->active)
drums.tail += v->s[7];
i = (uint32_t)(v - drums.v);
@@ -319,14 +336,7 @@ static void drum_on(uint32_t note, uint32_t vel)
drums.v[i].active = 0;
drums.tail += drums.v[i].s[7]; /* fade what it was playing, not a step */
}
- for (i = 0; i < NDRUM; i++) { /* free voice, else the oldest */
- if (!drums.v[i].active) {
- v = &drums.v[i];
- break;
- }
- if (drums.v[i].age < v->age)
- v = &drums.v[i];
- }
+ v = drum_pick(note); /* (2.8.3: a free one, its own, else the oldest but a kick) */
if (v->active)
drums.tail += v->s[7]; /* stolen voice: fade its last value */
v->note = (uint8_t)note;
diff --git a/firmware/src/main.c b/firmware/src/main.c
index 7c9df5a..be0702d 100644
--- a/firmware/src/main.c
+++ b/firmware/src/main.c
@@ -130,6 +130,8 @@ UI_SMALL static void fm1_fault(const fm1_crash_t *c)
{
char b[12];
uint32_t t0;
+ if (fm1_c1_on) /* (2.8.3, X0X ed35a45) a crash beside the second core: one */
+ fm1_cpu1_bar(); /* core until power-off (a misread on core 0 can't be caught) */
fm1_audio_stop();
lcd_fill(0, 0, 240, 240, RGB(160, 0, 0));
draw_text_box(0, 8, 240, &FONT_S, "FELUCCA CRASH", C_WHITE, 1);
@@ -151,6 +153,8 @@ UI_SMALL static void fm1_fault(const fm1_crash_t *c)
fmt_int(t + str_len(t), (int32_t)cpu1_state);
str_cpy(t + str_len(t), " LATE ", 7);
fmt_int(t + str_len(t), (int32_t)(cpu1_timeouts > 99u ? 99u : cpu1_timeouts));
+ str_cpy(t + str_len(t), " BAD ", 6); /* (2.8.3) jobs core 1 read wrong and refused (fm1_cpu1.h) */
+ fmt_int(t + str_len(t), (int32_t)(fm1_c1_mb.bad > 99u ? 99u : fm1_c1_mb.bad));
draw_text_box(10, 162, 220, &FONT_S, t, C_WHITE, 0);
}
t0 = fm1_ticks();
@@ -366,6 +370,8 @@ UI_SMALL static void fm1_main(void)
UI_SMALL void fm1_cstart(void)
{
uint32_t *s, *d, p3, src, wdt, boot_mode;
+ fm1_cpu1_halt(); /* (2.8.3, X0X 20353c9) a second core left running by the reset would
+ * read the RAM cleared below (fm1_sys.h: registers only) */
fm1_time_init();
fm1_supplies_stock(); /* (2.7) VDC14 1.60 V, SYSVDD 1.38 V, as M-VAVE's firmware: both cores
* read the flash and SRAM right on every unit (fm1_sys.h) */
diff --git a/firmware/src/midi_uart.c b/firmware/src/midi_uart.c
index 3ce8dd4..d594ad6 100644
--- a/firmware/src/midi_uart.c
+++ b/firmware/src/midi_uart.c
@@ -72,6 +72,8 @@ static void um_byte(uint32_t b)
um.msgs++;
} else {
um.drops++;
+ if ((um.st & 0xE0u) == 0x80u)
+ midi_in_lost = 1; /* (2.8.3: a note lost: seq.c ends the MIDI notes held) */
}
}
}
diff --git a/firmware/src/seq.c b/firmware/src/seq.c
index cbb4201..379606c 100644
--- a/firmware/src/seq.c
+++ b/firmware/src/seq.c
@@ -584,6 +584,189 @@ UI_SMALL static uint32_t cont_notes(const step_t *s, uint32_t except, uint8_t *o
return n;
}
+/* ---- (2.8.3) a note's length under later notes (SEQ > NOTES LEN: ui.c note_span_set; a free take: ft_close) ----
+ * POLY: a note's LEN runs on under the notes after it: it joins their steps as a note going on (SF_CONT, as a
+ * recording over held notes writes it, seq.c rec_hold), 4 notes a step at most; after them, a NOTE of its notes only,
+ * all going on, carries it (the others end there). A long bass under a melody, programmed. MONO / LEGATO parts play one
+ * note at a time: it stops there and says so. The step format is 2.7's: a project of 2.8.3 opens in 2.7 and later.
+ * span_why: why the last note_span_set stopped short (0 a note ahead, 1 the step is full, 2 a MONO sound, 3 the end) */
+static uint8_t span_why;
+static int sp_on(const step_t *st) { return st->time == ST_NOTE && st->n; }
+UI_SMALL static uint32_t span_notes(const step_t *st, uint8_t *s) /* the notes step st starts (not ones going on) */
+{
+ uint32_t k, n = 0;
+ for (k = 0; k < st->n && k < 4u; k++)
+ if (!(st->flags & SF_CONT(k)))
+ s[n++] = st->note[k];
+ return n;
+}
+UI_SMALL static int span_in(const uint8_t *c, uint32_t nc, uint32_t note)
+{
+ uint32_t i;
+ for (i = 0; i < nc; i++)
+ if (c[i] == note)
+ return 1;
+ return 0;
+}
+/* the chain going into step j: 1 it carries all of s, and *other: notes not in s too */
+UI_SMALL static int span_chain(const track_t *t, uint32_t j, const uint8_t *s, uint32_t ns, int *other, uint8_t *oc, uint32_t *no)
+{
+ uint8_t c[4];
+ uint32_t n = chain_notes(t, j, c), i, all = 1;
+ *other = 0;
+ if (no)
+ *no = 0;
+ for (i = 0; i < ns; i++)
+ all &= (uint32_t)span_in(c, n, s[i]);
+ for (i = 0; i < n; i++)
+ if (!span_in(s, ns, c[i])) {
+ *other = 1;
+ if (oc)
+ oc[(*no)++] = c[i];
+ }
+ return n && all;
+}
+UI_SMALL static int span_cont_all(const step_t *st, const uint8_t *s, uint32_t ns) /* all of s go on in st */
+{
+ uint32_t i, k;
+ if (!sp_on(st))
+ return 0;
+ for (i = 0; i < ns; i++) {
+ for (k = 0; k < st->n && !(st->note[k] == s[i] && (st->flags & SF_CONT(k))); k++)
+ ;
+ if (k == st->n)
+ return 0;
+ }
+ return 1;
+}
+UI_SMALL static uint32_t span_len(const track_t *t, uint32_t i, const uint8_t *s, uint32_t ns) /* the steps s sounds from i */
+{
+ uint32_t len = (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP), n = 1;
+ int other;
+ while (i + n < len) {
+ const step_t *st = &t->step[i + n];
+ if (st->time == ST_TIE ? !span_chain(t, i + n, s, ns, &other, 0, 0) : !span_cont_all(st, s, ns))
+ break;
+ n++;
+ }
+ return n;
+}
+UI_SMALL static void span_drop(step_t *st, const uint8_t *s, uint32_t ns) /* s's notes going on in st: out */
+{
+ uint32_t k = 0;
+ while (k < st->n) {
+ if ((st->flags & SF_CONT(k)) && span_in(s, ns, st->note[k])) {
+ uint32_t j, c;
+ for (j = k; j + 1u < st->n; j++)
+ st->note[j] = st->note[j + 1u];
+ st->lvl = (uint8_t)((st->lvl & ((1u << (2u * k)) - 1u)) | ((st->lvl >> (2u * k + 2u)) << (2u * k)));
+ st->rat = (uint8_t)((st->rat & ((1u << (2u * k)) - 1u)) | ((st->rat >> (2u * k + 2u)) << (2u * k)));
+ c = (st->flags & SF_CONT_ALL) / SF_CONT0;
+ c = (c & ((1u << k) - 1u)) | ((c >> (k + 1u)) << k);
+ st->flags = (uint8_t)((st->flags & ~SF_CONT_ALL) | c * SF_CONT0);
+ st->n--;
+ } else {
+ k++;
+ }
+ }
+ if (!st->n) {
+ memset(st, 0, sizeof *st);
+ st->time = ST_REST;
+ }
+}
+/* the notes s (started at step i) sound want steps; returns the steps they got (span_why: why fewer) */
+UI_SMALL static uint32_t span_set(track_t *t, uint32_t i, const uint8_t *s, uint32_t ns, uint32_t want)
+{
+ uint32_t len = (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP), cur, j, n, no, k;
+ uint8_t oc[4];
+ int other;
+ span_why = 3;
+ cur = span_len(t, i, s, ns);
+ if (want == cur)
+ return cur;
+ /* 1. back to one step: what carried its notes after it goes. Read first (the chains as they are), then written: a
+ * TIE of its notes only goes (a REST), its notes going on in later steps go; the melody's TIEs stay (theirs again) */
+ {
+ uint8_t act[NSTEP];
+ for (j = i + 1u; j < i + cur; j++)
+ act[j] = t->step[j].time == ST_TIE ? (uint8_t)(span_chain(t, j, s, ns, &other, 0, 0) && !other) : 2u;
+ for (j = i + 1u; j < i + cur; j++) {
+ step_t *st = &t->step[j];
+ if (act[j] == 1u) {
+ if (!st->n)
+ memset(st, 0, sizeof *st);
+ st->time = ST_REST; /* (a TIE holding notes (an older SLOOP) keeps them) */
+ } else if (act[j] == 2u) {
+ span_drop(st, s, ns);
+ }
+ }
+ for (j = i + 1u; j <= i + cur && j < len; j++) { /* an end it left in a melody's note (step 3 below): a TIE again */
+ step_t *st = &t->step[j];
+ uint8_t c[4];
+ uint32_t nc, m, same;
+ if (!step_pure_cont(st) || j == i)
+ continue;
+ nc = chain_notes(t, j, c);
+ same = nc == st->n;
+ for (m = 0; m < st->n && same; m++)
+ same = (uint32_t)span_in(c, nc, st->note[m]);
+ if (same) {
+ memset(st, 0, sizeof *st);
+ st->time = ST_TIE;
+ }
+ }
+ }
+ /* 2. on to want */
+ for (n = 1, j = i + 1u; n < want && j < len; n++, j++) {
+ step_t *st = &t->step[j];
+ if (st->time == ST_TIE) {
+ if (!span_chain(t, j, s, ns, &other, 0, 0)) {
+ span_why = 0;
+ break;
+ }
+ continue;
+ }
+ if (sp_on(st)) {
+ uint32_t add = 0;
+ if (t->p[P_VOICE] != V_POLY) {
+ span_why = 2;
+ break;
+ }
+ for (k = 0; k < ns; k++)
+ add += !span_in(st->note, st->n, s[k]);
+ if (add < ns || st->rat || (st->flags & SF_SLIDE)) { /* (the same pitch played there, ratchets, a slide) */
+ span_why = 0;
+ break;
+ }
+ if (st->n + add > 4u) {
+ span_why = 1;
+ break;
+ }
+ for (k = 0; k < ns; k++) {
+ st->flags |= (uint8_t)SF_CONT(st->n);
+ st->note[st->n++] = s[k];
+ }
+ continue;
+ }
+ span_chain(t, j, s, ns, &other, 0, 0);
+ memset(st, 0, sizeof *st);
+ if (other) { /* after a melody's note: its notes only, going on */
+ for (k = 0; k < ns; k++) {
+ st->note[k] = s[k];
+ st->flags |= (uint8_t)SF_CONT(k);
+ }
+ st->n = (uint8_t)ns;
+ st->time = ST_NOTE;
+ } else {
+ st->time = ST_TIE;
+ }
+ }
+ /* 3. it ends inside a melody's note: from there, the melody's only */
+ if (j < len && t->step[j].time == ST_TIE && span_chain(t, j, s, ns, &other, oc, &no) && other)
+ chain_end(t, j, oc, no);
+ return n;
+}
+
/* (2.7.1) several notes held while recording (POLY): each goes on until its own key is let go. A note recorded over a
* held one makes its step a NOTE of the held ones going on + the new one (as over a pattern's held notes, above); one let
* go while others are held ends there: the step it ends on becomes a NOTE of the others only, all going on (hold_restart),
@@ -752,6 +935,48 @@ static void rec_hit(track_t *t, uint32_t lane, uint32_t lvl, uint32_t rat)
}
/* the sequencer enters step idx (before playing it): a recorded note still held ties into it */
+/* (2.8.3) POLY: the notes held go on through a step that has notes of its own (an overdub over a recorded melody):
+ * they join it as notes going on (SF_CONT), 4 notes a step at most. 0: no room, the hold ends before it (as up to 2.8.1) */
+UI_SMALL static int hold_merge(track_t *t, step_t *s)
+{
+ uint32_t i, k, add = 0;
+ for (i = 0; i < t->rh_n; i++) {
+ for (k = 0; k < s->n && s->note[k] != t->rh_note[i]; k++)
+ ;
+ add += k == s->n;
+ }
+ if (t->p[P_VOICE] != V_POLY || s->n > 4u || s->n + add > 4u || (s->flags & SF_SLIDE) || s->rat)
+ return 0; /* (ratchets, a slide: the step plays as written, the hold ends) */
+ for (i = 0; i < t->rh_n; i++) {
+ for (k = 0; k < s->n && s->note[k] != t->rh_note[i]; k++)
+ ;
+ if (k == s->n)
+ s->note[s->n++] = t->rh_note[i];
+ s->flags |= (uint8_t)SF_CONT(k); /* (the same pitch there: it goes on, not played again) */
+ }
+ return 1;
+}
+/* (2.8.3) a step the hold goes on into, after notes that are not this hold's (a recorded melody's): a NOTE of the held
+ * notes only, all going on, so the melody's notes end there and only the hold goes on */
+UI_SMALL static int hold_only(track_t *t, step_t *s, uint32_t idx)
+{
+ uint8_t c[4];
+ uint32_t n = chain_notes(t, idx, c), i, other = 0;
+ if (s->time == ST_TIE)
+ return 0; /* (a TIE: the melody's note goes on with the hold, as recorded) */
+ for (i = 0; i < n; i++)
+ other |= !rh_held(t, c[i]);
+ if (!other || t->p[P_VOICE] != V_POLY || !t->rh_n)
+ return 0;
+ memset(s, 0, sizeof *s);
+ for (i = 0; i < t->rh_n && i < 4u; i++) {
+ s->note[i] = t->rh_note[i];
+ s->flags |= (uint8_t)SF_CONT(i);
+ }
+ s->n = (uint8_t)i;
+ s->time = ST_NOTE;
+ return 1;
+}
UI_SMALL static void rec_hold(track_t *t, uint32_t idx, uint32_t len, uint32_t abs)
{
step_t *s;
@@ -782,15 +1007,27 @@ UI_SMALL static void rec_hold(track_t *t, uint32_t idx, uint32_t len, uint32_t a
return;
}
if (s->time == ST_NOTE && s->n) {
- t->rh_n = 0; /* a step with notes: the hold ends before it */
+ step_t bak = *s;
+ if (hold_merge(t, s)) { /* (2.8.3) POLY: it goes on through them */
+ t->rh_bak = bak;
+ t->rh_put = *s;
+ t->rh_last = (uint8_t)idx;
+ t->rh_last_abs = abs;
+ t->rh_ties++;
+ return;
+ }
+ t->rh_n = 0; /* a step with notes, no room: the hold ends before it */
return;
}
t->rh_bak = *s;
t->rh_last = (uint8_t)idx;
t->rh_last_abs = abs;
t->rh_ties++;
- memset(s, 0, sizeof *s);
- s->time = ST_TIE;
+ if (!hold_only(t, s, idx)) { /* (2.8.3: after a melody's notes, only the hold goes on) */
+ memset(s, 0, sizeof *s);
+ s->time = ST_TIE;
+ }
+ t->rh_put = *s;
}
/* a key of a recorded note is up: the hold ends with the last one */
@@ -826,10 +1063,26 @@ UI_SMALL static void rec_release(track_t *t, uint32_t note)
t->step[t->rh_last].time = ST_REST; /* into: not held into it */
}
t->rh_end = t->rh_rs = t->rh_offn = 0;
- if (!t->rh_ties || !early)
- return;
- if (t->step[t->rh_last].time == ST_TIE)
+ if (t->rh_ties && early && (t->step[t->rh_last].time == ST_TIE || !memcmp(&t->step[t->rh_last], &t->rh_put, sizeof t->rh_put)))
t->step[t->rh_last] = t->rh_bak; /* released early in it: not held into this step */
+ { /* (2.8.3) the hold ended inside a recorded melody's note (TIEs carrying it and the held note on): from the step
+ * it ended in, only the melody's notes go on */
+ uint32_t j = t->rh_ties && early ? t->rh_last : (uint32_t)(t->rh_ties || t->rh_rs ? t->rh_last : t->rh_start) + 1u;
+ uint8_t c[4], keep[4];
+ uint32_t n, i, nk = 0, has = 0;
+ j %= len;
+ if (t->step[j].time != ST_TIE || j == t->rh_start)
+ return;
+ n = chain_notes(t, j, c);
+ for (i = 0; i < n; i++) {
+ if (c[i] == note)
+ has = 1;
+ else
+ keep[nk++] = c[i];
+ }
+ if (has && nk)
+ chain_end(t, j, keep, nk);
+ }
}
/* LIVE recording, no click needed (REC: ui_input.c rec_toggle).
@@ -1157,6 +1410,14 @@ static void ft_close(void)
uint32_t d = ft_ev[i].d == FT_OPEN || ft_ev[i].t + ft_ev[i].d > T ? T - ft_ev[i].t : ft_ev[i].d;
uint32_t idx = (ft_ev[i].t * len * 2u + T) / (2u * T) % len;
uint32_t steps = (d * len * 2u + T) / (2u * T);
+ if (t->p[P_VOICE] == V_POLY) { /* (2.8.3) POLY: on under the notes after it, as held (it used to
+ * stop at the next step with notes: a held C1 cut by the scale
+ * played over it, Sam on the FM-1). Inside the loop */
+ uint8_t nn = ft_ev[i].note;
+ if (steps > 1u)
+ span_set(t, idx, &nn, 1u, steps < len - idx ? steps : len - idx);
+ continue;
+ }
for (k = 1; k < steps && k < len; k++) {
step_t *s = &t->step[(idx + k) % len];
if (s->time == ST_NOTE && s->n)
@@ -1580,6 +1841,32 @@ static int kh_any(const track_t *t)
const uint32_t *m = kh_set[trk_index(t) % NTRK];
return (m[0] | m[1] | m[2] | m[3]) != 0u;
}
+/* (2.8.3) the notes a player holds on each track (a key, MIDI): the sequencer never restarts nor ends them, nor the
+ * notes going on for a player (the pedal, KBD HOLD). A C1 held while C2 D2 E2 were recorded over it used to restart where
+ * the take went on, then end at that step's gate, the key still down (reddit "SLOOP 2.8.1 chopping notes", after
+ * Melodee's live_held by Kerem Kilic, GPL-3.0) */
+static uint32_t live_held[NTRK][4];
+static uint32_t mi_trk_held[NTRK][4];
+static volatile uint8_t mono_hint; /* (2.8.3) a key played over a held one on a MONO / LEGATO sound while
+ * recording: the screen says how to hold both (ui_input.c, once) */ /* (2.8.3) of them, the ones a MIDI note-on holds */
+static void live_set(const track_t *t, uint32_t note, int on)
+{
+ uint32_t *w = &live_held[trk_index(t) % NTRK][(note >> 5) & 3u], bit = 1u << (note & 31u);
+ *w = on ? *w | bit : *w & ~bit;
+}
+static int live_has(const track_t *t, uint32_t note)
+{
+ uint32_t ti = trk_index(t) % NTRK, w = (note >> 5) & 3u, bit = 1u << (note & 31u);
+ return ((live_held[ti][w] | sus_wait[ti][w]) & bit) != 0u || (kh_on(t) && kh_has(t, note));
+}
+static int seq_has(const track_t *t, uint32_t note) /* a note the sequencer holds now */
+{
+ uint32_t i;
+ for (i = 0; i < t->seq_n && i < 4u; i++)
+ if (t->seq_notes[i] == note)
+ return 1;
+ return 0;
+}
static void kh_release(track_t *t) /* every held note ends */
{
uint32_t ti = trk_index(t) % NTRK, w, b;
@@ -1590,6 +1877,7 @@ static void kh_release(track_t *t) /* every held note ends */
if (ft_on && t == &trk[ft_trk % NTRK])
ft_note_off(n);
rec_release(t, n);
+ live_set(t, n, 0); /* (2.8.3: no longer held for a player) */
trk_note_off(t, n);
if ((kh_mo[ti][w] >> b) & 1u)
midi_out_note(kh_mc[ti], n, 0);
@@ -1631,6 +1919,13 @@ static void input_on(track_t *t, uint32_t note, uint32_t vel)
arp_add(t, note); /* (the arp records the notes it plays) */
return;
}
+ if (t->p[P_VOICE] != V_POLY && (((song.rec >> trk_index(t)) & 1u) || (ft_on && ft_trk == trk_index(t)))) { /* (2.8.3) one
+ * note at a time (recording, or a free take): say so */
+ const uint32_t *h = live_held[trk_index(t) % NTRK];
+ if (h[0] | h[1] | h[2] | h[3])
+ mono_hint = 1;
+ }
+ live_set(t, note, 1); /* (2.8.3) held by its key: the sequencer leaves it alone */
if (((song.rec >> trk_index(t)) & 1u) && song.playing)
rec_note(t, note, vel, 0, 1);
if (in_chord) /* a chord from the keys: maybe strummed (voice.c) */
@@ -1663,7 +1958,9 @@ static void input_off_now(track_t *t, uint32_t note)
ft_note_off(note);
rec_release(t, note);
arp_remove(t, note); /* both: the note may have started in the */
- trk_note_off(t, note); /* other mode (ARP switched while held) */
+ live_set(t, note, 0);
+ if (!(song.playing && seq_has(t, note))) /* other mode (ARP switched while held). (2.8.3) The pattern plays */
+ trk_note_off(t, note); /* it too: it ends with the pattern's note, not with the key */
}
/* a drum hit from a key, MIDI or a roll: lane, level; rat: its ratchet when recorded (rolls); rec: it
@@ -2304,7 +2601,8 @@ static void seq_release(track_t *t)
{
uint32_t i;
for (i = 0; i < t->seq_n; i++) {
- trk_note_off(t, t->seq_notes[i]);
+ if (!live_has(t, t->seq_notes[i])) /* (2.8.3: a note a player holds goes on) */
+ trk_note_off(t, t->seq_notes[i]);
seq_out_off(t, t->seq_notes[i]);
}
if (is_drum(t))
@@ -2380,11 +2678,15 @@ static void seq_step(track_t *t, const step_t *s, uint32_t slen, uint32_t skip)
if (i < s->n) {
kept |= 1u << i;
} else {
- trk_note_off(t, old[j]);
+ if (!live_has(t, old[j]))
+ trk_note_off(t, old[j]);
seq_out_off(t, old[j]);
}
}
t->slide_glide = 0;
+ for (i = 0; i < s->n; i++) /* (2.8.3) a note going on that a player holds: the key's, it sounds */
+ if ((s->flags & SF_CONT(i)) && !((kept >> i) & 1u) && live_has(t, s->note[i]))
+ skip |= 1u << i;
for (i = 0; i < s->n; i++)
if (!((kept >> i) & 1u) && !((skip >> i) & 1u) && !roll_has(t, s->note[i])) {
trk_note_on(t, s->note[i], step_vel(s, i)); /* (a note going on that was not playing: from here) */
@@ -2394,7 +2696,7 @@ static void seq_step(track_t *t, const step_t *s, uint32_t slen, uint32_t skip)
for (i = 0; i < s->n; i++)
if (!((skip >> i) & 1u))
t->seq_notes[t->seq_n++] = s->note[i];
- t->seq_off = gate;
+ t->seq_off = step_pure_cont(s) ? gate + slen / 2u : gate; /* (2.8.3: notes that only go on end as a TIE's do) */
t->seq_hold = (s->flags & SF_SLIDE) != 0 || next_tie;
return;
}
@@ -2426,7 +2728,8 @@ static void seq_step(track_t *t, const step_t *s, uint32_t slen, uint32_t skip)
for (j = 0; j < s->n && s->note[j] != t->seq_notes[i]; j++)
;
if (j == s->n) {
- trk_note_off(t, t->seq_notes[i]);
+ if (!live_has(t, t->seq_notes[i]))
+ trk_note_off(t, t->seq_notes[i]);
seq_out_off(t, t->seq_notes[i]);
}
}
@@ -3101,6 +3404,8 @@ static void events_block(uint32_t n)
} else {
trk_all_off(t);
}
+ live_held[i][0] = live_held[i][1] = live_held[i][2] = live_held[i][3] = 0; /* (2.8.3: all of it ended) */
+ mi_trk_held[i][0] = mi_trk_held[i][1] = mi_trk_held[i][2] = mi_trk_held[i][3] = 0;
sus_wait[i][0] = sus_wait[i][1] = sus_wait[i][2] = sus_wait[i][3] = 0; /* (what the pedal held: gone too, */
sus_on[i] = 0; /* and the pedal: never stuck) */
if (!((arp_keep_req >> i) & 1u)) { /* (2.7: a sound loaded under a running arp:
@@ -3230,13 +3535,28 @@ static void events_block(uint32_t n)
mi_pen[d1 >> 5] |= 1u << (d1 & 31u);
}
step_in_push(d1 | 0x80u | trk_index(t) << 8);
+ mi_trk_held[trk_index(t) % NTRK][d1 >> 5] |= 1u << (d1 & 31u);
input_on(t, d1, d2);
} else {
mi_pen[d1 >> 5] &= ~(1u << (d1 & 31u));
step_in_push(d1 | trk_index(t) << 8);
+ mi_trk_held[trk_index(t) % NTRK][d1 >> 5] &= ~(1u << (d1 & 31u));
input_off(t, d1);
}
}
+ if (midi_in_lost) { /* (2.8.3) a note message was lost (the ring full), once what came is read: the notes MIDI
+ * holds end, none stays stuck for a lost note-off */
+ uint32_t ti, w, b;
+ midi_in_lost = 0;
+ for (ti = 0; ti < NTRK; ti++)
+ for (w = 0; w < 4u; w++)
+ for (b = 0; b < 32u; b++)
+ if ((mi_trk_held[ti][w] >> b) & 1u) {
+ mi_trk_held[ti][w] &= ~(1u << b);
+ input_off(&trk[ti], w * 32u + b);
+ }
+ mi_pen[0] = mi_pen[1] = mi_pen[2] = mi_pen[3] = 0;
+ }
for (i = 0; i < NTRK; i++)
seq_tick(&trk[i], adv);
click_tick();
diff --git a/firmware/src/ui.c b/firmware/src/ui.c
index 6a8134c..aaaeb61 100644
--- a/firmware/src/ui.c
+++ b/firmware/src/ui.c
@@ -3,7 +3,7 @@
/* Felucca user interface. Four columns map to KNOB 1..4. Rendering is lazy:
* every element remembers what it last drew and is redrawn only on change. */
#ifndef FELUCCA_VERSION
-#define FELUCCA_VERSION "SLOOP 2.8.1" /* the beat machine firmware for the FM-1 (based on Felucca) */
+#define FELUCCA_VERSION "SLOOP 2.8.3" /* the beat machine firmware for the FM-1 (based on Felucca) */
#endif
static void project_save(uint32_t slot);
static void arrangement_save(void);
@@ -213,6 +213,30 @@ UI_SMALL static uint32_t note_set_len(track_t *t, uint32_t i, uint32_t want)
}
return n;
}
+/* ---- (2.8.3) LEN under later notes ----
+ * POLY: a note's LEN runs on under the notes after it: it joins their steps as a note going on (SF_CONT, as a
+ * recording over held notes writes it, seq.c rec_hold), 4 notes a step at most; after them, a NOTE of its notes only,
+ * all going on, carries it (the others end there). A long bass under a melody, programmed. MONO / LEGATO parts play one
+ * note at a time: it stops there and says so. The step format is 2.7's: a project of 2.8.3 opens in 2.7 and later.
+ * The work: seq.c span_len / span_set (a free take uses them too); span_why: why it stopped short */
+UI_SMALL static uint32_t note_span(const track_t *t, uint32_t i) /* LEN: the steps step i's notes sound */
+{
+ uint8_t s[4];
+ uint32_t ns;
+ if (!step_on(&t->step[i]) || !(ns = span_notes(&t->step[i], s)))
+ return note_len(t, i);
+ return span_len(t, i, s, ns);
+}
+UI_SMALL static uint32_t note_span_set(track_t *t, uint32_t i, uint32_t want)
+{
+ uint8_t s[4];
+ uint32_t ns;
+ span_why = 3;
+ if (!step_on(&t->step[i]) || !(ns = span_notes(&t->step[i], s)))
+ return note_set_len(t, i, want);
+ return span_set(t, i, s, ns, want);
+}
+
/* a synth step's velocity as it plays (seq.c step_vel: ACC 127, else its VEL, 96 when 0, through its first note's level) */
UI_SMALL static uint32_t step_vel_shown(const step_t *st)
{
@@ -327,6 +351,18 @@ static uint8_t drop2(uint32_t v, uint32_t k) /* a 2-bit field per not
{
return (uint8_t)((v & ((1u << (2u * k)) - 1u)) | ((v >> (2u * k + 2u)) << (2u * k)));
}
+UI_SMALL static void note_del_one(step_t *st, uint32_t k) /* note k out of a chord's step */
+{
+ uint32_t j, c;
+ for (j = k; j + 1u < st->n; j++)
+ st->note[j] = st->note[j + 1u];
+ st->lvl = drop2(st->lvl, k);
+ st->rat = drop2(st->rat, k);
+ c = (st->flags & SF_CONT_ALL) / SF_CONT0;
+ c = (c & ((1u << k) - 1u)) | ((c >> (k + 1u)) << k);
+ st->flags = (uint8_t)((st->flags & ~SF_CONT_ALL) | c * SF_CONT0);
+ st->n--;
+}
UI_SMALL static void note_del(track_t *t, uint32_t i, uint32_t k) /* one note of a chord; the last one: the step */
{
step_t *st = &t->step[i];
@@ -334,10 +370,19 @@ UI_SMALL static void note_del(track_t *t, uint32_t i, uint32_t k) /* one note
if (!step_on(st))
return;
if (st->n <= 1u) {
- note_set_len(t, i, 1); /* (its TIEs: RESTs) */
+ note_span_set(t, i, 1); /* (its TIEs: RESTs; 2.8.3: where it went on under others, out) */
step_clear(st);
return;
}
+ { /* (2.8.3) one note of a chord: the chord back to one step, then the others as long again (its going on: gone) */
+ uint32_t w = note_span(t, i);
+ if (w > 1u && w != note_len(t, i)) {
+ note_span_set(t, i, 1);
+ note_del_one(st, k);
+ note_span_set(t, i, w);
+ return;
+ }
+ }
for (j = k; j + 1u < st->n; j++)
st->note[j] = st->note[j + 1u];
st->lvl = drop2(st->lvl, k);
@@ -356,8 +401,8 @@ UI_SMALL static int step_free(const track_t *t, uint32_t i) /* nothing there:
UI_SMALL static int32_t note_shift(track_t *t, uint32_t i, int32_t dir, int copy)
{
uint32_t len = trk_len(t), n = note_len(t, i), j, to;
- if (!step_on(&t->step[i]))
- return -1;
+ if (!step_on(&t->step[i]) || note_span(t, i) != n)
+ return -1; /* (2.8.3: one going on under later notes: LEN 1 first) */
to = copy ? i + n : dir > 0 ? i + 1u : i - 1u;
if ((!copy && dir < 0 && i == 0u) || to + n > len)
return -1;
diff --git a/firmware/src/ui_draw.c b/firmware/src/ui_draw.c
index 8863a9a..e2f712b 100644
--- a/firmware/src/ui_draw.c
+++ b/firmware/src/ui_draw.c
@@ -995,7 +995,7 @@ UI_SMALL static void draw_columns(void)
}
draw_column(1, "PITCH", val, u, on ? VAL(1u) : C_DIM, -1, ICON_AUTO);
if (on)
- fmt_int(ln, (int32_t)note_len(TSEL, ui.cursor));
+ fmt_int(ln, (int32_t)note_span(TSEL, ui.cursor));
else
str_cpy(ln, "--", 8);
draw_column(2, "LEN", ln, on ? "STEP" : "", on ? VAL(2u) : C_DIM, -1, ICON_AUTO);
diff --git a/firmware/src/ui_input.c b/firmware/src/ui_input.c
index 6ebb5c0..3515cc2 100644
--- a/firmware/src/ui_input.c
+++ b/firmware/src/ui_input.c
@@ -439,13 +439,14 @@ UI_SMALL static void step_edit(uint32_t slot, int32_t steps)
break;
case 2: /* LEN: the note and the TIEs after it (2.6: ui.c note_set_len) */
if (step_on(st)) {
- uint32_t was = note_len(t, ui.cursor), n;
+ uint32_t was = note_span(t, ui.cursor), n; /* (2.8.3: under later notes too, POLY) */
note_mark();
fm1_irq_off();
- n = note_set_len(t, ui.cursor, (uint32_t)clamp((int32_t)was + steps, 1, NSTEP));
+ n = note_span_set(t, ui.cursor, (uint32_t)clamp((int32_t)was + steps, 1, NSTEP));
fm1_irq_on();
if (steps > 0 && n == was)
- ui_message(ui.cursor + n < (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP) ? "NOTE AHEAD" : "END OF PATTERN");
+ ui_message(ui.cursor + n >= (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP) ? "END OF PATTERN"
+ : span_why == 2u ? "MONO: SET VOICE POLY" : span_why == 1u ? "STEP FULL: 4 NOTES" : "NOTE AHEAD");
}
break;
default: /* FORCE: GHOST SOFT NORM HARD, ACC (the step's accent) */
@@ -625,6 +626,14 @@ static uint8_t mi_ok; /* the last frame reac
UI_SMALL static uint32_t midi_held(void) { return mi_held[0] | mi_held[1] | mi_held[2] | mi_held[3]; }
UI_SMALL static void midi_entry(void) /* (top of ui_input: every frame) */
{
+ { /* (2.8.3) recording on a MONO / LEGATO sound, a key over a held one: it replaces it. Said once a session */
+ static uint8_t mono_said;
+ if (mono_hint && !mono_said) {
+ mono_said = 1;
+ ui_message("MONO: SET VOICE POLY");
+ }
+ mono_hint = 0;
+ }
track_t *t = TSEL;
int on_page = mi_ok && song.seq_mode && cur_page()->scope == SC_STEP && !is_drum(t) && !song.rec && !rec_wait && !ft_on;
int rec_arm = song.rec || rec_wait || ft_on; /* (2.6) recording, armed or a free take: on which track */
diff --git a/firmware/src/ui_layers.c b/firmware/src/ui_layers.c
index 7117b20..d98dd90 100644
--- a/firmware/src/ui_layers.c
+++ b/firmware/src/ui_layers.c
@@ -30,7 +30,8 @@ static uint32_t sec_armed_ms;
static uint8_t chain_tap[CHAIN_MAX], chain_taps; /* the section keys tapped in this SAVE hold (the first
* is asked for at once; two or more: a chain on release) */
#define TAP_MS 450u /* a press shorter than this, untouched: a tap */
-#define SHOW_MS 140u /* the layer shows after this (a tap does not flash it) */
+#define SHOW_MS 350u /* the layer shows after this (a tap does not flash it; 2.8.3: was 0.14 s,
+ * a quick tap flashed it; a key or knob used shows it at once) */
/* the ISR's view of the panel: the layers' buttons, OCT- / OCT+, REC / PLAY of a free take */
UI_SMALL static void layers_init(void)
diff --git a/firmware/src/usb.c b/firmware/src/usb.c
index 6133eab..d9a0db8 100644
--- a/firmware/src/usb.c
+++ b/firmware/src/usb.c
@@ -159,6 +159,8 @@ static volatile uint32_t so_w, so_r;
#define MQ 64u
static uint32_t midi_in_q[MQ], midi_out_q[MQ];
static volatile uint32_t mi_w, mi_r, mo_w, mo_r;
+static volatile uint8_t midi_in_lost; /* (2.8.3) a note message did not fit: seq.c ends the MIDI notes held
+ * (a lost note-off must not leave a note stuck; after Melodee 1.5) */
static void midi_out_event(uint32_t pkt) /* from the audio ISR */
{
if (usb.config && mo_w - mo_r < MQ) {
@@ -827,6 +829,8 @@ static void midi_in_event(uint32_t pkt)
midi_in_q[mi_w % MQ] = pkt;
RING_PUBLISH();
mi_w++;
+ } else if (cin == 8u || cin == 9u) {
+ midi_in_lost = 1;
}
return;
}
diff --git a/firmware/src/voice.c b/firmware/src/voice.c
index 3c67dc3..b76daf2 100644
--- a/firmware/src/voice.c
+++ b/firmware/src/voice.c
@@ -200,8 +200,12 @@ static voice_t *voice_alloc(track_t *t, uint32_t note)
uint32_t i, np = trk_nvoice(t), best = np, low = np, nfree = 0;
int32_t bd = 0x7FFFFFFF;
for (i = 0; i < np; i++) {
- if (t->v[i].active && t->v[i].note == note)
+ if (t->v[i].active && t->v[i].note == note) {
+ if (t->v[i].stage == 4u && voices_busy() >= NVOICE)
+ voice_room(t, 0); /* (2.8.3) a voice fading out (given up) sounds again: within the
+ * budget of NVOICE, as a new one (after Melodee's voice_reuse) */
return &t->v[i];
+ }
nfree += !t->v[i].active;
}
if (nfree && voices_busy() >= NVOICE) {
@@ -276,12 +280,35 @@ static void glide_set(track_t *t, voice_t *v, int glide)
}
}
+/* (2.8.3) a sample (SAMPLE, SLICE) played again on a voice still sounding: it starts over at its first frame, so
+ * its attack must start from silence too. Up to 2.8.2 the envelope went on from the level it had: the sample jumped
+ * from where it was to its start at that level (a click), and ATK did nothing. That was every note in MONO /
+ * LEGATO / UNISON (one voice) and the same note played again in POLY (its voice reused); different notes in POLY
+ * took fresh voices and faded in (a user's chopped breaks, ATK set to soften the chops' starts). Now the voice fades
+ * out over KILL_BLOCKS (~1.5 ms: env_tick stage 4), then the note starts on it from silence with its ATK
+ * (track_render: VP_ON). A note-off within the fade is kept for it (VP_OFF: released as it starts) */
+#define VP_ON 1u
+#define VP_OFF 2u
+#define VP_GLIDE 4u
static void voice_start(track_t *t, voice_t *v, uint32_t note, uint32_t vel, int glide)
{
const engine_t *e = ENGINES[t->engine];
int sounding = v->active && v->stage != 0;
uint32_t ph0 = v->ph[0], ph1 = v->ph[1], ph2 = v->ph[2];
int32_t s0 = v->s[0], s1 = v->s[1], s4 = v->s[4], s5 = v->s[5], s6 = v->s[6], s7 = v->s[7];
+ if (sounding && eng_sampled(e)) { /* (2.8.3) fade it out first, then this note from silence */
+ v->note = (uint8_t)note; /* (the same note again finds it: voice_alloc) */
+ v->pend_note = (uint8_t)note;
+ v->pend_vel = (uint8_t)vel;
+ v->pend = (uint8_t)(VP_ON | (glide ? VP_GLIDE : 0u));
+ v->gate = 0;
+ if (v->stage != 4u)
+ v->kill = KILL_BLOCKS;
+ v->stage = 4;
+ v->age = ++vage;
+ return;
+ }
+ v->pend = 0;
v->note = (uint8_t)note;
v->vel = (uint8_t)vel;
v->gate = 1;
@@ -491,12 +518,15 @@ static void trk_note_off(track_t *t, uint32_t note)
}
}
}
- for (i = 0; i < NVOICE; i++) /* POLY voices (also ones left from another mode: */
+ for (i = 0; i < NVOICE; i++) { /* POLY voices (also ones left from another mode: */
if (t->v[i].note == note && t->v[i].gate && /* VOICE changed while they were held) */
(mode == V_POLY || i >= (mode == V_UNISON ? trk_nvoice(t) : 1u) || t->mono_note != note)) {
t->v[i].gate = 0;
t->v[i].stage = 3;
}
+ if ((t->v[i].pend & VP_ON) && t->v[i].pend_note == note && t->mono_note != note)
+ t->v[i].pend |= VP_OFF; /* (2.8.3) waiting for its fade: it starts, then releases */
+ }
}
static void trk_all_off(track_t *t)
@@ -506,6 +536,7 @@ static void trk_all_off(track_t *t)
for (i = 0; i < NVOICE; i++) {
t->v[i].gate = 0;
t->v[i].stage = t->v[i].active ? 3 : 0;
+ t->v[i].pend = 0; /* (2.8.3: a note waiting for its voice's fade: gone too) */
}
t->nmono = 0;
t->mono_note = 0;
@@ -738,6 +769,17 @@ static uint32_t track_render(track_t *t, int32_t *out, uint32_t n)
voice_t *v = &t->v[i];
vmod_t m;
int32_t env, pitch;
+ if ((v->pend & VP_ON) && !v->active && !fade) { /* (2.8.3) faded out: the sample's note, from silence */
+ uint32_t pf = v->pend;
+ v->pend = 0;
+ if (voice_room(t, 0)) { /* (it was not counted while fading: within the budget) */
+ voice_start(t, v, v->pend_note, v->pend_vel, (pf & VP_GLIDE) != 0);
+ if (pf & VP_OFF) { /* let go within the fade (~1.5 ms): released as it starts */
+ v->gate = 0;
+ v->stage = 3;
+ }
+ }
+ }
if (!v->active)
continue;
{
diff --git a/tests/chop_attack_test.c b/tests/chop_attack_test.c
new file mode 100644
index 0000000..ca4f3a7
--- /dev/null
+++ b/tests/chop_attack_test.c
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-3.0-only */
+/* SLOOP 2.8.3: a sample (SAMPLE, SLICE) played again on a voice still sounding starts over from silence, with its ATK
+ * (voice.c voice_start, VP_ON). A user's chopped breaks with ATK set to soften the chops' starts: the attack worked
+ * only on different notes in POLY; the same note again in POLY, and every note in MONO / LEGATO / UNISON, started at
+ * the level the voice had (a click, ATK ignored). Checks, per voice mode: the second chop's level over its first
+ * blocks (it starts low and rises with ATK), and the largest step between two output samples around its start
+ * against the largest within the chop (no click). LEGATO with the first chop still held glides on by design.
+ * Exit status: the number of failed checks. */
+#define main hostsim_main
+#include "hostsim.c"
+#undef main
+static int fails;
+static void check(int ok, const char *what) { printf("chop: %-74s %s\n", what, ok ? "ok" : "FAIL"); fails += !ok; }
+static int32_t outb[CTL * 2];
+static int32_t jump_max, last;
+static void block(void)
+{
+ uint32_t i;
+ mix_block(outb, CTL);
+ for (i = 0; i < CTL; i++) {
+ int32_t d = outb[2 * i] - last;
+ d = d < 0 ? -d : d;
+ if (d > jump_max) jump_max = d;
+ last = outb[2 * i];
+ }
+}
+static voice_t *voice_of(track_t *t, uint32_t n)
+{
+ uint32_t i;
+ for (i = 0; i < NVOICE; i++)
+ if ((t->v[i].active || t->v[i].pend) && t->v[i].note == n)
+ return &t->v[i];
+ return 0;
+}
+static void run(int mode, uint32_t n1, uint32_t n2, const char *what)
+{
+ track_t *t = &trk[1];
+ uint32_t k;
+ double lv[8];
+ int32_t steady, start;
+ char b[200];
+ host_tracks_init();
+ host_preset(t, 4, 0); /* SAMPLE */
+ for (k = 0; k < NVOICE; k++) memset(&t->v[k], 0, sizeof t->v[k]);
+ t->nmono = 0; t->mono_note = 0;
+ t->p[P_VOICE] = (int16_t)mode;
+ t->p[P_ATK] = 60; t->p[P_SUS] = 127; t->p[P_REL] = 90;
+ for (k = 0; k < 8; k++) block();
+ trk_note_on(t, n1, 100);
+ for (k = 0; k < 40; k++) block();
+ jump_max = 0;
+ for (k = 0; k < 80; k++) block(); /* the chop as it plays: its own largest step */
+ steady = jump_max;
+ trk_note_off(t, n1);
+ for (k = 0; k < 3; k++) block(); /* its release still sounding */
+ jump_max = 0;
+ trk_note_on(t, n2, 100);
+ for (k = 0; k < 8; k++) {
+ voice_t *v;
+ block();
+ v = voice_of(t, n2);
+ lv[k] = v && v->active && v->stage != 4u ? v->env * 100.0 / (1 << 24) : -1.0;
+ }
+ start = jump_max;
+ snprintf(b, sizeof b, "%s: the 2nd chop starts from silence with its ATK (%.1f %% .. %.1f %%)", what, lv[2], lv[7]);
+ check(lv[2] >= 0 && lv[2] < 5.0 && lv[7] > lv[2], b);
+ snprintf(b, sizeof b, "%s: no click at its start (largest step %d, in the chop %d)", what, start, steady);
+ check(start <= steady + steady / 4, b);
+}
+int main(void)
+{
+ run(V_POLY, 60, 60, "POLY, the same chop again");
+ run(V_POLY, 60, 62, "POLY, another chop");
+ run(V_MONO, 60, 62, "MONO, another chop");
+ run(V_LEGATO, 60, 62, "LEGATO, another chop");
+ run(V_UNISON, 60, 62, "UNISON, another chop");
+ printf("chop: %d failed\n", fails);
+ return fails;
+}
diff --git a/tests/drum_steal_test.c b/tests/drum_steal_test.c
new file mode 100644
index 0000000..0788e50
--- /dev/null
+++ b/tests/drum_steal_test.c
@@ -0,0 +1,98 @@
+/* SLOOP 2.8.3: drum voices on a busy beat (kick on the beat, 16th hats, open hats, snare + clap, crash, ride, a tom
+ * fill), every kit: no kick is cut short by another sound taking its voice (NDRUM voices; up to 2.8.2 the oldest went,
+ * kick or not: 11 to 13 kicks of 16 cut on the 808, GM and AMBIENT kits; a tester's report). A kick re-hit while it
+ * still sounds may take its own voice (as on a drum machine). Exit status: the kits that fail */
+#define FELUCCA_ARRANGER 1
+#define main hostsim_main
+#include "hostsim.c"
+#undef main
+#define PROJ_HOST 1
+static uint32_t trk_def_engine(uint32_t i) { return i < NPART ? i : 0; }
+#include "../firmware/src/project.c"
+static struct { uint8_t force; } ui;
+static uint8_t sync_reload;
+#include "../firmware/src/arranger_scene.c"
+static void block(void) { int32_t out[CTL * 2]; mix_block(out, CTL); }
+typedef struct { uint32_t age, start, alive; } kk_t;
+static uint32_t early, hits, lost, lostk;
+static uint32_t slot_age[16], slot_t0[16];
+static uint32_t run_kit(uint32_t kit, int dense, uint32_t *kicks, uint32_t *natural_ms)
+{
+ uint32_t step, b, i, cut = 0, nk = 0, SB = FS / 8u / CTL, now = 0;
+ kk_t k[64];
+ memset(&drums, 0, sizeof drums);
+ drums.set = -2;
+ TDRUM->p[P_E0] = (int16_t)kit;
+ TDRUM->p[P_MUTE] = 0;
+ for (i = 0; i < 20; i++) block();
+ /* the kick alone: how long it sounds */
+ drum_on(36, 110);
+ for (b = 0; b < FS * 2u / CTL; b++) { int a = 0; for (i = 0; i < NDRUM; i++) a |= drums.v[i].active && drums.v[i].note == 36; if (!a) break; block(); }
+ *natural_ms = b * CTL * 1000u / FS;
+ for (i = 0; i < 40; i++) block();
+ for (step = 0; step < 64; step++) {
+ uint32_t s = step % 16;
+ uint8_t notes[10]; uint32_t n = 0;
+ if (s % 4 == 0) notes[n++] = 36; /* kick */
+ if (dense) {
+ if (s == 0) notes[n++] = 49; /* crash, each bar */
+ if (s == 4 || s == 12) { notes[n++] = 38; notes[n++] = 39; } /* snare + clap */
+ notes[n++] = (s % 4 == 2) ? 46 : 42; /* hats: open on the off-beat */
+ if (s % 2 == 0) notes[n++] = 51; /* ride, 8ths */
+ if (step >= 56 && s % 2 == 1) notes[n++] = s < 12 ? 48 : 43; /* a tom fill */
+ } else {
+ notes[n++] = 42;
+ if (s == 4 || s == 12) notes[n++] = 38;
+ }
+ uint32_t ages[10];
+ for (i = 0; i < n; i++) {
+ drum_on(notes[i], 100);
+ ages[i] = drums.age;
+ if (notes[i] == 36) {
+ uint32_t v;
+ for (v = 0; v < NDRUM; v++) if (drums.v[v].active && drums.v[v].note == 36 && drums.v[v].age == drums.age) break;
+ k[nk].age = drums.age; k[nk].start = now; k[nk].alive = 1; nk++;
+ }
+ }
+ for (i = 0; i < n && dense; i++) { /* a hit of this step already gone: never heard */
+ uint32_t v, f = 0;
+ for (v = 0; v < NDRUM; v++) f |= drums.v[v].age == ages[i] && drums.v[v].active;
+ if (!f && notes[i] != 46) { lost++; if (notes[i] == 36) lostk++; }
+ }
+ for (b = 0; b < SB; b++) {
+ block(); now++;
+ { uint32_t v; for (v = 0; v < NDRUM; v++) { if (drums.v[v].age != slot_age[v]) { if (slot_age[v] && dense && (now - slot_t0[v]) * CTL * 1000u / FS < 120u && drums.v[v].note != 0) early++; slot_age[v] = drums.v[v].age; slot_t0[v] = now; if (dense) hits++; } } }
+ for (i = 0; i < nk; i++) {
+ uint32_t v, found = 0, ended = 1;
+ if (!k[i].alive) continue;
+ for (v = 0; v < NDRUM; v++) if (drums.v[v].age == k[i].age) { found = 1; ended = !drums.v[v].active; }
+ if (!found) { /* its voice went to another hit */
+ uint32_t self = 0;
+ for (v = 0; v < NDRUM; v++) if (drums.v[v].active && drums.v[v].note == 36 && drums.v[v].age > k[i].age) self = 1;
+ if (self) { k[i].alive = 0; continue; }
+ k[i].alive = 0;
+ if ((now - k[i].start) * CTL * 1000u / FS < *natural_ms * 9u / 10u) cut++;
+ k[i].alive = 0;
+ } else if (ended) k[i].alive = 0;
+ }
+ }
+ }
+ *kicks = nk;
+ return cut;
+}
+int main(void)
+{
+ uint32_t kit, kicks, nat, c1, c2, fails = 0;
+ host_tracks_init();
+ printf("NDRUM %u\n", NDRUM);
+ for (kit = 0; kit < DRUM_USR; kit++) {
+ c1 = run_kit(kit, 0, &kicks, &nat);
+ c2 = run_kit(kit, 1, &kicks, &nat);
+ lost = lostk = early = hits = 0;
+ printf("drums: kit %2u (%-8s) kick %4u ms; kicks cut by another sound: simple beat %u/%u, busy beat %u/%u %s\n", kit,
+ kit >= DRUM_SAMPLED ? DS_KITS[kit - DRUM_SAMPLED].name : "GM", nat, c1, kicks, c2, kicks, c1 || c2 ? "FAIL" : "ok");
+ fails += c1 || c2;
+ }
+ printf("drums: %u kits failed\n", fails);
+ return (int)fails;
+}
diff --git a/tests/golden.txt b/tests/golden.txt
index 9ad58d9..c527a57 100644
--- a/tests/golden.txt
+++ b/tests/golden.txt
@@ -60,16 +60,16 @@ preset/LOFI/04_CHIP_CHORD e55424ac13f3ece1
preset/LOFI/05_1BIT_BEEP e1742bf68ea67ad1
preset/LOFI/06_WAVE_LEAD 23a2f1e11d67dfad
preset/LOFI/07_CHIP_NOISE ca1058917a10b3b0
-preset/SAMPLE/00_GRAND_PNO d923a2cd58dd6c07
+preset/SAMPLE/00_GRAND_PNO 9c5d53a1ab12d0fc
preset/SAMPLE/01_UP_BASS ab929b7cd01d615c
-preset/SAMPLE/02_VIBES b990857c2a729642
+preset/SAMPLE/02_VIBES 6e14271dc9c6ebf0
preset/SAMPLE/03_HORN_STAB f2b3917cde0d0110
preset/SAMPLE/04_STRING_STB 131105f7f10785fe
-preset/SAMPLE/05_LOFI_FLUTE 79c66528bf0b1c74
+preset/SAMPLE/05_LOFI_FLUTE 0db1d1b6c42b8dff
preset/SAMPLE/06_SCRATCH e64ad5d2d779891c
preset/SAMPLE/07_GM_KIT 13999abe5e115815
-preset/SAMPLE/08_DUSTY_PNO 3918c5839bb7a848
-preset/SAMPLE/09_LOFI_KEYS 6fa2f6b1e30b1f3d
+preset/SAMPLE/08_DUSTY_PNO 09c7cc02bc9e2468
+preset/SAMPLE/09_LOFI_KEYS 9c85a710ae9edfa6
preset/SAMPLE/10_DEEP_BASS d68154cf4ef76038
preset/VOICE/00_CHOIR_AAH d71bac99365842d0
preset/VOICE/01_SOUL_OOH 54efb0da8718978f
@@ -153,7 +153,7 @@ preset/NOISE/07_RISER fcea3ada4f424206
preset/NOISE/08_NZ_SNARE b0fe837467457eee
preset/NOISE/09_BITCRUSH 57785f07c4efb016
preset/NOISE/10_RADIO 7bdab4709d2209ac
-drums/gm_kit 97750328f0896d25
+drums/gm_kit b56f39d6452ad27c
mode/ANALOG/POLY 8469751e1f620a8c
mode/ANALOG/MONO 9583d8d67d814abc
mode/ANALOG/LEGATO 688683752bbf85f8
diff --git a/tests/hold_rec_test.c b/tests/hold_rec_test.c
new file mode 100644
index 0000000..452d8ff
--- /dev/null
+++ b/tests/hold_rec_test.c
@@ -0,0 +1,322 @@
+/* SLOOP 2.8.3: a note held while others are played over it (reddit "SLOOP 2.8.1 chopping notes").
+ * live POLY: hold C1, play C2 D2 E2 over it while the pattern plays and records: C1 is never
+ * restarted nor released while its key is down
+ * playback the take plays back: C1 sounds from its start to its end in one go, the scale over it
+ * len SEQ > NOTES, LEN: a note's length runs on under the notes after it (POLY)
+ * Exit status: the number of failed checks. */
+#define FELUCCA_ARRANGER 1
+#define main hostsim_main
+#include "hostsim.c"
+#undef main
+#define PROJ_HOST 1
+static uint32_t trk_def_engine(uint32_t i) { return i < NPART ? i : 0; }
+#include "../firmware/src/project.c"
+static struct { uint8_t force; } ui;
+static uint8_t sync_reload;
+#include "../firmware/src/arranger_scene.c"
+
+static int fails;
+static void check(int ok, const char *what) { printf("hold: %-74s %s\n", what, ok ? "ok" : "FAIL"); fails += !ok; }
+static uint64_t blk;
+static void block(void) { int32_t out[CTL * 2]; mix_block(out, CTL); blk++; }
+/* C1's voice on track t: its age (a restart makes a new one), gated or not; 0 = no gated voice */
+static uint32_t voice_of(track_t *t, uint32_t note, int *gated)
+{
+ uint32_t i;
+ *gated = 0;
+ for (i = 0; i < NVOICE; i++)
+ if (t->v[i].active && t->v[i].note == note && t->v[i].gate) { *gated = 1; return t->v[i].age; }
+ return 0;
+}
+static uint32_t SB; /* blocks a step (1/16 at 120 BPM) */
+static void steps(uint32_t n) { uint32_t i; for (i = 0; i < n * SB; i++) block(); }
+static void reset(uint32_t ti, int voice)
+{
+ uint32_t i;
+ host_tracks_init();
+ for (i = 0; i < NTRK; i++) { steps_clear(&trk[i]); trk_all_off(&trk[i]); }
+ memset(&drums, 0, sizeof drums);
+ drums.set = -2;
+ song.g[G_BPM] = 120;
+ host_preset(&trk[ti], ti == 0 ? 0 : 1, 0);
+ if (voice >= 0) trk[ti].p[P_VOICE] = (int16_t)voice;
+ trk[ti].p[P_SLEN] = 16;
+ song.sel = (uint8_t)ti;
+ blk = 0;
+}
+
+/* live: transport on, record armed; C1 down at step 0, C2 D2 E2 (two steps each) from step 2, C1 up at step 10.
+ * Returns the restarts / releases of C1 seen while its key was down */
+static void live_take(uint32_t ti, int voice, const char *what, int pass2)
+{
+ track_t *t = &trk[ti];
+ const uint32_t C1 = 36, SC[3] = {48, 50, 52};
+ uint32_t age0, restarts = 0, cuts = 0, k, b, i;
+ int g;
+ reset(ti, voice);
+ SB = div_samples(2) / CTL;
+ song.rec = (uint8_t)(1u << ti);
+ rec_wait = 0;
+ transport_req = 1;
+ block();
+ /* (a pass already recorded under it, for the overdub case) */
+ input_on(t, C1, 100);
+ for (i = 0; i < 4; i++) block();
+ age0 = voice_of(t, C1, &g);
+ for (k = 0; k < 12u * SB; k++) {
+ uint32_t st = k / SB, at = k % SB;
+ if (at == 0 && st >= 2 && st < 8 && st % 2 == 0) input_on(t, SC[(st - 2) / 2], 100);
+ if (at == SB - 2 && st >= 2 && st < 8 && st % 2 == 1) input_off(t, SC[(st - 3) / 2]);
+ if (at == 0 && st == 10) input_off(t, C1);
+ block();
+ if (st < 10) {
+ uint32_t a = voice_of(t, C1, &g);
+ if (!g) { if (!cuts && getenv("DBG")) printf(" cut at step %u +%u blocks\n", st, at); cuts++; }
+ else if (a != age0) { if (getenv("DBG")) printf(" restart at step %u +%u\n", st, at); restarts++; age0 = a; }
+ }
+ }
+ {
+ char b2[160];
+ snprintf(b2, sizeof b2, "%s, live: C1 held under the scale (restarts %u, cut %u blocks)", what, restarts, cuts);
+ check(!restarts && !cuts, b2);
+ voice_of(t, C1, &g);
+ snprintf(b2, sizeof b2, "%s, live: C1 ends when its key is let go", what);
+ check(!g, b2);
+ }
+ if (!pass2) return;
+ /* playback: the rest of the bar, then the take plays on its own (record off) */
+ song.rec = 0;
+ while (t->seq_idx != 0 || (clk_pos != 0 && 0)) block();
+ {
+ uint32_t first = 0, gated = 0, restarts2 = 0, a0 = 0;
+ for (k = 0; k < 10u * SB; k++) {
+ uint32_t a;
+ block();
+ a = voice_of(t, C1, &g);
+ if (k < SB) continue;
+ if (g) { gated++; if (!a0) a0 = a; else if (a != a0) { restarts2++; a0 = a; } }
+ }
+ {
+ char b2[160];
+ snprintf(b2, sizeof b2, "%s, playback: C1 sounds under the scale in one go (gated %u/%u, restarts %u)", what, gated, 9u * SB, restarts2);
+ check(gated >= 9u * SB - 2u && !restarts2, b2);
+ }
+ }
+ transport_req = 2;
+ block();
+}
+
+static void dump(track_t *t)
+{
+ uint32_t i, k;
+ for (i = 0; i < 12; i++) {
+ step_t *x = &t->step[i];
+ printf(" %2u %s", i, x->time == ST_TIE ? "TIE " : x->time == ST_REST ? "REST" : "NOTE");
+ for (k = 0; k < x->n; k++) printf(" %u%s", x->note[k], (x->flags & SF_CONT(k)) ? "c" : "");
+ printf("\n");
+ }
+}
+/* overdub: a scale recorded first (pass 1), then C1 held over it from step 0 to step 10 (pass 2): it plays back
+ * in one go under the scale (2.8.1 ended the hold at the first step with notes) */
+static void overdub(uint32_t ti, int voice, const char *what, uint32_t rel)
+{
+ track_t *t = &trk[ti];
+ const uint32_t C1 = 36, SC[3] = {48, 50, 52};
+ uint32_t k, gated = 0, restarts = 0, a0 = 0, a;
+ int g;
+ char b2[160];
+ reset(ti, voice);
+ SB = div_samples(2) / CTL;
+ song.rec = (uint8_t)(1u << ti);
+ rec_wait = 0;
+ transport_req = 1;
+ block();
+ for (k = 0; k < 16u * SB; k++) { /* pass 1: the scale, steps 2..7 */
+ uint32_t st = k / SB, at = k % SB;
+ if (at == 0 && st >= 2 && st < 8 && st % 2 == 0) input_on(t, SC[(st - 2) / 2], 100);
+ if (at == SB - 2 && st >= 2 && st < 8 && st % 2 == 1) input_off(t, SC[(st - 3) / 2]);
+ block();
+ }
+ for (k = 0; k < 16u * SB; k++) { /* pass 2: C1 held from step 0 to step 10 */
+ uint32_t st = k / SB, at = k % SB;
+ if (at == 0 && st == 0 && !getenv("NOC1")) input_on(t, C1, 100);
+ if (at == 0 && st == rel && !getenv("NOC1")) input_off(t, C1);
+ block();
+ }
+ song.rec = 0;
+ if (getenv("DUMP")) dump(t);
+ uint32_t late = 0, scale_on = 0, scale_late = 0;
+ for (k = 0; k < 16u * SB; k++) { /* pass 3: plays back */
+ block();
+ { int g2; uint32_t q; for (q = 0; q < 3; q++) { voice_of(t, SC[q], &g2); if (g2) { if (k / SB >= 2 && k / SB < 8) scale_on++; if (k / SB >= 9) scale_late++; } } }
+ a = voice_of(t, C1, &g);
+ if (g && k / SB >= rel + 1u) late++;
+ if (k / SB >= 1 && k / SB < rel - 1u) { if (g) { gated++; if (!a0) a0 = a; else if (a != a0) { restarts++; a0 = a; } } }
+ }
+ snprintf(b2, sizeof b2, "%s, overdub to step %u: C1 held over a recorded scale plays back whole (%u/%u, restarts %u)", what, rel, gated, (rel - 2u) * SB, restarts);
+ check(gated >= (rel - 2u) * SB - 2u && !restarts, b2);
+ snprintf(b2, sizeof b2, "%s, overdub: C1 ends where it was let go (%u late blocks)", what, late);
+ check(!late, b2);
+ snprintf(b2, sizeof b2, "%s, overdub: the scale plays as recorded (%u blocks), and ends (%u late)", what, scale_on, scale_late);
+ check(scale_on >= 5u * SB && !scale_late, b2);
+ transport_req = 2;
+ block();
+}
+
+/* MIDI in overflow: a burst of 80 note-ons then their note-offs, faster than the audio reads them: the ring drops some
+ * note-offs; nothing stays held (2.8.1: the notes whose note-off was lost hung) */
+static void midi_burst(void)
+{
+ track_t *t = &trk[1];
+ uint32_t i, k, hung = 0;
+ reset(1, -1);
+ song.g[G_ROUTE] = 0;
+ for (k = 0; k < 4; k++) block();
+ for (i = 0; i < 40u; i++) /* (USB packets: cable 0, CIN 9 / 8, channel 1 = track 1? no: CH of track 2) */
+ midi_in_event(0x09u | (0x90u | (uint32_t)(song.g[G_CH2] - 1)) << 8 | (36u + i) << 16 | 100u << 24);
+ for (i = 0; i < 40u; i++)
+ midi_in_event(0x08u | (0x80u | (uint32_t)(song.g[G_CH2] - 1)) << 8 | (36u + i) << 16);
+ for (k = 0; k < 200; k++) block();
+ for (i = 0; i < NVOICE; i++)
+ hung += t->v[i].active && t->v[i].gate;
+ check(!hung, "MIDI in: a burst over the ring's 64: no note left hanging");
+}
+
+static void mono_note(void)
+{
+ track_t *t = &trk[0];
+ reset(0, -1); /* 808 BOOM: LEGATO */
+ song.rec = 1u;
+ rec_wait = 0;
+ transport_req = 1;
+ block();
+ mono_hint = 0;
+ input_on(t, 36, 100);
+ block();
+ check(!mono_hint, "MONO sound, recording: one key: nothing said");
+ input_on(t, 48, 100);
+ block();
+ check(mono_hint == 1u, "MONO sound, recording: a key over a held one: MONO: SET VOICE POLY");
+ input_off(t, 48); input_off(t, 36);
+ transport_req = 2;
+ block();
+ reset(0, -1); /* (2.8.3) and in a free take */
+ { uint32_t q; for (q = 0; q < NTRK; q++) steps_clear(&trk[q]); }
+ rec_tempo = 0; rec_count = 0; song.rec = 0; rec_wait = 1; song.sel = 0;
+ block();
+ mono_hint = 0;
+ input_on(t, 36, 100);
+ block();
+ input_on(t, 48, 100);
+ block();
+ check(ft_on && mono_hint == 1u, "MONO sound, free take: a key over a held one: MONO: SET VOICE POLY");
+ ft_on = 0;
+ input_off(t, 48); input_off(t, 36);
+ transport_req = 2;
+ block();
+}
+
+/* (2.8.3, Sam on the FM-1) a FREE TAKE (REC in an empty project: no tempo, the loop set by the second REC): C1 held, a
+ * scale played over it, then the take closes. It plays back with C1 whole under the scale (up to 2.8.3 the take's
+ * lengths stopped at the next step with notes: C1 was cut at the first note over it) */
+static void free_take(uint32_t ti, int voice, const char *what, int quant_off)
+{
+ track_t *t = &trk[ti];
+ const uint32_t C1 = 36, SC[3] = {48, 50, 52};
+ uint32_t k, SBk, gated = 0, restarts = 0, a0 = 0, a, late = 0, scale_on = 0, i;
+ int g;
+ char b2[200];
+ reset(ti, voice);
+ for (i = 0; i < NTRK; i++) steps_clear(&trk[i]);
+ song.g[G_BPM] = 120;
+ SB = div_samples(2) / CTL; /* (a 16th at 120 BPM: the take's grid once it closes) */
+ rec_tempo = 0;
+ rec_count = 0;
+ rec_quant_off = (uint8_t)quant_off;
+ song.rec = 0;
+ rec_wait = 1;
+ song.sel = (uint8_t)ti;
+ block();
+ input_on(t, C1, 100); /* the first note: the free take starts */
+ check(ft_on == 1u, "free take: the first note starts it");
+ for (k = 0; k < 16u * SB; k++) { /* one bar at 120: C1 held to step 12, C2 D2 E2 over it */
+ uint32_t st = k / SB, at = k % SB;
+ if (at == 0 && st >= 2 && st < 8 && st % 2 == 0) input_on(t, SC[(st - 2) / 2], 100);
+ if (at == SB - 2 && st >= 2 && st < 8 && st % 2 == 1) input_off(t, SC[(st - 3) / 2]);
+ if (at == 0 && st == 12) input_off(t, C1);
+ block();
+ }
+ ft_close(); /* REC on the downbeat: the loop, 1 bar */
+ if (getenv("DUMP")) dump(t);
+ for (k = 0; k < 16u * SB; k++) { /* it plays back */
+ block();
+ a = voice_of(t, C1, &g);
+ if (k / SB >= 1 && k / SB < 11) { if (g) { gated++; if (!a0) a0 = a; else if (a != a0) { restarts++; a0 = a; } } }
+ if (g && k / SB >= 13) late++;
+ { int g2; uint32_t q; for (q = 0; q < 3; q++) { voice_of(t, SC[q], &g2); if (g2 && k / SB >= 2 && k / SB < 8) scale_on++; } }
+ }
+ snprintf(b2, sizeof b2, "%s, free take%s: C1 held under the scale plays back whole (%u/%u, restarts %u)", what,
+ quant_off ? " (QUANT OFF)" : "", gated, 10u * SB, restarts);
+ check(gated >= 10u * SB - 4u && !restarts, b2);
+ snprintf(b2, sizeof b2, "%s, free take: C1 ends where it was let go, the scale plays (%u late, scale %u)", what, late, scale_on);
+ check(!late && scale_on >= 5u * SB, b2);
+ rec_quant_off = 0;
+ transport_req = 2;
+ block();
+}
+
+/* (2.8.3) REC armed in a project with notes: the first note starts the transport and the recording (rec_wait), C1 held
+ * from it, the scale over it: plays back whole */
+static void armed_take(uint32_t ti, const char *what)
+{
+ track_t *t = &trk[ti];
+ const uint32_t C1 = 36, SC[3] = {48, 50, 52};
+ uint32_t k, gated = 0, restarts = 0, a0 = 0, a, i;
+ int g;
+ char b2[200];
+ reset(ti, -1);
+ SB = div_samples(2) / CTL;
+ trk[2].step[0].note[0] = 72; trk[2].step[0].n = 1; trk[2].step[0].time = ST_NOTE; /* (not empty: no free take) */
+ rec_tempo = 0; rec_count = 0;
+ song.rec = 0;
+ rec_wait = 1;
+ song.sel = (uint8_t)ti;
+ block();
+ input_on(t, C1, 100);
+ check(song.playing && ((song.rec >> ti) & 1u), "armed: the first note starts the transport and the recording");
+ for (k = 0; k < 12u * SB; k++) {
+ uint32_t st = k / SB, at = k % SB;
+ if (at == 0 && st >= 2 && st < 8 && st % 2 == 0) input_on(t, SC[(st - 2) / 2], 100);
+ if (at == SB - 2 && st >= 2 && st < 8 && st % 2 == 1) input_off(t, SC[(st - 3) / 2]);
+ if (at == 0 && st == 10) input_off(t, C1);
+ block();
+ }
+ song.rec = 0;
+ while (t->seq_idx != 0) block();
+ for (k = 0; k < 10u * SB; k++) {
+ block();
+ a = voice_of(t, C1, &g);
+ if (k / SB >= 1 && k / SB < 9) { if (g) { gated++; if (!a0) a0 = a; else if (a != a0) { restarts++; a0 = a; } } }
+ }
+ snprintf(b2, sizeof b2, "%s, armed take: C1 held under the scale plays back whole (%u/%u, restarts %u)", what, gated, 8u * SB, restarts);
+ check(gated >= 8u * SB - 4u && !restarts, b2);
+ (void)i;
+ transport_req = 2;
+ block();
+}
+
+int main(void)
+{
+ live_take(1, -1, "track 2 RHODES (POLY)", 1);
+ live_take(0, V_POLY, "track 1 808 BOOM set to POLY", 1);
+ free_take(1, -1, "track 2 RHODES (POLY)", 0);
+ free_take(1, -1, "track 2 RHODES (POLY)", 1);
+ armed_take(1, "track 2 RHODES (POLY)");
+ midi_burst();
+ mono_note();
+ overdub(1, -1, "track 2 RHODES (POLY)", 10);
+ overdub(1, -1, "track 2 RHODES (POLY)", 5);
+ overdub(1, -1, "track 2 RHODES (POLY)", 7);
+ printf("hold: %d failed\n", fails);
+ return fails;
+}
diff --git a/tests/len_test.c b/tests/len_test.c
new file mode 100644
index 0000000..64fd6eb
--- /dev/null
+++ b/tests/len_test.c
@@ -0,0 +1,214 @@
+/* (from ui_pages_test.c's harness) SPDX-License-Identifier: GPL-3.0-only */
+/* The real UI (ui.c, ui_draw.c, ui_studio.c, ui_layers.c, ui_song.c, ui_menu.c, ui_input.c) on a
+ * framebuffer with panel / flash / storage doubles, the audio (mix_block) running between frames as on
+ * the device. Renders every screen to PPM for review (DIR/page-*.ppm, live-*.ppm, layer-*.ppm) and
+ * drives the panel:
+ * taps a layer button tapped opens its pages; held + a key / knob it does not
+ * FX held + a white key: punch-in; knobs: filter, dust, duck
+ * SEQ held: the steps on the white keys (drums: the sound played last), OCT: pages, a step key
+ * held + KNOB 1..4: sound / note, level, ratchet, nudge (2.4); PRESETS a lock of the parameter
+ * ALGORITHM picks (the sound parameter last touched first); + OCT-: its nudge, locks and fill
+ * condition go; + OCT+: the condition (normal, fill only, no fill)
+ * EDIT held + a key: erase; OCT- / OCT+: undo / redo; KNOB 1 shift, 2 length x2
+ * ARP held + a key: a roll; KNOB 1 the rate
+ * SEL held + a key: the key of the song
+ * GLO held + keys: mute, solo, fill (held) / fill the next bar, tap tempo; knobs: levels
+ * REC press: arm / record at once; held: the clear ring, to the end: cleared (undo brings it back)
+ * SAVE tapped: the song page; held: the SONG layer (sections A..D: play / store, SONG REC; two or more
+ * section taps: a chain, "chain A B" on the sub line)
+ * DRUMS the grid: sound / step / hit / level knobs, GRID <-> KIT
+ * then 20000 frames of random use: every draw stays on the screen. */
+#define FELUCCA_ARRANGER 1
+#define main hostsim_main
+#include "hostsim.c"
+#undef main
+#include
+static uint16_t screen[240*240];
+static void lcd_sync(void) {}
+static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
+{ uint32_t i,j; assert(x+w<=240 && y+h<=240); for(j=0;j> 7); }
+#include "../firmware/src/editor_live.c"
+static void live(uint32_t op, uint32_t x, uint32_t y, uint32_t z)
+{
+ uint8_t a[4] = {(uint8_t)op, (uint8_t)x, (uint8_t)y, (uint8_t)z};
+ lv_n = 0;
+ ed_live(a, 4);
+}
+static void live5(uint32_t op, uint32_t x, uint32_t y, uint32_t z, uint32_t w)
+{
+ uint8_t a[5] = {(uint8_t)op, (uint8_t)x, (uint8_t)y, (uint8_t)z, (uint8_t)w};
+ lv_n = 0;
+ ed_live(a, 5);
+}
+
+/* SLOOP 2.8.3: SEQ > NOTES, LEN under later notes (POLY), the MONO and STEP FULL messages, shrink and delete */
+static int fails;
+static void check(int ok, const char *what) { printf("len: %-74s %s\n", what, ok ? "ok" : "FAIL"); fails += !ok; }
+static void put(track_t *t, uint32_t i, uint32_t note, uint32_t ties)
+{
+ uint32_t k;
+ memset(&t->step[i], 0, sizeof t->step[i]);
+ t->step[i].note[0] = (uint8_t)note; t->step[i].n = 1; t->step[i].time = ST_NOTE;
+ for (k = 1; k <= ties; k++) { memset(&t->step[i + k], 0, sizeof t->step[i]); t->step[i + k].time = ST_TIE; }
+}
+static void dump(track_t *t, uint32_t n)
+{
+ uint32_t i, k;
+ for (i = 0; i < n; i++) {
+ step_t *x = &t->step[i];
+ printf(" %2u %s", i, x->time == ST_TIE ? "TIE " : x->time == ST_REST ? "REST" : "NOTE");
+ for (k = 0; k < x->n; k++) printf(" %u%s", x->note[k], (x->flags & SF_CONT(k)) ? "c" : "");
+ printf("\n");
+ }
+}
+static uint64_t blk;
+static void block(void) { int32_t out[CTL * 2]; mix_block(out, CTL); blk++; }
+static uint32_t gated_blocks(track_t *t, uint32_t note, uint32_t from, uint32_t to, uint32_t *restarts)
+{
+ uint32_t SB = div_samples(2) / CTL, k, i, n = 0, age = 0;
+ *restarts = 0;
+ for (k = 0; k < 16u * SB; k++) {
+ block();
+ if (k / SB < from || k / SB >= to) continue;
+ for (i = 0; i < NVOICE; i++)
+ if (t->v[i].active && t->v[i].gate && t->v[i].note == note) {
+ n++;
+ if (age && t->v[i].age != age) (*restarts)++;
+ age = t->v[i].age;
+ break;
+ }
+ }
+ return n;
+}
+static void melody(track_t *t)
+{
+ uint32_t i;
+ for (i = 0; i < NSTEP; i++) { memset(&t->step[i], 0, sizeof t->step[i]); t->step[i].time = ST_REST; }
+ put(t, 0, 36, 1); /* C1, two steps */
+ put(t, 2, 48, 1); put(t, 4, 50, 1); put(t, 6, 52, 1); /* C2 D2 E2 over it, two steps each */
+}
+int main(void)
+{
+ track_t *t;
+ uint32_t n, r, g, SB;
+ host_tracks_init();
+ t = &trk[1];
+ host_preset(t, 1, 0); /* DIGITAL RHODES: POLY */
+ t->p[P_SLEN] = 16;
+ song.sel = 1;
+ SB = div_samples(2) / CTL;
+ melody(t);
+ check(note_span(t, 0) == 2, "C1: LEN 2 to start with");
+ n = note_span_set(t, 0, 10);
+ if (getenv("DUMP")) dump(t, 12);
+ check(n == 10 && note_span(t, 0) == 10, "C1: LEN 10 under C2 D2 E2 (2.8.1: NOTE AHEAD at 2)");
+ check(note_span(t, 2) == 2 && note_span(t, 4) == 2 && note_span(t, 6) == 2, "the melody's notes keep their LEN 2");
+ transport_req = 1;
+ block();
+ g = gated_blocks(t, 36, 0, 10, &r);
+ check(g >= 10u * SB - 4u && !r, "plays: C1 sounds 10 steps in one go under the melody");
+ transport_req = 2; block();
+ for (n = 0; n < 40; n++) block();
+ transport_req = 1; block();
+ g = gated_blocks(t, 50, 4, 6, &r);
+ check(g >= 2u * SB - 4u, "plays: D2 sounds its 2 steps over it");
+ transport_req = 2; block();
+ n = note_span_set(t, 0, 5);
+ if (getenv("DUMP")) dump(t, 12);
+ check(n == 5 && note_span(t, 0) == 5 && note_span(t, 4) == 2 && note_span(t, 6) == 2, "shorter: LEN 5 ends inside D2, D2 keeps its length");
+ n = note_span_set(t, 0, 2);
+ check(n == 2 && t->step[2].n == 1 && t->step[4].n == 1 && t->step[6].n == 1 && t->step[5].time == ST_TIE && t->step[7].time == ST_TIE,
+ "back to LEN 2: the melody exactly as it was");
+ note_span_set(t, 0, 9);
+ note_del(t, 0, 0);
+ check(!step_on(&t->step[0]) && t->step[2].n == 1 && t->step[4].n == 1 && t->step[6].n == 1 && t->step[8].time != ST_NOTE,
+ "C1 deleted: nothing of it left under the melody");
+ /* MONO: one note at a time */
+ melody(t);
+ t->p[P_VOICE] = V_MONO;
+ n = note_span_set(t, 0, 10);
+ check(n == 2 && span_why == 2u, "MONO sound: stops at C2, says MONO: SET VOICE POLY");
+ t->p[P_VOICE] = V_POLY;
+ /* a full step: 4 notes there already */
+ melody(t);
+ t->step[2].note[1] = 55; t->step[2].note[2] = 59; t->step[2].note[3] = 62; t->step[2].n = 4;
+ n = note_span_set(t, 0, 10);
+ check(n == 2 && span_why == 1u, "a step with 4 notes: stops, says STEP FULL");
+ /* no notes ahead: as 2.8.1 (clean TIEs) */
+ melody(t);
+ n = note_span_set(t, 6, 6);
+ check(n == 6 && t->step[8].time == ST_TIE && t->step[11].time == ST_TIE && t->step[12].time == ST_REST, "nothing ahead: plain TIEs, as before");
+ printf("len: %d failed\n", fails);
+ return fails;
+}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 0914c1a..caeda12 100644
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -53,6 +53,14 @@ $CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/studio_drums_test" tests/studio_d
run "drum lanes, kit audio, metronome, record arm, free take" "$OUT/studio_drums_test" "$OUT/drum-styles.wav"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/seq2_test" tests/seq2_test.c -lm
run "sequencer 2.0: no drift, ratchets, roll, erase / undo, ghost / hard, chords, mute / solo, nudge, locks" "$OUT/seq2_test"
+$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/hold_rec_test" tests/hold_rec_test.c -lm
+run "2.8.3: a note held under others (live, recorded, overdubbed), MIDI in overflow" "$OUT/hold_rec_test"
+$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/len_test" tests/len_test.c -lm
+run "2.8.3: SEQ > NOTES, LEN under later notes, MONO / STEP FULL, shorter, delete" "$OUT/len_test"
+$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/drum_steal_test" tests/drum_steal_test.c -lm
+run "2.8.3: drum voices on a busy beat, every kit: no kick cut by another sound" "$OUT/drum_steal_test"
+$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/chop_attack_test" tests/chop_attack_test.c -lm
+run "2.8.3: a sample played again starts from silence with its ATK (POLY same note, MONO, LEGATO, UNISON), no click" "$OUT/chop_attack_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/drumkit_test" tests/drumkit_test.c -lm
run "synthesised drum kits: every kit x sound bounded, audible, finite, levels, cost" "$OUT/drumkit_test" "$OUT/drum-kits.wav" "$OUT/drum-kits.txt"
diff --git a/tests/seq2_test.c b/tests/seq2_test.c
index 55862df..5fbd044 100644
--- a/tests/seq2_test.c
+++ b/tests/seq2_test.c
@@ -67,6 +67,8 @@ static void reset(uint32_t bpm)
rec_wait = 0;
fm1_in.notes = fm1_in.buttons = 0;
kb_prev = 0;
+ memset(live_held, 0, sizeof live_held); /* (2.8.3: the keys let go with kb_prev, as on the FM-1) */
+ memset(mi_trk_held, 0, sizeof mi_trk_held);
ly_bit[LY_ROLL] = 1u << 8; /* (the buttons: any bits) */
ly_bit[LY_ERASE] = 1u << 4;
dyn_bit[0] = 1u << 0;
diff --git a/tests/ui_pages_test.c b/tests/ui_pages_test.c
index dfff0a5..ad7a20c 100644
--- a/tests/ui_pages_test.c
+++ b/tests/ui_pages_test.c
@@ -247,7 +247,15 @@ int main(int argc, char **argv)
go_home(); frame();
tap(B_FX); check(cur_fam() == FAM_FX, "FX tapped: the FX pages");
go_home(); frame();
- press(B_FX); frames(12); check(ui.layer == LY_FX && punch.hold, "FX held: the punch layer shows");
+ { /* (2.8.3) a tap of 0.3 s: the layer never shows on the way (it used to flash after 0.14 s) */
+ uint32_t f, shown = 0;
+ press(B_FX);
+ for (f = 0; f < 18u; f++) { frame(); shown |= ui.layer == LY_FX; }
+ release(B_FX); frame();
+ check(!shown && cur_fam() == FAM_FX, "2.8.3: FX tapped in 0.3 s: no flash of the layer, the FX pages");
+ }
+ go_home(); frame();
+ press(B_FX); frames(24); check(ui.layer == LY_FX && punch.hold, "FX held: the punch layer shows"); /* (2.8.3: after 0.35 s) */
check(keys_guide() == (1u << key_of_white(0) | 1u << key_of_white(4) | 1u << key_of_white(8) | 1u << key_of_white(12)),
"FX held: keys 1, 5, 9, 13 lit dim (the rows of the grid)");
ppm("layer-punch");
@@ -547,7 +555,7 @@ int main(int argc, char **argv)
/* ---- SAVE: tap = the song page; held = the SONG layer (live sections, SONG REC) */
go_home(); frame();
song.playing = 0; live_sec = -1; live_req = -1; srec = 0; arrangement_enabled = 0;
- press(B_SAVE); frames(15); check(ui.layer == LY_SONG, "SAVE held: the song layer");
+ press(B_SAVE); frames(24); check(ui.layer == LY_SONG, "SAVE held: the song layer"); /* (2.8.3: after 0.35 s) */
key(key_of_white(4)); check(sec_stores == 0 && sec_armed == 1u, "store over a used A: asks again");
key(key_of_white(4)); check(sec_stores == 1 && live_sec == 0, "again: the loop stored in A");
key(key_of_white(6)); check(sec_stores == 2 && live_sec == 2, "an empty C: stored at once");