mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 12:54:29 +01:00
- LFO > MSEQ: per track a CV-style sequence of 16 levels with LEN, DIV and SLEW, running with the transport; the MOD matrix reads it as STEP. - DIST TYPE (SOFT as before, HARD, FOLD, CRUSH, RECT) and TONE (FX > DIST). - Delay: HPF in the feedback (COLR stays its high cut). WIDTH: the delay's right echo up to 1/32 later, the chorus's second tap opposite; 0 is mono as before. - Reverb: PRE (pre-delay up to 100 ms); MOD and RATE modulate the ROOM's comb lengths (interpolated reads) and deepen the SPRING's wobble. - Projects are FUNB (3840 bytes): 21 track parameters before P_E0 (P_COUNT 120, P_E0 112) and 5 globals after the header's 27. FUNA and older load mapped by count, the new values at their defaults; the goldens are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
398 lines
23 KiB
C
398 lines
23 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* FELUCCA core types: tracks, voices, engines, parameters.
|
|
* Four tracks, each a synth part: its own engine, preset, parameters, voices and 64-step
|
|
* pattern. The parts share one budget of NVOICE sounding voices (voice.c). Drums are the DRUM
|
|
* engine (General MIDI map) on any part; the SAMPLE engine's PERC set is retired (drum_from_perc).
|
|
* Sections: sizes, parameters, voices and engines, tracks and the song, system. */
|
|
#include <stdint.h>
|
|
|
|
/* ------------------------------------------------------------ sizes --- */
|
|
#define NVOICE 8 /* voices per part, and the budget shared by all parts */
|
|
#define NPART 4 /* synth parts: tracks 1..4 */
|
|
#define NTRK NPART /* tracks (the formats and the protocol count these): every track is a part */
|
|
#define NSTEP 64
|
|
#define HALF_FRAMES 128 /* I2S half buffer: 2.9 ms at 44.1 kHz (a key waits 0..1 half, then plays 1 half later) */
|
|
#ifndef FELUCCA_SLICE
|
|
#define FELUCCA_SLICE 1 /* the SLICE engine (eng_slice.c), engine 13; FELUCCA_SLICE=0 builds without it */
|
|
#endif
|
|
#ifndef FELUCCA_FM4
|
|
#define FELUCCA_FM4 0 /* the DIGITAL engine (eng_digital.c, four-operator FM): kept in the tree, not built
|
|
* by default; replaced by FM6, its sounds convert (fm4_convert.c) */
|
|
#endif
|
|
#define NENGINES (13 + FELUCCA_SLICE) /* SLICE (13) comes last: the other engines keep their numbers */
|
|
#define ENGI_DIGITAL 1u /* reserved without FELUCCA_FM4: never selectable (eng_ok), its sounds load as FM6 */
|
|
#define NENG_SHOWN (NENGINES - !FELUCCA_FM4 - 1) /* the engines one can pick: PRESETS, the EDIT layer, the editor,
|
|
* in the display order of engines.c ENGINE_ORDER (PHYS, 9, retired) */
|
|
#define UP_SLOTS 32u /* user presets (upreset.c) */
|
|
#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
/* ------------------------------------------------------- parameters --- */
|
|
enum {
|
|
F_INT, F_PCT, F_BIPCT, F_TIME, F_LFOHZ, F_CUTOFF, F_DB, F_SEMI, F_ENUM, F_BPM, F_NOTE,
|
|
F_ONOFF, F_OCT, F_STEPS
|
|
};
|
|
|
|
typedef struct {
|
|
const char *label;
|
|
uint8_t fmt;
|
|
int16_t min, max, def;
|
|
const char *const *names; /* F_ENUM */
|
|
const char *unit; /* F_INT / F_ENUM optional unit */
|
|
} param_desc_t;
|
|
|
|
enum { /* per-track parameters */
|
|
P_LEVEL,
|
|
P_ATK, P_DEC, P_SUS, P_REL,
|
|
P_ED_FLT, P_ED_PIT, P_ED_SHP, P_ED_FX, /* P_ED_FX: unused, kept for the formats / protocol */
|
|
P_LRATE, P_LWAVE, P_LPHASE, P_LFADE,
|
|
P_LD_PIT, P_LD_FLT, P_LD_SHP, P_LD_AMP,
|
|
P_AMODE, P_ARATE, P_AOCT, P_AGATE,
|
|
P_ASWING, P_APROB, P_AHOLD, P_AORDER,
|
|
P_ROOT, P_SCALE, P_QUANT, P_TRANS,
|
|
P_SLEN, P_SDIV, P_SSWING, P_SGATE,
|
|
P_DIST, P_CHOR, P_DLY, P_REV,
|
|
P_VOICE, P_GLIDE, P_PAN, P_MUTE,
|
|
P_GLMODE, P_PRIO, P_ALLOC, P_DETUNE,
|
|
P_SLCR, P_SLPAT, P_SLRATE, P_SLDEPTH, /* SLICER insert (slicer.c) */
|
|
P_M1SRC, P_M1DST, P_M1AMT, /* modulation matrix (mod.c): 4 slots of SRC, DST, AMT; */
|
|
P_M2SRC, P_M2DST, P_M2AMT, /* new common parameters go just before P_E0 (user presets */
|
|
P_M3SRC, P_M3DST, P_M3AMT, /* and projects map by count) */
|
|
P_M4SRC, P_M4DST, P_M4AMT,
|
|
P_FM1_ATK, P_FM1_DEC, P_FM1_SUS, P_FM1_REL, P_FM1_LEVEL,
|
|
P_FM2_ATK, P_FM2_DEC, P_FM2_SUS, P_FM2_REL, P_FM2_LEVEL,
|
|
P_FM3_ATK, P_FM3_DEC, P_FM3_SUS, P_FM3_REL, P_FM3_LEVEL,
|
|
P_FM4_ATK, P_FM4_DEC, P_FM4_SUS, P_FM4_REL, P_FM4_LEVEL,
|
|
P_SOFS, P_POFS, /* (JIANT; the former chord keys) the sequence offset: OFS steps, PIT semitones */
|
|
P_LN0, P_LN1, P_LN2, P_LN3, P_LN4, P_LN5, P_LN6, P_LN7, /* DRUM lane levels (eng_drum.c, #97): KICK .. BELL */
|
|
P_DTYPE, P_DTONE, /* (JIANT, FUNB) DIST's type and tone (fx.c track_dist) */
|
|
P_MSLEN, P_MSDIV, P_MSSLW, /* (JIANT, FUNB) the modulation sequence (mod.c MS_STEP): its length, */
|
|
P_MS0, P_MS15 = P_MS0 + 15, /* rate and slew, its 16 levels */
|
|
P_E0, P_E1, P_E2, P_E3, P_E4, P_E5, P_E6, P_E7,
|
|
P_COUNT
|
|
};
|
|
|
|
enum { /* global parameters */
|
|
G_BPM, G_SWING, G_CLOCK, G_TUNE,
|
|
G_DTIME, G_DFDBK, G_DCOLOR, G_DMIX,
|
|
G_RSIZE, G_RDAMP, G_CRATE, G_CDEPTH,
|
|
G_MIDI, G_DREL, G_ROUTE, G_INFO, /* G_DREL (JIANT): DUCK's release; was G_SYNC, a placeholder ("--", 0..0) */ /* G_ROUTE: MIDI IN, 0 CH1-4 (channels 1..4 -> parts 1..4, 5..16 ignored), 1 SEL (seq.c) */
|
|
G_SLOT, G_NAME, G_LOAD, G_SAVE,
|
|
G_ENGSEL, G_CLIP, /* no page: the editor switches the engine with a SET of G_ENGSEL. G_CLIP (JIANT):
|
|
* the master clipper; was G_ENGGO, unused (0..0) */
|
|
G_CLRSEQ, G_INITSND,
|
|
G_RTYPE, /* REVERB TYPE: 0 ROOM, 1 SPRING (fx.c). Was G_DRCH, the GM drum part's MIDI
|
|
* channel (inert since 1.0, never read); projects of formats before FUN7 load it
|
|
* as ROOM (project.c proj_rtype_room) */
|
|
G_PUNCH, G_DUCK, /* (JIANT) the drum bus's PUNCH and the kick's DUCK of the synths (fx.c, eng_drum.c).
|
|
* Were G_DRLVL / G_DRREV, inert since 1.0 (0..0): the GM drum part's level and
|
|
* reverb send, read only by the import of a project of before 1.0
|
|
* (proj_drums_to_part, which clears them after) */
|
|
G_NSTORE, /* the 27 a project's header holds (FUN7 on: their ids kept) */
|
|
G_DHPF = G_NSTORE, /* (JIANT, FUNB: after the punch-in lane, project.c) the delay's feedback low cut, */
|
|
G_WIDTH, /* the buses' stereo width (the delay's right echo later, the chorus's taps apart), */
|
|
G_RMOD, G_RRATE, /* the reverb's modulation (ROOM: its combs' lengths; SPRING: its wobble) depth, rate, */
|
|
G_RPRE, /* its pre-delay */
|
|
G_COUNT
|
|
};
|
|
#define G_SYNC G_DREL /* (the old names, for the formats' importers and their tests) */
|
|
#define G_ENGGO G_CLIP
|
|
#define G_DRLVL G_PUNCH
|
|
#define G_DRREV G_DUCK
|
|
|
|
/* stored parameters of an older layout -> today's P_* order. A store keeps np = the P_COUNT it was
|
|
* written with; common parameters are only ever added just before P_E0, so the first np - 8 are
|
|
* P_LEVEL.. in order and the last 8 are P_E0..P_E7; the parameters a store does not have take def[]
|
|
* (user presets, projects of formats 1 and 2) */
|
|
static void params_by_count(int16_t *out, const int16_t *in, uint32_t np, const int16_t *def)
|
|
{
|
|
uint32_t i, nc = np - 8u;
|
|
for (i = 0; i < P_E0; i++)
|
|
out[i] = i < nc ? in[i] : def[i];
|
|
for (i = 0; i < 8u; i++)
|
|
out[P_E0 + i] = in[nc + i];
|
|
}
|
|
|
|
/* engine indices the stores name (engines.c ENGINES[]: append-only) */
|
|
#define ENGI_PHYS 9u
|
|
#define ENGI_DRUM 10u
|
|
/* PHYS MODEL DRUM (MODEL 4, before 1.0) -> the DRUM engine, its E values in place: {MODEL, TUNE, TONE, DECY,
|
|
* SNAP, ACC, KICK, PERC} -> {MRPH 64, TUNE, TONE, DECY, NOIS 64, ACC, -, DRV 0}. 1 = it was one (its engine is
|
|
* ENGI_DRUM now); projects (project.c) and user presets (upreset.c) */
|
|
static int drum_from_phys(uint32_t engine, int16_t *e)
|
|
{
|
|
if (engine != ENGI_PHYS || e[0] != 4)
|
|
return 0;
|
|
e[0] = e[4] = 64;
|
|
e[6] = e[7] = 0;
|
|
return 1;
|
|
}
|
|
|
|
/* SAMPLE SET 4 was PERC, the GM-mapped drum kit (tools/gen_samples.py); retired after 1.0.2: its index stays
|
|
* (SET / GRAIN SRC 4 is an alias of PIANO; 5..7, once USR1..3, clamp to it). A sound that selected it is the DRUM engine with
|
|
* its default kit (eng_drum.c DRUM_PRESETS[0]: the same GM key map, so its patterns still play as drums): its E
|
|
* values become the kit's, the rest of the sound (mix, sends, matrix, ..) stays. 1 = it was one (its engine is
|
|
* ENGI_DRUM now); projects (project.c proj_perc), user presets (upreset.c up_migrate), factory preset 4 and
|
|
* favourites (ui.c, settings_persist.c). Idempotent */
|
|
#define ENGI_SAMPLE 4u
|
|
#define SMP_SET_PERC 4u
|
|
#define DRUM_KIT_E {64, 64, 70, 64, 64, 100, 0, 0} /* {MRPH, TUNE, TONE, DECY, NOIS, ACC, WARP, DRV} (eng_drum.c) */
|
|
static int drum_from_perc(uint32_t engine, int16_t *e)
|
|
{
|
|
static const int16_t KIT[8] = DRUM_KIT_E;
|
|
uint32_t i;
|
|
if (engine != ENGI_SAMPLE || e[0] != (int16_t)SMP_SET_PERC)
|
|
return 0;
|
|
for (i = 0; i < 8u; i++)
|
|
e[i] = KIT[i];
|
|
return 1;
|
|
}
|
|
|
|
/* ------------------------------------------------- voices, engines --- */
|
|
enum { V_POLY, V_MONO, V_LEGATO, V_UNISON }; /* P_VOICE */
|
|
typedef struct {
|
|
uint8_t note, vel, gate, active;
|
|
uint8_t stage; /* env: 0 off, 1 attack, 2 decay/sustain, 3 release */
|
|
int32_t env; /* Q24 */
|
|
int32_t env_out; /* last control-rate amplitude, Q15 */
|
|
int32_t pitch16, pitch_cur; /* 1/16 semitone, with glide */
|
|
int32_t gstep; /* glide TIME mode: 1/16 st per control tick, 0 = RATE mode */
|
|
int32_t fine; /* unison detune: phase increment * (1 + fine / 4096) */
|
|
uint32_t ph[3];
|
|
int32_t s[8]; /* engine state (filters, envs) */
|
|
uint32_t age;
|
|
uint8_t mvel; /* mod.c: the note-on velocity (before UNISON scaling) and RAND of the note */
|
|
int16_t mrnd;
|
|
} voice_t;
|
|
|
|
typedef struct { /* per-voice control-rate modulation, computed in voice.c */
|
|
uint32_t inc; /* phase increment of the base pitch */
|
|
int32_t pitch16;
|
|
int32_t amp0, amp1; /* Q15 ramp over the block */
|
|
int32_t cutoff; /* 0..127 << 8 */
|
|
int32_t shape; /* 0..127 << 8 */
|
|
int32_t envq15; /* env value (for engines that use it as a mod source) */
|
|
int32_t fine; /* the residual below 1/16 semitone in inc: unison detune, TUNE, bend (1/4096) */
|
|
} vmod_t;
|
|
|
|
typedef struct {
|
|
const char *name;
|
|
int8_t e[8]; /* P_E0..P_E7 (signed: an interval below the note; every value fits) */
|
|
uint8_t env[4]; /* ATK DEC SUS REL */
|
|
int8_t fenv; /* ENV -> FILTER amount (-64..63) */
|
|
uint8_t mono; /* 1 = MONO (bass / lead), 0 = POLY */
|
|
/* the rest of the patch; each value is stored + 1, 0 = the default */
|
|
uint8_t fx[4]; /* DIST, CHORUS, DELAY, REVERB sends */
|
|
uint8_t pat; /* suggested pattern (PATTERNS[pat - 1], 0 = none): only a hint. A sound load
|
|
* never touches the steps; SEQ > PATTERNS loads a pattern (ui.c pat_load). The
|
|
* arp is the track's too: a preset does not set it */
|
|
} preset_t;
|
|
#define FX(d, c, dl, r) .fx = {(d) + 1, (c) + 1, (dl) + 1, (r) + 1}
|
|
#define PAT(n) .pat = (n)
|
|
|
|
struct track;
|
|
typedef struct { /* an engine (engines.c ENGINES[]; the eng_*.c files) */
|
|
const char *name; /* "ANALOG" (PRESETS, the editor) */
|
|
const char *page_title[2]; /* EDIT 1 and EDIT 2 */
|
|
param_desc_t edit[8]; /* P_E0..P_E7 */
|
|
const preset_t *presets;
|
|
uint8_t npresets;
|
|
uint8_t knob[4]; /* HOME: the four parameters on KNOB 1..4 */
|
|
uint8_t poly; /* voice cap for POLY and UNISON, 0 = NVOICE */
|
|
uint8_t sampled; /* 1 = plays recorded material (a position, not a phase): voice.c keeps
|
|
* no phases over a retrigger, spreads none for UNISON, renders at SUS 0 */
|
|
uint8_t keep; /* bit k: s[k] is kept when a sounding voice is retriggered (filters) */
|
|
uint8_t oneshot; /* 1 = hits (DRUM): always POLY, no glide; amp ends its voices (eng_drum.c) */
|
|
void (*note_on)(struct track *t, voice_t *v);
|
|
void (*render)(struct track *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m);
|
|
/* optional (0 = none): the voice amplitude instead of the ADSR curve, once per control tick;
|
|
* gets the ADSR value (Q15, env_tick already ran: it still gates the voice), returns Q15 */
|
|
int32_t (*amp)(struct track *t, voice_t *v, int32_t adsr);
|
|
/* optional: a mode-dependent descriptor of EDIT k (the same range and default as edit[k],
|
|
* another label / value names), 0 = edit[k] */
|
|
const param_desc_t *(*desc)(const struct track *t, uint32_t k);
|
|
/* optional: once per block and part, before its voices (also with no voice sounding) */
|
|
void (*block)(struct track *t);
|
|
/* optional: the note of key k (0 = the lowest) when the engine maps the keys itself, else -1
|
|
* (then the scale keyboard of seq.c kb_map) */
|
|
int32_t (*keys)(const struct track *t, uint32_t k);
|
|
/* 1 = the engine's own envelopes are the voice's amplitude (FM6): voice.c renders it at 1.0 (no ADSR, no
|
|
* velocity; LFO -> AMP, the matrix's AMP and the fades still apply; ENV is 0) and the voice ends when
|
|
* done() says so (once per control tick, before the render), not at the end of the ADSR's release */
|
|
uint8_t ownenv;
|
|
int (*done)(struct track *t, voice_t *v);
|
|
} engine_t;
|
|
|
|
/* ------------------------------------------------- tracks, the song --- */
|
|
enum { ST_NOTE, ST_TIE, ST_REST };
|
|
#define SF_ACCENT 1u
|
|
#define SF_SLIDE 2u
|
|
#define SF_RATCH_SH 3u /* RATCH: the hits of a NOTE step - 1 (0..3: x1..x4, seq.c seq_ratchet); */
|
|
#define SF_RATCH (3u << SF_RATCH_SH) /* bits 3..4, so a user preset's pattern (flag 4 = tie) carries it too */
|
|
#define NLANE 8 /* drum lanes of a step (the DRUM engine's: eng_drum.c DRUM_LANE_NOTE) */
|
|
typedef struct { /* acid-style step: up to 4 notes (POLY), time, accent, slide; drum hits */
|
|
uint8_t note[4];
|
|
uint8_t n; /* notes in use, 0 = empty */
|
|
uint8_t time; /* ST_NOTE / ST_TIE / ST_REST */
|
|
uint8_t flags; /* SF_ACCENT | SF_SLIDE | SF_RATCH */
|
|
uint8_t vel;
|
|
uint8_t hit; /* bit l: lane l hits (its GM note, on any engine): the DRUM grid */
|
|
uint8_t acc; /* bit l: that hit is accented (velocity 127) */
|
|
uint8_t probability; /* 0 = legacy 100%; 1..100 = percent, 101 = silent */
|
|
} step_t;
|
|
typedef struct { /* a step as formats 1..4 (projects to FUN4) stored it: no hits */
|
|
uint8_t note[4];
|
|
uint8_t n, time, flags, vel;
|
|
} step8_t;
|
|
|
|
/* Probability keeps zero-initialized and legacy patterns at 100%. */
|
|
static uint32_t step_chance(const step_t *s) { return !s->probability ? 100u : s->probability <= 100u ? s->probability : 0u; }
|
|
static void step_set_chance(step_t *s, uint32_t chance) { s->probability = (uint8_t)(chance >= 100u ? 0u : chance ? chance : 101u); }
|
|
/* RATCH: a NOTE step plays its notes and hits this many times (1..4), in equal parts of the step; every older
|
|
* pattern holds 0 there, x1 */
|
|
static uint32_t step_ratchet(const step_t *s) { return ((s->flags & SF_RATCH) >> SF_RATCH_SH) + 1u; }
|
|
static void step_set_ratchet(step_t *s, uint32_t hits)
|
|
{
|
|
s->flags = (uint8_t)((s->flags & ~SF_RATCH) | ((hits < 1u ? 0u : hits > 4u ? 3u : hits - 1u) << SF_RATCH_SH));
|
|
}
|
|
#define MOTION_MAX 64u
|
|
/* Four tracks x64 steps fit one byte. Values retain their signed parameter range.
|
|
* param: the P_* id (< 128: P_COUNT is at most 127, project.c), bit 7 (MOTION_LOCK, 1.1) a parameter lock: the value
|
|
* sounds on that step only and goes back after it (motion.c motion_step); without it an automation event, the
|
|
* value holds until another one changes it. One record per (track, step, id), of either kind */
|
|
#define MOTION_LOCK 0x80u
|
|
#define MOTION_ID(e) ((uint32_t)(e)->param & 0x7Fu)
|
|
typedef struct { uint8_t place, param; int16_t value; } motion_event_t;
|
|
typedef struct { uint8_t count, on, rsv[2]; motion_event_t event[MOTION_MAX]; } motion_store_t;
|
|
_Static_assert(sizeof(motion_store_t) == 260u, "motion disk layout");
|
|
#define CHAIN_ROWS 16u
|
|
typedef struct { uint8_t slot, bars; } chain_row_t; /* a song row: section A..D (a project slot), 1..CHAIN_BARS bars */
|
|
#define CHAIN_BARS 64u
|
|
typedef struct {
|
|
uint8_t count, rsv[3];
|
|
chain_row_t row[CHAIN_ROWS];
|
|
} chain_config_t;
|
|
|
|
typedef struct track {
|
|
int16_t p[P_COUNT];
|
|
uint8_t engine, preset; /* engine: what the audio ISR renders */
|
|
uint8_t eng_req; /* engine the UI asked for (the ISR switches at a block start) */
|
|
uint8_t user; /* user preset slot + 1 the sound came from (UI), 0 = none */
|
|
voice_t v[NVOICE];
|
|
/* LFO */
|
|
uint32_t lfo_ph;
|
|
int32_t lfo_val; /* Q15 */
|
|
int32_t lfo_fade; /* Q15 ramp after note-on */
|
|
uint32_t lfo_rnd;
|
|
/* keyboard / arp input: held notes in press order */
|
|
uint8_t held[16];
|
|
uint8_t nheld;
|
|
uint8_t arp_phys; /* keys physically held for the arp */
|
|
uint8_t latched; /* HOLD: keep notes after release */
|
|
/* arp runtime */
|
|
uint32_t arp_pos; /* q8 samples into the current arp step */
|
|
uint32_t arp_idx;
|
|
uint8_t arp_note; /* sounding arp note, 0 = none */
|
|
uint8_t arp_walk; /* WALK: the place in the note list it stands on */
|
|
uint8_t arp_ch[3]; /* CHORD: the other notes sounding with arp_note, 0 = none */
|
|
uint32_t arp_off; /* q8 sample time of its note-off */
|
|
/* sequencer */
|
|
step_t step[NSTEP];
|
|
uint32_t seq_pos; /* q8 samples into the current step */
|
|
uint16_t seq_idx;
|
|
uint8_t seq_notes[4 + NLANE]; /* sounding seq notes (the step's notes, then its hits) */
|
|
uint8_t seq_n;
|
|
uint8_t seq_hold; /* last step slides: keep the notes until the next step */
|
|
uint8_t slide_glide; /* next legato note glides (slide) */
|
|
uint8_t rat_left; /* RATCH: repeats of the playing step still to come (seq.c seq_ratchet) */
|
|
uint32_t seq_off;
|
|
uint8_t seq_active; /* any step programmed */
|
|
uint8_t rskip_idx; /* live recording put notes into the step about to play: */
|
|
uint8_t rskip_n, rskip[NLANE]; /* do not trigger them again there (they sound already) */
|
|
/* live recording of held notes (seq.c rec_hold): the steps they are held into become TIEs */
|
|
uint8_t rh_n, rh_note[4]; /* recorded notes still held, 0 = none */
|
|
uint8_t rh_start; /* the step they were recorded into */
|
|
uint8_t rh_ties; /* TIE steps written after it */
|
|
uint8_t rh_last; /* the last of them; rh_bak: what it held (an early release puts it back) */
|
|
step_t rh_bak;
|
|
/* mono */
|
|
uint8_t mono_stack[8];
|
|
uint8_t nmono;
|
|
uint8_t mono_note; /* note the MONO / LEGATO / UNISON voice(s) play, 0 = none */
|
|
uint8_t rr; /* POLY ROTATE: next voice to try */
|
|
/* mix runtime */
|
|
int32_t peak;
|
|
int32_t dist_hp, dist_lp1, dist_lp2; /* DIST insert state (fx.c) */
|
|
int32_t dist_dc, dist_hold; /* (JIANT) RECT's DC; CRUSH's held sample */
|
|
uint8_t dist_hc; /* .. CRUSH's hold count */
|
|
int32_t ms_v; /* (JIANT) the modulation sequence's level now (mod.c MS_STEP, Q15, slewed) */
|
|
uint8_t tail; /* blocks to mix after the last voice (the DIST tail) */
|
|
int16_t armp, aholdp; /* P_AMODE / P_AHOLD as last seen by the ISR */
|
|
/* engine switch (voice.c engine_block): the old engine's voices fade out, then it switches */
|
|
uint8_t xf_on, xf; /* fading; blocks of the fade still to render */
|
|
int16_t pe_old[8]; /* P_E0..P_E7 of the sounding engine: the fade renders with these */
|
|
uint8_t xp_n, xp_note[4], xp_vel[4]; /* note-ons during the fade, played on the new engine */
|
|
/* modulation matrix (mod.c): MIDI performance controllers of the track's channel, 0..127 */
|
|
uint8_t mw, at; /* CC1 mod wheel, channel aftertouch */
|
|
uint8_t ex_off; /* 127 - CC11 expression (0: full, the MIDI default) */
|
|
uint8_t m_vel, m_key, m_vi; /* the latest note-on: velocity, note, voice index (per-block destinations) */
|
|
int16_t m_rnd; /* .. its RAND */
|
|
int32_t m_env; /* the amp envelope of voice m_vi, last block (Q15) */
|
|
/* the punch-in MIDI effects (pfx.c), the ISR's: what acts on this track this block, never saved */
|
|
int8_t trn; /* ARP TRNS (seq.c): the semitones the keys set (from C4), on the steps' notes */
|
|
uint8_t pfx; /* PFX_* */
|
|
int16_t pfx_pit; /* OCT- / OCT+: 1/16 semitones on every voice */
|
|
int16_t pfx_rpit; /* RANDOM: the next note's offset (1/16 semitones), drawn by trk_note_on */
|
|
uint8_t pfx_half; /* 1/2 TEMPO: the odd sample carried; pfx_rs: let go, back to the real place */
|
|
uint8_t pfx_rs;
|
|
uint16_t pfx_idx0; /* .. where it was pressed (step, samples into it) and the samples since */
|
|
uint32_t pfx_pos0, pfx_el;
|
|
uint8_t pfx_ln[4], pfx_lv[4], pfx_lnn; /* the last notes struck together (a step's), STUTTER / ARP repeat them */
|
|
uint32_t pfx_lblk; /* .. the block they were struck in */
|
|
uint8_t pfx_sn[4], pfx_snn; /* the notes a repeat holds now */
|
|
uint8_t pfx_si; /* ARP: the next of them */
|
|
uint32_t pfx_sc; /* samples since the last repeat */
|
|
} track_t;
|
|
enum { PFX_RND = 1, PFX_HALF = 2, PFX_REP = 4, PFX_DEC = 8 }; /* (track_t.pfx) */
|
|
|
|
typedef struct {
|
|
int16_t g[G_COUNT];
|
|
uint8_t playing, seq_mode;
|
|
uint8_t grid; /* 1: the keys are the DRUM grid (ui.c grid_on): only the lane keys play (seq.c);
|
|
* 2: NAME (ui_name.c): no key plays */
|
|
uint8_t rec; /* live recording armed: bit per track */
|
|
uint8_t sel; /* selected track 0..NTRK-1: keys, pages, editor */
|
|
int8_t octave;
|
|
uint32_t tick; /* sub-blocks since play */
|
|
uint32_t cpu_q8; /* audio ISR load, 1/256 */
|
|
uint32_t master_q12;
|
|
int32_t batt_raw; /* smoothed ADC ch3 (battery divider), 0 = not read yet */
|
|
} song_t;
|
|
|
|
static track_t trk[NTRK]; /* the instrument: four parts */
|
|
static song_t song;
|
|
#define TSEL (&trk[song.sel]) /* the selected track */
|
|
|
|
/* SWING of a track's step clock: the track's own plus the global one, at most 100 (#31). The sequencer
|
|
* (seq.c step_samples) and the SLICER (slicer.c sl_enter) both time steps with it. At 100 the even
|
|
* steps are 1.4 x the straight length and the odd ones 0.6 x. */
|
|
#define SWING_MAX 100
|
|
static inline int32_t track_swing(const track_t *t)
|
|
{
|
|
int32_t sw = t->p[P_SSWING] + song.g[G_SWING];
|
|
return sw < 0 ? 0 : sw > SWING_MAX ? SWING_MAX : sw;
|
|
}
|
|
/* the length of step idx of a straight length `base`, swung: even steps longer, odd ones shorter */
|
|
static inline uint32_t swing_step_len(const track_t *t, uint32_t base, uint32_t idx)
|
|
{
|
|
int32_t sw = track_swing(t) * (int32_t)base / 250;
|
|
return base + (uint32_t)((idx & 1u) ? -sw : sw);
|
|
}
|
|
|
|
/* ----------------------------------------------------------- system --- */
|
|
#define RING_PUBLISH() __asm__ volatile("" ::: "memory") /* slot store before the index update */
|
|
static volatile uint32_t fm1_ms; /* milliseconds since boot (TIMER4-based, TIMER5 ISR in main.c) */
|
|
/* boot-loop guard (main.c): two boots in a row that die in the first 30 s -> UBOOT */
|
|
#define BOOTGUARD_MAGIC 0x42475244u
|
|
struct { uint32_t magic, failed, pending; } bootguard __attribute__((section(".noinit")));
|