From d679c8f30412d5db9c2c2f0e0bc8445fbcd64f56 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 22:40:33 +0000 Subject: [PATCH] DRUM-X kit in the section: project format FUNA - dx_kit is the music's DRUM-X kit (KIT X plays it); FUNA (3744 bytes) is FUN9 with the kit (88 bytes + 8 reserved) at 3120, before the FM6 patches. FUN9 and older load with the factory kit; a kit value out of range is neither packed nor loaded. - project_capture / restore carry the kit; the song stages it with the section and the ISR swaps it in on the bar. - Tests: layout, kit round trip, refusal, a FUN9 of Felucca 1.1 loading. EDITOR_PROTOCOL.md: FUNA. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh --- firmware/src/drumx_voice.c | 39 ++++++++++++++++++++-------- firmware/src/eng_drum.c | 2 +- firmware/src/project.c | 47 ++++++++++++++++++++++++++-------- firmware/src/song_chain.c | 5 ++-- firmware/src/song_main.c | 1 + firmware/src/song_play.c | 1 + firmware/src/ui_graph.c | 2 +- tests/backup_test.c | 4 +-- tests/motion_test.c | 6 ++--- tests/project_test.c | 52 ++++++++++++++++++++++++++++++++------ web/EDITOR_PROTOCOL.md | 15 +++++++---- 11 files changed, 130 insertions(+), 44 deletions(-) diff --git a/firmware/src/drumx_voice.c b/firmware/src/drumx_voice.c index 5286a7ea..8d867f16 100644 --- a/firmware/src/drumx_voice.c +++ b/firmware/src/drumx_voice.c @@ -148,14 +148,31 @@ static __attribute__((noinline)) void dx_run(const dx_lane_t *L, dx_voice_t *v, v->live = 0; } -/* the kit DRUM-X's first step plays (DRUM KIT X): {mode, A, B}, A {PITCH PMOD DECAY NOISE COLOR} */ -static const dx_lane_t DX_KIT_DEF[8] = { - {DX_MODE(DXW_SINE, DXF_LP, 1), {9, 70, 72, 4, 20}, {14, 100, 88, 10, 60}}, /* KICK */ - {DX_MODE(DXW_FM, DXF_BP, 0), {40, 30, 52, 80, 90}, {46, 18, 64, 104, 70}}, /* SNARE */ - {DX_MODE(DXW_SINE, DXF_BP, 0), {60, 0, 46, 127, 84}, {54, 0, 58, 127, 76}}, /* CLAP */ - {DX_MODE(DXW_METAL, DXF_HP, 0), {100, 0, 22, 96, 116}, {108, 0, 14, 112, 122}}, /* HAT CL */ - {DX_MODE(DXW_METAL, DXF_HP, 0), {100, 0, 62, 96, 112}, {108, 0, 74, 112, 118}}, /* HAT OP */ - {DX_MODE(DXW_SINE, DXF_LP, 1), {30, 40, 66, 10, 30}, {36, 60, 76, 20, 50}}, /* TOM */ - {DX_MODE(DXW_BELL, DXF_HP, 1), {63, 10, 14, 16, 46}, {70, 24, 20, 30, 60}}, /* RIM */ - {DX_MODE(DXW_METAL, DXF_BP, 0), {69, 0, 72, 0, 40}, {74, 0, 84, 12, 56}}, /* BELL */ -}; +/* the factory kit (DRUM's KIT X): {mode, A, B}, A and B {PITCH PMOD DECAY NOISE COLOR}. dx_kit is the music's + * kit: a section's (project.c keeps it in the project, the song stages it with the section), edited on EDIT > + * SOUND (ui_input.c); DX_KIT_DEF what a project without one gets */ +#define DX_KIT_INIT { \ + {DX_MODE(DXW_SINE, DXF_LP, 1), {9, 70, 72, 4, 20}, {14, 100, 88, 10, 60}}, /* KICK */ \ + {DX_MODE(DXW_FM, DXF_BP, 0), {40, 30, 52, 80, 90}, {46, 18, 64, 104, 70}}, /* SNARE */ \ + {DX_MODE(DXW_SINE, DXF_BP, 0), {60, 0, 46, 127, 84}, {54, 0, 58, 127, 76}}, /* CLAP */ \ + {DX_MODE(DXW_METAL, DXF_HP, 0), {100, 0, 22, 96, 116}, {108, 0, 14, 112, 122}}, /* HAT CL */ \ + {DX_MODE(DXW_METAL, DXF_HP, 0), {100, 0, 62, 96, 112}, {108, 0, 74, 112, 118}}, /* HAT OP */ \ + {DX_MODE(DXW_SINE, DXF_LP, 1), {30, 40, 66, 10, 30}, {36, 60, 76, 20, 50}}, /* TOM */ \ + {DX_MODE(DXW_BELL, DXF_HP, 1), {63, 10, 14, 16, 46}, {70, 24, 20, 30, 60}}, /* RIM */ \ + {DX_MODE(DXW_METAL, DXF_BP, 0), {69, 0, 72, 0, 40}, {74, 0, 84, 12, 56}}, /* BELL */ \ +} +static const dx_lane_t DX_KIT_DEF[8] = DX_KIT_INIT; +static dx_lane_t dx_kit[8] = DX_KIT_INIT; +/* a stored kit as the voice takes it: values 0..127, the mode's fields in range (wave 0..3, filter 0..2, snap) */ +static int dx_kit_ok(const dx_lane_t *k) +{ + uint32_t l, i; + for (l = 0; l < 8u; l++) { + if ((k[l].mode & ~0x1Fu) || ((k[l].mode >> 2) & 3u) > DXF_HP) + return 0; + for (i = 0; i < DXP_N; i++) + if (k[l].a[i] > 127u || k[l].b[i] > 127u) + return 0; + } + return 1; +} diff --git a/firmware/src/eng_drum.c b/firmware/src/eng_drum.c index b99ed84e..9888d15c 100644 --- a/firmware/src/eng_drum.c +++ b/firmware/src/eng_drum.c @@ -286,7 +286,7 @@ static void drum_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const if (n > CTL) n = CTL; if (drum_kit_plays(p[P_E0]) == DK_X) { /* DRUM-X: SNAP is MORPH, TUNE TONE DECY move every lane */ - dx_run(&DX_KIT_DEF[(uint32_t)v->s[0] & (DV_NLANE - 1u)], &L->x, p[P_E4], L->st * 16 + (p[P_E1] - 64) * 3, + dx_run(&dx_kit[(uint32_t)v->s[0] & (DV_NLANE - 1u)], &L->x, p[P_E4], L->st * 16 + (p[P_E1] - 64) * 3, p[P_E3] - 64, p[P_E2] - 64, y, n); } else { r = L->role; diff --git a/firmware/src/project.c b/firmware/src/project.c index 5e4a29a4..65e7944b 100644 --- a/firmware/src/project.c +++ b/firmware/src/project.c @@ -48,6 +48,11 @@ * its 91 parameters mapped by count: the lane levels 100 %) and FUN7 are read; the retained cache grew again (its * slot 1 still starts with the older record, read as above). * + * Format A ("FUNA", written since JIANT 0.1) = FUN9 with 96 more bytes: the section's DRUM-X kit (drumx_voice.c + * dx_lane_t[8], 88 bytes, then 8 reserved, written 0) at PROJ_DX_OFF, just before the FM6 patches. 3744 bytes (a + * flash object holds 3840); the serialized part still ends by 3120 (FUN9's 48 spare bytes stay). FUN9 is read + * (its kit: the factory one, DX_KIT_DEF), as every older format. + * * Parameter locks (1.1, core.h MOTION_LOCK) are motion records with bit 7 of their id byte set (P_COUNT 99 < 128: * the bit is free): no byte moved for them, and every project before 1.1 has none. FUN9 holds them. A FUN8 / FUN7 * record of a 1.1 development build may hold some: on load their ids move to today's positions as the others do, @@ -70,7 +75,8 @@ * * Built on the Mac too (tests/project_test.c, -DPROJ_HOST): the part above the #ifndef * PROJ_HOST needs core.h, params.c (TP) and engines.c. */ -#define PROJ_MAGIC 0x46554E39u /* "FUN9": FUN8, 64 bytes longer (the DRUM lane levels, 99 parameters) */ +#define PROJ_MAGIC 0x46554E41u /* "FUNA": FUN9 + the DRUM-X kit (JIANT) */ +#define PROJ_MAGIC_V9 0x46554E39u /* "FUN9": FUN8, 64 bytes longer (the DRUM lane levels, 99 parameters) */ #define PROJ_MAGIC_V8 0x46554E38u /* "FUN8": FUN7 + the tracks' FM6 patches */ #define PROJ_MAGIC_V7 0x46554E37u /* "FUN7": serialized (byte params, packed steps), chain, motion */ #define PROJ_MAGIC_V6 0x46554E36u /* FUN6: 69 parameters, drum grid, chain */ @@ -102,6 +108,7 @@ typedef struct { chain_config_t chain; motion_store_t motion; uint8_t fm6[NTRK][FM6_PACKED]; /* each track's FM6 patch, packed (eng_fm6.c) */ + dx_lane_t dx[8]; /* the DRUM-X kit (drumx_voice.c) */ char name[PROJ_NAME_LEN]; /* the project's name: upper-case ASCII 32..126, 0-padded; "" = none */ uint32_t sum; } project_t; @@ -125,14 +132,18 @@ _Static_assert(sizeof(project_v5_t) == 3352u && sizeof(project_v6_t) == 3388u, " * never reads them, so every FUN7 file stays valid both ways; FUN6..FUN1 imports get no name. * FUN8: the same, 3584 bytes, the four packed FM6 patches at PROJ_FM6_OFF (before the name); 16 bytes of the * reserved tail were left for parameters added later. FUN9: the same, 3648 bytes (see the top). */ -#define PROJ_STORE_SIZE 3648u /* FUN9 */ +#define PROJ_STORE_SIZE 3744u /* FUNA */ +#define PROJ_STORE_V9 3648u /* FUN9 */ #define PROJ_STORE_V8 3584u /* FUN8 */ #define PROJ_STORE_V7 3388u /* FUN7 */ #define PROJ_NAME_OFF (PROJ_STORE_SIZE - 4u - PROJ_NAME_LEN) #define PROJ_FM6_OFF (PROJ_NAME_OFF - NTRK * FM6_PACKED) +#define PROJ_DX_SIZE 96u /* the kit, 88 bytes, and 8 reserved */ +#define PROJ_DX_OFF (PROJ_FM6_OFF - PROJ_DX_SIZE) typedef union { uint32_t align; uint8_t raw[PROJ_STORE_SIZE]; } project_store_t; _Static_assert(G_COUNT == 27u, "FUN7 globals retain original IDs"); -_Static_assert(sizeof(project_store_t) == 3648u && PROJ_STORE_V7 == sizeof(project_v6_t), "FUN9 / FUN7 sizes"); +_Static_assert(sizeof(project_store_t) == 3744u && PROJ_STORE_V7 == sizeof(project_v6_t), "FUNA / FUN7 sizes"); +_Static_assert(sizeof(dx_lane_t[8]) == 88u && PROJ_DX_OFF == 3120u, "the kit's place: where FUN9's patches were"); typedef struct { /* a track of format 4, read only */ int16_t p[PROJ_NP_V4]; uint8_t engine, preset; @@ -474,12 +485,13 @@ static int proj_from_v1(project_t *q, const project_v1_t *v1, int n) /* n bytes of a stored project (any format) -> slot q as format 6; 0 = not a project */ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t size); -/* the init patch on every track (a project of a format before FUN8) */ +/* the init patch on every track (a project of a format before FUN8), the factory DRUM-X kit (before FUNA) */ static void proj_fm6_init(project_t *q) { uint32_t t; for (t = 0; t < NTRK; t++) memcpy(q->fm6[t], FM6_INIT, FM6_PACKED); + memcpy(q->dx, DX_KIT_DEF, sizeof q->dx); q->sum = proj_sum(q); } static int proj_import_old(project_t *q, const void *b, int n); @@ -512,6 +524,8 @@ static int proj_import_any(project_t *q, const void *b, int n) if (n == PROJ_STORE_SIZE && ((const uint32_t *)b)[1] >= 8u && ((const uint32_t *)b)[1] < PROJ_STORE_SIZE) n = (int)((const uint32_t *)b)[1]; /* a retained slot holding an older, shorter record: its own size * (every format checks its magic and hash) */ + if (n == (int)PROJ_STORE_V9 && ((const uint32_t *)b)[0] == PROJ_MAGIC_V9) + return proj_unpack(q, b, PROJ_STORE_V9); if (n == (int)PROJ_STORE_V8 && ((const uint32_t *)b)[0] == PROJ_MAGIC_V8) return proj_unpack(q, b, PROJ_STORE_V8); if (n == (int)PROJ_STORE_V7 && ((const uint32_t *)b)[0] == PROJ_MAGIC_V7) @@ -608,9 +622,10 @@ static int proj_pack(project_store_t *out, const project_t *q) b[pos++] = (uint8_t)(s->probability | (r >> 1) << 7); } } - if (pos + sizeof q->chain + sizeof q->motion > PROJ_FM6_OFF) return 0; + if (pos + sizeof q->chain + sizeof q->motion > PROJ_DX_OFF || !dx_kit_ok(q->dx)) return 0; memcpy(b + pos, &q->chain, sizeof q->chain); pos += sizeof q->chain; memcpy(b + pos, &q->motion, sizeof q->motion); + memcpy(b + PROJ_DX_OFF, q->dx, sizeof q->dx); memcpy(b + PROJ_FM6_OFF, q->fm6, sizeof q->fm6); { /* the name (0-padded; stops at the first 0) */ char n[PROJ_NAME_LEN + 1u]; @@ -635,14 +650,16 @@ static int proj_motion_ids(motion_store_t *m, uint32_t np) } return 1; } -/* a stored FUN9 (st = PROJ_STORE_SIZE), FUN8 (PROJ_STORE_V8: the same, its tail 64 bytes shorter) or FUN7 - * (PROJ_STORE_V7: no patches, the init one) */ +/* a stored FUNA (st = PROJ_STORE_SIZE), FUN9 (PROJ_STORE_V9: no kit, the factory one), FUN8 (PROJ_STORE_V8: as FUN9, + * its tail 64 bytes shorter) or FUN7 (PROJ_STORE_V7: no patches, the init one) */ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) { - uint32_t pos = 68u, t, i, magic, size, sum, np = b[66], v7 = st == PROJ_STORE_V7; - uint32_t name_off = st - 4u - PROJ_NAME_LEN, end = v7 ? name_off : name_off - NTRK * FM6_PACKED; + uint32_t pos = 68u, t, i, magic, size, sum, np = b[66], v7 = st == PROJ_STORE_V7, va = st == PROJ_STORE_SIZE; + uint32_t name_off = st - 4u - PROJ_NAME_LEN, fm6_off = name_off - NTRK * FM6_PACKED; + uint32_t end = v7 ? name_off : va ? fm6_off - PROJ_DX_SIZE : fm6_off; memcpy(&magic, b, 4); memcpy(&size, b + 4, 4); memcpy(&sum, b + st - 4u, 4); - if (magic != (v7 ? PROJ_MAGIC_V7 : st == PROJ_STORE_V8 ? PROJ_MAGIC_V8 : PROJ_MAGIC) || size != st || sum != proj_hash(b, st - 4u) || + if (magic != (v7 ? PROJ_MAGIC_V7 : st == PROJ_STORE_V8 ? PROJ_MAGIC_V8 : st == PROJ_STORE_V9 ? PROJ_MAGIC_V9 : PROJ_MAGIC) || + size != st || sum != proj_hash(b, st - 4u) || np < 8u || np > P_COUNT || 68u + NTRK * (np + 2u + NSTEP * 9u) + sizeof q->chain + sizeof q->motion > end) return 0; memset(q, 0, sizeof *q); q->magic = PROJ_MAGIC; q->size = sizeof *q; @@ -677,7 +694,13 @@ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) memcpy(q->fm6[t], FM6_INIT, FM6_PACKED); else for (i = 0; i < FM6_PACKED; i++) - q->fm6[t][i] = b[end + t * FM6_PACKED + i] & 0x7Fu; + q->fm6[t][i] = b[fm6_off + t * FM6_PACKED + i] & 0x7Fu; + } + if (va) { /* the DRUM-X kit (a broken one: not a project) */ + memcpy(q->dx, b + end, sizeof q->dx); + if (!dx_kit_ok(q->dx)) return 0; + } else { + memcpy(q->dx, DX_KIT_DEF, sizeof q->dx); } { char n[PROJ_NAME_LEN + 1u]; @@ -804,6 +827,7 @@ static void project_capture(project_t *p) fm6_pack(fm6_patch[i], p->fm6[i]); } p->motion = motion; + memcpy(p->dx, dx_kit, sizeof p->dx); motion_unguard(f); memcpy(p->name, proj_name, str_len(proj_name)); p->sum = proj_sum(p); @@ -909,6 +933,7 @@ static int project_restore_runtime(const project_t *input) seq_stop(); transport_req = 0; chain.ended = 0; /* (a song stopped by this load: the load wins, song_poll keeps out) */ + memcpy(dx_kit, dx_kit_ok(p->dx) ? p->dx : DX_KIT_DEF, sizeof dx_kit); /* (the section's DRUM-X kit) */ /* (the rows are the song's, not a section's: kept) */ motion = p->motion; memset(motion_active, 0, sizeof motion_active); diff --git a/firmware/src/song_chain.c b/firmware/src/song_chain.c index a0685560..5ca7848b 100644 --- a/firmware/src/song_chain.c +++ b/firmware/src/song_chain.c @@ -3,8 +3,8 @@ * JIANT (FELUCCA TONIC): the song as SLOOP 2.4.1 plays it (isod89/sloop-fm1, GPL-3.0: arranger.h, arranger_scene.c, * its live sections, quick chain and SONG REC), rebuilt on Felucca's sequencer. */ /* The song (docs/TONIC-SONG-PLAN.md). Four sections A..D, the four saved projects: a section is the whole project, the - * four tracks' sounds (engine, parameters, FM6 patch), their steps and the motion; the tempo and the globals are the - * song's (not the sections'). Sections go in on the bar (a 4/4 bar of 16 1/16 steps at the tempo), every track from + * four tracks' sounds (engine, parameters, FM6 patch), the DRUM-X kit, their steps and the motion; the tempo and the + * globals are the song's (not the sections'). Sections go in on the bar (a 4/4 bar of 16 1/16 steps at the tempo), every track from * its step 0, the remainder of the block carried. * the song up to CHAIN_ROWS rows, each a section and the bars it plays (1..CHAIN_BARS): PLAY on SONG (or anywhere * in SONG mode) plays it from the top and keeps the music as it was (song_keep), which comes back when @@ -38,6 +38,7 @@ typedef struct { /* a track of a section, as the ISR puts i static struct { sec_trk_t t[NTRK]; motion_store_t motion; + dx_lane_t dx[8]; /* the section's DRUM-X kit */ volatile uint8_t ready; /* main: staged; ISR: taken (0) */ uint8_t row, section; /* the song row it is for (SEC_LIVE: a live jump), the section (0..3) */ } sec_stage __attribute__((section(".pool"))); diff --git a/firmware/src/song_main.c b/firmware/src/song_main.c index b2d5f672..919874de 100644 --- a/firmware/src/song_main.c +++ b/firmware/src/song_main.c @@ -78,6 +78,7 @@ static int song_stage(uint32_t s, uint32_t row) fm6_sanitize(d->fm6); } sec_stage.motion = p->motion; + memcpy(sec_stage.dx, p->dx, sizeof sec_stage.dx); sec_stage.row = (uint8_t)row; sec_stage.section = (uint8_t)(s & 3u); RING_PUBLISH(); diff --git a/firmware/src/song_play.c b/firmware/src/song_play.c index 917f3efe..6bdb6d41 100644 --- a/firmware/src/song_play.c +++ b/firmware/src/song_play.c @@ -29,6 +29,7 @@ static void sec_apply(void) t->rat_left = 0; } motion = sec_stage.motion; + memcpy(dx_kit, sec_stage.dx, sizeof dx_kit); memset(motion_active, 0, sizeof motion_active); memset(motion_locked, 0, sizeof motion_locked); motion_base_valid = 0; diff --git a/firmware/src/ui_graph.c b/firmware/src/ui_graph.c index 97ce3e84..70ddadbc 100644 --- a/firmware/src/ui_graph.c +++ b/firmware/src/ui_graph.c @@ -582,7 +582,7 @@ static void graph_drumx(const track_t *t) } } { /* the hats' noise stipples the dorsal sepal */ - const dx_lane_t *L = &DX_KIT_DEF[DV_HATC]; + const dx_lane_t *L = &dx_kit[DV_HATC]; int32_t n = L->a[DXP_NOISE] + ((L->b[DXP_NOISE] - L->a[DXP_NOISE]) * morph) / 127; og_stipple(cx, cy - 30 * u, 7 * u, 12 * u, (uint32_t)n / 3u, 0x9E3779B9u, ux_mix(T_SURF, cyan, 80)); } diff --git a/tests/backup_test.c b/tests/backup_test.c index 2f1a1b7f..ae626b81 100644 --- a/tests/backup_test.c +++ b/tests/backup_test.c @@ -175,8 +175,8 @@ int main(void) reset(); trk[0].step[0] = (step_t){{60}, 1, ST_NOTE, 0, 96, 0, 0}; - bad += check("LIST captures the runtime: 13 objects (id 8 empty, id 9 the FM6 patches), runtime 3648 B (FUN9)", - list(0, &len, &crc) == 0 && rep[2] == 10u && len == sizeof(project_store_t) && len == 3648u && + bad += check("LIST captures the runtime: 13 objects (id 8 empty, id 9 the FM6 patches), runtime 3744 B (FUNA)", + list(0, &len, &crc) == 0 && rep[2] == 10u && len == sizeof(project_store_t) && len == 3744u && crc == st_crc32(ED_BK_RAW, len)); bad += check("an empty project slot lists as length 0", list(2, &len, &crc) == 0 && len == 0); bad += check("GET of the runtime copy", get(0, 0, 64) == 0); diff --git a/tests/motion_test.c b/tests/motion_test.c index 2fb11f04..1efd634a 100644 --- a/tests/motion_test.c +++ b/tests/motion_test.c @@ -18,7 +18,7 @@ static int motion_recording(void) project_t q; project_store_t packed; project_capture(&q); bad += check("project snapshot saves base + independent events while sounding", q.t[0].p[P_REV] == 23 && q.motion.event[0].value == 110 && - proj_pack(&packed, &q) && sizeof packed == 3648u); + proj_pack(&packed, &q) && sizeof packed == 3744u); seq_stop(); bad += check("stop before another step restores the original parameter", t->p[P_REV] == 23); seq_start(); seq_tick(t, CTL); @@ -77,8 +77,8 @@ static int compact_project(void) motion_set_event(t, 3, P_REV, 110); project_t before, after; project_store_t packed, corrupt; project_capture(&before); - bad += check("FUN9 fits the retained and flash extent", sizeof(proj_slot) == 4u * 3648u && proj_pack(&packed, &before)); - bad += check("FUN9 round trip preserves signed values/FM params/probability/motion", proj_import(&after, &packed, sizeof packed) && + bad += check("FUNA fits the retained and flash extent", sizeof(proj_slot) == 4u * 3744u && proj_pack(&packed, &before)); + bad += check("FUNA round trip preserves signed values/FM params/probability/motion", proj_import(&after, &packed, sizeof packed) && !memcmp(&before, &after, sizeof before)); corrupt = packed; corrupt.raw[112] ^= 1u; bad += check("FUN7 torn or corrupted payload is refused", !proj_import(&after, &corrupt, sizeof corrupt)); diff --git a/tests/project_test.c b/tests/project_test.c index 568ad138..b1380a73 100644 --- a/tests/project_test.c +++ b/tests/project_test.c @@ -174,8 +174,8 @@ int main(void) bad += check("layout: SLICER after DETUNE, then the matrix just before P_E0", P_SLCR == P_DETUNE + 1 && P_SLDEPTH + 1 == P_M1SRC && P_M4AMT + 1 == P_FM1_ATK && P_FM4_LEVEL + 1 == P_CHRD && P_VOIC + 1 == P_LN0 && P_LN7 + 1 == P_E0 && P_E0 == 91 && P_COUNT == PROJ_NP_V3 + 42u && PROJ_NP_V3 == PROJ_NP_V2 + 4u); - bad += check("FUN9 fits one flash object, the retained cache in NOINIT", sizeof(project_store_t) <= 4096u - 256u && - sizeof(project_store_t) == 3648u && 0xC8u + 4u * sizeof(project_store_t) <= 0x3D50u); + bad += check("FUNA fits one flash object, the retained cache in NOINIT", sizeof(project_store_t) <= 4096u - 256u && + sizeof(project_store_t) == 3744u && 0xC8u + 4u * sizeof(project_store_t) <= 0x3D50u); /* format 2, as written before the SLICER */ memset(&v2, 0, sizeof v2); @@ -422,9 +422,10 @@ int main(void) project_t a, c; project_store_t st, st2; uint32_t i, zero = 1; - bad += check("FUN9 name at the end of the reserved tail, the FM6 patches before it, after the data (48 spare)", - PROJ_NAME_OFF == 3632u && PROJ_FM6_OFF == 3120u && 68u + NTRK * (P_COUNT + 2u + NSTEP * 9u) + - sizeof(chain_config_t) + sizeof(motion_store_t) + 48u == PROJ_FM6_OFF); + bad += check("FUNA name at the end of the reserved tail, the FM6 patches and the kit before it, after the data (48 spare)", + PROJ_NAME_OFF == 3728u && PROJ_FM6_OFF == 3216u && PROJ_DX_OFF == 3120u && + 68u + NTRK * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + sizeof(motion_store_t) + 48u == + PROJ_DX_OFF); memset(&a, 0, sizeof a); a.magic = PROJ_MAGIC; a.size = sizeof a; a.parts = NPART; a.phys = PROJ_PHYS; chain_defaults(&a.chain); @@ -473,14 +474,49 @@ int main(void) } memcpy(a.name, "FM SONG", 7); a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && ((uint32_t *)st.raw)[0] == 0x46554E39u && proj_import(&c, &st, sizeof st); + ok = proj_pack(&st, &a) && ((uint32_t *)st.raw)[0] == 0x46554E41u && proj_import(&c, &st, sizeof st); for (k = 0; k < NTRK; k++) ok &= !memcmp(c.fm6[k], FM6_FACTORY[k * 2u], FM6_PACKED) && c.t[k].engine == ENGI_FM6 && !memcmp(st.raw + PROJ_FM6_OFF + k * FM6_PACKED, FM6_FACTORY[k * 2u], FM6_PACKED); - bad += check("FUN9: the four FM6 patches round trip (bytes at PROJ_FM6_OFF)", ok && !memcmp(c.name, "FM SONG", 7)); + bad += check("FUNA: the four FM6 patches round trip (bytes at PROJ_FM6_OFF)", ok && !memcmp(c.name, "FM SONG", 7)); st.raw[PROJ_FM6_OFF + 5] ^= 1u; - bad += check("FUN9: a patch byte changed: the hash refuses it", !proj_import(&c, &st, sizeof st)); + bad += check("FUNA: a patch byte changed: the hash refuses it", !proj_import(&c, &st, sizeof st)); st.raw[PROJ_FM6_OFF + 5] ^= 1u; + { /* FUNA's DRUM-X kit (JIANT): round trip; a value out of range refused; a FUN9 loads the factory kit */ + static uint8_t v9[3648]; + static project_store_t st2; + uint32_t magic9 = 0x46554E39u, size9 = 3648u, sum9; + memcpy(a.dx, DX_KIT_DEF, sizeof a.dx); + a.dx[3].b[DXP_COLOR] = 99; + a.dx[0].mode = DX_MODE(DXW_BELL, DXF_HP, 1); + a.sum = proj_sum(&a); + ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st) && !memcmp(c.dx, a.dx, sizeof a.dx) && + !memcmp(st.raw + PROJ_DX_OFF, a.dx, sizeof a.dx); + bad += check("FUNA: the DRUM-X kit round trips (88 bytes at PROJ_DX_OFF)", ok); + a.dx[2].a[DXP_PITCH] = 200; + a.sum = proj_sum(&a); + ok = !proj_pack(&st2, &a); + a.dx[2].a[DXP_PITCH] = 60; + a.sum = proj_sum(&a); + proj_pack(&st2, &a); + st2.raw[PROJ_DX_OFF + 7] = 0xC8; /* (a value past 127, the hash made right) */ + { + uint32_t h = proj_hash(st2.raw, PROJ_STORE_SIZE - 4u); + memcpy(st2.raw + PROJ_STORE_SIZE - 4u, &h, 4); + } + ok &= !proj_import(&c, &st2, sizeof st2); + bad += check("FUNA: a kit value out of range: not packed, not loaded", ok); + memcpy(v9, st.raw, PROJ_DX_OFF); /* FUN9 = FUNA without the kit */ + memcpy(v9 + PROJ_DX_OFF, st.raw + PROJ_FM6_OFF, NTRK * FM6_PACKED); + memcpy(v9 + 3632u, st.raw + PROJ_NAME_OFF, PROJ_NAME_LEN); + memcpy(v9, &magic9, 4); + memcpy(v9 + 4, &size9, 4); + sum9 = proj_hash(v9, 3644u); + memcpy(v9 + 3644u, &sum9, 4); + ok = proj_import(&c, v9, sizeof v9) && !memcmp(c.dx, DX_KIT_DEF, sizeof c.dx) && + !memcmp(c.fm6, a.fm6, sizeof c.fm6) && !memcmp(c.name, "FM SONG", 7); + bad += check("FUN9 (Felucca 1.1) loads: its patches and name, the factory DRUM-X kit", ok); + } { /* FUN8 as 1.0.x wrote it (3584 bytes, 91 parameters: E0..E7 at 83..90, the patches at 3056): the DRUM * lane levels 100 %, E0..E7 and their motion at today's P_E0.., the patches and the name kept */ static uint8_t v8[3584]; diff --git a/web/EDITOR_PROTOCOL.md b/web/EDITOR_PROTOCOL.md index d0eb5685..5bd54e60 100644 --- a/web/EDITOR_PROTOCOL.md +++ b/web/EDITOR_PROTOCOL.md @@ -46,7 +46,7 @@ takes P_COUNT and P_E0 from `INFO` keeps working (see "The chord keys" below). **DRUM lane levels (99 parameters, 1.1):** eight track parameters, `KICK` .. `BELL` (83..90, the DRUM engine's lane levels), went in before the engine parameters, which moved from 83..90 to 91..98: P_COUNT 99, P_E0 91. No command -changed; projects are FUN9 (3648 bytes, see "Projects (FUN9)"). See "The DRUM lane levels" below. +changed; projects were FUN9 (3648 bytes, see "Projects (FUN9)"; JIANT writes FUNA). See "The DRUM lane levels" below. ## Framing @@ -521,6 +521,11 @@ when the track's engine is not the saved one). 91 parameters) loads mapped by count (the lane levels 127, the engine values and their motion events and locks from 83..90 to 91..98, a lock's bit 7 kept); FUN7 and older as before. Firmware 1.0.x refuses a FUN9 (its size, magic and P_COUNT). Backups, `PROJECT` and the editor's project files carry the 3648 bytes; a backup `PUT` takes 3648, 3584 or 3388. +- **Projects (FUNA, JIANT 0.1).** FUN9 with 96 more bytes, `46 55 4E 41` ("FUNA"), size 3744: the section's DRUM-X + kit (8 sounds × 11 bytes: the mode, then PITCH PMOD DECAY NOISE COLOR of patch A and of patch B, each 0..127; + the mode: bits 0..1 the wave, 2..3 the noise filter 0..2, bit 4 SNAP) at 3120..3207, 8 reserved bytes (0), the FM6 + patches at 3216..3727, the name at 3728..3739, the hash last. FUN9 and older load with the factory kit. Backups, + `PROJECT` and the editor's project files carry the 3744 bytes; a backup `PUT` also takes 3648, 3584 or 3388. - **MIDI clock** has no SysEx. `G_CLOCK` selects the source: 0 INT, 1 USB, 2 TRS. With 1 or 2 the sequencer steps on that port's Clock pulses (the other port's are ignored), Start (0xFA) restarts from step 0, Continue (0xFB) resumes and Stop (0xFC) stops; BPM follows the incoming tempo (40..240), and 500 ms @@ -583,9 +588,9 @@ this firmware sends 3. Requests name objects, never flash addresses. | id | object | size | | --- | --- | --- | -| 0 | runtime: the music being played now, as a FUN9 project (1.0.x: FUN8, 3584; firmware before FM6: FUN7, 3388) | 3648 | +| 0 | runtime: the music being played now, as a FUNA project (Felucca 1.1: FUN9, 3648; 1.0.x: FUN8, 3584; before FM6: FUN7, 3388) | 3744 | | 1 | settings (palette, speaker, HOLD time, favorites, panel calibration, ...) | the settings record's size | -| 2..5 | PROJECT slots 1..4 (FUN9; 1.0.x: FUN8, 3584); JIANT: sections A..D of the current song | 3648, or 0 if empty | +| 2..5 | PROJECT slots 1..4 (FUNA; Felucca: FUN9 3648, FUN8 3584); JIANT: sections A..D of the current song | 3744, or 0 if empty | | 6, 7 | user preset banks (slots 1..16, 17..32) | the bank's size, or 0 if empty | | 8 | the FM6 patch bank of 1.0..1.0.2 (B1..B27). Since 1.0.3 always listed empty (see below) | 3472, or 0 if empty | | 9 | the user presets' FM6 patches (1.0.3; `up_fm6.c`: per slot a tag and the packed patch) | 3728, or 0 if none | @@ -598,8 +603,8 @@ against the list; if it differs the device changed, so start again. Restoring: `BACKUP_PUT` takes ids 0..9 (firmware before 1.0.3: 0..8, id 9 answers rc 1 at begin and nothing is written). Ids 32..34 (Felucca's user sample slots) are retired with the slots: the web editor skips them when it reads an older -archive and restores the rest. Begin: `0, id, size u32, crc u32`: size is 3648 (FUN9), 3584 (FUN8) or 3388 (FUN7, FUN6) for id 0, -the settings record's size for id 1, 3648, 3584, 3388 or 0 (empty the slot) for ids 2..5, the bank's size or 0 for 6 and 7, +archive and restores the rest. Begin: `0, id, size u32, crc u32`: size is 3744 (FUNA), 3648 (FUN9), 3584 (FUN8) or 3388 (FUN7, FUN6) for id 0, +the settings record's size for id 1, 3744, 3648, 3584, 3388 or 0 (empty the slot) for ids 2..5, the bank's size or 0 for 6 and 7, 3472 or 0 for 8 (the FM6 bank: its magic, layout and every byte below 128 are checked), 3728 or 0 for 9 (its magic, version and slot count checked; 0 clears the patches). FUN8, FUN7 and FUN6 become FUN9. An archive without id 8 (written before FM6) still restores; the web editor reads all three kinds (8, 9, 10 objects;