diff --git a/firmware/src/gen.c b/firmware/src/gen.c index 11afa281..4f8b4e22 100644 --- a/firmware/src/gen.c +++ b/firmware/src/gen.c @@ -2,7 +2,7 @@ * Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) * JIANT (0.6.91) the song generator, second version: HOME + SELECT opens GEN, a screen of three pages (GENRE SEED * ENERGY FORM; DRUMS BASS CHORDS ARP; LEAD COMPLEX SWING HUMAN), OCT+ makes the piece, HOME (or OCT-) is done. Included by - * ui_input.c after song_dice.c (whose helpers it shares: the roles, dhold, euclid, dtonic, dname_has, dlevel ..). + * ui_input.c after song_dice.c (whose helpers it shares: the roles, dhold, euclid, dname_has, dlevel ..). * * The piece is deterministic: a seed and the knobs make the same piece every time (the same settings and OCT+ again * throw a new seed). Each part (drums, bass, chords, arp, lead, sounds, form) draws from its own stream, so turning @@ -656,19 +656,40 @@ static int32_t gbass_near(int32_t lo, const gch_t *c, int32_t ref) /* (a walk' return n; } /* (0.9.7) an archetype's note and flag at step i (gen_bass.h: the text's characters) */ -static char ba_note(const barch_t *a, uint32_t i) { return ".=R23456789ALNSx"[BA_STEP[a->at + i] & 15u]; } -static char ba_flag(const barch_t *a, uint32_t i) { return ".asg"[(BA_STEP[a->at + i] >> 4) & 3u]; } +#define BA_NOTE(c) (".=R23456789ALNSx"[(c) & 15u]) +#define BA_FLAG(c) (".asg"[((c) >> 4) & 3u]) +/* (0.9.18) the archetype as this throw plays it: one to three of its steps moved (a ghost or a soft root after a note + * on an off sixteenth, a weak root up the octave or to the fifth, a weak note left out, a note a sixteenth late or + * early), the same in every bar (a riff, its own): until 0.9.17 a genre's throws played one of its three archetypes as + * written, the same bass in a third of them (MICRO HOUSE: as one of the 8 before in 60 %) */ +static void gba_vary(uint8_t *bc, uint32_t alen) +{ + uint32_t n = (uint32_t)grr(1, 2 + (int32_t)gs.complex / 40), j, tries; + for (j = 0, tries = 0; j < n && tries < 24u; tries++) { + uint32_t p = 1u + gr() % (alen - 1u), q = (p + 1u) % alen, c = bc[p] & 15u, pc = bc[p - 1u] & 15u, op = gr() % 4u; + if (!(p % 4u) || (bc[q] & 15u) == 1u) continue; /* (the beats kept; a note held on kept whole) */ + if (op == 0u && !c && (p & 1u) && pc > 1u) bc[p] = gch(50) ? 15u : 2u | 3u << 4; + else if (op == 1u && c == 2u) bc[p] = (uint8_t)((bc[p] & 0xF0u) | (gch(60) ? 9u : 6u)); + else if (op == 2u && (c == 2u || c == 6u || c == 9u) && pc != 0u) bc[p] = 0; + else if (op == 3u && q % 4u && (!c) != !(bc[q] & 15u) && c != 1u) { uint8_t x = bc[p]; bc[p] = bc[q]; bc[q] = x; } + else continue; + j++; + } +} static void gen_bass(track_t *t, uint32_t len) { const ggenre_t *g = gs.g; const barch_t *a = &BASS_ARCH[gs.ba]; int32_t lo = g->bass_lo, prev = -1, root0 = -1; uint32_t i, alen = 16u * a->bars, held = 0, walk = gs.ba == BA_WALK || gs.ba == BA_WALK2 || gs.ba == BA_TWOFEEL; + uint8_t bc[64]; gseed(GS_BASS); if (gs.ba == BA_ACID) { gen_acid(t, len, lo); return; } + memcpy(bc, &BA_STEP[a->at], alen); + if (!walk) gba_vary(bc, alen); for (i = 0; i < len; i++) { step_t *s = &t->step[i]; - char c = ba_note(a, i % alen), f = ba_flag(a, i % alen); + char c = BA_NOTE(bc[i % alen]), f = BA_FLAG(bc[i % alen]); const gch_t *cc = gchord(i), *nc = gchord_next(i); int32_t root, n[1], vel = 96, same = nc == cc || (nc->deg == cc->deg && nc->alt == cc->alt); uint32_t fl = 0, chg = gchord_starts(i); @@ -685,8 +706,8 @@ static void gen_bass(track_t *t, uint32_t len) switch (c) { case '7': /* (a seventh alone over a major one with a major seventh: its * sixth, the reggae's and the funk's note; in a run 6 7 8 it passes) */ - n[0] = gbass_tone(cc, root, giv(cc, 6) == 11 && giv(cc, 2) == 4 && ba_note(a, (i + alen - 1u) % alen) != '6' && - ba_note(a, (i + 1u) % alen) != '8' ? '6' : '7'); + n[0] = gbass_tone(cc, root, giv(cc, 6) == 11 && giv(cc, 2) == 4 && BA_NOTE(bc[(i + alen - 1u) % alen]) != '6' && + BA_NOTE(bc[(i + 1u) % alen]) != '8' ? '6' : '7'); break; case '2': case '3': case '5': case '6': case '9': n[0] = gbass_tone(cc, root, c); break; case 'L': n[0] = gbass_tone(cc, root, '5') - 12; break; @@ -2092,70 +2113,13 @@ static void gen_scale_page(void) sl_root = gs.root; sl_scale = gs.scale; sl_quant = qn; } static int8_t dice_force_style = -1, dice_force_energy = -1; /* (a film's script, the renders: this genre, this energy) */ -static void gen_make(void) +/* (0.9.18) the piece's choices after its genre (gen_make's, from the GS_PICK stream: the same calls in the same order): + * the key, the energy and the amounts, the progression, the loop, the plan, the bass's archetype. SEQ + SELECT's too + * (dice_seq: a part where no piece of the generator plays) */ +static void gen_pick(void) { - const ggenre_t *g; - uint32_t k, dr = NTRK, nlive = trk_live < NTRK ? trk_live : NTRK, nmel, drums, next, pr, wet; - uint32_t steps; - /* the choices from the seed: the genre (RANDOM), the root, the scale, the progression, the bass */ - gseed(GS_PICK); - gx.on = (uint8_t)(dice_force_style < 0 && gp.genre == GEN_EXPLORE); - gx.nan = gx.nvo = gx.np = 0; gx.eng = -1; gx.w = gp.complex; gx.nmax = 4; - if (!gx.on && gx.dirty) { /* (0.8.6) after an EXPLORE piece: DIV and PLAYHEADS as a genre's - * piece has them (1/16, none) */ - for (k = 0; k < NTRK; k++) trk[k].p[P_SDIV] = 2; - memset(fg_set, 0, sizeof fg_set); - gx.dirty = 0; - } - if (gx.on) { /* (0.8.6) EXPLORE: a genre of its own a seed */ - gs.gi = NGENRE; - gs.mutant = 0; - gx_genre(&gmut); - gx.dirty = 1; - for (k = 0; k < NTRK; k++) trk[k].p[P_SDIV] = 2; - memset(fg_set, 0, sizeof fg_set); - g = gs.g = &gmut; - } else { - gs.gi = dice_force_style >= 0 ? (uint32_t)dice_force_style % NGENRE : gp.genre ? (gp.genre - 1u) % NGENRE : gr() % NGENRE; - g = gs.g = &GENRE[gs.gi]; - gmut = *g; - gs.mutant = 0; - if (!gp.genre && dice_force_style < 0 && gch(45)) { /* (0.6.95) RANDOM: a mutant, the drums of one genre, the bass - * of another, the rest from either; a name of its own: "EBM+JAZZ" */ - const ggenre_t *b = &GENRE[gr() % NGENRE], *c = &GENRE[gr() % NGENRE]; - uint32_t k2, n2 = 0; - gmut.drum = b->drum; gmut.kit = b->kit; gmut.ghosts = b->ghosts; gmut.hats = b->hats; gmut.fills = b->fills; - gmut.sd_micro = b->sd_micro; gmut.snd[GP_DRUMS] = b->snd[GP_DRUMS]; - gmut.drum_pct = (uint8_t)(b->drum_pct > g->drum_pct ? b->drum_pct : g->drum_pct); - for (k2 = 0; k2 < 3u; k2++) gmut.bass[k2] = c->bass[k2]; - gmut.bass_lo = c->bass_lo; gmut.kick_mode = c->kick_mode; gmut.bass_gate = c->bass_gate; gmut.snd[GP_BASS] = c->snd[GP_BASS]; - if (gch(50)) { - for (k2 = 0; k2 < 3u; k2++) gmut.prog[k2] = b->prog[k2]; - gmut.cbars = b->cbars; gmut.pads = b->pads; gmut.voicing = b->voicing; gmut.snd[GP_CHORDS] = b->snd[GP_CHORDS]; - gmut.hx = b->hx; /* (0.8.3: the harmony with its progressions) */ - } - if (gch(50)) { gmut.arp[0] = c->arp[0]; gmut.arp[1] = c->arp[1]; gmut.snd[GP_ARP] = c->snd[GP_ARP]; } - if (gch(50)) { gmut.lead = b->lead; gmut.snd[GP_LEAD] = b->snd[GP_LEAD]; } - if (gch(50)) { gmut.rtype = b->rtype; gmut.dtime = b->dtime; gmut.wet = b->wet; gmut.dtype = b->dtype; } - gmut.scale[1] = b->scale[0]; gmut.scale[3] = c->scale[0]; - gmut.tex = c->tex; - gmut.bpm_lo = (uint8_t)(((uint32_t)g->bpm_lo + b->bpm_lo) / 2u); - gmut.bpm_hi = (uint8_t)(((uint32_t)g->bpm_hi + b->bpm_hi) / 2u); - if (gmut.bpm_hi < gmut.bpm_lo + 4u) gmut.bpm_hi = (uint8_t)(gmut.bpm_lo + 4u); - gmut.swing = (uint8_t)(((uint32_t)g->swing + b->swing) / 2u); - for (k2 = 0; g->name[k2] && g->name[k2] != ' ' && k2 < 7u; k2++) gmut_name[n2++] = g->name[k2]; /* (the first words) */ - gmut_name[n2++] = '+'; - for (k2 = 0; b->name[k2] && b->name[k2] != ' ' && k2 < 6u; k2++) gmut_name[n2++] = b->name[k2]; - gmut_name[n2] = 0; - gmut.name = gmut_name; - gs.mutant = 1; - } - /* (0.6.95) a throw its own: the drums from the map's family, the chords' play and a role's recipe from the neighbours */ - if (gmut.drum < DM_NONE && gmut.drum != DM_IDM && gch(35)) gmut.drum = DM_ALT[gmut.drum][gr() % 2u]; - if (gmut.pads <= CS_TRANCE && gch(35)) gmut.pads = CS_ALT[gmut.pads][gr() % 2u]; - for (k = 1; k < GP_N; k++) if (gmut.snd[k] < SR_N && gch(30)) gmut.snd[k] = SR_ALT[gmut.snd[k]][gr() % 2u]; - g = gs.g = &gmut; - } + const ggenre_t *g = gs.g; + uint32_t k, pr, steps; gs.root = (int16_t)grr(0, 11); { /* (0.8.3) the key: always a mode of seven, so the CHORD page, the chords, the arp and the lead stand on it; a * genre's pentatonic or blues is its lead's palette over the mode that holds it (dorian where the genre is @@ -2238,6 +2202,71 @@ static void gen_make(void) gplan(0); gs.ba = g->bass[gr() % 3u]; if (gs.amt[GP_BASS] > 70u && gch(30)) gs.ba = g->bass[0]; +} +static void gen_make(void) +{ + const ggenre_t *g; + uint32_t k, dr = NTRK, nlive = trk_live < NTRK ? trk_live : NTRK, nmel, drums, next, wet; + /* the choices from the seed: the genre (RANDOM), the root, the scale, the progression, the bass */ + gseed(GS_PICK); + gx.on = (uint8_t)(dice_force_style < 0 && gp.genre == GEN_EXPLORE); + gx.nan = gx.nvo = gx.np = 0; gx.eng = -1; gx.w = gp.complex; gx.nmax = 4; + if (!gx.on && gx.dirty) { /* (0.8.6) after an EXPLORE piece: DIV and PLAYHEADS as a genre's + * piece has them (1/16, none) */ + for (k = 0; k < NTRK; k++) trk[k].p[P_SDIV] = 2; + memset(fg_set, 0, sizeof fg_set); + gx.dirty = 0; + } + if (gx.on) { /* (0.8.6) EXPLORE: a genre of its own a seed */ + gs.gi = NGENRE; + gs.mutant = 0; + gx_genre(&gmut); + gx.dirty = 1; + for (k = 0; k < NTRK; k++) trk[k].p[P_SDIV] = 2; + memset(fg_set, 0, sizeof fg_set); + g = gs.g = &gmut; + } else { + gs.gi = dice_force_style >= 0 ? (uint32_t)dice_force_style % NGENRE : gp.genre ? (gp.genre - 1u) % NGENRE : gr() % NGENRE; + g = gs.g = &GENRE[gs.gi]; + gmut = *g; + gs.mutant = 0; + if (!gp.genre && dice_force_style < 0 && gch(45)) { /* (0.6.95) RANDOM: a mutant, the drums of one genre, the bass + * of another, the rest from either; a name of its own: "EBM+JAZZ" */ + const ggenre_t *b = &GENRE[gr() % NGENRE], *c = &GENRE[gr() % NGENRE]; + uint32_t k2, n2 = 0; + gmut.drum = b->drum; gmut.kit = b->kit; gmut.ghosts = b->ghosts; gmut.hats = b->hats; gmut.fills = b->fills; + gmut.sd_micro = b->sd_micro; gmut.snd[GP_DRUMS] = b->snd[GP_DRUMS]; + gmut.drum_pct = (uint8_t)(b->drum_pct > g->drum_pct ? b->drum_pct : g->drum_pct); + for (k2 = 0; k2 < 3u; k2++) gmut.bass[k2] = c->bass[k2]; + gmut.bass_lo = c->bass_lo; gmut.kick_mode = c->kick_mode; gmut.bass_gate = c->bass_gate; gmut.snd[GP_BASS] = c->snd[GP_BASS]; + if (gch(50)) { + for (k2 = 0; k2 < 3u; k2++) gmut.prog[k2] = b->prog[k2]; + gmut.cbars = b->cbars; gmut.pads = b->pads; gmut.voicing = b->voicing; gmut.snd[GP_CHORDS] = b->snd[GP_CHORDS]; + gmut.hx = b->hx; /* (0.8.3: the harmony with its progressions) */ + } + if (gch(50)) { gmut.arp[0] = c->arp[0]; gmut.arp[1] = c->arp[1]; gmut.snd[GP_ARP] = c->snd[GP_ARP]; } + if (gch(50)) { gmut.lead = b->lead; gmut.snd[GP_LEAD] = b->snd[GP_LEAD]; } + if (gch(50)) { gmut.rtype = b->rtype; gmut.dtime = b->dtime; gmut.wet = b->wet; gmut.dtype = b->dtype; } + gmut.scale[1] = b->scale[0]; gmut.scale[3] = c->scale[0]; + gmut.tex = c->tex; + gmut.bpm_lo = (uint8_t)(((uint32_t)g->bpm_lo + b->bpm_lo) / 2u); + gmut.bpm_hi = (uint8_t)(((uint32_t)g->bpm_hi + b->bpm_hi) / 2u); + if (gmut.bpm_hi < gmut.bpm_lo + 4u) gmut.bpm_hi = (uint8_t)(gmut.bpm_lo + 4u); + gmut.swing = (uint8_t)(((uint32_t)g->swing + b->swing) / 2u); + for (k2 = 0; g->name[k2] && g->name[k2] != ' ' && k2 < 7u; k2++) gmut_name[n2++] = g->name[k2]; /* (the first words) */ + gmut_name[n2++] = '+'; + for (k2 = 0; b->name[k2] && b->name[k2] != ' ' && k2 < 6u; k2++) gmut_name[n2++] = b->name[k2]; + gmut_name[n2] = 0; + gmut.name = gmut_name; + gs.mutant = 1; + } + /* (0.6.95) a throw its own: the drums from the map's family, the chords' play and a role's recipe from the neighbours */ + if (gmut.drum < DM_NONE && gmut.drum != DM_IDM && gch(35)) gmut.drum = DM_ALT[gmut.drum][gr() % 2u]; + if (gmut.pads <= CS_TRANCE && gch(35)) gmut.pads = CS_ALT[gmut.pads][gr() % 2u]; + for (k = 1; k < GP_N; k++) if (gmut.snd[k] < SR_N && gch(30)) gmut.snd[k] = SR_ALT[gmut.snd[k]][gr() % 2u]; + g = gs.g = &gmut; + } + gen_pick(); gs.fm6 = 0; /* the orchestration: the drums (unless the genre or the knob leaves them out), then the melodic roles with an * amount, the most important first; the drums on the DRUM track (none: the fourth, or the last live) */ @@ -2453,6 +2482,69 @@ static uint32_t dice_print(void) /* a fingerprint of the return h; } +/* (0.6.67; 0.9.18 the generator's) SEQ + SELECT: the selected track's sequence diced as GEN writes its part, a new + * stream each press (the random numbers, the ticks in them). Where a piece of the generator plays in the track's key, + * on its harmony (its plan, its genre, the track's role in it): the part fits the others. Else a piece's choices made + * up for it (the last genre, or any; the track's own key where it is a mode of seven): the drums on a DRUM track, else + * the role its steps sound like (low: the bass, chords: the chords, else a lead or an arp). Until 0.9.17 song_dice.c's + * own parts: a random genre's progression against the song's (its lead's strong steps on the chords' tones 58 % of the + * time, GEN's 90 %). The sound, the mix and the automation stay. Its message */ +static uint32_t dsq_last[NTRK]; /* (each track's last diced sequence) */ +static const char *dice_seq(track_t *t) +{ + static const char *const RN[RL_N] = {"SEQ DICED: DRUMS", "SEQ DICED: BASS", "SEQ DICED: PAD", "SEQ DICED: LEAD", + "SEQ DICED: ARP", "SEQ DICED: TEXTURE"}; + uint32_t k = trk_index(t) % NTRK, r, i, len, lo = 0, cnt = 0, chord = 0; + uint16_t s0 = gp.seed; + rng_state ^= fm1_ticks() * 2654435761u; + if (!rng_state) rng_state = 0x1234567u; + for (i = 0; i < NSTEP; i++) /* (what it plays now: its register, its chords) */ + if (t->step[i].time == ST_NOTE && t->step[i].n) { lo += t->step[i].note[0]; cnt++; chord += t->step[i].n > 1u; } + r = drum_track(t) ? RL_DRUM : gs.g && gs.role[k] != RL_DRUM ? gs.role[k] : cnt && lo / cnt < 48u ? RL_BASS : + chord * 3u > cnt && cnt ? RL_PAD : rng() % 2u ? RL_LEAD : RL_ARP; + gp.seed = (uint16_t)(rng() % 10000u); + if (!gs.g || gs.root != t->p[P_ROOT] || gs.scale != t->p[P_SCALE]) { /* (no piece here: its choices made up) */ + uint32_t m = SCALE_MASK[(uint32_t)t->p[P_SCALE] % (sizeof SCALE_MASK / sizeof SCALE_MASK[0])], c, d; + gs.gi = gs.g && gs.gi < NGENRE ? gs.gi : rng() % NGENRE; + gmut = GENRE[gs.gi]; gs.g = &gmut; gs.mutant = 0; gx.on = 0; + gseed(GS_PICK); + gen_pick(); + for (d = 0, c = 0; c < 12u; c++) d += (m >> c) & 1u; + gs.root = t->p[P_ROOT]; + if (d == 7u && t->p[P_SCALE] != 10) { /* (its own mode, LOC aside) */ + gs.scale = t->p[P_SCALE]; + for (d = 0, c = 0; c < 12u && d < 7u; c++) if ((m >> c) & 1u) gs.sc[d++] = (uint8_t)c; + gplan(0); + } + gs.kick = 0; + for (c = 0; c < NTRK; c++) /* (the kick a bass answers: the DRUM track's) */ + if (drum_track(&trk[c]) && &trk[c] != t) + for (i = 0; i < dlen(&trk[c]); i++) gs.kick |= (uint64_t)(trk[c].step[i].time == ST_NOTE && (trk[c].step[i].hit & 1u)) << i; + } + gs.ba = gs.g->bass[rng() % 3u]; + if (gmut.lead == LD_NONE) gmut.lead = LD_HOOK; /* (asked for: a lead) */ + for (i = 0; i < GP_N; i++) if (!gs.amt[i]) gs.amt[i] = 60; + gs.role[k] = (uint8_t)r; gs.act[r] = 1; gs.trk_of[r] = (uint8_t)k; + len = (uint32_t)t->p[P_SLEN]; + if (len < 8u || len > NSTEP) len = gs.len < 16u ? 16u : gs.len; + load_begin(t, LOAD_PAT); + latch_drop_req |= (uint8_t)(1u << k); + for (cnt = 0; cnt < 4u; cnt++) { /* (never the press before's again: another stream, three times + * at most) */ + for (i = 0; i < NSTEP; i++) step_clear(&t->step[i]); + gen_role(t, k, len); + if (steps_sig(t) != dsq_last[k]) break; + gp.seed = (uint16_t)(rng() % 10000u); + gs.ba = gs.g->bass[rng() % 3u]; + } + dsq_last[k] = steps_sig(t); + t->p[P_SLEN] = (int16_t)len; + if (r != RL_DRUM) dlevel(t, len); + load_end(t); + gp.seed = s0; + return RN[r]; +} + /* ------------------------------------------------------------------------------------------- the GEN screen --- */ static const char *const GEN_LBL[3][4] = {{"GENRE", "SEED", "ENERGY", "FORM"}, {"DRUMS", "BASS", "CHORDS", "ARP"}, {"LEAD", "COMPLEX", "SWING", "HUMAN"}}; diff --git a/firmware/src/song_dice.c b/firmware/src/song_dice.c index e5444e27..c57a7675 100644 --- a/firmware/src/song_dice.c +++ b/firmware/src/song_dice.c @@ -1,47 +1,12 @@ /* SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) - * JIANT (0.6.26; 0.6.32 darker; 0.6.34 a generator of pieces, not of conditions): HOME + SELECT's DICE ALL. Included - * by ui_input.c (main loop only). - * - * Three choices make a piece, then guard rails keep it musical inside the chaos: - * GENRE (dstyle_t) its tempo, scales, progressions, drum family (or none) and kits, bass figure and register, how - * its chords move, how its lead and its arp speak, which engines it likes for each role, its space (reverb, - * delay, how wet). (0.6.80) The wave's: POST PUNK, SYNTH POP, MINIMAL SYNTH, MAN MACHINE (Joy Division, - * New Order, Suicide, Kraftwerk; two throws in five). The night's (DARK MINIMAL, DUB TECHNO, IDM, DARK IDM, - * DARK ELECTRO, ACID NIGHT, BROKEN, HYPNOTIC, DEEP BREAKS) and SOUNDTRACK (enveloping pads, no drums or a - * heartbeat), HARD TECHNO, NEO CLASSICAL (Reich's pulses and phases, Glass's additive arps, Part's - * tintinnabuli). - * ENERGY 0 SPACE (two or three things sounding, long tails: minimalism, so the timbres are cared for), 1 MID, - * 2 FRANTIC (everything, denser, ratchets); inside the genre's range. - * ORCHESTRATION which roles play: the genre's order of importance cut by the energy; the drums may not play at all; - * a role left out keeps its sound and an empty sequence (play it, record it). - * The guard rails: one harmony anchored on the tonic in every register; the chords four notes (0.6.80: or three, a - * power chord or a triad), voiced in a middle register and led to the nearest voicing; the bass deep (from E1; the - * wave's hook from E2); the arps in the middle octaves (C3..C5); the lead under G5 and coherent: a rhythmic motif of a - * few notes, its contour in steps and repeated notes (a leap filled back by a step), its strong beats on chord tones - * three times in five, repeated over four bars (A, A moved to the next chord, A, A' its last note moved or left out: - * 0.6.80, it ended on a cadence held on the tonic, a nursery tune's); high notes softer, a part that sits high quieter; space between notes. A throw in five gets a TWIST, one - * experiment (two loops phasing, a comb, the grain delay an octave down, a polymetric lead, a drone): surprises with - * refinement. Sounds: a preset whose name fits the role and is not a bright one, its envelope shaped for the role and - * the energy, filtered by role with an envelope on the filter, a TYPE that changes, an LFO of its own shape; the kit - * (0.6.35: back to 0.6.33's, it sounded better) the DRUM-X kit diced around the factory one, through a soft low-pass. No automation and no - * modulation matrix beyond the macros' routes. UNDO (GLO + G4) brings back what was there */ + * JIANT (0.6.26 .. 0.9.17 DICE ALL's own song-idea generator; 0.9.18 the helpers GEN shares, gen.c): the roles, the + * engines' and scales' numbers, a step's tie, a note held, an euclid, a preset's name, a part's level by its register, a + * track's loop, the CPU TEST song. Included by ui_input.c (main loop only) before gen.c. (0.9.18) Its own generator + * (DSTYLE's 21 genres, their drum bars, bass figures, chords, leads and arps) is gone: SEQ + SELECT, its last user, + * dices with GEN's parts (gen.c dice_seq), on the song's harmony */ enum { RL_DRUM, RL_BASS, RL_PAD, RL_LEAD, RL_ARP, RL_TEX, RL_N }; -enum { DS_MOTORIK, DS_ELECTRO, DS_BREAK, DS_BROKEN, DS_MINIMAL, DS_DEEP, DS_HARD, DS_PUNK, DS_INDIE, DS_SPARSE, - DS_POSTPUNK, DS_RBOX, DS_NEWORD, DS_KLING, DS_EBM, DS_DARK, DS_IDM, DS_NONE }; /* (0.6.80: the wave's four before - * DS_IDM; 0.6.81: EBM's, darkwave's) */ -enum { KT_808, KT_HARD, KT_CLICK, KT_INDUS, KT_SOFT, KT_GLITCH, KT_ELECTRO }; -enum { BS_OCT8, BS_PUMP, BS_ACID, BS_DRONE, BS_ROLL, BS_BLIP, BS_SUB, BS_PUNK, BS_INDIE, BS_RUMBLE, BS_IDM, - BS_HOOK, BS_SUICIDE, BS_SEQ, BS_EBM, BS_DARK }; /* (0.6.80) a bass that sings high, a rockabilly ostinato, a - * sequencer; (0.6.81) EBM's galloping sixteenths, darkwave's - * low root hammered in eighths */ -enum { PS_HOLD, PS_STAB, PS_PULSE, PS_SPARSE, PS_DUB, PS_SWELL, PS_DRONE, PS_POWER }; /* (0.6.80: an organ's drone, a - * guitar's power chords) */ -enum { VC_7, VC_9, VC_QUART, VC_SUS, VC_ADD9, VC_MIX, VC_POWER, VC_TRIAD }; /* the chords' voicings: four notes; (0.6.80) - * the root, its fifth and its octave; a plain triad */ -enum { LM_MOTIF, LM_OSTINATO, LM_SPARSE, LM_TINTI, LM_MECH }; /* how the lead speaks (0.6.80: a machine's motif) */ -enum { AR_UPDOWN, AR_ALBERTI, AR_GLASS, AR_PULSE, AR_WALK, AR_SEQ }; /* how the arp speaks (0.6.80: a sequencer) */ #define EG_A 0u /* ANALOG */ #define EG_PH 2u /* PHASE */ #define EG_LO 3u /* LOFI */ @@ -58,179 +23,6 @@ enum { AR_UPDOWN, AR_ALBERTI, AR_GLASS, AR_PULSE, AR_WALK, AR_SEQ }; /* how th #define SC_MIX 4u #define SC_LYD 9u -typedef struct { - const char *name; - uint8_t bpm_lo, bpm_hi, swing; - uint8_t scale[4]; - int8_t prog[3][4]; /* scale degrees, a chord each (127: the progression ends) */ - uint8_t drums, drum_pct, kit[2]; /* the family (DS_NONE: never), how often it plays, two kits */ - uint8_t bass, pads, voicing, lead, arp; - uint8_t e_lo, e_hi; /* its energies */ - uint8_t prio[5]; /* the melodic roles, the most important first */ - uint8_t odd; /* percent: loops of odd lengths against each other */ - uint8_t e_bass[3], e_pad[3], e_lead[3], e_arp[3], e_tex[3]; - uint8_t rtype[2], dtime[2]; /* reverb types (no SHIMMER), delay times (N_DTIME) */ - uint8_t bars, wet; /* chords every 1, 2 or 4 bars; 0..100: how wet the space */ - uint8_t plain; /* (0.6.81) a band's sound: open filters (air, cymbals), plain - * chords (rarely the rich ones), hats on the offbeat eighths */ -} dstyle_t; - -#define X 127 -#define P_DANCE {RL_BASS, RL_PAD, RL_LEAD, RL_ARP, RL_TEX} -#define P_ARPS {RL_BASS, RL_ARP, RL_PAD, RL_LEAD, RL_TEX} -#define P_PADS {RL_PAD, RL_TEX, RL_LEAD, RL_BASS, RL_ARP} -#define P_SONG {RL_BASS, RL_LEAD, RL_PAD, RL_ARP, RL_TEX} -#define P_CLASS {RL_ARP, RL_PAD, RL_LEAD, RL_TEX, RL_BASS} -static const dstyle_t DSTYLE[] = { - {"IDM", 86, 140, 10, {SC_PHRY, SC_HARM, SC_MIN, SC_DOR}, {{0, 5, 1, X}, {0, 3, 1, 5}, {0, 1, 5, 4}}, - DS_IDM, 100, {KT_GLITCH, KT_CLICK}, BS_IDM, PS_SPARSE, VC_MIX, LM_MOTIF, AR_WALK, 0, 2, P_ARPS, 60, - {EG_FM, EG_A, EG_PH}, {EG_FM, EG_PH, EG_LO}, {EG_PH, EG_LO, EG_FM}, {EG_FM, EG_LO, EG_PH}, {EG_NO, EG_LO, EG_PH}, - {4, 3}, {4, 5}, 1, 60}, - {"DARK IDM", 78, 112, 14, {SC_PHRY, SC_HARM, SC_PHRY, SC_MIN}, {{0, X, X, X}, {0, 1, X, X}, {0, 5, 1, X}}, - DS_IDM, 90, {KT_GLITCH, KT_INDUS}, BS_DRONE, PS_SPARSE, VC_QUART, LM_SPARSE, AR_WALK, 0, 1, P_PADS, 60, - {EG_FM, EG_PH, EG_A}, {EG_PH, EG_FM, EG_VO}, {EG_PH, EG_VO, EG_FM}, {EG_FM, EG_PH, EG_LO}, {EG_NO, EG_VO, EG_LO}, - {4, 3}, {5, 4}, 2, 75}, - {"DARK MINIMAL", 122, 128, 4, {SC_MIN, SC_PHRY, SC_DOR, SC_MIN}, {{0, X, X, X}, {0, 5, X, X}, {0, 1, X, X}}, - DS_MINIMAL, 100, {KT_CLICK, KT_808}, BS_ROLL, PS_DUB, VC_9, LM_OSTINATO, AR_PULSE, 0, 1, P_DANCE, 40, - {EG_A, EG_FM, EG_A}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_FM}, {EG_FM, EG_A, EG_PH}, {EG_NO, EG_VO, EG_PH}, - {0, 4}, {1, 4}, 2, 60}, - {"DUB TECHNO", 116, 124, 6, {SC_MIN, SC_DOR, SC_MIN, SC_MPEN}, {{0, X, X, X}, {0, 3, X, X}, {0, 5, 3, X}}, - DS_DEEP, 100, {KT_SOFT, KT_808}, BS_SUB, PS_DUB, VC_9, LM_SPARSE, AR_PULSE, 0, 1, P_PADS, 0, - {EG_A, EG_FM, EG_A}, {EG_A, EG_PH, EG_FM}, {EG_PH, EG_A, EG_VO}, {EG_FM, EG_A, EG_PH}, {EG_NO, EG_VO, EG_A}, - {4, 0}, {0, 4}, 2, 85}, - {"DARK ELECTRO", 126, 134, 0, {SC_PHRY, SC_MIN, SC_HARM, SC_PHRY}, {{0, 0, 1, 0}, {0, 5, 1, X}, {0, X, X, X}}, - DS_ELECTRO, 100, {KT_ELECTRO, KT_808}, BS_PUMP, PS_STAB, VC_SUS, LM_OSTINATO, AR_UPDOWN, 1, 2, P_DANCE, 0, - {EG_A, EG_FM, EG_PH}, {EG_A, EG_PH, EG_FM}, {EG_A, EG_PH, EG_VO}, {EG_A, EG_LO, EG_FM}, {EG_NO, EG_VO, EG_A}, - {1, 0}, {4, 1}, 1, 35}, - {"ACID NIGHT", 124, 132, 4, {SC_PHRY, SC_HARM, SC_MIN, SC_DOR}, {{0, X, X, X}, {0, 1, X, X}, {0, 5, X, X}}, - DS_MINIMAL, 95, {KT_808, KT_HARD}, BS_ACID, PS_SPARSE, VC_QUART, LM_SPARSE, AR_PULSE, 1, 2, P_DANCE, 0, - {EG_A, EG_A, EG_PH}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_VO}, {EG_FM, EG_A, EG_PH}, {EG_NO, EG_VO, EG_PH}, - {0, 4}, {4, 1}, 2, 45}, - /* (0.6.80) the wave: Joy Division, Suicide, New Order, Kraftwerk. Few chords (one, two), the bass carrying the - * tune high, machines' drums, power chords and triads instead of lush ones, a lead that repeats; their degrees - * major or minor in every scale they take (iv, VII: never dorian's diminished sixth) */ - /* (0.6.81, measured on Joy Division and Bauhaus: the kick on every beat, the hat on the offbeat eighths, the bass - * repeating each note two to four eighths, one chord or two over four bars, major too (Love Will Tear Us Apart: - * A, D), bright) */ - {"POST PUNK", 118, 150, 0, {SC_MIN, SC_MAJ, SC_PHRY, SC_MIN}, {{0, X, X, X}, {0, 3, X, X}, {0, 5, X, X}}, - DS_POSTPUNK, 100, {KT_SOFT, KT_808}, BS_HOOK, PS_POWER, VC_POWER, LM_SPARSE, AR_UPDOWN, 1, 2, - {RL_BASS, RL_LEAD, RL_PAD, RL_TEX, RL_ARP}, 0, - {EG_A, EG_A, EG_PH}, {EG_A, EG_PH, EG_FM}, {EG_A, EG_FM, EG_PH}, {EG_A, EG_PH, EG_FM}, {EG_NO, EG_A, EG_VO}, - {0, 1}, {1, 0}, 4, 55, 1}, - {"BROKEN", 80, 100, 14, {SC_DOR, SC_MIN, SC_MEL, SC_DOR}, {{0, 3, X, X}, {0, X, X, X}, {0, 6, 3, X}}, - DS_BROKEN, 90, {KT_SOFT, KT_GLITCH}, BS_DRONE, PS_SPARSE, VC_QUART, LM_MOTIF, AR_WALK, 0, 1, P_SONG, 60, - {EG_FM, EG_VO, EG_PH}, {EG_PH, EG_VO, EG_FM}, {EG_VO, EG_FM, EG_PH}, {EG_FM, EG_PH, EG_LO}, {EG_VO, EG_NO, EG_PH}, - {4, 3}, {0, 4}, 2, 65}, - {"HYPNOTIC", 124, 130, 2, {SC_PHRY, SC_MIN, SC_DOR, SC_HARM}, {{0, X, X, X}, {0, X, X, X}, {0, 1, X, X}}, - DS_DEEP, 100, {KT_CLICK, KT_808}, BS_BLIP, PS_DUB, VC_SUS, LM_OSTINATO, AR_PULSE, 1, 2, P_ARPS, 50, - {EG_A, EG_FM, EG_PH}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_LO}, {EG_A, EG_FM, EG_PH}, {EG_NO, EG_PH, EG_VO}, - {0, 4}, {5, 1}, 2, 55}, - {"DEEP BREAKS", 108, 122, 8, {SC_MIN, SC_HARM, SC_DOR, SC_PHRY}, {{0, 5, X, X}, {0, 6, 5, X}, {0, 3, 1, X}}, - DS_BREAK, 100, {KT_ELECTRO, KT_SOFT}, BS_ACID, PS_STAB, VC_9, LM_MOTIF, AR_UPDOWN, 1, 2, P_DANCE, 0, - {EG_A, EG_PH, EG_A}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_VO}, {EG_A, EG_FM, EG_PH}, {EG_NO, EG_VO, EG_PH}, - {1, 4}, {4, 1}, 1, 40}, - {"SOUNDTRACK", 64, 92, 0, {SC_MIN, SC_DOR, SC_MEL, SC_MPEN}, {{0, 5, 3, 6}, {0, 3, X, X}, {0, 5, 2, 6}}, - DS_SPARSE, 35, {KT_SOFT, KT_808}, BS_SUB, PS_SWELL, VC_ADD9, LM_SPARSE, AR_ALBERTI, 0, 1, P_PADS, 30, - {EG_A, EG_FM, EG_PH}, {EG_A, EG_PH, EG_VO}, {EG_FM, EG_PH, EG_VO}, {EG_FM, EG_A, EG_PH}, {EG_NO, EG_VO, EG_PH}, - {4, 0}, {0, 4}, 2, 90}, - {"HARD TECHNO", 138, 150, 0, {SC_PHRY, SC_MIN, SC_HARM, SC_PHRY}, {{0, X, X, X}, {0, 1, X, X}, {0, X, X, X}}, - DS_HARD, 100, {KT_HARD, KT_INDUS}, BS_RUMBLE, PS_STAB, VC_SUS, LM_OSTINATO, AR_PULSE, 1, 2, P_DANCE, 0, - {EG_A, EG_PH, EG_A}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_LO}, {EG_A, EG_PH, EG_FM}, {EG_NO, EG_NO, EG_PH}, - {1, 0}, {4, 2}, 2, 30}, - {"SYNTH POP", 118, 130, 0, {SC_MIN, SC_DOR, SC_MIN, SC_PHRY}, {{0, 6, X, X}, {0, 3, X, X}, {3, 6, 0, 0}}, - DS_NEWORD, 100, {KT_ELECTRO, KT_808}, BS_HOOK, PS_STAB, VC_TRIAD, LM_MOTIF, AR_SEQ, 1, 2, - {RL_BASS, RL_ARP, RL_LEAD, RL_PAD, RL_TEX}, 0, - {EG_A, EG_FM, EG_A}, {EG_A, EG_PH, EG_FM}, {EG_A, EG_FM, EG_PH}, {EG_FM, EG_A, EG_PH}, {EG_NO, EG_VO, EG_A}, - {0, 4}, {1, 2}, 1, 40}, - {"MINIMAL SYNTH", 104, 132, 0, {SC_MIN, SC_DOR, SC_MIN, SC_PHRY}, {{0, X, X, X}, {0, X, X, X}, {0, 3, X, X}}, - DS_RBOX, 100, {KT_808, KT_SOFT}, BS_SUICIDE, PS_DRONE, VC_POWER, LM_SPARSE, AR_PULSE, 0, 1, - {RL_BASS, RL_PAD, RL_LEAD, RL_TEX, RL_ARP}, 0, - {EG_A, EG_LO, EG_A}, {EG_A, EG_LO, EG_PH}, {EG_A, EG_VO, EG_A}, {EG_A, EG_LO, EG_PH}, {EG_NO, EG_LO, EG_A}, - {1, 0}, {2, 1}, 2, 50}, - {"NEO CLASSICAL", 70, 112, 0, {SC_MIN, SC_DOR, SC_MAJ, SC_MEL}, {{0, 5, 3, 4}, {0, 3, 4, 0}, {0, 2, 5, 4}}, - DS_NONE, 0, {KT_SOFT, KT_SOFT}, BS_SUB, PS_HOLD, VC_ADD9, LM_TINTI, AR_GLASS, 0, 1, P_CLASS, 50, - {EG_FM, EG_PH, EG_A}, {EG_PH, EG_A, EG_VO}, {EG_FM, EG_PH, EG_VO}, {EG_FM, EG_PH, EG_A}, {EG_VO, EG_PH, EG_NO}, - {0, 4}, {0, 1}, 2, 70}, - {"MAN MACHINE", 100, 124, 0, {SC_MIN, SC_MAJ, SC_DOR, SC_MIN}, {{0, X, X, X}, {0, 3, X, X}, {0, 3, 0, 4}}, - DS_KLING, 100, {KT_ELECTRO, KT_CLICK}, BS_SEQ, PS_HOLD, VC_TRIAD, LM_MECH, AR_SEQ, 1, 2, - {RL_BASS, RL_LEAD, RL_ARP, RL_PAD, RL_TEX}, 0, - {EG_A, EG_PH, EG_FM}, {EG_A, EG_PH, EG_FM}, {EG_A, EG_PH, EG_FM}, {EG_PH, EG_A, EG_FM}, {EG_VO, EG_NO, EG_PH}, - {0, 0}, {1, 0}, 2, 15}, - /* (0.6.81) EBM (DAF, Nitzer Ebb, Front 242: a galloping sequenced bass, a hard machine, a shout), GOTHIC (Bauhaus, - * Sisters of Mercy, the Cure: the bass singing, chorused chords, a big room), BREAKBEAT (the break and an acid - * bass), IMPRESSION (Debussy, Ravel: lydian, ninths moving in parallel, arps like water, no beat or a breath) */ - {"EBM", 112, 126, 0, {SC_PHRY, SC_MIN, SC_PHRY, SC_HARM}, {{0, X, X, X}, {0, X, X, X}, {0, 3, X, X}}, - DS_EBM, 100, {KT_HARD, KT_ELECTRO}, BS_EBM, PS_STAB, VC_POWER, LM_SPARSE, AR_SEQ, 1, 2, - {RL_BASS, RL_LEAD, RL_ARP, RL_PAD, RL_TEX}, 0, - {EG_A, EG_PH, EG_FM}, {EG_A, EG_PH, EG_FM}, {EG_VO, EG_A, EG_PH}, {EG_A, EG_PH, EG_LO}, {EG_NO, EG_VO, EG_LO}, - {0, 1}, {1, 2}, 2, 25}, - {"GOTHIC", 98, 140, 0, {SC_MIN, SC_HARM, SC_PHRY, SC_MIN}, {{0, X, X, X}, {0, X, X, X}, {0, 5, X, X}}, - DS_POSTPUNK, 100, {KT_SOFT, KT_808}, BS_HOOK, PS_SWELL, VC_TRIAD, LM_SPARSE, AR_UPDOWN, 1, 2, - {RL_BASS, RL_PAD, RL_LEAD, RL_ARP, RL_TEX}, 0, - {EG_A, EG_PH, EG_A}, {EG_A, EG_FM, EG_PH}, {EG_A, EG_FM, EG_PH}, {EG_PH, EG_A, EG_FM}, {EG_NO, EG_VO, EG_A}, - {1, 0}, {1, 4}, 4, 75, 1}, - {"BREAKBEAT", 126, 140, 6, {SC_MIN, SC_DOR, SC_PHRY, SC_MIN}, {{0, X, X, X}, {0, 3, X, X}, {0, 6, X, X}}, - DS_BREAK, 100, {KT_ELECTRO, KT_HARD}, BS_ACID, PS_STAB, VC_9, LM_OSTINATO, AR_UPDOWN, 1, 2, P_DANCE, 0, - {EG_A, EG_PH, EG_A}, {EG_PH, EG_A, EG_FM}, {EG_A, EG_PH, EG_VO}, {EG_A, EG_FM, EG_PH}, {EG_NO, EG_VO, EG_PH}, - {1, 0}, {2, 4}, 1, 40}, - {"IMPRESSION", 60, 92, 0, {SC_LYD, SC_MAJ, SC_LYD, SC_MPEN}, {{0, 1, X, X}, {0, 3, X, X}, {0, 5, 1, X}}, - DS_SPARSE, 30, {KT_SOFT, KT_SOFT}, BS_SUB, PS_SWELL, VC_9, LM_TINTI, AR_UPDOWN, 0, 1, - {RL_PAD, RL_ARP, RL_LEAD, RL_TEX, RL_BASS}, 50, - {EG_FM, EG_PH, EG_A}, {EG_FM, EG_PH, EG_A}, {EG_FM, EG_PH, EG_VO}, {EG_FM, EG_PH, EG_A}, {EG_VO, EG_PH, EG_NO}, - {4, 0}, {0, 4}, 2, 90}, - /* (0.6.81) DARKWAVE (Boy Harsher, measured: four on the floor, the snare on 2 and 4, the hat on the offbeat, a low - * synth bass hammering its root in eighths, minor, one chord or two, a lot of room) */ - {"DARKWAVE", 124, 136, 0, {SC_MIN, SC_PHRY, SC_DOR, SC_MIN}, {{0, X, X, X}, {0, 3, X, X}, {0, 6, X, X}}, - DS_DARK, 100, {KT_808, KT_ELECTRO}, BS_DARK, PS_HOLD, VC_TRIAD, LM_SPARSE, AR_PULSE, 1, 2, - {RL_BASS, RL_PAD, RL_LEAD, RL_TEX, RL_ARP}, 0, - {EG_A, EG_A, EG_PH}, {EG_A, EG_PH, EG_A}, {EG_A, EG_PH, EG_FM}, {EG_A, EG_PH, EG_FM}, {EG_NO, EG_VO, EG_A}, - {0, 1}, {1, 2}, 4, 50, 1}, -}; -#undef X -#define NDSTYLE (sizeof DSTYLE / sizeof DSTYLE[0]) -#define DSTYLE_IDM 2u -#define DSTYLE_DARK 10u /* (the first ten: the night's) */ -/* (0.6.80) the wave's four (POST PUNK, SYNTH POP, MINIMAL SYNTH, MAN MACHINE; 0.6.81: and EBM, GOTHIC, BREAKBEAT, - * IMPRESSION): nearly one throw in two */ -static const uint8_t DSTYLE_WAVE[9] = {6, 12, 13, 15, 16, 17, 18, 19, 20}; /* (0.6.81: EBM, GOTHIC, BREAKBEAT, - * IMPRESSION, DARKWAVE) */ - -static int32_t rr(int32_t lo, int32_t hi) { return lo + (int32_t)(rng() % (uint32_t)(hi - lo + 1)); } -static int chance(uint32_t pct) { return rng() % 100u < pct; } -static uint32_t dstyle_pick(void) -{ - return chance(45) ? DSTYLE_WAVE[rng() % 9u] : chance(25) ? rng() % DSTYLE_IDM : chance(80) ? rng() % DSTYLE_DARK : - DSTYLE_DARK + rng() % (NDSTYLE - DSTYLE_DARK); -} - -/* the piece: the harmony (the progression, how long each chord lasts, the voicing, the last chord voiced: the next is - * led to it), the energy, the twist */ -enum { TW_NONE, TW_PHASE, TW_COMB, TW_GRAIN, TW_POLY, TW_DRONE }; -static struct { - const int8_t *prog; - uint32_t n, steps, voicing, nlast, energy, twist, plain; - uint32_t arp; /* (0.6.81) how the arp speaks this throw (the genre's, or - * ambient: up and down in eighths over a rich chord) */ - int32_t last[4]; -} dh; -static int32_t chord_at(uint32_t step) { return dh.prog[(step / dh.steps) % dh.n]; } -/* the tonic at or above lo: every part's degree 0 (0.6.32: the chords and the lead had the fifth and the third) */ -static int32_t dtonic(const track_t *t, int32_t lo) { return lo + ((t->p[P_ROOT] - lo) % 12 + 12) % 12; } - -static void dstep_note(step_t *s, const int32_t *n, uint32_t cnt, uint32_t vel, uint32_t flags) -{ - uint32_t j; - int32_t top = 0; - s->n = (uint8_t)cnt; - for (j = 0; j < 4u; j++) { - s->note[j] = (uint8_t)(j < cnt ? clamp(n[j], 0, 127) : 0); - if (j < cnt && n[j] > top) top = n[j]; - } - s->time = ST_NOTE; - s->flags = (uint8_t)(flags | (s->flags & SF_MFINE)); /* (0.9.1: MICRO's 64ths stay with its sixteenth) */ - if (top > 74) vel -= (uint32_t)((top - 74) * 2 < 30 ? (top - 74) * 2 : 30); /* (high notes measured: softer) */ - s->vel = (uint8_t)clamp((int32_t)vel + rr(-6, 6), 40, 127); /* (a human's hand: never twice the same) */ -} static void dstep_tie(step_t *s) { s->n = 0; s->time = ST_TIE; s->flags &= SF_MFINE; s->vel = 0; } /* holds the note of step i over the next k steps (as far as the loop goes and the next note) */ static void dhold(track_t *t, uint32_t i, uint32_t k, uint32_t len) @@ -250,449 +42,6 @@ static int euclid(uint32_t i, uint32_t k, uint32_t n, uint32_t rot) return (i * k) % n < k; } -/* ---- DRUMS (lanes: 0 BD, 1 SD, 2 CP, 3 CH, 4 OH, 5 TM, 6 RS, 7 CB): a family's bar as strings ('x' a hit, 'a' - * accented, 'g' a ghost: three times in four), a fill over the loop's last beat (0.6.35: as 0.6.33 wrote them, the - * energy leaves the drums alone: they sounded better) */ -/* (0.9.7, flash) the text tools/gen_drum_maps.py reads (not compiled): build/gen/dice_bars.h holds each lane once, 2 bits - * a step (DB_LANE), the table as lane numbers (DRUM_BAR_I: db_char) */ -#ifdef GEN_DRUM_MAPS_TEXT -static const char *const DRUM_BAR[][8] = { - [DS_MOTORIK] = {"x...x...x...x...", "....x.......x...", "", "x.x.x.x.x.x.x.x.", "", "", "..x.....x.x.....", ""}, - [DS_ELECTRO] = {"a......x..x.....", "....a.......a...", "....x.......x..x", "xgxgxgxgxgxgxgxg", "", "..............x.", "", "......x........."}, - [DS_BREAK] = {"a.........x.....", "....a..g.g..a..g", "", "x.x.x.x.x.x.x.x.", "......x.......x.", "", "", ""}, - [DS_BROKEN] = {"x..x....x.x.....", "....a..g.g..a...", "", "x.xgx.x.x.xgx.x.", ".......x........", "", "", ""}, - [DS_MINIMAL] = {"a...x...a...x...", "", "....g.......g...", "g.x...xgg.x...x.", "..x...x...x...x.", "", "...x..g...x..x..", "......g........."}, - [DS_DEEP] = {"a...x...a...x...", "", "............g...", "..x...x...x...x.", "..g...x...g...x.", "", ".g.....x.g....x.", ""}, - [DS_HARD] = {"a...a...a...a...", "", "....x.......x...", "xgxgxgxgxgxgxgxg", "..x...x...x...x.", "", "..g..g....g..g..", "......g.......g."}, - [DS_PUNK] = {"a.....x.a.x.....", "....a.......a...", "", "x.x.x.x.x.x.x.x.", "", "", "", ""}, - [DS_INDIE] = {"a......xa.x.....", "....a.......a..g", "", "x.xgx.xgx.xgx.xg", "..............x.", "", "", ""}, - [DS_SPARSE] = {"x...............", "", "", "", "", "", "......g.....x...", "..........g....."}, - /* (0.6.80) the wave's: Stephen Morris's tight kit (sixteenths on the hat, the floor tom answering), a cheap rhythm - * box (Suicide), Blue Monday's four on the floor and its handclap, Kraftwerk's dry machine and its metal */ - [DS_POSTPUNK] = {"a...x...a...x...", "....a.......a...", "", "x.a.x.a.x.a.x.a.", "", "", "", ""}, /* (0.6.81: - * measured, the kick on every beat, the hat's offbeats) */ - [DS_RBOX] = {"x.......x.x.....", "....x.......x...", "", "xgxgxgxgxgxgxgxg", "", "", "", ""}, - [DS_NEWORD] = {"a...a...a...a...", "", "....a.......a...", "xgxgxgxgxgxgxgxg", "..x.......x.....", "", "", ""}, - [DS_KLING] = {"x.....x.x.......", "....x.......x...", "", "x.x.x.x.x.x.x.x.", "", "", "..........x...x.", "x..x..x...x.x..."}, - [DS_EBM] = {"a...a...a...a...", "....a.......a...", "....x.......x...", "..x...x...x...x.", "", "", "", ""}, /* (0.6.81) */ - [DS_DARK] = {"a...a...a...a...", "....a.......a...", "....x.......x...", "..a...a...a...a.", "", "", "", ""}, -}; -static const char *const DRUM_BAR_KICK[1] = {"a.......a.x....."}; /* (0.6.81: the post punk kick's other bar) */ -#endif -#include "dice_bars.h" -static char db_char(uint32_t k, uint32_t p) /* lane k's step p: '.' 'x' 'a' 'g' */ -{ - return ".xag"[(DB_LANE[k][(p >> 2) & 3u] >> (6u - 2u * (p & 3u))) & 3u]; -} -static void dice_drums(track_t *t, const dstyle_t *st, uint32_t len) -{ - uint32_t i, l; - if (st->drums == DS_IDM) { /* euclids against each other, ratchets, chance (0.6.33's) */ - uint32_t kb = (uint32_t)rr(3, 6), ks = (uint32_t)rr(2, 4), kh = (uint32_t)rr(7, 13), rot = (uint32_t)rr(0, 7); - for (i = 0; i < len; i++) { - step_t *s = &t->step[i]; - uint32_t h = 0, b = i / 16u; /* (each bar its own: the hats denser or sparser, the kick turned) */ - if (euclid(i, kb, 16, rot + (b == 3u ? 2u : 0u))) h |= 1u << 0; - if (euclid(i, ks, 16, rot + 4u) && !(h & 1u)) h |= 1u << (chance(50) ? 1 : 6); - if (euclid(i, kh + (b & 1u) * 2u - (b == 2u ? 3u : 0u), 16, b)) h |= 1u << (chance(20) ? 4 : 3); - if (chance(8)) h |= 1u << (5u + rng() % 3u); - if (!h) continue; - s->time = ST_NOTE; s->hit = (uint8_t)h; s->acc = (uint8_t)(i % 4u == 0u ? h & 1u : 0u); - s->vel = (uint8_t)(h & 1u ? 104 : rr(70, 100)); - if ((h & (1u << 3)) && chance(25)) step_set_ratchet(s, (uint32_t)rr(2, 4)); - if (!(h & 1u) && chance(30)) step_set_chance(s, (uint32_t)rr(45, 85)); - } - return; - } - /* (0.6.81) the post punk kick now and then on 1 and 3 and an eighth before 3 (Boy Harsher's Pain); darkwave's - * snare now and then a sixteenth before the bar (step 15); the hat's open one on the last offbeat */ - uint32_t kick = st->drums == DS_POSTPUNK && chance(30) ? DRUM_BAR_KICK_I : 0u; /* (dice_bars.h) */ - uint32_t snr15 = st->drums == DS_DARK && chance(50), oh = (st->drums == DS_POSTPUNK || st->drums == DS_DARK) && chance(40); - for (i = 0; i < len; i++) { - step_t *s = &t->step[i]; - uint32_t h = 0, a = 0, ghost = 0, p = i % 16u; - uint32_t fill = len > 16u && i >= len - 4u && st->drums != DS_DEEP && st->drums != DS_SPARSE && - st->drums != DS_KLING && st->drums != DS_RBOX && st->drums != DS_DARK; /* (machines: no fills) */ - for (l = 0; l < NLANE; l++) { - uint32_t b = l == 0u && kick ? kick : DRUM_BAR_I[st->drums][l]; - char c = b ? db_char(b, p) : '.'; - if (c == 'x' || c == 'a' || (c == 'g' && rng() % 4u)) h |= 1u << l; - if (c == 'a') a |= 1u << l; - if (c == 'g') ghost = 1; - } - if (snr15 && p == 15u && (i / 16u) % 2u == 1u) h |= 1u << 1; - if (oh && p == 14u && (i / 16u) % 2u == 1u) h = (h & ~(1u << 3)) | (1u << 4); - if (fill) { - if (st->drums == DS_NEWORD) h |= 1u; /* (Blue Monday's sixteenth kicks) */ - else if (chance(50)) h |= 1u << (chance(50) ? 1 : 5); - h &= ~(1u << 4); - } - if (i >= 16u && !fill && chance(8)) h ^= 1u << (chance(50) ? 6 : 7); /* bar 2: a percussion moved */ - if (!h) continue; - s->time = ST_NOTE; s->hit = (uint8_t)h; s->acc = (uint8_t)(a & h); /* (0.6.90: an accent only on a hit: one - * moved away or swapped left its accent, which a save dropped) */ - s->vel = (uint8_t)(st->drums == DS_KLING ? (a ? 112 : 100) : ghost && !a ? rr(62, 82) : rr(96, 110)); /* (a - * machine: the same every time) */ - if (fill && chance(40)) step_set_ratchet(s, 2); - if ((st->drums == DS_ELECTRO || st->drums == DS_MINIMAL || st->drums == DS_HARD) && (h & (1u << 3)) && chance(10)) - step_set_ratchet(s, 2); - if (!(h & 1u) && (st->drums == DS_MINIMAL || st->drums == DS_DEEP || st->drums == DS_SPARSE) && chance(15)) - step_set_chance(s, (uint32_t)rr(50, 85)); - } -} -/* ---- the chords: degree d's four notes from the tonic t0 in the voicing, then led (each note an octave up or down) - * to the nearest of the last chord inside [t0 - 2, t0 + 17] (C3..F4 or so): no leaps, a middle register */ -static uint32_t dchord(const track_t *t, int32_t t0, int32_t d, uint32_t vc, int32_t *n) -{ - static const int8_t V[6][4] = {{0, 2, 4, 6}, {0, 2, 6, 8}, {0, 3, 6, 9}, {0, 3, 4, 8}, {0, 2, 4, 8}, {0, 2, 4, 0}}; /* - * 7th, 9th (no 5th), fourths, sus4 add9, add9; (0.6.80) a triad */ - uint32_t j, i, cnt = 4; - if (vc == VC_MIX) vc = rng() % 5u; - if (vc == VC_POWER) { /* (0.6.80) the root, its fifth, its octave: parallel, a - * guitar's (the fifth always perfect, the scale or not) */ - n[0] = scale_steps(t, t0, d); - n[1] = n[0] + 7; - n[2] = n[0] + 12; - cnt = 3; - } else { - if (vc == VC_TRIAD) { vc = 5; cnt = 3; } - for (j = 0; j < cnt; j++) n[j] = scale_steps(t, t0, d + V[vc][j]); - } - for (j = 0; j < cnt; j++) { - while (n[j] < t0 - 2) n[j] += 12; - while (n[j] > t0 + 15) n[j] -= 12; - } - if (dh.nlast) { /* led: each note the octave nearest the last chord's middle */ - int32_t mid = 0; - for (i = 0; i < dh.nlast; i++) mid += dh.last[i]; - mid /= (int32_t)dh.nlast; - for (j = 0; j < cnt; j++) { - if (n[j] - mid > 7 && n[j] - 12 >= t0 - 5) n[j] -= 12; - else if (mid - n[j] > 7 && n[j] + 12 <= t0 + 17) n[j] += 12; - } - } - for (i = 1; i < cnt; i++) /* (low to high) */ - for (j = i; j > 0 && n[j] < n[j - 1]; j--) { int32_t x = n[j]; n[j] = n[j - 1]; n[j - 1] = x; } - for (j = 1; j < cnt; j++) /* (no unisons: a clash an octave up) */ - if (n[j] == n[j - 1]) n[j] += 12; - for (j = 0; j < cnt; j++) dh.last[j] = n[j]; - dh.nlast = cnt; - return cnt; -} - -/* ---- the bass: deep (from E1: its register starts low), the figure the genre's, denser with the energy */ -static void dice_bass(track_t *t, const dstyle_t *st, uint32_t len) -{ - int32_t base = dtonic(t, 28), n[1]; - uint32_t i, e = dh.energy; - static const uint8_t PUMP[16] = {1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0}; - uint8_t acid[16], roll[16], ind[16]; - int8_t hook[8]; - { /* (0.6.80) Peter Hook's line: eight eighths a bar, high, a tune of its own around the chord's root, the bar's - * last two moved on the fourth bar. (0.6.81, measured: a real one repeats the note before it in half to three - * quarters of its eighths: each note now hammered two to four eighths (one now and then), then a step, a - * third now and then; it started on the root) */ - int32_t d = 0, j, mv, run = 0; - for (j = 0; j < 8; j++) { - if (!run) { - if (j) { - mv = chance(70) ? (chance(50) ? 1 : -1) : (chance(50) ? 2 : -2); - if (d + mv > 5 || d + mv < -2) mv = -mv; - d += mv; - } - run = chance(15) ? 1 : rr(2, 4); - } - hook[j] = (int8_t)d; - run--; - } - } - for (i = 0; i < 16u; i++) { /* (one bar's figure, kept: a riff, not noise) */ - acid[i] = (uint8_t)(i % 4u == 0u ? 1u : chance(30 + e * 10u) ? 1u + rng() % 4u : 0u); - roll[i] = (uint8_t)(i % 4u == 2u ? 1u : i % 4u == 3u ? chance(20 + e * 15u) : i % 4u == 1u ? chance(e * 8u) : 0u); - ind[i] = (uint8_t)(i == 0u || i == 10u || (i == 6u && chance(50)) || (i == 14u && chance(40))); - } - if (st->bass != BS_DRONE && st->bass != BS_SUB && base < 33) base += 12; /* (a figure: from A1; a drone: E1) */ - if (st->bass == BS_HOOK) base = dtonic(t, 40); /* (0.6.80: the hook an octave up, from E2: it sings) */ - if (st->bass == BS_DARK) base = dtonic(t, 31); /* (0.6.81: darkwave's, low: from G1) */ - for (i = 0; i < len; i++) { - step_t *s = &t->step[i]; - int32_t d = chord_at(i), on = 0, oct = 0, step = 0, vel = 96; - uint32_t fl = 0, p = i % 16u, hold = 0; - switch (st->bass) { - case BS_OCT8: on = i % 2u == 0u && (e || i % 4u == 0u); oct = (i / 2u) & 1u; break; - case BS_PUMP: on = PUMP[p]; oct = p == 11u; fl = p == 0u ? SF_ACCENT : 0; break; - case BS_ACID: on = acid[p] != 0u; step = acid[p] == 2u ? 1 : acid[p] == 3u ? 4 : acid[p] == 4u ? -1 : 0; - oct = acid[p] == 3u && chance(50); fl = (p % 4u == 0u ? SF_ACCENT : 0) | (chance(25) ? SF_SLIDE : 0); break; - case BS_DRONE: on = i % (dh.steps < 16u ? dh.steps : 16u) == 0u; hold = 15; break; - case BS_ROLL: on = roll[p]; vel = p % 4u == 2u ? 100 : 80; break; - case BS_SUB: - on = p == 0u || (e && p == 10u) || (e == 2u && p == 6u); - hold = p == 0u ? (e ? 5 : 13) : 2; - if (p == 10u && chance(40)) step = 4; - break; - case BS_BLIP: on = (p % 4u == 2u && chance(70)) || p == 0u; vel = 90; break; - case BS_PUNK: on = i % 2u == 0u; step = p >= 12u && chance(40) ? 4 : 0; fl = p % 8u == 0u ? SF_ACCENT : 0; break; - case BS_INDIE: on = ind[p]; step = p == 14u ? (chord_at(i + 2u) - d) - 1 : p == 10u && chance(40) ? 4 : 0; - hold = p == 0u ? 3 : 1; break; - case BS_RUMBLE: on = p % 4u != 0u && (p % 4u == 2u || chance(30 + e * 20u)); vel = p % 4u == 2u ? 96 : 76; break; - case BS_HOOK: /* (0.6.80) the tune on the eighths, legato */ - on = p % 2u == 0u; - step = hook[p / 2u] + ((i / 16u) % 4u == 3u && p >= 12u ? (p == 12u ? 1 : -1) : 0); - vel = p % 8u == 0u ? 100 : 88; - hold = 1; - break; - case BS_SUICIDE: { /* (0.6.80) Martin Rev's rockabilly ostinato: root, root, - * fifth, root .. the seventh, the fifth; an octave every - * other bar's end */ - static const int8_t SU[8] = {0, 0, 4, 0, 0, 0, 6, 4}; - on = p % 2u == 0u; - step = SU[p / 2u]; - oct = (i / 16u) % 2u == 1u && p == 14u; - fl = p % 8u == 0u ? SF_ACCENT : 0; - vel = 92; - break; - } - case BS_EBM: { /* (0.6.81) EBM's gallop: sixteenths, root, root, octave, root; - * the off-beat ones softer */ - static const int8_t EB[4] = {0, 0, 12, 0}; - n[0] = scale_steps(t, base, d) + EB[p % 4u]; - dstep_note(s, n, 1, p % 2u ? 82u : 96u, 0); - continue; - } - case BS_DARK: /* (0.6.81) the root hammered in eighths, the downbeats harder; - * the octave at the end of every second bar, the fifth before - * it now and then */ - on = p % 2u == 0u; - oct = (i / 16u) % 2u == 1u && p == 14u; - step = (i / 16u) % 4u == 3u && p == 12u && chance(50) ? 4 : 0; - vel = p % 4u == 0u ? 100 : 86; - break; - case BS_SEQ: { /* (0.6.80) Kraftwerk's sequencer: sixteenths, root, octave, - * fifth, octave; the same strength every step */ - static const int8_t SQ[4] = {0, 12, 7, 12}; /* (semitones: the fifth always perfect) */ - on = 1; - n[0] = scale_steps(t, base, d) + SQ[p % 4u]; - dstep_note(s, n, 1, 90, 0); - continue; - } - default: on = chance(25 + e * 10u); step = (int32_t)(rng() % 3u) * 2 - 2; oct = chance(10); break; /* BS_IDM */ - } - if (!on) continue; - n[0] = scale_steps(t, base, d + step) + (oct ? 12 : 0); - dstep_note(s, n, 1, (uint32_t)vel + (fl & SF_ACCENT ? 16u : 0u), fl); - if (hold) dhold(t, i, hold, len); - if (st->bass == BS_IDM && chance(12)) step_set_ratchet(s, 2); - } -} - -/* ---- the chords: always four notes; held, swelling, stabbed, pulsed, dubbed or sparse */ -static void dice_pads(track_t *t, const dstyle_t *st, uint32_t len) -{ - int32_t t0 = dtonic(t, 50), n[4]; - uint32_t i, c, last_d = 0xFFFFu, e = dh.energy; - uint8_t dub[16]; - { /* (PS_DUB: one bar's stab figure, kept: the first offbeat and one to three of the others) */ - static const uint8_t AT[6] = {6, 10, 14, 7, 11, 13}; - uint32_t m = (uint32_t)rr(1, 2) + (e == 2u), j; - for (i = 0; i < 16u; i++) dub[i] = (uint8_t)(i == 2u); - for (j = 0; j < m; j++) dub[AT[rng() % 6u]] = 1; - } - dh.nlast = 0; - for (i = 0; i < len; i++) { - step_t *s = &t->step[i]; - uint32_t pp = i % dh.steps, p = i % 16u; - int on = 0; - switch (st->pads) { - case PS_HOLD: case PS_SWELL: on = pp == 0u; break; - case PS_STAB: on = (p % 4u == 2u && chance(35 + e * 15u)) || (pp == 0u && chance(40)); break; - case PS_PULSE: on = i % (e == 2u ? 2u : 4u) == 0u && !(p == 12u && chance(50)); break; - case PS_DUB: on = dub[p]; break; - case PS_DRONE: on = i == 0u; break; /* (0.6.80) one chord held under everything: an organ */ - case PS_POWER: on = pp == 0u || (p == 8u && (i / 16u) % 2u == 1u && chance(60)); break; /* (0.6.80) a guitar's - * power chords: the chord's first beat, now and then a push */ - default: on = pp == 0u && (i == 0u || chance(65)); break; /* PS_SPARSE: some chords (the first), the rest silence */ - } - if (!on) continue; - if ((uint32_t)chord_at(i) != last_d || st->pads == PS_HOLD || st->pads == PS_SWELL || st->pads == PS_SPARSE || - st->pads == PS_DRONE) { - c = dchord(t, t0, chord_at(i), dh.voicing, n); - last_d = (uint32_t)chord_at(i); - } else { /* (the same chord: the same voicing, stab after stab) */ - for (c = 0; c < dh.nlast; c++) n[c] = dh.last[c]; - } - dstep_note(s, n, c, st->pads == PS_DUB ? (p == 2u ? 90u : 78u) : st->pads == PS_SWELL || st->pads == PS_DRONE ? 74u : 80u, 0); - if (st->pads == PS_HOLD || st->pads == PS_SWELL || st->pads == PS_SPARSE) dhold(t, i, dh.steps - 1u, len); - if (st->pads == PS_DRONE) dhold(t, i, len - 1u, len); - if (st->pads == PS_POWER) dhold(t, i, p == 8u ? 5u : 7u, len); - if (st->pads == PS_PULSE && chance(40)) dhold(t, i, 1, len); - } -} - -/* (0.6.37) a lead note: the scale's degree d from base, folded down under G5 whatever the path (a cell, a line, a - * cadence: the motif's fold alone let a FRANTIC cell reach C#6) */ -static int32_t dlead_note(const track_t *t, int32_t base, int32_t d) -{ - int32_t n = scale_steps(t, base, d); - while (n > 79) n -= 12; - return n; -} -/* ---- the lead (around the tonic at G3..: never past G5). LM_MOTIF: a rhythmic motif of 2..5 notes (more with the - * energy), its contour in steps (a leap filled back by a step the other way), its strong steps on chord tones; - * the phrase A, A moved to the next chord (a sequence), A (its end varied), a cadence (its first half, then the tonic - * held). LM_OSTINATO: a cell of 2..4 notes on an euclidean rhythm, turning. LM_SPARSE: a few long chord tones - * stepping. LM_TINTI: Part's M voice, a scale line in long notes, rising or falling around the tonic */ -static int32_t dnear_ct(int32_t deg, int32_t chord) /* the chord tone (chord + 0, 2, 4) nearest a degree */ -{ - int32_t best = chord, k; - for (k = -7; k <= 11; k += 2) { - int32_t c = chord + k; - if (((c - chord) % 7 + 7) % 7 > 4) continue; /* (0, 2, 4 of the chord: its triad) */ - if ((deg - c < 0 ? c - deg : deg - c) < (deg - best < 0 ? best - deg : deg - best)) best = c; - } - return best; -} -static void dice_lead(track_t *t, const dstyle_t *st, uint32_t len) -{ - int32_t base = dtonic(t, 55), n[1]; - uint32_t i, e = dh.energy; - if (st->lead == LM_OSTINATO) { - static const int8_t CELL[6][4] = {{0, 0, 1, 0}, {0, 2, 1, 0}, {4, 2, 0, 1}, {0, -1, 0, 2}, {0, 4, 3, 1}, {2, 1, 0, -2}}; - const int8_t *cl = CELL[rng() % 6u]; - uint32_t k = (uint32_t)rr(3, 5) + e, rot = (uint32_t)rr(0, 3), nc = (uint32_t)rr(2, 4), j = 0; - for (i = 0; i < len; i++) { - uint32_t b = i / 16u; - if (!euclid(i % 16u, k, 16, rot)) continue; - if (b % 4u == 3u && chance(50)) continue; /* (the fourth bar: a breath) */ - n[0] = dlead_note(t, base, cl[j % nc] + (b % 4u == 2u && j % nc == nc - 1u ? 1 : 0)); - dstep_note(&t->step[i], n, 1, j % nc == 0u ? 98u : 82u, chance(15) ? SF_SLIDE : 0); - j++; - } - return; - } - if (st->lead == LM_MECH) { /* (0.6.80) a machine's tune (Kraftwerk): a figure of chord - * tones and their octave on an euclidean rhythm, the same in - * every bar (moved with the chord), the same strength, short */ - static const int8_t MT[4][8] = {{0, 2, 4, 2, 0, 4, 7, 4}, {4, 4, 2, 0, 2, 2, 0, -1}, {0, 0, 4, 0, 5, 4, 2, 0}, - {7, 4, 2, 4, 0, 2, 4, 0}}; - const int8_t *mt = MT[rng() % 4u]; - uint32_t k = (uint32_t)rr(4, 6) + e, rot = (uint32_t)rr(0, 3), idx, q; - for (i = 0; i < len; i++) { - if (!euclid(i % 16u, k, 16, rot)) continue; - for (q = 0, idx = 0; q < i % 16u; q++) idx += euclid(q, k, 16, rot); /* (its place in the bar's figure) */ - n[0] = dlead_note(t, base, mt[idx % 8u] + chord_at(i - i % 16u)); - dstep_note(&t->step[i], n, 1, 92, 0); - } - return; - } - if (st->lead == LM_SPARSE || st->lead == LM_TINTI) { /* long notes: 1 or 2 a bar (TINTI: a scale line) */ - int32_t d = st->lead == LM_TINTI ? rr(2, 5) : 2, dir = chance(50) ? -1 : 1; - for (i = 0; i < len; i += 8u) { - uint32_t b = i / 16u; - if (st->lead == LM_SPARSE && ((i % 16u) || (b % 2u == 1u && chance(40)))) continue; - if (st->lead == LM_SPARSE) d = dnear_ct(d + rr(-1, 1), chord_at(i)); - else { d += dir; if (d < -2 || d > 7) { dir = -dir; d += 2 * dir; } } - n[0] = dlead_note(t, base, d); - dstep_note(&t->step[i], n, 1, 84, 0); - dhold(t, i, st->lead == LM_TINTI ? 6 : 12, len); - } - return; - } - { /* LM_MOTIF (0.6.80: repeated, not a cadence: A A A A' over and over, as the wave's tunes go round; its notes - * on the strong steps a chord tone three times in five (the others a tension: a ninth, an eleventh, kept so in - * every repeat), repeated notes allowed in its contour; it never lands on the tonic to end) */ - uint8_t at[6], snap[6]; - int8_t deg[6]; - uint32_t k = (uint32_t)rr(2, 3) + e, j, rot = (uint32_t)rr(0, 5), bars = len / 16u ? len / 16u : 1u; - int32_t d = (int32_t)(rng() % 3u) * 2, prev = 0; - if (k > 5u) k = 5u; - for (i = 0, j = 0; i < 16u && j < k; i++) /* the motif's rhythm: k onsets, euclidean, turned */ - if (euclid(i, k, 16, rot)) at[j++] = (uint8_t)i; - k = j; - for (j = 0; j < k; j++) { /* its contour: steps, repeated notes; a leap, then a step back */ - int32_t mv = chance(25) ? 0 : chance(70) ? (chance(50) ? 1 : -1) : (chance(50) ? rr(2, 3) : -rr(2, 3)); - if (j && (prev >= 2 || prev <= -2)) mv = prev > 0 ? -1 : 1; /* (the gap filled) */ - if (j) d = clamp(d + mv, -3, 7); - deg[j] = (int8_t)d; - snap[j] = (uint8_t)chance(60); - prev = j ? mv : 0; - } - for (i = 0; i < bars; i++) { - uint32_t ph = i % 4u, b0 = i * 16u; - int32_t ch = chord_at(b0), shift = ph == 1u ? chord_at(b0) - chord_at(b0 >= 16u ? b0 - 16u : b0) : 0; - if (ph == 2u && chance(30)) continue; /* (now and then a bar of rest: space) */ - for (j = 0; j < k; j++) { - int32_t dd = deg[j] + shift; - uint32_t pos = b0 + at[j]; - if (ph == 3u && j == k - 1u) { /* (A': its last note moved a step, or left out) */ - if (chance(40)) continue; - dd += chance(50) ? 1 : -1; - } - if (at[j] % 4u == 0u && snap[j]) dd = dnear_ct(dd, ch); - if (pos >= len) break; - n[0] = dlead_note(t, base, dd); - dstep_note(&t->step[pos], n, 1, at[j] % 4u == 0u ? 96u : 82u, chance(10) ? SF_SLIDE : 0); - { /* held to the next onset, a step of air before it (more air with less energy) */ - uint32_t nxt = j + 1u < k ? at[j + 1u] : 16u + at[0], gap = nxt - at[j]; - if (gap > 2u + (2u - e)) dhold(t, pos, gap - 2u - (2u - e), len); - } - } - } - } -} - -/* ---- the arp, in the middle octaves (C3..C5) over the chord's four notes. AR_UPDOWN: up and down with holes; - * AR_ALBERTI: low, high, middle, high; AR_GLASS: Glass's additive groups (3, then 3+2, ...) in a steady pulse; - * AR_PULSE: Reich's repeated tone with accents; AR_WALK: a random walk over the chord (the IDM's) */ -static void dice_arp(track_t *t, const dstyle_t *st, uint32_t len) -{ - int32_t t0 = dtonic(t, 52), n[1], c[4]; - uint32_t i, e = dh.energy, rate = e == 2u || dh.arp == AR_GLASS ? 1u : 2u, k = (uint32_t)rr(5, 9) + e * 2u, w = 0; - static const uint8_t ALB[4] = {0, 3, 1, 3}; - if (dh.arp == AR_GLASS || dh.arp == AR_PULSE || dh.arp == AR_SEQ) k = 16; /* (a steady pulse: no holes) */ - if (dh.arp == AR_SEQ) rate = 1; /* (0.6.80: the sequencer's sixteenths) */ - dh.nlast = 0; - for (i = 0; i < len; i++) { - uint32_t idx = i / rate, j; - if (i % rate) continue; - if (!euclid(idx % 16u, k, 16, 0) && chance(80)) continue; /* (holes in the figure: space) */ - if (i % dh.steps == 0u || !dh.nlast) dchord(t, t0, chord_at(i), dh.voicing, c); /* (0.6.80: from the - * tonic; t0 + 2 snapped to the scale's next degree, so the arp - * played the chord a step above the harmony, against the bass) */ - else for (j = 0; j < dh.nlast; j++) c[j] = dh.last[j]; - switch (dh.arp) { - case AR_ALBERTI: j = ALB[idx % 4u]; break; - case AR_GLASS: { uint32_t g = (idx / 8u) % 2u ? 5u : 3u; j = (idx % g) % 4u; break; } - case AR_PULSE: j = idx % 8u == 7u ? 2u : 0u; break; - case AR_WALK: w = (w + (chance(50) ? 1u : 3u)) % 4u; j = w; break; - case AR_SEQ: { static const uint8_t SQ[4] = {0, 3, 1, 3}; j = SQ[idx % 4u]; break; } /* (0.6.80: low, top, - * middle, top; the top its last note) */ - default: j = (idx % 6u) < 4u ? idx % 6u : 6u - idx % 6u; break; /* up 0 1 2 3, down 2 1 */ - } - j = j >= dh.nlast ? dh.nlast - 1u : j; /* (0.6.80: three-note chords) */ - n[0] = c[j]; - while (n[0] > 72) n[0] -= 12; /* (the middle octaves) */ - while (n[0] < 48) n[0] += 12; - dstep_note(&t->step[i], n, 1, dh.arp == AR_SEQ ? 84u : idx % 4u == 0u ? 92u : dh.arp == AR_PULSE ? 70u : 78u, 0); - if (st->drums == DS_IDM && chance(10)) step_set_ratchet(&t->step[i], 2); - } -} - -/* ---- the texture: a long low note a bar or two (the root, the fifth, the second), or a drone over everything */ -static void dice_texture(track_t *t, const dstyle_t *st, uint32_t len) -{ - int32_t base = dtonic(t, 43), n[1]; - uint32_t i; - (void)st; - for (i = 0; i < len; i += 16u) { - uint32_t at = i + (uint32_t)rr(0, 2) * 4u; - if (i && chance(45)) continue; - n[0] = scale_steps(t, base, chance(30) ? 4 : chance(30) ? 1 : 0); - dstep_note(&t->step[at < len ? at : i], n, 1, 72, 0); - } - for (i = 0; i < len; i++) - if (t->step[i].time == ST_NOTE) dhold(t, i, dh.twist == TW_DRONE ? 63 : 11, len); -} - /* ---- the sound: a factory preset of engine e whose name says the role and is not a bright one, moved a little; * its envelope shaped for the role and the energy; filtered for the role */ static int dname_has(const char *s, const char *w) @@ -704,121 +53,6 @@ static int dname_has(const char *s, const char *w) } return 0; } -static int dbright(const char *s) /* (0.6.32) the cheerful ones: never picked */ -{ - static const char *const B[] = {"BELL", "BRASS", "MARIMBA", "ORGAN", "GOSPEL", "FLUTE", "8BIT", "JAZZ", "ARCADE", - "RAVE", "ROCK", "SQR BASS", "BYTEBEAT", "STEP LEAD"}; - uint32_t i; - for (i = 0; i < NELEM(B); i++) - if (dname_has(s, B[i])) return 1; - return 0; -} -static uint32_t dice_fm6; /* FM6 tracks this dice: two at most (its CPU) */ -static void dice_sound(track_t *t, uint32_t role, const uint8_t *el) -{ - static const char *const W[6][6] = {{0}, {"BASS", "ACID", "GROWL", 0}, - {"PAD", "PWM", "STR", "CHOIR", 0}, - {"SAW LEAD", "SYNC", "WIRE", "VOX", "WAVE LEAD", "TINE"}, - {"PLUCK", "FLOAT ARP", "SINE KEY", "TINE", "RESO", "BYTE TONE"}, - {"WIND", "RAIN", "WHISPER", "METAL", "BYTE BENT", "FLOAT FM"}}; - uint32_t e = el[rng() % 3u], tries, k, n, i, nm = 0, na = 0, en_ = dh.energy; - uint8_t m[32], any[32]; - const engine_t *en; - for (tries = 0; tries < 6u && (e == t->eng_req || (e == ENGI_FM6 && dice_fm6 >= 2u)); tries++) - e = el[rng() % 3u]; /* (another engine than it had, when it can; FM6 twice at most) */ - if (e == ENGI_FM6 && dice_fm6 >= 2u) - e = EG_A; - dice_fm6 += e == ENGI_FM6; - set_engine_of(t, e); - en = trk_engp(t); - n = en->npresets; - if (!n) return; - for (i = 0; i < n; i++) { /* the presets whose names fit the role; the not bright ones, - * and never a bass's sound off the bass (0.6.34) */ - const char *pn = en->presets[i].name; - if (dbright(pn) || (role != RL_BASS && (dname_has(pn, "BASS") || dname_has(pn, "GROWL") || dname_has(pn, "ACID")))) - continue; - if (na < sizeof any) any[na++] = (uint8_t)i; - for (k = 0; k < 6u && W[role][k]; k++) - if (dname_has(en->presets[i].name, W[role][k]) && nm < sizeof m) { m[nm++] = (uint8_t)i; break; } - } - apply_preset_to(t, nm ? m[rng() % nm] : na ? any[rng() % na] : rng() % n); /* (the role's, always: surprises - * come from the twist, not from a wrong sound) */ - for (i = 0; i < 8u; i++) { /* (a sixth of each range: still that sound, a bit its own) */ - const param_desc_t *d = track_desc(t, P_E0 + i); - int32_t span = (d->max - d->min) / 6; - if (!d->label || d->label[0] == '-' || d->max <= d->min || d->fmt == F_ENUM) continue; - t->p[P_E0 + i] = (int16_t)dice_by(t->p[P_E0 + i], d->min, d->max, span ? span : 1); - } - /* (0.6.34) the envelope for the role and the energy: pads that swell in space, plucked arps and basses, a lead - * that speaks; the engines' own colour a little warmer (FM6 its modulation down, PHASE its DCW down, ANALOG a - * little detune on the chords, a sub an octave down now and then) */ - switch (role) { - case RL_PAD: t->p[P_ATK] = (int16_t)(en_ == 0u ? rr(60, 100) : rr(20, 70)); t->p[P_REL] = (int16_t)rr(75, 110); - t->p[P_SUS] = (int16_t)rr(100, 120); break; - case RL_TEX: t->p[P_ATK] = (int16_t)rr(70, 110); t->p[P_REL] = (int16_t)rr(90, 120); break; - case RL_LEAD: t->p[P_ATK] = (int16_t)rr(2, en_ == 0u ? 40 : 20); t->p[P_REL] = (int16_t)rr(40, 80); break; - case RL_ARP: t->p[P_ATK] = (int16_t)rr(0, 8); t->p[P_DEC] = (int16_t)rr(30, 62); t->p[P_SUS] = (int16_t)rr(20, 70); - t->p[P_REL] = (int16_t)rr(40, 75); break; - case RL_BASS: t->p[P_ATK] = 0; t->p[P_DEC] = (int16_t)rr(40, 70); t->p[P_SUS] = (int16_t)rr(50, 105); - t->p[P_REL] = (int16_t)rr(18, 40); break; - } - if (e == EG_FM) t->p[P_E2] = (int16_t)clamp(t->p[P_E2] - rr(4, 24), -64, 63); - if (e == EG_PH) t->p[P_E2] = (int16_t)clamp(t->p[P_E2] - rr(0, 20), 20, 127); - if (e == EG_A && role == RL_PAD) t->p[P_E1] = (int16_t)rr(12, 32); - if (e == EG_A && role == RL_BASS && chance(30)) t->p[P_E7] = -12; - { /* filtered: the cutoff down by role (ANALOG its own filter, the others the part's), some resonance; never flat: - * the TYPE changes (LP mostly; band-pass, the comb tuned to the note for the arps and the textures), the - * envelope opens the filter on every sound, a slow LFO of its own shape on some cutoffs (S&H: the IDM's), - * a little grit on some basses and leads */ - static const uint8_t CUT[6][2] = {{0, 0}, {36, 66}, {48, 70}, {58, 82}, {48, 72}, {44, 76}}; - static const uint8_t ENV[6][2] = {{0, 0}, {18, 48}, {8, 28}, {12, 36}, {22, 50}, {0, 24}}; - static const uint8_t FT[6][4] = {{100, 0, 0, 0}, {100, 0, 0, 0}, {65, 0, 30, 5}, {75, 0, 20, 5}, {55, 0, 30, 15}, - {30, 10, 35, 25}}; /* LP HP BP COMB, percent */ - int32_t cut = rr(CUT[role][0], CUT[role][1]), res = rr(role == RL_BASS ? 12 : 20, role == RL_ARP ? 62 : 48); - uint32_t ft = 0, w = rng() % 100u, acc = 0; - if (role == RL_DRUM) return; - for (ft = 0; ft < 3u; ft++) { acc += FT[role][ft]; if (w < acc) break; } - if (dh.twist == TW_COMB && (role == RL_PAD || role == RL_ARP)) ft = 3; - t->p[P_FTYPE] = (int16_t)ft; - if (ft == 2u) cut += 10; /* (a band-pass: higher, or it is only a rumble) */ - if (dh.plain && role != RL_BASS) cut += rr(12, 22); /* (0.6.81, measured: a band's chords, guitars and leads - * open, air above 5 kHz; ours were twice as dark) */ - if (e == EG_A) { - t->p[P_E4] = (int16_t)(t->p[P_E4] < cut ? t->p[P_E4] : cut); - t->p[P_E5] = (int16_t)clamp(t->p[P_E5], res, 90); - } else { - t->p[P_FCUT] = (int16_t)(role == RL_BASS ? cut + 24 : cut); /* (a bass: only its fizz taken) */ - t->p[P_FRES] = (int16_t)res; - } - t->p[P_ED_FLT] = (int16_t)rr(ENV[role][0], ENV[role][1]); - if (role == RL_PAD || role == RL_TEX || chance(35)) { - static const uint8_t LW[4] = {0, 1, 4, 0}; /* SIN TRI S&H */ - t->p[P_LWAVE] = (int16_t)(role == RL_ARP && chance(50) ? 4 : LW[rng() % 4u]); - t->p[P_LRATE] = (int16_t)(t->p[P_LWAVE] == 4 ? rr(30, 70) : rr(4, 26)); - t->p[P_LD_FLT] = (int16_t)rr(8, role == RL_TEX ? 34 : 24); - } - if ((role == RL_BASS || role == RL_LEAD) && chance(35)) { - t->p[P_DIST] = (int16_t)rr(10, 38); - t->p[P_DTYPE] = (int16_t)(chance(60) ? 0 : 2); /* SOFT, or FOLD */ - } - if (role == RL_PAD) { /* (0.6.81) the chords: a slow, soft LFO on the filter always */ - t->p[P_LWAVE] = (int16_t)(chance(70) ? 0 : 1); /* (SIN, TRI) */ - t->p[P_LRATE] = (int16_t)rr(4, 16); - t->p[P_LD_FLT] = (int16_t)rr(8, 20); - } - if (role == RL_LEAD) { /* (0.6.81) a lead never stands still: its filter's envelope - * always opening it, and an LFO on the filter one in two */ - if (t->p[P_ED_FLT] < 12) t->p[P_ED_FLT] = (int16_t)rr(12, 36); - if (chance(50)) { - t->p[P_LWAVE] = (int16_t)(chance(60) ? 0 : 1); - t->p[P_LRATE] = (int16_t)rr(6, 30); - t->p[P_LD_FLT] = (int16_t)rr(8, 22); - } - } - } -} - /* a part that sits high plays quieter: its level down with its average note above E4 (and its highest) */ static void dlevel(track_t *t, uint32_t len) { @@ -847,9 +81,6 @@ static int32_t dsounding(const track_t *t, uint32_t i) /* the note sounding at } return -1; } -/* (0.6.67) SEQ + SELECT: the selected track's sequence diced as DICE ALL writes a part (a genre, its progression and - * energy; the track's own scale and root): the drums on a DRUM track; else the role its steps sound like (low: the - * bass, chords: a pad, else a lead or an arp). The sound, the mix and the automation stay. Its message */ /* (0.6.83) SAVE > TOOLS 6 CPU TEST: the heaviest song the instrument should play cleanly, to measure on the device * (USB console status: audio_max_us, audio_late, voices_shed) and to listen for clicks. Every live track: chords of four * on every step at 160 BPM, gliding into each other (GLIDE, POLY), two step components on each (ARP SEQ / ECHO x8 and @@ -895,44 +126,3 @@ static void cpu_test_song(void) load_end(t); } } -static const char *dice_seq(track_t *t) -{ - static const char *const RN[RL_N] = {"SEQ DICED: DRUMS", "SEQ DICED: BASS", "SEQ DICED: PAD", "SEQ DICED: LEAD", - "SEQ DICED: ARP", "SEQ DICED: TEXTURE"}; - const dstyle_t *st = &DSTYLE[dstyle_pick()]; - uint32_t r, i, len, pr = rng() % 3u, lo = 0, cnt = 0, chord = 0; - rng_state ^= fm1_ticks() * 2654435761u; - if (!rng_state) rng_state = 0x1234567u; - if (st->prog[pr][0] == 127) pr = 0; - dh.prog = st->prog[pr]; - for (dh.n = 0; dh.n < 4u && dh.prog[dh.n] != 127; dh.n++) {} - dh.steps = 16u * st->bars; - if (dh.steps * dh.n > NSTEP) dh.steps = NSTEP / dh.n; - dh.voicing = st->voicing; - dh.arp = st->arp; - dh.plain = st->plain; - dh.nlast = 0; - dh.energy = (uint32_t)rr(st->e_lo, st->e_hi); - dh.twist = TW_NONE; - for (i = 0; i < NSTEP; i++) /* (what it plays now: its register, its chords) */ - if (t->step[i].time == ST_NOTE && t->step[i].n) { lo += t->step[i].note[0]; cnt++; chord += t->step[i].n > 1u; } - r = drum_track(t) ? RL_DRUM : cnt && lo / cnt < 48u ? RL_BASS : chord * 3u > cnt && cnt ? RL_PAD : - chance(50) ? RL_LEAD : RL_ARP; - len = (uint32_t)t->p[P_SLEN]; - if (len < 8u || len > NSTEP) len = dh.steps * dh.n < 16u ? 16u : dh.steps * dh.n; - load_begin(t, LOAD_PAT); - latch_drop_req |= (uint8_t)(1u << trk_index(t)); - for (i = 0; i < NSTEP; i++) - step_clear(&t->step[i]); - switch (r) { - case RL_DRUM: dice_drums(t, st, len); break; - case RL_BASS: dice_bass(t, st, len); break; - case RL_PAD: dice_pads(t, st, len); break; - case RL_LEAD: dice_lead(t, st, len); break; - default: dice_arp(t, st, len); break; - } - t->p[P_SLEN] = (int16_t)len; - if (r != RL_DRUM) dlevel(t, len); - load_end(t); - return RN[r]; -} diff --git a/tests/dice_metrics.c b/tests/dice_metrics.c new file mode 100644 index 00000000..2a50392d --- /dev/null +++ b/tests/dice_metrics.c @@ -0,0 +1,297 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) + * (0.9.18) the dice measured (not a test: numbers): consecutive presses of every DICE path from a fresh power-on and + * mid-session, as the owner presses them. GEN (HOME + SELECT, OCT+ again: a new seed) per genre and EXPLORE; SEQ + + * SELECT (the selected track's sequence); EDIT + SELECT (its sound). Per role: the share of a press's part the same as + * the press before (exact, near: 90 % of its steps, transposition-invariant) and as one of the 8 before; the distinct + * presets; the lead's melody (in the key, steps, leaps past a fifth and their resolution, range, rests, syncopation, + * bar-to-bar reuse); the envelopes (static full-sustain, no release), the filter (cutoff, resonance, envelope, drive), + * LFO and vibrato, the kit's sends. + * cc -O1 -w -Ibuild/gen -Ifirmware/src -Itests -o build/host/dice_metrics tests/dice_metrics.c -lm + * build/host/dice_metrics [presses] (default 40) */ +#define UI_TEST_NO_MAIN 1 +#include "ui_test.c" + +#define DM_MAXP 200u +#define DM_NR 6u +#define DM_HIST 8u +typedef struct { uint16_t len; int16_t v[NSTEP]; } dm_seq_t; +static dm_seq_t dm_last[DM_NR][DM_HIST]; +static uint32_t dm_nh[DM_NR]; +static uint32_t dm_lcg = 12345u; +static uint32_t dm_rnd(void) { dm_lcg = dm_lcg * 1103515245u + 12345u; return dm_lcg >> 8; } + +static void dm_take(const track_t *t, int drum, int32_t ref, dm_seq_t *q) +{ + uint32_t i, len = dlen(t); + q->len = (uint16_t)len; + for (i = 0; i < len; i++) { + const step_t *s = &t->step[i]; + q->v[i] = drum ? (int16_t)(s->time == ST_NOTE ? s->hit : 0) : + (int16_t)(s->time == ST_NOTE && s->n ? 200 + s->note[0] - ref : s->time == ST_TIE ? 1 : 0); + } +} +static int dm_same(const dm_seq_t *a, const dm_seq_t *b, uint32_t pct) +{ + uint32_t i, eq = 0, n = a->len > b->len ? a->len : b->len, any = 0; + if (a->len != b->len) return 0; + for (i = 0; i < n; i++) { eq += a->v[i] == b->v[i]; any |= a->v[i] | b->v[i]; } + return any && eq * 100u >= n * pct; +} +typedef struct { uint32_t n, ex1, near1, ex8, near8; } dm_dup_t; +static void dm_note_dup(uint32_t r, const dm_seq_t *q, dm_dup_t *d) +{ + uint32_t k, e8 = 0, n8 = 0, h = dm_nh[r] < DM_HIST ? dm_nh[r] : DM_HIST; + int any = 0; + for (k = 0; k < q->len; k++) any |= q->v[k]; + if (!any) return; + d->n++; + if (h) { + const dm_seq_t *p = &dm_last[r][(dm_nh[r] - 1u) % DM_HIST]; + d->ex1 += dm_same(q, p, 100); d->near1 += dm_same(q, p, 90); + } + for (k = 0; k < h; k++) { e8 |= dm_same(q, &dm_last[r][k], 100); n8 |= dm_same(q, &dm_last[r][k], 90); } + d->ex8 += e8; d->near8 += n8; + dm_last[r][dm_nh[r] % DM_HIST] = *q; + dm_nh[r]++; +} +/* the melody's numbers */ +typedef struct { uint32_t notes, out, iv, step, rep, leap5, leap5r, range, ranges, steps, rest, onsets, sync, bars, reuse, ct, strong; } dm_mel_t; +static void dm_melody(const track_t *t, dm_mel_t *m, int harm) +{ + uint32_t i, len = dlen(t), pend = 0; + int32_t prev = -1, piv = 0, lo = 127, hi = 0; + uint16_t bar0 = 0; + for (i = 0; i < len; i++) { + const step_t *s = &t->step[i]; + m->steps++; + if (s->time == ST_REST) m->rest++; + if (s->time != ST_NOTE || !s->n) continue; + { + int32_t n = s->note[0], iv, a; + uint32_t mask = scale_mask(t); + m->notes++; m->onsets++; + m->sync += (i & 1u); + m->out += !((mask >> (uint32_t)((n - t->p[P_ROOT] + 120) % 12)) & 1u); + if (n < lo) lo = n; + if (n > hi) hi = n; + if (i < 16u) bar0 |= (uint16_t)(1u << i); + if (harm && i % 4u == 0u) { m->strong++; m->ct += (gchord_pcs(i) >> (uint32_t)(n % 12)) & 1u; } + if (prev >= 0) { + iv = n - prev; a = iv < 0 ? -iv : iv; + m->iv++; m->rep += !a; m->step += a && a <= 2; + if (pend) { m->leap5r += a && a <= 2 && (iv > 0) != (piv > 0); pend = 0; } + if (a > 7) { m->leap5++; pend = 1; piv = iv; } + } + prev = n; + } + } + if (hi >= lo) { m->range += (uint32_t)(hi - lo); m->ranges++; } + for (i = 16; i + 16u <= len; i += 16u) { + uint16_t bb = 0; + uint32_t q, d = 0; + for (q = 0; q < 16u; q++) if (t->step[i + q].time == ST_NOTE && t->step[i + q].n) bb |= (uint16_t)(1u << q); + if (!bb || !bar0) continue; + for (q = 0; q < 16u; q++) d += ((bb ^ bar0) >> q) & 1u; + m->bars++; m->reuse += d <= 3u; + } +} +static void dm_mel_print(const char *what, const dm_mel_t *m) +{ + printf(" %-12s in key %5.1f%% steps %4.1f%% repeats %4.1f%% leaps>5th %4.1f%% (resolved %3.0f%%) range %4.1f st rests %4.1f%% " + "offbeat onsets %4.1f%% bars reusing bar 1 %4.1f%% strong on chord tones %4.1f%%\n", what, + m->notes ? 100.0 * (m->notes - m->out) / m->notes : 0, m->iv ? 100.0 * m->step / m->iv : 0, m->iv ? 100.0 * m->rep / m->iv : 0, + m->iv ? 100.0 * m->leap5 / m->iv : 0, m->leap5 ? 100.0 * m->leap5r / m->leap5 : 0, m->ranges ? (double)m->range / m->ranges : 0, + m->steps ? 100.0 * m->rest / m->steps : 0, m->onsets ? 100.0 * m->sync / m->onsets : 0, m->bars ? 100.0 * m->reuse / m->bars : 0, + m->strong ? 100.0 * m->ct / m->strong : 0); +} +/* the sound's numbers, a role */ +typedef struct { uint32_t n, flat, swell, pluck, cut, cutn, res, envf, drive, lfof, vib, low; uint16_t pre[DM_MAXP]; uint32_t npre, pre_rep1; } dm_snd_t; +static void dm_sound(const track_t *t, dm_snd_t *s) +{ + uint32_t e = t->eng_req, id = e << 8 | t->preset, k; + int32_t cut = e == EG_A ? t->p[P_E4] : t->p[P_FCUT]; + s->n++; + s->flat += t->p[P_SUS] >= 120 && t->p[P_REL] <= 12; + s->swell += t->p[P_ATK] >= 40; + s->pluck += t->p[P_SUS] <= 90 && t->p[P_DEC] <= 80; + s->cut += (uint32_t)cut; s->cutn++; s->low += cut < 80; + s->res += (uint32_t)(e == EG_A ? t->p[P_E5] : t->p[P_FRES]); + s->envf += (uint32_t)(t->p[P_ED_FLT] > 0 ? t->p[P_ED_FLT] : 0); + s->drive += t->p[P_DIST] > 0; + s->lfof += t->p[P_LD_FLT] != 0; + s->vib += t->p[P_LD_PIT] != 0; + for (k = 0; k < s->npre && k < DM_MAXP; k++) if (s->pre[k] == id) break; + if (k == s->npre && s->npre < DM_MAXP) s->pre[s->npre++] = (uint16_t)id; +} +static void dm_snd_print(const char *what, const dm_snd_t *s) +{ + if (!s->n) return; + printf(" %-6s n %3u presets %3u static (SUS>=95%%, REL~0) %4.1f%% pluck %4.1f%% swell %4.1f%% cutoff %5.1f (under 80: %4.1f%%) " + "reso %4.1f env>flt %4.1f drive %4.1f%% LFO>flt %4.1f%% vibrato %4.1f%%\n", what, s->n, s->npre, + 100.0 * s->flat / s->n, 100.0 * s->pluck / s->n, 100.0 * s->swell / s->n, s->cutn ? (double)s->cut / s->cutn : 0, + s->cutn ? 100.0 * s->low / s->cutn : 0, (double)s->res / s->n, (double)s->envf / s->n, 100.0 * s->drive / s->n, + 100.0 * s->lfof / s->n, 100.0 * s->vib / s->n); +} +static const char *const RLN[DM_NR] = {"DRUMS", "BASS", "CHORDS", "LEAD", "ARP", "TEX"}; +static void dm_reset(void) +{ + ui_power_on(); + ui_rec_prefs |= PREF_SIX >> 8; rp_apply(); + settings.palette = UI_JIANT_INDEX; palette_set(UI_JIANT_INDEX); + memset(dm_nh, 0, sizeof dm_nh); +} +static void dm_wait(void) { uint32_t d = 600000u + dm_rnd() % 2400000u; host_ticks += d * 2u; fm1_ms += d / 1000u; } + +int main(int argc, char **argv) +{ + uint32_t N = argc > 1 ? (uint32_t)atoi(argv[1]) : 40u, g, p, k, r; + dm_dup_t tot[DM_NR] = {{0}}; + dm_mel_t mel_lead = {0}, mel_arp = {0}, mel_bass = {0}; + dm_snd_t snd_all[DM_NR] = {{0}}; + uint32_t seeds_same = 0, kit_send = 0, kit_lanes = 0, kit_n = 0; + uint32_t cost_max = 0; + double cost_sum = 0; + if (N > DM_MAXP) N = DM_MAXP; + if (argc > 2) { /* (prints: every genre's fingerprint at three seeds) */ + for (g = 0; g <= NGENRE + 1u; g++) + for (p = 0; p < 3u; p++) { + dm_reset(); + gp.genre = (uint8_t)g; gp.seed = (uint16_t)(p * 1234u + 7u); gp.energy = 50; gp.form = (uint8_t)(p % 3u); + gp.complex = 50; gp.swing = GA_AUTO; gp.human = 30; + for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO; + gen_go(); + printf("%u %u %08x\n", g, p, dice_print()); + } + return 0; + } + printf("== GEN: %u presses of OCT+ a genre (the same settings: a new seed each), mid-session\n", N); + for (g = 0; g <= NGENRE; g++) { /* (NGENRE: EXPLORE) */ + dm_dup_t d[DM_NR] = {{0}}; + dm_snd_t sn[DM_NR] = {{0}}; + uint32_t lastp[DM_NR], prep[DM_NR] = {0}; + uint16_t lastseed = 0xFFFF; + dm_reset(); + for (k = 0; k < DM_NR; k++) lastp[k] = 0xFFFFu; + gp.genre = (uint8_t)(g < NGENRE ? g + 1u : GEN_EXPLORE); + gp.energy = 50; gp.form = 0; gp.complex = 50; gp.swing = GA_AUTO; gp.human = 30; + for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO; + gp.seed = (uint16_t)(dm_rnd() % 10000u); + for (p = 0; p < N; p++) { + struct timespec t0, t1; + uint32_t us; + dm_wait(); + clock_gettime(CLOCK_MONOTONIC, &t0); + gen_press(); + clock_gettime(CLOCK_MONOTONIC, &t1); + us = (uint32_t)((t1.tv_sec - t0.tv_sec) * 1000000 + (t1.tv_nsec - t0.tv_nsec) / 1000); + cost_sum += us; if (us > cost_max) cost_max = us; + seeds_same += gp.seed == lastseed; lastseed = gp.seed; + for (k = 0; k < NTRK; k++) { + const track_t *t = &trk[k]; + dm_seq_t q; + r = gs.role[k]; + if (!gs.act[r] || (r == RL_TEX && k != gs.trk_of[RL_TEX])) continue; + dm_take(t, r == RL_DRUM, gs.root, &q); + dm_note_dup(r, &q, &d[r]); + if (r != RL_DRUM) { + uint32_t id = t->eng_req << 8 | t->preset; + dm_sound(t, &sn[r]); dm_sound(t, &snd_all[r]); + prep[r] += id == lastp[r]; lastp[r] = id; + } + if (r == RL_LEAD) dm_melody(t, &mel_lead, 1); + if (r == RL_ARP) dm_melody(t, &mel_arp, 1); + if (r == RL_BASS) dm_melody(t, &mel_bass, 1); + if (r == RL_DRUM) { + uint32_t l; + kit_n++; + for (l = 0; l < 8u; l++) { kit_lanes++; kit_send += (dx_snd[l] & 63u) != 0; } + } + } + } + printf("%-13s", g < NGENRE ? GENRE[g].name : "EXPLORE"); + for (r = 0; r < DM_NR; r++) { + if (!d[r].n) { printf(" %s -", RLN[r]); continue; } + printf(" %s %2u/%2u/%2u", RLN[r], d[r].ex1 * 100u / d[r].n, d[r].near1 * 100u / d[r].n, d[r].near8 * 100u / d[r].n); + if (r) printf("(p%u,r%u)", sn[r].npre, prep[r]); + tot[r].n += d[r].n; tot[r].ex1 += d[r].ex1; tot[r].near1 += d[r].near1; tot[r].ex8 += d[r].ex8; tot[r].near8 += d[r].near8; + } + printf("\n"); + } + printf(" (a role: %% the same as the press before exact / near / near one of the 8 before; p distinct presets, r the same preset as before)\n"); + printf("GEN all genres:"); + for (r = 0; r < DM_NR; r++) if (tot[r].n) printf(" %s %.1f/%.1f/%.1f%%", RLN[r], 100.0 * tot[r].ex1 / tot[r].n, 100.0 * tot[r].near1 / tot[r].n, 100.0 * tot[r].near8 / tot[r].n); + printf("\n seeds repeated back to back: %u; a press %.2f ms on the host (the most %.2f ms)\n", seeds_same, cost_sum / ((NGENRE + 1u) * N) / 1000.0, cost_max / 1000.0); + dm_mel_print("GEN lead", &mel_lead); dm_mel_print("GEN arp", &mel_arp); dm_mel_print("GEN bass", &mel_bass); + for (r = 1; r < DM_NR; r++) dm_snd_print(RLN[r], &snd_all[r]); + printf(" kit: sounds with a send %.1f%%\n", kit_lanes ? 100.0 * kit_send / kit_lanes : 0); + + /* ---- power-on: the first GEN press after five power-ons (another time each) */ + { + uint32_t h[5], same = 0, i, j; + for (i = 0; i < 5u; i++) { + dm_reset(); + rng_state = 0x1234567u; + host_ticks = 1000000u + i * 7777777u; + session_dice(host_ticks ^ (i * 3u) << 16); /* (main.c: the ticks and the battery's ADC) */ + gp.genre = GEN_EXPLORE; gp.seed = 1; gp.sig = 0; /* (gp as at power-on) */ + gen_press(); + h[i] = dice_print(); + for (j = 0; j < i; j++) same += h[j] == h[i]; + } + printf("== power-on: the first GEN press after 5 power-ons: %u pairs the same piece of 10\n", same); + } + /* ---- SEQ + SELECT: the selected track's sequence diced, N times, on a GEN piece's lead, bass, drums */ + { + uint32_t roles[3] = {RL_LEAD, RL_BASS, RL_DRUM}, ri; + printf("== SEQ + SELECT (dice_seq): %u presses on a HOUSE piece's track\n", N); + for (ri = 0; ri < 3u; ri++) { + dm_dup_t d = {0}; + dm_mel_t m = {0}; + uint32_t tk; + dm_reset(); + gp.genre = 1; gp.seed = 77; gp.energy = 50; gp.form = 0; gp.complex = 50; gp.swing = GA_AUTO; gp.human = 30; + for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO; + gen_go(); + tk = gs.trk_of[roles[ri]]; + if (tk >= NTRK) continue; + song.sel = (uint8_t)tk; + for (p = 0; p < N; p++) { + dm_seq_t q; + dm_wait(); + dice_seq(&trk[tk]); + dm_take(&trk[tk], roles[ri] == RL_DRUM, trk[tk].p[P_ROOT], &q); + dm_note_dup(roles[ri], &q, &d); + if (roles[ri] != RL_DRUM) dm_melody(&trk[tk], &m, 1); + } + printf(" %-6s the same as the press before %u%% exact %u%% near, near one of the 8 before %u%%\n", RLN[roles[ri]], + d.n ? d.ex1 * 100u / d.n : 0, d.n ? d.near1 * 100u / d.n : 0, d.n ? d.near8 * 100u / d.n : 0); + if (roles[ri] != RL_DRUM) dm_mel_print(RLN[roles[ri]], &m); + } + } + /* ---- EDIT + SELECT: the sound diced, N times a synth engine */ + { + static const uint8_t EN[5] = {EG_A, EG_FM, EG_PH, EG_LO, EG_VO}; + uint32_t ei; + printf("== EDIT + SELECT (sound_dice_of): %u presses an engine\n", N); + for (ei = 0; ei < 5u; ei++) { + dm_snd_t s = {0}; + uint32_t rep = 0, last = 0xFFFF, in8 = 0, h[8], nh = 0, j; + dm_reset(); + set_engine_of(&trk[1], EN[ei]); + for (p = 0; p < N; p++) { + uint32_t hit = 0; + dm_wait(); + sound_dice_of(&trk[1], 1); + dm_sound(&trk[1], &s); + rep += trk[1].preset == last; last = trk[1].preset; + for (j = 0; j < (nh < 8u ? nh : 8u); j++) hit |= h[j] == trk[1].preset; + in8 += hit; h[nh++ % 8u] = trk[1].preset; + } + printf(" %-7s of %2u presets: %2u chosen, the same as before %u, one of the 8 before %u;", ENGINES[EN[ei]]->name, + ENGINES[EN[ei]]->npresets, s.npre, rep, in8); + printf(" static env %.0f%%\n", 100.0 * s.flat / s.n); + } + } + return 0; +} diff --git a/tools/gen_drum_maps.py b/tools/gen_drum_maps.py index ee213cbe..90558f1f 100644 --- a/tools/gen_drum_maps.py +++ b/tools/gen_drum_maps.py @@ -63,42 +63,44 @@ def main(src, dice, out, dout, bout): for name, v in ptab: L.append(f"static const uint8_t {name}_I[{len(v)}] = {{{', '.join(map(str, v))}}};") size = 8 * len(lanes) + 8 * len(table) + sum(len(v) for _, v in ptab) - # DICE's bars + # DICE's bars (0.9.18: gone with song_dice.c's own generator; the header stays, empty, for an older source) d = Path(dice).read_text() m = re.search(r"static const char \*const DRUM_BAR\[\]\[8\] = \{(.*?)\n\};", d, re.S) - brows = re.findall(r"\[(DS_\w+)\]\s*=\s*\{([^}]*)\}", m.group(1)) - kick = re.findall(r'"([^"]*)"', re.search(r"static const char \*const DRUM_BAR_KICK\[1\] = \{(.*?)\};", d, re.S).group(1)) - bl, bi = [""], {"": 0} - code = {".": 0, "x": 1, "a": 2, "g": 3} - - def blane(x): - if x not in bi: - assert len(x) == 16 and set(x) <= set(code), f"gen_drum_maps: bar lane {x!r}" - assert set(x) != {"."}, "an all-rest lane would read as none" - bi[x] = len(bl) - bl.append(x) - return bi[x] - btab = [] - for name, body in brows: - ls = re.findall(r'"([^"]*)"', body) - assert len(ls) == 8, f"gen_drum_maps: {name} has {len(ls)} lanes" - btab.append((name, [blane(x) for x in ls])) - kk = [blane(x) for x in kick] Path(out).write_text("\n".join(L) + "\n") + bl, btab = [""], [] + if m: + brows = re.findall(r"\[(DS_\w+)\]\s*=\s*\{([^}]*)\}", m.group(1)) + kick = re.findall(r'"([^"]*)"', re.search(r"static const char \*const DRUM_BAR_KICK\[1\] = \{(.*?)\};", d, re.S).group(1)) + bi = {"": 0} + code = {".": 0, "x": 1, "a": 2, "g": 3} + + def blane(x): + if x not in bi: + assert len(x) == 16 and set(x) <= set(code), f"gen_drum_maps: bar lane {x!r}" + assert set(x) != {"."}, "an all-rest lane would read as none" + bi[x] = len(bl) + bl.append(x) + return bi[x] + for name, body in brows: + ls = re.findall(r'"([^"]*)"', body) + assert len(ls) == 8, f"gen_drum_maps: {name} has {len(ls)} lanes" + btab.append((name, [blane(x) for x in ls])) + kk = [blane(x) for x in kick] L = ["/* generated by tools/gen_drum_maps.py from firmware/src/song_dice.c (DRUM_BAR, DRUM_BAR_KICK, as text there): */", "/* each lane once, 2 bits a step ('.' 0 'x' 1 'a' 2 'g' 3; lane 0: none); the table as lane numbers */", "#pragma once", "#include "] - L.append(f"static const uint8_t DB_LANE[{len(bl)}][4] = {{") - for x in bl: - v = [code[c] for c in x] if x else [0] * 16 - L.append(" {" + ", ".join(f"0x{v[4 * i] << 6 | v[4 * i + 1] << 4 | v[4 * i + 2] << 2 | v[4 * i + 3]:02X}" for i in range(4)) - + "}," + (f" /* {x} */" if x else " /* (none) */")) - L.append("};") - L.append("static const uint8_t DRUM_BAR_I[][8] = {") - for name, v in btab: - L.append(f" [{name}] = {{{', '.join(map(str, v))}}},") - L.append("};") - L.append(f"#define DRUM_BAR_KICK_I {kk[0]}u") + if m: + L.append(f"static const uint8_t DB_LANE[{len(bl)}][4] = {{") + for x in bl: + v = [code[c] for c in x] if x else [0] * 16 + L.append(" {" + ", ".join(f"0x{v[4 * i] << 6 | v[4 * i + 1] << 4 | v[4 * i + 2] << 2 | v[4 * i + 3]:02X}" for i in range(4)) + + "}," + (f" /* {x} */" if x else " /* (none) */")) + L.append("};") + L.append("static const uint8_t DRUM_BAR_I[][8] = {") + for name, v in btab: + L.append(f" [{name}] = {{{', '.join(map(str, v))}}},") + L.append("};") + L.append(f"#define DRUM_BAR_KICK_I {kk[0]}u") Path(dout).write_text("\n".join(L) + "\n") size2 = 4 * len(bl) + 8 * len(btab) m = re.search(r"static const barch_t BASS_ARCH\[BA_N\] = \{(.*?)\n\};", s, re.S)