Generate songs in a RAM draft; explicit loop/song overwrite and project erase

This commit is contained in:
JUAN JIANT committed 2026-11-05 13:40:06 -03:00
1 parent 1ecbab097b
commit d9d68f752f
22 files changed
+416 -139

No files matched your search

+2
View File
@@ -45,6 +45,8 @@ jobs:
run: |
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/song_generator_test.c -lm -o build/song-check/generator
build/song-check/generator | tee build/song-check/generator.log
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/song_draft_test.c -lm -o build/song-check/draft
build/song-check/draft | tee build/song-check/draft.log
- name: Matrix and track follower regression
run: |
cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/mod_test.c -lm -o build/song-check/mod
+39
View File
@@ -0,0 +1,39 @@
# Generated songs and explicit project saves (ADD beta)
GEN works in a RAM draft. Existing A–D sections do not prevent generation.
The first generation checkpoints pending saved-project sections and its index,
then borrows the existing four section buffers. Further generations, section
edits and idle autosave do not write that draft over a saved project.
MAKE can regenerate while playback runs: transport stops, the next draft is
generated, and playback resumes in the new draft's mode. This is not a gapless
transition. GEN 1, 2 and 3 all show real sections and arrangement progress.
SAVE > SAVE SONG AS selects a destination and SCOPE:
- SONG saves A–D and the complete arrangement, scenes, track sources and variations.
- LOOP saves the currently loaded music in A and clears B–D and the arrangement
at that destination.
The current project is a valid destination. Occupied destinations require an
overwrite confirmation, then naming. Saving requires stopped transport. Saving
keeps the draft available for more generations; power-off discards an unsaved
draft. SAVE > PROJECTS selects saved destinations without loading them during a
draft; LOAD opens the selected saved project and discards the draft.
SAVE > PROJECTS > ERASE clears all saved parts and arrangement at the selected
destination after confirmation. SAVE > SECTIONS > ERASE clears the selected
part and removes arrangement rows referencing it, including per-track sources.
Erasing a draft part is RAM-only. Erasing a saved destination does not erase
the active draft.
Each storage object retains its existing A/B commit protection. A multi-part
save or erase is not atomic across all four parts and the index: retry an
interrupted operation. Failed saves retain the draft for retry. No flash map,
loader, project format or audio buffer changes are involved.
Validation: native NOR tests cover source preservation, both scopes, same-project
overwrite, failure/retry, project erase and dependent-row cleanup. Generator UI
tests cover 45 genre choices, distinct parts, playback traversal, regeneration
during playback and all GEN pages. Target memory checks and the ordinary pinned
audio layout must pass before publication. This release goes to beta only.
+1 -1
View File
@@ -44,7 +44,7 @@
#define FELUCCA_ID "FM-1_900" /* package identity (build.py: the .fwsc marker string) */
#endif
#ifndef FELUCCA_VERSION
#define FELUCCA_VERSION "V10.6c-matrix" /* (2026-11-03) V10.61: PROX tuned (the user: it works with the phone, but the phone had to go far away for PROX to let go; a narrower field, a quicker response): the PROX page's KNOB 1 MIN (0 .. 90 %: under it PROX is 0), KNOB 2 MAX (100 .. 10 %: over it PROX is full), both over the calibrated FAR .. NEAR, 10 % apart at least; KNOB 3 SPEED 1..5 (the level's smoothing 1/32 as before .. 1/2: quicker, noisier); saved as FAR / NEAR; 0, 100 and 1 as V10.60. (2026-11-03) V10.60: room (the user's ask): the conversion of DIGITAL's sounds to FM6 (fm4_convert.c) and the read of JIANT 0.1-0.5's projects (FUNB..FUN7, project.c proj_unpack) moved into the Bluetooth segment (without it: a DIGITAL sound loads as the FM6 factory preset that covers it, those old projects are not read); the app slot 4.3 KB free (was 0.8), the segment 2.7 KB; BTAPP_FN / BTAPP_RO in core.h. (2026-11-03) V10.59: FX > RPT 1/8 at slow tempos (the user: dimmed at 61 BPM): a REPEAT longer than the loop at 22 kHz (371 ms) records at 11 kHz, lo-fi (the effect's), up to 742 ms: 1/8 from 41 BPM (was 81), 1/16 from 21 (was 41); the faster ones as before, bit for bit. (2026-11-03) V10.58: users' reports: the master EQ (and TAPE) went back to flat on its own (going to GLO's pages, since V10.44): every read of a stored project or section (a slot checked, a section listed) set the EQ and TAPE playing; they now live in the project read and are applied only when it is loaded; MENU in BOTTOM and HUD showed its four cards under the panel (a blank band over it): the panel right under the tabs there, the cards at the foot as on every page of theirs; AIR's HOME: the beings swim under its cards (they crossed the tabs and the values); FX > EQ with SCOPE ON: the master's scope behind the curve. (2026-11-03) V10.57: USB > HOST takes an audio interface at 48 kHz too (the user's OP-Z, and the many interfaces with no 44,100): set to 48,000 when it has no 44,100, read at the I2S clock from a step of 48 / 44.1 (the reader's interpolation, its drift steering as before); packets of up to 50 frames taken. (2026-11-03) V10.56: USB IN+OUT no longer mixes the computer's or the phone's audio into the last track by itself (the user: recording from KOALA with IN+OUT on looped into a digital feedback, the app sending the FM-1's own output back): the input sounds where an INPUT track takes it; STEMS+IN keeps its own stem as before. (2026-11-03) V10.55: GEN's sounds right again: V10.42 replaced FM6 presets 8..12 and 14 and WHEEL 5, 6, and GEN still picked them by number for its roles (a SUB BASS played the bells, leads the electric pianos and plucks, a pedal bass the organs): its BELL EP PLUCK STRINGS SINE KEYS ORGAN DUB CHORD and KEYS take today's nearest (BELL MARIMBA TINE EP PLUCK PAD WAVE ORGAN GOSPEL JAZZ PERC); INPUT's meters keep FOLLOW's frame with the input silent; the host tests brought up to date with the UI (the DJ FILTER on LIVE > MANO, the roll's 13 px columns, INPUT in the engine lists). (2026-11-03) V10.54: the INPUT engine (the user's ask: the audio input routed, the track in an audio mode, an envelope follower): engine 15 plays the USB audio input (an interface on HOST, or the computer's USB IN+OUT) on its track: SOURCE IN 1 / IN 2 / 1+2 / STEREO (two tracks can take IN 1 and IN 2; STEREO keeps the image through the part's chain as IMAGE does), GAIN, GATE, PLAY THRU / KEYS (only while a note plays, at its envelope: a trance gate from the steps), WIDTH, RING (KEYS: a sine at the note), BITS, RATE; the track's FILTER DIST LEVEL PAN sends as any part's; EDIT INPUT shows both inputs' meters, GATE's level and FOLLOW; while a track is INPUT the last track's IN+OUT mix steps aside; MOD SRC FOLLOW, the input's envelope, on any track and any destination. (2026-11-03) V10.53: USB > HOST takes an audio interface too, an experiment (the user's ask: a USB audio input into the synth): a class compliant USB audio 1.0 capture (16-bit, mono or stereo, 44,1 kHz among its rates: Behringer UM2 / UCA and the like), alone or behind a powered hub, set to 44,1 kHz (SET_CUR) and read each frame (isochronous IN) into IN+OUT's ring: it plays through the last track (its LEVEL PAN and sends, as USB IN+OUT's host audio); usb_host_desc.h uh_parse_uac, tested; not yet on hardware. (2026-11-03) V10.52: a synth's STEREO page shows IMAGE at work (the user: no visual feedback): the field L .. R, each voice sounding a blob at its place, its size its level now, its note over it (IMAGE 0: the notes in a row), the silent ones a tick where they would sit, the span IMAGE opens as a bar. (2026-11-03) V10.51: the roll follows the playhead for real (the user: V10.47's did not): the bar playing was chosen in the roll's drawing, and a playhead out of the bar shown changed nothing the panel's redraw looks at (graph_signature): never drawn, never followed; now chosen there. (2026-11-03) V10.50: the user's fixes to V10.49: a synth's STEREO IMAGE its own parameter (P_SIMG, thLine truncated
#define FELUCCA_VERSION "V10.6c-draft" /* (2026-11-03) V10.61: PROX tuned (the user: it works with the phone, but the phone had to go far away for PROX to let go; a narrower field, a quicker response): the PROX page's KNOB 1 MIN (0 .. 90 %: under it PROX is 0), KNOB 2 MAX (100 .. 10 %: over it PROX is full), both over the calibrated FAR .. NEAR, 10 % apart at least; KNOB 3 SPEED 1..5 (the level's smoothing 1/32 as before .. 1/2: quicker, noisier); saved as FAR / NEAR; 0, 100 and 1 as V10.60. (2026-11-03) V10.60: room (the user's ask): the conversion of DIGITAL's sounds to FM6 (fm4_convert.c) and the read of JIANT 0.1-0.5's projects (FUNB..FUN7, project.c proj_unpack) moved into the Bluetooth segment (without it: a DIGITAL sound loads as the FM6 factory preset that covers it, those old projects are not read); the app slot 4.3 KB free (was 0.8), the segment 2.7 KB; BTAPP_FN / BTAPP_RO in core.h. (2026-11-03) V10.59: FX > RPT 1/8 at slow tempos (the user: dimmed at 61 BPM): a REPEAT longer than the loop at 22 kHz (371 ms) records at 11 kHz, lo-fi (the effect's), up to 742 ms: 1/8 from 41 BPM (was 81), 1/16 from 21 (was 41); the faster ones as before, bit for bit. (2026-11-03) V10.58: users' reports: the master EQ (and TAPE) went back to flat on its own (going to GLO's pages, since V10.44): every read of a stored project or section (a slot checked, a section listed) set the EQ and TAPE playing; they now live in the project read and are applied only when it is loaded; MENU in BOTTOM and HUD showed its four cards under the panel (a blank band over it): the panel right under the tabs there, the cards at the foot as on every page of theirs; AIR's HOME: the beings swim under its cards (they crossed the tabs and the values); FX > EQ with SCOPE ON: the master's scope behind the curve. (2026-11-03) V10.57: USB > HOST takes an audio interface at 48 kHz too (the user's OP-Z, and the many interfaces with no 44,100): set to 48,000 when it has no 44,100, read at the I2S clock from a step of 48 / 44.1 (the reader's interpolation, its drift steering as before); packets of up to 50 frames taken. (2026-11-03) V10.56: USB IN+OUT no longer mixes the computer's or the phone's audio into the last track by itself (the user: recording from KOALA with IN+OUT on looped into a digital feedback, the app sending the FM-1's own output back): the input sounds where an INPUT track takes it; STEMS+IN keeps its own stem as before. (2026-11-03) V10.55: GEN's sounds right again: V10.42 replaced FM6 presets 8..12 and 14 and WHEEL 5, 6, and GEN still picked them by number for its roles (a SUB BASS played the bells, leads the electric pianos and plucks, a pedal bass the organs): its BELL EP PLUCK STRINGS SINE KEYS ORGAN DUB CHORD and KEYS take today's nearest (BELL MARIMBA TINE EP PLUCK PAD WAVE ORGAN GOSPEL JAZZ PERC); INPUT's meters keep FOLLOW's frame with the input silent; the host tests brought up to date with the UI (the DJ FILTER on LIVE > MANO, the roll's 13 px columns, INPUT in the engine lists). (2026-11-03) V10.54: the INPUT engine (the user's ask: the audio input routed, the track in an audio mode, an envelope follower): engine 15 plays the USB audio input (an interface on HOST, or the computer's USB IN+OUT) on its track: SOURCE IN 1 / IN 2 / 1+2 / STEREO (two tracks can take IN 1 and IN 2; STEREO keeps the image through the part's chain as IMAGE does), GAIN, GATE, PLAY THRU / KEYS (only while a note plays, at its envelope: a trance gate from the steps), WIDTH, RING (KEYS: a sine at the note), BITS, RATE; the track's FILTER DIST LEVEL PAN sends as any part's; EDIT INPUT shows both inputs' meters, GATE's level and FOLLOW; while a track is INPUT the last track's IN+OUT mix steps aside; MOD SRC FOLLOW, the input's envelope, on any track and any destination. (2026-11-03) V10.53: USB > HOST takes an audio interface too, an experiment (the user's ask: a USB audio input into the synth): a class compliant USB audio 1.0 capture (16-bit, mono or stereo, 44,1 kHz among its rates: Behringer UM2 / UCA and the like), alone or behind a powered hub, set to 44,1 kHz (SET_CUR) and read each frame (isochronous IN) into IN+OUT's ring: it plays through the last track (its LEVEL PAN and sends, as USB IN+OUT's host audio); usb_host_desc.h uh_parse_uac, tested; not yet on hardware. (2026-11-03) V10.52: a synth's STEREO page shows IMAGE at work (the user: no visual feedback): the field L .. R, each voice sounding a blob at its place, its size its level now, its note over it (IMAGE 0: the notes in a row), the silent ones a tick where they would sit, the span IMAGE opens as a bar. (2026-11-03) V10.51: the roll follows the playhead for real (the user: V10.47's did not): the bar playing was chosen in the roll's drawing, and a playhead out of the bar shown changed nothing the panel's redraw looks at (graph_signature): never drawn, never followed; now chosen there. (2026-11-03) V10.50: the user's fixes to V10.49: a synth's STEREO IMAGE its own parameter (P_SIMG, theLine truncated
#endif
#if FELUCCA_OTA && !FELUCCA_FLASH
#error "FELUCCA_OTA needs FELUCCA_FLASH"
+32 -34
View File
@@ -1745,7 +1745,7 @@ static void gen_parts(void)
uint8_t pdeg[4], pq[4], pn = gs.pn;
const uint8_t *ord;
uint32_t nord;
if (form == FM_LOOP) return;
if (form == FM_LOOP) { section_store(0); dice_secs |= 1u; return; }
gseed(GS_FORM);
live.cur = -1;
section_store(0); /* A: the whole piece */
@@ -2463,18 +2463,17 @@ static void gen_go(void)
{
uint32_t k;
char b[8];
uint32_t play = song.playing || chain_busy() || seq_counting();
if (play) {
fm1_irq_off(); seq_stop(); transport_req = 0; fm1_irq_on();
song_poll();
}
gform_kept = 0;
/* Refuse before gen_clean: a requested SONG must not silently become a loop
* while also erasing the current arrangement. Never overwrite saved A-D. */
if (gp.form)
for (k = 0; k < 4u; k++)
if (project_used(k) && !((dice_secs >> k) & 1u)) {
gform_kept = 1;
ui_message("A-D SAVED");
str_cpy(ui.msg2, "USE AN EMPTY PROJECT", sizeof ui.msg2);
return;
}
undo_mark();
if (song_draft_begin()) {
if (play) { if (live.mode) chain_play_ui(); else transport_req = 1; }
return;
}
gen_make();
str_cpy(gp.last, gs.g->name, sizeof gp.last);
k = str_len(gp.last);
@@ -2483,6 +2482,7 @@ static void gen_go(void)
str_cpy(gp.last + k, b, sizeof gp.last - k);
ui_say("GEN: ", gp.last);
str_cpy(ui.msg2, live.mode ? "PLAY: SONG / SAVE: ALL PARTS" : "UNDO: GLO + G4", sizeof ui.msg2);
if (play) { if (live.mode) chain_play_ui(); else transport_req = 1; }
ui.force = 1;
}
static uint32_t gen_sig(void) /* the settings that make the piece */
@@ -2653,9 +2653,9 @@ static const char *dice_seq(track_t *t)
}
/* ------------------------------------------------------------------------------------------- the GEN screen --- */
static const char *const GEN_LBL[3][4] = {{"GENRE", "SEED", "ENERGY", "FORM"}, {"DRUMS", "BASS", "CHORDS", "ARP"},
static const char *const GEN_LBL[3][4] BTAPP_RO = {{"GENRE", "SEED", "ENERGY", "FORM"}, {"DRUMS", "BASS", "CHORDS", "ARP"},
{"LEAD", "COMPLEX", "SWING", "HUMAN"}};
static const char *const GEN_FORM[3] = {"LOOP", "PARTS", "SONG"};
static const char *const GEN_FORM[3] BTAPP_RO = {"LOOP", "PARTS", "SONG"};
static uint8_t gen_fresh; /* (0.6.96) the screen's first frame: the body cleared once */
static void gen_open(void)
{
@@ -2705,7 +2705,7 @@ static void gen_page_put(uint32_t p) /* (0.9.2) GEN 1..3: HO
gp.page = (uint8_t)(p % 3u);
ui.force = 1;
}
static void gen_value(uint32_t p, uint32_t k, char *b)
BTAPP_FN static void gen_value(uint32_t p, uint32_t k, char *b)
{
uint32_t v;
b[0] = 0;
@@ -2727,7 +2727,7 @@ static void gen_value(uint32_t p, uint32_t k, char *b)
/* (0.8.5) GEN in HOME's lens (ui_lens.c, the mock-up's GEN level): its four settings on the cards, the panel the five
* parts as rows (the ones the page's knobs weigh lit), each a preview of its density (its amount) and heat (ENERGY)
* from the seed, the FORM's sections as chips, the last piece and OCT+ MAKE */
static void gen_cards(void)
BTAPP_FN static void gen_cards_bt(void)
{
uint32_t k;
char v[16];
@@ -2744,18 +2744,21 @@ static void gen_cards(void)
draw_column(k, GEN_LBL[p][k], v, "", VAL(k), r, ICON_NONE);
}
}
static void gen_cards(void)
{
if (bt_hw_seg()) gen_cards_bt();
}
static uint32_t gen_draw_sig(void)
{
return gen_sig() * 31u + gp.page * 7u + str_hash(gp.hot * 977u, gp.last) + ux.gen +
chain_config.count * 7919u + live.mode * 13u + song.playing * 29u +
(chain.running ? (chain.row + 1u) * 104729u + chain.remaining * 1299709u : 0u);
}
static void gen_panel(void)
BTAPP_FN static void gen_panel_bt(void)
{
static const char *const ROLE[5] = {"DRUMS", "BASS", "CHORDS", "ARP", "LEAD"};
uint32_t k, p = gp.page % 3u;
uint32_t k;
char v[24];
if (p == 0u && chain_config.count) {
if (chain_config.count) {
/* Reuse the actual arrangement, not FORM's illustrative BCADCA chips.
* Progress refreshes per bar; no new high-rate animation or DSP work. */
graph_proj(2);
@@ -2768,22 +2771,17 @@ static void gen_panel(void)
fmt_int(v + str_len(v), chain.remaining);
} else str_cpy(v, song.playing ? "PLAYING LOOP" : live.mode ? "SONG READY" : "LOOP MODE", sizeof v);
cv_text(4, 128, &AF_X, v, T_TEXT);
cv_text_r(236, 128, &AF_X, "SAVE: SONG", T_ACCENT, T_SURF);
cv_text_r(236, 128, &AF_X, song_draft ? "DRAFT / SAVE" : "SAVE: SONG", T_ACCENT, T_SURF);
return;
}
/* Settings are shown numerically by the knob cards. The panel needs only
* their density bars; FORM is already labelled on GEN 1. */
for (k = 0; k < 5u; k++) {
int32_t y = 8 + (int32_t)k * 21;
uint32_t a = gp.amt[k] == GA_AUTO ? 55u : gp.amt[k];
uint16_t c = ((p == 1u && k < 4u) || (p == 2u && k == 4u)) ? T_THEME : T_MID;
cv_text(8, y, &AF_X, ROLE[k], c);
cv_rect(60, y + 3, 166, 4, T_LINE);
if (a) cv_rect(60, y + 3, (int32_t)a * 166 / 100, 4, c);
}
str_cpy(v, "LAST: ", sizeof v);
str_cpy(v + 6, gp.last[0] ? gp.last : "-", sizeof v - 6);
cv_clip_text(6, 126, &AF_X, v, T_MID, T_SURF, 150);
cv_text_r(234, 126, &AF_X, "OCT+ MAKE", T_ACCENT, T_SURF);
graph_proj(0);
cv_rect(0, 124, 240, 16, T_SURF);
cv_text(4, 128, &AF_X, song_draft ? "DRAFT LOOP" : "SAVED PARTS", T_TEXT);
cv_text_r(236, 128, &AF_X, "SAVE: LOOP/SONG", T_ACCENT, T_SURF);
}
static void gen_panel(void)
{
if (bt_hw_seg()) gen_panel_bt(); else graph_proj(chain_config.count ? 2 : 0);
}
+5 -21
View File
@@ -1752,7 +1752,7 @@ static int project_save_as(uint32_t slot, const char *name)
if (!proj_pack(&proj_wire, p)) { ui_message(proj_full ? "SECTION FULL" : "SAVE FORMAT ERROR"); return 2; }
#if FELUCCA_FLASH
if (flash_ok) {
if (flash_ok && !song_draft) {
if (st_save(proj_obj(slot), &proj_wire, sizeof proj_wire)) {
ui_message("SAVE ERROR");
return 2;
@@ -1770,7 +1770,7 @@ static int project_save_as(uint32_t slot, const char *name)
proj_name_get(proj_name, (const uint8_t *)p->name);
proj_cur = (uint8_t)(slot & 3u);
live.cur = (int8_t)(slot & 3u);
ui_message("SAVED (NO FLASH)");
ui_message(song_draft ? "PART STORED IN DRAFT" : "SAVED (NO FLASH)");
return 0;
}
static int project_save(uint32_t slot) { return project_save_as(slot, 0); }
@@ -2193,23 +2193,7 @@ static int project_used(uint32_t slot) { return proj_import(&proj_scratch, &proj
* erase). 0 done */
static int project_erase(uint32_t slot)
{
char b[8] = "SECT A";
slot &= 3u;
b[5] = (char)('A' + slot);
if (transport_busy()) { ui_message("STOP TO ERASE"); return 1; }
memset(&proj_slot[slot], 0, sizeof proj_slot[slot]);
live.dirty &= (uint8_t)~(1u << slot); /* (nothing left to write) */
if (live.cur == (int8_t)slot) live.cur = -1;
proj_wire_gen++; /* (the LIBRARY's picture again) */
#if FELUCCA_FLASH
if (flash_ok && (st_erase(st_sector(proj_obj(slot), 0)) || st_erase(st_sector(proj_obj(slot), 1)))) {
ui_message("ERASE ERROR");
return 2;
}
#endif
ui_say("ERASED ", b);
ui.force = 1;
return 0;
return song_erase_parts(song_cur, 1u << (slot & 3u));
}
/* (0.8.5) SAVE > LIBRARY: project n's sections stored (a bit each) and its section A's name (b, PROJ_NAME_LEN + 1),
@@ -2220,7 +2204,7 @@ static uint32_t lib_scan(uint32_t n, char *b)
{
uint32_t k, m = 0;
b[0] = 0;
if (n == song_cur) {
if (n == song_cur && !song_draft) {
for (k = 0; k < 4u; k++)
m |= (uint32_t)project_used(k) << k;
if (m & 1u)
@@ -2401,7 +2385,7 @@ static void autosave_poll(void)
}
#if FELUCCA_FLASH
uint32_t sig;
if (!flash_ok || fm1_ms - as.poll < AS_POLL_MS)
if (song_draft || !flash_ok || fm1_ms - as.poll < AS_POLL_MS)
return;
as.poll = fm1_ms;
sig = autosave_sig();
+1
View File
@@ -67,6 +67,7 @@ static void scene_capture(scene_t *s)
memcpy(s->mac, macro_v, sizeof s->mac);
}
static song_index_t song_idx;
static uint8_t song_draft; /* Generated workspace: never auto-written to project slots. */
static uint8_t song_cur; /* the song whose sections proj_slot holds (0: the four project slots) */
/* track k of the current song's row r: the section it plays (the row's own unless ARRANGE 2 gave it another) */
static uint32_t row_src(uint32_t r, uint32_t k, uint32_t s)
+32 -5
View File
@@ -363,6 +363,7 @@ static void song_rec_toggle(void)
static int song_flush(void)
{
uint32_t k;
if (song_draft) return 0;
#if FELUCCA_FLASH
if (!flash_ok)
return 0;
@@ -384,6 +385,7 @@ static void song_idx_touch(void)
/* the index into flash (the songs' rows, the current song): 0 done (or no flash) */
static int song_index_save(void)
{
if (song_draft) return 0;
song_idx.rows[song_cur] = chain_config;
song_idx.cur = song_cur;
#if FELUCCA_FLASH
@@ -394,6 +396,27 @@ static int song_index_save(void)
return 0;
}
/* Commit the old project before borrowing its four RAM buffers. All later
* generations are drafts until an explicit SAVE; no new audio storage. */
static int song_draft_begin(void)
{
if (!bt_hw_seg()) { ui_message("UPDATE PACKAGE"); return 1; }
if (transport_busy()) { ui_message("STOP TO GENERATE"); return 1; }
#if FELUCCA_FLASH
if (!flash_ok) { ui_message("NO FLASH"); return 1; }
#endif
if (!song_draft) {
if (song_flush() || song_index_save()) { ui_message("SAVE ERROR"); return 1; }
song_save_target = song_cur;
}
song_draft = 1;
live.dirty = 0; live.cur = live.req = -1; sec_stage.ready = 0;
proj_cur = PROJ_NO_SLOT; proj_name[0] = 0;
memset(proj_slot, 0, sizeof proj_slot);
proj_wire_gen++;
return 0;
}
#include "song_save.c"
/* song n (0..NSONG - 1) in, stopped only: the current one kept first, then n's sections and rows; load_a: its
@@ -403,17 +426,20 @@ static int song_switch(uint32_t n, int load_a)
{
char nm[PROJ_NAME_LEN + 1u];
uint32_t k;
if (n >= NSONG || n == song_cur)
if (n >= NSONG || (n == song_cur && !song_draft))
return 1;
if (transport_busy()) {
ui_message(load_a ? "STOP TO CHANGE SONG" : "STOP TO CHANGE PROJECT");
return 1;
}
if (song_flush()) {
ui_message("SAVE ERROR");
return 1;
if (song_draft) {
song_draft = 0; live.dirty = 0;
song_index_load();
} else {
if (song_flush()) { ui_message("SAVE ERROR"); return 1; }
song_idx.rows[song_cur] = chain_config;
}
song_idx.rows[song_cur] = chain_config; /* (the rows of the song left) */
/* The original index is restored before opening another saved project. */
song_cur = (uint8_t)n;
chain_config = song_idx.rows[n];
if (song_index_save()) { /* (failed: written again by song_poll) */
@@ -504,6 +530,7 @@ static void song_poll(void)
ui_message("SONG END");
}
}
if (song_draft) return;
chain_config.rsv[2] = SONG_MODE_TAG | (live.mode ? 1u : 0u);
if (memcmp(&chain_config, &song_idx.rows[song_cur], sizeof chain_config)) { /* the rows or PLAY mode changed */
song_idx.rows[song_cur] = chain_config;
+128 -15
View File
@@ -10,15 +10,18 @@
static int song_copy_section(uint32_t section, uint32_t current, const char *name)
{
project_t *p = &proj_scratch;
if (!proj_import(p, section == current ? &song_keep : &proj_slot[section], sizeof(project_store_t))) {
if (song_save_loop) {
if (section) return 0;
if (!proj_import(p, &song_keep, sizeof song_keep)) return -1;
} else if (!proj_import(p, section == current ? &song_keep : &proj_slot[section], sizeof(project_store_t))) {
if (section || !proj_import(p, &song_keep, sizeof song_keep)) return 0;
}
for (uint32_t i = 0; i < G_COUNT; i++)
p->g[i] = mom_base(MOM_G, i, song.g[i]);
p->g[G_DJF] = mom_base(MOM_G, G_DJF, motion_djf_value());
p->chain = chain_config;
if (song_save_loop) chain_defaults(&p->chain); else p->chain = chain_config;
p->chain.rsv[1] = 0; /* saved sections belong to the player, not GEN */
p->chain.rsv[2] = SONG_MODE_TAG | (live.mode ? 1u : 0u);
p->chain.rsv[2] = SONG_MODE_TAG | (!song_save_loop && live.mode ? 1u : 0u);
if (section == 0u && name) {
memset(p->name, 0, sizeof p->name);
memcpy(p->name, name, str_len(name) < PROJ_NAME_LEN ? str_len(name) : PROJ_NAME_LEN);
@@ -27,6 +30,24 @@ static int song_copy_section(uint32_t section, uint32_t current, const char *nam
return proj_pack(&proj_wire, p) ? 1 : -1;
}
/* Saved index and one destination's metadata; the live draft keeps its own row data. */
static int song_saved_index(song_index_t *index)
{
#if FELUCCA_FLASH
if (song_draft) return st_load(OBJ_SONGIDX, index, sizeof *index) != sizeof *index || index->magic != SONG_MAGIC;
#endif
memcpy(index, &song_idx, sizeof *index);
index->rows[song_cur] = chain_config;
return 0;
}
BTAPP_FN static void song_index_target(const song_index_t *index, uint32_t target)
{
song_idx.rows[target] = index->rows[target];
memcpy(song_idx.scene[target], index->scene[target], sizeof index->scene[target]);
memcpy(song_idx.tsrc[target], index->tsrc[target], sizeof index->tsrc[target]);
memcpy(song_idx.tvar[target], index->tvar[target], sizeof index->tvar[target]);
}
static int song_save_as(uint32_t target, const char *name)
{
#if FELUCCA_FLASH
@@ -34,7 +55,8 @@ static int song_save_as(uint32_t target, const char *name)
song_index_t *index = (song_index_t *)proj_wire_u.raw;
_Static_assert(sizeof(song_index_t) <= sizeof proj_wire_u.raw, "song index fits existing staging RAM");
if (transport_busy()) { ui_message("STOP TO SAVE"); return 1; }
if (target >= NSONG || target == song_cur) { ui_message("CHOOSE ANOTHER PROJECT"); return 1; }
if (!bt_hw_seg()) { ui_message("UPDATE PACKAGE"); return 1; }
if (target >= NSONG) { ui_message("CHOOSE ANOTHER PROJECT"); return 1; }
if (!flash_ok) { ui_message("NO FLASH: NOT SAVED"); return 1; }
current = live.cur >= 0 && live.cur < 4 ? (uint32_t)live.cur : proj_cur < 4u ? proj_cur : 0u;
project_capture(&proj_scratch);
@@ -48,14 +70,15 @@ static int song_save_as(uint32_t target, const char *name)
if (rc < 0) { ui_message("SECTION FULL"); return 2; }
if (rc) mask |= 1u << section;
}
if (!chain_valid(&chain_config)) { ui_message("INVALID ARRANGEMENT"); return 2; }
for (uint32_t row = 0; row < chain_config.count; row++) {
if (!song_save_loop && !chain_valid(&chain_config)) { ui_message("INVALID ARRANGEMENT"); return 2; }
for (uint32_t row = 0; !song_save_loop && row < chain_config.count; row++) {
if (!(mask & (1u << chain_config.row[row].slot))) { ui_message("MISSING SECTION"); return 2; }
for (uint32_t track = 0; track < NTRK; track++)
if (!(mask & (1u << row_src(row, track, chain_config.row[row].slot)))) {
ui_message("MISSING SECTION"); return 2;
}
}
if (song_saved_index(index)) { ui_message("SAVE INDEX ERROR"); return 2; }
proj_wire_gen++; /* invalidate editor staging and the library, even on failure */
for (section = 0; section < 4u; section++) {
uint32_t obj = target ? OBJ_SONG1 + (target - 1u) * 4u + section : OBJ_PROJECT0 + section;
@@ -66,18 +89,36 @@ static int song_save_as(uint32_t target, const char *name)
ui_message("SAVE ERROR: RETRY"); return 2;
}
}
memcpy(index, &song_idx, sizeof *index);
index->rows[song_cur] = chain_config;
index->rows[target] = chain_config;
if (song_saved_index(index)) { ui_message("SAVE INDEX ERROR"); return 2; }
if (song_save_loop) {
chain_defaults(&index->rows[target]);
memset(index->scene[target], 0, sizeof index->scene[target]);
memset(index->tsrc[target], 0, sizeof index->tsrc[target]);
memset(index->tvar[target], 0, sizeof index->tvar[target]);
} else {
index->rows[target] = chain_config;
memcpy(index->scene[target], song_idx.scene[song_cur], sizeof index->scene[target]);
memcpy(index->tsrc[target], song_idx.tsrc[song_cur], sizeof index->tsrc[target]);
memcpy(index->tvar[target], song_idx.tvar[song_cur], sizeof index->tvar[target]);
}
index->rows[target].rsv[1] = 0;
index->rows[target].rsv[2] = SONG_MODE_TAG | (live.mode ? 1u : 0u);
memcpy(index->scene[target], song_idx.scene[song_cur], sizeof index->scene[target]);
memcpy(index->tsrc[target], song_idx.tsrc[song_cur], sizeof index->tsrc[target]);
memcpy(index->tvar[target], song_idx.tvar[song_cur], sizeof index->tvar[target]);
index->rows[target].rsv[2] = SONG_MODE_TAG | (!song_save_loop && live.mode ? 1u : 0u);
if (st_save(OBJ_SONGIDX, index, sizeof *index)) { ui_message("SAVE ERROR: RETRY"); return 2; }
memcpy(&song_idx, index, sizeof song_idx);
/* Keep the live draft metadata while updating the destination's library entry. */
if (!song_draft || target != song_cur) song_index_target(index, target);
if (!song_draft && target == song_cur) {
for (section = 0; section < 4u; section++) {
int rc = song_copy_section(section, current, name);
if (rc > 0) memcpy(&proj_slot[section], &proj_wire, sizeof proj_wire);
else memset(&proj_slot[section], 0, sizeof proj_slot[section]);
}
chain_config = song_idx.rows[target];
live.mode = !song_save_loop && live.mode;
if (song_save_loop) live.cur = proj_cur = 0;
live.dirty = 0;
}
song_idx_dirty = 0;
{ char b[4]; fmt_int(b, (int32_t)target + 1); ui_say("SAVED SONG ", b); }
{ char b[4]; fmt_int(b, (int32_t)target + 1); ui_say(song_save_loop ? "SAVED LOOP " : "SAVED SONG ", b); }
ui.force = 1;
return 0;
#else
@@ -86,3 +127,75 @@ static int song_save_as(uint32_t target, const char *name)
return 1;
#endif
}
/* Drop rows which would reference an erased part, moving scene/source/variation together. */
BTAPP_FN static void song_remove_parts(song_index_t *index, uint32_t target, uint32_t mask)
{
chain_config_t *c = &index->rows[target];
uint32_t r, w = 0, k;
for (r = 0; r < c->count; r++) {
uint32_t used = 1u << c->row[r].slot;
for (k = 0; k < NTRK; k++) {
uint32_t src = index->tsrc[target][r] >> (3u * k) & 7u;
if (src && src <= 4u) used |= 1u << (src - 1u);
}
if (used & mask) continue;
c->row[w] = c->row[r];
index->scene[target][w] = index->scene[target][r];
index->tsrc[target][w] = index->tsrc[target][r];
index->tvar[target][w++] = index->tvar[target][r];
}
c->count = (uint8_t)w; c->rsv[1] &= (uint8_t)~mask;
if (!w) c->rsv[2] = SONG_MODE_TAG;
for (; w < CHAIN_ROWS; w++) {
c->row[w] = (chain_row_t){0,1};
memset(&index->scene[target][w], 0, sizeof(scene_t));
index->tsrc[target][w] = index->tvar[target][w] = 0;
}
}
/* parts=0 erases a saved project; a part in a draft is RAM-only. Tombstone
* commits preserve each object's previous copy on a failed write. Multi-part
* erasure is not atomic across a power failure; a failed current-project erase
* keeps its RAM and queues completed parts for restoration. */
static int song_erase_parts(uint32_t target, uint32_t parts)
{
song_index_t *index = (song_index_t *)proj_wire_u.raw;
uint32_t mask = parts ? parts : 15u, done = 0, k;
int draft = parts && song_draft && target == song_cur;
if (!bt_hw_seg()) { ui_message("UPDATE PACKAGE"); return 1; }
if (target >= NSONG || transport_busy()) { ui_message("STOP TO ERASE"); return 1; }
if (draft) { memcpy(index, &song_idx, sizeof *index); index->rows[target] = chain_config; }
else if (song_saved_index(index)) { ui_message("SAVE INDEX ERROR"); return 1; }
song_remove_parts(index, target, mask);
#if FELUCCA_FLASH
if (!draft && !flash_ok) { ui_message("NO FLASH: NOT ERASED"); return 1; }
if (!draft && flash_ok) {
for (k = 0; k < 4u; k++) if ((mask >> k) & 1u) {
uint32_t obj = target ? OBJ_SONG1 + (target - 1u) * 4u + k : OBJ_PROJECT0 + k;
if (st_save(obj, 0, 0)) goto failed;
done |= 1u << k;
}
if (!parts && target == song_cur && st_save(OBJ_AUTOSAVE, 0, 0)) goto failed;
if (st_save(OBJ_SONGIDX, index, sizeof *index)) goto failed;
}
#endif
if (!song_draft || target != song_cur || draft) song_index_target(index, target);
if (target == song_cur && (!song_draft || draft)) {
chain_config = song_idx.rows[target];
for (k = 0; k < 4u; k++) if ((mask >> k) & 1u) memset(&proj_slot[k], 0, sizeof proj_slot[k]);
live.dirty &= (uint8_t)~mask;
if (live.cur >= 0 && ((mask >> live.cur) & 1u)) live.cur = -1;
if (!chain_config.count) live.mode = 0;
if (!parts) { system_init(); proj_cur = PROJ_NO_SLOT; live.cur = -1; }
ui.song_row = 0;
}
proj_wire_gen++; ui.force = 1;
ui_message(parts ? "PART ERASED" : "PROJECT ERASED");
return 0;
#if FELUCCA_FLASH
failed:
if (target == song_cur && !song_draft) live.dirty |= (uint8_t)done;
proj_wire_gen++;
ui_message("ERASE ERROR: RETRY"); return 2;
#endif
}
+9 -6
View File
@@ -13,6 +13,10 @@ static uint32_t trk_eng(const track_t *t) { return t->eng_req % NENGINES; } /*
static const engine_t *trk_engp(const track_t *t) { return ENGINES[trk_eng(t)]; } /* .. its engine's table */
static int project_save(uint32_t slot);
static int song_save_as(uint32_t target, const char *name);
static int song_draft_begin(void);
static int song_erase_parts(uint32_t target, uint32_t parts);
static void song_poll(void);
static uint8_t song_save_loop;
static void song_name(char *b);
static uint8_t song_save_target __attribute__((section(".pool"))); /* destination picker: never opens the project */
static void panel_setup(void);
@@ -349,7 +353,7 @@ static uint16_t val_col(uint32_t c) { return c == ui.hot_col && ui.hot_t ? T_ACC
enum { CF_NONE, CF_CLEAR_SEQ, CF_CLEAR_TRK, CF_OVR_PROJ, CF_OVR_USER, CF_LOAD_PAT,
CF_DEL_ROW, CF_CLEAR_SONG, CF_INIT_SOUND, CF_CLEAR_MOTION, CF_ERASE_USER, CF_CLEAR_PFX,
CF_RECALL_SOUND, CF_CLEAR_ALL, CF_DICE_ALL, CF_INIT_SYS, CF_DICE_SOUND, CF_DICE_SEQ, CF_DICE_LFO,
CF_DICE_FX, CF_CPU_TEST, CF_MUT_BACK, CF_LIVE_COMMIT, CF_ERASE_SECT, CF_OVR_SONG }; /* ui.confirm: TOOLS' clears; (0.6.21) HOME + SELECT:
CF_DICE_FX, CF_CPU_TEST, CF_MUT_BACK, CF_LIVE_COMMIT, CF_ERASE_SECT, CF_OVR_SONG, CF_ERASE_SONG }; /* ui.confirm: TOOLS' clears; (0.6.21) HOME + SELECT:
* everything diced; (0.6.65) EDIT + SELECT: keep the diced sound?; (0.6.67) SEQ / LFO / FX + SELECT:
* keep the diced sequence / LFO / effects?;
* SAVE over a used slot; a pattern over the user's steps;
@@ -802,8 +806,7 @@ static void page_entered(void)
{
const page_t *pg = cur_page();
br_armed = 0;
if (pg->graph == GR_SONGSAVE && song_save_target == song_cur)
song_save_target = (uint8_t)((song_cur + 1u) % NSONG);
if (pg->graph == GR_SONGSAVE && !song_draft) song_save_target = song_cur;
ui.knob_ms = fm1_ms; /* (0.9.0) HUD: the knob row whole again on a new page */
if (!ui.home && pg->fam == FAM_FX && fx_trk_k(ui.page) < 0 && pg->graph != GR_BUSES)
ui.fxmod = (uint8_t)fx_mod_of(ui.page); /* (FX: the effect shown, BUSES' tile lit) */
@@ -1944,7 +1947,7 @@ static uint32_t act_cols(void) /* the columns that are actions
if (pg->graph == GR_SONGSAVE) return 8u;
if (pg->graph == GR_USER)
return 14u; /* LOAD ERASE SAVE */
if (pg->graph == GR_SLOTS && save_on() && save_level() == SV_PROJ)
if (pg->graph == GR_SLOTS && save_on())
return 14u; /* (V10.17) SECTIONS: ERASE LOAD SAVE */
if (pg->scope == SC_GLOBAL)
for (c = 0; c < 4u; c++)
@@ -1999,7 +2002,7 @@ static int act_ready(void)
uint32_t c = act_col(), s = song.sel, id;
if (!c--)
return 0;
if (cur_page()->graph == GR_SONGSAVE) return !transport_busy() && song_save_target != song_cur;
if (cur_page()->graph == GR_SONGSAVE) return !transport_busy();
if (cur_page()->graph == GR_MOTION) return !chain_busy() && motion_count(TSEL);
if (cur_page()->graph == GR_EVENTS) return ev_act_ready();
if (cur_page()->graph == GR_LYRIC) return 1;
@@ -2013,7 +2016,7 @@ static int act_ready(void)
if (cur_page()->graph == GR_USER)
return c == 3u ? !song.playing : up_used(ui.uslot) && (c == 1u || !song.playing);
if (cur_page()->graph == GR_SLOTS && c == 1u) /* (V10.17) SECTIONS: ERASE a stored section, stopped */
return project_used((uint32_t)song.g[G_SLOT] - 1u) && !transport_busy();
return !transport_busy() && (save_level() == SV_LIB || project_used((uint32_t)song.g[G_SLOT] - 1u));
id = cur_page()->id[c & 3u];
if (id == G_LOAD)
return project_used((uint32_t)song.g[G_SLOT] - 1u);
+11 -8
View File
@@ -1643,9 +1643,9 @@ static void draw_columns(void)
if (cur_page()->graph == GR_SONGSAVE) {
fmt_int(val, (int32_t)song_save_target + 1);
hot_gauge_column(0, "DEST", val, song_save_target * 1000 / (NSONG - 1u));
empty_column(1);
text_column(1, "SCOPE", song_save_loop ? "LOOP" : "SONG", T_TEXT);
empty_column(2);
draw_act_column(3, "SAVE SONG", T_THEME, ICON_AUTO);
draw_act_column(3, "SAVE", T_THEME, ICON_AUTO);
return;
}
if (cur_page()->graph == GR_SLOTS) { /* (0.6.12) PROJECT, SECT A-D, then LOAD and SAVE */
@@ -1656,10 +1656,9 @@ static void draw_columns(void)
hot_gauge_column(0, "SECT", val, (int32_t)(k & 3u) * 1000 / 3);
draw_act_column(1, "ERASE", used ? T_THEME : T_DIM, ICON_AUTO); /* (V10.17; the name: the card) */
} else {
fmt_int(val, (int32_t)song_cur + 1);
hot_gauge_column(0, "PROJECT", val, (int32_t)song_cur * 1000 / (int32_t)(NSONG - 1u));
val[0] = (char)('A' + (k & 3u)); val[1] = 0;
hot_gauge_column(1, "SECT", val, (int32_t)(k & 3u) * 1000 / 3);
fmt_int(val, (int32_t)(song_draft ? song_save_target : song_cur) + 1);
hot_gauge_column(0, "PROJECT", val, (int32_t)(song_draft ? song_save_target : song_cur) * 1000 / (int32_t)(NSONG - 1u));
draw_act_column(1, "ERASE", T_THEME, ICON_AUTO);
}
draw_act_column(2, "LOAD", used ? T_THEME : T_DIM, ICON_AUTO);
draw_act_column(3, "SAVE", T_THEME, ICON_AUTO);
@@ -2130,10 +2129,10 @@ static void confirm_text(char *a, char *b)
a[12] = (char)('1' + k % NTRK);
break;
case CF_OVR_SONG:
str_cpy(a, "REPLACE WHOLE SONG ", 24);
str_cpy(a, "OVERWRITE PROJECT ", 24);
fmt_int(a + str_len(a), (int32_t)k + 1);
str_cpy(a + str_len(a), "?", 2);
str_cpy(b, "ALL A-D + ARRANGEMENT", 24);
str_cpy(b, song_save_loop ? "LOOP A; CLEAR B-D" : "ALL A-D + ARRANGEMENT", 24);
break;
case CF_OVR_PROJ:
str_cpy(a, "OVERWRITE PROJECT A?", 24);
@@ -2192,6 +2191,10 @@ static void confirm_text(char *a, char *b)
str_cpy(a + str_len(a), "?", 2);
up_name(k, b); /* the sound stored there */
break;
case CF_ERASE_SONG:
str_cpy(a, "ERASE PROJECT ", 24); fmt_int(a + str_len(a), (int32_t)k + 1); str_cpy(a + str_len(a), "?", 2);
str_cpy(b, "ALL A-D + ARRANGEMENT", 24);
break;
case CF_ERASE_SECT: /* (V10.17) SAVE > SECTIONS > ERASE */
str_cpy(a, "ERASE SECT A?", 24);
a[11] = (char)('A' + (k & 3u));
+26 -8
View File
@@ -1444,6 +1444,9 @@ static void edit_param(uint32_t slot, int32_t steps)
ui.force = 1;
return;
}
if (pg->graph == GR_SONGSAVE && slot == 1u) {
song_save_loop = (uint8_t)clamp((int32_t)song_save_loop + steps, 0, 1); return;
}
if (pg->graph == GR_SONGSAVE && slot == 0u) {
song_save_target = (uint8_t)clamp((int32_t)song_save_target + steps, 0, NSONG - 1);
return;
@@ -1466,8 +1469,9 @@ static void edit_param(uint32_t slot, int32_t steps)
}
sect:
if (pg->graph == GR_SLOTS && slot == 0u) { /* (0.6.12) KNOB 1 the project: its sections, the music kept */
int32_t n = clamp((int32_t)song_cur + (steps > 0 ? 1 : -1), 0, (int32_t)NSONG - 1);
if ((uint32_t)n != song_cur) (void)song_open((uint32_t)n);
int32_t n = clamp((int32_t)(song_draft ? song_save_target : song_cur) + (steps > 0 ? 1 : -1), 0, (int32_t)NSONG - 1);
if (song_draft) song_save_target = (uint8_t)n;
else if ((uint32_t)n != song_cur) (void)song_open((uint32_t)n);
return;
}
if (pg->graph == GR_USER) { /* KNOB 1 the slot */
@@ -1632,19 +1636,30 @@ static void act_do(void)
char title[13];
ui.act = 0;
if (transport_busy()) ui_message("STOP TO SAVE");
else if (song_save_target == song_cur) ui_message("CHOOSE ANOTHER PROJECT");
else if (lib_scan(song_save_target, title) || song_idx.rows[song_save_target].count)
else if (lib_scan(song_save_target, title) || ((!song_draft || song_save_target != song_cur) && song_idx.rows[song_save_target].count))
confirm_open(CF_OVR_SONG, song_save_target);
else name_open(NK_SONG_SAVE, song_save_target);
return;
}
if (cur_page()->graph == GR_SLOTS && save_level() == SV_LIB) {
uint32_t target = song_draft ? song_save_target : song_cur;
if (c == 1u) {
ui.act = 0;
if (transport_busy()) ui_message("STOP TO ERASE");
else confirm_open(CF_ERASE_SONG, target);
} else if (c == 2u && song_draft) (void)song_select(target);
else if (c == 3u) nav_put(SEC_SAVE, "SAVE SONG AS");
else goto slot_action;
return;
}
if (cur_page()->graph == GR_SLOTS && c == 1u) { /* (V10.17) SECTIONS: ERASE, the dialog first */
ui.act = 0;
if (transport_busy()) ui_message("STOP TO ERASE");
else if (!project_used(k)) ui_message("EMPTY SECTION");
else confirm_open(CF_ERASE_SECT, k);
else confirm_open(CF_ERASE_SECT, (song_cur << 2u) | (k & 3u));
return;
}
slot_action:
id = cur_page()->id[c & 3u];
if (id != G_LOAD)
ui.act = 0;
@@ -2563,7 +2578,7 @@ static void ui_input_frame(void)
uint32_t kind = ui.confirm;
ui.confirm = 0;
ui.force = 1;
if (kind != CF_OVR_PROJ && kind != CF_OVR_USER && kind != CF_ERASE_USER && kind != CF_ERASE_SECT && kind != CF_OVR_SONG && kind != CF_DICE_ALL &&
if (kind != CF_OVR_PROJ && kind != CF_OVR_USER && kind != CF_ERASE_USER && kind != CF_ERASE_SECT && kind != CF_OVR_SONG && kind != CF_ERASE_SONG && kind != CF_DICE_ALL &&
!dice_kind(kind) && kind != CF_DEL_ROW && kind != CF_CLEAR_SONG && !chain_busy())
undo_mark(); /* (0.6.21) the music before a clear, INIT, RECALL, pattern */
if (kind == CF_OVR_PROJ) { /* overwrite: the NAME screen writes it */
@@ -2574,8 +2589,11 @@ static void ui_input_frame(void)
name_open(NK_USER_SAVE, ui.confirm_trk);
} else if (kind == CF_ERASE_USER) {
up_ui(1u, ui.confirm_trk);
} else if (kind == CF_ERASE_SONG) {
song_erase_parts(ui.confirm_trk, 0);
} else if (kind == CF_ERASE_SECT) {
project_erase(ui.confirm_trk & 3u);
if ((ui.confirm_trk >> 2u) == song_cur) project_erase(ui.confirm_trk & 3u);
else ui_message("PROJECT CHANGED");
} else if (dice_kind(kind)) { /* (0.6.65) OK: the diced part stays */
ui_message(dk.msg);
} else if (kind == CF_LOAD_PAT) {
@@ -2798,7 +2816,7 @@ static void ui_input_frame(void)
if (b & 1u)
page_tap(panel_btn_of(id));
if (gen_on() && (oct & 2u)) { /* (0.9.2) GEN, HOME's pages: OCT+ the piece (the screen stays, */
if (!chain_busy()) gen_press(); /* OCT+ again: another), OCT- back to ECO */
gen_press(); /* OCT+ again: another), OCT- back to ECO */
} else if (gen_on() && (oct & 1u)) {
nav_go(SEC_HOME, 0, 0);
} else if (act_cols() && (oct & 2u)) { /* action pages: OCT+ does the picked action, */
-4
View File
@@ -220,10 +220,6 @@ static void nav_go(uint32_t sec, uint32_t e, int outside)
if (sec == SEC_HOME) {
if (e >= 4u) { /* GEN: the generator's screen, HOME's last group */
if (!gen_on()) {
if (chain_busy()) {
ui_message("SONG PLAYS: STOP IT TO EDIT");
return;
}
confirm_open(CF_DICE_ALL, song.sel);
gen_open();
}
+2 -2
View File
@@ -28,8 +28,8 @@ static void graph_lib(void)
uint32_t i, j;
for (i = 0; i < NSONG; i++) {
int32_t x = LZ_TX(i % 4u), y = (int32_t)(i / 4u) * 70;
int cur = i == song_cur;
int pick = cur_page()->graph == GR_SONGSAVE ? i == song_save_target : cur;
int cur = i == song_cur && !song_draft;
int pick = cur_page()->graph == GR_SONGSAVE || song_draft ? i == song_save_target : cur;
uint16_t bg = pick ? T_TINT : T_RAISE;
char b[4], nm[13];
cv_rect(x, y, 56, 66, bg);
+2 -2
View File
@@ -94,7 +94,7 @@ static void name_open(uint32_t kind, uint32_t slot)
return;
}
if (kind == NK_SONG_SAVE) {
str_cpy(nm.ph, "SONG", sizeof nm.ph);
str_cpy(nm.ph, song_save_loop ? "LOOP" : "SONG", sizeof nm.ph);
song_name(b);
} else if (kind == NK_USER_SAVE || kind == NK_USER_RENAME) {
uint32_t e = kind == NK_USER_RENAME ? up_engine(slot) : TSEL->eng_req;
@@ -327,7 +327,7 @@ static uint32_t name_leds(void)
static void nm_title(char *b)
{
if (nm.kind == NK_SONG_SAVE) {
str_cpy(b, "SAVE SONG TO PROJECT ", 24);
str_cpy(b, song_save_loop ? "SAVE LOOP TO PROJECT " : "SAVE SONG TO PROJECT ", 24);
fmt_int(b + str_len(b), (int32_t)nm.slot + 1);
return;
}
+2 -2
View File
@@ -521,8 +521,8 @@ int main(void)
ok = live.mode == 1 && chain_config.count == 6u && (dice_secs & 15u) == 15u;
section_store(1);
gen_with(1, 33, 60, 2);
ok &= live.mode == 1 && chain_config.count == 6u && str_eq(ui.msg2, "USE AN EMPTY PROJECT");
bad += gcheck("FORM after a power cycle: the song written again; a section of the player's kept, and said", ok);
ok &= live.mode == 1 && chain_config.count == 6u && song_draft && !gform_kept;
bad += gcheck("FORM generates a complete draft even when prior parts were stored", ok);
}
}
/* ---- (0.6.97) the kit's space, the top end's variety, Hook's register, the lead's envelope */
+4
View File
@@ -76,6 +76,7 @@ static int check(const char *what, int ok)
static void reset(void)
{
song_draft = song_save_loop = 0;
memset(nor, 0xFF, sizeof nor);
memset(&song, 0, sizeof song);
memset(trk, 0, sizeof trk);
@@ -506,6 +507,7 @@ static int songs_test(void)
#include "voice_user_cases.h"
#include "split_storage_cases.h"
#ifndef PERSISTENCE_TEST_NO_MAIN
int main(void)
{
int bad = 0, ok;
@@ -860,3 +862,5 @@ int main(void)
return bad != 0;
}
#endif
+76
View File
@@ -0,0 +1,76 @@
/* 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();
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));
assert(song_draft&&chain_config.count==4);
puts("draft: saving a full song elsewhere preserves the original project and current draft");
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&&chain_config.count==4&&song_draft);
puts("draft: LOOP writes current music to A, empties B-D and saves no arrangement");
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&&chain_config.count==4);
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"));
puts("draft: same-project overwrite is explicit; failed saves retain the draft for retry");
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));
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: saved project deletion preserves the draft; deleting a draft part 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);
puts("save: an existing open project can be explicitly replaced with one loop");
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");
return 0;
}
+24 -18
View File
@@ -61,26 +61,32 @@ int main(void)
seq_stop(); song_poll(); frame();
press(B_SAVE); frame();
bad += check("SAVE from GEN opens whole-song destination without changing source",
cur_page()->graph == GR_SONGSAVE && song_save_target != song_cur && !name_on());
cur_page()->graph == GR_SONGSAVE && song_save_target == song_cur && !name_on());
/* Saved user sections must never cause SONG generation to degrade silently
* into a new loop while erasing the arrangement. */
/* A saved/non-generated section is no longer a dead end. GEN owns only
* the draft buffers and may replace them, even while the previous song plays. */
make_song(1, 31);
section_store(1);
chain_config_t rows = chain_config;
uint32_t slots = proj_hash(proj_slot, sizeof proj_slot), music = dice_print();
gp.seed = 32; gen_go();
bad += check("protected A-D refuses before changing music, sections, mode or arrangement",
gform_kept && live.mode && !memcmp(&rows, &chain_config, sizeof rows) &&
music == dice_print() && slots == proj_hash(proj_slot, sizeof proj_slot) &&
str_eq(ui.msg2, "USE AN EMPTY PROJECT"));
song_poll();
live.mode = 0; song_index_boot();
bad += check("saved SONG mode survives boot of the same project", live.mode == 1);
live.mode = 0; song_poll();
live.mode = 1; song_index_boot();
bad += check("explicit LOOP mode also survives boot", live.mode == 0);
section_store(1); live.mode = 1;
nav_put(SEC_HOME, "GEN 2"); frame();
press(B_PLAY); events_block(CTL); song_poll();
uint32_t before_seed = gp.seed; gp.sig = gen_sig();
press(B_OCTUP); events_block(CTL); song_poll(); frame();
bad += check("GEN 2 rerolls a playing song as a draft and resumes arrangement playback",
song_draft && !gform_kept && chain_config.count >= 4 && song.playing && chain.running && gp.seed != before_seed);
screen_save("build/song-check", "generator-draft-page2");
nav_put(SEC_HOME, "GEN 3"); frame();
bad += check("GEN 3 keeps real parts visible while editing generator settings", gen_page()==2 && chain_config.count>=4);
screen_save("build/song-check", "generator-draft-page3");
seq_stop();song_poll();
nav_put(SEC_SAVE,"SAVE SONG AS");frame();turn(EN_K2,1);frame();
bad += check("SAVE scope selects LOOP without changing the live song", song_save_loop && chain_config.count>=4);
song_save_loop=0;
/* Draft arrangements intentionally do not overwrite the saved boot index. */
song_draft=0;song_poll();
live.mode=0;song_index_boot();
bad += check("committed SONG mode survives boot", live.mode==1);
live.mode=0;song_poll();live.mode=1;song_index_boot();
bad += check("committed LOOP mode survives boot", live.mode==0);
chain_config_t old = chain_config;
old.rsv[2] = 0; song_idx.rows[song_cur] = old;
live.mode = 0; song_index_boot();
+2 -2
View File
@@ -78,10 +78,10 @@ static int song_save_test(void)
before = erases;
song.playing = 1; ok = song_save_as(1, "X") != 0; song.playing = 0;
transport_req = 1; ok &= song_save_as(1, "X") != 0; transport_req = 0;
ok &= song_save_as(0, "X") != 0 && song_save_as(8, "X") != 0;
ok &= song_save_as(8, "X") != 0;
flash_ok = 0; ok &= song_save_as(1, "X") != 0; flash_ok = 1;
ok &= erases == before;
bad += check("playing, pending PLAY, same slot, invalid slot and no flash refuse without writing", ok);
bad += check("playing, pending PLAY, invalid slot and no flash refuse without writing", ok);
song_fixture();
memset(&proj_slot[3], 0, sizeof proj_slot[3]);
+6 -4
View File
@@ -11,8 +11,8 @@ static int test_song_save_ui(void)
live.cur = -1;
name_close();
nav_put(SEC_SAVE, "SAVE SONG AS"); frame();
ok = cur_page()->graph == GR_SONGSAVE && save_level() == SV_PROJ && ui.act == 4u && song_save_target != song_cur;
bad += check("SAVE SONG AS is a PROJECT page with SAVE armed and another destination", ok);
ok = cur_page()->graph == GR_SONGSAVE && save_level() == SV_PROJ && ui.act == 4u && song_save_target == song_cur;
bad += check("SAVE SONG AS is a PROJECT page with SAVE armed and the current destination", ok);
target = song_save_target;
turn(EN_K1, 1); frame();
ok = song_save_target == target + 1u && song_cur == 0 && live.cur == -1;
@@ -28,7 +28,7 @@ static int test_song_save_ui(void)
turn(EN_K4, 1); press(B_OCTUP); frame();
ok = ui.confirm == CF_OVR_SONG && !name_on();
confirm_text(a, b);
ok &= strstr(a, "REPLACE WHOLE SONG") != 0 && !strcmp(b, "ALL A-D + ARRANGEMENT");
ok &= strstr(a, "OVERWRITE PROJECT") != 0 && !strcmp(b, "ALL A-D + ARRANGEMENT");
press(B_OCTDN); frame();
ok &= !ui.confirm && !name_on();
bad += check("occupied destination asks whole-song overwrite; cancel writes nothing", ok);
@@ -41,7 +41,9 @@ static int test_song_save_ui(void)
bad += check("overwrite confirmation leads to naming; failed save keeps the name open", ok);
song_save_target = song_cur;
turn(EN_K4, 1); press(B_OCTUP); frame();
bad += check("current project is refused, so SAVE AS cannot overwrite its source", !name_on() && !ui.confirm && strstr(ui.msg, "ANOTHER PROJECT") != 0);
bad += check("current project is available as an explicit save destination", name_on() || ui.confirm == CF_OVR_SONG);
if (name_on()) { press(B_OCTDN); frame(); }
else if (ui.confirm) { press(B_OCTDN); frame(); }
song_save_target = 2;
song.playing = 1;
turn(EN_K4, 1); press(B_OCTUP); frame();
+9 -6
View File
@@ -175,6 +175,7 @@ static int check(const char *what, int ok)
static void ui_power_on(void)
{
uint32_t i;
song_draft = song_save_loop = 0;
memset(split_cfg, 0, sizeof split_cfg); memset(&midi_map, 0, sizeof midi_map);
if (!lyb_ok)
sing_init(); /* (0.9.0: as felucca_init, VOICE's English generator words) */
@@ -7565,7 +7566,9 @@ static int test_save_lens(void)
ok &= song_cur == 0u && (TSEL->preset != pr || TSEL->eng_req != trk_def_engine(0)) && cur_page()->graph == GR_SLOTS;
bad += check("0.9.2 SAVE > PROJECTS: KNOB 1 the project; PRESETS a sound (was the project)", ok);
ok = 1;
turn(EN_K4, 1); press(B_OCTUP); frame(); /* SAVE: the NAME screen, its own layout */
turn(EN_K4, 1); press(B_OCTUP); frame(); /* PROJECTS opens explicit save scope first. */
ok &= cur_page()->graph == GR_SONGSAVE && !name_on();
press(B_OCTUP); frame();
ok &= name_on() && !lz_on();
press(B_OCTDN); frame();
ok &= !name_on() && lz_on();
@@ -8815,11 +8818,11 @@ static int test_project_page(void)
ok = song_cur == 1 && trk[0].step[0].note[0] == 80 && live.cur < 0 && !chain_config.count && msg_is("PROJECT 2");
bad += check(" KNOB 1: project 2 in (its sections, its song), the music kept", ok);
song.g[G_SLOT] = 1;
turn(EN_K2, 1); frame(); /* LIBRARY: KNOB 2 the section */
ok = song.g[G_SLOT] == 2 && save_level() == SV_LIB;
turn(EN_K2, 1); frame(); /* PROJECTS: KNOB 2 selects ERASE, never a different part. */
ok = song.g[G_SLOT] == 1 && save_level() == SV_LIB && ui.act == 2;
turn(EN_SELECT, -1); frame(); /* (V10.1) SONG's SECTIONS (one back): KNOB 1 */
ok &= save_level() == SV_PROJ && cur_page()->graph == GR_SLOTS;
turn(EN_K1, 1); frame();
turn(EN_K1, 2); frame();
ok &= song.g[G_SLOT] == 3;
turn(EN_K1, 1); frame();
ok &= song.g[G_SLOT] == 4 && song_cur == 1;
@@ -8829,7 +8832,7 @@ static int test_project_page(void)
ok &= ui.act == 0u;
turn(EN_K1, -1); frame();
ok &= song.g[G_SLOT] == 3;
bad += check(" LIBRARY's KNOB 2, SECTIONS' KNOB 1: the section (C); SECTIONS' KNOB 2 ERASE (V10.17)", ok);
bad += check(" PROJECTS KNOB 2 ERASE; SECTIONS KNOB 1 selects C, KNOB 2 erases the part", ok);
turn(EN_K4, 1); press(B_OCTUP); frame(); /* SAVE into project 2's C: the NAME screen, then OK */
for (k = 0; k < 8u && name_on(); k++) { press(B_OCTUP); frame(); }
ok = project_used(2) && live.cur == 2;
@@ -8843,7 +8846,7 @@ static int test_project_page(void)
press(B_OCTDN); frame();
ok &= !ui.confirm && project_used(2);
turn(EN_K2, 1); press(B_OCTUP); frame(); press(B_OCTUP); frame(); /* .. OCT+ erases it */
ok &= !ui.confirm && !project_used(2) && live.cur < 0 && msg_is("ERASED SECT C") && trk[0].step[0].note[0] == 80;
ok &= !ui.confirm && !project_used(2) && live.cur < 0 && msg_is("PART ERASED") && trk[0].step[0].note[0] == 80;
turn(EN_K2, 1); press(B_OCTUP); frame(); /* (empty now: no dialog) */
ok &= !ui.confirm;
bad += check("V10.17 SECTIONS KNOB 2 ERASE: the dialog (ERASE SECT C?), then EMPTY; the music stays; not playing", ok);
+3 -1
View File
@@ -103,7 +103,9 @@ def main(src, dst):
# Sparse MIDI control dispatch runs per received message, never per rendered sample.
# Keep synthesis, clocks, DMA, note release and ownership queries at -Os.
input_size = {"midi_event", "midi_control", "midi_cc_map", "midi_cc_set", "midi_learned", "midi_route_ch14"}
names, hit = (size_names() - isr) | input_size, set()
cold_ui = {"mod_dst_ok", "mod_dst_offer_bt", "mod_dst_name_bt", "gen_value", "gen_cards_bt", "gen_panel_bt",
"song_index_target", "song_remove_parts"}
names, hit = ((size_names() | cold_ui) - isr) | input_size, set()
def mark(m):
if m.group(2) not in names: