Files
JIANT/tests/song_draft_test.c
T
Claude a1d7651c45 V10.8.52: SAVE asks before overwriting a part, its UNDO; a saved GEN draft is that project; RESTORE LAST follows it
- SAVE + C4..F4 / SAVE + OCT+ over a part with music: OVERWRITE A? (OCT+ yes,
  OCT- no; "UNDO: GLO + G4" under it), once a part until another project
  opens. The part's previous content kept in the UNDO buffer (undo_st[0],
  undo_ok 2): GLO + G4 puts it back, again redoes the save. GEN's own
  section stores keep their UNDO mark.
- PROJECTS > SAVE of a GEN draft ("SAVED SONG n") ends the draft: project n is
  the open one (index cur written), so SAVE + C4, the flush and the autosave
  go there. Was: still a draft, nothing written, and RESTORE LAST gave back the
  autosave from before GEN (the autosave is off during a draft and was only
  rewritten when n was the project open before GEN).
- ARRANGE OCT+ on a row: "ROW DUPLICATED" (it copies the row picked).
- song_save_as's index row building in the Bluetooth segment (room).
- Tests: song_draft_test (draft ends on save, SAVE + C4 and its UNDO/REDO,
  RESTORE LAST after a draft saved elsewhere, OVERWRITE A? once, an empty part
  saved at once); ui_test (SAVE + OCT+ through the dialog).
- docs/SEQ-EDIT-V10.8.52.patch: the SEQ EDIT page, built and measured but
  parked: 3308 B over the app slot.
- Layout re-recorded (REPIN=keep: row_var moved 2 B); no sound code changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-26 14:18:55 +00:00

142 lines
9.0 KiB
C

