Files
JIANT/tests/clay_test.c
Claude 8b042c54e7 V10.8.80: FX > EQ's four bands drawn again
The EQ page shows the LOW, LO MID, HI MID and HIGH bars again (60, 250,
2K, 8K), drawn by SL PITCH's bar graph so it costs no new flash. To make
room, the V10.8.21-26 Clay conversion ('C' 'Y' blocks) is gone: those
projects load with Clay off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-12-04 15:05:01 +00:00

232 lines
11 KiB
C

// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant). All rights reserved.
/* (V10.8.21) DRONE CLAY (seq.c clay.c, JIANT BYTE's): the drone on and off, RATE's strikes, a modulator moving its
* destination through mod_begin, the 'C' 'L' block saved and loaded, an older project loading with it off.
* (V10.8.27) BYTE's fix: RATE on the bar's grid (0 HOLD, 3 1/16), each modulator its own RATE, clay_vk what it adds;
* tests/clay_engines_test.c every engine.
* cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src -Itests tests/clay_test.c -lm */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
static void blocks(uint32_t n)
{
int32_t o[2 * CTL];
uint32_t i;
for (i = 0; i < n; i++) {
mix_block(o, CTL);
if (!(i & 15u)) { host_ticks += 16000u; fm1_ms += 16u; ui_input(); song_poll(); }
}
}
static int voice_on(const track_t *t, uint32_t note)
{
uint32_t k;
for (k = 0; k < NVOICE; k++)
if (t->v[k].active && t->v[k].gate && t->v[k].note == note) return 1;
return 0;
}
int main(void)
{
int bad = 0, ok;
const uint32_t tr = 1;
track_t *t = &trk[tr];
uint32_t dn, k, strikes = 0, last;
ui_power_on();
ok = !clay[tr][CL_ON] && !clay_dn[tr];
bad += check("clay: off at power-on, no drone", ok);
clay_defaults(clay[tr]);
clay[tr][CL_ON] = 1; clay[tr][CL_RUN] = 1; clay[tr][CL_RATE] = 0; /* FREE: runs stopped; HOLD */
blocks(200);
dn = 12u * (uint32_t)(clay[tr][CL_OCT] + 1) + (uint32_t)clamp(t->p[P_ROOT], 0, 11);
ok = clay_dn[tr] == dn && voice_on(t, dn);
bad += check("clay ON (FREE): the drone sounds on the track's voice, C(OCT+1) on the ROOT", ok);
{ /* (V10.8.30, the owner) every modulator's AMOUNT 0 (their EUCLIDs on, a HIT on MOD 1), RATE HOLD: the drone held
* clean, one note-on for bars, no strikes, no dips in its level */
uint32_t m, att = 0, was = 1, lit = 0, gap = 0, b2;
for (m = 0; m < 4u; m++) clay[tr][CL_MF(m, 3u)] = 0;
clay_tick(1);
for (b2 = 0; b2 < 6000u; b2++) { /* (a few bars at 120) */
int32_t o[2 * CTL];
uint32_t i, st = 0;
mix_block(o, CTL);
for (i = 0; i < NVOICE; i++)
if (t->v[i].active && t->v[i].note == clay_dn[tr]) st = t->v[i].stage;
att += st == 1u && was != 1u;
was = st;
lit |= form_lit[tr];
gap += !voice_on(t, clay_dn[tr]);
}
ok = !att && !lit && !gap && !form_st[tr].hb.on;
if (!ok) printf(" (re-attacks %u, lit %u, blocks without it %u)\n", att, lit, gap);
bad += check("clay AMOUNT 0 everywhere, RATE HOLD: the drone held clean (one note-on, no strike, no duck)", ok);
clay_defaults(clay[tr]); clay[tr][CL_ON] = 1; clay[tr][CL_RUN] = 1; clay[tr][CL_RATE] = 0;
}
{ /* (V10.8.79, the owner: "según el mod que esté seleccionado, las teclas graban en rec las notas y el modificador
* en su línea") KEYS ON: a key plays its note and strikes the pages' MOD (its SHAPE); KEYS OFF: its note alone */
uint32_t i, live = 0;
clay_km[tr] = 1; song.octave = 0; /* MOD 2 */
clay[tr][CL_MF(1u, 1u)] = 0; /* its SHAPE: the first, KICK (the HITS first) */
for (i = 0; i < FORM_G; i++) form_st[tr].g[i].fl = 0;
key_on(0u, t);
for (i = 0; i < FORM_G; i++) live |= (form_st[tr].g[i].fl & 8u) && form_st[tr].g[i].mod == 1u;
ok = live && kb_on[0] && (form_lit[tr] & 2u);
ui_input();
ok &= (clay_key_event & 1023u) == 256u;
key_off(0u, t);
ok &= !proj_any(clay[tr] + CL_LN, 16u); /* (not recording: no line) */
bad += check("clay KEYS ON: a key plays its note and strikes the pages' MOD (its SHAPE), no line unrecorded", ok);
clay[tr][CL_RUN] = 3; /* FREE, KEYS OFF */
for (i = 0; i < FORM_G; i++) form_st[tr].g[i].fl = 0;
form_lit[tr] = 0;
key_on(0u, t);
ok = kb_on[0] != 0 && !(form_lit[tr] & 2u);
key_off(0u, t);
clay[tr][CL_RUN] = 1;
bad += check("clay KEYS OFF: the key plays its note, no strike", ok);
}
clay[tr][CL_ON] = 0;
blocks(40);
ok = !clay_dn[tr] && !clay_nn[tr] && !clay_vk(tr, 0) && !clay_vk(tr, 1) && !clay_vk(tr, 2) && !clay_vk(tr, 3);
bad += check("clay OFF: the drone and its gestures end, the modulators at 0", ok);
clay[tr][CL_ON] = 1; clay[tr][CL_RATE] = 3; /* 1/16: struck again each sixteenth */
last = clay_lr[tr];
for (k = 0; k < 400u; k++) { blocks(4); if (clay_lr[tr] != last) { strikes++; last = clay_lr[tr]; } }
bad += check("clay RATE 1/16: the drone struck again and again", strikes >= 8u);
{ /* (BYTE's ff242c4) one voice (MONO): a key's note takes it, the drone back after */
uint32_t n0;
clay[tr][CL_RATE] = 0;
t->p[P_VOICE] = V_MONO;
blocks(40);
n0 = clay_dn[tr];
seq_note_on(t, 72u, 100u);
blocks(40);
ok = n0 && !clay_dn[tr] && voice_on(t, 72u);
seq_note_off(t, 72u);
blocks(40);
ok &= clay_dn[tr] == n0;
t->p[P_VOICE] = V_POLY; clay[tr][CL_RATE] = 3;
bad += check("clay on MONO: a key's note takes the voice, the drone back after it", ok);
}
{ /* a modulator on DIST (CLAY_MD 6): mod_begin moves the track's parameter by what it adds, mod_end puts it back */
uint32_t id = mod_param(MD_DIST), moved = 0;
int16_t keep;
for (k = 0; k < 4u; k++) { clay[tr][CL_MF(k, 0u)] = 0; clay[tr][CL_MF(k, 3u)] = 0; }
clay[tr][CL_MF(0u, 0u)] = 6; clay[tr][CL_MF(0u, 3u)] = 127; clay[tr][CL_MF(0u, 2u)] = 2; clay[tr][CL_MF(0u, 5u)] = 2; /* 1/16 */
t->p[id] = 64;
keep = t->p[id];
for (k = 0; k < 600u && !moved; k++) {
blocks(2);
if (clay_vk(tr, 0)) {
macro_master();
if (mod_begin(t)) { moved = t->p[id] != keep; mod_end(t); }
}
}
ok = moved && t->p[id] == keep;
bad += check("clay MOD 1 on DIST: mod_begin moves it, mod_end restores the stored value", ok);
}
{ /* (V10.8.79) a MOD's line: set, it strikes on its steps alone (its EUCLID none), saved and loaded with the project
* ('C' 'K'), EUCLID turned: gone */
static project_t q, r;
static project_store_t st;
uint32_t m = 2u, hits = 0, others = 0, s0, j;
for (k = 0; k < 4u; k++) clay[tr][CL_MF(k, 3u)] = 0;
clay[tr][CL_MF(m, 3u)] = 100; clay[tr][CL_MF(m, 2u)] = 0; clay[tr][CL_MF(m, 5u)] = 2; /* AMOUNT, EUCLID off, 1/16 */
clay[tr][CL_LN + 4u * m] = 0x11; /* steps 0 and 4 of 32 */
for (j = 0; j < 3000u; j++) {
s0 = (uint32_t)form_st[tr].lastm[m];
form_lit[tr] = 0;
blocks(1);
if ((uint32_t)form_st[tr].lastm[m] != s0) {
if (form_lit[tr] & (1u << m)) { hits++; others += ((uint32_t)form_st[tr].lastm[m] & 31u) % 4u != 0u; }
}
}
ok = hits >= 2u && !others;
if (!ok) printf(" (hits %u, off the line %u)\n", hits, others);
bad += check("clay MOD 3's line (steps 1 and 5): it strikes there alone, its EUCLID none", ok);
project_capture(&q);
ok = proj_pack(&st, &q);
memset(&r, 0, sizeof r);
ok &= proj_unpack_c(&r, st.raw) != 0 && r.cln[tr][4u * m] == 0x11 && !proj_any(r.cln[tr ^ 1u], 16u);
clay_put(tr, CL_MF(m, 2u), 0, 3);
ok &= !clay[tr][CL_LN + 4u * m];
bad += check("clay's line saved and loaded ('C' 'K'); EUCLID turned: the line gone", ok);
clay[tr][CL_MF(m, 2u)] = 0;
}
{ /* (V10.8.79) recording: a key struck while REC plays sets the MOD's line at its step now */
uint32_t m = 0u, s;
clay_km[tr] = (int16_t)m;
memset(clay[tr] + CL_LN, 0, 16u);
transport_req = 1;
blocks(64);
song.rec |= 1u << tr;
s = (uint32_t)form_st[tr].lastm[m] & 31u;
key_on(3u, t); key_off(3u, t);
ok = (clay[tr][CL_LN + 4u * m + s / 8u] >> (s & 7u) & 1) != 0;
song.rec &= ~(1u << tr);
transport_req = 2;
blocks(16);
memset(clay[tr] + CL_LN, 0, 16u);
bad += check("clay REC: a key sets its MOD's line at the step now", ok);
}
{ /* saved and loaded: the 'C' 'L' block, the track's 30 settings back (PITCH biased) */
static project_t q, r;
static project_store_t st;
clay[tr][CL_PIT] = -7; clay[tr][CL_MF(2u, 5u)] = 17;
project_capture(&q);
ok = proj_pack(&st, &q);
memset(&r, 0, sizeof r);
ok &= proj_unpack_c(&r, st.raw) != 0;
ok &= !memcmp(r.clay[tr], q.clay[tr], CLAY_NF);
{
clay_t back[CLAY_NF];
clay_unpack(r.clay[tr], back);
ok &= back[CL_PIT] == -7 && back[CL_MF(2u, 5u)] == 17 && back[CL_ON] == 1;
}
for (k = 0; k < NTRK; k++) ok &= k == tr || !r.clay[k][CL_ON];
bad += check("clay saved and loaded: its 30 settings back (PITCH -7, MOD 3's RATE), the other tracks off", ok);
clay[tr][CL_ON] = 0;
blocks(20);
project_capture(&q); /* no track ON: no 'C' 'Y' block, as an older project */
ok = proj_pack(&st, &q);
memset(&r, 0xFF, sizeof r.clay);
ok &= proj_unpack_c(&r, st.raw) != 0;
for (k = 0; k < NTRK; k++) ok &= !r.clay[k][CL_ON];
bad += check("a project without the block (older): DRONE CLAY off on every track", ok);
}
{
static project_t q, r;
static project_store_t saved;
song.sel = tr;
track_defaults_steps(t);
clay_defaults(clay[tr]);
clay[tr][CL_RUN] = 1;
blocks(32);
key_on(0u, t);
rec_clear();
blocks(128);
ok = !clay_on(tr) && !clay_dn[tr] && !clay_nn[tr] && !form_lit[tr];
for (k = 0; k < FORM_G; k++) ok &= !form_st[tr].g[k].fl;
project_capture(&q);
ok &= proj_pack(&saved, &q) && proj_unpack_c(&r, saved.raw);
clay_unpack(r.clay[tr], clay[tr]);
clay_put(tr, CL_ON, 0, 1);
for (k = 0; k < 4u; k++)
ok &= !clay[tr][CL_MF(k, 2)] && !clay[tr][CL_MF(k, 3)] && !clay_vk(tr, k);
bad += check("CLEAR on a Clay-only track: no gestures or patterns after reload and re-enable", ok);
}
{
t->p[P_QUANT] = QN_WHITE;
clay[tr][CL_ON] = 1;
clay[tr][CL_RUN] = 0;
bad += check("Clay KEYS ON in QUANT WHITE: a black key plays its own note", kb_map(t, 20u) != KB_SILENT);
clay[tr][CL_RUN] = 2;
bad += check("QUANT WHITE keeps its normal behavior with Clay keys off", kb_map(t, 20u) == KB_SILENT);
}
printf(bad ? "clay: %d FAILED\n" : "clay: all passed\n", bad);
return bad != 0;
}