mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 12:54:29 +01:00
- SKIN in MENU > DISPLAY after COLOR (COLORS by default; ui_skin, engine 15 byte 20 of the settings: older settings and unknown values load as COLORS; the editor's MENU id 21; DISPLAY now seven rows, the menu's TAB rows 17 apart, its MENU tiles 72 / 64 tall, ROWS 5-7). ux.skin follows it (style_apply); BOTTOM and HUD make SURF the background. - Palettes (tools/gen_ui_palettes.py): four knob colours each (KNOBS: the mock-up's for JIANT PAPER GREEN AMBER ICE, the rest in its spirit; GREY grey, MONO white; 4.5:1 on BG and SURF, 4:1 on RAISE checked), gfx.c T_K(c); JIANT's SURF the mock-up's near-black (10, 9, 14) and its RAISE 4 % (the 0.6 cards, #131218); its boxes rounded like the others (the black-SURF square case gone). JIANT's heat ramp the 0.6's (indigo violet red orange amber cream white). - Values and the header's BPM in a rounded sans again, as 0.6 (the mock-up's "Sans 0.6"): face M is Inter Tight SemiBold 15 px (assets/fonts, already credited), was Chakra Petch; labels, tabs, breadcrumb keep the 5 x 7 face. - The header (every skin, the mock-up's): the selected track's number in an ACCENT box, a THEME triangle playing, the BPM in M; HUD: no rule. The breadcrumb: the lens DIM, the level THEME, the set TEXT, the count TEXT. - COLORS: rounded tabs (THEME / RAISE), rounded RAISE cards with a 7 x 7 mark before the label where the label has one (CUT RES ATK REL WAVE DETUNE MIX NOISE STEP NOTE TYPE ACCENT SIZE DEPTH and kin), the label TEXT, the value and a 3 px rounded gauge in the knob's colour, the knob turned framed in it; the panel rounded. - BOTTOM: the tabs three words (the level's THEME with a pill), the panel the screen's width with no box (42..189; HOME's beings 240 x 148), the knobs a slim row over the breadcrumb (191..223: mark and label MID, the value in its colour, a hairline gauge); LINE draws its rules over and under the panel. - HUD: as BOTTOM; on HOME (ECO) the beings' water is the whole screen: every strip (header, tabs, the middle, the four cards 60 px each, the breadcrumb) is drawn each frame on the beings under it (ui_lzhome.c eco_draw / eco_backdrop: a being off the strip skipped; the numbers only in the middle), its words with a 1 px BG outline (gfx.c cv_halo), the level's word underlined; the knob row fades to 22 % 3 s after the last knob turn (ui.knob_ms) and is whole again at a turn. LOAD LITE / ECO pace the whole HUD frame as the panel's. - MENU > LARGE: COLORS' layout (the tall cards on top) in every skin, with the skin's tabs and colours. - Panels after the mock-up: EDIT > SOUND (the being larger, the scope a tile, the page's four parameters as chips in their knobs' colours, "2/2 CUT RES DRIVE" under them); FX > BUSES's tiles (lz_tile: COLORS rounded cards, the module framed THEME; BOTTOM / HUD bare, the module underlined); SEQ's bar cells and roll (BOTTOM / HUD: bare cells over a line, the beats only; the cursor framed TEXT); PUNCH's empty steps ticks; the dialogs (NOTICE, DICE) in the skin's tabs, cards and buttons; header messages in plain 5 x 7 words (the keycap gone). - CV_MAX 240 x 150 (HUD's middle). The new statics in the pool section, so the audio's data and code are where they were (target budgets identical to 0.8.8's). - Tests: ui_test SKIN (default, menu steps, saved / older / unknown, geometry, HUD's beings over the screen, the fade, every lens page in each skin); the menu, header, roll, editor and theme tests updated for SKIN, the box and Inter Tight; ui_render: every screen in BOTTOM and HUD (FLAT, LINE, LARGE, every palette) linted, their PNGs (JIANT PAPER GREY MONO), the draw cost per skin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
239 lines
14 KiB
Python
239 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
|
|
"""The UI palettes (run by tools/build.py generate()).
|
|
|
|
gen_ui_palettes.py OUT.h [--report]
|
|
|
|
A palette is five colours: BG (background), SURF (surface: dialogs, menu rows, mixer strips),
|
|
TEXT, THEME (identity colour: values, curves, gauges, selection) and ACCENT (the one active
|
|
thing: hot knob, cursor, playhead, a sounding step). The firmware derives the rest with fixed
|
|
blends at palette_set() time (src/gfx.c, the same integer maths as mix() here):
|
|
MID = mix(BG, TEXT, 70 %) labels, units, secondary text
|
|
DIM = mix(BG, TEXT, 42 %) inactive, empty steps, disabled
|
|
LINE = mix(BG, TEXT, 18 %) 1 px dividers, the faint gauge track
|
|
SEL = mix(BG, THEME, 80 %) selection fill and gauge fill (the "mid" of the theme)
|
|
TINT = mix(BG, THEME, 12 %) a faint area (the selected drum lane)
|
|
RAISE = mix(SURF, TEXT, 12 %) a raised area on a surface: empty step stubs, guides, the selected drum
|
|
lane, fader slots, button wells, chips
|
|
KEY = mix(BG, TEXT, 78 %) a keycap's fill (a mid-light cushion; its label INK, unavailable: a DIM fill)
|
|
INK = BG: text on a selection or THEME fill (GREY, MONO: a light fill, dark ink)
|
|
Outside the palette: REC, a fixed red (GREY, MONO: ACCENT); the QR code's fixed black and white; the crash
|
|
screen's fixed red. GREY is pure grayscale (R = G = B) in every colour and every derived tint.
|
|
MONO is black and white: its tokens are not blended but set (src/gfx.c palette_set, bw() here): BG SURF
|
|
TINT GRID black; TEXT THEME ACCENT MID SEL KEY white (a selection, a THEME or ACCENT fill, a keycap: white
|
|
with black INK, an inversion); and one mid grey, BW_GREY, for DIM LINE RAISE LANE. That grey is the one
|
|
exception: RAISE is the fill under white text on chips, idle cells and button wells and the track of
|
|
empty steps, slots and gauges, and DIM marks the inactive and the unavailable; black would hide them,
|
|
white would hide the text on them or make the inactive read as active. Only antialiased edges add greys.
|
|
Saved settings name palettes by a tagged id (PAL_TAG + index); older firmware saved the index into
|
|
its 20 palettes, mapped by UI_PALETTE_MIGRATE.
|
|
--report prints the WCAG contrast of every pairing. The tool fails (exit 1) on any miss.
|
|
"""
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# name, bg, surf, text, theme, accent (8-bit RGB; stored as RGB565)
|
|
PALETTES = [
|
|
("GREY", (14, 14, 14), (36, 36, 36), (204, 204, 204), (232, 232, 232), (255, 255, 255)),
|
|
("GREEN", (6, 18, 10), (16, 40, 26), (226, 244, 230), (84, 214, 120), (255, 214, 92)),
|
|
("AMBER", (18, 14, 8), (42, 32, 18), (246, 236, 216), (255, 168, 40), (96, 214, 230)),
|
|
("ICE", (8, 16, 24), (20, 36, 52), (228, 240, 248), (80, 184, 236), (255, 140, 100)),
|
|
("VIOLET", (16, 12, 28), (36, 28, 60), (240, 232, 252), (178, 136, 246), (110, 228, 168)),
|
|
("ROSE", (24, 10, 18), (52, 22, 40), (252, 232, 242), (244, 114, 182), (255, 214, 110)),
|
|
("PAPER", (244, 239, 228), (226, 218, 202), (34, 30, 24), (10, 84, 70), (172, 56, 8)),
|
|
("HI-CON", (0, 0, 0), (40, 40, 40), (255, 255, 255), (255, 232, 0), (0, 230, 255)),
|
|
# appended (saved ids are indices: append only). #50, the 0.9 look: true black, green-tinted text and lines
|
|
# (the derived MID / DIM / LINE are tints of TEXT), phosphor-green values, white for the one active thing
|
|
("NIGHT", (0, 0, 0), (0, 24, 10), (150, 230, 170), (56, 220, 100), (255, 255, 255)),
|
|
# 1.0.2: black and white (the derived tokens are set, not blended: bw()); the old MONO is GREY (id 0)
|
|
("MONO", (0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255)),
|
|
# JIANT FM (docs/TONIC-UI.md): a thermal camera. Black, white details, violet for what is selected, orange for the
|
|
# one active thing; every value, curve and hit as heat (ui_graph.c heat_col: cyan blue violet red orange yellow
|
|
# white). The default since JIANT 0.1 (src/panel.c); 0.5: violet selection (was cyan), the heat everywhere
|
|
("JIANT", (0, 0, 0), (10, 9, 14), (244, 241, 234), (184, 112, 255), (255, 122, 0)), # (0.6.60: SURF black, no boxes;
|
|
# 0.8.9, the skins' mock-up: the 0.6 colours, a near-black panel and near-black cards: RAISE_OF below)
|
|
]
|
|
# (0.8.9) MENU > DISPLAY > SKIN (the approved mock-up opciones_skin.html, "0.6 COLORS"): each knob its colour, as the 0.6
|
|
# firmware had them, on its card's value and gauge (and the EDIT chips, the knob row of BOTTOM and HUD): KNOB 1..4. The
|
|
# mock-up's for JIANT PAPER GREEN AMBER ICE; the others in the same spirit (GREY: greys; MONO: white, black and white)
|
|
KNOBS = {
|
|
"GREY": [(232, 232, 232), (196, 196, 196), (255, 255, 255), (168, 168, 168)],
|
|
"GREEN": [(70, 224, 122), (255, 210, 92), (47, 196, 176), (198, 255, 106)],
|
|
"AMBER": [(255, 176, 0), (255, 128, 80), (255, 217, 138), (255, 138, 61)],
|
|
"ICE": [(79, 210, 255), (255, 179, 92), (150, 164, 255), (255, 128, 128)],
|
|
"VIOLET": [(192, 156, 250), (255, 214, 110), (110, 228, 168), (250, 136, 196)],
|
|
"ROSE": [(244, 114, 182), (255, 214, 110), (150, 170, 255), (255, 150, 120)],
|
|
"PAPER": [(80, 52, 190), (112, 74, 0), (30, 58, 178), (164, 38, 22)],
|
|
"HI-CON": [(255, 232, 0), (0, 230, 255), (255, 255, 255), (255, 130, 130)],
|
|
"NIGHT": [(56, 220, 100), (200, 255, 120), (120, 240, 210), (150, 230, 170)],
|
|
"MONO": [(255, 255, 255)] * 4,
|
|
"JIANT": [(138, 108, 255), (255, 210, 60), (88, 116, 255), (255, 75, 75)],
|
|
}
|
|
# RAISE = mix(SURF, TEXT, RAISE_PCT); JIANT (0.8.9): the mock-up's near-black card (#131218) on its panel, 4 %
|
|
RAISE_OF = {"JIANT": 4}
|
|
BW = "MONO"
|
|
BW_GREY = (82, 82, 82) # MONO's one mid grey (RGB565 10/20/10): DIM LINE RAISE LANE
|
|
# the 20 palettes of the earlier firmware (index order) -> the new palette
|
|
OLD = ["GREEN", "AMBER", "CYAN", "RED", "MONO", "VIOLET", "PINK", "ICE", "WARM", "OCEAN", "DUSK", "HI-CON",
|
|
"LIGHT", "PAPER", "SKY", "MINT", "LILAC", "ROSE", "SAND", "L-HICON"]
|
|
OLD_TO_NEW = {"GREEN": "GREEN", "AMBER": "AMBER", "CYAN": "ICE", "RED": "ROSE", "MONO": "GREY", "VIOLET": "VIOLET",
|
|
"PINK": "ROSE", "ICE": "ICE", "WARM": "AMBER", "OCEAN": "ICE", "DUSK": "VIOLET", "HI-CON": "HI-CON",
|
|
"LIGHT": "PAPER", "PAPER": "PAPER", "SKY": "PAPER", "MINT": "PAPER", "LILAC": "PAPER", "ROSE": "PAPER",
|
|
"SAND": "PAPER", "L-HICON": "HI-CON"}
|
|
PAL_TAG = 64 # stored id = PAL_TAG + index; below 20: an old id
|
|
REC_DARK, REC_LIGHT = (255, 72, 72), (190, 24, 40)
|
|
QR_LIGHT, QR_DARK, CRASH_BG, CRASH_INK = (255, 255, 255), (0, 0, 0), (160, 0, 0), (255, 255, 255)
|
|
PCT = {"MID": 70, "DIM": 42, "LINE": 18, "SEL": 80, "TINT": 12, "KEY": 78}
|
|
RAISE_PCT = 12 # SURF -> TEXT
|
|
|
|
|
|
def to565(c, exact=False):
|
|
r, g, b = c
|
|
if r == g == b and not exact: # a gray stays on the RGB565 gray axis (G = 2 R)
|
|
return ((r >> 3) << 11) | ((r >> 3) << 6) | (r >> 3)
|
|
return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
|
|
|
|
|
|
def from565(v):
|
|
return ((v >> 11) * 255 // 31, ((v >> 5) & 63) * 255 // 63, (v & 31) * 255 // 31)
|
|
|
|
|
|
def cdiv(a, b):
|
|
return a // b if a >= 0 else -((-a) // b)
|
|
|
|
|
|
def mix(a, b, pct, mono=False):
|
|
"""src/gfx.c ux_mix: a + (b - a) * pct / 100 per channel, rounded; GREY, MONO on the 5-bit red channel"""
|
|
if mono:
|
|
x, y = a >> 11, b >> 11
|
|
d = (y - x) * pct
|
|
v = x + cdiv(d + (50 if d >= 0 else -50), 100)
|
|
return (v << 11) | (v << 6) | v
|
|
out = 0
|
|
for sh, mask in ((11, 31), (5, 63), (0, 31)):
|
|
x, y = (a >> sh) & mask, (b >> sh) & mask
|
|
d = (y - x) * pct
|
|
out |= (x + cdiv(d + (50 if d >= 0 else -50), 100)) << sh
|
|
return out
|
|
|
|
|
|
def luma(c):
|
|
"""src/gfx.c ux_luma: 0..255, integer"""
|
|
r, g, b = c >> 11, (c >> 5) & 63, c & 31
|
|
return (r * 255 // 31 * 54 + g * 255 // 63 * 183 + b * 255 // 31 * 19) >> 8
|
|
|
|
|
|
def lum(c565):
|
|
def lin(v):
|
|
v /= 255.0
|
|
return v / 12.92 if v <= 0.04045 else ((v + 0.055) / 1.055) ** 2.4
|
|
r, g, b = from565(c565)
|
|
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b)
|
|
|
|
|
|
def contrast(a, b):
|
|
la, lb = lum(a), lum(b)
|
|
return (max(la, lb) + 0.05) / (min(la, lb) + 0.05)
|
|
|
|
|
|
def derive(p):
|
|
name, *cols = p
|
|
bg, surf, text, theme, accent = (to565(c, name == BW) for c in cols)
|
|
mono = name == "GREY"
|
|
d = dict(bg=bg, surf=surf, text=text, theme=theme, accent=accent,
|
|
mid=mix(bg, text, PCT["MID"], mono), dim=mix(bg, text, PCT["DIM"], mono),
|
|
line=mix(bg, text, PCT["LINE"], mono), sel=mix(bg, theme, PCT["SEL"], mono),
|
|
tint=mix(bg, theme, PCT["TINT"], mono), raise_=mix(surf, text, RAISE_OF.get(name, RAISE_PCT), mono),
|
|
key=mix(bg, text, PCT["KEY"], mono))
|
|
d["ink"] = bg
|
|
d["light"] = luma(bg) > 128
|
|
d["rec"] = accent if mono or name == BW else to565(REC_LIGHT if d["light"] else REC_DARK)
|
|
for i, k in enumerate(KNOBS[name]):
|
|
d[f"k{i}"] = to565(k, name == BW)
|
|
if name == BW: # src/gfx.c palette_set: set, not blended
|
|
grey = to565(BW_GREY)
|
|
d.update(mid=text, sel=theme, key=text, dim=grey, line=grey, raise_=grey, lane=grey, tint=bg, grid=bg)
|
|
return name, d
|
|
|
|
|
|
# (foreground, background, minimum contrast, why)
|
|
CHECKS = [("text", "bg", 12.0, "body text"), ("text", "surf", 9.0, "body text on a surface"),
|
|
("mid", "bg", 5.0, "labels"), ("mid", "surf", 4.0, "labels on a surface"),
|
|
("dim", "bg", 2.2, "inactive (not read)"), ("line", "bg", 1.25, "1 px dividers"),
|
|
("theme", "bg", 4.5, "values, curves"), ("theme", "surf", 4.5, "values on a surface"),
|
|
("accent", "bg", 4.5, "hot value, cursor, playhead"), ("accent", "surf", 4.5, "hot on a surface"),
|
|
("ink", "sel", 4.5, "text on a selection"), ("ink", "theme", 4.5, "text on a THEME fill"),
|
|
("sel", "bg", 1.8, "gauge fill vs track"), ("rec", "bg", 3.0, "REC (graphic)"),
|
|
("text", "raise_", 7.0, "text on a RAISE chip or button"), ("ink", "rec", 4.5, "text on the REC chip"),
|
|
("ink", "key", 4.5, "a keycap's label"), ("key", "bg", 3.0, "a keycap on the background"),
|
|
("key", "surf", 2.5, "a keycap on a surface"), ("ink", "dim", 1.8, "an unavailable keycap's label"),
|
|
("ink", "accent", 4.5, "text on the ARM badge")] + \
|
|
[(f"k{i}", b, 4.5 if b != "raise_" else 4.0, f"KNOB {i + 1}'s value") for i in range(4) for b in ("bg", "surf", "raise_")]
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
ap.add_argument("out", nargs="?")
|
|
ap.add_argument("--report", action="store_true")
|
|
a = ap.parse_args()
|
|
fails = []
|
|
assert PALETTES[0][0] == "GREY" and len(OLD) == 20 and len(PALETTES) <= 63
|
|
rows = [derive(p) for p in PALETTES]
|
|
for name, d in rows:
|
|
if name == "GREY":
|
|
for k, v in d.items():
|
|
if k == "light":
|
|
continue
|
|
if not (v >> 11 == v & 31 and ((v >> 5) & 63) == (v >> 11) << 1):
|
|
fails.append(f"{name} is not grayscale: {k} = {v:#06x}")
|
|
if name == BW: # every token pure black or white, or the one grey (DIM LINE RAISE LANE)
|
|
for k, v in d.items():
|
|
if k != "light" and v not in (0x0000, 0xFFFF) and not (v == to565(BW_GREY) and k in ("dim", "line", "raise_", "lane")):
|
|
fails.append(f"{name} is not black and white: {k} = {v:#06x}")
|
|
for f, b, lim, why in CHECKS:
|
|
c = contrast(d[f], d[b])
|
|
if c < lim:
|
|
fails.append(f"{name}: {f}/{b} {c:.2f} < {lim} ({why})")
|
|
if a.report:
|
|
print(f"{'palette':8s} " + " ".join(f"{f}/{b}".ljust(12) for f, b, _, _ in CHECKS))
|
|
for name, d in rows:
|
|
print(f"{name:8s} " + " ".join(f"{contrast(d[f], d[b]):5.1f}".ljust(12) for f, b, _, _ in CHECKS))
|
|
print("minimum " + " ".join(f"{lim:<12.2f}" for _, _, lim, _ in CHECKS))
|
|
if a.out:
|
|
names = [p[0] for p in PALETTES]
|
|
assert set(KNOBS) == {p[0] for p in PALETTES}
|
|
out = ["/* generated by tools/gen_ui_palettes.py: the UI palettes (5 colours each, the rest derived) */",
|
|
"#pragma once", "#include <stdint.h>", "",
|
|
"/* ui_pal_t {name, bg, surf, text, theme, accent} (src/gfx.c) */",
|
|
"static const ui_pal_t UI_PALETTES[] = {"]
|
|
for p in PALETTES:
|
|
v = [to565(c, p[0] == BW) for c in p[1:]]
|
|
out.append(f' {{"{p[0]}", ' + ", ".join(f"0x{x:04x}" for x in v) + "},")
|
|
out += ["};", "/* (0.8.9) KNOB 1..4's colours (MENU > DISPLAY > SKIN, the 0.6 colours) */",
|
|
"static const uint16_t UI_KNOBS[][4] = {"]
|
|
out += [f' {{' + ", ".join(f"0x{to565(c, p[0] == BW):04x}" for c in KNOBS[p[0]]) + f'}}, /* {p[0]} */' for p in PALETTES]
|
|
out += ["};", "static const uint8_t UI_RAISE_OF[] = {" + ", ".join(str(RAISE_OF.get(p[0], RAISE_PCT)) for p in PALETTES) + "};",
|
|
f"#define UI_NPALETTES {len(PALETTES)}u", "#define UI_GREY_INDEX 0u",
|
|
f"#define UI_BW_INDEX {names.index(BW)}u /* MONO: black and white (src/gfx.c palette_set) */",
|
|
f"#define UI_JIANT_INDEX {names.index('JIANT')}u /* JIANT FM: the default (src/panel.c) */",
|
|
f"#define UI_BW_GREY 0x{to565(BW_GREY):04x}u /* MONO's one grey: DIM LINE RAISE LANE */",
|
|
f"#define UI_PAL_TAG {PAL_TAG}u /* stored id = UI_PAL_TAG + index; below 20: an old id */"]
|
|
out += [f"#define UI_{k}_PCT {v}" for k, v in PCT.items()] + [f"#define UI_RAISE_PCT {RAISE_PCT} /* SURF -> TEXT */"]
|
|
out += [f"#define UI_REC_DARK 0x{to565(REC_DARK):04x}u", f"#define UI_REC_LIGHT 0x{to565(REC_LIGHT):04x}u",
|
|
f"#define UI_QR_LIGHT 0x{to565(QR_LIGHT):04x}u", f"#define UI_QR_DARK 0x{to565(QR_DARK):04x}u",
|
|
f"#define UI_CRASH_BG 0x{to565(CRASH_BG):04x}u", f"#define UI_CRASH_INK 0x{to565(CRASH_INK):04x}u", "",
|
|
"/* the 20 palettes of earlier firmware: " + " ".join(OLD) + " */",
|
|
"static const uint8_t UI_PALETTE_MIGRATE[20] = {" +
|
|
", ".join(str(names.index(OLD_TO_NEW[n])) for n in OLD) + "};", ""]
|
|
Path(a.out).write_text("\n".join(out))
|
|
for f in fails:
|
|
print("FAIL", f)
|
|
if fails:
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|