From 253ff329dbd918681cc78dab6c11f2bbcb8ccfad Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 17:09:51 -0300 Subject: [PATCH] FMini: a turned SLOT loads after 50 ms still fmini_poll no longer loads a slot at each step of the knob: the slot the knob points to loads once it has been still for FMINI_LOAD_MS (50). Each turn restarts the count. OWN changes stay immediate. A note played in that window sounds the previous patch (accepted). fmini_bank_test checks the count (not at once; 30 ms still no; 50 ms still loads). Co-Authored-By: Claude Haiku 5.5 Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94 --- firmware/src/eng_fmini.c | 17 ++++++++++++++++- tests/fmini_bank_test.c | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/firmware/src/eng_fmini.c b/firmware/src/eng_fmini.c index 15fe492..7471f7f 100644 --- a/firmware/src/eng_fmini.c +++ b/firmware/src/eng_fmini.c @@ -78,6 +78,9 @@ static int32_t fmini_det(const uint8_t *g, uint32_t i) /* the cents of DET byt static uint8_t fmini_patch[NTRK][FG_SIZE]; /* the tracks' patches (main loop writes, then fmini_pgen) */ static volatile uint8_t fmini_pgen[NTRK]; /* +1 after each write of fmini_patch[t] */ static uint16_t fmini_slot[NTRK]; /* the SLOT value last loaded (main loop); 0xFFFF = none (1.14.0: 256 = OWN) */ +#define FMINI_LOAD_MS 50u /* a SLOT that keeps turning loads when it stops for this long (1.14.0) */ +static uint16_t fmini_want[NTRK]; /* the slot the knob points to, not loaded yet (0xFFFF: none) */ +static uint32_t fmini_want_ms[NTRK]; /* when fmini_want last changed */ static uint8_t fmini_own[NTRK][FG_SIZE]; /* the own patch while SLOT shows a factory one (fmini_poll) */ static uint8_t fmini_own_ok; /* bit tr: fmini_own[tr] holds it */ static struct { /* the patch as the audio ISR sees it (taken at a block's start) */ @@ -190,6 +193,7 @@ static void fmini_init(void) /* power-on: every track F1 */ for (tr = 0; tr < NTRK; tr++) { fmini_set_patch(tr, FMINI_FACTORY[0]); fmini_slot[tr] = 0xFFFFu; + fmini_want[tr] = 0xFFFFu; } } @@ -200,9 +204,20 @@ static void fmini_poll(void) uint32_t tr, bit; for (tr = 0; tr < NTRK; tr++) { int32_t s = trk[tr].p[P_E7]; - if (trk[tr].eng_req != ENGI_FMINI || s == fmini_slot[tr]) + if (trk[tr].eng_req != ENGI_FMINI || s == fmini_slot[tr]) { + fmini_want[tr] = 0xFFFFu; continue; + } bit = 1u << tr; + if (s >= 0 && s < (int32_t)FMINI_NSLOT) { /* a slot: loads once the knob has been still for FMINI_LOAD_MS */ + if (fmini_want[tr] != (uint16_t)s) { + fmini_want[tr] = (uint16_t)s; + fmini_want_ms[tr] = fm1_ms; + continue; + } + if (fm1_ms - fmini_want_ms[tr] < FMINI_LOAD_MS) + continue; + } if (s < 0 || s >= (int32_t)FMINI_NSLOT) { /* OWN */ if (fmini_own_ok & bit) fmini_set_patch(tr, fmini_own[tr]); diff --git a/tests/fmini_bank_test.c b/tests/fmini_bank_test.c index 3b626e0..97a827d 100644 --- a/tests/fmini_bank_test.c +++ b/tests/fmini_bank_test.c @@ -67,6 +67,28 @@ int main(void) fbchk(!strcmp(fb_name[0], "MINI LEAD") && !strcmp(fb_name[FMINI_NFACTORY], "INIT") && !strcmp(fb_name[FB_NSLOT - 1], "INIT"), "the RAM name list: slot 0 and the INIT slots"); + /* the load waits: a SLOT loads once it has been still for 50 ms; each turn starts the count again */ + { + uint32_t t0 = 1000u; + uint8_t want[FB_SLOT]; + (void)want; + trk[0].eng_req = ENGI_FMINI; + fmini_slot[0] = 0xFFFFu; + fm1_ms = t0; + trk[0].p[P_E7] = 5; + fmini_poll(); + fbchk(fmini_slot[0] != 5u, "a turned slot is not loaded at once"); + fm1_ms = t0 + 30u; + trk[0].p[P_E7] = 6; /* turned again: the count restarts */ + fmini_poll(); + fm1_ms = t0 + 60u; /* 30 ms since the last turn */ + fmini_poll(); + fbchk(fmini_slot[0] != 6u, "still turning (30 ms since the last change): not loaded"); + fm1_ms = t0 + 80u; /* 50 ms since the last turn */ + fmini_poll(); + fbchk(fmini_slot[0] == 6u, "still for 50 ms: the slot loads"); + } + printf(bad ? "FMINI BANK TEST FAILED\n" : "fmini_bank test passed\n"); return bad != 0; }