From ee130ccac084e85ff660a7ae21dfcee5ea91335f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 17:59:53 +0000 Subject: [PATCH] JIANT 0.6.0: six tracks, compressed sections, fill warning - NPART 6: T5 PHASE, T6 WHEEL by default; ALGORITHM scrolls T1..T6 - FUNC section format: six tracks in the same 3840-byte slot (8 songs x 4 sections kept); only non-default parameters and non-empty steps stored, variable-length steps; FUNB / older formats import (T5/T6 at power-on) - Section store packs aside first: SECTION FULL keeps the stored section - Fill warning (SECTION 90% FULL / TOO FULL TO SAVE), checked once after edits - Motion: track bit 2 in the value's bit 12 (old records read unchanged) - Scenes: T5/T6 mutes in the scene's spare bits - GLO / FX layers: six mutes and solos, DRUM groups on black keys 7..10, levels follow the selected track; MIXER shows four around the selection; HOME six beings - MIDI IN ROUT CH1-6; FX mute gains start open on every track - comb_buf and proj_scratch moved to the pool (RAM 74.6 of 96 KB) - Web editor: six tracks in the mock, motion on T5/T6, texts - Tests adapted (legacy builders on PROJ_LT, FUNB writer for byte checks), new FUNC round trip, fuzz and fill tests; README changelog and manual Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh --- README.md | 39 +++- firmware/src/core.h | 15 +- firmware/src/editor.c | 6 +- firmware/src/engines.c | 4 +- firmware/src/felucca.c | 2 +- firmware/src/icons.c | 2 + firmware/src/motion.c | 62 ++++--- firmware/src/params.c | 2 +- firmware/src/perform.c | 9 +- firmware/src/project.c | 367 +++++++++++++++++++++++++++++++++----- firmware/src/song_chain.c | 11 +- firmware/src/song_main.c | 6 +- firmware/src/song_play.c | 2 +- firmware/src/ui_being.c | 4 +- firmware/src/ui_draw.c | 4 +- firmware/src/ui_events.c | 10 +- firmware/src/ui_graph.c | 22 +-- firmware/src/ui_layer.c | 66 ++++--- firmware/src/ui_tools.c | 4 +- firmware/src/voice.c | 2 +- tests/backup_test.c | 9 +- tests/editor_test.c | 4 +- tests/fm4_div0_test.c | 8 +- tests/midi_control_test.c | 54 +++--- tests/motion_test.c | 13 +- tests/perform_test.c | 2 +- tests/persistence_test.c | 8 +- tests/project_test.c | 153 +++++++++++----- tests/ratchet_test.c | 10 +- tests/robust_test.c | 4 +- tests/ui_test.c | 54 ++++-- web/EDITOR_PROTOCOL.md | 8 +- web/editor.html | 26 +-- web/test_web.mjs | 16 +- 34 files changed, 717 insertions(+), 291 deletions(-) diff --git a/README.md b/README.md index c08159b0..fdd3f654 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,36 @@ and takes its song system from [SLOOP](https://github.com/isod89/sloop-fm1). the FM-1, with sound, and is played with your computer keyboard or the mouse. The emulator, the installer and the editor update themselves with every change merged into `main`. -> **Status: in development (v0.5.5).** It builds and passes every test (Felucca's and its own), but **it has not been +> **Status: in development (v0.6.0).** It builds and passes every test (Felucca's and its own), but **it has not been > tested thoroughly on a real FM-1 yet**. Back up the flash before installing it. ## Changelog Every update is listed here, newest first. +### v0.6.0 +- **Six tracks instead of four.** T5 starts on PHASE and T6 on WHEEL (any engine can go on any track, as always), + each with its own sequence, sound, effects sends and automation. **ALGORITHM** scrolls T1..T6. +- **Same storage, everything kept**: still 8 songs × 4 sections plus the 4 project slots, and the song sequencer + (rows of sections with repeats and scenes) works as before, so you can build whole songs with intro, verse, + chorus and bridge. To fit six tracks in the same space, sections are now saved **compressed**: only the steps + that have something, and only the parameters you changed, are stored. The music at power-on takes about a + quarter of a section; even six tracks with 4-note chords on all 64 steps fit. +- **A fill warning**: a moment after you stop editing, if the music is near the size of a section the screen says + **SECTION 90% FULL**; if it no longer fits, **TOO FULL TO SAVE**. Saving a section in that state says + **SECTION FULL** and changes nothing: the section already saved stays as it was. All memory is fixed at build + time (nothing is allocated while you play), so a full section can never crash the system. +- **Projects and sections from 0.5 load as they were**: their four tracks keep their sound and steps, T5 and T6 + start empty on their default sounds. +- **GLO** (held): black keys 1–6 mute T1–T6, 7–10 the DRUM groups (KICK, SNARE, HAT, PERC); white keys F3–D4 solo + T1–T6 while held, E4 unmutes everything, F4 tap tempo. The four knobs are T1–T4's levels, or T3–T6's when T5 or + T6 is selected. **FX** (held): black keys 1–6 mute T1–T6. +- **MIXER** shows four tracks at a time and follows the selected one (T5 or T6 selected: T3–T6). +- **HOME**: six beings in the ecosystem, a bit smaller. +- **Song scenes** remember the mutes of T5 and T6 too. **Automation** (knobs and per-step locks) works on all six. +- **MIDI IN**: ROUT **CH1-6** (was CH1-4): channels 1–6 play tracks 1–6, 7–16 stay free for other instruments. +- Web editor: six tracks in the track selector, the mixer and automation. + ### v0.5.5 - **FLOAT is a floatbeat generator now**: bytebeat's sibling in floats. Each of the 32 ALGOs is a formula of `t` made of sines, as in the floatbeat scene: `sin(t·(t>>11 ^ t>>13 & 7))`, FM whose index walks with `t`'s bits, @@ -99,7 +122,7 @@ That's why everything in JIANT is alive and visible. The screen works like a **t decoration, it's intensity. Cold is cyan and violet, hot is red, orange, yellow and white. A high parameter burns; a sounding voice glows; silence cools down. Each engine is a **being**, a protozoan drawn in lines whose shape comes from what you're playing: open the filter and it grows spines, raise the resonance and its membrane vibrates, detune -the oscillators and its nuclei drift apart. HOME is an **ecosystem**: four creatures, one per track, breathing with +the oscillators and its nuclei drift apart. HOME is an **ecosystem**: six creatures, one per track, breathing with their own audio. You don't need to read numbers to know what's going on; you can see it. At the same time, what is technical is shown as technical. The LFO runs at its rate, the envelope shows where the @@ -257,13 +280,13 @@ Turning fast sweeps the whole range; turning slowly is fine adjustment. Turn it | Hold | Keys | Knobs | | --- | --- | --- | -| **FX** | F3 G3 A3 REPEAT 1/8, 1/16, 1/32; B3 LPF; C4 HPF. MIDI punch-ins: D4 OCT−, E4 OCT+, F4 1/2 TEMPO, G4 DEC−, A4 DEC+, B4 C5 STUTTER 1/8 · 1/16, D5 ATK+ (everything's attack up, drums included), E5 ARP (drums: a new fill on every press), F5 RANDOM (notes and steps). Everything comes in on the transport's next 1/16. Black keys 1–4: mute T1–T4; A#4 chooses which tracks the MIDI ones affect (all, synths, drums). **Automate**: with REC armed and playing, whatever you hold is recorded in the section's lane (64 steps of 1/16); G5 erases it where the playhead passes, or entirely with the transport stopped | FILTER, CRUSH, THROW, DEPTH | +| **FX** | F3 G3 A3 REPEAT 1/8, 1/16, 1/32; B3 LPF; C4 HPF. MIDI punch-ins: D4 OCT−, E4 OCT+, F4 1/2 TEMPO, G4 DEC−, A4 DEC+, B4 C5 STUTTER 1/8 · 1/16, D5 ATK+ (everything's attack up, drums included), E5 ARP (drums: a new fill on every press), F5 RANDOM (notes and steps). Everything comes in on the transport's next 1/16. Black keys 1–6: mute T1–T6; A#4 chooses which tracks the MIDI ones affect (all, synths, drums). **Automate**: with REC armed and playing, whatever you hold is recorded in the section's lane (64 steps of 1/16); G5 erases it where the playhead passes, or entirely with the transport stopped | FILTER, CRUSH, THROW, DEPTH | | **ARP TRNS** | With the ARP mode on TRNS, the keys (and incoming MIDI) transpose the track's sequence by their interval from C4, without playing notes; the transposition stays on release | — | | **SEQ > SHIFT** | OFS shifts the track's sequence from −32 to +32 steps (within LEN; live recording writes where you hear it) and PIT transposes it ±24 semitones (not on kits). Both can be automated and are also on the SCL layer (KNOB 3 / 4) | OFS, PIT | -| **REC + another button** | Hold REC and press FX, EDIT, ENV, LFO, SCL, ARP or GLO: clears that part's automation on the selected track (knob movements and per-step locks; stored values stay). FX: the punch-in lane too. GLO: levels and pan of the 4 tracks. The other way round (FX held then REC) arms recording, as always | — | -| **SEQ + REC** | Hold SEQ and press REC: CLEAR ALL SEQUENCES? (OCT+ confirms): clears the steps and automation of the 4 tracks and the punch-in lane | — | +| **REC + another button** | Hold REC and press FX, EDIT, ENV, LFO, SCL, ARP or GLO: clears that part's automation on the selected track (knob movements and per-step locks; stored values stay). FX: the punch-in lane too. GLO: levels and pan of the 6 tracks. The other way round (FX held then REC) arms recording, as always | — | +| **SEQ + REC** | Hold SEQ and press REC: CLEAR ALL SEQUENCES? (OCT+ confirms): clears the steps and automation of the 6 tracks and the punch-in lane | — | | **LFO** | — (**MACRO** layer: below, where each macro goes) | M1, M2, M3, M4 | -| **GLO** | Black keys 1–4 mute T1–T4 (latched); 5–8 DRUM group mutes: KICK, SNARE, HAT, PERC; F3–B3 solo while held; C4 unmutes everything; F4 tap tempo | T1–T4 level | +| **GLO** | Black keys 1–6 mute T1–T6 (latched); 7–10 DRUM group mutes: KICK, SNARE, HAT, PERC; F3–D4 solo T1–T6 while held; E4 unmutes everything; F4 tap tempo | T1–T4 level (with T5 or T6 selected: T3–T6) | | **SCL** | Any key picks the root | ROOT, SCL, OFS, PIT | | **EDIT** | F3 **INIT**: the track's sound goes back to factory (on DRUM, the DRUM-X kit too). G3 **RECALL**: back to the sound saved in the section (on DRUM, with its kit). Both ask for confirmation and leave the steps alone. On a DRUM track, black keys 1–8 mute each DRUM-X sound. The engine and sounds are picked in PRESETS | The engine's first 4 EDIT knobs | | **SEQ** | On the SEQ pages: SEQ TOOLS | LEN, DIV, SWING, GATE | @@ -284,7 +307,7 @@ each layer. ### 1. Getting around - Each page button (EDIT, ENV, LFO, FX, SEQ, SCL, ARP, GLO, SAVE) opens its first page; pressing it again moves to the next one. The title at the top tells you where you are. **HOME** takes you back to the ecosystem. -- **ALGORITHM** picks the track (T1–T4) from any page; track pages show the selected track. +- **ALGORITHM** picks the track (T1–T6) from any page; track pages show the selected track. - The four knobs drive the four columns on screen. Turning fast sweeps the whole range, slowly fine-tunes. - **Holding** a button opens its layer (FX, GLO, SCL, LFO, EDIT, SAVE…): release it and you're back where you were. @@ -329,7 +352,7 @@ locks it into a short window. CHIP sets the resolution: FULL is smooth, 4BIT and - **FOLD** folds each hit's wave: the attack shines and the tail comes back clean. **FM** dirties the timbre. - **EDIT > SOUND 1–3** edits each sound (BD, SD, CP, CH, OH, TM, RS, CB; KNOB 1 picks which). SOUND 3 has **PMOD** (how the pitch falls: DECAY, 808-style LONG, NOISE, SINE), DRV and WAVE. -- Mutes: **GLO held** + black keys 5–8 (KICK, SNARE, HAT, PERC); **EDIT held** + black keys 1–8 (each sound). +- Mutes: **GLO held** + black keys 7–10 (KICK, SNARE, HAT, PERC); **EDIT held** + black keys 1–8 (each sound). - SELECT on a DRUM track rolls a new kit around the factory one. - **EDIT > X-MOD** moves the kit by itself: **RATE** (OFF, 4 bars … 1/32, in time with the tempo), **DPTH** (how far it swings MORPH), **SHPE** (SINE, TRI, SAW, RAMP, S&H) and **RAND** (each hit gets its own MORPH and up to a diff --git a/firmware/src/core.h b/firmware/src/core.h index a4cc177b..7289ec35 100644 --- a/firmware/src/core.h +++ b/firmware/src/core.h @@ -9,7 +9,7 @@ /* ------------------------------------------------------------ sizes --- */ #define NVOICE 8 /* voices per part, and the budget shared by all parts */ -#define NPART 4 /* synth parts: tracks 1..4 */ +#define NPART 6 /* synth parts: tracks 1..6 (JIANT 0.6: was 4) */ #define NTRK NPART /* tracks (the formats and the protocol count these): every track is a part */ #define NSTEP 64 #define HALF_FRAMES 128 /* I2S half buffer: 2.9 ms at 44.1 kHz (a key waits 0..1 half, then plays 1 half later) */ @@ -308,14 +308,25 @@ static void step_set_ratchet(step_t *s, uint32_t hits) s->flags = (uint8_t)((s->flags & ~SF_RATCH) | ((hits < 1u ? 0u : hits > 4u ? 3u : hits - 1u) << SF_RATCH_SH)); } #define MOTION_MAX 64u -/* Four tracks x64 steps fit one byte. Values retain their signed parameter range. +/* Four tracks x64 steps fit one byte (JIANT 0.6, six tracks: the track's bit 2 is value's bit 12 flipped against its + * sign, MOTION_TRK; values stay within -64..127, so an old record reads as track 0..3). Values retain their signed parameter range. * param: the P_* id (< 128: P_COUNT is at most 127, project.c), bit 7 (MOTION_LOCK, 1.1) a parameter lock: the value * sounds on that step only and goes back after it (motion.c motion_step); without it an automation event, the * value holds until another one changes it. One record per (track, step, id), of either kind */ #define MOTION_LOCK 0x80u #define MOTION_ID(e) ((uint32_t)(e)->param & 0x7Fu) +#define MOTION_HI(e) ((uint32_t)(((e)->value >> 12) ^ ((e)->value >> 15)) & 1u) +#define MOTION_TRK(e) ((uint32_t)(e)->place >> 6 | MOTION_HI(e) << 2) +#define MOTION_STEP(e) ((uint32_t)(e)->place & 63u) +#define MOTION_PLACE(e) (MOTION_TRK(e) << 6 | MOTION_STEP(e)) /* track << 6 | step */ +#define MOTION_VAL(e) ((int16_t)((e)->value ^ (int32_t)(MOTION_HI(e) << 12))) typedef struct { uint8_t place, param; int16_t value; } motion_event_t; typedef struct { uint8_t count, on, rsv[2]; motion_event_t event[MOTION_MAX]; } motion_store_t; +static void motion_at(motion_event_t *e, uint32_t place, int16_t v) /* place: track << 6 | step; v: the value */ +{ + e->place = (uint8_t)(place & 255u); + e->value = (int16_t)(v ^ (int32_t)(((place >> 8) & 1u) << 12)); +} _Static_assert(sizeof(motion_store_t) == 260u, "motion disk layout"); #define CHAIN_ROWS 16u typedef struct { uint8_t slot, bars; } chain_row_t; /* a song row: section A..D (a project slot), 1..CHAIN_BARS bars */ diff --git a/firmware/src/editor.c b/firmware/src/editor.c index 761457b9..067ec71e 100644 --- a/firmware/src/editor.c +++ b/firmware/src/editor.c @@ -306,11 +306,11 @@ static void ed_motion_reply(uint32_t k, uint32_t rc, uint32_t kinds) ed_b(k); ed_b(rc); ed_b(motion_enabled(t)); ed_b(motion_count(t)); ed_b(MOTION_MAX); for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; - if ((e->place >> 6) != k) continue; - ed_b(e->place & 63u); ed_b(MOTION_ID(e)); ed_v(e->value); + if (MOTION_TRK(e) != k) continue; + ed_b(MOTION_STEP(e)); ed_b(MOTION_ID(e)); ed_v(MOTION_VAL(e)); } for (i = 0; kinds && i < motion.count; i++) - if ((motion.event[i].place >> 6) == k) + if (MOTION_TRK(&motion.event[i]) == k) ed_b((motion.event[i].param & MOTION_LOCK) != 0u); } static int ed_args_ok(uint32_t cmd, const uint8_t *a, uint32_t n) diff --git a/firmware/src/engines.c b/firmware/src/engines.c index 14858ef7..7661f40a 100644 --- a/firmware/src/engines.c +++ b/firmware/src/engines.c @@ -146,6 +146,6 @@ static const struct { #define NPATTERNS (sizeof PATTERNS / sizeof PATTERNS[0]) /* the parts at power-on (engine, preset, PATTERNS[n - 1] in the sequencer, 0 = empty: all are): bass, pad, lead, drums */ -static const uint8_t TRK_DEF[NPART][3] = {{0, 4, 0}, {ENGI_FM6, 4, 0}, {3, 3, 0}, {ENGI_DRUM, 0, 0}}; /* ANALOG ACID, - * FM6 PAD (was DIGITAL PAD), LOFI PULSE LD (3: BYTE first), DRUM KIT */ +static const uint8_t TRK_DEF[NPART][3] = {{0, 4, 0}, {ENGI_FM6, 4, 0}, {3, 3, 0}, {ENGI_DRUM, 0, 0}, {2, 0, 0}, {7, 0, 0}}; +/* ANALOG ACID, FM6 PAD (was DIGITAL PAD), LOFI PULSE LD (3: BYTE first), DRUM KIT; (JIANT 0.6) PHASE's first, WHEEL's first */ static uint32_t trk_def_engine(uint32_t i) { return TRK_DEF[i % NPART][0]; } diff --git a/firmware/src/felucca.c b/firmware/src/felucca.c index bb84cf0c..f1128629 100644 --- a/firmware/src/felucca.c +++ b/firmware/src/felucca.c @@ -32,7 +32,7 @@ #define FELUCCA_ID "FM-1_900" /* package identity (build.py: the .fwsc marker string) */ #endif #ifndef FELUCCA_VERSION -#define FELUCCA_VERSION "v0.5.5" /* JIANT's (based on Felucca 1.1.5.1): the splash, the menu, the console, the editor */ +#define FELUCCA_VERSION "v0.6.0" /* JIANT's (based on Felucca 1.1.5.1): the splash, the menu, the console, the editor */ #endif #if FELUCCA_OTA && !FELUCCA_FLASH #error "FELUCCA_OTA needs FELUCCA_FLASH" diff --git a/firmware/src/icons.c b/firmware/src/icons.c index 2431e6f7..7050cf22 100644 --- a/firmware/src/icons.c +++ b/firmware/src/icons.c @@ -16,6 +16,8 @@ * keycaps are. (filled: kept for the callers; every cushion is filled) */ #define ICON_TRK 0xF0u /* + k (above ICON_COUNT, below ICON_AUTO) */ static uint32_t trk_icon(uint32_t k, int filled) { (void)filled; return ICON_TRK + k % NTRK; } +/* (JIANT 0.6) four tracks on screen of the six (MIXER, GLO's knobs): T1..T4, or T3..T6 with T5 / T6 selected */ +static uint32_t trk_base4(void) { return song.sel < 4u ? 0u : NTRK - 4u; } static int32_t cv_trk(int32_t x, int32_t y, uint32_t size, uint32_t k, uint16_t fill, uint16_t under) { const aafont_t *f = size > 16u ? &AF_M : &AF_S; diff --git a/firmware/src/motion.c b/firmware/src/motion.c index 641cc31e..e81e19b5 100644 --- a/firmware/src/motion.c +++ b/firmware/src/motion.c @@ -47,9 +47,9 @@ static int motion_valid(const motion_store_t *m) if (m->count > MOTION_MAX || (m->on & ~((1u << NTRK) - 1u))) return 0; for (i = 0; i < m->count; i++) { const motion_event_t *e = &m->event[i]; - if (!motion_param(MOTION_ID(e)) || e->value < -64 || e->value > 127) return 0; + if (!motion_param(MOTION_ID(e)) || MOTION_VAL(e) < -64 || MOTION_VAL(e) > 127) return 0; for (j = 0; j < i; j++) - if (m->event[j].place == e->place && MOTION_ID(&m->event[j]) == MOTION_ID(e)) return 0; + if (MOTION_PLACE(&m->event[j]) == MOTION_PLACE(e) && MOTION_ID(&m->event[j]) == MOTION_ID(e)) return 0; } return 1; } @@ -57,14 +57,14 @@ static int motion_enabled(const track_t *t) { return (motion.on >> trk_index(t)) static uint32_t motion_count(const track_t *t) { uint32_t i, n = 0, k = trk_index(t); - for (i = 0; i < motion.count; i++) n += (motion.event[i].place >> 6) == k; + for (i = 0; i < motion.count; i++) n += MOTION_TRK(&motion.event[i]) == k; return n; } /* track t's parameter locks (of motion_count) */ static uint32_t motion_lock_count(const track_t *t) { uint32_t i, n = 0, k = trk_index(t); - for (i = 0; i < motion.count; i++) n += (motion.event[i].place >> 6) == k && (motion.event[i].param & MOTION_LOCK); + for (i = 0; i < motion.count; i++) n += MOTION_TRK(&motion.event[i]) == k && (motion.event[i].param & MOTION_LOCK); return n; } /* the steps of track k that hold a lock, bit s = step s (the roll and the grid mark them) */ @@ -73,8 +73,8 @@ static uint64_t motion_lock_steps(uint32_t k) uint32_t i; uint64_t m = 0; for (i = 0; i < motion.count; i++) - if ((motion.event[i].place >> 6) == k && (motion.event[i].param & MOTION_LOCK)) - m |= (uint64_t)1 << (motion.event[i].place & 63u); + if (MOTION_TRK(&motion.event[i]) == k && (motion.event[i].param & MOTION_LOCK)) + m |= (uint64_t)1 << MOTION_STEP(&motion.event[i]); return m; } /* the lock of track t on step / id: 1 and its value in *v, 0 = none */ @@ -82,8 +82,8 @@ static int motion_lock_get(const track_t *t, uint32_t step, uint32_t id, int16_t { uint32_t i, place = trk_index(t) << 6 | step; for (i = 0; i < motion.count; i++) - if (motion.event[i].place == place && motion.event[i].param == (id | MOTION_LOCK)) { - *v = motion.event[i].value; + if (MOTION_PLACE(&motion.event[i]) == place && motion.event[i].param == (id | MOTION_LOCK)) { + *v = MOTION_VAL(&motion.event[i]); return 1; } return 0; @@ -97,7 +97,7 @@ static uint32_t motion_mask(uint32_t k, uint32_t m[(P_COUNT + 31u) / 32u]) if (k >= NTRK || !((motion.on >> k) & 1u)) return 0; for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; - if ((e->place >> 6) != k || MOTION_ID(e) >= P_COUNT) continue; + if (MOTION_TRK(e) != k || MOTION_ID(e) >= P_COUNT) continue; m[MOTION_ID(e) / 32u] |= 1u << (MOTION_ID(e) % 32u); any = 1; } @@ -151,7 +151,7 @@ static void motion_clear(track_t *t) uint32_t f = motion_guard(), k = trk_index(t), i, n = 0; motion_restore(t); for (i = 0; i < motion.count; i++) - if ((motion.event[i].place >> 6) != k) motion.event[n++] = motion.event[i]; + if (MOTION_TRK(&motion.event[i]) != k) motion.event[n++] = motion.event[i]; memset(motion.event + n, 0, (MOTION_MAX - n) * sizeof motion.event[0]); motion.count = (uint8_t)n; motion.on &= (uint8_t)~(1u << k); @@ -172,11 +172,10 @@ static int motion_put(track_t *t, uint32_t step, uint32_t id, int16_t value, uin value = (int16_t)param_fit(d, value); /* (a retired KIT: the kit it plays) */ f = motion_guard(); for (i = 0; i < motion.count; i++) - if (motion.event[i].place == (k << 6 | step) && MOTION_ID(&motion.event[i]) == id) break; + if (MOTION_PLACE(&motion.event[i]) == (k << 6 | step) && MOTION_ID(&motion.event[i]) == id) break; if (i == MOTION_MAX) { motion_full = 1; motion_unguard(f); return 2; } - motion.event[i].place = (uint8_t)(k << 6 | step); + motion_at(&motion.event[i], k << 6 | step, value); motion.event[i].param = (uint8_t)(id | kind); - motion.event[i].value = value; RING_PUBLISH(); if (i == motion.count) motion.count++; motion.on |= (uint8_t)(1u << k); @@ -193,7 +192,7 @@ static void motion_delete_event(track_t *t, uint32_t step, uint32_t id) /* (ei uint32_t f = motion_guard(), place = trk_index(t) << 6 | step, i, n = 0; motion_restore(t); for (i = 0; i < motion.count; i++) - if (motion.event[i].place != place || MOTION_ID(&motion.event[i]) != id) motion.event[n++] = motion.event[i]; + if (MOTION_PLACE(&motion.event[i]) != place || MOTION_ID(&motion.event[i]) != id) motion.event[n++] = motion.event[i]; memset(motion.event + n, 0, (MOTION_MAX - n) * sizeof motion.event[0]); motion.count = (uint8_t)n; motion_unguard(f); @@ -205,7 +204,7 @@ static uint32_t motion_clear_locks(track_t *t, uint32_t step) uint32_t f = motion_guard(), k = trk_index(t), i, n = 0, gone; for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; - if ((e->place >> 6) == k && (e->param & MOTION_LOCK) && (step >= NSTEP || (e->place & 63u) == step)) continue; + if (MOTION_TRK(e) == k && (e->param & MOTION_LOCK) && (step >= NSTEP || MOTION_STEP(e) == step)) continue; motion.event[n++] = *e; } gone = motion.count - n; @@ -251,11 +250,11 @@ static __attribute__((noinline)) void motion_unlock(track_t *t, uint32_t step, c v = motion_base[k][id]; for (i = 0; i < m->count; i++) { const motion_event_t *e = &m->event[i]; - int32_t s = (int32_t)(e->place & 63u); - if ((e->place >> 6) != k || e->param != id || s > (int32_t)step || s <= best) + int32_t s = (int32_t)MOTION_STEP(e); + if (MOTION_TRK(e) != k || e->param != id || s > (int32_t)step || s <= best) continue; /* (e->param == id: automation only, no MOTION_LOCK) */ best = s; - v = (int16_t)param_fit(param_desc_of(eng_idx(t->eng_req), id), e->value); + v = (int16_t)param_fit(param_desc_of(eng_idx(t->eng_req), id), MOTION_VAL(e)); } t->p[id] = v; } @@ -277,9 +276,9 @@ static __attribute__((noinline)) void motion_step(track_t *t, uint32_t step, con for (i = 0; i < m->count; i++) { const motion_event_t *e = &m->event[i]; uint32_t id = MOTION_ID(e); - if (e->place != (k << 6 | step) || ((e->param & MOTION_LOCK) && !play)) continue; + if (MOTION_PLACE(e) != (k << 6 | step) || ((e->param & MOTION_LOCK) && !play)) continue; const param_desc_t *d = param_desc_of(eng_idx(t->eng_req), id); - t->p[id] = (int16_t)param_fit(d, e->value); + t->p[id] = (int16_t)param_fit(d, MOTION_VAL(e)); motion_active[k][id / 32u] |= 1u << (id % 32u); if (e->param & MOTION_LOCK) motion_locked[k][id / 32u] |= 1u << (id % 32u); @@ -291,14 +290,14 @@ static void motion_snapshot_track(track_t *t, motion_store_t *out) memset(out, 0, sizeof *out); out->on = motion.on & (uint8_t)(1u << k); for (i = 0; i < motion.count; i++) - if ((motion.event[i].place >> 6) == k) out->event[out->count++] = motion.event[i]; + if (MOTION_TRK(&motion.event[i]) == k) out->event[out->count++] = motion.event[i]; motion_unguard(f); } static int motion_replace_track(track_t *t, const motion_store_t *in) { uint32_t k = trk_index(t), n = motion.count - motion_count(t), f; if (!motion_valid(in) || n + in->count > MOTION_MAX) return 2; - for (uint32_t i = 0; i < in->count; i++) if ((in->event[i].place >> 6) != k) return 1; + for (uint32_t i = 0; i < in->count; i++) if (MOTION_TRK(&in->event[i]) != k) return 1; f = motion_guard(); motion_clear(t); memcpy(motion.event + motion.count, in->event, in->count * sizeof in->event[0]); @@ -314,7 +313,7 @@ static int32_t motion_find(const track_t *t, uint32_t step, uint32_t id) { uint32_t i, place = trk_index(t) << 6 | step; for (i = 0; i < motion.count; i++) - if (motion.event[i].place == place && MOTION_ID(&motion.event[i]) == id) + if (MOTION_PLACE(&motion.event[i]) == place && MOTION_ID(&motion.event[i]) == id) return (int32_t)i; return -1; } @@ -324,12 +323,12 @@ static uint32_t motion_rows(uint32_t k, uint8_t *idx) uint32_t i, j, n = 0; for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; - uint32_t key = (uint32_t)(e->place & 63u) << 7 | MOTION_ID(e); - if ((e->place >> 6) != k) + uint32_t key = (uint32_t)MOTION_STEP(e) << 7 | MOTION_ID(e); + if (MOTION_TRK(e) != k) continue; for (j = n; j > 0u; j--) { /* (insertion: at most MOTION_MAX) */ const motion_event_t *o = &motion.event[idx[j - 1u]]; - if (((uint32_t)(o->place & 63u) << 7 | MOTION_ID(o)) <= key) + if (((uint32_t)MOTION_STEP(o) << 7 | MOTION_ID(o)) <= key) break; idx[j] = idx[j - 1u]; } @@ -345,7 +344,7 @@ static int motion_move(track_t *t, uint32_t i, uint32_t step, uint32_t id, int16 const param_desc_t *d; int32_t at; uint32_t f; - if (i >= motion.count || (motion.event[i].place >> 6) != trk_index(t) || step >= NSTEP || !motion_param(id)) + if (i >= motion.count || MOTION_TRK(&motion.event[i]) != trk_index(t) || step >= NSTEP || !motion_param(id)) return 1; at = motion_find(t, step, id); if (at >= 0 && (uint32_t)at != i) @@ -354,11 +353,10 @@ static int motion_move(track_t *t, uint32_t i, uint32_t step, uint32_t id, int16 if (v < d->min || v > d->max || v < -64 || v > 127) return 1; f = motion_guard(); - if (motion.event[i].place != (trk_index(t) << 6 | step) || MOTION_ID(&motion.event[i]) != id) + if (MOTION_PLACE(&motion.event[i]) != (trk_index(t) << 6 | step) || MOTION_ID(&motion.event[i]) != id) motion_restore(t); /* (a value alone: what sounds stays) */ - motion.event[i].place = (uint8_t)(trk_index(t) << 6 | step); + motion_at(&motion.event[i], trk_index(t) << 6 | step, (int16_t)param_fit(d, v)); motion.event[i].param = (uint8_t)((motion.event[i].param & MOTION_LOCK) | id); - motion.event[i].value = (int16_t)param_fit(d, v); motion_unguard(f); return 0; } @@ -372,7 +370,7 @@ static uint32_t motion_clear_ids(track_t *t, const uint32_t m[(P_COUNT + 31u) / for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; uint32_t id = MOTION_ID(e); - if ((e->place >> 6) == k && id < P_COUNT && ((m[id / 32u] >> (id % 32u)) & 1u)) + if (MOTION_TRK(e) == k && id < P_COUNT && ((m[id / 32u] >> (id % 32u)) & 1u)) continue; motion.event[n++] = *e; } @@ -398,7 +396,7 @@ static uint32_t motion_sound_loaded(track_t *t, uint32_t from, uint32_t to) f = motion_guard(); for (i = 0; i < motion.count; i++) { const motion_event_t *e = &motion.event[i]; - if ((e->place >> 6) == k && motion_engine_id(MOTION_ID(e))) + if (MOTION_TRK(e) == k && motion_engine_id(MOTION_ID(e))) continue; motion.event[n++] = *e; } diff --git a/firmware/src/params.c b/firmware/src/params.c index c7928bd8..e19b3b79 100644 --- a/firmware/src/params.c +++ b/firmware/src/params.c @@ -26,7 +26,7 @@ static const char *const N_ALLOC[] = {"ROT", "REUSE"}; static const char *const N_ORDER[] = {"NOTE", "PLAY"}; static const char *const N_CLOCK[] = {"INT", "USB", "TRS"}; static const char *const N_MIDI_INPUT[] = {"USB", "TRS"}; -static const char *const N_ROUTE[] = {"CH1-4", "SEL"}; /* MIDI IN (seq.c): 1..4 -> parts, 5..16 ignored / all -> selected */ +static const char *const N_ROUTE[] = {"CH1-6", "SEL"}; /* MIDI IN (seq.c): 1..6 -> parts, 7..16 ignored / all -> selected */ static const char *const N_NOTE[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; static const char *const N_DASH[] = {"--"}; static const char *const N_RTYPE[] = {"ROOM", "SPRING", "SHIMR", "RESO", "CLOUD"}; /* (JIANT 0.5: + 3) */ /* G_RTYPE: the reverb bus's model (fx.c) */ diff --git a/firmware/src/perform.c b/firmware/src/perform.c index e9e33f5e..b5af2671 100644 --- a/firmware/src/perform.c +++ b/firmware/src/perform.c @@ -10,7 +10,7 @@ * REPEAT starts on the next 1/16 (at once while stopped); the filters at once; all end when let go, with a 2.9 ms * ramp. Effects of different kinds stack; of the REPEATs the last pressed plays, and letting it go returns to the * one held before. - * The buffer: the SLICER's recordings (sl_buf, 32 KB) borrowed as one stereo loop of 8192 frames at 22.05 kHz + * The buffer: the SLICER's recordings (sl_buf, its first 32 KB) borrowed as one stereo loop of 8192 frames at 22.05 kHz * (371 ms). While borrowed, STUT tracks play live; their recordings are dropped afterwards. A REPEAT 1/8 longer * than the loop at the tempo (below 81 BPM) does nothing (the map shows it dimmed). * KNOB 1..4 with FX: the macros FILTER (the LPF / HPF), CRUSH, THROW (the dry mix into the delay and reverb @@ -31,7 +31,8 @@ enum { PF_R8, PF_R16, PF_R32, PF_LPF, PF_HPF, #define PF_BUF PF_REPEAT /* the buffer effects */ #define PF_MUTE (((1u << NTRK) - 1u) << PF_M1) #define PF_MIDI (((1u << (PF_RND + 1)) - 1u) & ~((1u << PF_OCTD) - 1u)) /* PF_OCTD .. PF_RND: on the notes (pfx.c) */ -#define PB_FRAMES (NTRK * SL_LEN / 2u) /* stereo frames in sl_buf: 8192, 371 ms at 22.05 kHz */ +#define PB_FRAMES 8192u /* stereo frames in sl_buf (a power of 2: the mask), 371 ms at 22.05 kHz */ +_Static_assert(PB_FRAMES * 2u <= NTRK * SL_LEN && !(PB_FRAMES & (PB_FRAMES - 1u)), "the REPEAT loop in sl_buf"); #define PB_MAX (2u * PB_FRAMES) /* the longest loop, 44.1 kHz samples */ #define PF_TOP (63 << 8) /* filter cutoff index, Q8 (PF_SVF): the LPF's open end */ #define PF_LOW (14 << 8) /* .. the LPF sweep's end, the HPF sweep's (and K1's) top */ @@ -87,7 +88,7 @@ static struct { uint32_t cn; int32_t td; /* THROW: the share of the dry mix sent, Q15 */ int32_t mg[NTRK]; /* mute gains, Q15 (32768 = open) */ -} pf = {.src = PF_N, .next = PF_N, .lc = PF_TOP, .mg = {32768, 32768, 32768, 32768}}; +} pf = {.src = PF_N, .next = PF_N, .lc = PF_TOP, .mg = {[0 ... NTRK - 1] = 32768}}; /* (every track open: 0.6, six) */ /* the loop length of a REPEAT at the tempo, 44.1 kHz samples; 0 = not one */ static const uint8_t PF_DEN[PF_R32 + 1] = {2, 4, 8}; @@ -201,7 +202,7 @@ static void perf_buf_select(uint32_t e) * Returns 1 when a stage has something to do */ static __attribute__((noinline)) int perf_begin(uint32_t n) { - uint32_t held = perf_kill ? 0u : (perf_held | perf_latched | (perf_solo ? (~(uint32_t)perf_solo & 15u) << PF_M1 : 0u)) & perf_avail() & ~PF_MIDI; + uint32_t held = perf_kill ? 0u : (perf_held | perf_latched | (perf_solo ? (~(uint32_t)perf_solo & ((1u << NTRK) - 1u)) << PF_M1 : 0u)) & perf_avail() & ~PF_MIDI; uint32_t q, k, ph0, bnd; int32_t m; if (!held && !pf.busy && !(perf_k[0] | perf_k[1] | perf_k[2])) { /* idle: the clock only */ diff --git a/firmware/src/project.c b/firmware/src/project.c index cd839537..49542946 100644 --- a/firmware/src/project.c +++ b/firmware/src/project.c @@ -84,7 +84,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 0x46554E42u /* "FUNB": FUNA, 96 bytes longer (JIANT: DIST TYPE TONE, the modulation +#define PROJ_MAGIC 0x46554E43u /* "FUNC" (JIANT 0.6): six tracks, the steps packed (see proj_pack) */ +#define PROJ_MAGIC_VB 0x46554E42u /* "FUNB": FUNA, 96 bytes longer (JIANT: DIST TYPE TONE, the modulation * sequence: 120 parameters; the buses' new globals) */ #define PROJ_MAGIC_VA 0x46554E41u /* "FUNA": FUN9 + the DRUM-X kit (JIANT 0.1) */ #define PROJ_MAGIC_V9 0x46554E39u /* "FUN9": FUN8, 64 bytes longer (the DRUM lane levels, 99 parameters) */ @@ -100,6 +101,7 @@ #define PROJ_NG_V2 27u /* G_COUNT of formats 1 and 2 */ #define PROJ_NP_V3 57u /* P_COUNT of format 3 (P_E0 was 49) */ #define PROJ_NP_V4 69u /* P_COUNT of format 4 (P_E0 61) */ +#define PROJ_LT 4u /* the tracks of every format before FUNC */ #define PROJ_PHYS 2u /* project_t.phys: PHYS without DUST and DRUM (see the top) */ #define PROJ_NAME_LEN 12u /* the name: FUN7 bytes PROJ_NAME_OFF.. (the reserved tail's end) */ typedef struct { /* one track */ @@ -135,11 +137,11 @@ typedef struct { /* format 5, before the song chai uint32_t magic, size; int16_t g[PROJ_NG_V2]; uint8_t sel, parts, phys, rsv; - proj_trk_v5_t t[NTRK]; + proj_trk_v5_t t[PROJ_LT]; uint32_t sum; } project_v5_t; typedef struct { uint32_t magic, size; int16_t g[PROJ_NG_V2]; uint8_t sel, parts, phys, rsv; - proj_trk_v5_t t[NTRK]; chain_config_t chain; uint32_t sum; } project_v6_t; + proj_trk_v5_t t[PROJ_LT]; chain_config_t chain; uint32_t sum; } project_v6_t; _Static_assert(sizeof(project_v5_t) == 3352u && sizeof(project_v6_t) == 3388u, "frozen formats 5 / 6 sizes"); /* Serialized FUN7 keeps the retained cache's exact extent. Params are biased * bytes, steps pack n/time/flags. Reserved tail is zero and covered by hash. @@ -154,7 +156,7 @@ _Static_assert(sizeof(project_v5_t) == 3352u && sizeof(project_v6_t) == 3388u, " #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_FM6_OFF (PROJ_NAME_OFF - PROJ_LT * FM6_PACKED) /* (FUNB's layout: the tail kept by FUNC) */ #define PROJ_DX_SIZE 96u /* the kit, 88 bytes, and 8 reserved */ #define PROJ_DX_OFF (PROJ_FM6_OFF - PROJ_DX_SIZE) #define PROJ_PFX_OFF (PROJ_DX_OFF - 48u) /* the punch-in lane (32) and its tracks (1): FUN9's 48 spare bytes, 0 in @@ -166,7 +168,7 @@ _Static_assert(sizeof(dx_lane_t[8]) == 88u && PROJ_DX_OFF == 3216u, "the kit's p #define PROJ_GX_OFF (PROJ_PFX_OFF + 37u) /* (FUNB) after the lane, its tracks and the macros: 1, then the globals */ _Static_assert(37u + 1u + (G_COUNT - G_NSTORE) <= 48u, "the new globals in the punch-in block's spare bytes"); _Static_assert(G_COUNT - G_NSTORE == 10u, "marker 3 holds ten new globals"); -_Static_assert(68u + NTRK * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + sizeof(motion_store_t) <= PROJ_PFX_OFF, +_Static_assert(68u + PROJ_LT * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + sizeof(motion_store_t) <= PROJ_PFX_OFF, "the punch-in lane after the serialized part"); typedef struct { /* a track of format 4, read only */ int16_t p[PROJ_NP_V4]; @@ -177,7 +179,7 @@ typedef struct { /* format 4 (1.0 development buil uint32_t magic, size; int16_t g[PROJ_NG_V2]; uint8_t sel, parts, phys, rsv; - proj_trk_v4_t t[NTRK]; + proj_trk_v4_t t[PROJ_LT]; uint32_t sum; } project_v4_t; typedef struct { /* a track of format 3, read only */ @@ -189,7 +191,7 @@ typedef struct { /* format 3 (0.9 .. 1.0), read on uint32_t magic, size; int16_t g[PROJ_NG_V2]; uint8_t sel, parts, rsv[2]; - proj_trk_v3_t t[NTRK]; + proj_trk_v3_t t[PROJ_LT]; uint32_t sum; } project_v3_t; #define PROJ_DEF_SOUND 0xFFu /* preset byte: the track's power-on sound, no steps (format 1) */ @@ -203,7 +205,7 @@ typedef struct { /* format 2 (until 0.9), read onl uint32_t magic, size; int16_t g[PROJ_NG_V2]; uint8_t sel, rsv[3]; - proj_trk_v2_t t[NTRK]; + proj_trk_v2_t t[PROJ_LT]; uint32_t sum; } project_v2_t; typedef struct { /* format 1 (until 0.5 beta), read only */ @@ -278,13 +280,29 @@ static void proj_trk_from_v2(proj_trk_t *d, const proj_trk_v2_t *s) { proj_trk_from(d, s->p, PROJ_NP_V2, s->engine, s->preset, s->step); } +/* (JIANT 0.6) the tracks from `from` on of a project read from a format of PROJ_LT tracks: their power-on sounds + * (PROJ_DEF_SOUND: project_restore_runtime gives TRK_DEF's), no steps */ +static void proj_new_tracks(project_t *q, uint32_t from) +{ + uint32_t i, k; + for (i = from; i < NTRK; i++) { + for (k = 0; k < P_COUNT; k++) + q->t[i].p[k] = param_desc_of(trk_def_engine(i), k)->def; + q->t[i].engine = (uint8_t)trk_def_engine(i); + q->t[i].preset = PROJ_DEF_SOUND; + for (k = 0; k < NSTEP; k++) { + memset(&q->t[i].step[k], 0, sizeof q->t[i].step[k]); + q->t[i].step[k].time = ST_REST; + } + } +} /* a project written with the GM drum part as track 4 (parts 0) -> track 4 a part (see the top); * project_load gives it DRUM's kit (PROJ_DEF_KEEP; the SAMPLE PERC sound until 1.0.2). Idempotent */ static void proj_drums_to_part(project_t *q) { - proj_trk_t *d = &q->t[NTRK - 1u]; - if (q->parts == NPART) + proj_trk_t *d = &q->t[PROJ_LT - 1u]; + if (q->parts >= PROJ_LT) /* (4: a FUN7 .. FUNB, NPART: today's) */ return; d->engine = ENGI_DRUM; /* DRUM's first kit: independent of today's power-on drum sound */ d->preset = PROJ_DEF_KEEP; @@ -342,7 +360,7 @@ static void proj_fm4(project_t *q) return; for (i = n = 0; i < q->motion.count && i < MOTION_MAX; i++) { const motion_event_t *e = &q->motion.event[i]; - if (((hit >> (e->place >> 6)) & 1u) && (MOTION_ID(e) >= P_E0 || (MOTION_ID(e) >= P_FM1_ATK && MOTION_ID(e) <= P_FM4_LEVEL))) + if (((hit >> MOTION_TRK(e)) & 1u) && (MOTION_ID(e) >= P_E0 || (MOTION_ID(e) >= P_FM1_ATK && MOTION_ID(e) <= P_FM4_LEVEL))) continue; q->motion.event[n++] = *e; } @@ -389,7 +407,7 @@ static void proj_phys_gone(project_t *q) return; for (i = n = 0; i < q->motion.count && i < MOTION_MAX; i++) { const motion_event_t *e = &q->motion.event[i]; - if (((hit >> (e->place >> 6)) & 1u) && MOTION_ID(e) >= P_E0) + if (((hit >> MOTION_TRK(e)) & 1u) && MOTION_ID(e) >= P_E0) continue; q->motion.event[n++] = *e; } @@ -418,7 +436,7 @@ static void proj_perc(project_t *q) return; for (i = n = 0; i < q->motion.count && i < MOTION_MAX; i++) { const motion_event_t *e = &q->motion.event[i]; - if (((hit >> (e->place >> 6)) & 1u) && MOTION_ID(e) >= P_E0) + if (((hit >> MOTION_TRK(e)) & 1u) && MOTION_ID(e) >= P_E0) continue; q->motion.event[n++] = *e; } @@ -443,8 +461,9 @@ static int proj_from_v4(project_t *q, const project_v4_t *v4, int n) q->sel = v4->sel; q->parts = v4->parts; q->phys = v4->phys; - for (i = 0; i < NTRK; i++) + for (i = 0; i < PROJ_LT; i++) proj_trk_from(&q->t[i], v4->t[i].p, PROJ_NP_V4, v4->t[i].engine, v4->t[i].preset, v4->t[i].step); + proj_new_tracks(q, PROJ_LT); q->sum = proj_sum(q); proj_drums_to_part(q); return 1; @@ -464,8 +483,9 @@ static int proj_from_v3(project_t *q, const project_v3_t *v3, int n) proj_rtype_room(q->g); q->sel = v3->sel; q->parts = v3->parts; - for (i = 0; i < NTRK; i++) + for (i = 0; i < PROJ_LT; i++) proj_trk_from(&q->t[i], v3->t[i].p, PROJ_NP_V3, v3->t[i].engine, v3->t[i].preset, v3->t[i].step); + proj_new_tracks(q, PROJ_LT); q->sum = proj_sum(q); proj_drums_to_part(q); /* (a format 3 of firmware before 1.0: parts 0) */ return 1; @@ -483,8 +503,9 @@ static int proj_from_v2(project_t *q, const project_v2_t *v2, int n) q->size = sizeof *q; proj_g_from_v2(q->g, v2->g); q->sel = v2->sel; - for (i = 0; i < NTRK; i++) + for (i = 0; i < PROJ_LT; i++) proj_trk_from_v2(&q->t[i], &v2->t[i]); + proj_new_tracks(q, PROJ_LT); proj_drums_to_part(q); /* (format 2 had the drum track: parts 0) */ return 1; } @@ -503,15 +524,8 @@ static int proj_from_v1(project_t *q, const project_v1_t *v1, int n) proj_g_from_v2(q->g, v1->g); q->parts = NPART; /* (format 1 had no track 4) */ proj_trk_from_v2(&q->t[0], &v1->t); - for (i = 1; i < NTRK; i++) { /* the other tracks: their defaults, no steps */ - uint32_t k; - for (k = 0; k < P_COUNT; k++) - q->t[i].p[k] = param_desc_of(trk_def_engine(i), k)->def; - q->t[i].engine = (uint8_t)trk_def_engine(i); - q->t[i].preset = PROJ_DEF_SOUND; - for (k = 0; k < NSTEP; k++) - q->t[i].step[k].time = ST_REST; - } + (void)i; + proj_new_tracks(q, 1u); /* the other tracks: their defaults, no steps */ q->sum = proj_sum(q); return 1; } @@ -531,6 +545,7 @@ static void proj_fm6_init(project_t *q) } static int proj_import_old(project_t *q, const void *b, int n); static int proj_import_any(project_t *q, const void *b, int n); +static int proj_unpack_c(project_t *q, const uint8_t *b); /* every track's engine one this firmware has (DIGITAL, 1, is one: it converts): a project of another number * is not one (it never was: no engine number past the last was ever stored) */ static int proj_engines_ok(const project_t *q) @@ -555,6 +570,8 @@ static int proj_import(project_t *q, const void *b, int n) static int proj_import_any(project_t *q, const void *b, int n) { if (n == PROJ_STORE_SIZE && ((const uint32_t *)b)[0] == PROJ_MAGIC) + return proj_unpack_c(q, b); /* (JIANT 0.6: six tracks, packed) */ + if (n == PROJ_STORE_SIZE && ((const uint32_t *)b)[0] == PROJ_MAGIC_VB) return proj_unpack(q, b, PROJ_STORE_SIZE); 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 @@ -598,7 +615,7 @@ static int proj_import_old(project_t *q, const void *b, int n) proj_g_from_v2(q->g, v->g); proj_rtype_room(q->g); q->sel = v->sel; q->parts = v->parts; q->phys = v->phys; - for (i = 0; i < NTRK; i++) { + for (i = 0; i < PROJ_LT; i++) { int16_t def[P_COUNT]; if (v->t[i].engine >= NENGINES) return 0; for (k = 0; k < P_COUNT; k++) def[k] = param_desc_of(v->t[i].engine, k)->def; @@ -609,6 +626,7 @@ static int proj_import_old(project_t *q, const void *b, int n) q->t[i].step[k].flags &= 3u; /* (x1: no RATCH then) */ } } + proj_new_tracks(q, PROJ_LT); if (bytes == sizeof *v6) q->chain = v6->chain; else chain_defaults(&q->chain); q->sum = proj_sum(q); proj_drums_to_part(q); proj_phys(q); return 1; @@ -637,17 +655,144 @@ static uint32_t proj_name_get(char *d, const uint8_t *s) /* its length */ } /* A stable serialized schema: first header retains FUN6's fields; at byte66 - * np, format flags, then four byte-param tracks and nine-byte steps; FUN8: the patches at PROJ_FM6_OFF. */ + * np, format flags, then four byte-param tracks and nine-byte steps; FUN8: the patches at PROJ_FM6_OFF (FUNB: + * proj_unpack reads them all; JIANT 0.6 writes FUNC, below). */ +/* (JIANT 0.6) FUNC: six tracks in FUNB's 3840 bytes (a flash object's payload, a section slot), packed. Bytes 0..67 + * as FUNB's (b[66] the parameters stored, np; b[67] the tracks: 6); then each track: engine, preset; a byte, 1 when its + * FM6 patch follows (128 bytes: an FM6 track's, or one not the init patch); a map of its parameters that are not the + * engine's default ((np + 7) / 8 bytes) and those alone (biased bytes, +64); a 64-bit map of its steps that are not + * empty (step_clear's) and those alone, each: n | time << 3 | flags << 5 | X << 7; with X a byte x (bit 0 hit and + * accent follow, bit 1 the chance follows, bit 2 RATCH bit 1, bit 3 all four notes); its n notes (4 with x's bit 3); + * velocity | RATCH bit 0 << 7; hit, accent; chance. Then the chain, the motion's 4 header bytes and its records. The tail at fixed places + * from the end: the punch-in lane, the macros and the new globals (PROJC_PFX_OFF), the DRUM-X kit (PROJC_DX_OFF), the + * name, the hash. A project too full to fit: proj_pack 0 and proj_full set (SECTION FULL) */ +#define PROJC_DX_OFF (PROJ_NAME_OFF - PROJ_DX_SIZE) +#define PROJC_PFX_OFF (PROJC_DX_OFF - 48u) +#define PROJC_GX_OFF (PROJC_PFX_OFF + 37u) +#define PROJC_PMAP ((P_COUNT + 7u) / 8u) +static uint8_t proj_full; /* the last proj_pack failed for room (not for a value) */ +static int proj_step_empty(const step_t *s) +{ + return !s->n && s->time == ST_REST && !s->flags && !s->vel && !s->hit && !s->acc && !s->probability; +} +static uint32_t proj_step_x(const step_t *s, uint32_t *nn) /* its x byte (0: none), *nn the notes stored */ +{ + uint32_t r = step_ratchet(s) - 1u, j, all = 0; + for (j = s->n; j < 4u; j++) + all |= s->note[j]; + *nn = all ? 4u : s->n; + return (s->hit || s->acc ? 1u : 0u) | (s->probability ? 2u : 0u) | (r & 2u ? 4u : 0u) | (all ? 8u : 0u); +} +static uint32_t proj_step_size(const step_t *s) +{ + uint32_t nn, x = proj_step_x(s, &nn); + return 2u + nn + (x ? 1u + (x & 1u ? 2u : 0u) + (x & 2u ? 1u : 0u) : 0u); +} +static int proj_fm_kept(const project_t *q, uint32_t t) +{ + return q->t[t].engine == ENGI_FM6 || memcmp(q->fm6[t], FM6_INIT, FM6_PACKED) != 0; +} +static int16_t proj_pdef(uint32_t engine, uint32_t i) { return param_desc_of(engine, i)->def; } +/* the bytes q takes as FUNC up to the tail (PROJC_PFX_OFF: the room); more than the room: SECTION FULL */ +static uint32_t proj_packed_size(const project_t *q) +{ + uint32_t n = 68u + sizeof q->chain + 4u + q->motion.count * sizeof q->motion.event[0], t, i; + for (t = 0; t < NTRK; t++) { + uint32_t e = q->t[t].engine < NENGINES ? q->t[t].engine : 0u; + n += 3u + PROJC_PMAP + 8u + (proj_fm_kept(q, t) ? FM6_PACKED : 0u); + for (i = 0; i < P_COUNT; i++) + n += q->t[t].p[i] != proj_pdef(e, i); + for (i = 0; i < NSTEP; i++) + n += proj_step_empty(&q->t[t].step[i]) ? 0u : proj_step_size(&q->t[t].step[i]); + } + return n; +} static int proj_pack(project_store_t *out, const project_t *q) { - uint8_t *b = out->raw; uint32_t pos = 68u, t, i; uint32_t magic = PROJ_MAGIC, size = PROJ_STORE_SIZE, sum; - for (t = 0; t < NTRK; t++) + uint8_t *b = out->raw; uint32_t pos = 68u, t, i; uint32_t magic = PROJ_MAGIC, size = PROJ_STORE_SIZE, sum, mlen; + proj_full = 0; + for (t = 0; t < NTRK; t++) { /* the values first: out untouched when one is wrong */ + if (q->t[t].engine >= NENGINES) return 0; + for (i = 0; i < FM6_PACKED; i++) + if (q->fm6[t][i] > 127u) return 0; + for (i = 0; i < P_COUNT; i++) + if (q->t[t].p[i] < -64 || q->t[t].p[i] > 127) return 0; + for (i = 0; i < NSTEP; i++) { + const step_t *s = &q->t[t].step[i]; + if (s->n > 4u || s->time > ST_REST || (s->flags & ~(3u | SF_RATCH)) || s->probability > 101u) return 0; + } + } + if (!chain_valid(&q->chain) || !motion_valid(&q->motion) || P_COUNT > 127u || !dx_kit_ok(q->dx)) return 0; + if (proj_packed_size(q) > PROJC_PFX_OFF) { proj_full = 1; return 0; } + memset(out, 0, sizeof *out); memcpy(b, &magic, 4); memcpy(b + 4, &size, 4); + memcpy(b + 8, q->g, G_NSTORE * 2u); b[62] = q->sel; b[63] = q->parts; b[64] = q->phys; b[66] = P_COUNT; + b[67] = NTRK; + for (t = 0; t < NTRK; t++) { + uint32_t e = q->t[t].engine, map, fm = (uint32_t)proj_fm_kept(q, t); + b[pos++] = (uint8_t)e; b[pos++] = q->t[t].preset; b[pos++] = (uint8_t)fm; + if (fm) { memcpy(b + pos, q->fm6[t], FM6_PACKED); pos += FM6_PACKED; } + map = pos; + pos += PROJC_PMAP; + for (i = 0; i < P_COUNT; i++) + if (q->t[t].p[i] != proj_pdef(e, i)) { + b[map + i / 8u] |= (uint8_t)(1u << (i & 7u)); + b[pos++] = (uint8_t)(q->t[t].p[i] + 64); + } + map = pos; + pos += 8u; /* (the steps' map, filled below) */ + for (i = 0; i < NSTEP; i++) { + const step_t *s = &q->t[t].step[i]; + uint32_t r = step_ratchet(s) - 1u, nn, x, j; /* (what proj_unpack_c checks, so a saved project always + * loads: notes and velocity 0..127, accents only on hits) */ + if (proj_step_empty(s)) + continue; + x = proj_step_x(s, &nn); + b[map + i / 8u] |= (uint8_t)(1u << (i & 7u)); + b[pos++] = (uint8_t)(s->n | s->time << 3 | (s->flags & 3u) << 5 | (x ? 128u : 0u)); + if (x) + b[pos++] = (uint8_t)x; + for (j = 0; j < nn; j++) + b[pos++] = s->note[j] > 127u ? 127u : s->note[j]; + b[pos++] = (uint8_t)((s->vel > 127u ? 127u : s->vel) | (r & 1u) << 7); + if (x & 1u) { b[pos++] = s->hit; b[pos++] = s->acc & s->hit; } + if (x & 2u) b[pos++] = s->probability; + } + } + memcpy(b + pos, &q->chain, sizeof q->chain); pos += sizeof q->chain; + mlen = 4u + q->motion.count * sizeof q->motion.event[0]; + memcpy(b + pos, &q->motion, mlen); + memcpy(b + PROJC_PFX_OFF, q->pfx_lane, sizeof q->pfx_lane); + b[PROJC_PFX_OFF + sizeof q->pfx_lane] = q->pfx_ltgt > 2u ? 0u : q->pfx_ltgt; + for (i = 0; i < 4u; i++) + b[PROJC_PFX_OFF + sizeof q->pfx_lane + 1u + i] = q->macro[i] & 127u; + b[PROJC_GX_OFF] = 3u; /* the new globals (biased bytes, as FUNB's) */ + for (i = G_NSTORE; i < G_COUNT; i++) + b[PROJC_GX_OFF + 1u + i - G_NSTORE] = (uint8_t)(clamp(q->g[i], -64, 127) + 64); + memcpy(b + PROJC_DX_OFF, q->dx, sizeof q->dx); + b[PROJC_DX_OFF + sizeof q->dx] = q->dx_mute & DXG_ALL; + b[PROJC_DX_OFF + sizeof q->dx + 1u] = (uint8_t)(q->dx_mute >> 8); + b[PROJC_DX_OFF + sizeof q->dx + 2u] = 4u; /* (FUNB's marker 4: the values as today's) */ + memcpy(b + PROJC_DX_OFF + sizeof q->dx + 3u, q->dx_mot, sizeof q->dx_mot); + { /* the name (0-padded; stops at the first 0) */ + char n[PROJ_NAME_LEN + 1u]; + memcpy(b + PROJ_NAME_OFF, n, proj_name_get(n, (const uint8_t *)q->name)); + } + sum = proj_hash(b, PROJ_STORE_SIZE - 4u); memcpy(b + PROJ_STORE_SIZE - 4u, &sum, 4); + return 1; +} +#ifdef PROJ_FUNB_WRITER +/* (tests only) the first PROJ_LT tracks of q as FUNB, as JIANT 0.2 .. 0.5 wrote it: the older formats' imports are + * tested from it */ +static int proj_pack_vb(project_store_t *out, const project_t *q) +{ + uint8_t *b = out->raw; uint32_t pos = 68u, t, i; uint32_t magic = PROJ_MAGIC_VB, size = PROJ_STORE_SIZE, sum; + for (t = 0; t < PROJ_LT; t++) for (i = 0; i < FM6_PACKED; i++) if (q->fm6[t][i] > 127u) return 0; if (!chain_valid(&q->chain) || !motion_valid(&q->motion) || P_COUNT > 127u) return 0; memset(out, 0, sizeof *out); memcpy(b, &magic, 4); memcpy(b + 4, &size, 4); memcpy(b + 8, q->g, G_NSTORE * 2u); b[62] = q->sel; b[63] = q->parts; b[64] = q->phys; b[66] = P_COUNT; - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (i = 0; i < P_COUNT; i++) { if (q->t[t].p[i] < -64 || q->t[t].p[i] > 127) return 0; b[pos++] = (uint8_t)(q->t[t].p[i] + 64); @@ -683,7 +828,7 @@ static int proj_pack(project_store_t *out, const project_t *q) * 4 (0.5.4) LOFI BYTE / FLOAT's MOTN, GRIT / DCY; * 3 (0.4) LOFI's and ANALOG's new E values (core.h sound_v04) */ memcpy(b + PROJ_DX_OFF + sizeof q->dx + 3u, q->dx_mot, sizeof q->dx_mot); /* (0.5.1) X-MOD: 0 before it (off) */ - memcpy(b + PROJ_FM6_OFF, q->fm6, sizeof q->fm6); + memcpy(b + PROJ_FM6_OFF, q->fm6, PROJ_LT * FM6_PACKED); { /* the name (0-padded; stops at the first 0) */ char n[PROJ_NAME_LEN + 1u]; memcpy(b + PROJ_NAME_OFF, n, proj_name_get(n, (const uint8_t *)q->name)); @@ -691,6 +836,112 @@ static int proj_pack(project_store_t *out, const project_t *q) sum = proj_hash(b, PROJ_STORE_SIZE - 4u); memcpy(b + PROJ_STORE_SIZE - 4u, &sum, 4); return 1; } +#endif +/* a FUNC store (3840 bytes) -> q; 0 = not one (its hash, a value out of range, a length past its room) */ +static int proj_unpack_c(project_t *q, const uint8_t *b) +{ + uint32_t pos = 68u, t, i, size, sum, np = b[66], nt = b[67], room = PROJC_PFX_OFF; + memcpy(&size, b + 4, 4); memcpy(&sum, b + PROJ_STORE_SIZE - 4u, 4); + if (size != PROJ_STORE_SIZE || sum != proj_hash(b, PROJ_STORE_SIZE - 4u) || np < 8u || np > P_COUNT || !nt || nt > NTRK) + return 0; + memset(q, 0, sizeof *q); q->magic = PROJ_MAGIC; q->size = sizeof *q; + memcpy(q->g, b + 8, G_NSTORE * 2u); q->sel = b[62]; + for (i = G_NSTORE; i < G_COUNT; i++) { + uint32_t gm = b[PROJC_GX_OFF]; + q->g[i] = gm && gm <= 3u && i < G_NSTORE + (gm == 1u ? 5u : gm == 2u ? 9u : 10u) + ? (int16_t)clamp((int32_t)b[PROJC_GX_OFF + 1u + i - G_NSTORE] - 64, GP[i].min, GP[i].max) : GP[i].def; + } + q->parts = b[63]; q->phys = b[64]; + for (t = 0; t < nt; t++) { + int16_t values[P_COUNT], def[P_COUNT]; + uint32_t map, e, nc = np - 8u, pm = (np + 7u) / 8u; + if (pos + 3u > room) return 0; + q->t[t].engine = (uint8_t)(e = b[pos++]); q->t[t].preset = b[pos++]; + if (e >= NENGINES || b[pos] > 1u) return 0; + if (b[pos++]) { + if (pos + FM6_PACKED > room) return 0; + for (i = 0; i < FM6_PACKED; i++) q->fm6[t][i] = b[pos++] & 0x7Fu; + } else { + memcpy(q->fm6[t], FM6_INIT, FM6_PACKED); + } + for (i = 0; i < P_COUNT; i++) def[i] = proj_pdef(e, i); + map = pos; + pos += pm; + if (pos > room) return 0; + for (i = 0; i < np; i++) { /* (an older np: params_by_count's places, their defaults) */ + if (!((b[map + i / 8u] >> (i & 7u)) & 1u)) { + values[i] = def[i < nc ? i : P_E0 + i - nc]; + continue; + } + if (pos >= room || b[pos] > 191u) return 0; + values[i] = (int16_t)b[pos++] - 64; + } + params_by_count(q->t[t].p, values, np, def); + if (pos + 8u > room) return 0; + map = pos; + pos += 8u; + for (i = 0; i < NSTEP; i++) { + step_t *s = &q->t[t].step[i]; uint32_t meta, x = 0, nn, j, r; + if (!((b[map + i / 8u] >> (i & 7u)) & 1u)) { + s->time = ST_REST; /* (an empty step: step_clear's) */ + continue; + } + if (pos + 1u > room) return 0; + meta = b[pos++]; + s->n = meta & 7u; s->time = (meta >> 3) & 3u; s->flags = (meta >> 5) & 3u; + if (s->n > 4u || s->time > ST_REST) return 0; + nn = s->n; + if (meta & 128u) { + if (pos + 1u > room) return 0; + x = b[pos++]; + if (!x || (x & ~15u)) return 0; + if (x & 8u) nn = 4u; + } + if (pos + nn + 1u > room) return 0; + for (j = 0; j < nn; j++) + if ((s->note[j] = b[pos++]) > 127u) return 0; + s->vel = b[pos] & 127u; r = b[pos++] >> 7; + if (x & 1u) { + if (pos + 2u > room) return 0; + s->hit = b[pos++]; s->acc = b[pos++]; + if (s->acc & ~s->hit) return 0; + } + if (x & 2u) { + if (pos + 1u > room || (s->probability = b[pos++]) > 101u || !s->probability) return 0; + } + r |= (x >> 1) & 2u; + step_set_ratchet(s, r + 1u); + } + } + if (pos + sizeof q->chain + 4u > room) return 0; + memcpy(&q->chain, b + pos, sizeof q->chain); pos += sizeof q->chain; + memcpy(&q->motion, b + pos, 4u); pos += 4u; + if (q->motion.count > MOTION_MAX || pos + q->motion.count * sizeof q->motion.event[0] > room) return 0; + memcpy(q->motion.event, b + pos, q->motion.count * sizeof q->motion.event[0]); + if (!chain_valid(&q->chain) || !motion_valid(&q->motion)) return 0; + proj_new_tracks(q, nt); /* (a FUNC of fewer tracks: the rest at power-on) */ + for (t = nt; t < NTRK; t++) + memcpy(q->fm6[t], FM6_INIT, FM6_PACKED); + memcpy(q->pfx_lane, b + PROJC_PFX_OFF, sizeof q->pfx_lane); + q->pfx_ltgt = b[PROJC_PFX_OFF + sizeof q->pfx_lane] > 2u ? 0u : b[PROJC_PFX_OFF + sizeof q->pfx_lane]; + for (i = 0; i < 4u; i++) + q->macro[i] = b[PROJC_PFX_OFF + sizeof q->pfx_lane + 1u + i] & 127u; + memcpy(q->dx, b + PROJC_DX_OFF, sizeof q->dx); + if (!dx_kit_ok(q->dx)) return 0; + q->dx_mute = (uint16_t)((b[PROJC_DX_OFF + sizeof q->dx] & DXG_ALL) | b[PROJC_DX_OFF + sizeof q->dx + 1u] << 8); + memcpy(q->dx_mot, b + PROJC_DX_OFF + sizeof q->dx + 3u, sizeof q->dx_mot); + q->dx_mot[XM_RATE] = q->dx_mot[XM_RATE] > 8u ? 0u : q->dx_mot[XM_RATE]; + q->dx_mot[XM_DPTH] &= 127u; + q->dx_mot[XM_SHPE] = q->dx_mot[XM_SHPE] > 4u ? 0u : q->dx_mot[XM_SHPE]; + q->dx_mot[XM_RAND] &= 127u; + { + char n[PROJ_NAME_LEN + 1u]; + memcpy(q->name, n, proj_name_get(n, b + PROJ_NAME_OFF)); + } + q->parts = NPART; + q->sum = proj_sum(q); + return 1; +} /* the motion of a FUN7 / FUN8 written with np parameters (np < P_COUNT: a FUN7 of 89 before the chord keys, every * FUN8 of 91 before the DRUM lane levels) -> today's ids: an event names a parameter id, and the ids from that * store's P_E0 (np - 8) on moved up with P_E0, as its values did (params_by_count); the ones below kept theirs. A @@ -713,13 +964,13 @@ 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 vb = st == PROJ_STORE_SIZE, va = vb || st == PROJ_STORE_VA; /* (va: FUNA or FUNB, the kit's layout) */ - uint32_t name_off = st - 4u - PROJ_NAME_LEN, fm6_off = name_off - NTRK * FM6_PACKED; + uint32_t name_off = st - 4u - PROJ_NAME_LEN, fm6_off = name_off - PROJ_LT * 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 : st == PROJ_STORE_V9 ? PROJ_MAGIC_V9 : - st == PROJ_STORE_VA ? PROJ_MAGIC_VA : PROJ_MAGIC) || + st == PROJ_STORE_VA ? PROJ_MAGIC_VA : PROJ_MAGIC_VB) || 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) + np < 8u || np > P_COUNT || 68u + PROJ_LT * (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; memcpy(q->g, b + 8, G_NSTORE * 2u); q->sel = b[62]; @@ -731,7 +982,7 @@ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) q->parts = b[63]; q->phys = b[64]; if (v7 && (q->g[G_RTYPE] < 0 || q->g[G_RTYPE] > 1)) /* a FUN7 may still hold the old drum channel there */ proj_rtype_room(q->g); - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { int16_t values[P_COUNT], def[P_COUNT]; for (i = 0; i < np; i++) { if (b[pos] > 191u) return 0; values[i] = (int16_t)b[pos++] - 64; } q->t[t].engine = b[pos++]; q->t[t].preset = b[pos++]; @@ -755,7 +1006,7 @@ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) memcpy(&q->motion, b + pos, sizeof q->motion); if (!proj_motion_ids(&q->motion, np) || !chain_valid(&q->chain) || !motion_valid(&q->motion)) return 0; for (t = 0; t < NTRK; t++) { - if (v7) + if (v7 || t >= PROJ_LT) memcpy(q->fm6[t], FM6_INIT, FM6_PACKED); else for (i = 0; i < FM6_PACKED; i++) @@ -782,19 +1033,19 @@ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) q->dx_mot[XM_RAND] &= 127u; } if (!va || b[end + sizeof q->dx + 2u] < 1u || b[end + sizeof q->dx + 2u] > 4u) /* written before SHIFT: */ - for (t = 0; t < NTRK; t++) /* its chord keys are no offset */ + for (t = 0; t < PROJ_LT; t++) /* its chord keys are no offset */ q->t[t].p[P_SOFS] = q->t[t].p[P_POFS] = 0; if (!va || b[end + sizeof q->dx + 2u] < 2u || b[end + sizeof q->dx + 2u] > 4u) /* (JIANT) before FM: DRUM's E5 */ - for (t = 0; t < NTRK; t++) /* was ACC: FM off */ + for (t = 0; t < PROJ_LT; t++) /* was ACC: FM off */ if (q->t[t].engine == ENGI_DRUM) q->t[t].p[P_E5] = 0; if (!va || b[end + sizeof q->dx + 2u] < 3u || b[end + sizeof q->dx + 2u] > 4u) /* (JIANT 0.4) LOFI's, ANALOG's E * values as today's */ - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) sound_v04(q->t[t].engine, &q->t[t].p[P_E0]); if (!va || b[end + sizeof q->dx + 2u] < 4u || b[end + sizeof q->dx + 2u] > 4u) /* (0.5.4) a LOFI BYTE / FLOAT: E4 was * the old CUT (MOTN as written: 64), E5 its RES (GRIT, DCY: 0) */ - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) if (q->t[t].engine == 3u && q->t[t].p[P_E1] >= 5) q->t[t].p[P_E4] = 64, q->t[t].p[P_E5] = 0; if (!va) { @@ -802,6 +1053,7 @@ static int proj_unpack(project_t *q, const uint8_t *b, uint32_t st) q->dx_mute = 0; memset(q->dx_mot, 0, sizeof q->dx_mot); } + proj_new_tracks(q, PROJ_LT); /* (JIANT 0.6: tracks 5, 6 their power-on sounds) */ { char n[PROJ_NAME_LEN + 1u]; memcpy(q->name, n, proj_name_get(n, b + name_off)); @@ -835,7 +1087,7 @@ static void proj_legacy_drums(track_t *t) t->p[P_DIST + i] = (int16_t)(pr->fx[i] ? pr->fx[i] - 1 : FX_DEF[i]); } -static project_t proj_scratch; /* decoded main-loop work, never audio ISR */ +static project_t proj_scratch __attribute__((section(".pool"))); /* decoded main-loop work, never audio ISR (0.6: pool) */ static char proj_name[PROJ_NAME_LEN + 1u] /* the name of the music as it is now (loaded, saved, the editor's */ __attribute__((section(".pool"))); /* runtime restore); "" = none. A save takes it unless one is given */ #define PROJ_NO_SLOT 0xFFu @@ -953,7 +1205,7 @@ static int project_save_as(uint32_t slot, const char *name) memcpy(p->name, name, str_len(name) < PROJ_NAME_LEN ? str_len(name) : PROJ_NAME_LEN); } proj_wire_gen++; - if (!proj_pack(&proj_wire, p)) { ui_message("SAVE FORMAT ERROR"); return 2; } + if (!proj_pack(&proj_wire, p)) { ui_message(proj_full ? "SECTION FULL" : "SAVE FORMAT ERROR"); return 2; } #if FELUCCA_FLASH if (flash_ok) { @@ -1004,7 +1256,7 @@ static int project_rename(uint32_t slot, const char *name) memset(p->name, 0, sizeof p->name); memcpy(p->name, name, str_len(name) < PROJ_NAME_LEN ? str_len(name) : PROJ_NAME_LEN); proj_wire_gen++; - if (!proj_pack(&proj_wire, p)) { ui_message("SAVE FORMAT ERROR"); return 2; } + if (!proj_pack(&proj_wire, p)) { ui_message(proj_full ? "SECTION FULL" : "SAVE FORMAT ERROR"); return 2; } #if FELUCCA_FLASH if (flash_ok && st_save(proj_obj(slot), &proj_wire, sizeof proj_wire)) { ui_message("SAVE ERROR"); @@ -1312,8 +1564,37 @@ static int autosave_quiet(void) static void autosave_hold(void) { as.t = fm1_ms; } /* the editor's transfers: their staging RAM is proj_wire */ /* main loop, every pass (after settings_poll) */ +/* (JIANT 0.6) how full the music is for a section (FUNC): 1.5 s after the last change, once, said at 90 % and when it + * no longer fits (a section store or a save would say SECTION FULL; what is stored stays). Main loop, autosave_poll */ +static struct { uint32_t sig, t; uint8_t due, said; } proj_fill; +static uint32_t proj_fill_pct(void) +{ + project_capture(&proj_scratch); + return proj_packed_size(&proj_scratch) * 100u / PROJC_PFX_OFF; +} +static void proj_fill_poll(uint32_t sig) +{ + if (sig != proj_fill.sig) { + proj_fill.sig = sig; + proj_fill.t = fm1_ms; + proj_fill.due = 1; + } else if (proj_fill.due && fm1_ms - proj_fill.t >= 1500u) { + uint32_t pct = proj_fill_pct(); + proj_fill.due = 0; + if (pct > 100u && proj_fill.said < 2u) + ui_message("TOO FULL TO SAVE"); + else if (pct >= 90u && pct <= 100u && !proj_fill.said) + ui_message("SECTION 90% FULL"); + proj_fill.said = (uint8_t)(pct > 100u ? 2u : pct >= 90u ? (proj_fill.said ? proj_fill.said : 1u) : pct < 85u ? 0u : proj_fill.said); + } +} static void autosave_poll(void) { + static uint32_t fill_poll; + if (fm1_ms - fill_poll >= 250u) { /* (JIANT 0.6) how full the music is, flash or not */ + fill_poll = fm1_ms; + proj_fill_poll(autosave_sig()); + } #if FELUCCA_FLASH uint32_t sig; if (!flash_ok || fm1_ms - as.poll < AS_POLL_MS) diff --git a/firmware/src/song_chain.c b/firmware/src/song_chain.c index d3f4d71d..5182b8ce 100644 --- a/firmware/src/song_chain.c +++ b/firmware/src/song_chain.c @@ -25,7 +25,7 @@ static chain_config_t chain_config; /* the current song's rows */ * macros and the punch-in MIDI effects become what was stored; they stay through the rows after it that have none. * Stored by KNOB 4 on SONG (the state now) or by SONG REC (the state as each row began) */ typedef struct { - uint8_t on; /* 1 = the row has one */ + uint8_t on; /* bit 0 = the row has one; (JIANT 0.6) bits 1, 2: T5, T6 muted */ uint8_t mute; /* bits 0..3 T1..T4 muted, 4..7 DRUM's groups (DXG_*) */ uint16_t pfx; /* the punch-in MIDI effects held: bit k = PF_OCTD + k */ uint8_t mac[4]; /* M1..M4 (mod.c macro_v) */ @@ -40,11 +40,14 @@ static void song_idx_touch(void); /* song_main.c: the index changed, /* the state now as a scene (main loop: KNOB 4 on SONG; ISR: SONG REC) */ static void scene_capture(scene_t *s) { - uint32_t i, m = dx_mute & DXG_ALL; + uint32_t i, m = dx_mute & DXG_ALL, on = 1u; m <<= 4; for (i = 0; i < NTRK; i++) - m |= (trk[i].p[P_MUTE] ? 1u : 0u) << i; - s->on = 1; + if (trk[i].p[P_MUTE]) { + if (i < 4u) m |= 1u << i; + else on |= 1u << (i - 3u); + } + s->on = (uint8_t)on; s->mute = (uint8_t)m; s->pfx = (uint16_t)((((perf_held | perf_latched) & PF_MIDI) >> PF_OCTD) | (scene_pfx >> PF_OCTD)); memcpy(s->mac, macro_v, sizeof s->mac); diff --git a/firmware/src/song_main.c b/firmware/src/song_main.c index 1b5ac618..629bc228 100644 --- a/firmware/src/song_main.c +++ b/firmware/src/song_main.c @@ -186,10 +186,12 @@ static void section_store(uint32_t s) s &= 3u; b[0] = (char)('A' + s); project_capture(&proj_scratch); - if (!proj_pack(&proj_slot[s], &proj_scratch)) { - ui_message("SAVE FORMAT ERROR"); + if (!proj_pack(&proj_wire, &proj_scratch)) { /* (0.6: packed aside first, the section kept if it does not fit) */ + ui_message(proj_full ? "SECTION FULL" : "SAVE FORMAT ERROR"); return; } + proj_wire_gen++; + memcpy(&proj_slot[s], &proj_wire, sizeof proj_slot[s]); live.cur = (int8_t)s; live.dirty |= (uint8_t)(1u << s); ui_say("STORED ", b); diff --git a/firmware/src/song_play.c b/firmware/src/song_play.c index 7862794b..dbab8c52 100644 --- a/firmware/src/song_play.c +++ b/firmware/src/song_play.c @@ -62,7 +62,7 @@ static void scene_apply(uint32_t row) return; } for (i = 0; i < NTRK; i++) - trk[i].p[P_MUTE] = (int16_t)((s->mute >> i) & 1u); + trk[i].p[P_MUTE] = (int16_t)(i < 4u ? (s->mute >> i) & 1u : (s->on >> (i - 3u)) & 1u); dx_mute_set((uint16_t)((dx_mute & ~DXG_ALL) | ((s->mute >> 4) & DXG_ALL))); } static void chain_apply(void) /* a song row's section in */ diff --git a/firmware/src/ui_being.c b/firmware/src/ui_being.c index 4c5a892c..ff2112d6 100644 --- a/firmware/src/ui_being.c +++ b/firmware/src/ui_being.c @@ -191,7 +191,7 @@ static void graph_being(const track_t *t) * selected one larger, its number in the theme colour. Still in silence */ static void graph_ecosys(void) { - static const int16_t PX[NTRK] = {52, 128, 186, 92}, PY[NTRK] = {40, 34, 74, 88}; + static const int16_t PX[NTRK] = {44, 120, 196, 64, 146, 206}, PY[NTRK] = {34, 28, 40, 84, 78, 86}; static int32_t en[NTRK], sx[NTRK], sy[NTRK], vx[NTRK], vy[NTRK]; /* (positions and speeds, Q8 px; a frame) */ static uint32_t tm[NTRK], f0; static uint8_t init; @@ -215,7 +215,7 @@ static void graph_ecosys(void) track_t *t = &trk[c]; uint32_t e = t->eng_req % NENGINES; const genome_t *g = e == ENGI_DRUM ? &LANE_G_HOME : &GENOME[EGEN[e]]; - int32_t v = t->peak * 256 / 7000, r = (c == song.sel ? 19 : 14) * 16, rad, sp; + int32_t v = t->peak * 256 / 7000, r = (c == song.sel ? 17 : 12) * 16, rad, sp; uint8_t ids[4]; bfeat_t f; char num[2] = {(char)('1' + c), 0}; diff --git a/firmware/src/ui_draw.c b/firmware/src/ui_draw.c index c94b2276..af2be5f3 100644 --- a/firmware/src/ui_draw.c +++ b/firmware/src/ui_draw.c @@ -854,9 +854,9 @@ static void draw_columns(void) fmt_int(val, (int32_t)r + 1); str_cpy(val + str_len(val), "/", 4); fmt_int(val + str_len(val), (int32_t)n); - step = e->place & 63u; + step = MOTION_STEP(e); id = MOTION_ID(e); - v = e->value; + v = MOTION_VAL(e); } else { ev_fix(); str_cpy(val, "ADD", sizeof val); diff --git a/firmware/src/ui_events.c b/firmware/src/ui_events.c index e0dc0718..50bfcdba 100644 --- a/firmware/src/ui_events.c +++ b/firmware/src/ui_events.c @@ -133,7 +133,7 @@ static void ev_knob(uint32_t slot, int32_t s) } i = idx[r]; e = &motion.event[i]; - step = e->place & 63u; + step = MOTION_STEP(e); id = MOTION_ID(e); if (slot == 1u) { /* the next step where its parameter is free */ uint32_t top = ev_len(t) > step ? ev_len(t) : step + 1u, m = (uint32_t)(s > 0 ? s : -s); @@ -148,7 +148,7 @@ static void ev_knob(uint32_t slot, int32_t s) } if (to == (int32_t)step) return; - (void)motion_move(t, i, (uint32_t)to, id, e->value); + (void)motion_move(t, i, (uint32_t)to, id, MOTION_VAL(e)); } else if (slot == 2u) { /* another parameter, from the sound's own value */ uint32_t to = id, m = (uint32_t)(s > 0 ? s : -s); while (m--) /* a detent each: the next free parameter */ @@ -160,7 +160,7 @@ static void ev_knob(uint32_t slot, int32_t s) } else { /* the value */ d = track_desc(t, id); s = accel(EN_K1 + slot, s, d->fmt == F_ENUM ? 0 : d->max - d->min); - (void)motion_move(t, i, step, id, (int16_t)param_turn(d, e->value, s)); + (void)motion_move(t, i, step, id, (int16_t)param_turn(d, MOTION_VAL(e), s)); } ev_follow(i); } @@ -196,7 +196,7 @@ static void ev_oct(void) { const motion_event_t e = motion.event[idx[r]]; uint32_t lock = !(e.param & MOTION_LOCK); - (void)motion_put(t, e.place & 63u, MOTION_ID(&e), e.value, lock ? MOTION_LOCK : 0u); + (void)motion_put(t, MOTION_STEP(&e), MOTION_ID(&e), MOTION_VAL(&e), lock ? MOTION_LOCK : 0u); ui_message(lock ? "NOW A LOCK" : "NOW AUTOMATION"); } } @@ -215,7 +215,7 @@ static void ev_delete(void) if (ev_busy()) return; e = &motion.event[idx[r]]; - motion_delete_event(t, e->place & 63u, MOTION_ID(e)); + motion_delete_event(t, MOTION_STEP(e), MOTION_ID(e)); ui.ev_row = (uint8_t)r; /* (ev_row clamps it to the new count) */ ui_message("DELETED"); } diff --git a/firmware/src/ui_graph.c b/firmware/src/ui_graph.c index e068d71d..2a45d490 100644 --- a/firmware/src/ui_graph.c +++ b/firmware/src/ui_graph.c @@ -1059,14 +1059,14 @@ static void graph_events(void) char b[16], nm[12]; const char *unit; const param_desc_t *d = track_desc(t, id); - b[0] = (char)('0' + ((e->place & 63u) + 1u) / 10u); - b[1] = (char)('0' + ((e->place & 63u) + 1u) % 10u); + b[0] = (char)('0' + (MOTION_STEP(e) + 1u) / 10u); + b[1] = (char)('0' + (MOTION_STEP(e) + 1u) % 10u); b[2] = 0; GFX_HOOK_ALIGN(0, y, 0, y + 16, AL_V, "list row text centred up/down"); cv_text_on(14, y + CAP_IN(S, 16), &AF_S, lock ? "LOCK" : "AUTO", sel ? T_INK : lock ? T_ACCENT : T_MID, bg); GFX_HOOK_ALIGN(0, y, 0, y + 16, AL_V, "list row text centred up/down"); cv_text_on(54, y + CAP_IN(S, 16), &AF_S, b, sel ? T_INK : T_MID, bg); - param_format(d, e->value, b, &unit); + param_format(d, MOTION_VAL(e), b, &unit); if (unit && unit[0] && str_len(b) + str_len(unit) < sizeof b) str_cpy(b + str_len(b), unit, sizeof b - str_len(b)); ev_name(t, id, nm); @@ -1103,7 +1103,7 @@ static void graph_slots(void) #define KB_Y 37 #define KS_Y 86 /* PAN / REV knobs: boxes 86..105, centres x 15 and 42 */ static struct { - uint32_t col[NTRK]; + uint32_t col[4]; /* (the cards: the tracks from trk_base4) */ uint8_t meter[NTRK]; } ts; @@ -1204,11 +1204,11 @@ static void track_strip(uint32_t c, uint32_t sel, uint32_t st, uint32_t mute, ui cv_rrect(5, TSS_MY, gw, 3, 1, T_RAISE, T_SURF); if (m) cv_rrect(5, TSS_MY, m < 3 ? 3 : m, 3, 1, T_MID, T_RAISE); - cv_blit((uint32_t)CARD_X(c), LG_Y_GRAPH); + cv_blit((uint32_t)CARD_X(c - trk_base4()), LG_Y_GRAPH); } static void draw_tracks(void) { - uint32_t c, sk = strip_kind() == SK_TRK; + uint32_t c, sk = strip_kind() == SK_TRK, b4 = trk_base4(); if (ui.force) { lcd_fill(0, graph_y(), 240, graph_h(), T_BG); if (ux.style) /* LINE: the strips divided as the cards above */ @@ -1216,7 +1216,7 @@ static void draw_tracks(void) for (c = 0; c < NTRK; c++) ts.meter[c] = 0; } - for (c = 0; c < NTRK; c++) { + for (c = b4; c < b4 + 4u; c++) { /* (JIANT 0.6: four of the six) */ track_t *t = &trk[c]; uint32_t sel = c == song.sel, lvl = trk_level(c), mute = t->p[P_MUTE] != 0; uint32_t arm = (song.rec >> c) & 1u, st = arm ? (song.playing ? 1u : 2u) : mute ? 3u : 0u, sig; @@ -1232,10 +1232,10 @@ static void draw_tracks(void) m = ts.meter[c] - 1; /* falls ~2 dB a frame */ ts.meter[c] = (uint8_t)(m < 0 ? 0 : m); sig = str_hash(1u + sel + st * 2u + (mute && arm) * 16u + hot * 32u, b) + lvl * 7919u + - ts.meter[c] * 131u + (uint32_t)(pan + 128) * 104729u + (uint32_t)rv * 1299709u + mute * 3u + sk * 0x9E37u; - if (!ui.force && sig == ts.col[c]) + ts.meter[c] * 131u + (uint32_t)(pan + 128) * 104729u + (uint32_t)rv * 1299709u + mute * 3u + sk * 0x9E37u + c * 0x51u; + if (!ui.force && sig == ts.col[c - b4]) continue; - ts.col[c] = sig; + ts.col[c - b4] = sig; if (sk) { track_strip(c, sel, st, mute, arm, hot, lvl, b); continue; @@ -1324,7 +1324,7 @@ static void draw_tracks(void) cv_text_in(42 - KNOB_SMALL_R, KS_Y + 17, 2 * KNOB_SMALL_R, &AF_S, v, rc, T_SURF); } } - cv_blit((uint32_t)CARD_X(c), Y_GRAPH); + cv_blit((uint32_t)CARD_X(c - b4), Y_GRAPH); } } /* oscilloscope of the output, triggered on a rising zero crossing: a RAISE centre line, the trace 2 px (in silence diff --git a/firmware/src/ui_layer.c b/firmware/src/ui_layer.c index cea1d6f0..5e50effb 100644 --- a/firmware/src/ui_layer.c +++ b/firmware/src/ui_layer.c @@ -478,6 +478,9 @@ static void session_dice(uint32_t seed) macro_dice(0); } +/* GLO's white keys after the SOLOs (F3 ..): unmute all, tap tempo; KNOB 1..4: the levels from track trk_base4() */ +#define GLO_ALL ((uint32_t)NTRK) +#define GLO_TAP 7u static void layer_key(uint32_t l, uint32_t k) { uint32_t p = key_place(k), i; @@ -489,11 +492,11 @@ static void layer_key(uint32_t l, uint32_t k) dx_mute_set(dx_mute ^ (1u << (p - NTRK))); } else if (p < NTRK) { lys.solo |= 1u << k; /* (layer_masks: perf_solo while held) */ - } else if (p == 4u) { + } else if (p == GLO_ALL) { for (i = 0; i < NTRK; i++) trk[i].p[P_MUTE] = 0; dx_mute_set(0); - } else if (p == 7u) { + } else if (p == GLO_TAP) { glo_tap(); } } else if (l == LAYER_SCL) { @@ -548,11 +551,12 @@ static void layer_knob(uint32_t k, int32_t s) if (k == 3u) s = -s; /* DEPTH (100 - perf_k[3]) rises to the right (#40: it fell) */ perf_k[k] = (int8_t)clamp(perf_k[k] + accel(EN_K1 + k, s, k ? 100 : 200), k ? 0 : -100, 100); /* (#126) */ - } else if (l == LAYER_GLO) { /* T1..T4 LEVEL, recorded as on MIXER */ - int16_t *vp = &trk[k].p[P_LEVEL]; + } else if (l == LAYER_GLO) { /* T1..T4 LEVEL (T5, T6 selected: T3..T6), recorded as on MIXER */ + track_t *t = &trk[k + trk_base4()]; + int16_t *vp = &t->p[P_LEVEL]; *vp = (int16_t)clamp(*vp + accel(EN_K1 + k, s, TP[P_LEVEL].max - TP[P_LEVEL].min), TP[P_LEVEL].min, TP[P_LEVEL].max); - motion_capture(&trk[k], P_LEVEL, *vp); + motion_capture(t, P_LEVEL, *vp); } else if (l == LAYER_SAVE) { /* KNOB 1: the song (in when SAVE lets go); 2..4: none */ if (k == 0u) lys.song = (uint8_t)(clamp((int32_t)(lys.song ? lys.song - 1u : song_cur) + (s > 0 ? 1 : -1), 0, @@ -649,7 +653,7 @@ static uint32_t layer_leds(uint32_t *br) } else if (l == LAYER_GLO) { /* sounding lit; SOLO held lit, the others, C4, F4 breathe */ on = b ? (p < NTRK && glo_sounding(p)) || (p >= NTRK && p < NTRK + 4u && !((dx_mute >> (p - NTRK)) & 1u)) : p < NTRK && ((lys.solo >> k) & 1u); /* (a group sounding: lit) */ - can = !b && (p < NTRK || p == 4u || (p == 7u && !song.g[G_CLOCK])); + can = !b && (p < NTRK || p == GLO_ALL || (p == GLO_TAP && !song.g[G_CLOCK])); } else if (l == LAYER_SCL) { /* the root lit, the scale's notes breathe */ e = (k + 5u + 12u - root) % 12u; on = e == 0u; @@ -686,7 +690,9 @@ static uint32_t layer_leds(uint32_t *br) static const char *const PF_NAME[PF_M1] = {"1/8", "1/16", "1/32", "LPF", "HPF", /* the audio ones (perform.c) */ "OCT-", "OCT+", "1/2", "DEC-", "DEC+", "ST8", "ST16", "ATK+", "ARP", "RND"}; /* the MIDI ones (pfx.c) */ static const char W_NOTE[16] = {'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F', 'G'}; -static const char B_NOTE[8] = {'F', 'G', 'A', 'C', 'D', 'F', 'G', 'A'}; /* black keys 1..8: F# G# A# C# D# F# G# A# */ +static const char B_NOTE[10] = {'F', 'G', 'A', 'C', 'D', 'F', 'G', 'A', 'C', 'D'}; /* black keys 1..10: F# G# A# C# D# F# .. D# */ +#define G6_X(c) (7 + 38 * (int32_t)(c)) /* (JIANT 0.6) a cell per track: 36 px wide, 2 px apart */ +#define G6_W 36 #define LC_X(c) (6 + 58 * (int32_t)(c)) /* cell column c: 54 px wide, 4 px apart */ #define LC_W 54 #define LC_H 42 /* the big cells: rows at y 4 and 50 */ @@ -791,9 +797,10 @@ static void lcell(int32_t x, int32_t y, int32_t h, const char *note, uint32_t ic } } else { GFX_HOOK_ALIGN(0, y, 0, y + h, AL_V, "layer key cell icon / name centred up/down"); - cv_icon_in(x + lc_w - 31, y, 0, h, 12, icon, ink, fill); + if (icon != ICON_NONE) /* (JIANT 0.6: a narrow cell, G6_W, the track's alone) */ + cv_icon_in(x + lc_w - 31, y, 0, h, 12, icon, ink, fill); GFX_HOOK_ALIGN(0, y, 0, y + h, AL_V, "layer key cell icon / name centred up/down"); - cv_icon_in(x + lc_w - 17, y, 0, h, 12, icon2, ink, fill); + cv_icon_in(x + lc_w - (lc_w < LC_W ? 14 : 17), y, 0, h, 12, icon2, ink, fill); } if (tri) { int32_t j; @@ -817,11 +824,12 @@ static void layer_fx(void) lcell(LF_X(e % 5u), 4 + 28 * (int32_t)(e / 5u), 24, 0, ICON_COUNT, 0, PF_NAME[e], st, 0); /* (its name alone: the * cells stand where the keys do, 5 a row) */ } - lc_w = LC_W; - for (e = 0; e < NTRK; e++) { /* the mutes of the black keys 1..4 */ + lc_w = G6_W; + for (e = 0; e < NTRK; e++) { /* the mutes of the black keys 1..6 */ bnote(n, e); - lcell(LC_X(e), LM_Y, LM_H, n, ICON_MUTE, trk_icon(e, 0), 0, (held >> (PF_M1 + e)) & 1u ? LS_MUTE : LS_OFF, 0); + lcell(G6_X(e), LM_Y, LM_H, n, ICON_NONE, trk_icon(e, 0), 0, (held >> (PF_M1 + e)) & 1u ? LS_MUTE : LS_OFF, 0); } + lc_w = LC_W; } /* a track playing DRUM: the rows shrink (28, 28, 24 px) and the group mutes take the third */ static const char *const GLO_GROUP[4] = {"KICK", "SNR", "HAT", "PERC"}; @@ -830,22 +838,26 @@ static void layer_glo(void) uint32_t e, dr = (uint32_t)glo_drums(); int32_t h = dr ? 28 : LC_H, y2 = dr ? 36 : 50; char n[3] = {0, 0, 0}; - for (e = 0; e < NTRK; e++) { /* F3 .. B3: SOLO while held */ + lc_w = G6_W; + for (e = 0; e < NTRK; e++) { /* F3 .. D4: SOLO while held */ n[0] = W_NOTE[e]; - lcell(LC_X(e), 4, h, n, trk_icon(e, 0), 0, "SOLO", (perf_solo >> e) & 1u ? LS_HELD : LS_OFF, 1); + lcell(G6_X(e), 4, h, n, trk_icon(e, 0), 0, "SOLO", (perf_solo >> e) & 1u ? LS_HELD : LS_OFF, 1); } - n[0] = 'C'; + lc_w = LC_W; + n[0] = W_NOTE[GLO_ALL]; lcell(LC_X(0), y2, h, n, ICON_MUTE, 0, "ALL", LS_OFF, 0); /* (unmute all) */ - n[0] = 'F'; + n[0] = W_NOTE[GLO_TAP]; lcell(LC_X(3), y2, h, n, ICON_TEMPO, 0, "TAP", song.g[G_CLOCK] ? LS_DIM : LS_OFF, 0); - for (e = 0; dr && e < 4u; e++) { /* black keys 5..8: the DRUM groups, latched */ + for (e = 0; dr && e < 4u; e++) { /* black keys 7..10: the DRUM groups, latched */ bnote(n, NTRK + e); lcell(LC_X(e), 68, 24, n, 0, 0, GLO_GROUP[e], (dx_mute >> e) & 1u ? LS_MUTE : LS_OFF, 0); } - for (e = 0; e < NTRK; e++) { /* the black keys 1..4: MUTE, latched */ + lc_w = G6_W; + for (e = 0; e < NTRK; e++) { /* the black keys 1..6: MUTE, latched */ bnote(n, e); - lcell(LC_X(e), LM_Y, LM_H, n, ICON_MUTE, trk_icon(e, 0), 0, trk[e].p[P_MUTE] ? LS_MUTE : LS_OFF, 0); + lcell(G6_X(e), LM_Y, LM_H, n, ICON_NONE, trk_icon(e, 0), 0, trk[e].p[P_MUTE] ? LS_MUTE : LS_OFF, 0); } + lc_w = LC_W; } static void layer_scl(void) /* KNOB 2's scales, 4 x 4, the one now selected */ { @@ -1068,11 +1080,12 @@ static void layer_cards(uint32_t l) perf_k[2] * 10, ICON_DELAY); fmt_int(val, 100 - perf_k[3]); draw_column(3, "DEPTH", val, "%", VAL(3u), (100 - perf_k[3]) * 10, ICON_MIX); - } else if (l == LAYER_GLO) { /* T1..T4 LEVEL (the track's icon; muted: dim) */ - for (c = 0; c < NTRK; c++) { - param_format(&TP[P_LEVEL], trk[c].p[P_LEVEL], val, &unit); - draw_column(c, "LEVEL", val, unit, glo_sounding(c) ? VAL(c) : T_DIM, RATIO(&TP[P_LEVEL], trk[c].p[P_LEVEL]), - trk_icon(c, 1)); + } else if (l == LAYER_GLO) { /* T1..T4 LEVEL (T5, T6 selected: T3..T6; the icon; muted: dim) */ + for (c = 0; c < 4u; c++) { + uint32_t t = c + trk_base4(); + param_format(&TP[P_LEVEL], trk[t].p[P_LEVEL], val, &unit); + draw_column(c, "LEVEL", val, unit, glo_sounding(t) ? VAL(c) : T_DIM, RATIO(&TP[P_LEVEL], trk[t].p[P_LEVEL]), + trk_icon(t, 1)); } } else if (l == LAYER_SAVE) { /* the section, LOOP / SONG, SONG REC, the song row */ uint32_t n = lys.song ? lys.song - 1u : song_cur; @@ -1091,7 +1104,7 @@ static void layer_cards(uint32_t l) draw_column(c, M[c], val, "%", macro_routes(c, 0, 0) ? VAL(c) : T_DIM, macro_v[c] * 1000 / 127, ICON_MIX); } } else if (l == LAYER_REC) { /* CLICK, then empty cards */ - for (c = 0; c < NTRK; c++) { + for (c = 0; c < 4u; c++) { uint32_t v = c < RL_N ? rp_get(RL_F[c]) : 0u; if (c < RL_N) draw_column(c, RL_LABEL[c], rl_name(c, v), "", !v ? T_DIM : VAL(c), (int32_t)v * 500, RL_ICON[c]); @@ -1118,7 +1131,8 @@ static void draw_layer(void) sig += (perf_kill ? 0u : perf_held | perf_latched) * 31u + perf_latch_on * 11u + perf_act * 131u + perf_avail() * 7u; else if (l == LAYER_GLO) sig += perf_solo * 31u + (uint32_t)song.g[G_CLOCK] * 5u + - (uint32_t)(trk[0].p[P_MUTE] | trk[1].p[P_MUTE] << 1 | trk[2].p[P_MUTE] << 2 | trk[3].p[P_MUTE] << 3) * 131u + + (uint32_t)(trk[0].p[P_MUTE] | trk[1].p[P_MUTE] << 1 | trk[2].p[P_MUTE] << 2 | trk[3].p[P_MUTE] << 3 | + trk[4].p[P_MUTE] << 4 | trk[5].p[P_MUTE] << 5) * 131u + ((uint32_t)dx_mute * 2u + (uint32_t)glo_drums()) * 4099u; else if (l == LAYER_SCL) sig += (uint32_t)TSEL->p[P_SCALE] * 31u; diff --git a/firmware/src/ui_tools.c b/firmware/src/ui_tools.c index c079964f..7d721a37 100644 --- a/firmware/src/ui_tools.c +++ b/firmware/src/ui_tools.c @@ -57,8 +57,8 @@ static void tl_order(track_t *t, uint32_t len, const uint8_t *src) f = motion_guard(); for (j = 0; j < motion.count; j++) { motion_event_t *e = &motion.event[j]; - if ((e->place >> 6) == k && (e->place & 63u) < len) - e->place = (uint8_t)(k << 6 | to[e->place & 63u]); + if (MOTION_TRK(e) == k && MOTION_STEP(e) < len) + e->place = (uint8_t)((e->place & 0xC0u) | to[MOTION_STEP(e)]); /* (the track's bits kept, MOTION_TRK) */ } motion_unguard(f); } diff --git a/firmware/src/voice.c b/firmware/src/voice.c index c5eb52e5..63289b43 100644 --- a/firmware/src/voice.c +++ b/firmware/src/voice.c @@ -47,7 +47,7 @@ static uint32_t lfo_rand(track_t *t) * CUT (+-32 semitones; 64: the note: a resonance at the pitch), RES its feedback (up to ~0.99: long metallic rings); * the level kept about the dry's. One line a part (1024 samples: down to ~43 Hz) */ #define COMB_LEN 1024u -static int16_t comb_buf[NTRK][COMB_LEN]; +static int16_t comb_buf[NTRK][COMB_LEN] __attribute__((section(".pool"))); /* (0.6: six tracks, in the pool) */ static uint16_t comb_w[NTRK]; static int16_t comb_p16[NTRK]; static __attribute__((noinline)) void track_comb(track_t *t, int32_t *out, uint32_t n, int32_t cut, int32_t res) diff --git a/tests/backup_test.c b/tests/backup_test.c index 1d48f644..e9d61ce2 100644 --- a/tests/backup_test.c +++ b/tests/backup_test.c @@ -16,6 +16,7 @@ static void lcd_wake_now(void) {} static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p) { (void)x; (void)y; (void)w; (void)h; (void)p; } #define FELUCCA_FLASH 1 +#define PROJ_FUNB_WRITER 1 /* (JIANT 0.6) the FUN8 image below is made of a FUNB */ #include "../firmware/src/gfx.c" #include "../firmware/src/panel.c" #include "../firmware/src/ui.c" @@ -302,17 +303,17 @@ int main(void) uint32_t pos = 68u, pos9 = 68u, k, j, sum; trk[2].p[P_E0] = 2; project_capture(&proj_scratch); - proj_pack(&st, &proj_scratch); + proj_pack_vb(&st, &proj_scratch); /* (a FUNB: its fixed places) */ memcpy(v8, st.raw, 68); v8[66] = 91; - for (k = 0; k < NTRK; k++) { + for (k = 0; k < PROJ_LT; k++) { for (j = 0; j < 91u; j++) v8[pos++] = st.raw[pos9 + (j < 83u ? j : P_E0 + j - 83u)]; pos9 += P_COUNT; memcpy(v8 + pos, st.raw + pos9, 2u + NSTEP * 9u); pos += 2u + NSTEP * 9u; pos9 += 2u + NSTEP * 9u; } memcpy(v8 + pos, st.raw + pos9, sizeof(chain_config_t) + sizeof(motion_store_t)); - memcpy(v8 + 3056u, st.raw + PROJ_FM6_OFF, NTRK * FM6_PACKED); + memcpy(v8 + 3056u, st.raw + PROJ_FM6_OFF, PROJ_LT * FM6_PACKED); ((uint32_t *)v8)[0] = 0x46554E38u; ((uint32_t *)v8)[1] = 3584u; sum = proj_hash(v8, 3580u); @@ -327,7 +328,7 @@ int main(void) v6.size = sizeof v6; for (uint32_t i = 0; i < G_NSTORE; i++) v6.g[i] = GP[i].def; - for (uint32_t i = 0; i < NTRK; i++) + for (uint32_t i = 0; i < PROJ_LT; i++) v6.t[i].engine = trk[i].engine; v6.t[0].step[0] = (step10_t){{255, 72}, 9, 7, 0, 96, 0, 0}; v6.t[0].p[61] = 3; /* old E0 */ diff --git a/tests/editor_test.c b/tests/editor_test.c index 6cc4a483..b4c6dbb9 100644 --- a/tests/editor_test.c +++ b/tests/editor_test.c @@ -474,11 +474,11 @@ static int fm6_patches(void) a[1] = 5; request(ED_FM6_GET, a, 2); bad += check("an erased preset's patch is gone (GET rc 2)", host_wire[7] == 2u); - a[0] = ED_FM6_TRACK; a[1] = 4; + a[0] = ED_FM6_TRACK; a[1] = NTRK; request(ED_FM6_PUT, a, sizeof a); i = host_wire[7]; request(ED_FM6_PUT, a, 20); - bad += check("FM6_PUT: a fifth track or a short record: rc 1", i == 1u && host_wire[7] == 1u); + bad += check("FM6_PUT: a seventh track or a short record: rc 1", i == 1u && host_wire[7] == 1u); a[0] = 4; a[1] = 0; request(ED_FM6_GET, a, 2); bad += check("FM6_GET of an unknown target: rc 1", host_wire[7] == 1u); diff --git a/tests/fm4_div0_test.c b/tests/fm4_div0_test.c index 4220d6f8..f74eeaa5 100644 --- a/tests/fm4_div0_test.c +++ b/tests/fm4_div0_test.c @@ -247,10 +247,10 @@ int main(void) printf(" %u inputs, %u with INDEX + FLT ENV == 0\n", n_cmp, n_zero); /* 2. 0.9 projects with DIGITAL tracks (FUN3: P_E0 at 49, no OP ENV values or matrix yet) */ - for (k = 0; k < FM4_NPRESETS; k += NTRK) { + for (k = 0; k < FM4_NPRESETS; k += PROJ_LT) { static project_v3_t v3; static project_t q; - int16_t full[NTRK][P_COUNT], ref[P_COUNT]; + int16_t full[PROJ_LT][P_COUNT], ref[P_COUNT]; uint8_t v[FP_SIZE + 1u], pk[FM6_PACKED]; uint32_t t, pr, n; int ok; @@ -260,7 +260,7 @@ int main(void) for (i = 0; i < G_COUNT; i++) v3.g[i] = GP[i].def; v3.parts = NPART; - for (t = 0; t < NTRK; t++) { /* ORGAN PAD MARIMBA FUNK KEY, then E.PIANO BELL BASS BRASS */ + for (t = 0; t < PROJ_LT; t++) { /* ORGAN PAD MARIMBA FUNK KEY, then E.PIANO BELL BASS BRASS */ n = (k + t + 4u) % FM4_NPRESETS; defaults(full[t]); fm4_preset_values(full[t], n); @@ -273,7 +273,7 @@ int main(void) } v3.sum = proj_hash(&v3, sizeof v3 - 4u); ok = sizeof v3 == 2584u && proj_import(&q, &v3, (int)sizeof v3) && proj_ok(&q); - for (t = 0; t < NTRK && ok; t++) { + for (t = 0; t < PROJ_LT && ok; t++) { memcpy(ref, full[t], sizeof ref); pr = fm4_convert_ref(ref, v); fm6_pack(v, pk); diff --git a/tests/midi_control_test.c b/tests/midi_control_test.c index 36f5e076..81120f19 100644 --- a/tests/midi_control_test.c +++ b/tests/midi_control_test.c @@ -242,39 +242,39 @@ static int route_test(void) { int bad = 0; uint32_t ch, src, owned = 0; midi_test_reset(); song.sel = 2; - bad += check("ROUT defaults to CH1-4", song.g[G_ROUTE] == 0); + bad += check("ROUT defaults to CH1-6", song.g[G_ROUTE] == 0); for (src = 1; src <= 2u; src++) - for (ch = 4; ch < 16u; ch++) queued(0x90 | ch, 60 + ch, 100, src); - for (ch = 4; ch < 16u; ch++) owned |= mn_get(ch, 60 + ch); - bad += check("CH1-4: note-ons on channels 5..16 (USB and TRS) play nothing", !any_gate() && !owned && !midi_owners[2] && !midi_hint); + for (ch = 6; ch < 16u; ch++) queued(0x90 | ch, 60 + ch, 100, src); + for (ch = 6; ch < 16u; ch++) owned |= mn_get(ch, 60 + ch); + bad += check("CH1-6: note-ons on channels 7..16 (USB and TRS) play nothing", !any_gate() && !owned && !midi_owners[2] && !midi_hint); queued(0x91, 62, 100, 1); queued(0x93, 40, 100, 2); - bad += check("CH1-4: channels 2 and 4 still play parts 2 and 4", gate_note(&trk[1], 62) && mn_get(1, 62) == 2u && mn_get(3, 40) == 4u); - queued(0xE4, 127, 127, 1); queued(0xEF, 0, 0, 2); queued(0xE9, 127, 127, 1); - bad += check("CH1-4: pitch bend on channels 5, 10, 16 bends no part", !midi_bend_target[0] && !midi_bend_target[1] && !midi_bend_target[2] && !midi_ch[4].bend && !midi_ch[15].bend); - queued(0xB4, 1, 99, 1); queued(0xB9, 11, 10, 2); queued(0xDF, 77, 0, 1); - bad += check("CH1-4: CC1 / CC11 and aftertouch on channels 5..16 reach no MOD source", !trk[2].mw && !trk[2].ex_off && !trk[2].at && !trk[0].mw && !trk[0].at); - queued(0xB4, 101, 0, 1); queued(0xB4, 100, 0, 1); queued(0xB4, 6, 24, 1); - bad += check("CH1-4: RPN on channel 5 changes nothing", midi_ch[4].semis != 24u); - queued(0xB4, 64, 127, 1); queued(0x81, 62, 0, 1); - bad += check("CH1-4: a channel 5 sustain pedal does not hold channel 2's note", !gate_note(&trk[1], 62) && !mn_get(1, 62)); + bad += check("CH1-6: channels 2 and 4 still play parts 2 and 4", gate_note(&trk[1], 62) && mn_get(1, 62) == 2u && mn_get(3, 40) == 4u); + queued(0xE6, 127, 127, 1); queued(0xEF, 0, 0, 2); queued(0xE9, 127, 127, 1); + bad += check("CH1-6: pitch bend on channels 7, 10, 16 bends no part", !midi_bend_target[0] && !midi_bend_target[1] && !midi_bend_target[2] && !midi_ch[6].bend && !midi_ch[15].bend); + queued(0xB6, 1, 99, 1); queued(0xB9, 11, 10, 2); queued(0xDF, 77, 0, 1); + bad += check("CH1-6: CC1 / CC11 and aftertouch on channels 7..16 reach no MOD source", !trk[2].mw && !trk[2].ex_off && !trk[2].at && !trk[0].mw && !trk[0].at); + queued(0xB6, 101, 0, 1); queued(0xB6, 100, 0, 1); queued(0xB6, 6, 24, 1); + bad += check("CH1-6: RPN on channel 7 changes nothing", midi_ch[6].semis != 24u); + queued(0xB6, 64, 127, 1); queued(0x81, 62, 0, 1); + bad += check("CH1-6: a channel 7 sustain pedal does not hold channel 2's note", !gate_note(&trk[1], 62) && !mn_get(1, 62)); queued(0x91, 62, 100, 1); queued(0xB1, 1, 50, 1); - queued(0xB4, 120, 0, 1); queued(0xB9, 123, 0, 2); queued(0xBF, 121, 0, 1); - bad += check("CH1-4: CC120 / CC123 / CC121 on channels 5..16 leave parts 1..4 sounding", gate_note(&trk[1], 62) && gate_note(&trk[3], 40) && midi_owners[1] == 1u && trk[1].mw == 50); + queued(0xB6, 120, 0, 1); queued(0xB9, 123, 0, 2); queued(0xBF, 121, 0, 1); + bad += check("CH1-6: CC120 / CC123 / CC121 on channels 7..16 leave parts 1..4 sounding", gate_note(&trk[1], 62) && gate_note(&trk[3], 40) && midi_owners[1] == 1u && trk[1].mw == 50); queued(0xB1, 123, 0, 1); queued(0x83, 40, 0, 2); - bad += check("CH1-4: panic on channel 2 still works", !gate_note(&trk[1], 62) && !midi_owners[1] && !midi_owners[3]); + bad += check("CH1-6: panic on channel 2 still works", !gate_note(&trk[1], 62) && !midi_owners[1] && !midi_owners[3]); midi_test_reset(); song.sel = 2; song.g[G_ROUTE] = 1; trk[2].p[P_VOICE] = V_POLY; trk[2].p[P_SUS] = 127; events_block(CTL); - queued(0x90, 60, 100, 1); queued(0x94, 62, 100, 2); queued(0x99, 64, 100, 1); queued(0x9F, 65, 100, 2); - bad += check("SEL: channels 1, 5, 10, 16 all play the selected track", gate_note(&trk[2], 60) && gate_note(&trk[2], 62) && gate_note(&trk[2], 64) && gate_note(&trk[2], 65) && !gate_note(&trk[0], 60) && midi_owners[2] == 4u); - queued(0xEF, 127, 127, 1); queued(0xB9, 1, 66, 2); queued(0xD4, 33, 0, 1); - bad += check("SEL: bend, CC1 and aftertouch from channels 5..16 reach the selected track", midi_bend_target[2] == 512 && trk[2].mw == 66 && trk[2].at == 33); - queued(0xB4, 64, 127, 1); queued(0x84, 62, 0, 2); - bad += check("SEL: channel 5 pedal holds its note", gate_note(&trk[2], 62) && (mn_get(4, 62) & MIDI_PEDAL_NOTE)); + queued(0x90, 60, 100, 1); queued(0x96, 62, 100, 2); queued(0x99, 64, 100, 1); queued(0x9F, 65, 100, 2); + bad += check("SEL: channels 1, 7, 10, 16 all play the selected track", gate_note(&trk[2], 60) && gate_note(&trk[2], 62) && gate_note(&trk[2], 64) && gate_note(&trk[2], 65) && !gate_note(&trk[0], 60) && midi_owners[2] == 4u); + queued(0xEF, 127, 127, 1); queued(0xB9, 1, 66, 2); queued(0xD6, 33, 0, 1); + bad += check("SEL: bend, CC1 and aftertouch from channels 7..16 reach the selected track", midi_bend_target[2] == 512 && trk[2].mw == 66 && trk[2].at == 33); + queued(0xB6, 64, 127, 1); queued(0x86, 62, 0, 2); + bad += check("SEL: channel 7 pedal holds its note", gate_note(&trk[2], 62) && (mn_get(6, 62) & MIDI_PEDAL_NOTE)); song.g[G_ROUTE] = 0; events_block(CTL); - bad += check("SEL -> CH1-4 releases channels 5..16's notes (pedal-held too), keeps channel 1's", + bad += check("SEL -> CH1-6 releases channels 7..16's notes (pedal-held too), keeps channel 1's", !gate_note(&trk[2], 62) && !gate_note(&trk[2], 64) && !gate_note(&trk[2], 65) && gate_note(&trk[2], 60) && - !mn_get(4, 62) && !mn_get(9, 64) && !mn_get(15, 65) && midi_owners[2] == 1u && !midi_ch[4].pedal); - bad += check(".. and resets their bend: each part follows its own channel 1..4", !midi_bend_target[2] && !midi_ch[15].bend); + !mn_get(6, 62) && !mn_get(9, 64) && !mn_get(15, 65) && midi_owners[2] == 1u && !midi_ch[6].pedal); + bad += check(".. and resets their bend: each part follows its own channel 1..6", !midi_bend_target[2] && !midi_ch[15].bend); queued(0x80, 60, 0, 1); bad += check("channel 1's note-off still releases its note after the switch", !any_gate() && !midi_owners[2]); return bad; @@ -328,9 +328,9 @@ static int cc_map_test(void) queued(0xB0, 20, 99, 1); queued(0xB0, 76, 99, 1); queued(0xB0, 95, 99, 1); bad += check("CCs outside the map change nothing", !memcmp(before, trk[0].p, sizeof before)); memcpy(before, trk[2].p, sizeof before); - queued(0xB4, 7, 5, 1); queued(0xB9, 74, 5, 2); queued(0xBF, 91, 5, 1); + queued(0xB6, 7, 5, 1); queued(0xB9, 74, 5, 2); queued(0xBF, 91, 5, 1); ok = !memcmp(before, trk[2].p, sizeof before) && trk[0].p[P_LEVEL] != 5 && trk[3].p[P_LEVEL] != 5; - bad += check("ROUT CH1-4: mapped CCs on channels 5..16 reach no part", ok); + bad += check("ROUT CH1-6: mapped CCs on channels 7..16 reach no part", ok); song.g[G_ROUTE] = 1; song.sel = 2; events_block(CTL); queued(0xB9, 7, 5, 2); bad += check("ROUT SEL: channel 10's CC7 sets the selected track's LEVEL", trk[2].p[P_LEVEL] == 5 && trk[0].p[P_LEVEL] != 5); diff --git a/tests/motion_test.c b/tests/motion_test.c index ed525295..c8a1466a 100644 --- a/tests/motion_test.c +++ b/tests/motion_test.c @@ -85,12 +85,15 @@ static int compact_project(void) corrupt = packed; corrupt.raw[68] = 255; uint32_t sum = proj_hash(corrupt.raw, sizeof corrupt - 4u); memcpy(corrupt.raw + sizeof corrupt - 4u, &sum, 4); bad += check("compact parameter range is validated even with a correct hash", !proj_import(&after, &corrupt, sizeof corrupt)); - corrupt = packed; uint32_t probability_byte = 68u + P_COUNT + 2u + 8u; corrupt.raw[probability_byte] = 127; + corrupt = packed; uint32_t probability_byte = 68u + 3u + (proj_fm_kept(&before, 0) ? FM6_PACKED : 0u) + PROJC_PMAP + 8u + 7u; + for (uint32_t i = 0; i < P_COUNT; i++) /* (FUNC: track 1's engine, preset, patch, its changed parameters, the + * map; its step 4 alone: meta, x, 2 notes, velocity, hit, accent, chance) */ + probability_byte += before.t[0].p[i] != proj_pdef(before.t[0].engine, i); corrupt.raw[probability_byte] = 127; sum = proj_hash(corrupt.raw, sizeof corrupt - 4u); memcpy(corrupt.raw + sizeof corrupt - 4u, &sum, 4); bad += check("invalid probability is refused even with a correct hash", !proj_import(&after, &corrupt, sizeof corrupt)); project_v6_t old; memset(&old, 0, sizeof old); old.magic = PROJ_MAGIC_V6; old.size = sizeof old; memcpy(old.g, before.g, sizeof old.g); old.parts = NPART; old.phys = PROJ_PHYS; - for (uint32_t k = 0; k < NTRK; k++) { + for (uint32_t k = 0; k < PROJ_LT; k++) { for (uint32_t j = 0; j < 61u; j++) old.t[k].p[j] = before.t[k].p[j]; for (uint32_t j = 0; j < 8u; j++) old.t[k].p[61u + j] = before.t[k].p[P_E0 + j]; old.t[k].engine = before.t[k].engine; old.t[k].preset = before.t[k].preset; @@ -111,10 +114,10 @@ static int compact_project(void) * 81..88, motion ids from 81 on for E0..E7 (m: its events as that firmware numbered them) */ static void pack_fun7_89(project_store_t *out, const project_t *q, const motion_store_t *m) { - uint8_t *b = out->raw; uint32_t pos = 68u, t, i, magic = PROJ_MAGIC, size = PROJ_STORE_SIZE, sum; + uint8_t *b = out->raw; uint32_t pos = 68u, t, i, magic = PROJ_MAGIC_VB, size = PROJ_STORE_SIZE, sum; memset(out, 0, sizeof *out); memcpy(b, &magic, 4); memcpy(b + 4, &size, 4); memcpy(b + 8, q->g, sizeof q->g); b[62] = q->sel; b[63] = q->parts; b[64] = q->phys; b[66] = 89; - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (i = 0; i < 89u; i++) b[pos++] = (uint8_t)(q->t[t].p[i < 81u ? i : P_E0 + i - 81u] + 64); b[pos++] = q->t[t].engine; b[pos++] = q->t[t].preset; for (i = 0; i < NSTEP; i++) { @@ -146,7 +149,7 @@ static int fun7_89(void) m.event[2] = (motion_event_t){6, 61, 20}; /* FM OP1 ATK: 61 then and now */ pack_fun7_89(&old, &before, &m); ok = proj_import(&after, &old, sizeof old); - for (k = 0; ok && k < NTRK; k++) { + for (k = 0; ok && k < PROJ_LT; k++) { { int16_t e[8]; /* (DRUM's E5, ACC then, FM now: 0; LOFI's and ANALOG's */ for (i = 0; i < 8u; i++) e[i] = before.t[k].p[P_E0 + i]; /* E values as 0.4's: core.h sound_v04) */ diff --git a/tests/perform_test.c b/tests/perform_test.c index 7b04a4cc..52cda07e 100644 --- a/tests/perform_test.c +++ b/tests/perform_test.c @@ -47,7 +47,7 @@ static void perf_reset(void) memset(&pf, 0, sizeof pf); pf.src = pf.next = PF_N; pf.lc = PF_TOP; - pf.mg[0] = pf.mg[1] = pf.mg[2] = pf.mg[3] = 32768; + for (uint32_t m = 0; m < NTRK; m++) pf.mg[m] = 32768; perf_held = perf_act = 0; perf_kill = 0; memset((void *)perf_k, 0, sizeof perf_k); diff --git a/tests/persistence_test.c b/tests/persistence_test.c index b3164bc4..bb0584df 100644 --- a/tests/persistence_test.c +++ b/tests/persistence_test.c @@ -385,7 +385,7 @@ static int autosave_test(void) fail_after = -1; ok = as.err; as_power_on(); - ok &= autosave_boot(1) == 1 && song.g[G_BPM] != 150 && trk[0].step[8].n == 1u; + ok &= autosave_boot(1) == 1 && song.g[G_BPM] != 150 && trk[8u % NTRK].step[8].n == 1u; bad += check("autosave: a write cut short (power off): the copy before is restored", ok); /* wear: a 4-hour session: 3 h of editing (a change every 3 s), pauses and playing it back, then an hour away */ as_power_on(); @@ -659,8 +659,8 @@ int main(void) { /* FUN7 itself refuses a step outside its fields: a damaged slot is empty, the tracks stay */ step_t keep = trk[0].step[0]; old = proj_slot[0]; - proj_slot[0].raw[68 + P_COUNT + 2 + 4] = 7; /* track 1 step 1: n = 7 */ - bad += check("damaged FUN7 slot (hash ok, n > 4) is refused", (memcpy(proj_slot[0].raw + PROJ_STORE_SIZE - 4, + proj_slot[0].raw[67] = 9; /* (FUNC) 9 tracks: more than it can hold */ + bad += check("damaged FUN7 slot (hash ok, 9 tracks) is refused", (memcpy(proj_slot[0].raw + PROJ_STORE_SIZE - 4, &(uint32_t){proj_hash(proj_slot[0].raw, PROJ_STORE_SIZE - 4)}, 4), !project_used(0))); st_save(OBJ_PROJECT0, &proj_slot[0], sizeof proj_slot[0]); ui.msg[0] = 0; @@ -677,7 +677,7 @@ int main(void) v5.size = sizeof v5; for (i = 0; i < G_COUNT; i++) v5.g[i] = GP[i].def; - for (i = 0; i < NTRK; i++) { + for (i = 0; i < PROJ_LT; i++) { v5.t[i].engine = trk[i].engine; memcpy(v5.t[i].p, trk[i].p, sizeof v5.t[i].p); } diff --git a/tests/project_test.c b/tests/project_test.c index 9487feec..0e277917 100644 --- a/tests/project_test.c +++ b/tests/project_test.c @@ -21,6 +21,7 @@ #include "hostsim.c" #undef main #define PROJ_HOST 1 /* (trk_def_engine: engines.c, through hostsim.c) */ +#define PROJ_FUNB_WRITER 1 /* (JIANT 0.6) proj_pack_vb: the older formats are made of a FUNB */ #include "../firmware/src/project.c" static int check(const char *what, int ok) @@ -32,7 +33,7 @@ static int check(const char *what, int ok) /* the value parameter k (old id) of track t had in the old project */ static int16_t oldv(uint32_t t, uint32_t k) { return (int16_t)(t * 100u + k * 3u + 1u); } -static const uint8_t OLD_ENG[NTRK] = {7, 0, 5, 0}; /* WHEEL, ANALOG, VOICE; the drum track: 0 (no engine) */ +static const uint8_t OLD_ENG[PROJ_LT] = {7, 0, 5, 0}; /* WHEEL, ANALOG, VOICE; the drum track: 0 (no engine) */ static void fill_v2_track(proj_trk_v2_t *d, uint32_t t) { uint32_t k; @@ -89,7 +90,7 @@ static void to_v4(project_v4_t *v, const project_t *q) v->sel = q->sel; v->parts = q->parts; v->phys = q->phys; - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (k = 0; k < 61u; k++) v->t[t].p[k] = q->t[t].p[k]; for (k = 0; k < 8u; k++) v->t[t].p[61u + k] = q->t[t].p[P_E0 + k]; v->t[t].engine = q->t[t].engine; @@ -111,7 +112,7 @@ static void to_v4(project_v4_t *v, const project_t *q) static void v04_tracks(proj_trk_t *t) { uint32_t k; - for (k = 0; k < NTRK; k++) + for (k = 0; k < PROJ_LT; k++) sound_v04(t[k].engine, &t[k].p[P_E0]); } static int track_ok(const proj_trk_t *n, const proj_trk_v2_t *o, uint32_t t, int drum, int16_t lvl, int16_t rev) @@ -179,12 +180,12 @@ static void old_image(uint8_t *o, const project_store_t *st, uint32_t np, uint32 { const uint8_t *b = st->raw; uint32_t pos = 68u, src = 68u, t, j, sum, k; - uint32_t name = size - 4u - PROJ_NAME_LEN, fm6 = name - NTRK * FM6_PACKED; + uint32_t name = size - 4u - PROJ_NAME_LEN, fm6 = name - PROJ_LT * FM6_PACKED; memset(o, 0, size); memcpy(o, b, 68); memcpy(o, &magic, 4); memcpy(o + 4, &size, 4); o[66] = (uint8_t)np; - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (j = 0; j < np; j++) o[pos++] = b[src + (j < np - 8u ? j : P_E0 + j - (np - 8u))]; src += P_COUNT; memcpy(o + pos, b + src, 2u + NSTEP * 9u); @@ -202,7 +203,7 @@ static void old_image(uint8_t *o, const project_store_t *st, uint32_t np, uint32 memcpy(o + fm6 - 96u, b + PROJ_DX_OFF, 96u); } if (size >= PROJ_STORE_V8) - memcpy(o + fm6, b + PROJ_FM6_OFF, NTRK * FM6_PACKED); + memcpy(o + fm6, b + PROJ_FM6_OFF, PROJ_LT * FM6_PACKED); memcpy(o + name, b + PROJ_NAME_OFF, PROJ_NAME_LEN); sum = proj_hash(o, size - 4u); memcpy(o + size - 4u, &sum, 4); @@ -240,7 +241,7 @@ int main(void) for (i = 0; i < PROJ_NG_V2; i++) v2.g[i] = (int16_t)(500 + i); v2.sel = 2; - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) fill_v2_track(&v2.t[t], t); v2.sum = proj_hash(&v2, sizeof v2 - 4u); bad += check("FUN2 image is 2552 bytes (as stored)", sizeof v2 == 2552u); @@ -252,7 +253,7 @@ int main(void) ok &= q.g[i] == (i == G_RTYPE || i == G_DRLVL || i == G_DRREV ? 0 : (int16_t)(500 + i)); bad += check("FUN2 -> FUN6: globals (id 24, the old drum channel: ROOM; 25 26, the drum part's: off) and selected track", ok); ok = 1; - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) ok &= track_ok(&q.t[t], &v2.t[t], t, t == 3u, 127, 127); /* (G_DRLVL / G_DRREV 525 / 526: 127) */ bad += check("FUN2 -> FUN6: every parameter mapped, SLICER and matrix OFF (4 tracks)", ok); @@ -272,7 +273,7 @@ int main(void) v3.g[i] = (int16_t)(600 + i); v3.sel = 3; v3.parts = NPART; - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) fill_v3_track(&v3.t[t], t); v3.sum = proj_hash(&v3, sizeof v3 - 4u); bad += check("FUN3 image is 2584 bytes (as stored)", sizeof v3 == 2584u); @@ -281,7 +282,7 @@ int main(void) q.parts == NPART; for (i = 0; i < G_NSTORE; i++) ok &= q.g[i] == (i == G_RTYPE ? 0 : (int16_t)(600 + i)); - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) ok &= track_v3_ok(&q.t[t], &v3.t[t], t); bad += check("FUN3 -> FUN6: every parameter kept, the matrix OFF, steps, globals (24: ROOM)", ok); @@ -322,7 +323,7 @@ int main(void) project_v5_t old; memset(&old, 0, sizeof old); memcpy(old.g, q.g, sizeof old.g); old.sel = q.sel; old.parts = q.parts; old.phys = q.phys; - for (uint32_t k = 0; k < NTRK; k++) { + for (uint32_t k = 0; k < PROJ_LT; k++) { for (uint32_t j = 0; j < 61u; j++) old.t[k].p[j] = q.t[k].p[j]; for (uint32_t j = 0; j < 8u; j++) old.t[k].p[61u + j] = q.t[k].p[P_E0 + j]; old.t[k].engine = q.t[k].engine; old.t[k].preset = q.t[k].preset; @@ -332,7 +333,7 @@ int main(void) old.size = sizeof old; old.sum = proj_hash(&old, sizeof old - 4u); bad += check("FUN5 -> FUN6: sounds, grid and reserved lane bytes kept, no chain", - proj_import(&q2, &old, sizeof old) && (memcpy(qx, q.t, sizeof q.t), v04_tracks(qx), !memcmp(q2.t, qx, sizeof q.t)) && + proj_import(&q2, &old, sizeof old) && (memcpy(qx, q.t, sizeof q.t), v04_tracks(qx), !memcmp(q2.t, qx, PROJ_LT * sizeof q.t[0])) && !q2.chain.count && chain_valid(&q2.chain)); old.sum ^= 1u; bad += check("FUN5: damaged checksum refused", !proj_import(&q2, &old, sizeof old)); @@ -357,7 +358,7 @@ int main(void) !memcmp(q2.g, q.g, sizeof q.g); memcpy(qx, q.t, sizeof q.t); v04_tracks(qx); - for (t = 0; t < NTRK; t++) + for (t = 0; t < PROJ_LT; t++) ok &= !memcmp(q2.t[t].p, qx[t].p, sizeof q.t[t].p) && q2.t[t].engine == q.t[t].engine && steps_same(q2.t[t].step, v4.t[t].step); bad += check("FUN4 -> FUN6: parameters, engines, globals; steps as they were, no hits", ok); @@ -413,7 +414,7 @@ int main(void) memcpy(&buf, &v1, sizeof v1); ok = proj_import(&q, &buf, (int)sizeof v1) && proj_ok(&q) && track_ok(&q.t[0], &v1.t, 0, 0, 0, 0) && q.g[5] == 705 && q.parts == NPART; - for (t = 1; t < NTRK; t++) + for (t = 1; t < PROJ_LT; t++) ok &= q.t[t].preset == PROJ_DEF_SOUND && q.t[t].engine == trk_def_engine(t) && q.t[t].p[P_SLCR] == 0 && q.t[t].p[P_LEVEL] == TP[P_LEVEL].def && q.t[t].p[P_E0] == ENGINES[trk_def_engine(t)]->edit[0].def && q.t[t].step[0].time == ST_REST; bad += check("FUN1 -> FUN6: track 1 mapped, tracks 2..4 defaults", ok); @@ -483,26 +484,26 @@ int main(void) uint32_t i, zero = 1; bad += check("FUNB name at the end of the reserved tail, the FM6 patches and the kit before it, after the data (48: the punch-in block, no spare)", PROJ_NAME_OFF == 3824u && PROJ_FM6_OFF == 3312u && PROJ_DX_OFF == 3216u && - 68u + NTRK * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + sizeof(motion_store_t) + 48u == + 68u + PROJ_LT * (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); a.t[1].p[P_LEVEL] = 99; a.sum = proj_sum(&a); - ok = proj_pack(&st, &a); + ok = proj_pack_vb(&st, &a); for (i = 0; i < PROJ_NAME_LEN; i++) zero &= st.raw[PROJ_NAME_OFF + i] == 0u; bad += check("FUN7 no name: the tail all zero (as firmware before wrote it)", ok && zero); bad += check("FUN7 of before names (zero tail): loads, no name", proj_import(&c, &st, sizeof st) && !c.name[0] && c.t[1].p[P_LEVEL] == 99); memcpy(a.name, "lofi jam", 8); a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st); + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st); bad += check("FUN7 name round trip (upper case, 0-padded)", ok && !memcmp(c.name, "LOFI JAM\0\0\0\0", 12) && !memcmp(st.raw + PROJ_NAME_OFF, "LOFI JAM\0\0\0\0", 12)); memcpy(a.name, "ABCDEFGHIJKL", 12); /* 12: no 0 */ a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st); + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st); bad += check("FUN7 name of 12 characters (no terminator)", ok && !memcmp(c.name, "ABCDEFGHIJKL", 12)); st2 = st; st2.raw[PROJ_NAME_OFF + 3] ^= 1u; @@ -526,15 +527,15 @@ int main(void) memset(&a, 0, sizeof a); a.magic = PROJ_MAGIC; a.size = sizeof a; a.parts = NPART; a.phys = PROJ_PHYS; chain_defaults(&a.chain); - for (k = 0; k < NTRK; k++) { + for (k = 0; k < PROJ_LT; k++) { memcpy(a.fm6[k], FM6_FACTORY[k * 2u], FM6_PACKED); a.t[k].engine = ENGI_FM6; a.t[k].p[P_E7] = (int16_t)(k * 2u); } memcpy(a.name, "FM SONG", 7); a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && ((uint32_t *)st.raw)[0] == 0x46554E42u && proj_import(&c, &st, sizeof st); - for (k = 0; k < NTRK; k++) + ok = proj_pack_vb(&st, &a) && ((uint32_t *)st.raw)[0] == 0x46554E42u && proj_import(&c, &st, sizeof st); + for (k = 0; k < PROJ_LT; 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("FUNA: the four FM6 patches round trip (bytes at PROJ_FM6_OFF)", ok && !memcmp(c.name, "FM SONG", 7)); @@ -549,18 +550,18 @@ int main(void) 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) && + ok = proj_pack_vb(&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_mute = (uint16_t)(DXG_SNARE | DXG_PERC | DXM_LANE(6)); a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && st.raw[PROJ_DX_OFF + 88u] == (DXG_SNARE | DXG_PERC) && st.raw[PROJ_DX_OFF + 89u] == 0x40 && + ok = proj_pack_vb(&st, &a) && st.raw[PROJ_DX_OFF + 88u] == (DXG_SNARE | DXG_PERC) && st.raw[PROJ_DX_OFF + 89u] == 0x40 && proj_import(&c, &st, sizeof st) && c.dx_mute == a.dx_mute; bad += check("FUNA: the group and sound mutes round trip (the kit's first two reserved bytes)", ok); memset(a.pfx_lane, 0, sizeof a.pfx_lane); a.pfx_lane[2] = 0x21; a.pfx_lane[31] = 0xA0; a.pfx_ltgt = 2; a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && st.raw[PROJ_PFX_OFF + 2] == 0x21 && st.raw[PROJ_PFX_OFF + 32] == 2 && + ok = proj_pack_vb(&st, &a) && st.raw[PROJ_PFX_OFF + 2] == 0x21 && st.raw[PROJ_PFX_OFF + 32] == 2 && proj_import(&c, &st, sizeof st) && !memcmp(c.pfx_lane, a.pfx_lane, sizeof a.pfx_lane) && c.pfx_ltgt == 2; bad += check("FUNA: the punch-in lane round trips (the spare bytes at PROJ_PFX_OFF)", ok); { /* (JIANT 0.3) the nine new globals round trip behind a 2; a FUNB of 0.2 (behind a 1: five) loads the @@ -569,7 +570,7 @@ int main(void) a.g[G_RPRE] = 40; a.g[G_RFILT] = -30; a.g[G_RWIDE] = 90; a.g[G_DPIT] = -7; a.g[G_DSPRY] = 55; a.g[G_STRN] = -3; a.t[1].engine = ENGI_DRUM; a.t[1].p[P_E5] = 77; a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && st.raw[PROJ_GX_OFF] == 3u && proj_import(&c, &st, sizeof st) && + ok = proj_pack_vb(&st, &a) && st.raw[PROJ_GX_OFF] == 3u && proj_import(&c, &st, sizeof st) && c.g[G_RPRE] == 40 && c.g[G_RFILT] == -30 && c.g[G_RWIDE] == 90 && c.g[G_DPIT] == -7 && c.g[G_DSPRY] == 55 && c.g[G_STRN] == -3 && c.t[1].p[P_E5] == 77; bad += check("FUNB: the ten new globals round trip (FILT -30, PITCH -7, STRN -3: signed), DRUM's FM kept", ok); @@ -594,7 +595,7 @@ int main(void) for (i = 0; i < 8u; i++) a.t[2].p[P_E0 + i] = TS[i]; a.t[2].p[P_ATK] = 2; a.t[2].p[P_REL] = 40; a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st) && c.t[2].engine == 0 && + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st) && c.t[2].engine == 0 && c.t[2].p[P_E0] == 5 && c.t[2].p[P_E0 + 1] == 11 && c.t[2].p[P_E0 + 4] == 82 && c.t[2].p[P_E0 + 5] == 30 && c.t[2].p[P_ATK] == 2 && c.t[2].p[P_REL] == 40; bad += check("TRIO (engine 6, folded in): ANALOG SYNC (its INT2 9 the ratio, DTN 11), CUT RES and the envelope kept", ok); @@ -602,16 +603,16 @@ int main(void) for (i = 0; i < 8u; i++) a.t[2].p[P_E0 + i] = (int16_t)(i == 7u ? 4 : 0); a.t[2].p[P_ATK] = a.t[2].p[P_REL] = 0; a.sum = proj_sum(&a); - proj_pack(&st, &a); /* (st as before: the older images below are made of it) */ + proj_pack_vb(&st, &a); /* (st as before: the older images below are made of it) */ a.t[1].engine = ENGI_FM6; a.t[1].p[P_E5] = 0; a.sum = proj_sum(&a); } a.dx[2].a[DXP_PITCH] = 200; a.sum = proj_sum(&a); - ok = !proj_pack(&st2, &a); + ok = !proj_pack_vb(&st2, &a); a.dx[2].a[DXP_PITCH] = 60; a.sum = proj_sum(&a); - proj_pack(&st2, &a); + proj_pack_vb(&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); @@ -622,13 +623,13 @@ int main(void) (void)magic9; (void)size9; (void)sum9; old_image(v9, &st, 99u, 3648u, 0x46554E39u); /* FUN9 = FUNA without the kit (99 parameters) */ ok = proj_import(&c, v9, sizeof v9) && !c.dx_mute && !memcmp(c.dx, DX_KIT_DEF, sizeof c.dx) && - !memcmp(c.fm6, a.fm6, sizeof c.fm6) && !memcmp(c.name, "FM SONG", 7) && c.t[2].p[P_E7] == 4 && + !memcmp(c.fm6, a.fm6, PROJ_LT * sizeof c.fm6[0]) && !memcmp(c.name, "FM SONG", 7) && c.t[2].p[P_E7] == 4 && c.t[0].p[P_MSLEN] == 16 && c.g[G_RRATE] == 30; bad += check("FUN9 (Felucca 1.1) loads: its patches and name, the factory DRUM-X kit, the new values' defaults", ok); { /* FUNA (JIANT 0.1, 99 parameters): its kit, mutes and lane; the new parameters and globals their defaults */ static uint8_t va[3744]; a.dx_mute = DXG_SNARE; a.g[G_RMOD] = 77; a.t[1].p[P_DTYPE] = 3; a.sum = proj_sum(&a); - ok = proj_pack(&st2, &a); + ok = proj_pack_vb(&st2, &a); old_image(va, &st2, 99u, 3744u, 0x46554E41u); ok &= proj_import(&c, va, sizeof va) && c.dx_mute == DXG_SNARE && !memcmp(c.dx, a.dx, sizeof c.dx) && c.t[2].p[P_E7] == 4 && c.t[1].p[P_DTYPE] == 0 && c.g[G_RMOD] == 0 && c.t[3].p[P_MSDIV] == 2; @@ -653,20 +654,20 @@ int main(void) f.motion.event[2] = (motion_event_t){3u << 6 | 5u, (uint8_t)(P_LN2 | MOTION_LOCK), 40}; f.motion.event[3] = (motion_event_t){3u << 6 | 6u, (uint8_t)(P_E5 | MOTION_LOCK), -3}; f.sum = proj_sum(&f); - ok = proj_pack(&st, &f) && proj_import(&g, &st, sizeof st) && !memcmp(&f.motion, &g.motion, sizeof f.motion); + ok = proj_pack_vb(&st, &f) && proj_import(&g, &st, sizeof st) && !memcmp(&f.motion, &g.motion, sizeof f.motion); bad += check("FUN9 round trip: locks on a lane level (P_LN2) and an engine value (P_E5) kept", ok && - st.raw[68u + NTRK * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + 4u + 8u + 1u] == + st.raw[68u + PROJ_LT * (P_COUNT + 2u + NSTEP * 9u) + sizeof(chain_config_t) + 4u + 8u + 1u] == (P_LN2 | MOTION_LOCK) && g.motion.event[3].param == (P_E5 | MOTION_LOCK)); } e.motion.count = 3; /* a FUN8 of a 1.1 development build (91 parameters) could hold a lock: its E5 then */ e.motion.event[2] = (motion_event_t){3u << 6 | 6u, (uint8_t)(P_E5 | MOTION_LOCK), -3}; e.sum = proj_sum(&e); - ok = proj_pack(&st, &e); + ok = proj_pack_vb(&st, &e); (void)pos; (void)pos9; (void)j; old_image(v8, &st, 91u, 3584u, 0x46554E38u); /* (its E3 then: 86, its E5 a lock: 88 | the bit) */ ok &= v8[old_motion + 1u] == 83u + 3u && v8[old_motion + 8u + 1u] == ((83u + 5u) | MOTION_LOCK); ok = ok && proj_import(&c, v8, sizeof v8); - for (k = 0; ok && k < NTRK; k++) { + for (k = 0; ok && k < PROJ_LT; k++) { for (j = P_LN0; j <= P_LN7; j++) ok &= c.t[k].p[j] == 127; ok &= !memcmp(c.fm6[k], FM6_FACTORY[k * 2u], FM6_PACKED); } @@ -685,7 +686,7 @@ int main(void) /* the same music as FUN7 (3388 bytes, no patches): the data where it was, the name at 3372 */ old_image(v7, &st, 99u, PROJ_STORE_V7, 0x46554E37u); ok = proj_import(&c, v7, sizeof v7); - for (k = 0; k < NTRK; k++) + for (k = 0; k < PROJ_LT; k++) init &= !memcmp(c.fm6[k], FM6_INIT, FM6_PACKED); bad += check("FUN7 -> FUN9: the music and name kept, every track the init patch", ok && init && c.t[2].engine == ENGI_FM6 && c.t[2].p[P_E7] == 4 && !memcmp(c.name, "FM SONG", 7)); @@ -713,12 +714,12 @@ int main(void) bad += check("a retained slot of garbage is empty", !proj_import(&c, &slot, sizeof slot)); for (i = 0; i < FM6_PACKED; i++) a.fm6[1][i] = (uint8_t)(i | 0x80u); a.sum = proj_sum(&a); - bad += check("FUN8: a patch byte above 127 cannot be packed", !proj_pack(&st, &a)); + bad += check("FUN8: a patch byte above 127 cannot be packed", !proj_pack_vb(&st, &a)); memcpy(a.fm6[1], FM6_INIT, FM6_PACKED); a.t[0].step[3].n = 1; a.t[0].step[3].note[0] = 200; a.t[0].step[3].note[2] = 128; a.t[0].step[3].vel = 255; a.t[0].step[3].hit = 0x05; a.t[0].step[3].acc = 0xF7; a.sum = proj_sum(&a); - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st); + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st); bad += check("FUN8: a step out of range packs inside it (note, velocity 127; accents on hits): it loads", ok && c.t[0].step[3].note[0] == 127u && c.t[0].step[3].note[2] == 127u && c.t[0].step[3].vel == 127u && c.t[0].step[3].hit == 0x05u && c.t[0].step[3].acc == 0x05u); @@ -738,7 +739,7 @@ int main(void) memset(&a, 0, sizeof a); a.magic = PROJ_MAGIC; a.size = sizeof a; a.parts = NPART; a.phys = PROJ_PHYS; chain_defaults(&a.chain); - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (i = 0; i < P_COUNT; i++) a.t[t].p[i] = param_desc_of(t == 1u ? ENGI_DIGITAL : 0u, i)->def; a.t[t].engine = t == 1u ? ENGI_DIGITAL : 0u; @@ -761,7 +762,7 @@ int main(void) a.sum = proj_sum(&a); #define FM4_OK(c) ((c).t[1].engine == ENGI_FM6 && (c).t[1].preset == 4u && !memcmp((c).fm6[1], pk, FM6_PACKED) && \ !memcmp((c).t[1].p, p, sizeof p) && (c).t[0].engine == 0u && !memcmp((c).fm6[0], FM6_INIT, FM6_PACKED)) - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st); + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st); bad += check("FUN8 with a DIGITAL track: FM6, the converted patch its own, PTCH / preset FM6 PAD", ok && FM4_OK(c)); bad += check(" its motion on INDEX / OP LEVEL / E7 goes; a send's and the other track's stay", c.motion.count == 2u && c.motion.event[0].param == P_CHOR && c.motion.event[1].place == 3u && @@ -817,7 +818,7 @@ int main(void) memset(&a, 0, sizeof a); a.magic = PROJ_MAGIC; a.size = sizeof a; a.parts = NPART; a.phys = PROJ_PHYS; chain_defaults(&a.chain); - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (i = 0; i < P_COUNT; i++) a.t[t].p[i] = param_desc_of(ENGI_SAMPLE, i)->def; a.t[t].engine = ENGI_SAMPLE; @@ -840,7 +841,7 @@ int main(void) !memcmp((c).t[2].step, a.t[2].step, sizeof a.t[2].step) && \ (c).t[0].engine == ENGI_PHYS_TO && (c).t[0].p[P_E0] == ENGINES[ENGI_PHYS_TO]->presets[0].e[0] && \ (c).t[1].engine == ENGI_PHYS_TO) - ok = proj_pack(&st, &a) && proj_import(&c, &st, sizeof st); + ok = proj_pack_vb(&st, &a) && proj_import(&c, &st, sizeof st); bad += check("FUN8 with a SAMPLE PERC track: DRUM's kit, the rest of the sound and the steps kept; SAMPLE tracks ANALOG", ok && PERC_OK(c) && str_eq(ENGINES[ENGI_DRUM]->presets[0].name, "DRUM-X") && !memcmp(ENGINES[ENGI_DRUM]->presets[0].e, (int8_t[8])DRUM_KIT_E, 8)); @@ -861,7 +862,7 @@ int main(void) memset(&g, 0, sizeof g); g.magic = PROJ_MAGIC; g.size = sizeof g; g.parts = NPART; g.phys = PROJ_PHYS; chain_defaults(&g.chain); - for (t = 0; t < NTRK; t++) { + for (t = 0; t < PROJ_LT; t++) { for (i = 0; i < P_COUNT; i++) g.t[t].p[i] = param_desc_of(0, i)->def; memcpy(g.fm6[t], FM6_INIT, FM6_PACKED); memcpy(g.dx, DX_KIT_DEF, sizeof g.dx); @@ -871,12 +872,76 @@ int main(void) g.motion.event[0] = (motion_event_t){2u << 6 | 1u, P_E2, 30}; g.motion.event[1] = (motion_event_t){2u << 6 | 2u, P_REV, 40}; g.sum = proj_sum(&g); - ok = proj_pack(&gs, &g) && proj_import(&h, &gs, sizeof gs) && h.t[1].engine == ENGI_PHYS_TO && + ok = proj_pack_vb(&gs, &g) && proj_import(&h, &gs, sizeof gs) && h.t[1].engine == ENGI_PHYS_TO && h.t[2].engine == ENGI_PHYS_TO && h.t[2].p[P_LEVEL] == 66 && h.motion.count == 1u && h.motion.event[0].param == P_REV && h.t[2].p[P_E0] == ENGINES[ENGI_PHYS_TO]->presets[0].e[0] && !eng_ok(ENGI_GRAIN) && !eng_ok(ENGI_SLICE) && !eng_ok(ENGI_SAMPLE) && eng_live(ENGI_SLICE) == ENGI_PHYS_TO; bad += check("JIANT: GRAIN and SLICE tracks (retired) load as ANALOG, their engine motion gone, LEVEL and sends kept", ok); } + { /* (JIANT 0.6) FUNC: six tracks in FUNB's 3840 bytes, only the steps that are not empty stored */ + static project_t f, g, h; + static project_store_t fs, gs; + uint32_t k, i, n; + memset(&f, 0, sizeof f); + f.magic = PROJ_MAGIC; f.size = sizeof f; f.parts = NPART; f.phys = PROJ_PHYS; + chain_defaults(&f.chain); + proj_new_tracks(&f, 0u); + for (k = 0; k < NTRK; k++) memcpy(f.fm6[k], FM6_INIT, FM6_PACKED); + for (k = 0; k < G_COUNT; k++) f.g[k] = GP[k].def; + memcpy(f.dx, DX_KIT_DEF, sizeof f.dx); + for (k = 0; k < NTRK; k++) /* a typical song: 16 steps a track, T5 a chord on all 64 */ + for (i = 0; i < (k == 4u ? NSTEP : 16u); i++) { + step_t *s = &f.t[k].step[i]; + s->time = ST_NOTE; s->n = (uint8_t)(k == 4u ? 3u : 1u); s->vel = (uint8_t)(60u + k); + s->note[0] = (uint8_t)(40u + i); s->note[1] = 64; s->note[2] = 67; + if (i == 3u) step_set_ratchet(s, 3u), step_set_chance(s, 40u); + } + f.t[5].p[P_LEVEL] = 77; f.t[4].engine = ENGI_FM6; memcpy(f.fm6[4], FM6_FACTORY[3], FM6_PACKED); + motion_at(&f.motion.event[0], 5u << 6 | 9u, 33); f.motion.event[0].param = P_LEVEL; + motion_at(&f.motion.event[1], 4u << 6 | 2u, -20); f.motion.event[1].param = P_PAN | MOTION_LOCK; + f.motion.count = 2; f.motion.on = 0x30; + memcpy(f.name, "SIX", 3); + f.sum = proj_sum(&f); + ok = proj_pack(&fs, &f) && ((uint32_t *)fs.raw)[0] == PROJ_MAGIC && fs.raw[67] == NTRK && proj_import(&g, &fs, sizeof fs); + ok &= !memcmp(g.t, f.t, sizeof f.t) && !memcmp(g.fm6, f.fm6, sizeof f.fm6) && !memcmp(&g.motion, &f.motion, sizeof f.motion) && + !memcmp(g.name, "SIX", 3) && !memcmp(g.g, f.g, sizeof f.g) && !memcmp(g.dx, f.dx, sizeof f.dx); + ok &= MOTION_TRK(&g.motion.event[0]) == 5u && MOTION_STEP(&g.motion.event[0]) == 9u && MOTION_VAL(&g.motion.event[0]) == 33 && + MOTION_TRK(&g.motion.event[1]) == 4u && MOTION_VAL(&g.motion.event[1]) == -20; + bad += check("FUNC: six tracks round trip (steps, ratchet, chance, patches, T5 / T6 motion, name, globals)", ok); + ok = proj_pack_vb(&gs, &f) && proj_import(&h, &gs, sizeof gs) && !memcmp(h.t, f.t, PROJ_LT * sizeof f.t[0]) && + h.t[4].engine == trk_def_engine(4u) && h.t[5].engine == trk_def_engine(5u) && h.t[5].step[0].time == ST_REST; + bad += check("FUNB (0.5) -> six tracks: its four kept, T5 / T6 at their power-on sounds, empty", ok); + { /* damaged on purpose with the hash made right: refused or loaded, never read past the room (ASan) */ + static project_store_t z; + uint32_t r = 12345u, it, okz = 1, loaded = 0; + for (it = 0; it < 20000u; it++) { + uint32_t hz, nfl = 1u + (r >> 29), q2i; + z = fs; + for (q2i = 0; q2i < nfl; q2i++) { + r = r * 1664525u + 1013904223u; + z.raw[68u + (r >> 8) % (PROJC_PFX_OFF - 68u)] = (uint8_t)(r >> 24); + } + hz = proj_hash(z.raw, PROJ_STORE_SIZE - 4u); memcpy(z.raw + PROJ_STORE_SIZE - 4u, &hz, 4); + if (proj_import(&h, &z, sizeof z)) { + loaded++; + okz &= proj_ok(&h); + } + } + bad += check("FUNC: 20000 damaged sections (hash right): refused or loaded valid, nothing read past", okz && loaded < 20000u); + } + fs.raw[100] ^= 1u; + bad += check("FUNC: a byte changed: the hash refuses it", !proj_import(&g, &fs, sizeof fs)); + for (k = 0, n = 1; k < NTRK; k++) /* every step of every track a chord: too much for one slot */ + for (i = 0; i < NSTEP; i++) { + f.t[k].step[i].time = ST_NOTE; f.t[k].step[i].n = 4; f.t[k].step[i].hit = 3; f.t[k].step[i].acc = 1; + step_set_chance(&f.t[k].step[i], 50u); step_set_ratchet(&f.t[k].step[i], 4u); + } + f.sum = proj_sum(&f); + ok = !proj_pack(&fs, &f) && proj_full; + f.t[0].step[0].n = 9; /* (a value out of range: not for room) */ + ok &= !proj_pack(&fs, &f) && !proj_full; + bad += check("FUNC: six full tracks do not fit: not packed, proj_full (SECTION FULL); a bad value: not proj_full", ok && n); + } printf("%s\n", bad ? "PROJECT FORMAT TEST FAILED" : "project format test passed"); return bad != 0; } diff --git a/tests/ratchet_test.c b/tests/ratchet_test.c index 76ec06d9..358e0cd8 100644 --- a/tests/ratchet_test.c +++ b/tests/ratchet_test.c @@ -14,6 +14,7 @@ * The editor protocol (STEP_SET / TRACK_STEP, INFO 52 01 04) is in tests/editor_test.c. Built and run by * tests/run_tests.sh. */ #define UI_TEST_NO_MAIN 1 +#define PROJ_FUNB_WRITER 1 /* (JIANT 0.6) the byte checks below read a FUNB */ #include "ui_test.c" /* track 1 alone, a one-step loop: step 0 NOTE 60 (flags), RATCH hits, GATE 64, no swing; the transport started */ @@ -172,6 +173,7 @@ static int projects(void) after.t[0].step[i].vel == before.t[0].step[i].vel; bad += check("FUN8: x1..x4 round trip with their velocity, accent, chance (0 and 30 %) and lane hits", ok && step_ratchet(&after.t[3].step[5]) == 4u && after.t[3].step[5].hit == 0x81); + proj_pack_vb(&packed, &before); /* (FUNB: fixed places) */ pos = 68u + P_COUNT + 2u + 3u * 9u; /* step 3 of track 1: x4 -> bit 7 of its velocity and chance */ bad += check(" x4 is bit 7 of the velocity and the chance bytes", (packed.raw[pos + 5] & 128u) && (packed.raw[pos + 8] & 128u) && (packed.raw[pos + 5] & 127u) == before.t[0].step[3].vel); @@ -179,9 +181,9 @@ static int projects(void) for (i = 0; i < NSTEP; i++) trk[k].step[i].flags &= (uint8_t)~SF_RATCH; project_capture(&before); - proj_pack(&packed, &before); + proj_pack_vb(&packed, &before); ok = 1; - for (k = 0, pos = 68u; k < NTRK; k++, pos += P_COUNT + 2u + NSTEP * 9u) + for (k = 0, pos = 68u; k < PROJ_LT; k++, pos += P_COUNT + 2u + NSTEP * 9u) for (i = 0; i < NSTEP; i++) ok &= packed.raw[pos + P_COUNT + 2u + i * 9u + 5u] < 128u && packed.raw[pos + P_COUNT + 2u + i * 9u + 8u] < 128u; bad += check(" a project without ratchets: every velocity and chance byte below 128, as firmware before wrote", ok); @@ -194,7 +196,7 @@ static int projects(void) memset(old.raw + PROJ_STORE_V7 - 4u - PROJ_NAME_LEN, 0, PROJ_NAME_LEN); sum = proj_hash(old.raw, PROJ_STORE_V7 - 4u); memcpy(old.raw + PROJ_STORE_V7 - 4u, &sum, 4); ok = proj_import(&fun7, &old, PROJ_STORE_V7); - for (k = 0; ok && k < NTRK; k++) + for (k = 0; ok && k < PROJ_LT; k++) for (i = 0; i < NSTEP; i++) ok &= step_ratchet(&fun7.t[k].step[i]) == 1u; bad += check(" FUN7 of before: every step x1", ok && fun7.t[0].step[1].flags == SF_ACCENT); @@ -205,7 +207,7 @@ static int projects(void) v6.magic = PROJ_MAGIC_V6; v6.size = sizeof v6; v6.parts = NPART; v6.phys = PROJ_PHYS; memcpy(v6.g, before.g, sizeof v6.g); chain_defaults(&v6.chain); - for (k = 0; k < NTRK; k++) { + for (k = 0; k < PROJ_LT; k++) { for (i = 0; i < 69u; i++) v6.t[k].p[i] = TP[i < 61u ? i : i - 61u + P_E0].def; v6.t[k].step[0] = (step10_t){{60}, 1, ST_NOTE, 0xFBu, 100, 0, 0}; /* (stray high bits) */ } diff --git a/tests/robust_test.c b/tests/robust_test.c index 7abfa19f..0518a1d3 100644 --- a/tests/robust_test.c +++ b/tests/robust_test.c @@ -19,7 +19,7 @@ static int projects(void) reset(); project_capture(&p); bad += check("a captured project packs and imports", proj_pack(&st, &p) && proj_import(&q, &st, PROJ_STORE_SIZE)); - pos = 68u + st.raw[66]; /* track 1's engine byte (after its parameters) */ + pos = 68u; /* track 1's engine byte (FUNC: its first) */ for (e0 = NENGINES; e0 < 256u; e0 += 37u) { st.raw[pos] = (uint8_t)e0; sum = proj_hash(st.raw, PROJ_STORE_SIZE - 4u); @@ -30,7 +30,7 @@ static int projects(void) memset(&v5, 0, sizeof v5); /* FUN5 the same */ v5.magic = PROJ_MAGIC_V5; v5.size = sizeof v5; for (i = 0; i < G_NSTORE; i++) v5.g[i] = GP[i].def; - for (i = 0; i < NTRK; i++) { v5.t[i].engine = trk[i].engine; memcpy(v5.t[i].p, trk[i].p, sizeof v5.t[i].p); } + for (i = 0; i < PROJ_LT; i++) { v5.t[i].engine = trk[i].engine; memcpy(v5.t[i].p, trk[i].p, sizeof v5.t[i].p); } v5.t[2].engine = NENGINES; v5.sum = proj_hash(&v5, sizeof v5 - 4u); bad += check("FUN5 with an engine past the last is not a project", !proj_import(&q, &v5, sizeof v5)); diff --git a/tests/ui_test.c b/tests/ui_test.c index 2f8ac712..c82b3511 100644 --- a/tests/ui_test.c +++ b/tests/ui_test.c @@ -456,7 +456,7 @@ static int test_sound_loads(void) legacy.magic = PROJ_MAGIC_V6; legacy.size = sizeof legacy; legacy.parts = 0; legacy.phys = PROJ_PHYS; memcpy(legacy.g, decoded.g, sizeof legacy.g); - for (uint32_t ti = 0; ti < NTRK; ti++) { + for (uint32_t ti = 0; ti < PROJ_LT; ti++) { memcpy(legacy.t[ti].p, decoded.t[ti].p, 61u * sizeof(int16_t)); memcpy(legacy.t[ti].p + 61, decoded.t[ti].p + P_E0, 8u * sizeof(int16_t)); legacy.t[ti].engine = decoded.t[ti].engine; legacy.t[ti].preset = decoded.t[ti].preset; @@ -2589,7 +2589,7 @@ static int test_layer(void) for (i = 0; i < 15u; i++) /* the other effects (F3 .. F5): breathe */ ok &= i == 1u || ((a ^ b2) >> white(i)) & 1u; ok &= !((a | b2) >> white(15) & 1u); /* G5: no effect, dark */ - ok &= ((a ^ b2) >> key_at(1, 0)) & 1u && !((a | b2) >> key_at(1, 4) & 1u); /* a mute breathes, a spare black dark */ + ok &= ((a ^ b2) >> key_at(1, 0)) & 1u && !((a | b2) >> key_at(1, 6) & 1u); /* a mute breathes, a spare black dark */ song.g[G_BPM] = 72; a = leds_at(0); b2 = leds_at(250); ok &= !((a | b2) >> white(0) & 1u); /* 1/8: too long at 72 */ @@ -2928,6 +2928,26 @@ static int test_quick_layers(void) settings_import(&p, sizeof p) && layer_seen == 0x1Cu); } + { /* (JIANT 0.6) how full the music is for a section: said once, 1.5 s after the last change */ + uint32_t k2, i2, p0; + ui_power_on(); ui.msg_t = 0; + proj_fill_poll(autosave_sig()); fm1_ms += 2000u; proj_fill_poll(autosave_sig()); + p0 = proj_fill_pct(); + ok = !ui.msg_t && p0 < 35u; + for (k2 = 0; k2 < NTRK; k2++) /* every step a chord on every track: more than a section */ + for (i2 = 0; i2 < NSTEP; i2++) { + trk[k2].step[i2].time = ST_NOTE; trk[k2].step[i2].n = 4; trk[k2].step[i2].vel = 100; + trk[k2].step[i2].hit = 1; step_set_chance(&trk[k2].step[i2], 50u); /* (chords alone fit: 6 bytes a step) */ + } + proj_fill_poll(autosave_sig()); + ok &= !ui.msg_t; /* (not at once) */ + fm1_ms += 2000u; proj_fill_poll(autosave_sig()); + ok &= msg_is("TOO FULL TO SAVE") && proj_fill_pct() > 100u; + ui.msg_t = 0; fm1_ms += 2000u; proj_fill_poll(autosave_sig()); + ok &= !ui.msg_t; /* (said once) */ + bad += check("JIANT 0.6: the music too full for a section: TOO FULL TO SAVE once; the power-on music ~1/4 full", ok); + printf("ui: (power-on music: %u %% of a section)\n", (unsigned)p0); + } /* GLO: mutes latch (lit = sounding), SOLO while held, UNMUTE ALL, TAP, levels, OCT- */ ui_power_on(); usb.config = 1; mo = mo_w; @@ -2935,29 +2955,29 @@ static int test_quick_layers(void) ok = trk[1].p[P_MUTE] == 1 && ui.layer == LAYER_GLO && !gates() && mo_w == mo; a = leds_at(0); b2 = leds_at(250); ok &= ((a & b2) >> black(0)) & 1u && !(((a | b2) >> black(1)) & 1u); /* T1 sounding lit, T2 muted dark */ - ok &= ((a ^ b2) >> white(0)) & 1u && ((a ^ b2) >> white(7)) & 1u && !(((a | b2) >> white(5)) & 1u); + ok &= ((a ^ b2) >> white(0)) & 1u && ((a ^ b2) >> white(7)) & 1u && !(((a | b2) >> white(8)) & 1u); key_up(black(1)); btn_up(B_GLO); frame(); bad += check("GLO + black key 2: T2 MUTE latched (SET), silent, no MIDI; LEDs: sounding lit, muted dark", ok && trk[1].p[P_MUTE] == 1 && !ui.layer); - lay_combo(B_GLO, black(4)); key_up(black(4)); frame(); /* black keys 5..8: the DRUM group mutes */ - lay_combo(B_GLO, black(6)); key_up(black(6)); + lay_combo(B_GLO, black(6)); key_up(black(6)); frame(); /* black keys 7..10: the DRUM group mutes */ + lay_combo(B_GLO, black(8)); key_up(black(8)); a = leds_at(0); b2 = leds_at(250); - ok = dx_mute == (DXG_KICK | DXG_HAT) && ((a & b2) >> black(5)) & 1u && !(((a | b2) >> black(4)) & 1u) && - !(((a | b2) >> black(6)) & 1u) && trk[1].p[P_MUTE] == 1; + ok = dx_mute == (DXG_KICK | DXG_HAT) && ((a & b2) >> black(7)) & 1u && !(((a | b2) >> black(6)) & 1u) && + !(((a | b2) >> black(8)) & 1u) && trk[1].p[P_MUTE] == 1; btn_up(B_GLO); frame(); - lay_combo(B_GLO, black(6)); key_up(black(6)); btn_up(B_GLO); frame(); + lay_combo(B_GLO, black(8)); key_up(black(8)); btn_up(B_GLO); frame(); ok &= dx_mute == DXG_KICK; - lay_combo(B_GLO, white(4)); key_up(white(4)); btn_up(B_GLO); frame(); + lay_combo(B_GLO, white(6)); key_up(white(6)); btn_up(B_GLO); frame(); ok &= dx_mute == 0; - bad += check("GLO + black keys 5..8: KICK SNARE HAT PERC group mutes latched (lit = sounding), C4 clears them", ok); + bad += check("GLO + black keys 7..10: KICK SNARE HAT PERC group mutes latched (lit = sounding), E4 clears them", ok); lay_combo(B_GLO, black(1)); key_up(black(1)); btn_up(B_GLO); frame(); /* (T2 muted again, as the test goes on) */ lay_combo(B_GLO, black(1)); key_up(black(1)); frame(); - key_down(white(4)); key_up(white(4)); frame(); + key_down(white(6)); key_up(white(6)); frame(); lay_combo(B_GLO, black(2)); key_up(black(2)); frame(); ok = trk[1].p[P_MUTE] == 0 && trk[2].p[P_MUTE] == 1; - key_down(white(4)); frame(); key_up(white(4)); frame(); + key_down(white(6)); frame(); key_up(white(6)); frame(); btn_up(B_GLO); frame(); - bad += check(" again: unmuted; C4: UNMUTE ALL", ok && !trk[2].p[P_MUTE] && !trk[1].p[P_MUTE]); + bad += check(" again: unmuted; E4: UNMUTE ALL", ok && !trk[2].p[P_MUTE] && !trk[1].p[P_MUTE]); lay_combo(B_GLO, white(2)); perf_begin(CTL); ok = perf_solo == 4u && ((perf_act >> PF_M1) & 15u) == 0xBu; /* T3 solo: T1 T2 T4 muted */ @@ -7043,13 +7063,13 @@ static int test_organic(void) bad_dst += !m[1] || !m[2] || (pd && (pd->max <= pd->min || pd->label[0] == '-')); } } - ok = routes == 8u && per[0] == 2u && per[1] == 2u && per[2] == 2u && per[3] == 2u && !bad_dst && + ok = routes == 2u * NTRK && per[0] == NTRK / 2u && per[1] == NTRK / 2u && per[2] == NTRK / 2u && per[3] == NTRK / 2u && !bad_dst && trk[2].p[P_M1SRC] == MS_LFO && trk[2].p[P_M1AMT] == 30; session_dice(999u); /* (a session restored: its routes stay, none added) */ for (k = 0, j = 0; k < NTRK * 4u; k++) j += trk[k / 4u].p[P_M1SRC + 3u * (k % 4u)] >= MS_M1 && trk[k / 4u].p[P_M1SRC + 3u * (k % 4u)] < MS_M1 + 4; - ok &= j == 8u; - bad += check("MACRO DICE at power-on: 2 routes a track to what its sound has, each macro 2; own routes kept; restored: none added", ok); + ok &= j == 2u * NTRK; + bad += check("MACRO DICE at power-on: 2 routes a track to what its sound has, each macro 3; own routes kept; restored: none added", ok); go_home(); frames(64); song.playing = 1; /* (JIANT 0.5: a reroll routes the tracks that sound: playing, their steps) */ for (k = 0; k < NTRK; k++) { @@ -7063,7 +7083,7 @@ static int test_organic(void) key_down(white(0)); frame(); key_up(white(0)); frame(); /* F3: DICE */ for (k = 0, j = 0; k < NTRK * 4u; k++) j += trk[k / 4u].p[P_M1SRC + 3u * (k % 4u)] >= MS_M1 && trk[k / 4u].p[P_M1SRC + 3u * (k % 4u)] < MS_M1 + 4; - ok &= j == 8u; + ok &= j == 2u * NTRK; btn_up(B_LFO); frames(400); bad += check("MACRO layer: G3 clears the macros' routes (others kept), F3 rolls new ones", ok); { /* (JIANT 0.5) a reroll: only the tracks that sound now (track 2 muted: none) */ diff --git a/web/EDITOR_PROTOCOL.md b/web/EDITOR_PROTOCOL.md index 85609cab..5f19ca67 100644 --- a/web/EDITOR_PROTOCOL.md +++ b/web/EDITOR_PROTOCOL.md @@ -7,7 +7,7 @@ flash writes and live pushes (16-26, 32) have host coverage; that does not estab their hardware behavior. The step chance byte, motion (64) and the full backup (65-67) have host coverage only (`tests/editor_test.c`, `tests/backup_test.c`, `web/test_backup.mjs`). -**v3 (four tracks):** the device has four tracks, each a synth part (since 1.0; before it, track 4 +**v3 (tracks):** the device has NTRK tracks (six since JIANT 0.6, four before), each a synth part (since 1.0; before it, track 4 was a GM drum track: see "Track 4 since 1.0" below). One of them is *selected* (ALGORITHM on the device, or `TRACK`). Every v1 / v2 command acts on the selected track (its parameters, engine, preset, steps, the user presets it stores or loads); `TRACK`, @@ -124,7 +124,7 @@ watches (v2, `WATCH`), the device also sends push frames (cmds 23, 24, 26) at an | u32 (v7) | 5 bytes, 7 bits each, LSB first; the last byte is 0..15. Used by the backup commands | | string | ASCII bytes, ended by a 0 byte | | scope | 0 = parameter of the selected track (`P_*`, 0..P_COUNT−1); 1 = global parameter (`G_*`, 0..G_COUNT−1) | -| track | 0..3: tracks 1..4 (synth parts) | +| track | 0..NTRK-1: tracks 1..6 (synth parts; JIANT 0.6: six, INFO's NTRK; before, four) | | engine byte | 0..NENGINES−1 (firmware before 1.0: NENGINES = its drum track, no engine). The numbers are fixed, new engines are appended: 0 ANALOG, 1 reserved (DIGITAL before 1.0: see below), 2 PHASE, 3 LOFI, 4 SAMPLE, 5 VOICE, 6 TRIO, 7 WHEEL, 8 GRAIN, 9 reserved (PHYS until FELUCCA TONIC: its sounds load as ANALOG's first preset), 10 DRUM, 11 NOISE, 12 FM6, 13 SLICE (NENGINES 14; a build with `FELUCCA_SLICE=0` has 13). The device and the editor list them in another order (ANALOG FM6 PHASE LOFI SAMPLE VOICE TRIO WHEEL GRAIN NOISE SLICE DRUM: `ENGINE_ORDER`); the numbers stay | The engine parameters are `P_E0..P_E7`: P_COUNT−8 .. P_COUNT−1 (91..98), and `INFO` gives `P_E0`. @@ -208,7 +208,7 @@ at 1..3 and hides 6 5 8: what it sets still plays the right kit, and the device | cmd | Request args | Reply args | | --- | --- | --- | -| 1 INFO | — | version string, NENGINES, P_COUNT, G_COUNT, NSTEP, P_E0, then NENGINES engine-name strings, then (v3) NTRK (4), then (v6) CHAIN_ROWS (16), then the tagged blocks `55 01 uiCaps`, `4D 01 64 01`, `42 01 3`, `46 01 nfactory nbank`, `53 01 3`, (1.0.3) `50 01 3` and (1.0.4) `4E 01 count` (MENU settings; 12, 1.1: 15, 1.2: 17, 1.1.5: 18) and (1.0.5) `52 01 4` (ratchet) and (1.1) `4C 01 1` (parameter locks) (below); older firmware ends earlier | +| 1 INFO | — | version string, NENGINES, P_COUNT, G_COUNT, NSTEP, P_E0, then NENGINES engine-name strings, then (v3) NTRK (6 since JIANT 0.6, 4 before), then (v6) CHAIN_ROWS (16), then the tagged blocks `55 01 uiCaps`, `4D 01 64 01`, `42 01 3`, `46 01 nfactory nbank`, `53 01 3`, (1.0.3) `50 01 3` and (1.0.4) `4E 01 count` (MENU settings; 12, 1.1: 15, 1.2: 17, 1.1.5: 18) and (1.0.5) `52 01 4` (ratchet) and (1.1) `4C 01 1` (parameter locks) (below); older firmware ends earlier | | 2 GET | scope, id | scope, id, v14 | | 3 SET | scope, id, v14 | scope, id, v14 (the value after clamping). Setting global `G_ENGSEL` (id from DESC label "ENG") changes the engine: its defaults, then its first preset (as on the device) | | 4 DUMP | — | engine, preset, then P_COUNT × v14 (the selected track), then G_COUNT × v14 (globals) | @@ -452,7 +452,7 @@ grid lives in the steps themselves, so every engine has it: (3.20 with MENU > USB SERIAL OFF)); the MIDI port and this protocol are unchanged, and both work while the computer records. - **Global ids.** `G_ROUTE` (id 14, label "ROUT", GLO > SYSTEM) was a placeholder ("--", range 0..0); - since 1.0 it is the MIDI IN routing: 0 "CH1-4" (channels 1..4 → tracks 1..4; what projects stored + since 1.0 it is the MIDI IN routing: 0 "CH1-6" (JIANT 0.6; "CH1-4" before: channels 1..6 → tracks 1..6; what projects stored before. Until 1.0.2 every other channel played the selected track; since 1.0.3 channels 5..16 are ignored: notes, bend, CCs, aftertouch, panic and reset), 1 "SEL" (every channel → the selected track). Neither setting affects this SysEx protocol or MIDI clock. The diff --git a/web/editor.html b/web/editor.html index 0c7899ad..72963951 100644 --- a/web/editor.html +++ b/web/editor.html @@ -588,7 +588,7 @@ const req = { return [CMD.SONG, op === 1 ? [op, rows.length, ...rows.flatMap((r) => [r.slot, r.repeat])] : [op]]; }, motion: (track, op = 0, arg = {}) => { - if (!Number.isInteger(track) || track < 0 || track > 3 || ![0, 1, 2, 3, 4].includes(op)) throw new Error("Invalid motion request"); + if (!Number.isInteger(track) || track < 0 || track > 5 || ![0, 1, 2, 3, 4].includes(op)) throw new Error("Invalid motion request"); return [CMD.MOTION, [track, ...(op === 0 ? [] : op === 1 ? [op, arg.on ? 1 : 0] : op === 2 ? [op] : [op, arg.step & 63, arg.param & 127, ...(op === 3 ? v14enc(arg.value) : [])])]]; }, @@ -1435,7 +1435,7 @@ function makeMockDevice(opt = {}) { E("TIME", NDTIME, 1), D("FDBK", F.PCT, 0, 120, 60), D("TONE", F.PCT, 0, 127, 64), D("MIX", F.PCT, 0, 127, 90), /* (JIANT 0.4: free times past the divisions; TONE: COLR + HPF in one) */ D("SIZE", F.PCT, 0, 127, 90), D("DAMP", F.PCT, 0, 127, 60), D("CRT", F.LFOHZ, 0, 127, 40), D("CDP", F.PCT, 0, 127, 60), - E("MIDI", ["USB", "TRS"], 0), D("REL", F.PCT, 0, 100, 30), /* G_DREL (was SYNC): DUCK's release */ E("ROUT", ["CH1-4", "SEL"], 0), D("CPU", F.INT, 0, 0, 0), + E("MIDI", ["USB", "TRS"], 0), D("REL", F.PCT, 0, 100, 30), /* G_DREL (was SYNC): DUCK's release */ E("ROUT", ["CH1-6", "SEL"], 0), D("CPU", F.INT, 0, 0, 0), D("SLOT", F.INT, 1, 4, 1), E("NAME", NDASH, 0), E("LOAD", NGO, 0), E("SAVE", NGO, 0), E("ENG", ["ANALOG", "-", "PHASE", "LOFI", "-", "VOICE", "-", "WHEEL", "-", "-", "DRUM", "NOISE", "FM6", "-"], 0), D("CLIP", F.PCT, 0, 100, 0), /* G_CLIP (was SET) */ @@ -1558,14 +1558,14 @@ function makeMockDevice(opt = {}) { const P_COUNT = 123, G_COUNT = 37, NSTEP = 64, P_E0 = 115, G_ENGSEL = 20, P_SLCR = 45; const clamp = (v, a, b) => Math.max(a, Math.min(b, v)); const enumOrig = (d, v) => d.fmt === F.ENUM && d.names ? aliasOf(d.names, v - d.min) + d.min : v; /* params.c enum_orig */ - /* four tracks (firmware v3), four synth parts (1.0); engine / preset / p / step below are the selected track's */ - const NTRK = 4; + /* tracks (firmware v3): four synth parts (1.0), six (JIANT 0.6); engine / preset / p / step below are the selected track's */ + const NTRK = 6; const newTrack = () => ({ engine: 0, preset: 0, fm6: FM6.INIT_PK.slice(), p: TP.map((d) => d.def).concat(new Array(8).fill(0)), motion: {on: true, events: []}, step: Array.from({ length: NSTEP }, () => ({ chance: 100, ratchet: 1, n: 0, notes: [0, 0, 0, 0], time: 2, flags: 0, vel: 0, hit: 0, acc: 0 })) }); const st = { - tracks: [0, 1, 2, 3].map(newTrack), sel: 0, rec: 0, + tracks: Array.from({ length: NTRK }, newTrack), sel: 0, rec: 0, g: GP.map((d) => d.def), slots: [null, null, null, null], songRows: [], chainPlaying: false, chainRow: 0, chainRemaining: 0, bank: new Array(opt.slots || 32).fill(null), /* user presets: {engine, name, p, pattern, grid, fm6 (FM6: its patch)} */ @@ -1670,8 +1670,8 @@ function makeMockDevice(opt = {}) { st.bank[slot] = snapshot(name); clearSteps(); st.p[29] = 16; }); - /* the power-on sounds (engines.c TRK_DEF): ACID, PAD, PULSE LD, DRUM-X */ - [[1, FM6_E, 4], [2, 3, 3], [3, 10, 0], [0, 0, 4]].forEach(([i, e, p]) => { st.sel = i; setEngine(e); applyPreset(p); }); + /* the power-on sounds (engines.c TRK_DEF): ACID, PAD, PULSE LD, DRUM-X, PHASE, WHEEL */ + [[1, FM6_E, 4], [2, 3, 3], [3, 10, 0], [4, 2, 0], [5, 7, 0], [0, 0, 4]].forEach(([i, e, p]) => { st.sel = i; setEngine(e); applyPreset(p); }); /* the device powers on with its sequencers empty; the mock starts as a little demo to look at: track 1 with the ACID pattern, track 4 with BEAT (as SEQ > PATTERNS would load them), pads left, lead right */ st.sel = 3; loadPattern(11); @@ -2268,7 +2268,7 @@ const TEXT = { noreply: "応答がありません", error: "エラー: ", busy: "処理中", applying: "書き込み中 ", applied: "読み込みました", badfile: "ファイルを読み込めません: ", savedSlot: "保存しました: スロット ", loadedSlot: "読み込みました: スロット ", emptySlot: "空のスロットです: ", - confirmSave: "スロット {n} に上書き保存しますか?", confirmLoad: "スロット {n} を読み込みますか? 4 トラックすべての音色とシーケンスが置き換わります(元に戻せません)。", + confirmSave: "スロット {n} に上書き保存しますか?", confirmLoad: "スロット {n} を読み込みますか? すべてのトラックの音色とシーケンスが置き換わります(元に戻せません)。", confirmClear: "シーケンスを全部消しますか?", confirmInit: "音色を初期化しますか? シーケンスはそのままです(本体の SAVE 長押しで元に戻せます)。", erase: "消去", remove: "外す", layout: "(ファームウェアのパラメーター数が想定と違うため、簡易表示にしています)", @@ -2297,9 +2297,9 @@ const TEXT = { tabSeq: "シーケンサー", tabTracks: "トラック", tabSettings: "設定", needDevice: "FM-1 を接続すると編集できます。", bankConnect: "FM-1 を接続すると本体のユーザープリセットも扱えます。", bankNone: "このファームウェアにはユーザープリセットがありません。", - mixer: "ミキサー", mixHelp: "本体の MIXER ページと同じ 4 トラック。フェーダーはレベル。パンはどのトラックも選択を変えずに書き込みます(0.8 のファームウェアでは一瞬そのトラックを選びます)。REC は本体での録音待機の表示です。", + mixer: "ミキサー", mixHelp: "本体の MIXER ページと同じトラック。フェーダーはレベル。パンはどのトラックも選択を変えずに書き込みます(0.8 のファームウェアでは一瞬そのトラックを選びます)。REC は本体での録音待機の表示です。", level: "レベル", pan: "パン", mute: "ミュート", rec: "REC", selectTrack: "選択", selectedTrack: "選択中", - projHelp: "プロジェクトは本体の状態をまとめて保存します: 4 トラックの音色とパターン、曲の並び順、選択中のトラック、グローバル設定。", + projHelp: "プロジェクトは本体の状態をまとめて保存します: 全トラックの音色とパターン、曲の並び順、選択中のトラック、グローバル設定。", slot: "スロット", songTitle: "ソング", songHelp: "保存スロットのパターンと繰り返す回数を順に並べます。音色は現在のまま。並び順を残すには、上のプロジェクトを保存してください。切替はトラック1のパターン終端、曲末で停止します。", songAdd: "行を追加", songRemove: "最後の行を削除", songPlay: "先頭から再生", songStop: "停止", songReps: "回", songEmpty: "行を追加してください", songBusy: "停止してから編集してください", songInvalid: "スロットと回数を確認してください", songPlaying: "再生中の行", songSaved: "並び順を変更しました。プロジェクトを保存すると残せます。", system: "システム", firmware: "ファームウェア", sync: "同期", tracksN: "トラック", stepsN: "ステップ数", enginesL: "エンジン", userBank: "ユーザープリセット", none: "なし", @@ -2364,7 +2364,7 @@ const TEXT = { noreply: "No reply from the device", error: "Error: ", busy: "Busy", applying: "Writing ", applied: "Loaded", badfile: "Cannot read the file: ", savedSlot: "Saved to slot ", loadedSlot: "Loaded slot ", emptySlot: "Empty slot: ", - confirmSave: "Overwrite slot {n}?", confirmLoad: "Load slot {n}? The sounds and sequences of all four tracks are replaced (no undo).", + confirmSave: "Overwrite slot {n}?", confirmLoad: "Load slot {n}? The sounds and sequences of all tracks are replaced (no undo).", confirmClear: "Clear the whole sequence?", confirmInit: "Reset the sound to the engine defaults? The sequence stays (hold SAVE on the device to undo).", erase: "Erase", remove: "Remove", layout: "(The firmware has a different parameter count; showing a plain list.)", @@ -2393,9 +2393,9 @@ const TEXT = { tabSeq: "Sequencer", tabTracks: "Tracks", tabSettings: "Settings", needDevice: "Connect the FM-1 to edit.", bankConnect: "Connect the FM-1 to see its user presets too.", bankNone: "This firmware has no user presets.", - mixer: "Mixer", mixHelp: "The four tracks of the device's MIXER page. The fader is the level. Pan is written to any track without changing the selection (firmware 0.8: by selecting it for a moment). REC shows a track armed for live recording on the device.", + mixer: "Mixer", mixHelp: "The tracks of the device's MIXER page. The fader is the level. Pan is written to any track without changing the selection (firmware 0.8: by selecting it for a moment). REC shows a track armed for live recording on the device.", level: "Level", pan: "Pan", mute: "Mute", rec: "REC", selectTrack: "Select", selectedTrack: "Selected", - projHelp: "A project keeps the sounds and patterns of all four tracks, the song chain, the selected track and the global settings.", + projHelp: "A project keeps the sounds and patterns of all tracks, the song chain, the selected track and the global settings.", slot: "Slot", songTitle: "Song", songHelp: "Arrange sections (the saved projects A–D, with their sounds) and choose how many bars each plays (1–64). Save a project above to keep the chain. Rows change on the bar; the song stops at the end and the music before it comes back.", songAdd: "Add row", songRemove: "Remove last row", songPlay: "Play from start", songStop: "Stop", songReps: "bars", songEmpty: "Add a row first", songBusy: "Stop before editing", songInvalid: "Check sections and bars", songPlaying: "Playing row", songSaved: "Chain changed. Save a project to keep it.", system: "System", firmware: "Firmware", sync: "Sync", tracksN: "Tracks", stepsN: "Steps", enginesL: "Engines", userBank: "User presets", none: "none", diff --git a/web/test_web.mjs b/web/test_web.mjs index e0cc7f62..74414dd6 100644 --- a/web/test_web.mjs +++ b/web/test_web.mjs @@ -227,12 +227,12 @@ async function editorMock() { const set = E.parse[E.CMD.SET](await rq(E.req.set(0, 3, 500))); ok(set.value === 127, "editor: SET clamps to the range"); { - /* GLO > SYSTEM ROUT (G_ROUTE 14): MIDI IN CH1-4 (0, the default) / SEL (1); the id and G_COUNT unchanged */ + /* GLO > SYSTEM ROUT (G_ROUTE 14): MIDI IN CH1-6 (0, the default) / SEL (1); the id and G_COUNT unchanged */ const rd = E.parse[E.CMD.DESC](await rq(E.req.desc(1, 14))); const r1 = E.parse[E.CMD.SET](await rq(E.req.set(1, 14, 5))); const r0 = E.parse[E.CMD.SET](await rq(E.req.set(1, 14, 0))); - ok(rd.label === "ROUT" && rd.def === 0 && eq(rd.names, ["CH1-4", "SEL"]) && r1.value === 1 && r0.value === 0 && info.gcount === 37, - "editor: MIDI IN routing (ROUT CH1-4 / SEL, global id 14)"); + ok(rd.label === "ROUT" && rd.def === 0 && eq(rd.names, ["CH1-6", "SEL"]) && r1.value === 1 && r0.value === 0 && info.gcount === 37, + "editor: MIDI IN routing (ROUT CH1-6 / SEL, global id 14)"); } { /* FX > REVERB TYPE (G_RTYPE 24, the old drum channel's id): ROOM (0, the default) / SPRING (1) / SHIMR RESO CLOUD (JIANT 0.5); G_COUNT unchanged */ @@ -844,8 +844,8 @@ async function editorTracks() { const { m, rq, ev, done } = attachMock({ watchMs: 1000 }); const info = E.parse[C.INFO](await rq(E.req.info())); const tr = E.parse[C.TRACK](await rq(E.req.track())); - ok(info.ntrk === 4 && tr.sel === 0 && tr.ntrk === 4 && tr.tracks[0].engine === 0 && tr.tracks[1].engine === 12 - && tr.tracks[3].engine === 10 && tr.tracks[3].preset === 0, "tracks: INFO NTRK, TRACK lists 4 parts (track 4: DRUM)"); + ok(info.ntrk === 6 && tr.sel === 0 && tr.ntrk === 6 && tr.tracks[0].engine === 0 && tr.tracks[1].engine === 12 + && tr.tracks[3].engine === 10 && tr.tracks[3].preset === 0 && tr.tracks[4].engine === 2 && tr.tracks[5].engine === 7, "tracks: INFO NTRK, TRACK lists 6 parts (track 4: DRUM, 5 PHASE, 6 WHEEL)"); /* the v1 commands follow the selected track */ const d0 = E.parse[C.DUMP](await rq(E.req.dump()), info); const t1 = E.parse[C.TRACK](await rq(E.req.track(1))); @@ -906,7 +906,7 @@ async function editorMixer() { const info = E.parse[C.INFO](await rq(E.req.info())); const PAN = 39, MUTE = 40; const m0 = await E.mixer.read(rq, info, { pan: PAN }); - ok(m0.ntrk === 4 && m0.tracks.length === 4 && m0.tracks[1].pan === -24 && m0.tracks[2].pan === 20 && m0.tracks[3].engine === 10 + ok(m0.ntrk === 6 && m0.tracks.length === 6 && m0.tracks[1].pan === -24 && m0.tracks[2].pan === 20 && m0.tracks[3].engine === 10 && m0.tracks.every((x) => Number.isInteger(x.level) && (x.mute === 0 || x.mute === 1)), "mixer: read = TRACK + pan of every track (TRACK_DUMP)"); /* level / mute of tracks that are not selected (clamped) */ const a = await E.mixer.setMix(rq, 2, 70, 1); @@ -973,8 +973,8 @@ async function editorTrackParam() { ok(g.track === 1 && g.id === PAN && g.value === -24 && p2 === -40 && p1 === 63 && alg.value === 32 && lv.value === 0 && td2.p[PAN] === -40 && sel.sel === 0 && (sent[C.TRACK] || 0) === tracks0 + 1 && ev.pushes.length === pushes, "v4: TRACK_PARAM get / set on other tracks (clamped as SET, selection kept, no push)"); - const bad = await rq(E.req.trackParam(4, PAN), { timeout: 60, retries: 0, quiet: true }).then(() => "reply", () => "none"); - ok(bad === "none", "v4: TRACK_PARAM of track 5: no reply"); + const bad = await rq(E.req.trackParam(6, PAN), { timeout: 60, retries: 0, quiet: true }).then(() => "reply", () => "none"); + ok(bad === "none", "v4: TRACK_PARAM of track 7: no reply"); /* device-side changes: CHANGED for the selected track, TRACK_CHANGED for the others */ m.sim.param(2, PAN, 30); m.sim.param(3, MUTE, 1);