mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 12:54:29 +01:00
The owner: "que las fórmulas no cambien su time con las notas ... por defecto debería
estar así". MATH's t is already two clocks (MOTION's): the note's low 8 bits (the wave,
its pitch) and the slow bits above (the rhythm, the phrase). TIME picks the slow clock's
pace:
- KEY the note's (as before: a key up, the formula faster). Every project and user
preset of before reads KEY (its slot held 0), so they sound as they did.
- LOCK C4's whatever the key: every key the same rhythm, transposed. At C4 KEY and LOCK
are the same, bit for bit (the MOTION 64 shortcut kept where the paces are one).
A factory preset load (ui.c apply_preset_to) sets it: the new default.
- TEMPO the song's clock (MOTION's own SYNC, 128 .. 255: t >> 13 a beat at MOTION 64),
BYTE and FLOAT. WAVE SYNC (V10.8.62) stays as it was.
RESTART (KNOB 1) unchanged, combinable with any.
Where: core.h P_MTIME, in DRUM's IMAGE / VOICE's LYRIC slot (DIGITAL's OP3 REL: 0 on
every MATH track before it; a user preset and a project store it as any slot). MORE's
KNOB 2 (params.c PAGES, track_desc). lofi_render decides the slow clock once a block and
hands the renders its step in m->inc (0: the song's clock), so lofi_byte_render and
lofi_float_render each lose their own MOTION / WAVE SYNC tests (-4 B each).
Flash: TIME +108 B (code +76: lofi_render +68, apply_preset_to +12, track_desc +4, renders -8;
the descriptor and its names ~32), room 56 B: N_CHIP N_RWAVE N_MTIME packed into core.h (-24),
PNE (were tables of pointers), N_DIV = N_DTIME's first ten names (-32; PEN; enum_order tells
them apart by max; ui.c rate_name by str_nth; tests by N_DIV_N / desc_nm). Image 584336 B
of 584336 (0 B free; was 52). BT 73692 (unchanged), RAM .data+.bss 98120 (unchanged).
audio.c untouched; tools/audio_layout.txt recorded again (FELUCCA_REPIN=keep); a plain
build passes.
CPU (tests/cpu_lines_test.py, mean / worst %, the busier core): 101..108 and 0c the same
or 1 lower; 0d core 0 67 -> 68 / 71 -> 71 (+0.2 % instructions), 0e 82 / 85 unchanged;
0d / 0e with TIME KEY forced: the same as LOCK.
Tests: regress 219 golden renders, 0 changed (V23's intact); math_timelock_test rewritten
through lofi_render: WAVE SYNC as before, KEY faster up the octave, LOCK and TEMPO the
same slow time at C4 and C5 (BYTE, FLOAT), LOCK == KEY at C4, TEMPO follows the BPM, a
preset loads LOCK, a kit's IMAGE still 0; gen_test, fit_test, ui_test, app contract
(docs/NRPN.md, web/NRPN.md: 74 TIME on MATH) pass. The suite's other failures are the
same on 32099fee.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
152 lines
7.3 KiB
C
152 lines
7.3 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only */
|
|
/* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
|
#define UI_TEST_NO_MAIN 1
|
|
#include "ui_test.c"
|
|
|
|
static int fit_bad;
|
|
static void fit_check(const char *what, int ok) { fit_bad += check(what, ok); }
|
|
|
|
int main(void)
|
|
{
|
|
static const uint32_t tempos[] = {40, 61, 120, 239, 240}, swings[] = {0, 37, 100};
|
|
track_t *t = &trk[0];
|
|
int exact = 1, off_same = 1, positive = 1;
|
|
uint32_t checked = 0;
|
|
ui_power_on();
|
|
song.g[G_SWING] = 0;
|
|
for (uint32_t b = 0; b < NELEM(tempos); b++) {
|
|
song.g[G_BPM] = tempos[b];
|
|
for (uint32_t div = 0; div < N_DIV_N; div++) {
|
|
uint32_t period = div_samples(div);
|
|
for (uint32_t len = 1; len <= NSTEP; len++) {
|
|
t->p[P_SLEN] = len;
|
|
for (uint32_t s = 0; s < NELEM(swings); s++) {
|
|
t->p[P_SSWING] = swings[s];
|
|
for (uint32_t span = 1; span <= 64; span++) {
|
|
uint32_t total = 0;
|
|
t->seq_fit = 128u | span;
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
uint32_t duration = step_samples(t, period, i);
|
|
total += duration;
|
|
positive &= duration > 0;
|
|
}
|
|
exact &= total == period * span;
|
|
checked++;
|
|
}
|
|
t->seq_fit = 64;
|
|
for (uint32_t i = 0; i < len; i++)
|
|
off_same &= step_samples(t, period, i) == swing_step_len(t, period, i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fit_check("FIT: every LEN/SPAN 1..64, all DIV, five tempos and three swings sum exactly", exact && positive);
|
|
fit_check("FIT OFF: the previous clock is sample-identical, including odd lengths and swing", off_same);
|
|
printf("fit combinations checked: %u\n", checked);
|
|
|
|
fit_check("long-step gates avoid 32-bit intermediate overflow", fit_scale_samples(67737600u, 127u, 7u) == (uint32_t)(67737600ull * 127u / 128u));
|
|
fit_check("long-step microtiming avoids intermediate overflow", fit_scale_samples(67737600u, 64u, 6u) == 67737600u);
|
|
|
|
ui_power_on();
|
|
song.g[G_BPM] = 123;
|
|
song.g[G_SWING] = 0;
|
|
song.playing = 1;
|
|
memset(&lv, 0, sizeof lv);
|
|
for (uint32_t k = 0; k < 2; k++) {
|
|
track_t *q = &trk[k];
|
|
q->p[P_SLEN] = k ? 18 : 16;
|
|
q->p[P_SDIV] = 2;
|
|
q->p[P_SSWING] = 0;
|
|
q->seq_fit = k ? 128u | 16u : 0;
|
|
q->seq_idx = q->p[P_SLEN] - 1;
|
|
q->seq_pos = 0x7FFFFFFFu;
|
|
q->loops = q->ext = 0;
|
|
for (uint32_t i = 0; i < NSTEP; i++) step_clear(&q->step[i]);
|
|
seq_tick(q, 0);
|
|
}
|
|
{
|
|
uint32_t loop = 16u * div_samples(2), elapsed = 0, count = 200;
|
|
int aligned = 1;
|
|
for (uint32_t r = 1; r <= count; r++) {
|
|
while (elapsed < r * loop) {
|
|
uint32_t n = r * loop - elapsed;
|
|
if (n > CTL) n = CTL;
|
|
seq_tick(&trk[0], n); seq_tick(&trk[1], n);
|
|
elapsed += n;
|
|
}
|
|
aligned &= trk[0].seq_idx == 0 && trk[1].seq_idx == 0 &&
|
|
trk[0].seq_pos == 0 && trk[1].seq_pos == 0 &&
|
|
trk[0].loops == r && trk[1].loops == r;
|
|
}
|
|
fit_check("production sequencer: 18 steps vs 16 realign for 200 loops with no sample drift", aligned);
|
|
}
|
|
|
|
ui_power_on();
|
|
t->seq_fit = 128u | 16u;
|
|
t->p[P_SLEN] = 18; t->p[P_SGATE] = 64; t->seq_idx = 0;
|
|
t->p[P_SSWING] = 0; song.g[G_SWING] = 0;
|
|
for (uint32_t i = 0; i < NSTEP; i++) step_clear(&t->step[i]);
|
|
{
|
|
step_t s; uint32_t period = div_samples(2), unit = step_samples(t, period, 0);
|
|
memset(&s, 0, sizeof s); s.time = ST_NOTE; s.n = 1; s.note[0] = 60; s.vel = 100;
|
|
ev_off = 0; seq_step(t, &s, period, 0);
|
|
fit_check("normal gates follow the fitted step duration", t->seq_n == 1 && t->seq_off == unit / 2u);
|
|
s.ctime = 4u << 3; seq_step(t, &s, period, 0);
|
|
fit_check("per-step LENGTH follows fitted duration", t->seq_off == unit * 4u / 16u);
|
|
s.ctime = 0; s.flags = 3u << SF_RATCH_SH; seq_step(t, &s, period, 0);
|
|
fit_check("ratchet subdivisions and gates follow fitted duration", t->seq_off == unit / 4u / 2u);
|
|
t->step[1].time = ST_TIE;
|
|
fit_check("tie chains use the sum of fitted steps", tie_span(t, period, 18) == unit + step_samples(t, period, 1));
|
|
}
|
|
|
|
ui_power_on();
|
|
for (uint32_t p = 0; p < NPAGES; p++)
|
|
if (FIT_PAGE(&PAGES[p])) { ui.home = 0; ui.page = p; page_entered(); break; }
|
|
frame();
|
|
fit_check("SEQ > LENGTH has RHYTHM with default SPAN 16 / FIT OFF", FIT_PAGE(cur_page()) && fit_span(TSEL) == 16 && !TSEL->seq_fit);
|
|
t->seq_pos = 123; t->ext = 42;
|
|
fit_ui_set(t, 16);
|
|
fit_check("editing SPAN while FIT is OFF preserves phase and pending microtiming", t->seq_pos == 123 && t->ext == 42);
|
|
turn(EN_K1, 2); turn(EN_K2, 1); /* (codex/coherence: RHYTHM SPAN FIT on KNOB 1 and 2) */
|
|
fit_check("SPAN and FIT knobs set the selected track without changing DIV or another track", fit_span(TSEL) == 18 && (TSEL->seq_fit & 128u) && !trk[1].seq_fit);
|
|
turn(EN_K2, -1);
|
|
fit_check("FIT OFF remembers the chosen SPAN", fit_span(TSEL) == 18 && !(TSEL->seq_fit & 128u));
|
|
t->seq_pos = 1000000;
|
|
fit_ui_set(t, 128u | 1u);
|
|
fit_check("live ratio change cannot leave a huge catch-up queue", t->seq_pos < step_samples(t, div_samples(t->p[P_SDIV]), t->seq_idx));
|
|
lv.act = 1u; lv.gidx[0] = 0; lv.gpos[0] = 1000000u;
|
|
fit_ui_set(t, 128u | 2u);
|
|
fit_check("LIVE ghost also rescales safely on a ratio change", lv.gpos[0] < step_samples(t, div_samples(t->p[P_SDIV]), lv.gidx[0]));
|
|
lv.act = 0;
|
|
|
|
|
|
ui_power_on();
|
|
trk[0].seq_fit = 128u | 16u;
|
|
trk[1].seq_fit = 23u;
|
|
project_capture(&proj_scratch);
|
|
fit_check("project packing includes FIT and disabled SPAN", proj_pack(&proj_wire, &proj_scratch));
|
|
memset(proj_scratch.fit, 255, sizeof proj_scratch.fit);
|
|
fit_check("project import restores per-track FIT/SPAN", proj_import(&proj_scratch, &proj_wire, sizeof proj_wire) && proj_scratch.fit[0] == 144 && proj_scratch.fit[1] == 23);
|
|
trk[0].seq_fit = 0;
|
|
project_restore_runtime(&proj_scratch);
|
|
fit_check("project load applies FIT/SPAN to the runtime clock", trk[0].seq_fit == 144 && trk[1].seq_fit == 23);
|
|
transport_req = 0; song.playing = 0;
|
|
project_save(0);
|
|
trk[0].seq_fit = 0;
|
|
chain_config.count = 1; chain_config.row[0] = (chain_row_t){0, 1};
|
|
memset(song_idx.tsrc[song_cur], 0, sizeof song_idx.tsrc[song_cur]);
|
|
fit_check("arrangement section stages the track's fitted clock", !song_stage(0, 0) && sec_stage_fit[0] == 144);
|
|
sec_apply();
|
|
fit_check("arrangement section applies its fitted clock", trk[0].seq_fit == 144);
|
|
project_capture(&proj_scratch);
|
|
memset(proj_scratch.fit, 0, sizeof proj_scratch.fit);
|
|
proj_scratch.sum = proj_sum(&proj_scratch);
|
|
proj_pack(&proj_wire, &proj_scratch);
|
|
memset(proj_scratch.fit, 255, sizeof proj_scratch.fit);
|
|
int defaults = proj_import(&proj_scratch, &proj_wire, sizeof proj_wire);
|
|
for (uint32_t k = 0; k < NTRK; k++) defaults &= !proj_scratch.fit[k];
|
|
fit_check("projects without the new extension load with FIT OFF", defaults);
|
|
printf("FIT tests: %s\n", fit_bad ? "FAILED" : "passed");
|
|
return fit_bad != 0;
|
|
}
|