Files
JIANT/firmware/src/ui_menu.c
T

567 lines
29 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* Felucca menu (HOME held): its rows in tabs (1.0.5: DISPLAY CONTROL AUDIO SYSTEM; JIANT 0.9.12: MIDI before SYSTEM;
* ALGORITHM between them, PRESETS within one; no scrolling), the rows in menu_items.c (the settings, shared with the editor's MENU_DESC / MENU_SET).
* No BACK row: HOME closes it (ui_input.c). The two-valued rows are bits of ui_prefs (MENU_FLAGS). PRESETS scrolls from
* ABOUT through all credits (OCT- back to the tabs). ui.menu: 1 the tabs, 2 information. */
/* ------------------------------------------------------------ menu --- */
/* (the rows, their values and names, usb_serial_apply: menu_items.c) */
/* https://github.com/juanjiant-bit/JIANT, QR version 3, correction M, generated by segno (python).
* One row per word, leftmost module in bit 0; the constant matrix needs no encoder or RAM. */
static const uint32_t ABOUT_QR[29] = {
0x1FC4C67Fu, 0x10536541u, 0x1744955Du, 0x17531B5Du, 0x175FD65Du, 0x10575C41u,
0x1FD5557Fu, 0x00140300u, 0x0E721141u, 0x0DAE4A31u, 0x01049B58u, 0x02288C33u,
0x10D17AF2u, 0x19DD2702u, 0x0735EEEBu, 0x1588EE0Bu, 0x06AA4DD6u, 0x1DCE9F33u,
0x1309F7E3u, 0x00554009u, 0x1DFB8A75u, 0x0310B300u, 0x0759E87Fu, 0x111C3241u,
0x13FD305Du, 0x163F9A5Du, 0x0FF8865Du, 0x16C18641u, 0x05CAD17Fu,
};
static void draw_about_qr(int32_t x, int32_t y)
{
uint32_t row, col;
cv_rect(x, y, 74, 74, UI_QR_LIGHT); /* fixed light / dark, independent of the palette */
for (row = 0; row < 29u; row++)
for (col = 0; col < 29u; col++)
if ((ABOUT_QR[row] >> col) & 1u)
cv_rect(x + 8 + (int32_t)col * 2, y + 8 + (int32_t)row * 2, 2, 2, UI_QR_DARK);
}
/* All notices are in flash. Wrap at the font's actual width, without dropping URL
* characters; the same layout computes the scroll limit and draws clipped bands.
* Mixed case here (long text); S throughout, the title in L. */
#define MENU_DOC_H 196 /* the document: screen rows 24..220 */
enum { MC_TEXT, MC_TITLE, MC_URL };
typedef struct { const char *text; uint8_t kind; } menu_credit_t;
static const menu_credit_t MENU_CREDITS[] = {
{"FELUCCA", MC_TITLE}, /* (0.9.12) the base; MIDI LEARN from its 1.5 (midi_learn.c) */
{"Leo Kuroshita, Hugelton Instruments: the firmware JIANT builds on, MIDI LEARN: GPL-3.0", MC_TEXT},
{"https://github.com/hugelton/Felucca", MC_URL},
{"", MC_TEXT},
{"SKIFF", MC_TITLE}, /* (0.9.12) designs after it: 12 voices on two cores, the sound types */
{"illuminus5: 12 voices with two cores, sound types: GPL-3.0", MC_TEXT},
{"https://github.com/illuminus5/skiff", MC_URL},
{"", MC_TEXT},
{"SOUNDS + FONTS", MC_TITLE},
{"CrispyZebra (PHASE waveforms), the DRUM voices, the Sample Pack: GPL-3.0", MC_TEXT},
{"Fukiai icon font: MIT", MC_TEXT},
{"", MC_TEXT},
{"DUAL CORE", MC_TITLE}, /* (JIANT 0.6.71) hal/fm1_multicore.h */
{"Melodee (keremimo), fm1-x0x (Charles Vestal): GPL-3.0", MC_TEXT},
{"https://github.com/keremimo/melodee", MC_URL},
{"https://github.com/charlesvestal/fm1-x0x", MC_URL},
{"", MC_TEXT},
{"TESTING, CPU", MC_TITLE}, /* (JIANT 0.6.79) on a real FM-1: the load, the dual core, the RAM code */
{"praztalfractal", MC_TEXT},
{"https://github.com/gospodindilly-ops", MC_URL},
{"", MC_TEXT},
{"KLATTSCH", MC_TITLE},
{"Tony Gies / MIT", MC_TEXT},
{"https://github.com/tgies/klattsch", MC_URL},
{"", MC_TEXT},
{"DEXED + MSFA", MC_TITLE},
{"Pascal Gauthier, Google Inc.", MC_TEXT},
{"msfa: Apache-2.0, Dexed: GPL-3.0", MC_TEXT},
{"https://github.com/asb2m10/dexed", MC_URL},
{"", MC_TEXT},
{"INTER TIGHT", MC_TITLE},
{"The Inter Project Authors", MC_TEXT},
{"SIL Open Font License 1.1", MC_TEXT},
{"https://github.com/rsms/inter-tight", MC_URL},
{"", MC_TEXT},
{"VSCO-2 CE + VCSL", MC_TITLE},
{"Versilian Studios / CC0 1.0", MC_TEXT},
{"https://github.com/sgossner/VSCO-2-CE", MC_URL},
{"https://github.com/sgossner/VCSL", MC_URL},
{"", MC_TEXT},
{"VOICE", MC_TITLE},
{"Dennis H. Klatt (1980)", MC_TEXT},
{"https://doi.org/10.1121/1.383940", MC_URL},
{"Hillenbrand, Getty, Clark and Wheeler (1995)", MC_TEXT},
{"https://doi.org/10.1121/1.411872", MC_URL},
{"", MC_TEXT},
{"CMU DICT", MC_TITLE}, /* (JIANT 0.8.5) VOICE's English words (sing.c) */
{"Carnegie Mellon University / BSD-2-Clause", MC_TEXT},
{"https://github.com/cmusphinx/cmudict", MC_URL},
};
static int32_t menu_text(const char *s, int32_t y, uint16_t col, int draw)
{
while (*s) {
char line[64];
uint32_t n = 0, space = 0, take, prev = 0;
int32_t pen = 0; /* 1/16 px, as text_w adds it up */
while (s[n] && n < sizeof line - 1u) {
uint32_t c = (uint8_t)s[n];
line[n] = s[n];
line[n + 1u] = 0;
pen += (prev ? kern(&AF_S, prev, c) : 0) + AF_S.gh[glyph(&AF_S, c) >> AF_S.psh].adv;
prev = c;
if ((pen + 8) >> 4 > 226)
break;
if (s[n] == ' ')
space = n;
n++;
}
take = s[n] && space ? space : n;
if (!take) take = 1; /* progress even for an unusually wide glyph */
line[take] = 0;
if (draw && y + AF_S.h > 0 && y < MENU_DOC_H)
cv_text(6, y, &AF_S, line, col);
y += 18;
s += take;
while (*s == ' ') s++;
}
return y;
}
/* (0.9.14) SAVE > TOOLS 6 CPU TEST measured: its song played 10 s or more, its mean AUDIO LOAD from 2 s on kept in the
* settings with the cores it ran on (cpt_res %, cpt_cores; 0 = not run): ABOUT, PROFILE, and GEN's EXPLORE budget
* (gen.c gc_dev: the host's model holds the song at ~63 % of a half with two cores, ~77 % with one) */
#define cpt_res (favorites.factory[15][16]) /* (bytes no engine uses: engine 15) */
#define cpt_cores (favorites.factory[15][15])
#define cpt_arm (prf.cpt_arm) /* the CPU TEST song built, TRACKS 6 (song_dice.c cpu_test_song) */
static __attribute__((noinline)) void cpt_poll(void) /* (ui_input: every pass) */
{
uint32_t t = fm1_ms - prf.cpt_ms;
if (!cpt_arm)
return;
if (song.playing) {
if (!prf.cpt_ms)
prf.cpt_ms = fm1_ms | 1u;
else if (t > 2000u)
prf.cpt_sum += song.cpu_q8, prf.cpt_n++;
return;
}
if (prf.cpt_ms && t > 12000u && prf.cpt_n) { /* stopped after 10 s of it: kept */
cpt_res = (uint8_t)clamp((int32_t)(prf.cpt_sum / prf.cpt_n * 100u >> 8), 1, 250);
cpt_cores = (uint8_t)(mc_two() ? 2u : 1u);
settings_save();
ui_message("CPU TEST: SEE ABOUT");
}
cpt_arm = (uint8_t)!prf.cpt_ms; /* (played and stopped: done either way) */
prf.cpt_ms = prf.cpt_sum = prf.cpt_n = 0;
}
static void cpt_line(char *b) /* "CPU TEST 98 % (2 CORES)", "CPU TEST: TOOLS 6" */
{
str_cpy(b, cpt_res ? "CPU TEST " : "CPU TEST: SAVE > TOOLS 6", 40);
if (cpt_res) {
fmt_int(b + 9, cpt_res);
str_cpy(b + str_len(b), cpt_cores == 1u ? " % (1 CORE)" : " % (2 CORES)", 14);
}
}
/* (0.9.14) MENU > ABOUT > PROFILE (OCT+ on ABOUT): where the audio's time went (prof.c), in % of a block (725 us; the
* load meter's halves are 4 of them): the last second playing, its mean and its worst block, then the same for the last
* second stopped (grey). SELECT scrolls, OCT- back to ABOUT. The rows: the sequencer, each part (its engine; C1: mostly
* on the second core), the buses (of them the reverb, the rest the delay and chorus), core 0 waiting for core 1, the FX
* layer to CLIP, the master, USB and the output, core 1 busy, TIMER5 within the render, the whole half (= AUDIO LOAD);
* then (means only) TIMER5 in all, the audio interrupt's latest start (us), the late halves, the blocks the buses
* rested (%), the UI's frames */
static uint32_t gc_dev(void); /* (gen.c) */
enum { PRV_DC = PRF_N, PRV_T5, PRV_LAT, PRV_LATE, PRV_REST, PRV_FPS };
static int prf_val(const prf_win_t *w, uint32_t k, uint32_t mx, int32_t *v) /* 1: tenths, 2: whole, 0: none */
{
uint32_t bt = w->blocks * (PRF_BLK / 8u) / 125u + 1u, x; /* (a second's ticks / 1000: no 64-bit divide) */
if (k < PRF_N) {
*v = (int32_t)(mx ? w->max[k] * (k >= PRF_NB ? 250u : 1000u) / PRF_BLK : w->sum[k] / bt);
return 1;
}
if (mx)
return 0;
x = k == PRV_DC ? w->sum[PRF_FX] - w->sum[PRF_REV] : k == PRV_T5 ? w->t5 : k == PRV_LAT ? w->lat / 24u :
k == PRV_LATE ? w->late : k == PRV_REST ? w->fxrest * 100u / (w->blocks + 1u) : w->frames;
*v = (int32_t)(k <= PRV_T5 ? x / bt : x);
return k <= PRV_T5 ? 1 : 2;
}
static int32_t prf_row(int32_t y, int draw, const char *name, uint32_t k)
{
uint32_t c;
if (draw && y + AF_S.h > 0 && y < MENU_DOC_H) {
cv_text(6, y, &AF_S, name, T_TEXT);
for (c = 0; c < 4u; c++) {
char b[12];
int32_t v = 0;
int f = (prf_have >> (1u - c / 2u)) & 1u ? prf_val(&prf_win[1u - c / 2u], k, c & 1u, &v) : 0;
b[0] = '0'; /* ("0.5", not ".5") */
if (f) fmt_fix(b + (f == 1 && v < 10), v, f == 1); else str_cpy(b, "-", 2);
cv_text_r(136 + (int32_t)c * 31, y, &AF_S, b, c / 2u ? T_MID : T_TEXT, T_BG);
}
}
return y + 18;
}
static int32_t prof_document(int32_t y, int draw)
{
static const char *const NM[] = {"SEQUENCER", "FX BUSES", "REVERB ", "DELAY+CHORUS", "CORE 0 WAITS", "FX LAYER..CLIP",
"MASTER", "USB+OUTPUT", "CORE 1 BUSY", "TIMER5 IN IT", "WHOLE HALF", "TIMER5 ALL",
"IRQ LATE US", "LATE HALVES", "FX REST %", "UI FRAMES"};
static const uint8_t KS[] = {PRF_SEQ, PRF_FX, PRF_REV, PRV_DC, PRF_WAIT, PRF_POST, PRF_MST, PRF_IO, PRF_C1, PRF_IRQ,
PRF_HALF, PRV_T5, PRV_LAT, PRV_LATE, PRV_REST, PRV_FPS};
const prf_win_t *w = &prf_win[prf_have >> 1];
char b[40];
uint32_t k, i;
y = menu_text("% OF A BLOCK: PLAY AVG MAX, STOP AVG MAX", y + 4, T_THEME, draw);
for (i = 0; i < NELEM(KS); i++) {
str_cpy(b, NM[i], sizeof b);
if (KS[i] == PRF_REV)
str_cpy(b + 7, N_RTYPE[REV_LITE[LOAD_EFF() % 3u][clamp(song.g[G_RTYPE], 0, 4)]], 8);
y = prf_row(y, draw, b, KS[i]);
for (k = 0; !i && k < NPART; k++) { /* (the parts after the sequencer; C1: mostly on core 1) */
b[0] = 'T'; b[1] = (char)('1' + k); b[2] = ' ';
str_cpy(b + 3, k < trk_live ? ENGINES[trk[k].engine]->name : "-", 10);
if (w->c1[k] * 2u > w->blocks && w->blocks)
str_cpy(b + str_len(b), " C1", 4);
y = prf_row(y, draw, b, PRF_T1 + k);
}
}
str_cpy(b, "VOICES ", sizeof b);
fmt_int(b + 7, (int32_t)voices_busy());
str_cpy(b + str_len(b), " CAP ", 6);
fmt_int(b + str_len(b), (int32_t)voice_cap());
str_cpy(b + str_len(b), LOAD_EFF() == LOAD_ECO ? " ECO" : LOAD_EFF() ? " LITE" : " FULL", 6);
y = menu_text(b, y + 4, T_TEXT, draw);
y = menu_text(cpu_status(), y, T_TEXT, draw);
cpt_line(b);
y = menu_text(b, y, T_TEXT, draw);
str_cpy(b, "EXPLORE: DEVICE X", sizeof b);
fmt_fix(b + 17, (int32_t)gc_dev(), 2);
y = menu_text(b, y, T_TEXT, draw);
return menu_text(FELUCCA_VERSION, y, T_MID, draw) + 4;
}
static int32_t menu_document(int32_t y, int draw)
{
uint32_t i;
if (ui.menu == 3)
return prof_document(y, draw);
if (draw) {
cv_text(6, y + 2, &AF_L, "JIANT FM", T_THEME);
cv_text(6, y + 38, &AF_S, "Firmware for the MVAVE FM-1", T_TEXT);
cv_text(6, y + 58, &AF_M, FELUCCA_VERSION, T_THEME);
cv_text_r(232, y + 61, &AF_S, __DATE__, T_MID, T_BG);
cv_text(6, y + 82, &AF_S, "by Juan Jiant, Argentina", T_TEXT); /* (0.6.96: the project's own) */
cv_text(6, y + 100, &AF_S, "Free, GPL-3.0-only, no warranty", T_TEXT);
cv_text(6, y + 118, &AF_S, "Made in Argentina", T_TEXT);
cv_text(6, y + 138, &AF_S, "github.com", T_MID);
cv_text(6, y + 156, &AF_S, "/juanjiant-bit", T_MID);
cv_text(6, y + 174, &AF_S, "/JIANT", T_MID);
draw_about_qr(158, y + 122);
}
y = menu_text("THE PROJECT", y + 216, T_THEME, draw);
y = menu_text("Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)", y, T_TEXT, draw); /* (0.9.12) */
y = menu_text("Made in Argentina by Juan Jiant, visual artist and musician, a dad of two: an independent project, free for everyone.", y, T_TEXT, draw);
y = menu_text("Manual, emulator, installer, editor:", y + 4, T_TEXT, draw);
y = menu_text("juanjiant-bit.github.io/JIANT", y, T_MID, draw);
y = menu_text("Videos: youtube.com/@JUANJIANT", y, T_MID, draw);
y = menu_text("Support the work:", y + 4, T_TEXT, draw);
y = menu_text("ko-fi.com/juanjiant", y, T_MID, draw);
y = menu_text("cafecito.app/juanjiant (Argentina)", y, T_MID, draw);
y = menu_text("Free software, GPL-3.0-only: the full notices and the sources it builds on travel with the source.", y + 4, T_TEXT, draw);
y -= 216;
{ /* (0.6.17) the audio's load since power-on (voice.c load_diag): to tell what happened when it clicked */
char b[40], n[12];
y = menu_text("AUDIO LOAD", y + 216, T_THEME, draw);
str_cpy(b, "NOW ", sizeof b); fmt_int(n, (int32_t)((song.cpu_q8 * 100u) >> 8)); str_cpy(b + str_len(b), n, 8);
str_cpy(b + str_len(b), "% PEAK ", 10); fmt_int(n, (int32_t)load_diag.peak); str_cpy(b + str_len(b), n, 8);
str_cpy(b + str_len(b), "%", 2);
y = menu_text(b, y, T_TEXT, draw);
str_cpy(b, "LATE ", sizeof b); fmt_int(n, (int32_t)load_diag.late); str_cpy(b + str_len(b), n, 12);
str_cpy(b + str_len(b), " SHED ", 8); fmt_int(n, (int32_t)load_diag.shed); str_cpy(b + str_len(b), n, 12);
y = menu_text(b, y, T_TEXT, draw);
y = menu_text(cpu_status(), y, T_TEXT, draw); /* (0.6.71) the second core (fx.c; 0.9.12: cpu_safe.c) */
y = menu_text(cpu_is_320() ? "CPU 320 MHZ" : "CPU 360 MHZ", y, T_TEXT, draw); /* (0.9.12) the clock now */
cpt_line(b); /* (0.9.14) */
y = menu_text(b, y, T_TEXT, draw);
y = menu_text("OCT+: PROFILE", y, T_MID, draw);
}
{ /* (0.9.12) the last crash kept (cpu_safe.c crash_log; MANUAL: Troubleshooting) */
char b[CRASH_LOG_N + 1u];
y = menu_text("LAST CRASH", y + 4, T_THEME, draw);
y = menu_text(crash_log_get(b) ? b : "NONE", y, T_TEXT, draw) - 216 + 8;
}
y = menu_text("CREDITS", y + 216, T_THEME, draw) + 8;
for (i = 0; i < NELEM(MENU_CREDITS); i++) {
const menu_credit_t *c = &MENU_CREDITS[i];
const char *text = c->text;
/* Display host/path once; the full source URL stays in the flash table. */
if (c->kind == MC_URL && str_len(text) >= 8u && !memcmp(text, "https://", 8))
text += 8;
if (!text[0]) y += 8;
else y = menu_text(text, y, c->kind == MC_TITLE ? T_THEME : c->kind == MC_URL ? T_MID : T_TEXT, draw);
}
y = menu_text("LICENSES + SOURCE", y + 12, T_THEME, draw);
y = menu_text("DRUM + own samples: GPL-3.0-only", y, T_TEXT, draw);
y = menu_text("Fonts and icons: their licences travel with the source and the release files.", y, T_TEXT, draw);
y = menu_text("NO WARRANTY", y, T_TEXT, draw);
y = menu_text("Full notices in source:", y + 8, T_TEXT, draw);
y = menu_text("github.com/juanjiant-bit/JIANT", y, T_MID, draw);
return y + 4;
}
static int32_t menu_scroll_max(void)
{
int32_t h = menu_document(0, 0);
return h > MENU_DOC_H ? h - MENU_DOC_H : 0;
}
/* (0.8.5) The menu as a lens, as the approved mock-up (MENU . TAB . ROW; SELECT zooms, ui.mlv): the header "MENU .
* DISPLAY" (draw_head), the level tabs, four cards, a panel, the breadcrumb.
* cards the selected row's four (ROWS 1-4 / ROWS 5-6 of its tab: TAB's two sets, the set following the row); ROW:
* TAB, ROW k/n, the row's value
* panel MENU: the four tabs as tiles, each with its rows and their values (the tab shown framed); TAB: the tab's rows
* (the set's tinted with their knob's number, the selected one striped in the accent); ROW: the row's values as
* chips (the one set framed; COLOR: each palette's colours, live)
* The knobs, ALGORITHM, PRESETS, OCT-/+ as before (any knob or OCT-/+ the selected row's value; PRESETS its row, on MENU
* the tab). The drawing redone whole on a change (menu_sig) */
static int menu_large(void) { return (ui_prefs & PREF_LARGE) != 0u; }
static uint32_t menu_tab(void) { return MI_TAB[ui.menu_sel % MI_COUNT]; }
static uint32_t menu_set(void) { return (ui.menu_sel - mtab_first(menu_tab())) / 4u; } /* ROWS 1-4: 0, 5-6: 1 */
static void menu_val(uint32_t row, char *b) /* the row's value as it reads ("0.4 s"; OCT+ rows: "OPEN") */
{
if (row == MI_LCLEAR) { /* (0.9.12) LEARN CLEAR: how many CCs are learned, "NONE" */
uint32_t n = ml_count();
str_cpy(b, "NONE", 16);
if (n) {
fmt_int(b, (int32_t)n);
str_cpy(b + str_len(b), " CC", 4);
}
return;
}
str_cpy(b, !menu_valued(row) ? "OPEN" : row == MI_HOLD ? HOLD_N[settings_hold % 4u] : menu_vname(row, menu_get(row)), 16);
}
static const char *menu_short(uint32_t row) /* a card's label: the row's name, or its short form */
{
static const struct { uint8_t row; char s[9]; } SH[] = {
{MI_SCROFF, "SCR OFF"}, {MI_ACCEL, "ACCEL"}, {MI_SCLLED, "SCL LEDS"}, {MI_LOWCUT, "SPK EQ"}, {MI_USB, "USB LVL"},
{MI_CLKLVL, "CLICK LV"}, {MI_RESTORE, "RESTORE"}, {MI_PANEL, "CALIBR"}, {MI_INIT, "INIT SYS"},
{MI_CLOCK, "CPU CLK"}, {MI_LCLEAR, "LRN CLR"}};
uint32_t k;
for (k = 0; k < NELEM(SH); k++)
if (SH[k].row == row)
return SH[k].s;
return MI_NAME[row];
}
static void menu_cards(void)
{
uint32_t t = menu_tab(), f = mtab_first(t), n = mtab_rows(t), c, r;
char v[16];
if (ui.mlv == 2u) {
char k[8];
fmt_int(k, (int32_t)(ui.menu_sel - f) + 1);
str_cpy(k + str_len(k), "/", 2);
fmt_int(k + str_len(k), (int32_t)n);
draw_column(0, "TAB", MTAB_NAME[t], "", T_TEXT, (int32_t)t * 1000 / (MTAB_COUNT - 1), ICON_NONE);
draw_column(1, "ROW", k, "", T_TEXT, (int32_t)(ui.menu_sel - f) * 1000 / (int32_t)(n > 1u ? n - 1u : 1u), ICON_NONE);
menu_val(ui.menu_sel, v);
draw_column(2, menu_short(ui.menu_sel), v, "", T_TEXT, menu_valued(ui.menu_sel) && menu_n(ui.menu_sel) > 1u ?
(int32_t)menu_get(ui.menu_sel) * 1000 / (int32_t)(menu_n(ui.menu_sel) - 1u) : -1, ICON_NONE);
draw_column(3, "", "", "", T_DIM, -1, ICON_NONE);
return;
}
for (c = 0; c < 4u; c++) {
r = f + menu_set() * 4u + c;
if (r >= f + n) {
draw_column(c, "", "", "", T_DIM, -1, ICON_NONE);
continue;
}
menu_val(r, v);
draw_column(c, menu_short(r), v, "", r == ui.menu_sel ? T_ACCENT : T_TEXT, menu_valued(r) && menu_n(r) > 1u ?
(int32_t)menu_get(r) * 1000 / (int32_t)(menu_n(r) - 1u) : -1, ICON_NONE);
}
}
static void menu_panel(void)
{
uint32_t t = menu_tab(), f = mtab_first(t), n = mtab_rows(t), k, r;
char v[16];
if (ui.mlv != 2u) { /* TAB: its rows (0.9.12: MENU's view of the tabs as tiles gone:
* five do not fit, and since 0.9.2 the menu opens at TAB) */
cv_text(10, 6 - AF_X_CAP_Y, &AF_X, MTAB_NAME[t], T_THEME);
cv_text_r(228, 6 - AF_X_CAP_Y, &AF_X, "ALGO: TAB \xB7 SELECT: ROW", T_DIM, T_SURF);
for (r = 0; r < n; r++) { /* (0.8.9: seven rows fit, 17 apart; 0.9.7: eight, 15) */
uint32_t row = f + r, in = r / 4u == menu_set();
int32_t y = 14 + (int32_t)r * (n > 7u ? 15 : n > 6u ? 17 : 20), h = n > 7u ? 14 : n > 6u ? 16 : 18;
uint16_t bg = in ? T_TINT : T_RAISE;
cv_rect(8, y, 224, h, bg);
if (row == ui.menu_sel)
cv_rect(8, y, 3, h, T_ACCENT);
GFX_HOOK_ALIGN(0, y, 0, y + h, AL_V, "menu row name centred up/down");
cv_text_on(16, y + CAP_IN(S, h), &AF_S, MI_NAME[row], in ? T_TEXT : T_MID, bg);
menu_val(row, v);
cv_text_r(in ? 218 : 226, y + CAP_IN(S, h), &AF_S, v, in ? T_TEXT : T_MID, bg);
if (in) {
char kn[2] = {(char)('1' + r % 4u), 0};
cv_text(221, y + 2 - AF_X_CAP_Y, &AF_X, kn, T_THEME);
}
}
return;
}
{ /* ROW: the row's values as chips (COLOR: each palette's colours) */
uint32_t row = ui.menu_sel, nv = menu_valued(row) ? menu_n(row) : 0u, cur = nv ? menu_get(row) : 0u;
char b[32];
str_cpy(b, MTAB_NAME[t], 32);
str_cpy(b + str_len(b), " > ", 32 - str_len(b));
str_cpy(b + str_len(b), MI_NAME[row], 32 - str_len(b));
cv_text(10, 6 - AF_X_CAP_Y, &AF_X, b, T_THEME);
if (!nv) {
cv_text_in(4, 60 - AF_M_CAP_Y, 232, &AF_M, row == MI_LCLEAR ? "OCT+ CLEARS ALL" : "OCT+ OPENS IT", T_MID, T_SURF);
return;
}
for (k = 0; k < nv && k < 18u; k++) {
int32_t x = 8 + (int32_t)(k % 3u) * 75, y = 16 + (int32_t)(k / 3u) * 20;
uint16_t bg = k == cur ? T_TINT : T_RAISE;
cv_rect(x, y, 72, 18, bg);
if (k == cur) {
cv_rect(x, y, 72, 1, T_ACCENT); cv_rect(x, y + 17, 72, 1, T_ACCENT);
cv_rect(x, y, 1, 18, T_ACCENT); cv_rect(x + 71, y, 1, 18, T_ACCENT);
}
cv_clip_text(x + 5, y + 6 - AF_X_CAP_Y, &AF_X, row == MI_HOLD ? HOLD_N[k % 4u] : menu_vname(row, k),
k == cur ? T_TEXT : T_MID, bg, row == MI_COLOR ? 44 : 62);
if (row == MI_COLOR) { /* (the palette's THEME and ACCENT) */
uint32_t q;
for (q = 0; q < 2u; q++) {
uint16_t col = q ? UI_PALETTES[k % NPALETTES].accent : UI_PALETTES[k % NPALETTES].theme;
cv_rect(x + 50 + (int32_t)q * 10, y + 5, 8, 8, ux.mono || settings.palette == UI_BW_INDEX ?
ux_gray(ux_luma(col) >> 3) : col); /* (GREY, MONO: their grays) */
}
}
}
}
}
static void confirm_open(uint32_t kind, uint32_t trk); /* (0.6.58) INIT SYSTEM: ui_input.c */
static void draw_menu(void)
{
uint32_t sig;
sig = ui.menu * 7u + ui.menu_sel * 131u + settings.palette * 1009u + settings.lowcut * 7919u + settings_hold * 3511u +
settings_leds * 6151u + ui_prefs * 4099u + ui_style * 257u + ui_skin * 1543u + song.rec * 65537u + song.sel * 13u +
ui_rec_prefs * 92821u + ui_scr * 131071u + ui.mlv * 0x9E3779B1u + /* (#157: SCREEN OFF's value redraws its row) */
(ui.menu >= 2 ? ui.menu_scroll * 48611u : 0u) + (ui.menu == 3 ? prf_seq * 2971u + 1u : 0u) +
(ui.menu == 2 ? (song.cpu_q8 >> 3) * 7741u + load_diag.peak * 3329u + load_diag.late * 1931u +
load_diag.shed * 2671u : 0u); /* (0.6.19) ABOUT's AUDIO LOAD: live (NOW in ~3 % steps) */
draw_head(); /* (0.8.5: the pages' header, "MENU . DISPLAY") */
if (!ui.force && sig == ui.menu_sig)
return;
ui.menu_sig = sig;
if (ui.menu >= 2) {
uint32_t pass;
int32_t scroll = ui.menu_scroll, max = menu_scroll_max();
int32_t thumb = MENU_DOC_H * MENU_DOC_H / (max + MENU_DOC_H);
if (thumb < 12) thumb = 12;
for (pass = 0; pass < 2u; pass++) {
cv_begin(240, pass ? MENU_DOC_H - 124u : 124u, T_BG);
cv_oy = pass ? -124 : 0;
cv_scroll = 1;
menu_document(-scroll, 1);
cv_scroll = 0;
cv_rrect(235, 2, 3, MENU_DOC_H - 4, 1, T_LINE, T_BG); /* the scroll bar */
cv_rrect(235, 2 + (max ? scroll * (MENU_DOC_H - 4 - thumb) / max : 0), 3, thumb, 1, T_MID, T_LINE);
cv_oy = 0;
cv_blit(0, H_HEAD + pass * 124u);
}
cv_begin(240, 240 - (H_HEAD + MENU_DOC_H), T_BG);
{
static const khint_t KH[2] = {{KC_SELECT, "SCROLL"}, {KC_OCTDN, "BACK"}};
cv_key_row(8, 232, 4, KH, 2, 3u, T_BG);
}
cv_blit(0, H_HEAD + MENU_DOC_H);
return;
}
if (ui.force) { /* (0.9.0) round its tabs, cards, panel and footer, not under them */
int16_t R[7][4] = {{0, LT_Y, 240, (int16_t)(lz_low() ? LB_TAB_H : LT_H)}, {0, LZ_GRAPH_Y, 240, LZ_GRAPH_H},
{0, (int16_t)foot_y(), 240, (int16_t)foot_h()}};
uint32_t c;
for (c = 0; c < 4u; c++) {
R[3u + c][0] = (int16_t)CARD_X(c);
R[3u + c][1] = (int16_t)card_y();
R[3u + c][2] = CARD_W;
R[3u + c][3] = (int16_t)card_h();
}
fill_around((const int16_t (*)[4])R, 7);
}
draw_tabs();
menu_cards();
cv_begin(240, LZ_GRAPH_H, T_BG);
cv_rect(4, 0, 232, LZ_GRAPH_H, T_SURF);
cv_bg = T_SURF;
menu_panel();
cv_blit(0, LZ_GRAPH_Y);
draw_foot();
}
static void enc_drop(void) /* knob turns nobody takes */
{
uint32_t k;
for (k = 0; k < NE; k++)
panel_enc(k);
}
static void menu_close(void)
{
settings_save(); /* palette / panel table, if changed */
ui.menu = 0;
ui.force = 1;
go_home();
}
/* (0.9.2) the menu: SELECT walks every row, tab after tab (DISPLAY CONTROL AUDIO MIDI SYSTEM, no wrap), ALGORITHM jumps to
* the next / previous tab's first row (no wrap), PRESETS does nothing (rule 3: no presets here), any of KNOB 1..4 or
* OCT+ / OCT- change a value (menu_items.c menu_step), OCT+ opens CALIBRATION / ABOUT (OCT- nothing there); in ABOUT
* SELECT scrolls, OCT- goes back. HOME closes it, from ABOUT too (ui_input.c). (Until 0.9.1: SELECT zoomed MENU . TAB .
* ROW, PRESETS the row, ALGORITHM the tab round.) */
static void menu_tab_go(int32_t s) /* ALGORITHM: the next / previous tab, its first row */
{
int32_t t = clamp((int32_t)menu_tab() + s, 0, MTAB_COUNT - 1); /* (a tab a detent) */
ui.menu_sel = (uint8_t)mtab_first((uint32_t)t);
}
static void menu_input(uint32_t oct) /* oct: ui_input.c oct_taps */
{
int32_t s;
uint32_t k, up = (oct >> 1) & 1u, dn = oct & 1u;
if (ui.menu >= 2) { /* ABOUT: SELECT scrolls (bounded), OCT- back to the tabs; (0.9.14)
* OCT+ PROFILE (its OCT- back to ABOUT) */
if (dn)
ui.menu = (uint8_t)(ui.menu - 1), ui.menu_scroll = 0, ui.force = 1;
else if (up && ui.menu == 2) {
if (!prf_on)
memset(&prf_cur, 0, sizeof prf_cur);
ui.menu = 3, ui.menu_scroll = 0, prf_on = 1, ui.force = 1;
}
else if ((s = panel_enc(EN_SELECT)) != 0)
ui.menu_scroll = (uint16_t)clamp((int32_t)ui.menu_scroll + clamp(s, -128, 128) * 18, 0, menu_scroll_max());
enc_drop();
return;
}
if ((s = panel_enc(EN_SELECT)) != 0) /* (0.9.2) SELECT: every row, one a detent */
ui.menu_sel = (uint8_t)clamp((int32_t)ui.menu_sel + s, 0, MI_COUNT - 1);
ui.mlv = 1; /* (the tab's rows) */
if ((s = panel_enc(EN_ALGO)) != 0)
menu_tab_go(s);
for (s = 0, k = 0; k < 4u; k++) /* KNOB 1..4, any of them */
s += panel_enc(EN_K1 + k);
if (menu_valued(ui.menu_sel)) {
/* a step (OCT+ the next value, OCT- the previous); COLOR previews the palette, STYLE is drawn so from the next
* frame (FX LATCH: the latched effects are off while the menu is up) */
s += (int32_t)up - (int32_t)dn;
if (s)
menu_put(ui.menu_sel, menu_step(ui.menu_sel, s));
} else if (up) {
if (ui.menu_sel == MI_LCLEAR) { /* (0.9.12) LEARN CLEAR: every learned CC (no dialog: LEARN again
* brings one back) */
ui_message(ml_clear_all() ? "LEARN CLEARED" : "NOTHING LEARNED");
ui.force = 1;
} else if (ui.menu_sel == MI_PANEL) {
panel_setup();
scrn.idle = fm1_ms; /* (SCREEN OFF: its own loop had the input) */
ui.force = 1;
} else if (ui.menu_sel == MI_INIT) { /* (0.6.58) INIT SYSTEM: a new song from zero (as SAVE > TOOLS 5,
* its dialog; UNDO brings the music back) */
ui.menu = 0;
confirm_open(CF_INIT_SYS, song.sel);
ui.force = 1;
} else { /* MI_ABOUT */
ui.menu = 2;
ui.menu_scroll = 0;
ui.force = 1;
}
}
enc_drop(); /* swallow the rest while the menu is up */
}