From e9befab6009ecbcc85b3a2b4e91650247dd1bb10 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 19:11:58 +0000 Subject: [PATCH] REC then PLAY records the loop in SONG mode; NEW PROJECT plays the loop again A YouTube user (V10.7.6): "I pressed record then play and entered a few notes, pressed stop and pressed play to listen and it played nothing; if I then press record it plays notes I did not enter". After a GEN song (gen.c: live.mode = 1, kept with a saved song's rows over a power cycle) PLAY played the song, which does not record (song_play.c chain_start: song.rec off while it plays, REC's light out); STOP brought the music before PLAY back and PLAY played the song again. Now, a track armed, PLAY on any page but TIMELINE plays and records the loop (ui_input.c B_PLAY); REC off, PLAY plays the song as before. NEW PROJECT (system_init) left SONG mode on with no rows: PLAY did nothing ("ADD A SONG ROW"); it is LOOP now, as at power-on (gen_clean's own reset folded into it). rec_play_test: REC PLAY keys STOP PLAY from power-on, NEW PROJECT, a GEN song then NEW PROJECT, after a GEN song (SONG mode, and over a power cycle), the song again with REC off and the take kept after it, TIMELINE's row loop and STOP keeping the take (two checks fail on the old code). +16 B (148 B free). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh --- .github/workflows/rec-controls.yml | 2 + firmware/src/gen.c | 3 +- firmware/src/project.c | 1 + firmware/src/ui_input.c | 6 +- tests/rec_play_test.c | 118 +++++++++++++++++++++++++++++ tests/run_tests.sh | 2 + 6 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 tests/rec_play_test.c diff --git a/.github/workflows/rec-controls.yml b/.github/workflows/rec-controls.yml index e0b14e73..7df742f3 100644 --- a/.github/workflows/rec-controls.yml +++ b/.github/workflows/rec-controls.yml @@ -75,6 +75,8 @@ jobs: mkdir -p build/rec cc -O1 -w -Ibuild/gen -Ifirmware/src -Itests tests/rec_workflow_test.c -lm -o build/rec/rec_workflow build/rec/rec_workflow | tee build/rec/controls.log + cc -O1 -w -Ibuild/gen -Ifirmware/src -Itests tests/rec_play_test.c -lm -o build/rec/rec_play + build/rec/rec_play | tee build/rec/rec_play.log - name: Timing compared against exact base run: | cc -O1 -w -Ibuild/gen -I/tmp/rec-base/firmware/src -I/tmp/rec-base/tests /tmp/rec-base/tests/micro_test.c -lm -o build/rec/micro_base diff --git a/firmware/src/gen.c b/firmware/src/gen.c index 59c77a42..4ef7032c 100644 --- a/firmware/src/gen.c +++ b/firmware/src/gen.c @@ -2504,8 +2504,7 @@ static void gen_clean(void) int16_t bpm = song.g[G_BPM]; system_init_named(); if (ui_prefs & PREF_BPM_LOCK) song.g[G_BPM] = bpm; - memset(&gs, 0, sizeof gs); - live.mode = 0; + memset(&gs, 0, sizeof gs); /* (LOOP: system_init) */ } static int8_t dice_force_style = -1, dice_force_energy = -1; /* (a film's script, the renders: this genre, this energy) */ /* (p2, main 0.9.18) the piece's choices after its genre (gen_make's, from the GS_PICK stream: the same calls in the same diff --git a/firmware/src/project.c b/firmware/src/project.c index cefd7700..2233e1d6 100644 --- a/firmware/src/project.c +++ b/firmware/src/project.c @@ -1715,6 +1715,7 @@ static __attribute__((noinline)) void system_init(void) /* (snd8: out of its c for (i = 0; i < 5u; i++) song.g[KEEP[i]] = kept[i]; kept[0] = dice_secs; chain_defaults(&chain_config); + live.mode = 0; /* (no rows: PLAY the loop, as at power-on) */ dice_secs = (uint8_t)kept[0]; /* (gen6c) whose the sections in flash are: unchanged */ memset(song_idx.scene[song_cur], 0, sizeof song_idx.scene[song_cur]); memset(song_idx.tsrc[song_cur], 0, sizeof song_idx.tsrc[song_cur]); diff --git a/firmware/src/ui_input.c b/firmware/src/ui_input.c index f10c228a..e1e78b9c 100644 --- a/firmware/src/ui_input.c +++ b/firmware/src/ui_input.c @@ -2952,8 +2952,10 @@ static void ui_input_frame(void) break; if (song.playing || chain_busy() || seq_counting()) /* (a count-in: PLAY stops it) */ transport_req = 2; - else if ((!ui.home && cur_page()->graph == GR_SONG && !SONG_PARTS(cur_page()) && !SONG_CLIPS(cur_page())) || live.mode) /* (the song - * layer's SONG mode; PARTS: as KNOB 4 says) */ + else if (!song.rec && ((!ui.home && cur_page()->graph == GR_SONG && !SONG_PARTS(cur_page()) && + !SONG_CLIPS(cur_page())) || live.mode)) /* (the song layer's SONG mode; PARTS: as + * KNOB 4 says. A track armed: the loop, recorded; a song does + * not record, chain_start) */ chain_play_ui(); else transport_req = 1; diff --git a/tests/rec_play_test.c b/tests/rec_play_test.c new file mode 100644 index 00000000..ace64caf --- /dev/null +++ b/tests/rec_play_test.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* REC, PLAY, keys, STOP, PLAY: the take plays back (a YouTube user on V10.7.6: "I pressed record then play and entered + * a few notes, pressed stop and pressed play to listen and it played nothing; if I then press record it plays notes I + * did not enter"). A GEN song leaves PLAY in SONG mode (gen.c: live.mode, kept in the song index over a power cycle): + * PLAY played the song, which does not record (song_play.c chain_start), and REC's light went out; STOP brought the + * music before PLAY back, PLAY played the song again. Now a track armed plays (and records) the loop; NEW PROJECT + * (SAVE > TOOLS, system_init) is LOOP again (it left SONG mode with no rows: PLAY did nothing, "ADD A SONG ROW"). + * cc -O1 -w -Ibuild/gen -Ifirmware/src tests/rec_play_test.c -lm -o build/rec_play_test */ +#define UI_TEST_NO_MAIN 1 +#include "ui_test.c" + +static uint32_t rp_heard; /* audio blocks with a voice of the selected track gated */ +static void rp_run(uint32_t ms) /* the audio and the main loop together, 16 ms a frame */ +{ + uint32_t i, n; + for (i = 0; i < ms / 16u; i++) { + for (n = 0; n < 16u * FS / 1000u; n += CTL) { + events_block(CTL); + rp_heard += gated_notes(&trk[song.sel]) != 0; + } + song_poll(); + frame(); + } +} +static uint32_t rp_notes(uint32_t t) +{ + uint32_t i, n = 0; + for (i = 0; i < NSTEP; i++) n += trk[t].step[i].time == ST_NOTE; + return n; +} +static void rp_power_on(void) /* the device's power-on parts (ui_test.c ui_power_on_099) */ +{ + ui_power_on(); + load_depth++; + fm6_init(); + power_on_parts(); + load_depth--; + track_select(1); /* (T2 ANALOG: a melodic track) */ +} +static void rp_gen(void) /* a GEN song (SONG mode, its rows), stopped */ +{ + gp.genre = 3; gp.seed = 7; gp.energy = 60; gp.form = 2; + gp.complex = 50; gp.swing = GA_AUTO; gp.human = 30; + for (unsigned k = 0; k < GP_N; ++k) gp.amt[k] = GA_AUTO; + gen_go(); rp_run(500); + if (song.playing) { press(B_PLAY); rp_run(500); } +} +/* REC, PLAY, four keys, STOP, PLAY (no key): 1 when the take was recorded into the loop and is heard back */ +static int rp_take(void) +{ + uint32_t k, n0 = rp_notes(song.sel), n1; + int ok; + press(B_REC); rp_run(300); + press(B_PLAY); rp_run(600); + ok = song.playing && !chain.running && (song.rec >> song.sel & 1u); + for (k = 0; k < 4u; k++) { key_down(white(k)); rp_run(160); key_up(white(k)); rp_run(240); } + press(B_PLAY); rp_run(300); + n1 = rp_notes(song.sel); + press(B_PLAY); rp_run(100); rp_heard = 0; rp_run(2400); + ok &= song.playing && !chain.running && n1 >= n0 + 3u && rp_notes(song.sel) == n1 && rp_heard > 0u; + press(B_PLAY); rp_run(300); + return ok; +} + +int main(void) +{ + int bad = 0; + uint32_t n; + rp_power_on(); + bad += check("power-on: REC PLAY keys STOP PLAY plays the take back", rp_take()); + + rp_power_on(); undo_mark(); system_init(); + track_select(1); + bad += check("NEW PROJECT: the same", !live.mode && rp_take()); + + rp_power_on(); rp_gen(); undo_mark(); system_init(); + track_select(1); + bad += check("a GEN song, then NEW PROJECT: PLAY the loop again (was SONG with no rows: nothing played)", + !live.mode && rp_take()); + + rp_power_on(); rp_gen(); track_select(1); + bad += check("after a GEN song (SONG mode): a track armed, PLAY records the loop (was: the song, not recorded)", + live.mode && chain_config.count && rp_take()); + n = rp_notes(1); + press(B_REC); rp_run(300); + press(B_PLAY); rp_run(600); + bad += check(" REC off: PLAY plays the song again", !song.rec && chain.running && song.playing); + press(B_PLAY); rp_run(600); + bad += check(" STOP after the song: the take is back (the music before PLAY)", !song.playing && rp_notes(1) == n); + + { /* the song SAVEd (SAVE SONG AS: its PLAY mode with its rows), a power cycle: flash keeps the sections and the + * song index's rows (song_index_boot) */ + static project_store_t slots[4]; + chain_config_t cfg = chain_config; + memcpy(slots, proj_slot, sizeof slots); + rp_power_on(); + memcpy(proj_slot, slots, sizeof slots); + chain_config = cfg; + chain_config.rsv[2] = SONG_MODE_TAG | 1u; + song_mode_restore(); + } + bad += check("power-on after a saved GEN song (SONG mode kept): PLAY records the loop", live.mode && rp_take()); + rp_power_on(); rp_gen(); track_select(1); n = rp_notes(1); + { /* SAVE > TIMELINE with the song: PLAY loops its row, STOP brings the recorded loop back */ + uint32_t i; + for (i = 0; i < NPAGES && !SONG_TRK(&PAGES[i]); i++) {} + ui.home = 0; ui.page = (uint8_t)i; page_entered(); frame(); + press(B_REC); rp_run(300); + bad += check(" TIMELINE: REC asks for SEQ, nothing armed", msg_is("[SEQ] TO RECORD") && !song.rec); + press(B_PLAY); rp_run(1200); + bad += check(" TIMELINE: PLAY loops its row", chain.running && song.playing); + press(B_PLAY); rp_run(300); + bad += check(" TIMELINE: PLAY again, the song goes on", chain.running && !chain.hold && msg_is("THE SONG GOES ON")); + press(B_PLAY); rp_run(600); + bad += check(" TIMELINE: STOP, the take is back", !song.playing && rp_notes(1) == n); + } + return bad != 0; +} diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 410cb7ff..bf5f861d 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -301,6 +301,8 @@ if [ -f build/gen/felucca_tables.h ]; then run "settings: PER1..PER4 migration, palette ids and preference preservation" "$OUT/settings_test" $CC -w -Ibuild/gen -Ifirmware/src -o "$OUT/ui_test" tests/ui_test.c -lm run "UI: sounds keep steps, undo, recording, MIDI overflow, pending saves, panel recovery, drum grid, song chain, GREY gray, MONO neutral; (gen3) the COMP cards whole, every value" "$OUT/ui_test" + $CC -O1 -w -Ibuild/gen -Ifirmware/src -o "$OUT/rec_play_test" tests/rec_play_test.c -lm + run "REC PLAY keys STOP PLAY: the take plays back (power-on, NEW PROJECT, after a GEN song in SONG mode, TIMELINE)" "$OUT/rec_play_test" FV=$(sed -n 's/^#define FELUCCA_VERSION "\([^"]*\)".*/\1/p' firmware/src/felucca.c) # (the splash, ABOUT: the real version) $CC -O1 -w "-DFELUCCA_VERSION=\"$FV\"" -Ibuild/gen -Ifirmware/src -Itests -o "$OUT/ui_render" tests/ui_render.c -lm mkdir -p build/ui_new/ppm build/ui_slot