/* Generated RAM workspace and explicit LOOP/SONG saves against real NOR model. */
#define PERSISTENCE_TEST_NO_MAIN 1
#include "persistence_test.c"
#include <assert.h>
static uint8_t old_flash[8*ST_SECTOR];
static song_index_t saved_index;
static project_store_t draft_before[4];
static uint32_t object(unsigned n,unsigned s){return n?OBJ_SONG1+(n-1)*4+s:OBJ_PROJECT0+s;}
static void draft_music(unsigned note)
{
for(unsigned s=0;s<4;s++) {
trk[0].step[0]=(step_t){{note+s},1,ST_NOTE,0,100};section_store(s);
}
chain_defaults(&chain_config);chain_config.count=4;live.mode=1;
for(unsigned s=0;s<4;s++)chain_config.row[s]=(chain_row_t){s,1};
dice_secs=15;section_load(0);
}
static int saved_note(unsigned n,unsigned s)
{
int z=st_load(object(n,s),&proj_wire,sizeof proj_wire);
if(z<=0)return -1;
assert(proj_import(&proj_scratch,&proj_wire,sizeof proj_wire));return proj_scratch.t[0].step[0].note[0];
}
int main(void)
{
song_fixture();
memcpy(draft_before,proj_slot,sizeof draft_before);
erase_error=1;
assert(song_draft_begin()&&!song_draft&&!memcmp(draft_before,proj_slot,sizeof draft_before));
erase_error=0;
transport_req=1;assert(song_draft_begin()&&!song_draft);transport_req=0;
puts("draft: failed checkpoint and pending PLAY preserve the original workspace");
assert(!song_draft_begin()&&song_draft);
memcpy(old_flash,nor+0x97000,sizeof old_flash);
assert(st_load(OBJ_SONGIDX,&saved_index,sizeof saved_index)==sizeof saved_index);
unsigned writes=erases;
draft_music(64);song_poll();fm1_ms+=100000;autosave_poll();
assert(erases==writes&&!memcmp(old_flash,nor+0x97000,sizeof old_flash));
for(unsigned n=0;n<4;n++)assert(saved_note(0,n)==48+(int)n);
assert(!song_draft_begin());draft_music(72);song_poll();
assert(erases==writes&&!memcmp(old_flash,nor+0x97000,sizeof old_flash));
puts("draft: regeneration and idle polling never write saved projects or autosave");
assert(!song_save_as(1,"FULL SONG"));
for(unsigned n=0;n<4;n++)assert(saved_note(1,n)==72+(int)n);
assert(st_load(OBJ_SONGIDX,&proj_wire,sizeof saved_index)==sizeof saved_index);
assert(!memcmp(&((song_index_t*)&proj_wire)->rows[0],&saved_index.rows[0],sizeof(chain_config_t)));
assert(!memcmp(old_flash,nor+0x97000,sizeof old_flash));
/* (V10.8.52) a saved draft is that project, open: later SAVE + C4 and the autosave go there */
assert(!song_draft&&song_cur==1&&chain_config.count==4&&song_idx.cur==1);
assert(st_load(OBJ_SONGIDX,&proj_wire,sizeof saved_index)==sizeof saved_index&&((song_index_t*)&proj_wire)->cur==1);
for(unsigned n=0;n<4;n++)assert(project_used(n));
trk[0].step[0].note[0]=80;section_keep(1);song_poll();assert(saved_note(1,1)==80);
assert(proj_import(&proj_scratch,&undo_st[0],sizeof undo_st[0])&&proj_scratch.t[0].step[0].note[0]==73);
assert(!undo_do());song_poll();assert(saved_note(1,1)==73);
assert(!undo_do());song_poll();assert(saved_note(1,1)==80);
puts("draft: saving a full song elsewhere preserves the original project and opens the saved one; SAVE + C4 there, its UNDO");
assert(!song_draft_begin());draft_music(72);
song_save_loop=1;assert(!section_load(2));assert(!song_save_as(2,"JUST LOOP"));
assert(saved_note(2,0)==74);for(unsigned n=1;n<4;n++)assert(saved_note(2,n)==-1);
assert(song_idx.rows[2].count==0&&!song_draft&&song_cur==2&&!chain_config.count);
puts("draft: LOOP writes current music to A, empties B-D and saves no arrangement");
assert(!song_draft_begin());draft_music(72);section_load(2);
song_save_loop=0;assert(!song_save_as(0,"OVERWRITE"));
for(unsigned n=0;n<4;n++)assert(saved_note(0,n)==(n==2?74:72+(int)n));
assert(!song_draft&&song_cur==0&&chain_config.count==4);
assert(!song_draft_begin());draft_music(72);
memcpy(draft_before,proj_slot,sizeof draft_before);
erase_error=1;assert(song_save_as(3,"FAIL")&&song_draft&&!memcmp(draft_before,proj_slot,sizeof draft_before));erase_error=0;
assert(!song_save_as(3,"RETRY"));
{/* (V10.7.20, the owner's use) a LOOP saved over a whole song elsewhere: its A the music now, its B-D and its rows gone */
for(unsigned n=0;n<4;n++)assert(saved_note(3,n)>=0);assert(song_idx.rows[3].count==4);
song_save_loop=1;assert(!song_save_as(3,"LOOP OVER"));
assert(saved_note(3,0)==trk[0].step[0].note[0]);for(unsigned n=1;n<4;n++)assert(saved_note(3,n)==-1);
assert(song_idx.rows[3].count==0&&!song_draft&&!chain_config.count);
assert(!song_draft_begin());draft_music(72);
song_save_loop=0;assert(!song_save_as(3,"RETRY"));assert(song_idx.rows[3].count==4);
puts("draft: a LOOP saved over a whole song clears its B-D and its arrangement; the draft ends there");
}
puts("draft: same-project overwrite is explicit; failed saves retain the draft for retry");
assert(!song_select(0)&&song_cur==0);assert(!song_draft_begin());draft_music(72);memcpy(draft_before,proj_slot,sizeof draft_before);
assert(!song_erase_parts(1,0));for(unsigned n=0;n<4;n++)assert(saved_note(1,n)==-1);
assert(song_draft&&!memcmp(draft_before,proj_slot,sizeof draft_before));
/* (V10.7.22) the open project erased whole: its music goes too, the draft's as well (was: the draft kept) */
assert(!song_erase_parts(song_cur,0)&&song_draft&&!chain_config.count&&seq_is_empty(&trk[0]));
for(unsigned n=0;n<4;n++)assert(!project_used(n)&&saved_note(0,n)==-1);
draft_music(66);
song.playing=1;assert(song_select(3)&&song_draft);song.playing=0;
writes=erases;assert(!project_erase(1));assert(!project_used(1)&&erases==writes);
for(unsigned r=0;r<chain_config.count;r++)assert(chain_config.row[r].slot!=1);
puts("erase: another saved project preserves the draft, the open one clears it; draft part deletion is RAM-only");
assert(!song_select(3)&&!song_draft&&song_cur==3&&chain_config.count==4);
assert(!song_erase_parts(3,0)&&!song_draft&&!chain_config.count);
for(unsigned n=0;n<4;n++)assert(!project_used(n)&&saved_note(3,n)==-1);
assert(seq_is_empty(&trk[0]));
song_idx.rows[0].count=4; song_index_load(); song_index_boot();assert(!chain_config.count);
puts("erase: deleting the open project survives reload and clears its live sequence and arrangement");
song_fixture();song_save_loop=1;assert(!song_save_as(0,"LOOP IN PLACE"));
assert(saved_note(0,0)==90&&!chain_config.count&&live.cur==0);
for(unsigned k=1;k<4;k++)assert(!project_used(k)&&saved_note(0,k)==-1);
trk[0].step[0].note[0]=12;ui_prefs|=PREF_RESTORE_ON;
song_index_load();song_index_boot();
assert(autosave_boot(1)&&trk[0].step[0].note[0]==90&&!live.mode&&!chain_config.count);
puts("save: in-place LOOP also updates RESTORE LAST; reboot cannot restore stale music");
song_fixture();assert(!song_draft_begin());draft_music(65);
assert(!song_save_as(song_cur,"DRAFT BOOT"));
song_draft=0;trk[0].step[0].note[0]=12;ui_prefs|=PREF_RESTORE_ON;
song_index_load();song_index_boot();
assert(autosave_boot(1)&&trk[0].step[0].note[0]==65&&live.mode&&chain_config.count==4);
puts("save: in-place draft SONG restores its music and arrangement after reboot");
song_fixture();assert(!song_draft_begin());draft_music(65);
assert(!chain_prepare());events_block(CTL);song_poll();
events_block(chain_bar());song_poll();assert(chain.running&&live.cur==1);
seq_stop();song_poll();assert(live.cur==0&&trk[0].step[0].note[0]==65);
assert(!song_save_as(1,"AFTER PLAY"));
for(unsigned k=0;k<4;k++)assert(saved_note(1,k)==65+(int)k);
puts("save: PLAY then STOP then SONG save preserves every distinct section");
song_fixture();memcpy(draft_before,proj_slot,sizeof draft_before);erase_error=1;
assert(project_erase(0)&&!memcmp(draft_before,proj_slot,sizeof draft_before));erase_error=0;
assert(!project_erase(1));assert(!project_used(1));
for(unsigned r=0;r<chain_config.count;r++)for(unsigned t=0;t<NTRK;t++)assert(row_src(r,t,chain_config.row[r].slot)!=1);
puts("erase: failed writes keep RAM; deleting a source part removes dependent rows");
{/* (V10.8.52) RESTORE LAST after a GEN draft saved as another project: that music, and the autosave runs again */
song_fixture();assert(!song_draft_begin());draft_music(67);assert(!song_save_as(2,"ELSEWHERE"));
assert(!song_draft&&song_cur==2);
trk[0].step[0].note[0]=69;ui_prefs|=PREF_RESTORE_ON;
for(unsigned k=0;k<6;k++){fm1_ms+=70000;autosave_poll();}
assert(as.writes);trk[0].step[0].note[0]=12;
song_index_load();song_index_boot();
assert(song_cur==2&&autosave_boot(1)&&trk[0].step[0].note[0]==69);
puts("restore: after a draft saved elsewhere, RESTORE LAST gives the newest music (was: the one before GEN)");
/* SAVE + C4 over a part with music asks first (OVERWRITE A?), the part kept until YES */
memcpy(draft_before,proj_slot,sizeof draft_before);
assert(project_used(0));ui.confirm=0;trk[0].step[0].note[0]=91;section_ask(0);
assert(ui.confirm==CF_STORE_SECT&&!memcmp(draft_before,proj_slot,sizeof draft_before));
ui.confirm=0;sv_ok|=1u;section_ask(0);assert(ui.confirm==0&&memcmp(draft_before,proj_slot,sizeof proj_slot[0]));
assert(!undo_do()&&!memcmp(draft_before,proj_slot,sizeof draft_before));
assert(!song_erase_parts(song_cur,8u)&&!project_used(3));section_ask(3);assert(ui.confirm==0&&project_used(3));
puts("save: SAVE + C4 over music asks OVERWRITE A? once; GLO + G4 gives the part back");
}
return 0;
}