Files
skiff/tools/gen_sprites.py
T
illuminus5 32828c4aa5 Skiff 2.0: NOTES and FEEL, chains, sounds on song entries, drum lanes panned, your own drum kits
- The step pages, four become two: NOTES (the piano roll, a selection edited as one, notes that overlap with lengths
  of their own, copy, paste and delete) and FEEL (chance and conditions, ratchets, nudge, accent and slide).
- SONG: chains (entries on CHAIN played and edited as one long pattern), NEW, COPY+, copies numbered beside their
  originals, SONG ONCE, the pool's EMPTY and UNUSED, and a sound on any entry, loaded as the track comes onto it.
- DRUM and DRUM-X: LANE MIX, each lane's level and pan. DRUM's KIT on to USR1-3: a sample slot as the kit, built in
  the web editor's Samples tab, a WAV a lane.
- One mute in the GLO, FX and PERFORM layers, one RETURN, one MOD page, DIST through INSERT's shapers.
- A user sound stays the track's over a save, a load and power-on; RESTORE LAST writes 2 s after the last change.
- New save formats (projects, settings, user presets, parameters by stored id) with a converter in the installer and
  the editor's Restore (Felucca 1.2+ projects and presets too); about 30 KB freed on the FM-1; release builds without
  the serial console.
- The SMK-37 Pro: the sustain pedal holds the keys; its loaders start the flash at the app's speed.
- Fixes: REC on an armed track disarms every track, RANDOM on a lengthened line, PD BRASS's clicks (#41), settings
  from Felucca 1.4+ or JIANT.
2026-10-24 18:56:17 -05:00

85 lines
5.0 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""(Skiff 2.0) The themes' sprites (CRYPT's, NEON's, FM6 LAB's flame), packed for src/ui_crypt.c ui_sprite (run by
tools/build.py generate()). Each is drawn here as rows of characters; a character of its keys is a pixel of that
colour (the caller's cols[], in the keys' order), a space nothing. In the header each is
SPR_x[] = {w, h, bits, the pixels ...}
bits a pixel (1, 2 or 3: as few as its keys need), the key's number (1..) or 0, MSB first, rows back to back, a byte
spare at the end (ui_sprite reads two at a time).
gen_sprites.py OUT.h"""
import sys
from pathlib import Path
# name: (keys, rows): where it is drawn
SPRITES = {
# ui_crypt.c: cr_skull (a peak, a mute's crossed eyes), the splash's and LFO DEST's big ones (cr_spritez)
"SKULL": ("#.", [" ##### ", " ####### ", "#########", "#..###..#", "#..###..#", "####.####", " ####### ",
" #.#.# ", " ##### "]),
"SKULL_X": ("#.", [" ##### ", " ####### ", "#########", "#.#####.#", "##.###.##", "####.####", " ####### ",
" #.#.# ", " ##### "]),
# cr_torch: the flame's two frames (gold, flame, amber, ember), its head and stick (dim)
"TORCH0": ("YFORB", [" Y ", " YYY ", " YFY ", "YFFFY", "YORFY", " ORO ", " BBB ", " B ", " B ", " BBB ",
" B ", " B "]),
"TORCH1": ("YFORB", [" Y ", " YY ", " YYY ", "YFFFY", "YOFRY", " ORO ", " BBB ", " B ", " B ", " BBB ",
" B ", " B "]),
"SWORD": ("#", [" # ", " ### ## ", "######## ", " ### ## ", " # "]), # cr_sword's hilt
"FLAME": ("#.", [" ## ", " #..# ", " #..# ", "#....#", "#....#", " #### "]), # cr_meter's flame
"DROP": ("#", [" # ", " ### ", " ### ", " ##### ", "#######", "#######", "#######", " ##### ",
" ### "]), # cr_drop: REC, armed
"DROP_O": ("#", [" # ", " # # ", " # # ", " # # ", "# #", "# #", "# #", " # # ",
" ### "]), # .. another track armed
"HEAD": ("#.", [" #### ", " ###### ", "########", "##.#####", "########", " ###### "]), # cr_head: the snake's
"DAGGER": ("#", [" # ", " # ", "#####", " # ", " # ", " # ", " # "]), # cr_dagger: FLT's cutoff
# ui_neon.c: the car (body, glass, tail light, headlight, wheels; ne_car finds the tail light's row), NE_CAR 18 x 6
# (the splash), CAR24 24 x 8 (HOME)
"CAR": ("#.THO", [" ###### ", " ##.. ...## ", " ############## ", "T################H",
" ###OO######OO### ", " OO OO "]),
"CAR24": ("#.THO", [" ####### ", " ###.. ....## ", " ################# ",
" ######################", "T######################H", " #####OO########OO##### ",
" OOOO OOOO ", " OO OO "]),
"PALM": ("#", [" ## ## ", " ########## ", " #### ## #### ", " ## #### ## ",
"## ## # ## ##", "# ## # ## #", " ## # ## ", " # # # ",
" ## ", " ## ", " ## ", " ## ",
" ## ", " ## ", " ## ", " ## ",
" ## ", " #### "]),
"SPARK": ("#W", [" # ", " # ", " #W# ", "##WWW##", " #W# ", " # ", " # "]), # ne_spark
# ui_fm6.c: FM6 LAB's flame under the carrier that bites most (CRYPT)
"FM_FLAME": ("#.", [" # ", " ## ", " #.# ", "##.##", "#...#", " ### "]),
}
def pack(keys, rows):
w, h = len(rows[0]), len(rows)
assert all(len(r) == w for r in rows) and w < 256 and h < 256
bits = max(1, (len(keys)).bit_length())
acc = n = 0
out = bytearray([w, h, bits])
for r in rows:
for ch in r:
assert ch == " " or ch in keys, ch
acc = acc << bits | (keys.index(ch) + 1 if ch != " " else 0)
n += bits
while n >= 8:
out.append(acc >> (n - 8) & 255)
n -= 8
if n:
out.append(acc << (8 - n) & 255)
out.append(0) # (the spare byte)
return out
def main():
lines = ["/* generated by tools/gen_sprites.py: the themes' sprites (src/ui_crypt.c ui_sprite) */", "#pragma once", ""]
total = 0
for name, (keys, rows) in SPRITES.items():
b = pack(keys, rows)
total += len(b)
lines.append(f"static const uint8_t SPR_{name}[{len(b)}] = {{" + ", ".join(str(v) for v in b) + "}; /* "
f"{len(rows[0])} x {len(rows)}, keys {keys} */")
Path(sys.argv[1]).write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n")
print(f"sprites: {len(SPRITES)}, {total} bytes")
if __name__ == "__main__":
main()