Files
JIANT/firmware/src/ui_layer.c
T

1694 lines
85 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
* Portions Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* Felucca quick layers: while a page button is held, the keys and KNOB 1..4
* are its shortcuts and its map shows over the page. One table (LAYERS) drives the gesture, the keys, the knobs,
* the LEDs and the overlay:
* FX HOLD the performance effects (perform.c) and the track mutes while held; KNOB 1..4 its macros
* GLO SET black keys 1..4 (F#3 G#3 A#3 C#4) T1..T4 MUTE (latched; lit = sounding), F3..B3 SOLO T1..T4 while
* held (HOLD cells, a corner triangle), C4 UNMUTE ALL, F4 TAP tempo; KNOB 1..4 T1..T4 LEVEL;
* black keys 5..8 (D#4 F#4 G#4 A#4) the DRUM group mutes KICK SNARE HAT PERC (eng_drum.c dx_mute; the
* row shows while a track plays DRUM; C4 unmutes them too);
* GLO + PLAY: from the top without stopping
* SCL SET any key: its note name is ROOT; KNOB 1..4 ROOT SCL CHRD VOIC (LY_SCL: the SCL page's first two,
* the CHORD page's two; QNT TRN stay on SCL); the LEDs show the root lit and the scale's notes breathing
* EDIT SET (JIANT: Felucca's engine keys are gone, PRESETS picks engines and sounds) F3 INIT: the track's sound
* to its engine's first preset, a DRUM track's DRUM-X kit to the factory one; G3 RECALL: the track's
* sound (and a DRUM track's kit) as the section playing stored it, the safe state (project.c
* project_recall_sound). Each asks first (the dialog closes the layer); the steps stay. KNOB 1..4 the
* EDIT page's four (the engine's first); on a DRUM track black keys 1..8 mute each DRUM-X sound
* (eng_drum.c DXM_LANE, saved with the section; lit = sounding)
* SEQ SET (1.2, on the SEQ pages that show the pattern; 0.8.3: every page of LENTE's three levels, not PHRASES and
* SONG; elsewhere SEQ held is a tap) TOOLS: the white keys from F3 the sequence tools (ui_tools.c: CLEAR,
* REVERSE, SHIFT < >, RANDOM, COOK, CLR AUTO (0.6.8: the track's automation); on a DRUM track BEAT and the lane's CLEAR REVERSE FILL RANDOM), black
* keys 1..8 the lane (DRUM); KNOB 1..4 the PATTERN page's LEN DIV SWING GATE. No undo (TONIC: the song
* layer's RECALL)
* REC SET (1.1.5, on every page; REC's tap still arms / disarms) the white keys from F3: CLEAR (the selected
* track's steps and automation, no dialog), CLICK (OFF REC ON, each press the next value); KNOB 1 the
* same (TONIC: COUNT-IN and CLICK LEVEL only in MENU > AUDIO). The settings
* are MENU > AUDIO's (ui.c rp_get / rp_put: one store), saved when the layer closes.
* Replaces the old REC held on SEQ (Discussion #91:
* the CLEAR Tn SEQUENCE? dialog and its "HOLD: CLEAR" hint)
* The gesture: let go before HOLD (the menu: 0.3 .. 0.6 s) with nothing else touched: a tap, the button's page.
* Held past HOLD alone: the map (a peek), letting go does nothing. A key, a knob or a button meanwhile: a combo,
* the map at once, no tap. Keys pressed with the button down are the layer's (seq.c keyboard_block): silent, no
* MIDI, never recorded; keys held before stay notes. Only one layer at a time: a second layer button is ignored.
* PLAY and REC work in every layer (GLO + PLAY: RESTART); SAVE, HOME, SEQ and the other page buttons are swallowed. In SET
* layers OCT± do not shift the octave (TONIC: OCT- no longer puts back what the layer changed: no undo). A HOLD key's effect lasts until the key is let go, the map with it. No layer in the menu, a dialog,
* NAME or the UPDATE MODE countdown. A tap says nothing of the layer (0.9.5: the "HOLD [GLO] QUICK" hint is gone).
* TONIC: no lock (Felucca's double tap, Discussion #83, is gone): a layer is open while its button is held. */
#include "ui_tools.c" /* SEQ TOOLS' actions */
/* the song layer's actions (project.c: song_main.c) */
static int section_jump(uint32_t s);
static void section_store(uint32_t s);
static void section_ask(uint32_t s);
static void section_recall(void);
static void quick_chain(const uint8_t *s, uint32_t n);
static void song_rec_toggle(void);
static int song_select(uint32_t n);
static int project_used(uint32_t slot);
enum { LK_HOLD, LK_SET };
typedef struct {
uint8_t btn, kind, fam; /* the button, HOLD / SET, the family whose first page KNOB 1..4 edit */
const char *head; /* (FAM_HOME: the layer's own knobs) the header over the map */
khint_t foot[3]; /* the footer's key hints (a third with no word: none) */
} layer_t;
static const layer_t LAYERS[LAYER_N] = {
{0, 0, 0, "", {{0, 0}, {0, 0}, {0, 0}}},
{B_FX, LK_HOLD, FAM_HOME, "[FX] HOLD", {{KC_KEYS, "EFFECTS"}, {KC_K14, "MACROS"}, {0, 0}}}, /* (V10.7.66: the editor is FX > PUNCH IN's OCT+) */ /* (LET GO: the header's HOLD; V10.7.65: OCT+ the editor, was DICE) */
{B_GLO, LK_SET, FAM_HOME, "[GLO] SET", {{KC_PLAY, "RESTART"}, {KC_GLO, "DONE"}, {KC_KEYS, "G4 UNDO"}}}, /* (V10.7.66:
* UNDO said where it is) */
{B_SCL, LK_SET, FAM_SCL, "[SCL] SET", {{KC_KEYS, "ROOT"}, {KC_SCL, "DONE"}, {0, 0}}},
{B_EDIT, LK_SET, FAM_EDIT, "[EDIT] SET", {{KC_SELECT, "DICE"}, {KC_K14, "TWEAK"}, {KC_KEYS, "INIT / RECALL"}}}, /* (0.9.9-seq2e:
* KNOB 1..4 MOMENTARY: mom_knob; seq2f: SELECT the sound dice) */
{B_SEQ, LK_SET, FAM_SEQ, "[SEQ] EDIT", {{KC_OCTUP, "DO IT"}, {KC_OCTDN, "ALL STEPS"}, {KC_KEYS, "F#5 UNDO"}}}, /* (0.6.14: REC, all six
* tracks cleared, shown: it was nowhere) */
{B_REC, LK_SET, FAM_HOME, "[REC] SET", {{KC_KEYS, "RECORDING"}, {KC_REC, "DONE"}, {0, 0}}},
{B_SAVE, LK_SET, FAM_HOME, "[SAVE] SONG", {{KC_KEYS, "PLAY"}, {KC_OCTUP, "SAVE"}, {KC_OCTDN, "RECALL"}}},
{B_LFO, LK_SET, FAM_HOME, "[LFO] MACRO", {{KC_K14, "M1-M4"}, {KC_SELECT, "DICE"}, {KC_KEYS, "DICE / CLEAR"}}}, /* JIANT (mod.c macro_v; SELECT, F3: macro_dice, G3 clears) */
};
/* SCL's knobs: the key and the sequence offset (cur_page() while the layer edits or draws them: page_over) */
static const page_t LY_SCL = {"SCL", FAM_SCL, SC_TRACK, GR_SCALE, {P_ROOT, P_SCALE, P_SOFS, P_POFS}};
/* SEQ TOOLS' knobs: the PATTERN page's (the length the tools work in) */
static const page_t LY_SEQ = {"PATTERN", FAM_SEQ, SC_TRACK, GR_STEPS, {P_SLEN, P_SDIV, P_SSWING, P_SGATE}};
static const page_t *ly_page(uint32_t l) { return l == LAYER_SCL ? &LY_SCL : l == LAYER_SEQ ? &LY_SEQ : 0; }
#define LY_OPEN 2u /* ui.ly_t0: the map opened (no tap any more) */
#define LY_COMBO 4u /* .. by a combo */
#define LY_DEAD 8u /* .. pressed where there is no layer: does nothing */
enum { LY_INIT, LY_RECALL }; /* EDIT: the white keys F3 G3 */
static const khint_t FX_LATCH_FOOT[3] = {{KC_KEYS, "ON / OFF"}, {KC_K14, "MACROS"}, {KC_OCTDN, "ALL OFF"}};
static const khint_t MAC_LATCH_FOOT[3] = {{KC_K14, "M1-M4"}, {KC_SELECT, "DICE"}, {KC_LFO, "DONE"}}; /* (MACRO latched) */
static struct {
uint8_t l, oct; /* the layer open; OCT- / OCT+ pressed in a SET layer (bits) */
uint8_t cook; /* SEQ: COOK pressed since it opened */
uint8_t qc[8], nqc; /* SAVE: the sections tapped in this hold (two or more: a quick chain) */
uint8_t song; /* SAVE: the song KNOB 1 picked (+ 1; 0 none): in when SAVE lets go */
uint8_t rp_dirty; /* REC: a setting changed (settings_save when the layer lets go) */
uint32_t solo; /* GLO: the keys held that solo */
uint32_t tap[4]; /* GLO TAP: the last taps (fm1_ms) */
uint8_t ntap;
uint8_t quiet; /* #39: a layer closed after it opened: KNOB 1..4 do nothing until quiet_t + */
uint32_t quiet_t; /* LY_QUIET_MS (fm1_ms) */
uint8_t used; /* (0.6.44) a key, a knob or OCT used in the layer since it was armed */
} lys;
#define LY_QUIET_MS 250u
/* (0.6.44) FX LATCH: FX held open and let go locks its layer open, as the macros latch: its keys, knobs and map stay
* until FX is pressed again (or another layer is held over it, for as long as it is) */
static uint8_t fx_lock;
static int layer_allowed(void) { return !ui.menu && !dlg_on() && !ui.uboot && !name_on(); } /* (GEN: a page) */
static uint32_t ly_bit(uint32_t l) { return 1u << panel.btn[LAYERS[l].btn]; }
/* SEQ's layer is there on the SEQ pages only (elsewhere SEQ held is a tap: ui_input) */
static int tools_page(void)
{
const page_t *pg = &PAGES[ui.page];
return !ui.home && pg->fam == FAM_SEQ && 1 && pg->graph != GR_SONG; /* (0.8.3: every level
* of LENTE's, STRETCH PLAYHEADS MUTATE AUTO LIST too) */
}
static int ly_avail(uint32_t l) { return l != LAYER_MACRO && (l != LAYER_SEQ || tools_page()); } /* (REC: on every page;
* V10.7.66, the owner: the macros FX > PUNCH IN's only, LFO's
* layer gone) */
static uint32_t ly_down(uint32_t l) { return l && (fm1_in.buttons & ly_bit(l)) != 0u; }
static uint32_t layer_bits(void)
{
uint32_t l, m = 0;
for (l = LAYER_FX; l < LAYER_N; l++)
m |= ly_avail(l) ? ly_bit(l) : 0u;
return m;
}
static uint32_t layer_btn(void) { return LAYERS[ui.layer % LAYER_N].btn; }
static uint32_t layer_open(void);
static const char *layer_head(void) /* FX: LATCH, and the MIDI effects' tracks (A#4) */
{
static const char H[] = "[FX] HOLD\0" "[FX] LATCH\0" "[FX] LOCKED"; /* (V10.7.59: every track, no SYN DRM; V10.8.78:
* one per state, packed) */
return ui.layer == LAYER_FX ? str_nth(H, fx_lock && !ui.ly ? 2u : perf_latch_on ? 1u : 0u) : LAYERS[ui.layer % LAYER_N].head;
}
static uint32_t layer_open(void)
{
if (ui.ly && (ui.ly_t0 & LY_OPEN) && ly_down(ui.ly) && layer_allowed())
return ui.ly;
return fx_lock && !ui.ly && layer_allowed() ? LAYER_FX : 0u;
}
static int layer_set_open(void) /* (FX LATCH: FX is one too, OCT- turns all off) */
{
return layer_open() && (LAYERS[layer_open()].kind == LK_SET || (layer_open() == LAYER_FX && perf_latch_on));
}
static uint32_t layer_held(void) { return ui.ly && ly_down(ui.ly) && layer_allowed(); }
/* each pass, before the keys: what the ISR (seq.c keyboard_block) gives to a layer. Armed: its button; none
* armed: any layer button not already down (one pressed meanwhile is armed below; one held over from before
* is ignored, its keys stay notes); armed but dead (pressed under a dialog, a menu or NAME that has closed
* since): nothing, its keys stay notes and FX starts no effect with no map shown; FX's effects only with FX */
#define PK_MAGIC 0x504B4555u
static void pk_load(void);
static void pk_mod(void);
static void pk_mod_bt(void);
static void pk_name(uint32_t e, uint32_t o, char *nm);
#define PK_DST(o) (((o) & 15u) | ((o) >> 7) << 4) /* a PARAM key's destination from its options */
#define PK_SHP(e, o) ((((o) >> 4) & 7u) | ((e) >> 5 & 1u) << 3) /* .. its HOW (0..11: e's bit 5 the fourth bit) */
static void layer_masks(void)
{
uint32_t m = !layer_allowed() || (ui.ly && (ui.ly_t0 & LY_DEAD)) ? 0u
: ui.ly ? ly_bit(ui.ly) : layer_bits() & ~fm1_in.buttons;
kb_mask = m;
perf_mask = m & ly_bit(LAYER_FX);
if (pk.magic != PK_MAGIC) /* (V10.7.65) the punch-in keys: the slot played (once) */
pk_load();
pk_mod(); /* .. a MOD key's macro moving */
fx_lock_on = (uint8_t)(fx_lock && !ui.ly && layer_allowed());
}
/* a layer button pressed (its edge) while none is armed: it is now, a dead one where no layer opens */
static void layer_arm(uint32_t pressed, uint32_t now)
{
uint32_t l;
if (ui.ly == LAYER_REC && (pressed & ~ly_bit(LAYER_REC)))
lys.used = 1; /* (V10.7) REC held and another button: no UNDO at its let go */
if (ui.ly)
return;
if (fx_lock && (pressed & ly_bit(LAYER_FX))) { /* (0.6.44) FX pressed again: the lock off, nothing else */
fx_lock = 0;
ui.force = 1;
ui.ly = LAYER_FX;
ui.ly_t0 = (now & ~15u) | 1u | LY_DEAD;
ui_message("FX UNLOCKED");
return;
}
if (mac_latch && (pressed & ly_bit(LAYER_MACRO))) { /* (JIANT 0.4) LFO pressed again: the latch off, nothing else */
ui.force = 1;
ui.ly = LAYER_MACRO;
ui.ly_t0 = (now & ~15u) | 1u | LY_DEAD;
return;
}
for (l = LAYER_FX; l < LAYER_N; l++)
if ((pressed & ly_bit(l)) && ly_avail(l)) {
lys.used = 0;
ui.ly = (uint8_t)l;
ui.ly_t0 = (now & ~15u) | 1u | (layer_allowed() ? 0u : LY_DEAD);
return;
}
}
/* (0.9.9-seq2e) MOMENTARY, the owner's three EDIT gestures: a tap, EDIT's pages; held, its layer; held and KNOB 1..4
* turned (before the layer shows or after), the knob edits the page under it (the page shown before EDIT went down),
* live, recorded nowhere (no motion), and EDIT let go every parameter touched in the hold glides back over MOM_GLIDE_MS
* to its value when first touched (motion.c mom[]: up to MOM_N); a save meanwhile stores those values. The page under
* shows, "MOMENTARY" in the header; no tap, no layer after it. SELECT is the sound dice (0.9.9-seq2f; CF_DICE_SOUND) */
#define MOM_GLIDE_MS 32u
static void mom_release(void);
static int16_t *mom_ptr(const mom_t *m) { return m->t == MOM_G ? &song.g[m->id] : &trk[m->t % NTRK].p[m->id]; }
static void mom_finish(void) /* every value back, now */
{
uint32_t i;
for (i = 0; i < mom_n; i++)
*mom_ptr(&mom[i]) = mom[i].v;
mom_n = 0;
mom_glide = 0;
}
static void mom_forget(uint32_t t) /* track t's sound replaced (EDIT + SELECT's dice): its own kept */
{
uint32_t i, n = 0;
for (i = 0; i < mom_n; i++)
if (mom[i].t != t)
mom[n++] = mom[i];
mom_n = (uint8_t)n;
}
/* the knob k's value on the page under, if a plain parameter (a track's or a song global; not a list, an action, a step,
* the kit, an operator: those are not momentary) */
static __attribute__((noinline)) int16_t *mom_vp(uint32_t k, const param_desc_t **d)
{
const page_t *pg = cur_page();
int16_t *vp = 0;
uint32_t i, g = pg->graph;
*d = 0;
if (ui.menu || ui.confirm || gen_on() || mac_latch || lock_held())
return 0;
if (ui.home) {
if (home_macros())
return 0;
*d = home_param(k, &vp);
} else {
if (FIT_PAGE(pg) || pg->scope == SC_STEP || pg->scope == SC_TRK || ((act_cols() >> k) & 1u) || g == GR_COMP ||
g == GR_FUGUE || g == GR_DXSND || g == GR_SWARM || g == GR_FOCUS ||
g == GR_EVENTS || g == GR_MOTION || g == GR_SONG || g == GR_BROWSE || g == GR_TOOLS || g == GR_SLOTS ||
g == GR_USER || 0 /* PHRASES gone */ || DX_KIT3(pg) || fop_page(g) ||
(k == 0u && (BAR_PAGE(pg) || g == GR_SLPIT || g == GR_MSEQ || g == GR_MOD)))
return 0;
*d = page_desc(pg, k, &vp);
}
if (!*d || !vp || (*d)->max == (*d)->min)
return 0;
for (i = 0; i < NTRK; i++)
if (vp >= trk[i].p && vp < trk[i].p + P_COUNT)
return vp;
return vp >= song.g && vp < song.g + G_COUNT && vp != &song.g[G_SLOT] && vp != &song.g[G_LOAD] &&
vp != &song.g[G_SAVE] ? vp : 0;
}
static int mom_keep(uint32_t t, uint32_t id) /* (t, id) kept as it is now, once a hold; 0: no room */
{
uint32_t i;
for (i = 0; i < mom_n; i++)
if (mom[i].t == t && mom[i].id == id)
return 1;
if (mom_n >= MOM_N)
return 0;
mom[i].t = (uint8_t)t;
mom[i].id = (uint8_t)id;
mom[i].v = t == MOM_G ? song.g[id] : trk[t % NTRK].p[id];
mom_n++;
return 1;
}
static __attribute__((noinline)) void mom_knob(uint32_t k, int32_t s)
{
const param_desc_t *d;
int16_t *vp;
uint32_t t, id;
if (!mom_on) { /* the hold becomes MOMENTARY: no layer, no tap */
mom_finish(); /* (a glide still going: there now) */
mom_on = 1;
ui.ly_t0 = (ui.ly_t0 & ~LY_OPEN) | LY_DEAD;
ui_message("MOMENTARY");
ui.force = 1;
}
ui.hot_col = (uint8_t)k;
ui.hot_t = 40, ui.knob_ms = fm1_ms;
if ((vp = mom_vp(k, &d)) == 0) {
ui_message("NOT MOMENTARY HERE");
return;
}
for (t = 0; t < NTRK && !(vp >= trk[t].p && vp < trk[t].p + P_COUNT); t++)
;
id = t < NTRK ? (uint32_t)(vp - trk[t].p) : (uint32_t)(vp - song.g);
if (t >= NTRK)
t = MOM_G;
if (t == MOM_G && id == G_RTYPE && mom_n + 3u > MOM_N) {
ui_message("16 AT MOST");
return;
}
if (t == MOM_G && id == G_RTYPE) { /* (REVERB TYPE: PRE and DAMP change with it, ui_input.c) */
(void)mom_keep(MOM_G, G_RPRE);
(void)mom_keep(MOM_G, G_RDAMP);
}
if (!mom_keep(t, id)) {
ui_message("16 AT MOST");
return;
}
if (ui.home)
*vp = (int16_t)param_turn(d, *vp, accel(EN_K1 + k, s, d->fmt == F_ENUM ? 0 : d->max - d->min));
else
edit_param(k, s);
}
static void mom_release(void) /* EDIT let go: the glide back begins (a list's value: at once) */
{
uint32_t i;
mom_on = 0;
for (i = 0; i < mom_n; i++)
mom[i].from = *mom_ptr(&mom[i]);
mom_glide = mom_n != 0u;
mom_t0 = fm1_ms;
if (ui.msg_t && str_eq(ui.msg, "MOMENTARY"))
ui.msg_t = 0;
ui.force = 1;
mom_poll();
}
static void mom_poll(void) /* every pass */
{
uint32_t i, dt;
if (mom_on) {
if (ui.msg_t < 8u) /* the header's tag, as long as it lasts */
ui_message("MOMENTARY");
return;
}
if (!mom_glide)
return;
if ((dt = fm1_ms - mom_t0) >= MOM_GLIDE_MS) {
mom_finish();
return;
}
for (i = 0; i < mom_n; i++) {
const mom_t *m = &mom[i];
const param_desc_t *d = m->t == MOM_G ? &GP[m->id] : track_desc(&trk[m->t % NTRK], m->id);
*mom_ptr(m) = d->fmt == F_ENUM ? m->v :
(int16_t)(m->from + ((int32_t)m->v - m->from) * (int32_t)dt / (int32_t)MOM_GLIDE_MS);
}
}
static void undo_ui(void);
/* the armed layer lets go (its button up): FX's macros snap back (FX LATCH: they stay); one that
* opened, or a combo: KNOB 1..4 quiet for a while (#39: the knob still turning is not the page's) */
/* (V10.7.59, the owner) the FX layer's KNOB 1..4 are the MACROS (M1..M4, their routes on LFO > MACROS): turned with FX
* held, from what they were; FX let go, back there (FX LATCH: they stay, OCT- ALL OFF puts them back) */
static uint8_t fx_mb[4], fx_mon;
static void fx_macro_turn(uint32_t k, int32_t s)
{
if (!fx_mon) {
memcpy(fx_mb, macro_v, sizeof fx_mb);
fx_mon = 1;
}
macro_v[k & 3u] = (uint8_t)clamp(macro_v[k & 3u] + accel(EN_K1 + k, s, 127), 0, 127);
}
static void fx_macro_back(void)
{
if (fx_mon) {
memcpy(macro_v, fx_mb, sizeof fx_mb);
fx_mon = 0;
}
}
static __attribute__((noinline)) void layer_let_go(uint32_t quiet)
{
if (ui.ly == LAYER_SAVE && lys.nqc >= 2u) /* SAVE: two or more sections tapped: a quick chain */
quick_chain(lys.qc, lys.nqc);
if (ui.ly == LAYER_SAVE && lys.song && lys.song - 1u != song_cur) /* SAVE: KNOB 1 picked another song */
(void)song_select(lys.song - 1u);
lys.nqc = 0;
lys.song = 0;
if (ui.ly == LAYER_FX && !perf_latch_on) {
perf_k[0] = perf_k[1] = perf_k[2] = perf_k[3] = 0;
fx_macro_back();
}
if (ui.ly == LAYER_FX && (ui.ly_t0 & LY_OPEN) && !(ui.ly_t0 & (LY_DEAD | LY_COMBO)) &&
!lys.used && !kb_layer && layer_allowed()) {
fx_lock = 1; /* (0.6.44) held open, nothing used, let go: locked open;
* (0.6.64) whatever FX LATCH (the effects' own: momentary by
* default) */
ui_message("FX LOCKED: [FX] TO UNLOCK");
quiet = 0;
ui.force = 1;
}
if (ui.ly == LAYER_REC && (ui.ly_t0 & LY_OPEN) && !(ui.ly_t0 & (LY_DEAD | LY_COMBO)) && !lys.used &&
layer_allowed()) { /* (V10.7) REC held alone and let go: UNDO (again: REDO) */
undo_ui();
quiet = 0;
}
if (ui.ly == LAYER_EDIT && mom_on) /* (0.9.9-seq2e) MOMENTARY: what was touched glides back */
mom_release();
if (lys.rp_dirty) { /* REC: its settings kept, as MENU does when it closes */
lys.rp_dirty = 0;
settings_save(); /* (deferred while playing) */
}
if (quiet) {
lys.quiet = 1;
lys.quiet_t = fm1_ms;
}
ui.ly_t0 = 0;
ui.ly = 0;
}
/* the layer opened */
static void layer_opened(uint32_t l)
{
lys.l = (uint8_t)l;
lys.nqc = 0;
lys.song = 0;
}
/* the armed button: 0, or the layer whose button was tapped (let go) */
static uint32_t layer_gesture(uint32_t now, uint32_t combo)
{
uint32_t *t0 = &ui.ly_t0, l = ui.ly;
if (!l)
return 0;
if (!layer_allowed())
*t0 |= LY_DEAD;
if (ly_down(l)) {
if (!(*t0 & (LY_OPEN | LY_DEAD)) &&
(combo || now - (*t0 & ~15u) >= (uint32_t)HOLD_MS[settings_hold % 4u] * 1000u * FM1_TICKS_PER_US)) {
*t0 |= LY_OPEN | (combo ? LY_COMBO : 0u);
layer_opened(l);
}
return 0;
}
l = *t0 & (LY_OPEN | LY_DEAD) || combo ? 0u : l; /* (a knob turned as it was let go: a combo, no tap) */
layer_let_go(*t0 & LY_OPEN || combo || mom_on); /* (MOMENTARY: its knobs quiet too) */
return l;
}
/* #39: KNOB 1..4 belong to no page while a layer lets go: the frame its button is let go (the turns read then
* were made with it held), while its map still shows (its keys held after it), and LY_QUIET_MS after it closed.
* Their turns are dropped there (ui_input); before, they edited the page under the layer (an ARP page: ARP on) */
static int layer_knobs_quiet(void)
{
if (lys.quiet && fm1_ms - lys.quiet_t >= LY_QUIET_MS)
lys.quiet = 0;
return layer_allowed() && (ui.ly || ui.layer || lys.quiet);
}
/* the map shows while the button is held open, and after it while its keys are still held */
static void layer_show(void)
{
uint32_t show = layer_allowed() ? (layer_open() ? layer_open() : kb_layer ? ui.layer : 0u) : 0u;
if (show != ui.layer) {
ui.layer = (uint8_t)show;
ui.force = 1;
}
}
/* a tap: the button's page (0.9.5: no "HOLD [X] QUICK" hint any more: the layers show themselves when held) */
static void layer_tap(uint32_t l)
{
if (l == LAYER_REC) /* REC: arms / disarms (no page) */
(void)rec_tap();
else if (l == LAYER_SAVE) { /* GEN's SAVE keeps the whole song (or its loop: NAME's KNOB 3). */
if (gen_on()) { /* (PROJECTS, its SAVE armed: OCT+ saves; the SAVE SONG AS page,
* until V10.7.19) */
if (nav_put(SEC_SAVE, "PROJECTS"))
ui.act = 4u;
} else open_family(FAM_SAVE);
}
else
(void)page_tap(LAYERS[l].btn);
}
static uint32_t snd_id(void) { return TSEL->eng_req | (uint32_t)TSEL->preset << 8 | (uint32_t)TSEL->user << 16; }
/* EDIT RECALL: the section playing has a stored sound to come back to */
static int edit_recallable(void) { return project_recall_slot() >= 0; }
/* GLO TAP: from the third tap the tempo of the taps (the last 4); 2 s without one starts over. INT clock only */
static void glo_tap(void)
{
uint32_t n = lys.ntap, i;
if (song.g[G_CLOCK]) {
ui_message("TAP: CLK IS EXT");
return;
}
if (n && fm1_ms - lys.tap[n - 1u] > 2000u)
n = 0;
if (n == 4u) {
for (i = 0; i < 3u; i++)
lys.tap[i] = lys.tap[i + 1u];
n = 3;
}
lys.tap[n++] = fm1_ms;
lys.ntap = (uint8_t)n;
if (n >= 3u && lys.tap[n - 1u] != lys.tap[0]) {
song.g[G_BPM] = (int16_t)clamp((int32_t)(60000u * (n - 1u) / (lys.tap[n - 1u] - lys.tap[0])),
GP[G_BPM].min, GP[G_BPM].max);
ui.bpm_t = 40;
}
}
/* (V10.8.52) SEQ EDIT's white keys (ui_tools.c): F3 CLEAR, G3 ALL (no selection), A3 KNOB 1 / 2 START END <-> MOVE
* WIDTH, B3 .. E4 BAR 1 .. 4 selected, F4 CLR AUTO, G4 .. B4 the lane's (DRUM), C5 DUP, D5 the ACTION, E5 COPY, F5
* PASTE, G5 CLR STEP; black: the lanes (DRUM), C#5 / D#5 NUDGE < / > (ui_tools.c se_do: the steps selected or all) */
static void tools_key(uint32_t p)
{
uint32_t len = tl_len(TSEL), a = p == 0u ? SE_CLEAR : p == 7u ? SE_CAUTO : p == 11u ? SE_DUP : p == 13u ? SE_COPY :
p == 14u ? SE_PASTE : p == 15u ? SE_CSTEP : SE_N;
if (a < SE_N) se_do(a, 0);
else if (p == 1u) { cp_sel = 0; ui_message("ALL STEPS"); }
else if (p == 2u) se_st ^= 128;
else if (p == 12u) se_do((uint32_t)se_st & 127u, se_md);
else if (p >= 3u && p <= 6u) {
if ((p - 3u) * 16u >= len) ui_message("NO SUCH BAR");
else sel_set((p - 3u) * 16u, (p - 3u) * 16u + 15u < len ? (p - 3u) * 16u + 15u : len - 1u);
} else if (drum_track(TSEL) && !chain_busy()) {
undo_mark();
ui_message(tl_do(TSEL, p, ui.lane));
}
ui.force = 1;
}
/* KNOB 1 START (MOVE), 2 END (WIDTH): the selection, 3 the ACTION, 4 its amount */
static void se_knob(uint32_t k, int32_t d)
{
uint32_t len = tl_len(TSEL), lo, n, a, b, act = (uint32_t)se_st & 127u;
d = d > 0 ? 1 : -1;
(void)seq_sel(TSEL, &lo, &n, len);
a = lo; b = lo + n - 1u;
if (k == 2u) { act = (uint32_t)clamp((int32_t)act + d, 0, SE_N - 1); se_st = (int16_t)((se_st & 128) | act); se_md = SE[act].def; return; }
if (k == 3u) { se_md = (int16_t)clamp(se_md + d, SE[act].lo, act == SE_GEN ? (int32_t)NGENRE : SE[act].hi); return; }
if (se_st & 128) { /* MOVE, WIDTH */
if (!k) a = (uint32_t)clamp((int32_t)a + d, 0, (int32_t)(len - 1u - (b - a))), b = a + n - 1u;
else b = (uint32_t)clamp((int32_t)b + d, (int32_t)a, (int32_t)len - 1);
} else if (!k) { a = (uint32_t)clamp((int32_t)a + d, 0, (int32_t)len - 1); if (b < a) b = a; }
else { b = (uint32_t)clamp((int32_t)b + d, 0, (int32_t)len - 1); if (a > b) a = b; }
sel_set(a, b);
if (k) ui.bank = (uint8_t)(b / 16u);
}
/* (V10.8.49, the owner) SEQ TOOLS' black C#5 / D#5: NUDGE the notes (selected: theirs) a 16th of a step earlier / later */
static void nudge_key(uint32_t up)
{
const char *m;
uint32_t lo, n;
if (chain_busy()) { ui_message("SONG PLAYS: STOP IT TO EDIT"); return; }
undo_mark();
(void)seq_sel(TSEL, &lo, &n, tl_len(TSEL));
if ((m = tl_nudge(TSEL, up ? 4 : -4, lo, n, 0))) { ui_message(m); ui.force = 1; }
}
/* Shared by GLO + G4 and REC + A3. One global undo/redo snapshot. */
static void undo_ui(void)
{
if (chain_busy())
ui_message("SONG PLAYS: STOP IT TO EDIT");
else {
uint32_t g = gls.u && gls_sig == gls_hash(); /* (GEN's FROM LOOP: the loop as it was, in LOOP mode) */
if (undo_do()) { ui_message("NOTHING TO UNDO"); return; }
if (g) { chain_config.count = 0; live.mode = 0; gls.u = 0; }
if (ui.ly == LAYER_REC) song.rec = 0; /* keep the recovered take safe */
ui_message("UNDONE (AGAIN: REDO)");
}
}
/* REC: CLEAR, the selected track's steps and automation (and ARP's latched chord), no dialog, as SEQ TOOLS' CLEAR
* (up to 1.1.4 REC held on SEQ asked first, CF_CLEAR_SEQ) */
static void rec_clear(void)
{
track_t *t = TSEL;
if (chain_busy()) {
ui_message("SONG PLAYS: STOP IT TO EDIT");
return;
}
if (!track_clearable(t)) {
ui_message("NOTHING TO CLEAR");
return;
}
undo_mark(); /* (0.6.21) UNDO: GLO + G4 */
load_begin(t, LOAD_PAT);
clay_clear(trk_index(t));
track_defaults_steps(t);
load_end(t);
latch_drop_req |= (uint8_t)(1u << trk_slot(t)); /* (0.6.19) the latched chord too (events_block) */
{ /* (0.6.28) which track: the others play on */
char cb[16] = "T1 CLEARED";
cb[1] = (char)('1' + trk_slot(t));
ui_say(cb, "");
}
ui.force = 1;
}
/* REC's settings, row r (G3, KNOB 1): CLICK as MENU > AUDIO steps it (ui.c rp_*). TONIC: COUNT-IN and CLICK LEVEL
* left the layer (MENU > AUDIO still has them) */
#define RL_N 1u
static const uint8_t RL_F[RL_N] = {RP_CLICK};
static const char *const RL_LABEL[RL_N] = {"CLICK"};
static const uint8_t RL_ICON[RL_N] = {ICON_TEMPO};
static const char *rl_name(uint32_t r, uint32_t v) { (void)r; return CLICK_N[v % 3u]; }
static void rec_set(uint32_t r, uint32_t v)
{
if (v == rp_get(RL_F[r]))
return;
rp_put(RL_F[r], v);
lys.rp_dirty = 1;
}
static void rec_key(uint32_t p)
{
uint32_t r = p - 1u, v;
if (p == 2u) { undo_ui(); return; } /* A3: UNDO / REDO */
if (p == 3u) { /* B3: hard quantization off / on */
TSEL->p[P_HRQ] = TSEL->p[P_HRQ] ? 0 : 127;
ui_say("QUANTIZE ", TSEL->p[P_HRQ] ? "ON" : "OFF"); /* (V10.8.53: said) */
return;
}
if (p == 0u) {
rec_clear();
return;
}
v = (rp_get(RL_F[r]) + 1u) % 3u; /* the next value, round */
rec_set(r, v);
ui_say("CLICK ", rl_name(r, v));
}
/* SAVE, the song layer (song_chain.c): white key p. 1..4 (F3..B3) play section A..D (on the next bar; tapped in a row
* in one hold: a quick chain, layer_let_go), 5..8 (C4..F4) store the music into A..D, 13 (D5) LOOP / SONG (what PLAY
* plays), 14 (E5) SONG REC, 16 (G5) the SONG page */
#define SK_PLAY 0u /* the song layer's keys (white key places) */
#define SK_STORE 4u
#define SK_MODE 12u
#define SK_REC 13u
#define SK_PAGE 15u
#define SK_NAME 11u /* (0.9.2) C5: NAME, the slot's rename (EDIT's until 0.9.1) */
static void song_key(uint32_t p)
{
uint32_t k;
if (p < SK_STORE) {
if (lys.nqc < sizeof lys.qc)
lys.qc[lys.nqc++] = (uint8_t)p;
if (lys.nqc == 1u)
(void)section_jump(p); /* (the first: at once, as a single tap) */
else {
char b[24] = "CHAIN";
for (k = 0; k < lys.nqc && k < 8u; k++) {
char c[3] = {' ', (char)('A' + lys.qc[k]), 0};
str_cat(b, c, sizeof b - str_len(b));
}
ui_message(b);
}
} else if (p < SK_STORE + 4u) {
section_ask(p - SK_STORE);
} else if (p == SK_MODE) {
live.mode ^= 1u;
ui_message(live.mode ? "PLAY: THE SONG" : "PLAY: THE PART");
} else if (p == SK_REC) {
song_rec_toggle();
} else if (p == SK_NAME) { /* (0.9.2) SAVE + C5: USER's slot, PROJECT's project or section */
if (!ui.home && (cur_page()->graph == GR_USER || cur_page()->graph == GR_SLOTS))
name_rename();
else
ui_message("NAME: ON USER OR PROJECT");
} else if (p == SK_PAGE) {
for (k = 0; k < NPAGES && PAGES[k].graph != GR_SONG; k++)
;
if (k < NPAGES) {
ui.home = 0;
ui.page = (uint8_t)k;
page_entered();
}
}
}
/* a key pressed in layer l (k: 0 = F3 .. 26 = G5) */
/* (JIANT 0.4) MACRO DICE: random routes from M1..M4 to what each track's sound has (its engine's parameters, CUT,
* SHP, the sends, a little PITCH), two a track into its free MOD slots, the macros spread so each moves two tracks:
* the instrument invites a turn from the start, the routes there to tune (MOD) or keep (saved with the project).
* mode 0 (each power-on, project.c autosave_boot then main.c): only a track with no macro route yet, so a session
* restored keeps its own; 1 (MACRO layer F3): the macros' routes rolled again; 2 (G3): the macros' routes cleared */
/* (JIANT 0.5) a track that sounds now: not muted, and a voice of it ringing, or (playing) a step of its pattern on */
static int track_sounding(const track_t *t)
{
uint32_t i, len = (uint32_t)t->p[P_SLEN];
if (t->p[P_MUTE])
return 0;
for (i = 0; i < NVOICE; i++)
if (t->v[i].stage && t->v[i].stage < 4u)
return 1;
if (song.playing)
for (i = 0; i < len && i < NSTEP; i++)
if (step_on(&seq_steps(t)[i]))
return 1;
return 0;
}
static void macro_dice(uint32_t mode)
{
static const uint8_t DST[] = {MD_CUT, MD_SHP, MD_E1, MD_E1 + 1, MD_E1 + 2, MD_E1 + 3, MD_E1 + 4, MD_E1 + 5, MD_E1 + 6,
MD_E1 + 7, MD_E1, MD_E1 + 1, MD_E1 + 2, MD_E1 + 3, MD_DLY, MD_REV, MD_DIST}; /* (V10.8: no PITCH, the
* macros' drift wobbled whole tracks out of tune; the
* engine's, its first four twice as likely) */
uint32_t k, j, n;
for (k = 0; k < NTRK; k++) {
track_t *t = &trk[k];
uint32_t has = 0, used = 0;
for (j = 0; j < 4u; j++) {
int16_t *m = &t->p[P_M1SRC + 3u * j];
if (m[0] >= MS_M1 && m[0] < MS_M1 + 4) {
if (mode) m[0] = m[1] = m[2] = 0;
else has = 1;
}
if (m[0]) used |= 1u << m[1];
}
if (has || mode == 2u)
continue;
if (mode == 1u && !track_sounding(t)) /* (JIANT 0.5) a reroll: only the tracks that sound now */
continue;
if (mode == 3u && t->p[P_MUTE]) /* (0.6.21) DICE ALL: every track not muted */
continue;
for (j = 0, n = 0; j < 4u && n < 2u; j++) {
int16_t *m = &t->p[P_M1SRC + 3u * j];
uint32_t d, tries;
if (m[0])
continue;
for (tries = 0; tries < 16u; tries++) { /* a destination the sound has, not used on this track */
const param_desc_t *pd;
d = DST[rng() % sizeof DST];
if (((used >> d) & 1u) || !mod_dst_offer(t, d))
continue;
if (d >= MD_E1 && d < MD_E1 + 8u &&
((pd = track_desc(t, P_E0 + (d - MD_E1))) == 0 || pd->max <= pd->min || pd->label[0] == '-' ||
pd->fmt == F_SEMI)) /* (V10.38: never an interval, INT: out of tune) */
continue;
break;
}
if (tries == 16u)
continue;
used |= 1u << d;
m[0] = (int16_t)(MS_M1 + (k + 2u * n) % 4u);
m[1] = (int16_t)d;
m[2] = (int16_t)((d == MD_PITCH ? 4 + (int32_t)(rng() % 9u) : 24 + (int32_t)(rng() % 40u)) * (rng() & 1u ? 1 : -1));
n++;
}
}
}
/* (JIANT 0.4) the session's macros (main.c after autosave_boot; the emulator too): the random numbers seeded by
* something of this power-on, then the routes the tracks have none of */
static void session_dice(uint32_t seed)
{
rng_state ^= seed * 2654435761u;
if (!rng_state)
rng_state = 0x1234567u;
macro_dice(0);
}
/* GLO's white keys after the SOLOs (F3 ..): unmute all, tap tempo; KNOB 1..4: the levels from track trk_base4() */
static const char *const GLO_GROUP[4]; /* (the DRUM group's names, below) */
#define GLO_ALL ((uint32_t)NTRK)
#define GLO_TAP 7u
#define GLO_RESOUND 9u /* (V10.8.54) A4: RESOUND, new sounds for the whole song (gen.c) */
#define GLO_UNDO 8u /* (0.6.21) G4: UNDO the last big change (project.c undo_do) */
/* (V10.6) A4 FREEZE, B4 REVERT ALL and SEQ's D5 REVERT gone with MUTATE */
static __attribute__((noinline)) void layer_key(uint32_t l, uint32_t k)
{
uint32_t p = key_place(k), i;
if (l == LAYER_GLO) {
if (key_black(k)) { /* (V10.8.53, the owner: every combination says what it did) */
char n[3] = {'T', (char)('1' + p), 0};
if (p < NTRK) {
trk[p].p[P_MUTE] = (int16_t)!trk[p].p[P_MUTE];
ui_say(n, trk[p].p[P_MUTE] ? " MUTED" : " ON");
} else if (p < NTRK + 4u) {
dx_mute_set(dx_mute ^ (1u << (p - NTRK)));
ui_say(GLO_GROUP[p - NTRK], (dx_mute >> (p - NTRK)) & 1u ? " MUTED" : " ON");
}
} else if (p < NTRK) {
lys.solo |= 1u << k; /* (layer_masks: perf_solo while held) */
} else if (p == GLO_ALL) {
for (i = 0; i < NTRK; i++)
trk[i].p[P_MUTE] = 0;
dx_mute_set(0);
ui_message("ALL UNMUTED");
} else if (p == GLO_TAP) {
glo_tap();
} else if (p == GLO_UNDO) {
undo_ui();
} else if (p == GLO_RESOUND) {
gen_resound_key();
}
} else if (l == LAYER_SCL) {
TSEL->p[P_ROOT] = (int16_t)((k + 5u) % 12u); /* the key's note name (F3 = F) */
ui_say("ROOT ", NOTE_NM(TSEL->p[P_ROOT]));
} else if (l == LAYER_EDIT && key_black(k) && p < NLANE && drum_track(TSEL)) {
dx_mute_set(dx_mute ^ DXM_LANE(p)); /* DRUM: black keys 1..8 mute each sound (lit = sounding) */
ui_say(drum_lane_abbr(TSEL, p), dx_mute & DXM_LANE(p) ? " MUTED" : " ON");
} else if (l == LAYER_EDIT && !key_black(k) && p <= LY_RECALL) {
if (chain_busy())
ui_message("SONG PLAYS: STOP IT TO EDIT");
else if (p == LY_RECALL && !edit_recallable())
ui_message("NOTHING SAVED");
else
confirm_open(p == LY_INIT ? CF_INIT_SOUND : CF_RECALL_SOUND, song.sel); /* (the dialog closes the layer) */
} else if (l == LAYER_REC) {
if (!key_black(k) && p < 4u)
rec_key(p);
} else if (l == LAYER_SEQ) {
if (!key_black(k))
tools_key(p);
else if (p == 8u || p == 9u)
nudge_key(p == 9u); /* (V10.8.49) C#5 / D#5: NUDGE < / > */
else if (p == 10u)
se_undo(); /* (V10.8.52) F#5: UNDO / REDO the last edit */
else if (p < NLANE && drum_track(TSEL)) {
ui.lane = (uint8_t)p; /* (black keys 1..8: the lane, as on the grid) */
ui_say("LANE ", drum_lane_abbr(TSEL, p));
}
} else if (l == LAYER_SAVE && !key_black(k)) {
song_key(p);
}
}
/* each pass: the keys the layer got now; then GLO's solo: the tracks of its keys still held (perform.c) */
static void layer_keys(uint32_t keys)
{
uint32_t k, l = layer_open() ? layer_open() : ui.layer, s = 0;
if (keys) lys.used = 1;
for (k = 0; keys && k < 27u; k++)
if ((keys >> k) & 1u)
layer_key(l, k);
lys.solo &= kb_layer;
for (k = 0; k < 27u; k++)
if ((lys.solo >> k) & 1u)
s |= 1u << key_place(k);
perf_solo = (uint8_t)s;
}
/* KNOB 1..4 in the open layer: its own (FX macros, GLO levels, EDIT's sound), else the four of its page */
static BTAPP_FN void pke_knob_bt(uint32_t k, int32_t d);
static void layer_knob(uint32_t k, int32_t s)
{
uint32_t l = layer_open();
lys.used = 1;
if (l == LAYER_FX && pk.edit) { /* (V10.7.65) the punch-in editor: the held key's */
if (bt_hw_seg()) pke_knob_bt(k, s);
} else if (l == LAYER_FX) { /* (V10.7.59) the MACROS (was perform.c's FILTER CRUSH THROW DEPTH) */
fx_macro_turn(k, s);
} else if (l == LAYER_GLO) { /* T1..T4 LEVEL (T5, T6 selected: T3..T6), recorded as on MIXER */
track_t *t = &trk[k + trk_base4()];
int16_t *vp = &t->p[P_LEVEL];
*vp = (int16_t)clamp(*vp + accel(EN_K1 + k, s, TP[P_LEVEL].max - TP[P_LEVEL].min), TP[P_LEVEL].min,
TP[P_LEVEL].max);
motion_capture(t, P_LEVEL, *vp);
} else if (l == LAYER_SEQ) { /* (V10.8.52) SEQ EDIT */
se_knob(k, s);
ui.force = 1;
} else if (l == LAYER_SAVE) { /* KNOB 1: the song (in when SAVE lets go); 2..4: none */
if (k == 0u) {
char b[4];
lys.song = (uint8_t)(clamp((int32_t)(lys.song ? lys.song - 1u : song_cur) + (s > 0 ? 1 : -1), 0,
NSONG - 1) + 1);
fmt_int(b, lys.song);
ui_say("PROJECT ", b); /* (V10.8.54: in when SAVE lets go) */
str_cpy(ui.msg2, "LET GO: OPEN", sizeof ui.msg2);
}
} else if (l == LAYER_REC) { /* K1 CLICK, K2 REC Q */
if (k == 1u) {
char b[6];
TSEL->p[P_HRQ] = (int16_t)clamp(TSEL->p[P_HRQ] + accel(EN_K2, s, 127), 0, 127);
fmt_int(b, TSEL->p[P_HRQ] * 100 / 127);
str_cat(b, "%", 2);
ui_say("REC GRID ", b);
}
else if (k < RL_N)
rec_set(k, (uint32_t)clamp((int32_t)rp_get(RL_F[k]) + s, 0, 2));
} else if (l) { /* the page's knobs, wherever the page is */
uint8_t h = ui.home, pg = ui.page, nm[sizeof ui.nmem];
memcpy(nm, ui.nmem, sizeof nm); /* (the sections' memories: not this borrowed page's) */
ui.home = 0;
ui.page = (uint8_t)page_first(LAYERS[l].fam);
page_over = ly_page(l);
edit_param(k, s);
page_over = 0;
ui.home = h;
ui.page = pg;
memcpy(ui.nmem, nm, sizeof nm);
}
}
/* PLAY with GLO held open: RESTART (from the top, playing on); stopped: PLAY. 1 = done here */
static int layer_play(void)
{
if (layer_open() == LAYER_SEQ && song.playing) { /* (V10.8.40, the owner) RESYNC: every track from its first
* step at the next bar, in time (seq.c seq_anchor) */
seq_rs = (clk_n / 16u + 1u) * 16u;
ui_message("RESYNC");
return 1;
}
if (layer_open() != LAYER_GLO || chain_busy())
return 0;
if (song.g[G_CLOCK] && song.playing) {
ui_message("RESTART: CLK IS EXT");
return 1;
}
if (song.playing) ui_message("RESTART");
transport_req = song.playing ? 3u : 1u;
return 1;
}
/* OCT- / OCT+ pressed with a SET layer's button down (FX LATCH: FX's) before it opened: a combo, so it opens now,
* before oct_taps and layer_oct read it (else the press was nobody's: no put back / ALL OFF, no octave) */
static void layer_oct_open(uint32_t pressed)
{
uint32_t l = ui.ly, oct = 1u << panel.btn[B_OCTDN] | 1u << panel.btn[B_OCTUP];
if ((pressed & oct) && l && !(ui.ly_t0 & (LY_OPEN | LY_DEAD)) && layer_held() &&
(LAYERS[l].kind == LK_SET || (l == LAYER_FX && perf_latch_on))) {
ui.ly_t0 |= LY_OPEN | LY_COMBO;
layer_opened(l);
}
}
/* OCT- / OCT+ in a SET layer: no octave (TONIC: no put back; FX LATCH: OCT- all off). Returns the taps left */
static uint32_t layer_oct(uint32_t pressed, uint32_t oct)
{
uint32_t dn = panel.btn[B_OCTDN], up = panel.btn[B_OCTUP], mine;
if (layer_set_open())
lys.oct |= (uint8_t)(((pressed >> dn) & 1u) | ((pressed >> up) & 1u) << 1);
if (ui.ly && (pressed & (1u << dn | 1u << up)))
lys.used = 1; /* (0.6.44: an OCT with it: no FX lock) */
mine = oct & lys.oct;
if (lys.l == LAYER_SEQ && mine) /* (V10.8.52) SEQ EDIT: OCT+ the ACTION, OCT- ALL STEPS */
tools_key(mine & 2u ? 12u : 1u);
if ((mine & 1u) && lys.l == LAYER_FX) { /* OCT- (FX LATCH): every effect and macro off */
perf_latched = 0;
perf_k[0] = perf_k[1] = perf_k[2] = perf_k[3] = 0;
fx_macro_back();
ui_message("FX ALL OFF");
}
if (lys.l == LAYER_SAVE && (mine & 2u)) { /* SAVE + OCT+: STORE the music into the section playing */
if (live.cur < 0)
ui_message("PLAY A PART FIRST");
else
section_ask((uint32_t)live.cur);
}
if (lys.l == LAYER_SAVE && (mine & 1u)) /* SAVE + OCT-: RECALL it as it was stored */
section_recall();
lys.oct &= (uint8_t)(((fm1_in.buttons >> dn) & 1u) | ((fm1_in.buttons >> up) & 1u) << 1);
return oct & ~mine;
}
/* --------------------------------------------------------- the LEDs --- */
/* lit = in effect now (held, the value, a track sounding), breathing = can be pressed (*br: dark .. ~60 % and
* back, ~1.1 s, hal/fm1_input.h fm1_led_breath; was a hard 250 ms blink, #119), dark = nothing there */
static int glo_sounding(uint32_t t) { return !trk[t].p[P_MUTE] && (!perf_solo || ((perf_solo >> t) & 1u)); }
static int glo_drums(void) /* a track plays DRUM: GLO shows its group mutes */
{
uint32_t i;
for (i = 0; i < NTRK; i++)
if (drum_track(&trk[i]))
return 1;
return 0;
}
static int rec_clearable(void) { return track_clearable(TSEL); }
static uint32_t layer_leds(uint32_t *br)
{
uint32_t k, m = 0, n = 0, l = ui.layer, held = perf_held | perf_latched, ok = perf_avail();
uint32_t mask = scale_mask(TSEL), root = (uint32_t)TSEL->p[P_ROOT] % 12u;
for (k = 0; k < 27u; k++) {
uint32_t p = key_place(k), b = (uint32_t)key_black(k), on = 0, can = 0, e;
if (l == LAYER_FX) { /* effects breathe, held lit, a too-long REPEAT dark */
e = perf_key(k);
can = e < PF_N && ((ok >> e) & 1u);
on = can && ((held >> e) & 1u);
} else if (l == LAYER_GLO) { /* sounding lit; SOLO held lit, the others, C4, F4 breathe */
on = b ? (p < NTRK && glo_sounding(p)) || (p >= NTRK && p < NTRK + 4u && !((dx_mute >> (p - NTRK)) & 1u))
: p < NTRK && ((lys.solo >> k) & 1u); /* (a group sounding: lit) */
can = !b && ((p < NTRK && p < trk_live) || p == GLO_ALL || (p == GLO_TAP && !song.g[G_CLOCK]) ||
(p == GLO_UNDO && undo_ok));
/* (the keys that do something breathe: not an asleep track's) */
} else if (l == LAYER_SCL) { /* the root lit, the scale's notes breathe */
e = (k + 5u + 12u - root) % 12u;
on = e == 0u;
can = (mask >> e) & 1u;
} else if (l == LAYER_EDIT && !b) { /* INIT and RECALL breathe (RECALL: a stored section) */
can = (p == LY_INIT && !chain_busy()) || (p == LY_RECALL && edit_recallable()); /* (V10.6z8: RECALL in a song) */
} else if (l == LAYER_EDIT && p < NLANE && drum_track(TSEL)) { /* DRUM: a sound sounding lit, muted dark */
on = !dx_lane_muted(p);
} else if (l == LAYER_SEQ) { /* the tools breathe (not while a song plays); DRUM: the lane */
on = b ? p < NLANE && drum_track(TSEL) && p == ui.lane : p == 2u && (se_st & 128); /* lit, the other lanes breathe */
can = b ? (p < NLANE && drum_track(TSEL)) || ((p == 8u || p == 9u) && !chain_busy()) :
!chain_busy() && (p < 8u || p > 10u || drum_track(TSEL)) && (p != 14u || clip.n);
} else if (l == LAYER_SAVE && !b) { /* the section playing lit, the saved ones and the */
on = (p < SK_STORE && live.cur == (int8_t)p) || (p == SK_REC && live.srec) || /* actions breathe */
(p == SK_MODE && live.mode);
can = p < SK_STORE ? project_used(p) : p < SK_STORE + 4u || p == SK_MODE || p == SK_REC || p == SK_PAGE;
} else if (l == LAYER_REC && !b && p < 4u) { /* the click on: lit, else it breathes; CLEAR: */
on = (p == 1u && rp_get(RP_CLICK) != 0u) || (p == 3u && !TSEL->p[P_HRQ]); /* something to clear, not while a song plays */
can = p == 2u ? !chain_busy() && undo_ok : p ? 1u : !chain_busy() && rec_clearable();
}
m |= on << k;
n |= (can & !on) << k;
}
if (br)
*br = n;
return m;
}
/* ------------------------------------------------------ the overlay --- */
/* (0.8.9) The layers as the approved LENTE mock-up's CAPAS (MAP . KNOBS . STATE) in the skins' language (the mock-up
* opciones_skin.html): the header "[GLO] SET" in plain words; the cards KNOB 1..4 in their colours (COLORS on top,
* BOTTOM / HUD the knob row); MAP the keyboard itself, F3 .. G5, 16 white keys and 11 black, each named upright by what it
* does there (none: an empty key): a key that can be pressed RAISE (white) or tinted (black), the value now THEME, held
* the accent, a muted track KEY, unavailable its name DIM, its note under it; KNOBS the four as gauges in their knobs'
* colours over the layer's keys (the keycaps' words); STATE what is on, as chips. (Until 0.8.8: cells with note names,
* the Felucca map.) The keys and knobs do what they did: only the drawing is new */
static const char PF_NAME[] = /* (V10.8.69: packed, str_nth) */ /* the audio ones
* (perform.c; V10.7.59: REVERSE FREEZE, were LPF HPF) */
"RPT 1/8\0" "RPT 1/16\0" "RPT 1/32\0" "REVERSE\0" "FREEZE\0" "OCT-\0" "OCT+\0" "1/2 TEMPO\0" "DEC-\0"
"DEC+\0" "STUT 1/8\0" "STUT 1/16\0" "ATK+\0" "ARP\0" "RANDOM";
/* the MIDI ones (pfx.c) */
static const char W_NOTE[16] = {'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F', 'G'};
static const char B_NOTE[11] = {'F', 'G', 'A', 'C', 'D', 'F', 'G', 'A', 'C', 'D', 'F'}; /* black keys 1..11: F# G# .. F#5 */
static const uint8_t PK_BLK[11] = {1, 2, 3, 5, 6, 8, 9, 10, 12, 13, 15}; /* a black key: left of white key n */
enum { LS_OFF, LS_SEL, LS_HELD, LS_WAIT, LS_DIM, LS_MUTE };
static const char *const GLO_GROUP[4] = {"KICK", "SNARE", "HAT", "PERC"};
#define LMC_TW 140 /* MACRO's routes: their width (x 92 .. 232) */
static uint32_t macro_routes(uint32_t m, char *b, uint32_t n)
{
uint32_t i, k, c = 0;
if (b)
b[0] = 0;
for (i = 0; i < NTRK; i++)
for (k = 0; k < 4u; k++) {
const int16_t *p = &trk[i].p[P_M1SRC + 3u * k];
if (p[0] != (int16_t)(MS_M1 + m) || !p[1] || !p[2])
continue;
c++;
if (b && str_len(b) + 12u < n) { /* (as many as fit in LMC_TW; "+" when more) */
char e[16] = {'T', (char)('1' + i), ' ', 0};
uint32_t l0 = str_len(b);
str_cpy(e + 3, mod_dst_name(&trk[i], p[1]), sizeof e - 3);
str_cat(e, p[2] > 0 ? "+" : "", sizeof e - str_len(e));
fmt_cat(e, p[2] * 100 / 64);
if (l0)
str_cpy(b + l0, " ", n - l0);
str_cat(b, e, n - str_len(b));
if (text_w(&AF_S, b) > LMC_TW) {
b[l0] = 0;
str_cpy(b + l0, " +", n - l0);
n = l0 + 3u; /* (nothing more goes in) */
}
}
}
return c;
}
static uint32_t macro_sig(void)
{
uint32_t i, k, h = (uint32_t)macro_v[0] | (uint32_t)macro_v[1] << 8 | (uint32_t)macro_v[2] << 16 | (uint32_t)macro_v[3] << 24;
for (i = 0; i < NTRK; i++)
for (k = 0; k < 12u; k++)
h = (h ^ (uint32_t)trk[i].p[P_M1SRC + k]) * 16777619u;
return h + snd_id() * 31u;
}
/* key p (white, or black: blk) of layer l: its name into nm (12; "" none), its state */
static uint32_t ly_keyname(uint32_t l, int blk, uint32_t p, char *nm)
{
uint32_t busy = chain_busy() ? LS_DIM : LS_OFF;
nm[0] = 0;
if (l == LAYER_FX) {
uint32_t held = perf_kill ? 0u : perf_held | perf_latched, sl = blk ? 16u + p : p, e;
if (blk ? p >= 11u : p >= 16u)
return LS_OFF;
e = pk.edit ? (pk.we[sl] ? (pk.we[sl] & 31u) - 1u : perf_def(sl)) : pk.e[sl] ? (pk.e[sl] & 31u) - 1u : perf_def(sl); /* (V10.7.65:
* the slot's, the editor's copy) */
pk_name(e, pk.edit ? pk.wo[sl] : pk.o[sl], nm);
if (pk.edit) /* (the key being set lit) */
return sl == pk.ekey && kb_layer ? LS_HELD : e >= PF_N && e != PK_MOD ? LS_DIM : LS_OFF;
if (e == PF_CLR)
return pfx_clr ? LS_HELD : LS_OFF;
if (e == PK_MOD)
return PK_DST(pk.o[sl]) < 4u ? ((pk.mod >> (pk.o[sl] & 3u)) & 1u ? LS_HELD : LS_OFF) :
pk.pkey == sl + 1u ? LS_HELD : LS_OFF;
if (e >= PF_N)
return LS_OFF;
if (e >= PF_M1 && e < PF_M1 + NTRK)
return (held >> e) & 1u ? LS_MUTE : LS_OFF;
if (e >= PF_M1) /* LOOP 3, TAPE STOP, PITCH, STRETCH */
return !((held >> e) & 1u) ? LS_OFF : ((perf_act >> e) & 1u) || ((PF_LOOPS >> e) & 1u) ? LS_HELD : LS_WAIT;
return !((perf_avail() >> e) & 1u) ? LS_DIM : !((held >> e) & 1u) ? LS_OFF :
((perf_act >> e) & 1u) || ((PF_MIDI >> e) & 1u) ? LS_HELD : LS_WAIT;
}
if (l == LAYER_GLO) {
if (blk && p < NTRK) {
str_cpy(nm, "MUTE T1", 12);
nm[6] = (char)('1' + p);
return trk[p].p[P_MUTE] ? LS_MUTE : p >= trk_live ? LS_DIM : LS_OFF;
}
if (blk && p < NTRK + 4u && glo_drums()) {
str_cpy(nm, GLO_GROUP[p - NTRK], 12);
return (dx_mute >> (p - NTRK)) & 1u ? LS_MUTE : LS_OFF;
}
if (blk)
return LS_OFF;
if (p < NTRK) {
str_cpy(nm, "SOLO T1", 12);
nm[6] = (char)('1' + p);
return (perf_solo >> p) & 1u ? LS_HELD : p >= trk_live ? LS_DIM : LS_OFF;
}
str_cpy(nm, p == GLO_ALL ? "UNMUTE" : p == GLO_TAP ? "TAP" : p == GLO_UNDO ? "UNDO" : p == GLO_RESOUND ? "RESOUND" : "",
12); /* (V10.8.71, the owner: A4's RESOUND named on the map too) */
return p == GLO_TAP && song.g[G_CLOCK] ? LS_DIM : p == GLO_UNDO && !undo_ok ? LS_DIM : LS_OFF;
}
if (l == LAYER_SCL) { /* every key its note: the root lit, the scale's plain, the rest dim */
static const uint8_t WN[16] = {5, 7, 9, 11, 0, 2, 4, 5, 7, 9, 11, 0, 2, 4, 5, 7};
uint32_t n = blk ? (uint32_t)(WN[PK_BLK[p] - 1u] + 1u) % 12u : WN[p], deg;
nm[0] = blk ? B_NOTE[p] : W_NOTE[p];
nm[1] = blk ? '#' : 0;
nm[2] = 0;
deg = (n + 12u - (uint32_t)clamp(TSEL->p[P_ROOT], 0, 11)) % 12u;
return !deg ? LS_SEL : (scale_mask(TSEL) >> deg) & 1u ? LS_OFF : LS_DIM;
}
if (l == LAYER_EDIT) {
if (blk) {
if (p < NLANE && drum_track(TSEL)) {
str_cpy(nm, drum_lane_abbr(TSEL, p), 12);
return dx_lane_muted(p) ? LS_MUTE : LS_OFF;
}
return LS_OFF;
}
if (p > LY_RECALL)
return LS_OFF;
str_cpy(nm, p == LY_INIT ? (drum_track(TSEL) ? "INIT+KIT" : "INIT") : drum_track(TSEL) ? "RCL+KIT" : "RECALL", 12);
return p == LY_RECALL ? (edit_recallable() ? LS_OFF : LS_DIM) : busy; /* (V10.6z8: RECALL in a song too) */
}
if (l == LAYER_REC) {
if (blk || p > 3u)
return LS_OFF;
if (p >= 2u) {
str_cpy(nm, p == 2u ? "UNDO" : TSEL->p[P_HRQ] ? "Q ON" : "Q OFF", 12);
return p == 2u ? (!undo_ok || chain_busy() ? LS_DIM : LS_OFF) : !TSEL->p[P_HRQ] ? LS_SEL : LS_OFF;
}
str_cpy(nm, p ? "CLICK " : "CLEAR", 12);
if (p)
str_cpy(nm + 6, rl_name(0, rp_get(RL_F[0])), 6);
return p ? (rp_get(RL_F[0]) ? LS_SEL : LS_OFF) : chain_busy() || !rec_clearable() ? LS_DIM : LS_OFF;
}
if (l == LAYER_SAVE) {
if (blk)
return LS_OFF;
if (p < SK_STORE) {
str_cpy(nm, "PLAY A", 12);
nm[5] = (char)('A' + p);
return !project_used(p) ? LS_DIM : live.req == (int8_t)p ? LS_WAIT : live.cur == (int8_t)p ? LS_SEL : LS_OFF;
}
if (p < SK_STORE + 4u) {
str_cpy(nm, "SAVE A", 12);
nm[6] = (char)('A' + p - SK_STORE);
return (live.dirty >> (p - SK_STORE)) & 1u ? LS_WAIT : LS_OFF;
}
str_cpy(nm, p == SK_MODE ? (live.mode ? "SONG" : "PART") : p == SK_REC ? "SONG REC" : p == SK_PAGE ? "ARRANGE" :
p == SK_NAME ? "NAME" : "", 12);
if (p == SK_NAME)
return !ui.home && (cur_page()->graph == GR_USER || cur_page()->graph == GR_SLOTS) ? LS_OFF : LS_DIM;
return p == SK_MODE && live.mode ? LS_SEL : p == SK_REC ? (live.srec == 2u ? LS_HELD : live.srec ? LS_WAIT : LS_OFF) : LS_OFF;
}
return LS_OFF;
}
/* a key's fill and its name's ink by its state (named: n) */
static uint16_t pk_fill(uint32_t st, int blk, int n, uint16_t *ink)
{
*ink = st == LS_DIM ? T_DIM : blk ? T_TEXT : T_TEXT;
if (st == LS_HELD) { *ink = T_INK; return T_ACCENT; }
if (st == LS_SEL || st == LS_WAIT) { *ink = T_INK; return st == LS_WAIT ? ux_mix(T_RAISE, T_THEME, 55) : T_THEME; }
if (st == LS_MUTE) { *ink = T_INK; return T_KEY; }
if (!n)
return blk ? T_BG : ux_mix(T_BG, T_TEXT, 7);
return blk ? ux_mix(T_BG, T_THEME, 34) : ux_mix(T_BG, T_TEXT, 17);
}
static void ly_piano(uint32_t l)
{
int32_t h = (int32_t)graph_h() - 6, y = 3, bh = 54, i;
char nm[12], nt[2] = {0, 0};
for (i = 0; i < 16; i++) { /* the white keys */
int32_t x0 = 4 + i * 232 / 16, w = 4 + (i + 1) * 232 / 16 - x0 - 1;
uint16_t ink, fill = pk_fill(ly_keyname(l, 0, (uint32_t)i, nm), 0, nm[0] != 0, &ink);
cv_rect(x0, y, w, h, fill);
if (nm[0])
cv_text_up(x0 + HALF_UP(w - AF_X_CAP_H) - AF_X_CAP_Y, y + h - 14, &AF_X, nm, ink, fill, h - 14 - bh - 6);
nt[0] = W_NOTE[i]; /* (its note, the letter) */
GFX_HOOK_ALIGN(x0, 0, x0 + w, 0, AL_H, "layer key's note centred");
cv_text_in(x0, y + h - 9 - AF_X_CAP_Y, w, &AF_X, nt, ink == T_INK ? ink : T_DIM, fill);
}
for (i = 0; i < 11; i++) { /* the black keys over them */
int32_t x0 = 4 + PK_BLK[i] * 232 / 16 - 5;
uint16_t ink, fill = pk_fill(ly_keyname(l, 1, (uint32_t)i, nm), 1, nm[0] != 0, &ink);
cv_rect(x0 - 1, y, 12, bh + 1, T_BG);
cv_rect(x0, y, 10, bh, fill);
if (nm[0])
cv_text_up(x0 + HALF_UP(10 - AF_X_CAP_H) - AF_X_CAP_Y, y + bh - 4, &AF_X, nm, fill == T_BG ? T_DIM : ink, fill, bh - 8);
}
}
/* (V10.7.77, the owner: "clearer") the FX layer as Felucca's cells were: the keys that do something, five a row in the
* keys' order (F3 .. G5), each its name, its state's fill (held / latched lit) */
static __attribute__((noinline)) void ly_fx_cells(void)
{
static const uint8_t BK[12] = {0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0}; /* (from F: the black ones) */
uint32_t k, pass, n, m = 0, wi, bi;
int32_t ch = ((int32_t)graph_h() - 6) / 7;
char nm[12];
for (pass = 0; pass < 2u; pass++) /* the effects four a row, then the tracks' mutes a row of six */
for (k = 0, n = 0, wi = 0, bi = 0; k < 27u; k++) {
uint32_t b = BK[k % 12u], st, mu;
uint16_t ink, fill;
int32_t x, y, w;
st = ly_keyname(LAYER_FX, (int)b, b ? bi++ : wi++, nm);
mu = nm[0] == 'M' && nm[1] == 'U';
if (!nm[0] || mu != pass || (!pass && m >= 24u)) continue;
fill = pk_fill(st, 0, 1, &ink);
w = pass ? 36 : 56;
x = 4 + (int32_t)(n % (pass ? 6u : 4u)) * (w + 2);
y = 3 + (pass ? 6 : (int32_t)(n / 4u)) * ch;
cv_rrect(x, y, w, ch - 2, 3, fill, T_SURF);
cv_text_in(x, y + (ch - 2) / 2 - 4, w, &AF_X, pass ? nm + 5 : nm, ink, fill);
n++; m += !pass;
}
}
/* Draw REC controls separately so the pinned UI/audio boundary stays unchanged. */
static __attribute__((noinline)) void rec_columns(void)
{
char val[12];
uint32_t c;
int32_t raw = TSEL->p[P_HRQ], q = raw * 100 / 127;
fmt_int(val, q);
for (c = 0; c < 4u; c++) {
if (c == 1u)
draw_column(c, "REC GRID", raw ? val : "OFF", raw ? "%" : "", VAL(c), q * 10, ICON_NONE);
else if (c == 0u) {
uint32_t v = rp_get(RP_CLICK);
draw_column(c, RL_LABEL[0], rl_name(0, v), "", v ? VAL(c) : T_DIM, v * 500, RL_ICON[0]);
} else
empty_column(c);
}
}
/* (V10.7.65, the owner) THE PUNCH-IN EDITOR (perform.c pk): OCT+ on the FX layer (held, or locked open) opens it, OCT-
* leaves; a key held and KNOB 1..4 its EFFECT TARGET AMOUNT MODE (the help in the header), SELECT the slot (1..4), OCT+
* saves the slot and plays it. The slots: spare bytes of the settings' favourite rows (engines of few presets: 27 from
* byte 5), the effects' row and the options' row each; the slot played favorites.factory[6][18] (TRIO's retired row) */
/* (V10.7.66, the owner) two slots, three rows each: the keys' EFFECT, their options, a PARAM key's AMOUNT and TIME */
static uint8_t *pk_row(uint32_t sl, uint32_t o)
{
static const uint8_t R[2][3] = {{0, 2, 7}, {3, 5, 10}};
return &favorites.factory[R[sl & 1u][o % 3u]][5];
}
static void pk_load(void) /* the slot played, from the settings */
{
uint32_t s;
pk.slot = (uint8_t)(favorites.factory[6][18] & 1u);
memcpy(pk.e, pk_row(pk.slot, 0), PK_KEYS);
memcpy(pk.o, pk_row(pk.slot, 1), PK_KEYS);
memcpy(pk.x, pk_row(pk.slot, 2), PK_KEYS);
for (s = 0; s < PK_KEYS; s++)
if ((pk.e[s] & 31u) > PK_N || (pk.e[s] > 31u && (pk.e[s] & 31u) != PK_MOD + 1u)) pk.e[s] = 0; /* (unknown: the
* map's own; bit 5 a PARAM key's HOW only) */
pk.qpend = pk.exd = pk.exs = 0;
memset(pk.mt, 0, sizeof pk.mt);
pk.mod = pk.mon = pk.edit = pk.pkey = 0;
pk.magic = PK_MAGIC;
}
/* a PARAM key's destination (its options' bits 0-3): M1..M4, then a parameter of every track */
#define PD_N 32u /* (bits 0-3 and 7: the owner, "more destinations") */
static const char PD_NM[PD_N][9] = {"M1", "M2", "M3", "M4", "CUT", "FILTER", "PITCH", "VIBRATO", "TIMBRE", "VOLUME", "PAN",
"DIST", "CHORUS", "DELAY", "REVERB", "LFO RATE", "EDIT1 K1", "EDIT1 K2", "EDIT1 K3", "EDIT1 K4",
"EDIT2 K1", "EDIT2 K2", "EDIT2 K3", "EDIT2 K4", /* (V10.8.5, the owner: "EDIT 1..8, what
* are they?": each track's EDIT 1 / EDIT 2 page, its knob) */ "DLY TIME", "DLY FDBK", "DLY TONE", "DLY MIX",
"REV SIZE", "REV DAMP", "CHO RATE", "CHO DPTH"};
static void pk_name(uint32_t e, uint32_t o, char *nm)
{
static const char BN[] = "LOOP 3\0" "PITCH UP\0" "PITCH DN\0" "TAPE STOP\0" "STRETCH"; /* (V10.8.71: packed, str_nth) */
str_cpy(nm, e < PF_M1 ? str_nth(PF_NAME, e) : e < PF_M1 + NTRK ? "MUTE T1" : e == PF_STR ? "STRETCH" : e >= PF_LP3 && e <= PF_TAPE ?
str_nth(BN, (unsigned)(e - PF_LP3)) : e == PF_CLR ? "CLR AUTO" : e == PK_MOD ? PD_NM[PK_DST(o)] : "-", 12);
if (e >= PF_M1 && e < PF_M1 + NTRK) nm[6] = (char)('1' + e - PF_M1);
}
static int32_t pk_amt(uint32_t x) { return (int32_t)((x & 31u) ^ 16u) - 16; } /* -10..10: tens of % */
/* a PARAM key's SHAPE at t ms of its period per: 0..127. HOLD, RAMP UP / DN (once), DROP (fast, a pitch envelope's), SINE,
* STUTTER, STUT ACC (faster and faster over the period: 4 cuts to 32), S&H, PAT 1..4 (16-step gates over the period) */
static uint32_t pk_shape(uint32_t sh, uint32_t t, uint32_t per, uint32_t seed)
{
static const uint16_t PAT[4] = {0x2492u, 0xDB6Bu, 0xB5B7u, 0xD511u};
uint32_t u = t * 256u / per, ph = u & 255u, q;
switch (sh) {
case 0: return 127u;
case 1: return u >= 256u ? 127u : u / 2u;
case 2: return u >= 256u ? 0u : 127u - u / 2u;
case 3: q = u >= 256u ? 0u : 256u - u; return q * q / 256u * q / 256u / 2u;
case 4: return (uint32_t)(64 + ((sine_i(ph << 24) * 63) >> 15));
case 5: return ph < 128u ? 127u : 0u;
case 6: q = u >= 256u ? 18u * 256u + 32u * (u - 256u) : 4u * u + 14u * u * u / 256u; return (q & 255u) < 128u ? 127u : 0u;
case 7: return ((t / per + seed) * 2654435761u) >> 25;
default: return (PAT[(sh - 8u) & 3u] >> ((u / 16u) & 15u)) & 1u ? 127u : 0u;
}
}
static uint32_t pk_per(uint32_t x) /* TIME (x bits 5-7: 1/16 .. 8 BARS) in ms */
{
return 15000u * (1u << (x >> 5)) / (uint32_t)clamp(song.g[G_BPM], 20, 300) + 1u;
}
/* PARAM keys held: a macro moved from where it was by AMOUNT x SHAPE (let go: as it was); a parameter of every track
* (mod.c pkr_*: as a macro route, the last key held) */
static const uint8_t PD_MD[PD_N - 4u] = {MD_CUT, MD_FCUT, MD_PITCH, MD_VIB, MD_SHP, MD_AMP, MD_PAN, MD_DIST, MD_CHO, MD_DLY,
MD_REV, MD_RATE, MD_E1, MD_E1 + 1, MD_E1 + 2, MD_E1 + 3, MD_E1 + 4, MD_E1 + 5,
MD_E1 + 6, MD_E1 + 7, MD_DTIME, MD_DFDBK, MD_DCOL, MD_DMIX, MD_RSIZE, MD_RDAMP,
MD_CRATE, MD_CDEPTH};
static void pk_mod_bt(void) /* (V10.7.66: out of the segment, its room) */
{
uint32_t m, v;
for (m = 0; m < 4u; m++) {
uint32_t b = 1u << m, o = pk.mo[m];
if (!((pk.mod | pk.mon) & b)) continue;
if (!(pk.mod & b)) {
pk.mon &= (uint8_t)~b;
macro_v[m] = pk.mv0[m];
continue;
}
if (!(pk.mon & b)) { pk.mon |= (uint8_t)b; pk.mv0[m] = macro_v[m]; }
v = pk_shape(pk.ms[m], fm1_ms - pk.mt0[m], pk_per(pk.mx[m]), m);
macro_v[m] = (uint8_t)clamp((int32_t)pk.mv0[m] + (int32_t)v * pk_amt(pk.mx[m]) / 10, 0, 127);
}
if (pk.pkey) {
pkr_d = PD_MD[(PK_DST(pk.po) - 4u) % (PD_N - 4u)];
pkr_a = (int8_t)(pk_amt(pk.px) * 64 / 10);
v = pk_shape(pk.ps, fm1_ms - pk.pt0, pk_per(pk.px), 5u);
pkr_v = (uint8_t)v;
} else
pkr_v = 0;
}
static void pk_mod(void) { if (pk.mod | pk.mon | pk.pkey | pkr_v) pk_mod_bt(); }
static int pk_page(void) { return (ui.ly == LAYER_FX && layer_held()) || (fx_lock && (!ui.ly || ui.ly == LAYER_FX)); } /* (held,
* or locked open: fx_lock_on is the frame after) */
static uint32_t pke_e(uint32_t s) { return pk.we[s] ? (pk.we[s] & 31u) - 1u : perf_def(s); }
static int pke_tgt(uint32_t e) { return (e >= PF_OCTD && e <= PF_RND) || e == PF_LP3; }
static BTAPP_FN void pke_load(uint32_t sl)
{
pk.eslot = (uint8_t)(sl & 1u);
memcpy(pk.we, pk_row(sl, 0), PK_KEYS);
memcpy(pk.wo, pk_row(sl, 1), PK_KEYS);
memcpy(pk.wx, pk_row(sl, 2), PK_KEYS);
}
static const char PK_SH[12][9] = {"HOLD", "RAMP UP", "RAMP DN", "DROP", "SINE", "STUTTER", "STUT ACC", "S&H", "PAT 1",
"PAT 2", "PAT 3", "PAT 4"};
static const char PK_MD[3][6] = {"HOLD", "LATCH", "QUANT"};
static const char PK_TM[8][7] = {"1/16", "1/8", "1/4", "1/2", "1 BAR", "2 BARS", "4 BARS", "8 BARS"};
static BTAPP_FN void pke_help(uint32_t s) /* the key's effect and how, in the header */
{
uint32_t e = pke_e(s), o = pk.we[s] ? pk.wo[s] : 0u;
char nm[12];
pk_name(e, o, nm);
ui_message(nm);
str_cpy(ui.msg2, e == PK_MOD ? PK_SH[PK_SHP(pk.we[s], o) % 12u] : PK_MD[((o >> 4) & 3u) % 3u], sizeof ui.msg2);
}
/* KNOB 1 WHAT (an effect, or PARAM: a macro or a parameter), 2 HOW (an effect: HOLD LATCH QUANT; PARAM: its SHAPE),
* 3 AMOUNT (an effect: its TARGET; PARAM: -100 .. +100 %), 4 TIME (PARAM: 1/16 .. 8 BARS) */
static BTAPP_FN void pke_knob_bt(uint32_t k, int32_t d)
{
uint32_t s = pk.ekey % PK_KEYS, e = pke_e(s), r = pk.we[s] ? pk.wo[s] : 0u, x = pk.we[s] ? pk.wx[s] : 0u;
uint32_t o = e == PK_MOD ? PK_DST(r) : r & 15u, w = e == PK_MOD ? PK_MOD + o : e; /* (o: the
* destination, or an effect's TARGET) */
uint32_t hw = e == PK_MOD ? PK_SHP(pk.we[s], r) : (r >> 4) & 3u;
if (!(kb_layer & ((1u << 27) - 1u))) {
ui_message("HOLD A KEY");
return;
}
if (k == 2u && e == PK_MOD) /* (AMOUNT: as far as it is turned) */
x = (x & 0xE0u) | ((uint32_t)clamp(pk_amt(x) + d, -10, 10) & 31u);
d = d > 0 ? 1 : -1;
if (k == 0u) {
w = (w + PK_MOD + PD_N + (uint32_t)d) % (PK_MOD + PD_N);
e = w < PK_MOD ? w : PK_MOD;
o = w < PK_MOD ? 0u : w - PK_MOD;
if (e == PK_MOD && !pk_amt(x)) x = 10u | 4u << 5; /* (a new PARAM: +100 %, 1 BAR) */
hw = 0;
} else if (k == 1u && e != PF_N && e != PF_CLR)
hw = (uint32_t)clamp((int32_t)hw + d, 0, e == PK_MOD ? 11 : 2);
else if (k == 2u && pke_tgt(e))
o = (uint32_t)clamp((int32_t)o + d, 0, 8);
else if (k == 3u && e == PK_MOD)
x = (x & 31u) | (uint32_t)clamp((int32_t)(x >> 5) + d, 0, 7) << 5;
pk.we[s] = (uint8_t)((e + 1u) | (e == PK_MOD ? (hw >> 3) << 5 : 0u)); /* (HOW's fourth bit in bit 5) */
pk.wo[s] = (uint8_t)((o & 15u) | (e == PK_MOD ? hw & 7u : hw & 3u) << 4 | (o & 16u) << 3); /* (dest bit 4 in bit 7) */
pk.wx[s] = (uint8_t)x;
pke_help(s);
ui.force = 1;
}
static BTAPP_FN void pke_cards_bt(void)
{
static BTAPP_RO const char TG[9][4] = {"ALL", "SYN", "DRM", "T1", "T2", "T3", "T4", "T5", "T6"};
uint32_t s = pk.ekey % PK_KEYS, e = pke_e(s), o = pk.we[s] ? pk.wo[s] : 0u, x = pk.we[s] ? pk.wx[s] : 0u, c;
char nm[12];
if (!(kb_layer & ((1u << 27) - 1u))) { /* no key held: the slot, the way out */
nm[0] = (char)('A' + pk.eslot); nm[1] = 0;
hot_text_column(0, "SLOT", nm);
empty_column(1);
empty_column(2);
empty_column(3);
return;
}
pk_name(e, o, nm);
hot_text_column(0, "WHAT", nm);
if (e == PK_MOD) {
int32_t a = pk_amt(x) * 10;
text_column(1, "HOW", PK_SH[PK_SHP(pk.we[s], o) % 12u], VAL(1u));
nm[0] = a < 0 ? '-' : '+'; a = a < 0 ? -a : a;
nm[1] = a >= 100 ? '1' : (char)('0' + a / 10); nm[2] = a >= 100 ? '0' : (char)('0' + a % 10);
nm[3] = a >= 100 ? '0' : '%'; nm[4] = a >= 100 ? '%' : 0; nm[5] = 0;
text_column(2, "AMOUNT", nm, VAL(2u));
text_column(3, "TIME", PK_TM[x >> 5], VAL(3u));
return;
}
c = e == PF_N || e == PF_CLR;
text_column(1, "HOW", c ? "-" : PK_MD[((o >> 4) & 3u) % 3u], c ? T_DIM : VAL(1u));
text_column(2, "TARGET", pke_tgt(e) ? TG[(o & 15u) % 9u] : "-", pke_tgt(e) ? VAL(2u) : T_DIM);
empty_column(3);
}
/* OCT+ / OCT- on the FX layer: open, save; leave. 1: taken */
static BTAPP_FN int pke_oct_bt(int up)
{
char b[16] = "SAVED SLOT A";
if (!pk.edit) {
if (!up) return 0;
pke_load(pk.slot);
pk.edit = 1;
fx_lock = 1; /* (the FX layer locked open: the keys its, the map shown) */
ui_message("HOLD A KEY");
} else if (up) {
memcpy(pk_row(pk.eslot, 0), pk.we, PK_KEYS);
memcpy(pk_row(pk.eslot, 1), pk.wo, PK_KEYS);
memcpy(pk_row(pk.eslot, 2), pk.wx, PK_KEYS);
favorites.factory[6][18] = pk.eslot;
settings_save();
pk_load(); /* (the slot played now; the editor shut) */
pk.edit = 1;
b[11] = (char)('A' + pk.eslot);
ui_message(b);
ui.msg2[0] = 0;
} else {
pk.edit = 0;
fx_lock = 0; /* (back to the PUNCH IN page) */
ui.msg2[0] = 0;
}
ui.force = 1;
return 1;
}
static BTAPP_FN void pke_sel_bt(int32_t d)
{
char b[8] = "SLOT A";
(void)d;
pke_load(pk.eslot ^ 1u);
b[5] = (char)('A' + pk.eslot);
ui_message(b);
ui.force = 1;
}
static int pke_oct(int up) { if (!bt_hw_seg()) { if (up) seg_missing(); return up; } return pke_oct_bt(up); }
static __attribute__((noinline)) void layer_cards(uint32_t l)
{
char val[12];
const char *unit;
uint32_t c;
if (l == LAYER_FX && pk.edit) { /* (V10.7.65) the punch-in editor */
if (bt_hw_seg()) pke_cards_bt();
} else if (l == LAYER_FX) { /* (V10.7.59) M1..M4 (V10.7.66: "M1 CUT", ui_draw.c) */
macro_cards();
} else if (l == LAYER_GLO) { /* T1..T4 LEVEL (T5, T6 selected: T3..T6; the icon; muted: dim) */
for (c = 0; c < 4u; c++) {
uint32_t t = c + trk_base4();
param_format(&TP[P_LEVEL], trk[t].p[P_LEVEL], val, &unit);
draw_column(c, "LEVEL", val, unit, glo_sounding(t) ? VAL(c) : T_DIM, RATIO(&TP[P_LEVEL], trk[t].p[P_LEVEL]),
trk_icon(t, 1));
}
} else if (l == LAYER_SAVE) { /* the section, LOOP / SONG, SONG REC, the song row */
uint32_t n = lys.song ? lys.song - 1u : song_cur;
fmt_int(val, (int32_t)n + 1);
draw_column(0, "SONG", val, n != song_cur ? "NEXT" : "", VAL(0u), (int32_t)(n * 1000u / (NSONG - 1u)),
ICON_X_SONG);
val[0] = live.cur >= 0 ? (char)('A' + live.cur) : '-'; val[1] = 0;
text_column(1, "PART", val, live.cur >= 0 ? VAL(1u) : T_DIM);
hot_text_column(2, "PLAY", live.mode ? "SONG" : "PART");
text_column(3, "REC", live.srec == 2u ? "ON" : live.srec ? "ARM" : "OFF", live.srec ? VAL(3u) : T_DIM);
} else if (l == LAYER_REC) { /* CLICK, then empty cards */
rec_columns();
} else if (l == LAYER_EDIT) { /* (0.9.9-seq2f) ENG, No. (PRESETS), FAV (ui_draw.c) */
engine_columns();
} else if (l == LAYER_SEQ) { /* (V10.8.52) SEQ EDIT: START END (MOVE WIDTH), ACTION, AMOUNT */
uint32_t lo, n, a = (uint32_t)se_st & 127u, on = (uint32_t)seq_sel(TSEL, &lo, &n, tl_len(TSEL)), mv = (uint32_t)se_st >> 7 & 1u;
fmt_int(val, (int32_t)lo + 1);
text_column(0, mv ? "MOVE" : "START", on ? val : "ALL", on ? VAL(0u) : T_DIM);
fmt_int(val, (int32_t)(mv ? n : lo + n));
text_column(1, mv ? "WIDTH" : "END", on ? val : "ALL", on ? VAL(1u) : T_DIM);
hot_text_column(2, "ACTION", SE[a].nm);
se_amt(a, val);
text_column(3, SE[a].f == 'p' ? "MODE" : SE[a].f == '%' ? "AMOUNT" : SE[a].f == 'n' ? "64THS" : SE[a].f ? "BY" : "",
val, SE[a].f ? VAL(3u) : T_DIM);
} else { /* the page's four (SCL: LY_SCL) */
uint8_t h = ui.home, pg = ui.page, nm[sizeof ui.nmem];
memcpy(nm, ui.nmem, sizeof nm);
ui.home = 0;
ui.page = (uint8_t)page_first(LAYERS[l].fam);
page_over = ly_page(l);
draw_columns();
page_over = 0;
ui.home = h;
ui.page = pg;
memcpy(ui.nmem, nm, sizeof nm);
}
}
/* (0.8.5) a layer as a lens, as the approved mock-up (MAP . KNOBS . STATE; ALGORITHM while it is held): MAP the keys'
* map (the cells, no icons), KNOBS the four cards as gauges, STATE the key hints (the footer's until 0.8.4) and what is
* on. The header "[FX] HELD"; the breadcrumb "LENTE . MAP . FX" */
static const khint_t *layer_foot(uint32_t l)
{
return l == LAYER_FX && perf_latch_on ? FX_LATCH_FOOT : LAYERS[l].foot;
}
static void layer_knobs(uint32_t l) /* the four as gauges in their knobs' colours, the keys' words */
{
const khint_t *ft = layer_foot(l);
uint32_t c, k;
char b[48];
for (c = 0; c < 4u; c++) {
int32_t cx = CARD_X(c) + 28;
if (!ly_card[c].l[0]) {
lz_arc(cx, 50, 25, 1, 0, T_LINE, T_LINE);
continue;
}
lz_arc(cx, 50, 25, 4, ly_card[c].r < 0 ? 0 : ly_card[c].r, T_LINE,
ly_card[c].r < 0 ? T_LINE : knob_col(c, ly_card[c].r, ly_card[c].b)); /* (0.9.5 JIANT: its heat) */
GFX_HOOK_ALIGN(cx - 26, 0, cx + 26, 0, AL_H, "layer KNOBS gauge's words centred");
cv_text_in(cx - 26, 44 - AF_X_CAP_Y, 52, &AF_X, ly_card[c].l, T_MID, T_SURF);
cv_text_in(cx - 26, 54 - AF_X_CAP_Y, 52, &AF_X, ly_card[c].v, T_TEXT, T_SURF);
}
b[0] = 0;
for (k = 0; k < 3u; k++) /* "PLAY RESTART . GLO DONE": the keycaps' words */
if (ft[k].act) {
if (b[0])
str_cat(b, " \xB7 ", sizeof b - str_len(b));
str_cat(b, KC[ft[k].key % KC_COUNT].label, sizeof b - str_len(b));
str_cat(b, " ", sizeof b - str_len(b));
str_cat(b, ft[k].act, sizeof b - str_len(b));
}
GFX_HOOK_ALIGN(4, 0, 236, 0, AL_H, "layer KNOBS keys' words centred");
cv_text_in(4, 100 - AF_X_CAP_Y, 232, &AF_X, b, T_DIM, T_SURF);
}
/* STATE: "GLO . HELD", then what is on as chips, two a row (on: a THEME stripe, TEXT; off: DIM) */
static uint32_t lst_n __attribute__((section(".pool")));
static void lst_chip(const char *a, const char *v, int on)
{
int32_t x = 4 + (int32_t)(lst_n & 1u) * 117, y = 16 + (int32_t)(lst_n >> 1) * 15;
uint16_t bg = on ? T_TINT : T_RAISE;
char b[24];
if (lst_n >= 16u)
return;
lst_n++;
str_cpy(b, a, sizeof b);
if (v) {
str_cat(b, " ", sizeof b - str_len(b));
str_cat(b, v, sizeof b - str_len(b));
}
cv_rrect(x, y, 114, 13, 3, bg, T_SURF);
if (on)
cv_rect(x, y + 2, 2, 9, T_THEME);
cv_clip_text(x + 6, y + 3 - AF_X_CAP_Y, &AF_X, b, on ? T_TEXT : T_DIM, bg, 104);
}
static __attribute__((noinline)) void layer_state(uint32_t l)
{
static const char LN[] = "\0" "FX\0" "GLO\0" "SCL\0" "EDIT\0" "SEQ\0" "REC\0" "SAVE\0" "LFO"; /* (V10.8.71: packed, str_nth) */
uint32_t k, e;
char b[48], v[8];
str_cpy(b, str_nth(LN, (unsigned)(l)), sizeof b);
str_cat(b, " \xB7 HELD", sizeof b - str_len(b));
cv_text(6, 5 - AF_X_CAP_Y, &AF_X, b, T_THEME);
if (l == LAYER_FX && fx_lock)
cv_text_r(234, 5 - AF_X_CAP_Y, &AF_X, "[FX] LOCKED", T_ACCENT, T_SURF);
lst_n = 0;
if (l == LAYER_FX) { /* the lock, the tracks, the latch, the effects held */
uint32_t held = perf_kill ? 0u : perf_held | perf_latched;
static const char *const BN[5] = {"LOOP 3", "TAPE STOP", "PITCH UP", "PITCH DN", "STRETCH"};
static const uint8_t BE[5] = {PF_LP3, PF_TAPE, PF_PUP, PF_PDN, PF_STR};
lst_chip("LOCK", 0, fx_lock);
lst_chip("FX LATCH", perf_latch_on ? "ON" : "OFF", perf_latch_on);
for (e = 0; e < PF_M1; e++)
lst_chip(str_nth(PF_NAME, e), 0, (held >> e) & 1u);
for (e = 0; e < 5u; e++)
lst_chip(BN[e], 0, (held >> BE[e]) & 1u);
} else if (l == LAYER_GLO) { /* the tracks, the DRUM groups, UNDO */
for (k = 0; k < NTRK; k++) {
char t[3] = {'T', (char)('1' + k), 0};
lst_chip(t, trk[k].p[P_MUTE] ? "MUTE" : k >= trk_live ? "ASLEEP" : "ON", !trk[k].p[P_MUTE] && k < trk_live);
}
for (k = 0; glo_drums() && k < 4u; k++)
lst_chip(GLO_GROUP[k], (dx_mute >> k) & 1u ? "MUTE" : "ON", !((dx_mute >> k) & 1u));
lst_chip("UNDO", undo_ok ? "READY" : "-", undo_ok);
lst_chip("A4", "RESOUND", 1);
} else if (l == LAYER_REC) {
b[0] = 'T'; b[1] = (char)('1' + song.sel); b[2] = 0;
lst_chip("ARMED", b, (song.rec >> song.sel) & 1u);
lst_chip(b, rec_clearable() ? "SEQUENCE" : "EMPTY", rec_clearable());
lst_chip("CLICK", rl_name(0, rp_get(RP_CLICK)), rp_get(RP_CLICK) != 0u);
lst_chip("COUNT-IN", COUNTIN_N[rp_get(RP_COUNTIN) % 3u], rp_get(RP_COUNTIN) != 0u);
} else if (l == LAYER_SAVE) {
fmt_int(v, (int32_t)song_cur + 1);
lst_chip("SONG", v, 1);
v[0] = live.cur >= 0 ? (char)('A' + live.cur) : '-'; v[1] = 0;
lst_chip("PART", v, live.cur >= 0);
str_cpy(b, "CHAIN ", sizeof b);
for (k = 0; k < lys.nqc && k < 8u; k++) { char c[2] = {(char)('A' + lys.qc[k]), 0}; str_cat(b, c, sizeof b - str_len(b)); }
lst_chip(lys.nqc >= 2u ? b : "CHAIN -", 0, lys.nqc >= 2u);
lst_chip(live.mode ? "SONG" : "PART", 0, 1);
lst_chip("SONG REC", live.srec == 2u ? "ON" : live.srec ? "ARM" : "OFF", live.srec != 0u);
if (chain.running) {
fmt_int(v, (int32_t)chain.row + 1);
lst_chip("ROW", v, 1);
fmt_int(v, chain.remaining);
lst_chip("BARS LEFT", v, 1);
}
} else { /* the four knobs' values; the track's sound; DRUM's sounds */
for (k = 0; k < 4u; k++)
if (ly_card[k].l[0])
lst_chip(ly_card[k].l, ly_card[k].v, 1);
b[0] = 'T'; b[1] = (char)('1' + song.sel); b[2] = ' ';
str_cpy(b + 3, trk_engp(TSEL)->name, sizeof b - 3);
lst_chip(b, 0, 1);
sound_name(TSEL, b);
if (b[0])
lst_chip(b, 0, 1);
for (k = 0; (l == LAYER_EDIT || l == LAYER_SEQ) && drum_track(TSEL) && k < NLANE; k++)
lst_chip(drum_lane_abbr(TSEL, k), l == LAYER_SEQ ? (k == ui.lane % NLANE ? "LANE" : 0) : dx_lane_muted(k) ? "MUTE" : "ON",
l == LAYER_SEQ ? k == ui.lane % NLANE : !dx_lane_muted(k));
}
}
static __attribute__((noinline)) void draw_layer(void)
{
uint32_t l = ui.layer % LAYER_N, sig = l * 7919u + ux.gen * 977u, k;
for (fx_hk = 0, k = 0; k < 27u; k++) /* (V10.8.9) the FX layer's key held (+ 1), the highest */
if ((kb_layer & fm1_in.notes) >> k & 1u)
fx_hk = (uint8_t)(k + 1u);
if (l == LAYER_FX && !pk.edit && fx_hk) { /* (V10.8.13) physically held: the banner's words, its time */
char nm[12];
ly_keyname(LAYER_FX, key_black(fx_hk - 1u), key_place(fx_hk - 1u), nm);
if (nm[0]) bn_set(nm, fx_hk - 1u, 2);
}
layer_cards(l);
if (l == LAYER_FX)
{
uint32_t s;
sig += (perf_kill ? 0u : perf_held | perf_latched) * 31u + perf_latch_on * 11u + perf_act * 131u + perf_avail() * 7u;
sig += bn_on(2) * 524287u + (uint32_t)pfx_rec_ok() * 29u + pk.edit * 3u + pk.ekey * 4099u + (kb_layer != 0u) * 65537u + pk.mod * 17u + pk.pkey * 257u; /* (V10.8.5: the
* editor's key lit while pressed, its keys' names as set) */
for (s = 0; pk.edit && s < PK_KEYS; s++) sig = (sig ^ pk.we[s] ^ (uint32_t)pk.wo[s] << 8) * 16777619u;
}
else if (l == LAYER_GLO)
sig += perf_solo * 31u + (uint32_t)song.g[G_CLOCK] * 5u +
(uint32_t)(trk[0].p[P_MUTE] | trk[1].p[P_MUTE] << 1 | trk[2].p[P_MUTE] << 2 | trk[3].p[P_MUTE] << 3 |
trk[4].p[P_MUTE] << 4 | trk[5].p[P_MUTE] << 5) * 131u +
((uint32_t)dx_mute * 2u + (uint32_t)glo_drums()) * 4099u;
else if (l == LAYER_SCL)
sig += (uint32_t)TSEL->p[P_SCALE] * 31u;
else if (l == LAYER_REC)
sig += (uint32_t)ui_rec_prefs * 31u + (uint32_t)chain_busy() * 3u + (uint32_t)rec_clearable() * 5u + song.sel * 977u +
(uint32_t)TSEL->p[P_HRQ] * 131u + (uint32_t)undo_ok * 4099u;
else if (l == LAYER_SAVE)
sig += (uint32_t)(live.cur + 1) * 31u + (uint32_t)(live.req + 1) * 131u + live.srec * 7u + live.mode * 11u +
live.dirty * 977u + lys.nqc * 4099u + (chain.running ? chain.row * 13u + chain.remaining * 17u : 0u) +
(lys.song * 8u + song_cur) * 65537u;
else if (l == LAYER_SEQ)
sig += (uint32_t)drum_track(TSEL) * 31u + ui.lane * 5u + (uint32_t)chain_busy() * 3u + steps_hash(TSEL) * 131u + song.sel * 977u +
(uint16_t)cp_sel * 7u + ui.bank * 13u + ui.cursor * 17u + (song.playing ? pr_head_step(TSEL, 0) * 4099u : 0u) +
(uint32_t)TSEL->p[P_SLEN] * 65537u;
else
sig += snd_id() * 31u + (uint32_t)preset_favorite() * 13u + (uint32_t)chain_busy() * 3u + (uint32_t)(project_recall_slot() + 1) * 5u + dx_mute * 7919u +
(uint32_t)drum_track(TSEL) * 11u + up_gen * 101u;
if (ui.force || sig != ui.layer_sig) {
ui.layer_sig = sig;
cv_begin(240, graph_h(), T_BG);
cv_rrect(4, 0, 232, (int32_t)graph_h(), 6, T_SURF, T_BG);
cv_bg = T_SURF;
if (l == LAYER_FX && !pk.edit) ly_fx_cells(); /* (V10.7.77, the owner) FX: the effects as cells, as before 0.8.9 */
else if (l == LAYER_SEQ) { /* (V10.8.52) SEQ EDIT: the roll (the lanes), the steps selected */
uint32_t lo, n, i, dr = (uint32_t)drum_track(TSEL), on = (uint32_t)seq_sel(TSEL, &lo, &n, tl_len(TSEL));
int32_t x, w;
if (dr) graph_grid(TSEL, T_THEME); else graph_roll(TSEL, 0);
for (i = 0; on && i < 16u; i++)
if (ui.bank * 16u + i >= lo && ui.bank * 16u + i < lo + n) {
seq_col(dr, i, &x, &w);
cv_rect(x, 0, w + 1, 3, T_ACCENT);
}
} else ly_piano(l); /* MAP: the keyboard (V10.7.66: KNOBS / STATE gone) */
if (l == LAYER_FX && !pk.edit && bn_on(2)) /* (V10.8.9, the owner) the punch-in held, large (V10.8.13: */
hold_banner(bn_nm, bn_k, pfx_rec_ok()); /* 0.6 s after the key, never a latch's) */
cv_blit(0, graph_y());
}
draw_tabs(); /* (0.8.5: MAP . KNOBS . STATE, the breadcrumb) */
draw_foot();
}
static void tl_take(const track_t *t); /* (V10.8.8: GLO > LIVE, ui_live.c, gone; its prototypes stay) */
static uint16_t pk_fill(uint32_t st, int blk, int n, uint16_t *ink);
static void tracks_edit(uint32_t slot, int32_t steps);