Files
JIANT/tests/settings_test.c
Claude 8fa10082b7 V10.8.59: VISUAL from the song, very reactive to every hit; SCL lighter and PER1/PER2 settings no longer read (room)
(the owner: "por cada canción una visual bastante diferente, muy audio reactiva: que cambie la forma, la posición por
cada golpe"; "todas deformadas y fusionadas con este motor"; option 2 for the room: SCL's drawings and the old settings)
- VISUAL (codex/visual-react-wip 12906768): the scene's seed from the song (gen.c vis_song: GEN's seed and genre, MOOD
  and ENERGY the motion; else the project's sounds; the section A..D a variant of the same family); a track's new note
  a hit: a kick jumps and thumps the scene and eases back, a snare pulls the strips apart, a note jumps the field's
  lobes; one field (vp) bends every layer (mesh, skull, head, rings, the data's lines), REACT scales it.
- The room (the image was 708 B over):
  - SCL > CHORD: TYPE . VOICING no longer repeated under the chord's name (the page's cards say them); each degree's
    tag names its triad (chord_nm, as PROG: "D-", "E°", "F") instead of the chord TYPE would build there; the short
    chord names gone. "CHORD OFF" as the name when off.
  - SCL > PROG: "BAR n" no longer on every card (the cards' order and the bar under them say it).
  - SCL > KEY: the scales' long names in the Bluetooth segment (the short one if the segment is missing).
  - Settings: PER1 and PER2 (Felucca's first, before JIANT 0.6) no longer migrated: refused, the global settings
    start from the defaults once. PER3 and PER4 read as before.
- Not back for room: the hats' sparks, the note's name on the label, the drift, the MIXED duo's step every fourth kick.
- tests: ui_test (two GEN seeds two scenes, the same seed the same; a new note a hit); settings_test (PER1/PER2 refused).
Layout recorded again (FELUCCA_REPIN=keep); the plain build passes. Image 584196 of 584336 (140 B free), BT segment
73700 of 73728 (28 B free), RAM code unchanged (32700). audio.c as V23's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-27 12:52:16 +00:00

195 lines
12 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define __attribute__(x)
#define NENGINES 9u
#define UP_SLOTS 32u
#define ENGI_SAMPLE 4u /* (core.h: SAMPLE, DRUM, the retired PERC set) */
#define ENGI_DRUM 10u
#define SMP_SET_PERC 4u
static uint8_t fx_lowcut;
static void fm1_led_key(unsigned k, int on) { (void)k; (void)on; }
static int fm1_enc_take(unsigned k) { (void)k; return 0; }
static void lcd_sync(void) {}
static void lcd_power(uint32_t s) { (void)s; } /* (MENU > SCREEN OFF: lcd.c) */
static void lcd_wake_now(void) {}
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
{ (void)x; (void)y; (void)w; (void)h; (void)p; }
#include "../firmware/src/gfx.c"
#include "../firmware/src/panel.c"
static void settings_save(void) {}
#if __has_include("../firmware/src/favorites.c")
#include "../firmware/src/favorites.c"
#endif
static struct { uint8_t cal; } vs = {1}; /* (V10.6z6 / 6ba2f5e: settings_import reads the keys' calibration
* again: vel_kb.h's vk_cal; without it this test no longer built
* and run_tests.sh, set -e, stopped here, before 56 more suites) */
#define vk_cal (vs.cal)
#include "../firmware/src/settings_persist.c"
int main(void)
{
persist_t original = {0}, p;
original.magic = PERSIST_MAGIC;
original.palette = 4; original.bold = original.lowcut = original.zoom = 1; /* old id 4: MONO, now HUESO (5) */
original.panel = PANEL_DEFAULT; original.panel.enc[0] = 3;
original.favorites.factory[8][0] = 1;
original.favorites.user = 1u << 31; original.favorites.filter = 1;
p = original; /* (JIANT 0.6.81) at power-on, no mark yet: the palette set to JIANT once,
* marked; marked: kept */
assert(settings_import(&p, sizeof p) == 1);
settings_jiant_once(&p);
assert(settings.palette == UI_JIANT_INDEX && p.favorites.factory[15][23] == JIANT_PAL_SEEN &&
p.palette == palette_to_stored(UI_JIANT_INDEX));
p.palette = palette_to_stored(5);
assert(settings_import(&p, sizeof p) == 1);
settings_jiant_once(&p);
assert(settings.palette == 5u);
p = original;
assert(settings_import(&p, sizeof p) == 1); settings_init();
assert(settings.palette == 5u && fx_lowcut && settings.zoom && panel.enc[0] == 3);
assert(p.palette == palette_to_stored(5u)); /* migrated in place */
{ /* every old id maps to a palette; tagged ids round trip; anything else is JIANT */
persist_t q = original;
enum { JIANT, SELVA, CONTRAST, BRASA, ABISAL, HUESO, NEON };
/* the firmware up to V10.7.18 saved UI_PAL_TAG + its index: GREY GREEN AMBER ICE VIOLET ROSE PAPER HI-CON NIGHT
* MONO JIANT -> the nearest of the family */
static const uint8_t V10[11] = {HUESO, SELVA, BRASA, ABISAL, JIANT, BRASA, CONTRAST, CONTRAST, HUESO, HUESO, JIANT};
/* and what that firmware reads these settings as (its index; NEON: an id it does not know, its fallback) */
static const uint8_t AS[7] = {10, 1, 7, 2, 3, 0, 11};
assert(!strcmp(UI_PALETTES[HUESO].name, "HUESO") && !strcmp(UI_PALETTES[NEON].name, "NEON") && UI_JIANT_INDEX == JIANT);
for (uint32_t i = 0; i < 20u; i++) assert(palette_from_stored(i) < NPALETTES);
assert(palette_from_stored(13) == CONTRAST && palette_from_stored(11) == CONTRAST && palette_from_stored(19) == CONTRAST &&
palette_from_stored(0) == SELVA && palette_from_stored(1) == BRASA && palette_from_stored(5) == JIANT);
for (uint32_t i = 0; i < NPALETTES; i++)
assert(palette_from_stored(palette_to_stored(i)) == i && palette_to_stored(i) == UI_PAL_TAG + AS[i] &&
palette_stored_ok(palette_to_stored(i)));
for (uint32_t i = 0; i < 11u; i++)
assert(palette_from_stored(UI_PAL_TAG + i) == V10[i] && palette_stored_ok(UI_PAL_TAG + i));
for (uint32_t i = 0; i < 300u; i++) /* never an index out of the table, whatever was saved */
assert(palette_from_stored(i) < NPALETTES && palette_from_stored(0xFFFFFF00u + i) < NPALETTES);
assert(palette_from_stored(40) == UI_JIANT_INDEX && !palette_stored_ok(40) && palette_stored_ok(3) &&
palette_from_stored(UI_PAL_TAG + 12u) == UI_JIANT_INDEX && !palette_stored_ok(UI_PAL_TAG + 12u) &&
!palette_stored_ok(UI_PAL_TAG - 1u));
q.palette = UI_PAL_TAG + 9u; /* a saved MONO: HUESO, rewritten as HUESO's id */
assert(settings_import(&q, sizeof q) == 1 && settings.palette == HUESO && q.palette == UI_PAL_TAG + 0u);
q.palette = palette_to_stored(5);
assert(settings_import(&q, sizeof q) == 1 && settings.palette == 5u);
settings.magic = SETTINGS_MAGIC_OLD; settings.palette = 13; settings_init(); /* retained SET3 */
assert(settings.magic == SETTINGS_MAGIC && settings.palette == 2u);
p = original; assert(settings_import(&p, sizeof p) == 1); settings_init();
}
#ifdef FELUCCA_FAVORITES
assert(favorite_has(8, 0) && favorite_has(NENGINES, 31) && favorites.filter);
{ /* SAMPLE's PERC starred (preset 4, retired): DRUM's kit (preset 0) instead; SAMPLE's others kept; twice the same */
persist_t q = original;
q.favorites.factory[ENGI_SAMPLE][0] = 1u << SMP_SET_PERC | 1u << 2;
assert(settings_import(&q, sizeof q) == 1 && favorites.factory[ENGI_SAMPLE][0] == 1u << 2 &&
favorites.factory[ENGI_DRUM][0] == 1u);
settings_export(&q);
assert(settings_import(&q, sizeof q) == 1 && favorites.factory[ENGI_SAMPLE][0] == 1u << 2 &&
favorites.factory[ENGI_DRUM][0] == 1u);
p = original; assert(settings_import(&p, sizeof p) == 1);
}
#endif
settings.lowcut = 0;
settings_export(&p);
assert(!p.lowcut && p.bold == 1 && p.favorites.user == (1u << 31)); /* bold: kept as saved */
assert(p.favorites.factory[8][0] == 1 && p.favorites.filter == 1);
assert(p.panel.enc[0] == 3); /* saving one feature preserves the other */
p = original; p.magic = 0x50455233u;
assert(settings_import(&p, sizeof p - sizeof p.favorites) == 2);
assert(p.bold == 1 && !p.favorites.user && !p.favorites.filter);
settings_export(&p); assert(p.bold == 1); /* favorites-only preserves PER3 font */
p = original; p.magic = 0x50455232u; /* (V10.8.59) PER2 and PER1 no longer read */
assert(settings_import(&p, sizeof p - sizeof p.favorites - sizeof p.bold) == 0);
p = original; p.magic = 0x50455231u;
memcpy((uint8_t *)&p + 8, &PANEL_DEFAULT, sizeof(panel_t));
assert(settings_import(&p, 8 + sizeof(panel_t)) == 0);
{ /* HOLD: in the retired bold field; older records (bold 0 / 1) are 0.4 s, and stay as saved */
p = original; p.bold = 0;
assert(settings_import(&p, sizeof p) == 1 && settings_hold == HOLD_DEF && HOLD_MS[settings_hold] == 400u);
p = original;
assert(settings_import(&p, sizeof p) == 1 && settings_hold == HOLD_DEF);
settings_hold = 3;
settings_export(&p);
assert(hold_stored_ok(p.bold) && p.bold != 1u);
settings_hold = 0;
assert(settings_import(&p, sizeof p) == 1 && settings_hold == 3u && HOLD_MS[settings_hold] == 600u);
settings_hold = HOLD_DEF;
settings_export(&p);
assert(p.bold == 0u && settings_import(&p, sizeof p) == 1 && settings_hold == HOLD_DEF);
assert(!hold_stored_ok(2u) && !hold_stored_ok(HOLD_TAG + 4u) && hold_stored_ok(HOLD_TAG | 2u));
}
{ /* LEDS: in the retired zoom field; older records (zoom 0 / 1) are DIM, and stay as saved; idempotent */
persist_t q;
p = original; /* zoom 1: an older record's large readout */
assert(settings_import(&p, sizeof p) == 1 && settings_leds == LEDS_DIM);
q = p; settings_export(&q); assert(q.zoom == 1u); /* DIM: kept as saved */
settings_leds = LEDS_INV;
settings_export(&p);
assert(p.zoom == (LEDS_TAG | LEDS_INV) && leds_stored_ok(p.zoom));
q = p; settings_export(&q); assert(!memcmp(&q, &p, sizeof q)); /* a second save: the same record */
settings_leds = LEDS_DIM;
assert(settings_import(&p, sizeof p) == 1 && settings_leds == LEDS_INV);
q = p; assert(settings_import(&q, sizeof q) == 1 && !memcmp(&q, &p, sizeof q)); /* import twice: the same */
settings_leds = LEDS_DIM;
settings_export(&p);
assert(p.zoom == 0u && settings_import(&p, sizeof p) == 1 && settings_leds == LEDS_DIM);
assert(leds_stored_ok(0u) && leds_stored_ok(1u) && !leds_stored_ok(2u) && leds_stored_ok(LEDS_TAG | 2u) &&
leds_stored_ok(LEDS_TAG | 3u) && !leds_stored_ok(LEDS_TAG + 4u) && leds_from_stored(LEDS_TAG + 4u) == LEDS_DIM &&
leds_from_stored(7u) == LEDS_DIM && leds_from_stored(2u) == LEDS_DIM);
/* the modes appended (append-only: DIM 0, INV 1 as before): OFF 2, DIM LO 3, each saved and read back,
* twice the same */
{
uint32_t m;
static const uint32_t ADDED[2] = {LEDS_OFF, LEDS_DIM_LO};
assert(LEDS_DIM == 0 && LEDS_INV == 1 && LEDS_OFF == 2 && LEDS_DIM_LO == 3 && LEDS_COUNT == 4);
for (m = 0; m < 2u; m++) {
settings_leds = (uint8_t)ADDED[m];
settings_export(&p);
assert(p.zoom == (LEDS_TAG | ADDED[m]) && leds_stored_ok(p.zoom));
q = p; settings_export(&q); assert(!memcmp(&q, &p, sizeof q));
settings_leds = LEDS_DIM;
assert(settings_import(&p, sizeof p) == 1 && settings_leds == ADDED[m]);
}
settings_leds = LEDS_DIM;
settings_export(&p);
assert(p.zoom == 0u);
}
}
#ifdef FELUCCA_FAVORITES
{ /* 1.1 CLICK / CLICK LEVEL / COUNT-IN (ui.c ui_rec_prefs, favorites.factory[15][28]): 0 in every older record
* (the defaults: OFF / MID / OFF); each field 0..2 kept, 3 (no value) back to 0, bits 6-7 kept; twice the same */
persist_t q;
uint32_t b;
p = original; p.magic = 0x50455233u; /* PER3 (no favorites): 0 */
assert(settings_import(&p, sizeof p - sizeof p.favorites) == 2 && favorites.factory[15][28] == 0u);
for (b = 0; b < 256u; b++) {
uint32_t f, want = b;
for (f = 0; f < 3u; f++)
if (((b >> (2u * f)) & 3u) == 3u) want &= ~(3u << (2u * f));
p = original; p.favorites.factory[15][28] = (uint8_t)b;
assert(settings_import(&p, sizeof p) == 1 && favorites.factory[15][28] == want && p.favorites.factory[15][28] == want);
q = p; assert(settings_import(&q, sizeof q) == 1 && !memcmp(&q, &p, sizeof q));
settings_export(&q); assert(q.favorites.factory[15][28] == want);
}
p = original; assert(settings_import(&p, sizeof p) == 1);
}
{ /* 1.2 RESTORE LAST (ui.c PREF_RESTORE_OFF, bit 7 of MENU's flags, favorites.factory[15][30]): clear in every
* older record = ON; set = OFF, kept as saved with the other flags */
persist_t q;
p = original; p.magic = 0x50455233u;
assert(settings_import(&p, sizeof p - sizeof p.favorites) == 2 && !(favorites.factory[15][30] & 128u));
p = original; p.favorites.factory[15][30] = 128u | 64u | 1u;
assert(settings_import(&p, sizeof p) == 1 && favorites.factory[15][30] == (128u | 64u | 1u));
q = p; settings_export(&q); assert(q.favorites.factory[15][30] == (128u | 64u | 1u));
p = original; assert(settings_import(&p, sizeof p) == 1);
}
#endif
assert(settings_import(&p, 3) == 0 && settings_import(&p, -1) == 0);
assert(settings_import(&p, sizeof p - 1) == 0);
puts("Settings: PER3 migration (PER1/PER2 refused), palette ids, calibration, HOLD, LEDS, CLICK / COUNT-IN and independent feature preservation passed.");
}