diff --git a/firmware/src/core.h b/firmware/src/core.h index 5a463c7e..f73987b1 100644 --- a/firmware/src/core.h +++ b/firmware/src/core.h @@ -410,15 +410,23 @@ typedef struct { /* acid-style step: up to 4 notes (POLY), time, /* (0.8.5) a lane's mode (eng_drum.c, the DRUM-X octaves): its hit ratcheted x2 / x4 / x8 over the step, or struck SHORT, * GHOST, FLAM; that lane only. 0: as ever (every step before 0.8.5) */ enum { LM_NONE, LM_X2, LM_X4, LM_X8, LM_SHORT, LM_GHOST, LM_FLAM, LM_N }; +/* (0.9.16) LM_ONCE (the code left, 7): a hit recorded live into a step with a RATCH / ECHO, on a lane the step did not + * play: struck once, as it was heard (seq.c rec_drum, seq_step), not rolled by the step's repeats. Read as none by + * step_lmode (and by every firmware before: the hit then rolls with the step, as it did) */ +#define LM_ONCE 7u +static uint32_t step_lm_raw(const step_t *s, uint32_t l) +{ + return (((uint32_t)s->lm[0] | (uint32_t)s->lm[1] << 8 | (uint32_t)s->lm[2] << 16) >> (3u * (l & 7u))) & 7u; +} static uint32_t step_lmode(const step_t *s, uint32_t l) { - uint32_t v = (uint32_t)s->lm[0] | (uint32_t)s->lm[1] << 8 | (uint32_t)s->lm[2] << 16, m = (v >> (3u * (l & 7u))) & 7u; + uint32_t m = step_lm_raw(s, l); return m < LM_N ? m : LM_NONE; } static void step_set_lmode(step_t *s, uint32_t l, uint32_t m) { uint32_t v = (uint32_t)s->lm[0] | (uint32_t)s->lm[1] << 8 | (uint32_t)s->lm[2] << 16, sh = 3u * (l & 7u); - v = (v & ~(7u << sh)) | ((m < LM_N ? m : 0u) << sh); + v = (v & ~(7u << sh)) | ((m & 7u) << sh); s->lm[0] = (uint8_t)v; s->lm[1] = (uint8_t)(v >> 8); s->lm[2] = (uint8_t)(v >> 16); } static int step_lm_any(const step_t *s) { return s->lm[0] | s->lm[1] | s->lm[2]; } diff --git a/firmware/src/project.c b/firmware/src/project.c index f4f85239..8be89016 100644 --- a/firmware/src/project.c +++ b/firmware/src/project.c @@ -1130,12 +1130,12 @@ static int proj_unpack_c(project_t *q, const uint8_t *b) if (CT_DIV(s) >= CT_NDIV || s->ctime > 127u) return 0; } s->lm[0] = s->lm[1] = s->lm[2] = 0; - if (x & 64u) { /* (0.8.5) the lanes' modes (a 7: none) */ + if (x & 64u) { /* (0.8.5) the lanes' modes (0.9.16: a 7, LM_ONCE, kept) */ uint32_t l; if (pos + 3u > room) return 0; s->lm[0] = b[pos++]; s->lm[1] = b[pos++]; s->lm[2] = b[pos++]; for (l = 0; l < NLANE; l++) - step_set_lmode(s, l, step_lmode(s, l)); + step_set_lmode(s, l, step_lm_raw(s, l)); } r |= (x >> 1) & 2u; step_set_ratchet(s, r + 1u); diff --git a/firmware/src/seq.c b/firmware/src/seq.c index 124edd7a..94a055dd 100644 --- a/firmware/src/seq.c +++ b/firmware/src/seq.c @@ -602,7 +602,7 @@ static uint32_t rec_lmode(void) /* a hit (a GM note) into step s of a DRUM track (rec_note, a held ratchet's next step: dxo_rec_hold) */ static void rec_drum(track_t *t, step_t *s, uint32_t note, uint32_t vel, int32_t mic) { - uint32_t l = drum_lane(note), k; + uint32_t l = drum_lane(note), k, m = rec_lmode(), was; if (s->time != ST_NOTE || (!s->n && !s->hit)) { s->n = s->hit = s->acc = 0; s->flags = 0; @@ -616,13 +616,14 @@ static void rec_drum(track_t *t, step_t *s, uint32_t note, uint32_t vel, int32_t } s->time = ST_NOTE; if (note == DRUM_LANE_NOTE[l]) { /* a lane's note: its hit */ + was = (s->hit >> l) & 1u; /* (0.9.16) the sound in the step already (it rolls with it) */ s->hit |= (uint8_t)(1u << l); if (vel > 110) s->acc |= (uint8_t)(1u << l); } else { /* another GM drum (a low tom, a crash): a note */ for (k = 0; k < s->n && s->note[k] != note; k++) ; - if (k == s->n) { + if (!(was = k < s->n)) { if (s->n < 4u) s->n++; s->note[s->n - 1u] = (uint8_t)note; @@ -632,7 +633,12 @@ static void rec_drum(track_t *t, step_t *s, uint32_t note, uint32_t vel, int32_t } if (vel > s->vel) s->vel = (uint8_t)vel; - step_set_lmode(s, l, rec_lmode()); + /* (0.9.16) a plain hit on a lane new to a step with a RATCH or an ECHO: once, as played (it rolled x2..x4 at once, + * the step's next parts replaying it, and on every pass after: rolls finger drumming over a DICE / GEN beat); played + * there again, still once */ + if (!m && (was ? step_lm_raw(s, l) == LM_ONCE : step_ratchet(s) > 1u || s->comp == CP_ECHO || s->comp2 == CP_ECHO)) + m = LM_ONCE; + step_set_lmode(s, l, m); t->seq_active = 1; } static uint8_t rec_at, rec_late; /* (0.8.5) the step (play index + 1) the last hit went into; @@ -1887,7 +1893,10 @@ static __attribute__((noinline)) void seq_step(track_t *t, const step_t *s, uint } for (i = 0; i < m; i++) if (!((sk >> i) & 1u)) { - uint32_t a0 = vage, dt0 = t->dtch, lt = kit ? lm_touch(step_lmode(s, drum_lane(nn[i]))) : 0u; + uint32_t a0 = vage, dt0 = t->dtch, lt = kit ? step_lm_raw(s, drum_lane(nn[i])) : 0u; + if (lt == LM_ONCE && (skip & SEQ_REP)) + continue; /* (0.9.16) a hit recorded once: not in the step's repeats */ + lt = lm_touch(lt); if (lt) t->dtch = (uint8_t)lt; seq_note_on(t, nn[i], vv[i]); diff --git a/tests/drumx_oct_test.c b/tests/drumx_oct_test.c index 4eb2e5fd..420a3dfe 100644 --- a/tests/drumx_oct_test.c +++ b/tests/drumx_oct_test.c @@ -16,6 +16,8 @@ * MIDI 35..81 the GM map as before; 82.. ratchet bands, ..34 TOUCH bands (by pitch class), note-offs end them. * UI OCT on a DRUM track says what the octave does; SEQ > COMP shows a recorded TOUCH step, ECHO's EVEN kept * by its knob. + * ONCE (0.9.16) REC at OCT 0 over a RATCH / ECHO step (DICE, GEN): the key's new hit struck once, live and played + * back (LM_ONCE), the step's own hits still x2..x4; FUNC keeps it. * Built and run by tests/run_tests.sh. */ #define UI_TEST_NO_MAIN 1 #define PROJ_FUNB_WRITER 1 /* (an older format to load: FUNB, as JIANT 0.2 .. 0.5 wrote it) */ @@ -725,6 +727,111 @@ static int ui_part(void) return bad; } + +/* (0.9.16) finger drumming at OCT 0, recording over a beat with RATCH / ECHO steps (DICE and GEN write x2..x4 on hats, + * fills): Danil's "random rolls". A key's hit on a lane the step did not play is struck once, live and on every pass + * after (LM_ONCE), not x3 with the step's repeats; the step's own hits still roll; FUNC keeps it, a project of before + * plays as it did */ +static uint32_t lane_n[NLANE], lane_age[NVOICE]; +static void lanes_b(uint32_t nb) /* nb blocks, the hits of each lane counted */ +{ + uint32_t i; + while (nb--) { + events_block(CTL); + for (i = 0; i < NVOICE; i++) + if (dt->v[i].age != lane_age[i]) { + lane_age[i] = dt->v[i].age; + lane_n[drum_lane(dt->v[i].note)]++; + } + } +} +static void lanes_until(uint32_t idx, uint32_t from) /* to play index idx, from its sample from on */ +{ + while (!(dt->seq_idx == idx && dt->seq_pos >= from && dt->seq_pos < 0x7FFFFFFFu)) + lanes_b(1); +} +static int rec_ratch(void) +{ + int bad = 0, ok, late; + uint32_t r; + for (late = 0; late < 2; late++) + for (r = 2; r <= 4u; r++) { + uint32_t sl, at = late ? 1u : 2u; + drum_setup(); + dt->step[2] = (step_t){{0}, 0, ST_NOTE, 0, 100, 1u << DV_HATC}; + step_set_ratchet(&dt->step[2], r); + song.rec = 1u << 3; + seq_start(); + sl = step_len(2); + lanes_until(at, late ? sl * 3u / 4u : sl / 8u); /* early in step 3, or late in step 2 (into step 3) */ + memset(lane_n, 0, sizeof lane_n); + key_dn(KICK_KEY); + lanes_b(4); + key_upk(KICK_KEY); + lanes_until(3, 0); + ok = lane_n[DV_KICK] == 1u && lane_n[DV_HATC] == r - (late ? 0u : 1u) && dt->step[2].hit == (1u << DV_HATC | 1u << DV_KICK) && + step_ratchet(&dt->step[2]) == r && step_lm_raw(&dt->step[2], DV_KICK) == LM_ONCE && + step_lmode(&dt->step[2], DV_KICK) == LM_NONE; + memset(lane_n, 0, sizeof lane_n); /* the next pass: once, the hats x r */ + lanes_until(1, 0); + lanes_until(3, 0); + ok &= lane_n[DV_KICK] == 1u && lane_n[DV_HATC] == r; + memset(lane_n, 0, sizeof lane_n); /* played there again: the recorded one and the key's, once each */ + lanes_until(2, sl / 8u); + key_dn(KICK_KEY); + lanes_b(4); + key_upk(KICK_KEY); + lanes_until(3, 0); + ok &= lane_n[DV_KICK] == 2u && step_lm_raw(&dt->step[2], DV_KICK) == LM_ONCE; + memset(lane_n, 0, sizeof lane_n); /* a hat played into its own step: it rolls with it, as before */ + lanes_until(2, sl / 8u); + fm1_in.notes |= 1u << 13; /* (key 13: 42, the closed hat) */ + lanes_b(4); + fm1_in.notes &= ~(1u << 13); + lanes_until(3, 0); + ok &= drum_lane(29u + 13u) == DV_HATC && step_lmode(&dt->step[2], DV_HATC) == LM_NONE && + step_lm_raw(&dt->step[2], DV_HATC) == LM_NONE; + seq_stop(); + bad += check(late ? "REC at OCT 0 late into a RATCH step: the new hit once (live, after), the step's x2..x4" + : "REC at OCT 0 into a RATCH x2..x4 step: the new hit once (live, after), the step's x2..x4", + ok); + } + { /* an ECHO step the same; a step without repeats as before (no mode) */ + drum_setup(); + dt->step[2] = (step_t){{0}, 0, ST_NOTE, 0, 100, 1u << DV_HATC}; + dt->step[2].comp = CP_ECHO; + dt->step[2].carg = 1; /* (x3) */ + dt->step[5] = (step_t){{0}, 0, ST_NOTE, 0, 100, 1u << DV_HATC}; + song.rec = 1u << 3; + seq_start(); + lanes_until(2, step_len(2) / 8u); + memset(lane_n, 0, sizeof lane_n); + key_dn(KICK_KEY); + lanes_b(4); + key_upk(KICK_KEY); + lanes_until(3, 0); + ok = lane_n[DV_KICK] == 1u && lane_n[DV_HATC] == 2u && step_lm_raw(&dt->step[2], DV_KICK) == LM_ONCE; + lanes_until(5, step_len(5) / 8u); + key_dn(KICK_KEY); + lanes_b(4); + key_upk(KICK_KEY); + lanes_b(4); + ok &= !step_lm_any(&dt->step[5]) && dt->step[5].hit == (1u << DV_HATC | 1u << DV_KICK); + seq_stop(); + bad += check("REC at OCT 0 into an ECHO step: once; into a plain step: no lane mode, as before", ok); + } + { /* FUNC keeps it; read as none by the rest (and by a firmware before: the hit rolls with the step, as it did) */ + project_t before, after; + project_store_t b; + step_set_lmode(&dt->step[2], DV_KICK, LM_ONCE); + project_capture(&before); + ok = proj_pack(&b, &before) && proj_import(&after, &b, sizeof b) && + step_lm_raw(&after.t[3].step[2], DV_KICK) == LM_ONCE && step_lmode(&after.t[3].step[2], DV_KICK) == LM_NONE; + bad += check("FUNC: LM_ONCE round trip (step_lmode: none)", ok); + } + return bad; +} + int main(void) { int bad = 0; @@ -736,6 +843,7 @@ int main(void) bad += midi(); bad += per_lane(); bad += ui_part(); + bad += rec_ratch(); if (bad) { printf("drumx octaves: %d FAILED\n", bad); return 1; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index f2cae7ce..3aaab252 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -236,7 +236,7 @@ if [ -f build/gen/felucca_tables.h ]; then $CC -O1 -w -Ibuild/gen -Ifirmware/src -o "$OUT/live_test" tests/live_test.c -lm run "LIVE (0.9.11, GLO > LIVE MANO / RIELES): RATE on the beat, CORTE / LOOP / RATCH / THIN / REV / PING on the 1/16, the ghost, RETURN, BYPASS, COMMIT + UNDO, REC at the ghost, PISTAS ALL..T6, MANO's keys only there, the chain" "$OUT/live_test" $CC -O1 -w -Ibuild/gen -Ifirmware/src -o "$OUT/drumx_oct_test" tests/drumx_oct_test.c -lm - run "DRUM-X OCTAVES (0.8.5): ratchets above the kit, SHORT GHOST FLAM below, live, recorded and played back as heard, MIDI bands" "$OUT/drumx_oct_test" + run "DRUM-X OCTAVES (0.8.5): ratchets above the kit, SHORT GHOST FLAM below, live, recorded and played back as heard, MIDI bands, a hit recorded into a RATCH step once" "$OUT/drumx_oct_test" $CC -O1 -w -Ibuild/gen -Ifirmware/src -o "$OUT/midi_control_test" tests/midi_control_test.c -lm run "USB/TRS clock, bend, sustain, ownership and panic recovery" "$OUT/midi_control_test" $CC -O1 -w -DFELUCCA_FM4=1 -Ibuild/gen -Ifirmware/src -o "$OUT/digital_test" tests/digital_test.c -lm