Bound transposed MIDI ownership in LOWBUF and preserve the pool safety reserve

This commit is contained in:
JUAN JIANT committed 2026-11-04 19:52:23 -03:00
1 parent 3e5370dc10
commit a8b34914bc
7 files changed
+106 -18

No files matched your search

+18
View File
@@ -41,6 +41,24 @@ jobs:
python3 tests/uac_input_irq_test.py > build/song-check/usb-input.log
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/midi_control_test.c -lm -o build/song-check/midi
build/song-check/midi | tee build/song-check/midi.log
- name: Verified pre-split baseline for UI regression comparison
uses: actions/checkout@v4
with:
ref: f5f6b1bde3a2eefa14444ad2212626c7aa4d46a8
path: build/ui-baseline
persist-credentials: false
- name: Full UI comparison against known baseline
run: |
set -euo pipefail
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/ui_test.c -lm -o build/song-check/ui-full
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ibuild/ui-baseline/firmware/src build/ui-baseline/tests/ui_test.c -lm -o build/song-check/ui-base
set +e
build/song-check/ui-full > build/song-check/ui-full.log
FULL_RC=$?
build/song-check/ui-base > build/song-check/ui-base.log
BASE_RC=$?
set -e
python3 tests/ui_baseline_compare.py build/song-check/ui-base.log build/song-check/ui-full.log "$BASE_RC" "$FULL_RC"
- name: JieLi toolchain cache
uses: actions/cache@v4
with:
+7 -1
View File
@@ -20,6 +20,12 @@ Normal split notes take priority over SCENE multi-track fan-out. Names, shortcut
Each held physical/MIDI note retains the track and sounding note until release, even when split, track, octave, cut or selected track changes. Sustain, bend, wheel and channel aftertouch reach the split destinations. Notes share the existing synthesis voice/CPU budget.
Configuration is stored per project/section in the optional KS extension. Older projects decode OFF; disabling split does not discard its configuration. Existing firmware parameter IDs and flash map stay unchanged. MIDI sounding-note ownership uses pool RAM, including constant-time held-note reference counts to handle clamped/overlapping notes.
Configuration is stored per project/section in the optional KS extension. Older projects decode OFF; disabling split does not discard its configuration. Existing firmware parameter IDs and flash map stay unchanged. MIDI sounding-note ownership uses a dense, bounded LOWBUF remap list only for transposed presses, preserving the pool safety reserve. Up to 128 transposed presses retain their original sounding note; further transposed note-ons are refused until a key is released. Normal untransposed input keeps the existing channel/key ownership table.
Automated coverage includes both zones, sustain, changing split while held, clamped duplicate notes, CC120/123, pitch bend, SCENE priority, UI knob editing, NOR project round trips, legacy OFF, autosave signatures and invalid destinations. Existing MIDI/clock, persistence, backup, FIT and USB regressions run with the candidate. Hardware validation is still required before promoting this beta.
## General regression review
The full UI suite was run against the verified FIT base f5f6b1b and this candidate. Both runs report the same 18 failures (14 distinct checks); the split candidate adds no failing checks after updating the GLO page counts for its two added pages. These existing failures include assertions for older REC/SELECT navigation and page chains. This comparison is not a claim that the full legacy UI suite is clean.
The MIDI/clock integration suite, including split-specific cases, also ran with AddressSanitizer and bounds checks. The persistence and legacy project-format suites passed. Firmware checks separately enforce flash, RAM, pool and short-call reach limits. Six sparse MIDI controller dispatch routines use size optimization; synthesis, clocks, DMA and note ownership/release retain their existing optimization.
+36 -9
View File
@@ -22,8 +22,31 @@ static void mn_set(uint32_t ch, uint32_t note, uint32_t v)
uint32_t sh = (note & 1u) * 4u;
*b = (uint8_t)((*b & ~(15u << sh)) | (v & 15u) << sh);
}
static uint8_t midi_sound[16][128] __attribute__((section(".pool")));
static uint16_t midi_refs[NTRK][128] __attribute__((section(".pool")));
/* Dense remaps only for transposed keys; normal MIDI keeps its existing nibble table.
* At most 128 transposed presses, each retaining original channel/key until release.
* LOWBUF has linker-checked room; preserve the pool's 8 KiB safety reserve. */
static struct {
uint16_t n;
struct { uint16_t key; uint8_t note, rsv; } row[128];
} midi_map __attribute__((section(".lowbuf")));
static uint32_t midi_mapped(uint32_t ch, uint32_t note, uint32_t forget)
{
uint32_t key=(ch<<7)|note;
for(uint32_t i=0;i<midi_map.n;i++) if(midi_map.row[i].key==key) {
note=midi_map.row[i].note;
if(forget) midi_map.row[i]=midi_map.row[--midi_map.n];
break;
}
return note;
}
static int midi_remap(uint32_t ch,uint32_t note,uint32_t sound)
{
if(note==sound) return 1;
if(midi_map.n==128u) return 0; /* bounded admission; never lose a stored note-off */
midi_map.row[midi_map.n].key=(uint16_t)((ch<<7)|note);
midi_map.row[midi_map.n++].note=(uint8_t)sound;
return 1;
}
static uint16_t midi_owners[NTRK]; /* avoids rescanning all 2048 entries for CC123 */
#define MIDI_PEDAL_NOTE 0x8u
@@ -65,7 +88,12 @@ static void midi_expression_channel(uint32_t ch)
/* a MIDI note of track t sounds note */
static int midi_note_held(const track_t *t, uint32_t note)
{
return note < 128u && midi_refs[trk_index(t)][note] != 0u;
uint32_t id=trk_index(t)+1u;
for(uint32_t ch=0;ch<16u;ch++)
if((mn_get(ch,note)&7u)==id && midi_mapped(ch,note,0)==note) return 1;
for(uint32_t i=0;i<midi_map.n;i++)
if(midi_map.row[i].note==note && (mn_get(midi_map.row[i].key>>7,midi_map.row[i].key&127u)&7u)==id) return 1;
return 0;
}
/* a key held on track t sounds note */
@@ -86,10 +114,9 @@ static void midi_release(uint32_t ch, uint32_t note)
{
uint32_t id = mn_get(ch, note) & 0x7u;
uint32_t source = note;
note = midi_sound[ch][source];
note = midi_mapped(ch, source, 1);
mn_set(ch, source, 0);
if (id) {
if (midi_refs[id - 1u][note]) midi_refs[id - 1u][note]--;
midi_owners[id - 1u]--;
if (!--midi_ch[ch].owned[id - 1u])
midi_ch[ch].targets &= (uint8_t)~(1u << (id - 1u));
@@ -126,13 +153,12 @@ static void midi_note_event(uint32_t ch, uint32_t note, uint32_t vel)
/* Repeated notes replace the previous press, including a pedal-held one. */
if (id)
midi_release(ch, note);
if (!midi_remap(ch, note, sound)) return;
midi_expression(t, c);
if (t != TSEL)
midi_hint = (uint8_t)(trk_index(t) + 1u);
c->targets |= (uint8_t)(1u << trk_index(t));
midi_play(t, ch, sound, vel);
midi_sound[ch][note] = (uint8_t)sound;
midi_refs[trk_index(t)][sound]++;
mn_set(ch, note, (uint8_t)(trk_index(t) + 1u));
midi_owners[trk_index(t)]++;
c->owned[trk_index(t)]++;
@@ -162,13 +188,14 @@ static void __attribute__((noinline)) midi_forget_track(uint32_t track)
if (!(midi_ch[ch].targets & (1u << track)))
continue;
for (note = 0; note < 128u; note++)
if ((mn_get(ch, note) & 0x7u) == track + 1u)
if ((mn_get(ch, note) & 0x7u) == track + 1u) {
midi_mapped(ch, note, 1);
mn_set(ch, note, 0);
}
midi_ch[ch].targets &= (uint8_t)~(1u << track);
midi_ch[ch].owned[track] = 0;
}
midi_owners[track] = 0;
memset(midi_refs[track], 0, sizeof midi_refs[track]);
midi_bend_q8[track] = midi_bend_target[track] = 0;
}
+1 -1
View File
@@ -2868,7 +2868,7 @@ static void events_block(uint32_t n)
memset(midi_sel_on, 0, sizeof midi_sel_on);
memset(midi_ch, 0, sizeof midi_ch);
memset(midi_owners, 0, sizeof midi_owners);
memset(midi_refs, 0, sizeof midi_refs);
memset(&midi_map, 0, sizeof midi_map);
midi_hint = 0;
for (i = 0; i < NTRK; i++) {
trk[i].rh_n = trk[i].rskip_n = 0;
+17 -7
View File
@@ -8,7 +8,7 @@ static void midi_test_reset(void)
{
ui_power_on();
memset(midi_ch, 0, sizeof midi_ch); memset(midi_sel_on, 0, sizeof midi_sel_on);
memset(midi_owners, 0, sizeof midi_owners); memset(midi_refs, 0, sizeof midi_refs); memset(split_cfg, 0, sizeof split_cfg); memset(midi_bend_q8, 0, sizeof midi_bend_q8);
memset(midi_owners, 0, sizeof midi_owners); memset(&midi_map, 0, sizeof midi_map); memset(split_cfg, 0, sizeof split_cfg); memset(midi_bend_q8, 0, sizeof midi_bend_q8);
memset(midi_bend_target, 0, sizeof midi_bend_target); memset(&midi_clock, 0, sizeof midi_clock);
memset(&um, 0, sizeof um); memset(midi_in_source, 0, sizeof midi_in_source);
mi_r = mi_w = 0; midi_in_overflow = 0; midi_beat_samples = 0;
@@ -421,21 +421,21 @@ static int split_test(void)
split_cfg[0]=1; split_cfg[2]=0; split_cfg[3]=1; split_cfg[4]=(uint8_t)-1; split_cfg[5]=1;
split_cfg[6]=9; split_cfg[7]=60;
queued(0x99,48,100,1); queued(0x99,72,100,1);
bad += check("MIDI split: channel 10 reaches independent tracks and octaves", mn_get(9,48)==1 && mn_get(9,72)==2 && midi_refs[0][36]==1 && midi_refs[1][84]==1);
bad += check("MIDI split: channel 10 reaches independent tracks and octaves", mn_get(9,48)==1 && mn_get(9,72)==2 && midi_note_held(&trk[0],36) && midi_note_held(&trk[1],84));
queued(0xB9,64,127,1); queued(0x89,48,0,1); queued(0x89,72,0,1);
bad += check("MIDI split: sustain holds both zones", (mn_get(9,48)&8) && (mn_get(9,72)&8));
split_cfg[0]=0; split_cfg[2]=3; split_cfg[3]=2; split_cfg[4]=2; split_cfg[5]=0;
queued(0xB9,64,0,1);
bad += check("MIDI split: original notes release after settings change and split OFF", !mn_get(9,48) && !mn_get(9,72) && !midi_refs[0][36] && !midi_refs[1][84]);
bad += check("MIDI split: original notes release after settings change and split OFF", !mn_get(9,48) && !mn_get(9,72) && !midi_note_held(&trk[0],36) && !midi_note_held(&trk[1],84));
split_cfg[0]=1; split_cfg[6]=0; split_cfg[2]=0; split_cfg[3]=1; split_cfg[4]=(uint8_t)-4; split_cfg[5]=4;
queued(0x90,0,100,1); queued(0x90,12,100,1); queued(0x90,127,100,1);
bad += check("MIDI split: clamped notes retain separate owners", midi_refs[0][0]==2 && midi_refs[1][127]==1);
bad += check("MIDI split: clamped notes retain separate owners", midi_mapped(0,0,0)==0 && midi_mapped(0,12,0)==0 && midi_note_held(&trk[1],127));
queued(0x80,0,0,1);
bad += check("MIDI split: first duplicate release retains the other owner", midi_refs[0][0]==1 && midi_note_held(&trk[0],0));
bad += check("MIDI split: first duplicate release retains the other owner", mn_get(0,12) && midi_note_held(&trk[0],0));
queued(0xB0,123,0,1);
bad += check("MIDI split: CC123 releases both zones", !midi_refs[0][0] && !midi_refs[1][127]);
bad += check("MIDI split: CC123 releases both zones", !midi_note_held(&trk[0],0) && !midi_note_held(&trk[1],127));
queued(0x90,48,100,1); queued(0x90,72,100,1); queued(0xB0,120,0,1);
bad += check("MIDI split: CC120 clears both zones and ownership", !midi_owners[0] && !midi_owners[1] && !midi_refs[0][0] && !midi_refs[1][120]);
bad += check("MIDI split: CC120 clears both zones and ownership", !midi_owners[0] && !midi_owners[1] && !midi_note_held(&trk[0],0) && !midi_note_held(&trk[1],120));
split_cfg[4]=0; split_cfg[5]=0;
song.sel=2; midi_bend_target[2]=0;
queued(0xE0,127,127,1);
@@ -443,6 +443,16 @@ static int split_test(void)
queued(0xB0,1,91,1);queued(0xD0,73,0,1);
bad += check("MIDI split: wheel and aftertouch reach both zones only", trk[0].mw==91 && trk[1].mw==91 && trk[0].at==73 && trk[1].at==73 && !trk[2].mw && !trk[2].at);
midi_test_reset();
split_cfg[0]=1;split_cfg[3]=1;split_cfg[4]=split_cfg[5]=1;
for(uint32_t n=1;n<=100;n++) queued(0x90,n,100,1);
split_cfg[6]=1;
for(uint32_t n=1;n<=29;n++) queued(0x91,n,100,1);
bad += check("MIDI split: remap capacity refuses extra presses without corrupting owners", midi_map.n==128 && !mn_get(1,29));
queued(0x80,1,0,1);queued(0x91,29,100,1);
bad += check("MIDI split: a released remap is reused safely", midi_map.n==128 && mn_get(1,29));
queued(0xB0,123,0,1);queued(0xB1,123,0,1);
bad += check("MIDI split: all bounded remaps release after channel changes", !midi_map.n && !midi_owners[0] && !midi_owners[1]);
midi_test_reset();
split_cfg[0]=1;split_cfg[2]=0;split_cfg[3]=1;split_cfg[4]=(uint8_t)-1;split_cfg[5]=1;
scn_on=1; /* split has priority over SCENE for normal keyboard notes */
fm1_in.notes=(1u<<7)|(1u<<19); events_block(CTL);
+26
View File
@@ -0,0 +1,26 @@
"""Fail on new full-UI failures or crashes; report existing baseline debt explicitly."""
import collections
import re
import sys
from pathlib import Path
def failures(path, rc):
text = Path(path).read_text(errors="replace")
failed = collections.Counter(line for line in text.splitlines() if line.endswith("FAIL"))
reported = re.search(r"ui: (\d+) FAILED\s*$", text)
if failed:
assert int(rc) == 1 and reported and int(reported[1]) == sum(failed.values()), "UI crashed or failure report is incomplete"
else:
assert int(rc) == 0, "UI failed without an assertion report"
return failed
base = failures(sys.argv[1], sys.argv[3])
current = failures(sys.argv[2], sys.argv[4])
new = current - base
print(f"Full UI: {sum(base.values())} known baseline failures, {sum(current.values())} candidate failures")
for line, count in new.items():
print(f"NEW ({count}): {line}")
assert not new, "new UI regression"
print("PASS no new full-UI assertions; existing baseline failures remain visible in logs")
+1
View File
@@ -175,6 +175,7 @@ static int check(const char *what, int ok)
static void ui_power_on(void)
{
uint32_t i;
memset(split_cfg, 0, sizeof split_cfg); memset(&midi_map, 0, sizeof midi_map);
if (!lyb_ok)
sing_init(); /* (0.9.0: as felucca_init, VOICE's English generator words) */
memset(trk, 0, sizeof trk);