From a3dfb6b5e15b614195086eebc1dbf6561ef4ad68 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 14:38:20 +0000 Subject: [PATCH 1/2] KEYS LAYOUT: the pads as the key's degrees, chords on a chord track A FUNC menu row (PIANO / SCALE). On SCALE the lower KEYS pads are the key's degrees from the root, the upper pads the same an octave up; on a chord track a lower pad plays its degree's triad and names it. Saved as one byte on the end of PROJECT.BIN's MIDI section; an older file reads as PIANO. Host test, scenario_keyslayout.sh, W114, docs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Tw2EaEK2oaJWJMdGQTNLPf --- CHANGELOG.md | 6 ++ app/app.hpp | 4 ++ app/commands.hpp | 3 + app/engine.cpp | 4 ++ app/storage.cpp | 2 + app/ui_browsers.hpp | 69 +++++++++++++++---- app/ui_perfmix.hpp | 13 +++- core/help.cpp | 14 ++++ core/project.cpp | 9 ++- core/project.hpp | 7 ++ docs/CHEATSHEET.md | 7 +- docs/CONTROLS.md | 7 ++ docs/DESIGN_NOTES.md | 21 ++++++ docs/FEATURES.md | 1 + docs/MANUAL.md | 10 ++- docs/UNIT_CHECKLIST.md | 12 ++++ tests/scenario_keyslayout.sh | 128 +++++++++++++++++++++++++++++++++++ tests/test_app.cpp | 2 +- tests/test_project.cpp | 50 ++++++++++++-- tests/test_storage.cpp | 7 +- tests/test_ui.cpp | 88 +++++++++++++++++++++++- 21 files changed, 434 insertions(+), 30 deletions(-) create mode 100755 tests/scenario_keyslayout.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe32500..318b9d36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,12 @@ the project file format or the controls. swing and a section's BPM still play. Off in a new project, saved with the project: one byte on the end of PROJECT.BIN's MIDI section, which older builds ignore and which reads as off in an older file. +- **KEYS LAYOUT.** A FUNC menu row under TEMPO GUARD. `SCALE` turns KEYS's pads into the key: + the lower pads are its degrees from the root, the upper pads the same an octave up, so no pad + is out of key. On a chord track (VA POLY, WAVE POLY, FM4, MID) a lower pad plays its degree's + triad and names it (`T7 A3 MIN`). `PIANO` in a new project; saved as one byte on the end of + PROJECT.BIN's MIDI section, which older builds ignore and which reads as `PIANO` in an older + file. - **GEN ALL**, the FUNC menu's last row (FUNC+HOME, UP, OK): a new part on every unmuted track at once, each of its own GEN TYPE, with the track menu's DENSITY, RANGE, LEAP and WHAT. One undo level takes every track back; the menu stays open, so OK again is the next idea. LOAD DEMO is diff --git a/app/app.hpp b/app/app.hpp index ec7f8610..84d6eb3d 100644 --- a/app/app.hpp +++ b/app/app.hpp @@ -1018,6 +1018,10 @@ class Strata : public enaga::App { int16_t pad_held_note_[kPianoPads] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // KEYS: piano pads uint8_t pad_held_track_[kPianoPads] = {}; + // A SCALE chord pad's notes (pad_chord), so the release lets each go; 0 or 1 is one note, + // pad_held_note_'s. + uint8_t pad_chord_notes_[kPianoPads][kChordMaxNotes] = {}; + uint8_t pad_chord_count_[kPianoPads] = {}; int macro_learn_ = -1; // MACRO LEARN: the macro EDIT's pushes assign to bool learn_ended_ = false; // and when it ended, for the CLR guard uint32_t learn_ended_at_ms_ = 0; diff --git a/app/commands.hpp b/app/commands.hpp index d9f43703..cb613339 100644 --- a/app/commands.hpp +++ b/app/commands.hpp @@ -384,6 +384,9 @@ enum class Cmd : uint8_t { // TEMPO GUARD (core/project.hpp, `tempo_guard`): a: 1 on, 0 off. On, a plain turn or tap of // VALUE leaves the tempo alone (app/ui_gestures.hpp). Saved with the project. set_tempo_guard, + // KEYS LAYOUT (core/project.hpp, `keys_scale`): a: 1 SCALE, 0 PIANO. Only the pads read it + // (app/ui_browsers.hpp); the engine keeps it so it is saved with the project. + set_keys_layout, // The user's MIDI CH (Enaga's setting, 0-15), which only the main context reads: posted at // start and whenever it changes. a: the channel. Live state, not saved. set_midi_channel, diff --git a/app/engine.cpp b/app/engine.cpp index c6a1fc7c..3b709305 100644 --- a/app/engine.cpp +++ b/app/engine.cpp @@ -1591,6 +1591,10 @@ bool Engine::apply_notes(const Command &command, int track, int) { project_.settings.tempo_guard = command.a != 0; break; + case Cmd::set_keys_layout: + project_.settings.keys_scale = command.a != 0; + break; + case Cmd::set_midi_channel: midi_channel_ = uint8_t(command.a & 0x0Fu); break; diff --git a/app/storage.cpp b/app/storage.cpp index 339ccc16..d7364c84 100644 --- a/app/storage.cpp +++ b/app/storage.cpp @@ -203,6 +203,8 @@ bool mutates_project(Cmd cmd) { case Cmd::set_program_out: // And TEMPO GUARD, after it. case Cmd::set_tempo_guard: + // And KEYS LAYOUT, after that. + case Cmd::set_keys_layout: // A LOCK tap puts the send and master bytes and the live mutes back. case Cmd::lock_tap: // Track Launch: the lane sources and pins are PROJECT.BIN's section 8, and CAPTURE moves diff --git a/app/ui_browsers.hpp b/app/ui_browsers.hpp index 01434f76..9488f012 100644 --- a/app/ui_browsers.hpp +++ b/app/ui_browsers.hpp @@ -6,19 +6,47 @@ // --- KEYS: the pads as a piano --------------------------------------- - // The note a piano pad plays: C of the current octave plus its semitone, -1 for the two - // octave pads. Chromatic, as a keyboard is; the LEDs show which notes are in the scale. + // KEYS LAYOUT (FUNC menu): the pads as a piano, or as the key's scale. + bool keys_scale() const { return engine_.project().settings.keys_scale; } + + // The note a piano pad plays, -1 for the two octave pads. PIANO: C of the current octave + // plus its semitone, chromatic as a keyboard is; the LEDs show which notes are in the scale. + // SCALE: the lower pads are the key's degrees from the root of the current octave, the eighth + // the octave, and an upper pad plays the lower pad to its left an octave up, so every pad is + // in the key (review 2026-11-29, proposal 5). Under CHROMATIC a degree is a semitone. int pad_note(int pad) const { if (pad < 0 || pad >= kPianoPads || kPianoSemitone[pad] < 0) return -1; - return clamp_int(kPadOctaveNote + keys_octave_ * 12 + kPianoSemitone[pad], 0, 127); + const int c = kPadOctaveNote + keys_octave_ * 12; + if (!keys_scale()) return clamp_int(c + kPianoSemitone[pad], 0, 127); + const int root = clamp_int(c + int(engine_.key_root() % 12), 0, 127); + const int note = int(scale_step(uint8_t(root), engine_.key_root(), + int(engine_.key_scale()), pad / 2)); + return clamp_int(note + (pad % 2 == 1 ? 12 : 0), 0, 127); + } + + // SCALE on a chord track (the POLY three, MID): a lower pad plays its degree's triad, the + // key's own (core/chord.hpp: a major stack folded into the key is the diatonic triad on + // every degree). The upper pads stay single notes, a melody over the chords. Writes the + // notes into `notes` and returns how many: 1 where a pad plays one note. + int pad_chord(int pad, uint8_t note, uint8_t *notes) const { + notes[0] = note; + if (!keys_scale() || pad % 2 == 1 || !records_chords(selected_)) return 1; + const int n = chord_expand(note, chord_pack(ChordType::major, 0), engine_.key_root(), + int(engine_.key_scale()), notes, 3); + return n < 1 ? 1 : n; } void release_pad(int pad) { if (pad < 0 || pad >= kPianoPads || pad_held_note_[pad] < 0) return; - post(Cmd::release_note, uint8_t(pad_held_track_[pad]), 0, uint8_t(pad_held_note_[pad])); + const int count = pad_chord_count_[pad] < 1 ? 1 : int(pad_chord_count_[pad]); + for (int i = 0; i < count; i++) { + const uint8_t note = count == 1 ? uint8_t(pad_held_note_[pad]) : pad_chord_notes_[pad][i]; + post(Cmd::release_note, uint8_t(pad_held_track_[pad]), 0, note); + record_note_up(pad_held_track_[pad], note); + } mod_pressure_release(pad_held_track_[pad]); - record_note_up(pad_held_track_[pad], uint8_t(pad_held_note_[pad])); pad_held_note_[pad] = -1; + pad_chord_count_[pad] = 0; // The macro bend this pad's pressure made goes back to where the knob left it. if (pressure_pad_ == pad) { pressure_pad_ = -1; @@ -26,9 +54,9 @@ } } - // A piano pad played: the note held until the pad comes up, at the pad's own velocity, on - // the selected track, recorded like a STEP key in KEYS. The two pads with no black key walk - // the octave. + // A piano pad played: the note (or SCALE's chord) held until the pad comes up, at the pad's + // own velocity, on the selected track, recorded like a STEP key in KEYS: a chord's notes + // join on one step (record_note). The two pads with no black key walk the octave. void play_pad(int pad, int velocity) { if (kPianoSemitone[pad] == kPadOctaveDown || kPianoSemitone[pad] == kPadOctaveUp) { walk_keys_octave(kPianoSemitone[pad] == kPadOctaveDown ? -1 : +1); @@ -37,22 +65,35 @@ const uint8_t note = uint8_t(pad_note(pad)); const uint8_t vel = uint8_t(velocity < 1 ? 1 : (velocity > 127 ? 127 : velocity)); release_pad(pad); - pad_held_note_[pad] = int16_t(note); + uint8_t notes[kChordMaxNotes]; + const int count = pad_chord(pad, note, notes); + pad_held_note_[pad] = int16_t(notes[0]); pad_held_track_[pad] = uint8_t(selected_); - post(Cmd::trigger_note, uint8_t(selected_), 0, note, vel, 1); - record_note(selected_, note, vel); + pad_chord_count_[pad] = uint8_t(count); + for (int i = 0; i < count; i++) { + pad_chord_notes_[pad][i] = notes[i]; + post(Cmd::trigger_note, uint8_t(selected_), 0, notes[i], vel, 1); + record_note(selected_, notes[i], vel); + } char *out = notice_buffer_; append(out, "T"); append_number(out, uint32_t(selected_) + 1); append(out, " "); - append(out, note_name(note)); - append_number(out, uint32_t(note_octave(note) < 0 ? 0 : note_octave(note))); + append(out, note_name(notes[0])); + append_number(out, uint32_t(note_octave(notes[0]) < 0 ? 0 : note_octave(notes[0]))); + // A chord says its quality from its third and fifth: MIN, MAJ or DIM. + if (count >= 3) { + const int third = int(notes[1]) - int(notes[0]); + const int fifth = int(notes[2]) - int(notes[0]); + append(out, fifth == 6 ? " DIM" : (third == 3 ? " MIN" : (third == 4 ? " MAJ" : " CHD"))); + } *out = 0; notice(notice_buffer_); } // KEYS lights the pads as a keyboard: the root bright, the scale's other notes dim in the // selected track's colour, the rest dark, a held pad white; the two octave pads dim white. + // In SCALE every pad is in the key, so the roots are bright and the rest dim. void light_piano_pads() { const uint8_t root = engine_.key_root(); const int scale = int(engine_.key_scale()); @@ -61,7 +102,7 @@ const int note = pad_note(pad); if (note < 0) { leds_.pad(pad, 2, 2, 2); continue; } if (pad_held_note_[pad] >= 0) { leds_.pad(pad, 10, 10, 10); continue; } - const bool at_root = note % 12 == root; + const bool at_root = note % 12 == root % 12; const bool in_scale = scale_fold(uint8_t(note), root, scale) == uint8_t(note); const uint8_t level = at_root ? 10 : (in_scale ? 2 : 0); leds_.pad(pad, uint8_t(colour.r * level / 10), uint8_t(colour.g * level / 10), diff --git a/app/ui_perfmix.hpp b/app/ui_perfmix.hpp index 80173d70..b94c2ec8 100644 --- a/app/ui_perfmix.hpp +++ b/app/ui_perfmix.hpp @@ -18,7 +18,7 @@ // RELOAD SAMPLE) are in GRID's track menu (app/ui_trackmenu.hpp). enum class MenuItem : uint8_t { save, jam, arr, click, count_in, rec_mode, quantize, autofill, glide, transpose, loop_len, chain, song, arr_undo, - prog_out, tempo_guard, save_as, open, kits, fresh, reload, clear, demo, gen_all, + prog_out, tempo_guard, keys_layout, save_as, open, kits, fresh, reload, clear, demo, gen_all, count }; static constexpr int kMenuItems = int(MenuItem::count); static constexpr int kMenuRows = 9; @@ -37,6 +37,7 @@ case MenuItem::song: return "CHAIN END"; case MenuItem::prog_out: return "PROG CHG OUT"; case MenuItem::tempo_guard: return "TEMPO GUARD"; + case MenuItem::keys_layout: return "KEYS LAYOUT"; case MenuItem::autofill: return "AUTO-FILL"; case MenuItem::quantize: return "QUANTIZE"; case MenuItem::rec_mode: return "REC MODE"; @@ -68,6 +69,9 @@ case MenuItem::tempo_guard: append(out, tempo_guarded() ? "ON" : "OFF"); break; + case MenuItem::keys_layout: + append(out, keys_scale() ? "SCALE" : "PIANO"); + break; case MenuItem::autofill: append(out, auto_fill_name(engine_.auto_fill())); break; @@ -806,6 +810,13 @@ notice_logged(on ? "TEMPO GUARD ON" : "TEMPO GUARD OFF"); break; } + case MenuItem::keys_layout: { + // A switch, as TEMPO GUARD: PIANO or SCALE (app/ui_browsers.hpp, pad_note). + const bool scale = !keys_scale(); + post(Cmd::set_keys_layout, 0, 0, scale ? 1 : 0); + notice_logged(scale ? "KEYS SCALE" : "KEYS PIANO"); + break; + } case MenuItem::autofill: { // Off, 4, 8 or 16 bars. It wraps, since "off" is one of the four rather than an // end stop. diff --git a/core/help.cpp b/core/help.cpp index 5cde8dda..724b7678 100644 --- a/core/help.cpp +++ b/core/help.cpp @@ -478,6 +478,18 @@ constexpr Text kMenu = {"FUNC MENU:", { "FUNC+REC TWICE JAM", }}; +// KEYS LAYOUT, the FUNC menu's row that turns the KEYS pads from a piano into the key's scale. +constexpr Text kKeysLayout = {"KEYS LAYOUT:", { + "FUNC MENU KEYS LAYOUT", + "PIANO A KEYBOARD", + "SCALE LOWER PADS ARE", + "DEGREES OF THE KEY", + "UPPER PADS OCTAVE UP", + "POLY OR MID TRACK:", + "LOWER PAD PLAYS CHORD", + "SAVED WITH PROJECT", +}}; + // TEMPO GUARD, the FUNC menu's row that keeps VALUE off the tempo during a set. constexpr Text kTempoGuard = {"TEMPO GUARD:", { "ON: VALUE TURN OR TAP", @@ -918,6 +930,7 @@ bool own_page(const HelpPlace &place, int page, char title[kHelpChars + 1], list[listed++] = &kKeysPads; knobs = true; list[listed++] = &kKeysLights; + list[listed++] = &kKeysLayout; list[listed++] = &kTrackMenu; list[listed++] = &kZones; break; @@ -954,6 +967,7 @@ bool own_page(const HelpPlace &place, int page, char title[kHelpChars + 1], list[listed++] = &kGenAll; list[listed++] = &kArrRec; list[listed++] = &kTempoGuard; + list[listed++] = &kKeysLayout; break; case HelpScreen::prep: list[listed++] = &kPrep; diff --git a/core/project.cpp b/core/project.cpp index 39ee3b5c..85c9ea4c 100644 --- a/core/project.cpp +++ b/core/project.cpp @@ -366,7 +366,8 @@ constexpr uint32_t kProjectSongOffset = kProjectLiveOffset + kProjectLiveBytes; // Then TEMPO GUARD (2026-11-30); a section that stops before it is a file with the guard off. constexpr uint32_t kProjectMidiBytesV1 = uint32_t(kTracks); // MIDI OUT channel per track constexpr uint32_t kProjectMidiBytesV2 = kProjectMidiBytesV1 + 1; -constexpr uint32_t kProjectMidiBytes = kProjectMidiBytesV2 + 1; +constexpr uint32_t kProjectMidiBytesV3 = kProjectMidiBytesV2 + 1; // TEMPO GUARD +constexpr uint32_t kProjectMidiBytes = kProjectMidiBytesV3 + 1; // KEYS LAYOUT constexpr uint32_t kProjectMidiOffset = kProjectSongOffset + kProjectSongBytes; // EVOLVE: each track's period, then mode, mutation and amount; then (2026-11-29) each track's // GEN TYPE on the end, which a section from before it lacks: there every track offers its @@ -618,6 +619,7 @@ SerializeResult project_write(const Project &project, uint8_t *buffer, uint32_t for (int t = 0; t < kTracks; t++) w.u8(s.midi_out[t]); w.u8(s.program_out ? 1 : 0); w.u8(s.tempo_guard ? 1 : 0); + w.u8(s.keys_scale ? 1 : 0); for (int t = 0; t < kTracks; t++) w.u8(s.evolve_period[t]); w.u8(s.evolve_mode); w.u8(s.evolve_kind); @@ -885,6 +887,7 @@ SerializeResult project_read(Project &project, const uint8_t *buffer, uint32_t s for (int t = 0; t < kTracks; t++) s.midi_out[t] = kMidiOutOff; s.program_out = false; s.tempo_guard = false; + s.keys_scale = false; if (offset[5] != 0) { if (!r.seek(kHeaderBytes + offset[5])) return refuse(SerializeResult::malformed); for (int t = 0; t < kTracks; t++) { @@ -895,7 +898,9 @@ SerializeResult project_read(Project &project, const uint8_t *buffer, uint32_t s // changes to gear nobody asked to have them. s.program_out = length[5] >= kProjectMidiBytesV2 && r.u8() == 1; // TEMPO GUARD, the same way: only 1 is on, and a section without it is off. - s.tempo_guard = length[5] >= kProjectMidiBytes && r.u8() == 1; + s.tempo_guard = length[5] >= kProjectMidiBytesV3 && r.u8() == 1; + // KEYS LAYOUT likewise: only 1 is SCALE. + s.keys_scale = length[5] >= kProjectMidiBytes && r.u8() == 1; if (!r.ok()) return refuse(SerializeResult::truncated); } diff --git a/core/project.hpp b/core/project.hpp index 542262f8..f580b2f2 100644 --- a/core/project.hpp +++ b/core/project.hpp @@ -840,6 +840,13 @@ struct ProjectSettings { // after PROG CHG OUT: a set setting, like it. Off by default and in an older file. bool tempo_guard = false; + // KEYS LAYOUT (FUNC menu; review 2026-11-29, proposal 5): false the pads are a piano, true + // they are the key's scale -- the lower eight its degrees and the octave, the upper pads the + // lower pad to their left an octave up, and on a chord track (the POLY three, MID) a lower + // pad its degree's triad. How the player plays, so saved with TEMPO GUARD on the end of the + // MIDI section. PIANO in an older file. + bool keys_scale = false; + // EVOLVE (core/evolve.hpp), saved so a set comes back evolving (Roland, 2026-11-27). Each // track's period as kEvolvePeriod's index (0 OFF, then 1, 2, 4 or 8 loops), and the mode, // mutation and amount every track shares. The mutation and amount are also PERFORM's MUTATE diff --git a/docs/CHEATSHEET.md b/docs/CHEATSHEET.md index d09d5fbb..c3587cf5 100644 --- a/docs/CHEATSHEET.md +++ b/docs/CHEATSHEET.md @@ -38,7 +38,7 @@ pads and the performance mixer. | --- | --- | --- | | GRID | HOME (from anywhere) | All 8 tracks; STEP keys edit the selected track | | KEYS | HOME twice quickly (double-tap) | The pads are a piano (lower white, upper black keys), the STEP keys steps, on the selected track | -| FUNC menu | FUNC+HOME ("system") | The project-wide rows: save, JAM REC, ARR REC, click, count-in, REC MODE, quantize, auto-fill, FX glide, TRANSPOSE (scale or semitones), loop length, chain, song, ARR UNDO, PROG CHG OUT, TEMPO GUARD, save as, open, kits, new, reload, clear pattern, load demo, GEN ALL (a part on every unmuted track, one undo level) | +| FUNC menu | FUNC+HOME ("system") | The project-wide rows: save, JAM REC, ARR REC, click, count-in, REC MODE, quantize, auto-fill, FX glide, TRANSPOSE (scale or semitones), loop length, chain, song, ARR UNDO, PROG CHG OUT, TEMPO GUARD, KEYS LAYOUT, save as, open, kits, new, reload, clear pattern, load demo, GEN ALL (a part on every unmuted track, one undo level) | | EDIT | EDIT | The selected track's sound: pages SRC, FLTR, AMP, FX, LFO, ARP, and on the VA, WAVE, FM4 and GRAIN machines ENV and OSC, and SCAN on the WAVE machines | | MACHINE | FUNC+EDIT | Pick the machine on each track, and its MIDI OUT channel | | KIT | FUNC+EDIT twice, or the menu's KITS | Save and recall whole kits: 16 slots on the card, shared by all projects | @@ -202,7 +202,7 @@ Page 1 NOTE VEL LEN MICR, page 2 PROB COND RTCH RAMP, page 3 ACNT SLID CHRD. | FUNC menu | Row | Change a setting row | — | — | A: row, B: change | Run the row / close | — | **STEP lights:** a trig is green as bright as its velocity (soft, medium, loud, accent), blinks with a condition or probability, is amber with locks; red = trigless, bright red = the playhead. -**KEYS:** the pads are a piano: lower 1-8 C D E F G A B C, upper C# D# (octave down) F# G# A# (octave up), at the pad's velocity, held while down, pressure bends macro A; lit as a keyboard (root bright, scale dim, held white); FUNC + pad keeps its usual job. The STEP keys are the track's steps, as on GRID, and the pad-row keys their step page; LEFT/RIGHT or the two octave pads change the octave. Letting go of a pad also releases that note if the sequencer is playing it on the same track. +**KEYS:** the pads are a piano: lower 1-8 C D E F G A B C, upper C# D# (octave down) F# G# A# (octave up), at the pad's velocity, held while down, pressure bends macro A; lit as a keyboard (root bright, scale dim, held white); FUNC + pad keeps its usual job. The STEP keys are the track's steps, as on GRID, and the pad-row keys their step page; LEFT/RIGHT or the two octave pads change the octave. Letting go of a pad also releases that note if the sequencer is playing it on the same track. FUNC menu KEYS LAYOUT SCALE: lower pads the key's degrees, upper pads the same an octave up, a chord track's lower pads its triads. **PROJECT:** STEP 1-16 queue that slot of the shown bank; the pad-row keys change the shown bank. On the slots a tap on OK queues the one under the cursor and a hold (0.5 s) opens the pattern menu: COPY, PASTE, CLEAR, DOUBLE (doubles every track up to 64 steps, copying the steps). @@ -214,7 +214,8 @@ three throw away unsaved work, so each needs OK twice within 2 s (OK AGAIN: RELO NEW, OK AGAIN: DEMO). NEW is empty; LOAD DEMO is the factory demo a first start plays. **FUNC menu (FUNC+HOME):** SAVE, JAM REC, ARR REC, CLICK, COUNT-IN, REC MODE, QUANTIZE, AUTO-FILL, FX GLIDE, TRANSPOSE (SCALE or SEMI), LOOP LEN, CHAIN, CHAIN END, ARR UNDO, PROG CHG OUT, -TEMPO GUARD (ON: VALUE's turn and tap leave the tempo; saved), SAVE AS, +TEMPO GUARD (ON: VALUE's turn and tap leave the tempo; saved), KEYS LAYOUT (PIANO or SCALE: +the pads as the key's degrees, chords on a chord track's lower pads; saved), SAVE AS, OPEN PROJECT, KITS, NEW PROJECT, RELOAD PROJECT, CLEAR PATTERN, LOAD DEMO, GEN ALL. It always opens on SAVE: DOWN once is JAM REC, twice ARR REC, three times CLICK; the list wraps, so UP once is GEN ALL (GENERATE on every unmuted track, each of its own TYPE, one undo level; OK again diff --git a/docs/CONTROLS.md b/docs/CONTROLS.md index 14734e9f..8fcd77d0 100644 --- a/docs/CONTROLS.md +++ b/docs/CONTROLS.md @@ -127,6 +127,12 @@ HOME "system", PLAY "◀◀", STOP "▶▶", MIXER "fx", EDIT "rec src". a keyboard: the root bright in the track's colour, the scale's other notes dim, the rest dark, a held pad white, the two octave pads dim white. The octave is LEFT/RIGHT and the two octave pads; the STEP keys are steps (D12), so you play on the pads and edit at once. + **KEYS LAYOUT** (FUNC menu) `SCALE` turns the pads into the key instead (review 2026-11-29, + proposal 5): lower pad n is the key's degree n from the root of the current octave (the + eighth the octave), the upper pad to its right the same degree an octave up, every pad in + the key; the two octave pads stay. On a chord track (VA POLY, WAVE POLY, FM4, MID) a lower + pad plays its degree's triad in the key and says it (`T7 A3 MIN`); the upper pads stay + single notes, a melody over the chords. Every pad lights as a scale note, the roots bright. 2. **FUNC + something is either the key's printed second label or a performance move.** The rare setup actions are in the FUNC menu, named on the screen, not on chords that change from page to page. @@ -189,6 +195,7 @@ FUNC + EDIT twice is KIT. | ARR UNDO | swaps the chain the last ARR REC take replaced back in (`ARR UNDONE`); OK again brings the take back (`ARR REDONE`), unless the take captured launched lanes: then the undo also empties the slots it captured into and is final. `NO ARR TO UNDO` with none, or during a take | | | PROG CHG OUT | | `OFF` (a new project) / `ON`: a program change on MIDI CH every time the playing pattern changes, the pattern's number 0-127. Saved with the project | | TEMPO GUARD | | `OFF` (a new project) / `ON`: a plain turn or tap of VALUE where it would set the tempo changes nothing and says `TEMPO GUARD 130.0`; turn the row off to change the tempo. The nudge, VariSpeed, swing and a section's BPM still play (review 2026-11-29, proposal 9; Roland chose this over push + turn, which is swing, 2026-11-30). `EXT CLOCK` first under an outside clock. Saved with the project | +| KEYS LAYOUT | | `PIANO` (a new project) / `SCALE`: KEYS's pads as a keyboard, or as the key's degrees with chords on a chord track's lower pads (`KEYS SCALE`, `KEYS PIANO`). Saved with the project | | SAVE AS | PROJECTS page with the name entry open | | | OPEN PROJECT | PROJECTS page; OK twice there opens | | | KITS | the kit browser | | diff --git a/docs/DESIGN_NOTES.md b/docs/DESIGN_NOTES.md index 314fd69b..2a1d7843 100644 --- a/docs/DESIGN_NOTES.md +++ b/docs/DESIGN_NOTES.md @@ -740,3 +740,24 @@ rest are on the backlog with what each needs first. Measured and left alone: free-running oscillator phases on VA POLY (a stab's level then varies 1.7 dB from hit to hit), oversampling anywhere, and anti-aliasing the insert chain's DRV and the drum bus clip (their fold-over is at -40 dB or lower). + +## KEYS LAYOUT + +The second review's proposal 12 (from 2026-11-29's proposal 5): a pad layout where nothing is out +of key, for playing chords and lines without a keyboard player's hands. + +- **A FUNC menu row, not a gesture.** It is a setting a player picks once for a project, as + TEMPO GUARD is, and a row is named on the screen. One byte on the end of PROJECT.BIN's MIDI + section; an older file reads as `PIANO`. +- **Lower pads the degrees, upper pads an octave up.** Eight lower pads hold a scale's seven + degrees and the octave. The upper pad between two lower pads plays the left one an octave up, + so the hand that plays a chord below finds the melody above it. The two pads that are octave + down and up on the piano keep that job, so pads 3 and 7 of the upper row are not notes here + either. CHROMATIC has a semitone per degree. +- **Chords only on lower pads of chord tracks.** A chord track (`records_chords`: the POLY three + and MID) plays the diatonic triad, `chord_expand` with a major stack folded into the key, as the + step chords do. A mono track plays single notes, because a triad there would retrigger one + voice. The notice names the quality from the intervals (MIN, MAJ, DIM) so a player learns + where the minor chords sit. +- **Release by what was played.** A pad keeps the notes it started (`pad_chord_notes_`), so a + key or octave change while it is held cannot strand a note. diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 933955f3..d7846576 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -245,6 +245,7 @@ FM4 and GRAIN machines. | --- | --- | --- | --- | | Follows the unit's clock: internal, MIDI clock, SYNC IN; refuses tempo/transport under external clock | v0.1.0 | ○ (M7) | STRATA cannot set CLOCK SRC (Enaga has no setter). SYNC polarity not selectable (Enaga) | | Tap tempo on VALUE, nudge on FUNC + push VALUE + turn | v0.6.0 | ○ (W72, W80) | Internal clock only; nothing set until three taps agree within 25%; the nudge is 4% for 250 ms a detent | +| KEYS LAYOUT (FUNC menu): SCALE puts the key's degrees on the pads, triads on a chord track's lower pads | Unreleased | ○ (W114), E (scenario_keyslayout.sh) | PIANO by default; saved with the project (one byte on the end of PROJECT.BIN's MIDI section). The emulator has no pads, so the notes are host-tested | | TEMPO GUARD (FUNC menu): VALUE's plain turn and tap show the tempo and leave it | Unreleased | ○ (W99), E (scenario_tempoguard.sh) | Off by default; saved with the project (one byte on the end of PROJECT.BIN's MIDI section). Nudge, VariSpeed, swing and section BPMs still play | | **Song tempo kept apart from the project's**: a section's BPM plays without becoming the saved tempo; ARR REC writes BPM only where the tempo changed (and the take's start tempo on its first entry); VariSpeed held back near 300 BPM says so and returns at a slower tempo | v0.6.0 | ○ (W80), E (scenario_sections.sh, scenario_arrrec.sh) | The clock no longer jumps back for a moment after a section BPM, a VALUE turn or a tap | | MIDI OUT per track (OFF/1-16): steps, chords, ratchets, arp, note repeat, pads, KEYS, MIDI IN | v0.1.0 | ○ (8d) | **On Enaga 0.2.0 (v0.1.0-v0.3.1):** with USB connected to a computer not reading, DIN out stalls; unplug USB. Fixed in Enaga 0.3.0, which `main` needs | diff --git a/docs/MANUAL.md b/docs/MANUAL.md index f4e88b8d..9924d09b 100644 --- a/docs/MANUAL.md +++ b/docs/MANUAL.md @@ -625,7 +625,15 @@ the track's colour, the root brightest; the screen draws the same keyboard. LEFT octave, UP/DOWN the track, and FUNC + a pad still mutes on the bar. **Hold OK** for the track menu (GENERATE and EVOLVE, below), as in GRID; the pads stay the piano while it is open. The STEP keys are the track's steps, as on GRID, with the pad-row keys for the step page, so you can play a line on the pads and -place or fix steps at the same time. Press **REC** (it lights red) while playing and what you play is +place or fix steps at the same time. + +**KEYS LAYOUT** (FUNC menu, `PIANO` or `SCALE`) changes what the pads play. On `SCALE` every pad +is in the key: the lower pads are the key's degrees from its root, left to right, the eighth the +octave, and each upper pad plays the degree to its left an octave higher. On a chord track (VA +POLY, WAVE POLY, FM4 or MID) a lower pad plays the triad on its degree, the key's own chord, and +the screen names it (`T7 A3 MIN`); the upper pads stay single notes for a melody on top. The +octave pads and LEFT/RIGHT move the octave as on the piano. It is `PIANO` in a new project and +saved with the project. Press **REC** (it lights red) while playing and what you play is recorded onto the selected track, quantized by the SETUP page's QUANTIZE amount (100% by default). Pads record too, with their velocity. REC again stops. Turning A-D while recording writes locks onto the steps as they pass (motion recording). diff --git a/docs/UNIT_CHECKLIST.md b/docs/UNIT_CHECKLIST.md index 3eec0d78..1fc90f6a 100644 --- a/docs/UNIT_CHECKLIST.md +++ b/docs/UNIT_CHECKLIST.md @@ -3667,3 +3667,15 @@ headphones in, the transport STOPPED. - A to 1 BAR, OK, play a note: the take is exactly a bar at the tempo (SAMPLE loops it in time). OK again while it waits: `WAITING FOR INPUT`; CLR: `CANCELLED`. D to the floor's value or under, OK: the take starts at once. MIXER IN with the strip on: peak hold and `CLIP`. `____` + +**W114. KEYS LAYOUT: the pads in the key (4 min).** A01, a VA POLY track and a VA MONO track, +the key A minor (PROJECT page, B to A, C to MINOR), PLAY. +- FUNC menu, DOWN to KEYS LAYOUT (under TEMPO GUARD), RIGHT: `KEYS SCALE`, the row reads `SCALE`. + HOME twice for KEYS: every pad lights as a scale note, the A pads bright. `____` +- On the VA MONO track, lower pads left to right: A B C D E F G A, each in key; the upper pads + above them the same an octave up; the two octave pads still walk the octave. `____` +- On the VA POLY track, a lower pad plays a three-note chord and says it (`T7 A3 MIN`, the C pad + `MAJ`, the B pad `DIM`); the chord stops when the pad comes up. The upper pads play one note. With + REC on, a pad's chord lands on one step. `____` +- SAVE, NEW PROJECT, reopen it: the row still reads `SCALE`. Back to `PIANO` (OK on the row, + `KEYS PIANO`): the pads are a keyboard again. `____` diff --git a/tests/scenario_keyslayout.sh b/tests/scenario_keyslayout.sh new file mode 100755 index 00000000..7a7868dc --- /dev/null +++ b/tests/scenario_keyslayout.sh @@ -0,0 +1,128 @@ +#!/usr/bin/env bash +# KEYS LAYOUT in the emulator (FUNC menu; docs/CONTROLS.md, "The FUNC menu"): the beat running, the +# row switched to SCALE, KEYS opened (HOME twice) and its octave walked, then the row back to PIANO. +# +# What it proves is what the host cannot: the menu row draws and switches on the C674x, and KEYS +# lights its pads from the scale layout (light_piano_pads, app/ui_browsers.hpp) without a crash, +# an overrun or a stall. The emulator has no pads, so the notes and chords a pad plays are +# host-tested (tests/test_ui.cpp, ui_keys_scale_layout_plays_the_key_and_chords_on_a_poly_track). +# +# Observable through Enaga's log (notice_logged): `KEYS SCALE`, then `KEYS PIANO`; `run int` from +# the transport. +# +# Keys (third_party/enaga/include/enaga/abi.h): F5 = 22 (PLAY), F1 = 19, F4 = 27 (HOME), DOWN = 25, +# RIGHT = 18, LEFT = 17, OK = 23, CLR = 30. The row is found by name (tools/menu_rows.py), so a row +# added to the menu does not move it. +set -euo pipefail + +cd "$(dirname "$0")/.." +# shellcheck source=tools/env.sh +source tools/env.sh + +if [ "${1:-}" != "" ]; then + echo "error: unknown argument: $1" >&2 + exit 2 +fi + +if [ ! -f "$ENAGA_EMULATOR/cpu.py" ]; then + echo "SKIP: no emulator at $ENAGA_EMULATOR" >&2 + exit 0 +fi + +strata_require_toolchain +strata_link_emulator_toolchain +tools/build.sh > /dev/null + +STAGE="$ENAGA_BUILD/stage/STRATA" +mkdir -p "$ENAGA_BUILD" +LOG="$ENAGA_BUILD/scenario_keyslayout.log" + +downs=$(python3 -B tools/menu_rows.py app/ui_perfmix.hpp MenuItem keys_layout) +step=40000000 + +keys=(--key 22@300000000) +# FUNC + HOME, DOWN to KEYS LAYOUT, RIGHT (SCALE), CLR (closed). +at=380000000 +open_row() { + keys+=(--key "19@$at" --key "27@$((at + 5000000))") + at=$((at + 80000000)) + for ((i = 0; i < downs; i++)); do + keys+=(--key "25@$at") + at=$((at + step)) + done +} +open_row +keys+=(--key "18@$at"); at=$((at + step)) +keys+=(--key "30@$at"); at=$((at + step)) +# KEYS: HOME twice quickly, then the octave up and back down, a second in the scale layout. +keys+=(--key "27@$at" --key "27@$((at + 30000000))"); at=$((at + 2 * step)) +keys+=(--key "18@$at"); at=$((at + step)) +keys+=(--key "17@$at"); at=$((at + 372000000)) +# Back to PIANO: FUNC + HOME, DOWN to the row, OK, CLR. +open_row +keys+=(--key "23@$at"); at=$((at + step)) +keys+=(--key "30@$at"); at=$((at + step)) +CYCLES=$((at + 200000000)) + +echo "running the emulator for $CYCLES cycles: play, KEYS LAYOUT scale, KEYS, piano ..." +python3 -B tools/enaga_cached.py emulate "$STAGE" --cycles "$CYCLES" "${keys[@]}" \ + > "$LOG" 2>&1 || { + echo "FAIL: emulate.py exited non-zero" >&2 + tail -30 "$LOG" >&2 + exit 1 +} + +rc=0 +python3 - "$LOG" <<'PY' || rc=$? +import json, re, sys + +CYCLES_PER_BLOCK = 496_000 + +text = open(sys.argv[1]).read() +match = re.search(r'^\{.*?^\}', text, re.S | re.M) +if not match: + print(" FAIL no JSON report in the emulator output") + sys.exit(1) +report = json.loads(match.group(0)) + +failures = [] + +def check(ok, label, detail=""): + print(f" {'ok ' if ok else 'FAIL'} {label}{' ' + detail if detail else ''}") + if not ok: + failures.append(label) + +log = report.get("log", []) + +check(report.get("app_status") == "APP RUNNING", "app is running", + f'status={report.get("app_status")!r}') +check(not report.get("crash_reason"), "no crash", f'reason={report.get("crash_reason")!r}') +check("run int" in log, "the transport started", f"log={log}") +check("KEYS SCALE" in log, "the FUNC menu row switched KEYS to the scale", f"log={log}") +check("KEYS PIANO" in log, "OK on the row switched it back to the piano", f"log={log}") +if "KEYS SCALE" in log and "KEYS PIANO" in log: + check(log.index("KEYS SCALE") < log.index("KEYS PIANO"), "scale first, then piano", f"log={log}") +check("scr KEYS" in log, "HOME twice reached KEYS", f"log={log}") + +blocks = report.get("audio_blocks", 0) +check(blocks > 1000, "audio ran throughout", f"blocks={blocks}") +check(report.get("audio_overruns", -1) == 0, "no audio overruns", + f'overruns={report.get("audio_overruns")}') + +peak = report.get("audio_cycles_peak", 0) +percent = 100.0 * peak / CYCLES_PER_BLOCK +check(percent > 5.0, "the beat was sounding", f"{percent:.2f}% peak") +check(percent < 60.0, "load is inside the target", f"{percent:.2f}% peak") + +print() +print(f"emulator peak load: {percent:.2f}% ({peak} of {CYCLES_PER_BLOCK} cycles, {blocks} blocks)") + +sys.exit(1 if failures else 0) +PY + +echo +if [ "$rc" -ne 0 ]; then + echo "SCENARIO FAILED; full log: $LOG" >&2 + exit 1 +fi +echo "SCENARIO OK (log: $LOG)" diff --git a/tests/test_app.cpp b/tests/test_app.cpp index f4f45c50..a0ea1bcd 100644 --- a/tests/test_app.cpp +++ b/tests/test_app.cpp @@ -260,7 +260,7 @@ TEST(app_the_first_save_of_a_project_writes_all_ten_files) { // The sizes tests/test_project.cpp pins, reached through the real card protocol this time. project_file(path, "PROJECT.BIN"); - CHECK_EQ(host.file_bytes(path), 1081); // core/project.cpp: 305, 12 + 65 song, 12 + 10 MIDI, 12 + 19 EVOLVE, 4 chorus, 1 RDK, 1 PSH, 4 RDR RLP CLP MNO, 4 drum bus, 12 + 9 launch, 12 + 10 input, 12 + 577 sections (513 + 64 KIT) + CHECK_EQ(host.file_bytes(path), 1082); // core/project.cpp: 305, 12 + 65 song, 12 + 11 MIDI, 12 + 19 EVOLVE, 4 chorus, 1 RDK, 1 PSH, 4 RDR RLP CLP MNO, 4 drum bus, 12 + 9 launch, 12 + 10 input, 12 + 577 sections (513 + 64 KIT) project_file(path, "KIT.BIN"); CHECK_EQ(host.file_bytes(path), 1614); // 1076, LFO SLOW (12 + 8), SLAP (12 + 32), SCN (12 + 32), the widths (12 + 8), the chorus sends (12 + 8), the LFO layout (12 + 1), the arp settings (12 + 32), the choke groups (12 + 8), the mod slots (12 + 48), LFO TRIG (12 + 8), the filter layout (12 + 1), the LFO and arp (2 x (12 + 8 x 4)), SLC AUTO (12 + 8), ASR (12 + 32), the duck (12 + 12), OSC (12 + 32) project_file(path, "PERFORM.BIN"); diff --git a/tests/test_project.cpp b/tests/test_project.cpp index cf378660..01fecfa6 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -49,8 +49,8 @@ using namespace strata; // (12), a layout byte and 8 bytes per chain entry (513). 998 since PROG CHG OUT: // one byte on the end of the MIDI section. 999 since the reverb's duck: one send byte on the end // of the mixer section. 1008 since GEN TYPE: one byte per track on the end of -// the EVOLVE section. 1012 since RDR RLP CLP MNO: four on the end of the mixer section. 1015 since the drum bus: three more. 1016 since its OTT. 1017 since TEMPO GUARD, on the end of the MIDI section. 1081 since a section's KIT: 64 on the end of section 10. -constexpr uint32_t kProjectFileBytes = 1081; +// the EVOLVE section. 1012 since RDR RLP CLP MNO: four on the end of the mixer section. 1015 since the drum bus: three more. 1016 since its OTT. 1017 since TEMPO GUARD, on the end of the MIDI section. 1081 since a section's KIT: 64 on the end of section 10. 1082 since KEYS LAYOUT, on the end of the MIDI section. +constexpr uint32_t kProjectFileBytes = 1082; constexpr uint32_t kKitFileBytes = 1614; // 1594 before LFO SLOW (12 + 8), 1550 before SLAP (12 + 32), 1506 before the SCN page (12 + 32), 1486 before the widths (12 + 8), 1466 before the chorus sends (12 + 8), 1453 before the LFO layout (12 + 1), 1409 before the arp settings (12 + 32), 1389 before the choke groups (12 + 8), 1329 before the mod slots (12 + 48), 1309 before LFO TRIG (12 + 8), 1296 before the filter layout (12 + 1), 1076 before the LFO and arp (12 + 8 x 4 each), 1164 before SLC AUTO (12 + 8), 1184 before ASR (12 + 32), 1228 before the duck (12 + 12), 1252 before OSC (12 + 32) // Room past the end of every file, filled with a sentinel, so that a writer going one byte long @@ -1114,6 +1114,48 @@ TEST(project_a_damaged_tempo_guard_byte_is_off) { CHECK(!g_loaded.settings.tempo_guard); } +// KEYS LAYOUT rides after TEMPO GUARD on the end of the MIDI section: it round-trips, a section +// from before it (ten bytes) loads PIANO, and only a 1 is SCALE. +TEST(project_keys_layout_round_trips_and_an_older_file_plays_a_piano) { + for (const bool scale : {true, false}) { + fill_project(g_source, 0); + g_source.settings.keys_scale = scale; + g_source.settings.tempo_guard = !scale; + uint32_t written = 0; + CHECK_EQ(int(project_write(g_source, g_project, uint32_t(sizeof(g_project)), &written)), + int(SerializeResult::ok)); + CHECK_EQ(int(g_project[section_at(g_project, kSectionProjectMidi) + kTracks + 2]), + scale ? 1 : 0); + project_init(g_loaded); + g_loaded.settings.keys_scale = !scale; + CHECK_EQ(int(project_read(g_loaded, g_project, written)), int(SerializeResult::ok)); + CHECK_EQ(g_loaded.settings.keys_scale, scale); + CHECK_EQ(g_loaded.settings.tempo_guard, !scale); + } + + fill_project(g_source, 0); + g_source.settings.keys_scale = true; + g_source.settings.tempo_guard = true; + uint32_t written = 0; + CHECK_EQ(int(project_write(g_source, g_project, uint32_t(sizeof(g_project)), &written)), + int(SerializeResult::ok)); + const uint32_t midi = section_at(g_project, kSectionProjectMidi); + g_project[midi + kTracks + 2] = 0x7F; // damage: PIANO + refresh_crc(g_project); + project_init(g_loaded); + CHECK_EQ(int(project_read(g_loaded, g_project, written)), int(SerializeResult::ok)); + CHECK(!g_loaded.settings.keys_scale); + CHECK(g_loaded.settings.tempo_guard); + + poke_u32(g_project, section_entry_at(g_project, kSectionProjectMidi) + 8, uint32_t(kTracks) + 2u); + refresh_crc(g_project); + project_init(g_loaded); + g_loaded.settings.keys_scale = true; // a previous project's + CHECK_EQ(int(project_read(g_loaded, g_project, written)), int(SerializeResult::ok)); + CHECK(!g_loaded.settings.keys_scale); + CHECK(g_loaded.settings.tempo_guard); +} + TEST(project_refuses_a_midi_section_that_is_short) { fill_project(g_source, 0); uint32_t written = 0; @@ -1170,7 +1212,7 @@ TEST(project_a_file_from_before_song_mode_loops_and_recalls_no_mutes) { old_size = drop_last_section(g_project_alt, g_project_alt); old_size = drop_last_section(g_project_alt, g_project_alt); old_size = drop_last_section(g_project_alt, g_project_alt); - CHECK_EQ(old_size, kProjectFileBytes - 12 - 577 - 12 - 10 - 12 - 9 - 12 - 19 - 12 - 10 - 12 - 65); + CHECK_EQ(old_size, kProjectFileBytes - 12 - 577 - 12 - 10 - 12 - 9 - 12 - 19 - 12 - 11 - 12 - 65); // A previous project's song settings, which must not survive into this one. project_init(g_loaded); g_loaded.settings.chain_song = true; @@ -1747,7 +1789,7 @@ TEST(project_the_header_says_strata_and_the_version) { CHECK_EQ(song, live + 3); CHECK_EQ(midi, song + 1 + 64); const uint32_t evolve = section_at(g_project, kSectionProjectEvolve); - CHECK_EQ(evolve, midi + 10); // eight channels, PROG CHG OUT and TEMPO GUARD + CHECK_EQ(evolve, midi + 11); // eight channels, PROG CHG OUT, TEMPO GUARD and KEYS LAYOUT const uint32_t launch = section_at(g_project, kSectionProjectLaunch); CHECK_EQ(launch, evolve + 11 + 8); // and GEN TYPE per track const uint32_t input = section_at(g_project, kSectionProjectInput); diff --git a/tests/test_storage.cpp b/tests/test_storage.cpp index 53099275..30624dbb 100644 --- a/tests/test_storage.cpp +++ b/tests/test_storage.cpp @@ -601,6 +601,7 @@ const Expect kTable[] = { // live state, so neither touches a file. {Cmd::set_program_out, kDirtyProject, "set_program_out"}, {Cmd::set_tempo_guard, kDirtyProject, "set_tempo_guard"}, + {Cmd::set_keys_layout, kDirtyProject, "set_keys_layout"}, {Cmd::set_midi_channel, 0u, "set_midi_channel"}, {Cmd::locate, 0u, "locate"}, @@ -851,8 +852,8 @@ TEST(storage_every_file_of_a_project_round_trips_through_the_card) { // The sizes tests/test_project.cpp pins from the serializer, reached here through the real // card protocol: a file that came out a different size means the two have drifted apart. - CHECK_EQ(host.file_bytes(card_path("PROJECT.BIN")), 1081); - CHECK_EQ(project_bytes(), 1081u); + CHECK_EQ(host.file_bytes(card_path("PROJECT.BIN")), 1082); + CHECK_EQ(project_bytes(), 1082u); CHECK_EQ(host.file_bytes(card_path("KIT.BIN")), 1614); CHECK_EQ(kit_bytes(engine().project().kit), 1614u); CHECK_EQ(host.file_bytes(card_path("PERFORM.BIN")), 5773); @@ -1765,7 +1766,7 @@ TEST(storage_an_autosave_writes_every_file_and_leaves_the_project_dirty) { } CHECK(host.has_file(card_path(kFiles[i], true))); } - CHECK_EQ(host.file_bytes(card_path("PROJECT.BIN", true)), 1081); + CHECK_EQ(host.file_bytes(card_path("PROJECT.BIN", true)), 1082); CHECK_EQ(host.file_bytes(card_path("KIT.BIN", true)), 1614); CHECK_EQ(host.file_bytes(card_path("PERFORM.BIN", true)), 5773); diff --git a/tests/test_ui.cpp b/tests/test_ui.cpp index 002570b0..edcbdd0f 100644 --- a/tests/test_ui.cpp +++ b/tests/test_ui.cpp @@ -450,7 +450,7 @@ void open_keys() { // The FUNC menu's rows, in order (app/ui_perfmix.hpp, MenuItem). enum MenuRow : int { kMenuSave, kMenuJam, kMenuArr, kMenuClick, kMenuCountIn, kMenuRecMode, kMenuQuantize, kMenuAutofill, kMenuGlide, kMenuTranspose, kMenuLoopLen, - kMenuChain, kMenuSong, kMenuArrUndo, kMenuProgOut, kMenuTempoGuard, + kMenuChain, kMenuSong, kMenuArrUndo, kMenuProgOut, kMenuTempoGuard, kMenuKeysLayout, kMenuSaveAs, kMenuOpen, kMenuKits, kMenuNew, kMenuReload, kMenuClear, kMenuDemo, kMenuGenAll, kMenuRowCount }; @@ -10283,6 +10283,92 @@ TEST(ui_keys_plays_the_pads_as_a_piano) { pump(2); } +// KEYS LAYOUT SCALE (FUNC menu; review 2026-11-29, proposal 5): the lower pads are the key's +// degrees and the octave, an upper pad the lower one to its left an octave up, the octave pads +// stay; on a chord track a lower pad plays its degree's triad, recorded onto one step. +TEST(ui_keys_scale_layout_plays_the_key_and_chords_on_a_poly_track) { + Strata &app = fresh(); + post_cmd(Cmd::set_root, 9); // A + post_cmd(Cmd::set_scale, uint8_t(Scale::minor)); + post_track(Cmd::set_machine, 6, uint8_t(MachineId::va_poly)); + pump(4); + CHECK(!app_engine().project().settings.keys_scale); + menu_toggle(kMenuKeysLayout); + pump(2); + CHECK(app_engine().project().settings.keys_scale); + open_keys(); + pump(2); + check_layout(app, "KEYS, SCALE"); + + // A minor from the A of the current octave: A B C D E F G A. + const int a = UiProbe::pad_note(app, 0); + CHECK_EQ(a % 12, 9); + const int degrees[8] = {0, 2, 3, 5, 7, 8, 10, 12}; + for (int i = 0; i < 8; i++) CHECK_EQ(UiProbe::pad_note(app, 2 * i) - a, degrees[i]); + // The upper pads: the lower pad to their left an octave up; 5 and 13 still walk the octave. + for (int k : {0, 1, 3, 4, 5}) CHECK_EQ(UiProbe::pad_note(app, 2 * k + 1), UiProbe::pad_note(app, 2 * k) + 12); + CHECK_EQ(UiProbe::pad_note(app, 5), -1); + CHECK_EQ(UiProbe::pad_note(app, 13), -1); + // Every pad is in the key: none of them dark. + for (int pad = 0; pad < 15; pad++) { + const int sum = UiProbe::pad_r(app, pad) + UiProbe::pad_g(app, pad) + UiProbe::pad_b(app, pad); + CHECK(sum > 0); + } + + // On a mono track a pad is one note. + app.on_pad_press(0, 100); + CHECK_EQ(UiProbe::pad_held_note(app, 0), a); + CHECK(std::strncmp(UiProbe::notice(app), "T1 A", 4) == 0); + app.on_pad_release(0); + + // On the POLY track the lower pads are the key's triads: i is A minor, III C major, ii dim. + while (UiProbe::selected(app) != 6) key(ENAGA_KEY_DOWN); + app.on_pad_press(0, 100); + pump(2); + CHECK(std::strstr(UiProbe::notice(app), " MIN") != nullptr); + app.on_pad_release(0); + app.on_pad_press(4, 100); + CHECK(std::strstr(UiProbe::notice(app), " MAJ") != nullptr); + app.on_pad_release(4); + app.on_pad_press(2, 100); + CHECK(std::strstr(UiProbe::notice(app), " DIM") != nullptr); + app.on_pad_release(2); + app.on_pad_press(1, 100); // upper: one note, a melody over them + CHECK(std::strstr(UiProbe::notice(app), " MIN") == nullptr); + CHECK(std::strstr(UiProbe::notice(app), " MAJ") == nullptr); + app.on_pad_release(1); + pump(4); + check_layout(app, "KEYS, SCALE, a chord played"); + + // Recorded, the chord is one step of three notes. + FakeHost &host = FakeHost::the(); + host.set_running(true); + host.set_position(96); + key(ENAGA_KEY_F2); // REC on + app.on_pad_press(8, 90); // v: E minor + pump(2); + app.on_pad_release(8); + pump(2); + key(ENAGA_KEY_F2); + host.set_running(false); + int where = -1; + for (int st = 0; st < kStepsPerTrack; st++) { + if (trig_at(6, st)) where = st; + } + CHECK(where >= 0); + if (where >= 0) { + uint8_t notes[1 + kStepExtraNotes]; + notes[0] = step_of(6, where).note; + const int count = 1 + step_extra_notes(app_engine().pattern(), 6, where, notes + 1); + CHECK_EQ(count, 3); + CHECK_EQ(int(notes[0]), a + 7); + } + + menu_toggle(kMenuKeysLayout); // back to the piano + pump(2); + CHECK(!app_engine().project().settings.keys_scale); +} + TEST(ui_keys_pads_record_at_their_own_velocity) { Strata &app = fresh(); open_keys(); From d5fbb38a5e905fe1e7502fc5aac93026fb952e0a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 14:52:59 +0000 Subject: [PATCH 2/2] LOUD: one knob on MIXER CLIP moves PSH, CLP, MNO and GLU along a tuned curve LUD (knob C on CLIP) writes the master's four loudness bytes from one curve (core/loud.cpp): PSH is the position, MNO comes in early, CLP and GLU climb slower. The factory master is LOUD 40. Nothing new is stored: the position is read back from the four bytes, OWN when one was turned by hand. A01 measured -15.1 to -7.2 LUFS, peaks under -2 dB at the top (host render writes A01_LOUD*.wav). Host tests, scenario_loud.sh, W115, docs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Tw2EaEK2oaJWJMdGQTNLPf --- CHANGELOG.md | 5 ++ app/app.hpp | 10 +++- app/commands.hpp | 3 ++ app/engine.cpp | 9 ++++ app/storage.cpp | 1 + app/ui_mixer.hpp | 31 +++++++++++- app/ui_mixview.hpp | 5 +- core/help.cpp | 5 +- core/loud.cpp | 79 ++++++++++++++++++++++++++++++ core/loud.hpp | 54 +++++++++++++++++++++ docs/CHEATSHEET.md | 2 +- docs/DESIGN_NOTES.md | 37 ++++++++++++++ docs/FEATURES.md | 1 + docs/MANUAL.md | 8 +++ docs/UNIT_CHECKLIST.md | 9 ++++ host/render.cpp | 20 ++++++++ tests/scenario_loud.sh | 108 +++++++++++++++++++++++++++++++++++++++++ tests/test_loud.cpp | 67 +++++++++++++++++++++++++ tests/test_storage.cpp | 1 + tests/test_ui.cpp | 51 +++++++++++++++++++ 20 files changed, 499 insertions(+), 7 deletions(-) create mode 100644 core/loud.cpp create mode 100644 core/loud.hpp create mode 100755 tests/scenario_loud.sh create mode 100644 tests/test_loud.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 318b9d36..17dd75e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ the project file format or the controls. swing and a section's BPM still play. Off in a new project, saved with the project: one byte on the end of PROJECT.BIN's MIDI section, which older builds ignore and which reads as off in an older file. +- **LOUD.** MIXER's CLIP page, knob C (LUD): one knob that turns PSH, CLP, MNO and the drum + bus's GLU together along one curve, from `OFF` (none of them) through `40` (the factory + master) to `127`, about 6 LU louder than the factory with the peaks under -2 dB. A stage turned + on its own page shows `OWN` until LUD is turned again. Nothing new in the file: the four + bytes are the setting. - **KEYS LAYOUT.** A FUNC menu row under TEMPO GUARD. `SCALE` turns KEYS's pads into the key: the lower pads are its degrees from the root, the upper pads the same an octave up, so no pad is out of key. On a chord track (VA POLY, WAVE POLY, FM4, MID) a lower pad plays its degree's diff --git a/app/app.hpp b/app/app.hpp index 84d6eb3d..99fcb31f 100644 --- a/app/app.hpp +++ b/app/app.hpp @@ -36,6 +36,7 @@ #include "engine.hpp" #include "help.hpp" // the FUNC help's pages, one set per screen #include "energy.hpp" // ENERGY: FUNC + VALUE, on every screen +#include "loud.hpp" // LOUD: the CLIP page's macro on the master #include "transpose.hpp" // TRANSPOSE: FUNC + the screen keys #include "varispeed.hpp" // VariSpeed: FUNC + C in PERFORM, tempo and pitch together #include "liverand.hpp" // LIVE RND: FUNC + D in PERFORM @@ -155,6 +156,10 @@ struct MixerPage { constexpr int kMixerTrackPages = 2; +// The slot that is LOUD (core/loud.hpp) rather than one master byte: it moves PSH, CLP, MNO and +// GLU together, so it sits beside CLP and MNO, which it turns where the player can see them. +constexpr int8_t kMixerLoudField = -2; + constexpr MixerPage kMixerPages[] = { {"TRK 1-4", false, {-1, -1, -1, -1}}, // the faders, handled on their own {"TRK 5-8", false, {-1, -1, -1, -1}}, @@ -197,9 +202,10 @@ constexpr MixerPage kMixerPages[] = { {"IN+", false, {-1, -1, -1, -1}}, // The reverb return's rumble stage (RDR drive, RLP low-pass; RDK the duck is on ROUTE) and the // master's clipper and mono lows (CLP, MNO): the techno shaping, 2026-11-29. Before MST so - // that MST and EQ stay the last two pages, one and two presses round from TRK 1-4. + // that MST and EQ stay the last two pages, one and two presses round from TRK 1-4. LUD on C + // is the LOUD macro (the second review's proposal 12, 2026-11-30). {"RUMBLE", false, {int8_t(SendField::reverb_drive), int8_t(SendField::reverb_low_pass), -1, -1}}, - {"CLIP", true, {int8_t(MasterField::clip), int8_t(MasterField::mono_low), -1, -1}}, + {"CLIP", true, {int8_t(MasterField::clip), int8_t(MasterField::mono_low), kMixerLoudField, -1}}, // The drum bus: every KICK, SNARE, HAT and PERC track's dry sound, driven, boomed, glued. {"DRUMS", true, {int8_t(MasterField::drum_drive), int8_t(MasterField::drum_boom), int8_t(MasterField::drum_glue), int8_t(MasterField::drum_low)}}, diff --git a/app/commands.hpp b/app/commands.hpp index cb613339..317cd4f3 100644 --- a/app/commands.hpp +++ b/app/commands.hpp @@ -221,6 +221,9 @@ enum class Cmd : uint8_t { // the value the mixer runs on, and for the delay's time it needs the tempo to do it. set_sends, // a: SendField, b: int8 delta set_master, // a: MasterField, b: int8 delta + // LOUD (core/loud.hpp): b an int8 delta along the curve, from where the master's four bytes + // are on it (or its PSH, off it); the engine writes all four. + set_loud, // The sidechain duck (core/project.hpp, KitDuck): a: DuckField, b: int8 delta; track is the // track whose depth moves for DuckField::depth. Kit bytes, so a kit save keeps them. set_duck, diff --git a/app/engine.cpp b/app/engine.cpp index 3b709305..b04f4e52 100644 --- a/app/engine.cpp +++ b/app/engine.cpp @@ -6,6 +6,7 @@ #include "energy.hpp" // ENERGY: the amount held to its range, the tiers #include "transpose.hpp" // TRANSPOSE: which tracks move, and the note moved #include "autorec.hpp" // AUTO REC: the threshold steps +#include "loud.hpp" // LOUD: the master's four bytes along one curve #include "chainloops.h" // strata_choke_fade, a choke group's fade #include "masterloops.h" // strata_master_peak, for the input meter #include "pcm.hpp" // a streamed file's bytes to int16, in top_up_streams @@ -1711,6 +1712,14 @@ bool Engine::apply_mixer(const Command &command, int track, int) { apply_mixer_bytes(); break; + case Cmd::set_loud: + // From the engine's own bytes, not the UI's reading of them: a sweep's clicks + // arrive faster than the UI sees each land (edit_mixer_field says why). + loud_apply(project_.settings.master, + loud_start(project_.settings.master) + int(int8_t(command.b))); + apply_mixer_bytes(); + break; + case Cmd::set_input: { if (command.a >= uint8_t(kInputFields)) { status_.bump_refused(); diff --git a/app/storage.cpp b/app/storage.cpp index d7364c84..082b3105 100644 --- a/app/storage.cpp +++ b/app/storage.cpp @@ -190,6 +190,7 @@ bool mutates_project(Cmd cmd) { // setting was lost the moment the app restarted. case Cmd::set_sends: case Cmd::set_master: + case Cmd::set_loud: // And the kill EQ's switches, which sit in the same section. case Cmd::eq_kill: // The live-record quantize amount, which has a field in PROJECT.BIN and until now was diff --git a/app/ui_mixer.hpp b/app/ui_mixer.hpp index 6a54035c..750b6511 100644 --- a/app/ui_mixer.hpp +++ b/app/ui_mixer.hpp @@ -13,14 +13,19 @@ // fourteen of them live (core/project.hpp). There is no app-side copy to drift. uint8_t mixer_byte(int page, int slot) const { const int8_t field = kMixerPages[page].field[slot]; - if (field < 0) return 0; const ProjectSettings &settings = engine_.project().settings; + if (field == kMixerLoudField) return uint8_t(loud_start(settings.master)); + if (field < 0) return 0; return kMixerPages[page].master ? settings.master[field] : settings.sends[field]; } void edit_mixer_field(int page, int slot, int delta) { if (page < 0 || page >= kMixerPageCount || slot < 0 || slot >= 4) return; const int8_t field = kMixerPages[page].field[slot]; + if (field == kMixerLoudField) { + edit_loud(delta); + return; + } if (field < 0) return; // an empty slot on the routing page const bool master = kMixerPages[page].master; @@ -33,6 +38,22 @@ notice(master ? master_field_name(uint8_t(field)) : send_field_name(uint8_t(field))); } + // LOUD on the CLIP page: one click two steps along the curve, said as "LOUD 42" (or "LOUD + // OFF"), and logged, since the emulator cannot read the screen (tests/scenario_loud.sh). The + // figure is the UI's guess from the project it last saw; the engine moves from its own. + void edit_loud(int delta) { + post_delta(Cmd::set_loud, 0, 0, 0, delta * kLoudClick); + const int now = loud_start(engine_.project().settings.master) + delta * kLoudClick; + const int shown = now < 0 ? 0 : (now > kLoudMax ? kLoudMax : now); + char *out = notice_buffer_; + append(out, "LOUD "); + if (shown == 0) append(out, "OFF"); + else append_number(out, uint32_t(shown)); + *out = 0; + notice(notice_buffer_); + enaga::log(notice_buffer_); + } + // The chorus sends (KitTrack::chorus) on CHO 1-4 and CHO 5-8: an encoder is a track's send, // one click two counts as a send knob on EDIT's FX page is, and said as "T3 CHORUS 64". void edit_chorus_send(int page, int slot, int delta) { @@ -310,6 +331,14 @@ void append_mixer_value(char *&out, int page, int slot) { const int8_t field = kMixerPages[page].field[slot]; const uint8_t byte = mixer_byte(page, slot); + if (field == kMixerLoudField) { + // OWN when one of the four was turned on its own page: the curve no longer says + // what the master does, and the next turn of LUD puts all four back on it. + if (loud_position(engine_.project().settings.master) < 0) append(out, "OWN"); + else if (byte == 0) append(out, "OFF"); + else append_number(out, byte); + return; + } if (!kMixerPages[page].master && field == int8_t(SendField::delay_seconds)) { append(out, delay_division_name(byte)); return; diff --git a/app/ui_mixview.hpp b/app/ui_mixview.hpp index 9bc7ee95..9cd2e78b 100644 --- a/app/ui_mixview.hpp +++ b/app/ui_mixview.hpp @@ -61,7 +61,10 @@ append_slap_value(v, slot, int(slap_byte(slot))); } else { const int8_t field = kMixerPages[mixer_bank_].field[slot]; - if (field < 0) { + if (field == kMixerLoudField) { + append(n, "LUD"); + append_mixer_value(v, mixer_bank_, slot); + } else if (field < 0) { append(n, "---"); empty = true; } else { diff --git a/core/help.cpp b/core/help.cpp index 724b7678..e366693a 100644 --- a/core/help.cpp +++ b/core/help.cpp @@ -568,8 +568,9 @@ constexpr Text kMixer[kHelpMixerPages] = { "PUSH A IN ON OR OFF", "PUSH D GAIN", "SAVED IN THE PROJECT", nullptr}}, {"MIXER RUMBLE:", {"A RDR RETURN DRIVE", "B RLP LOW-PASS 24DB", "MONO REV INTO DRIVE", "LOW-PASS THEN RDK", "KICK INTO REV SNB", nullptr}}, - {"MIXER CLIP:", {"A CLP SOFT CLIPPER", "B MNO MONO BELOW HZ", "CLP ROUNDS PEAKS", - "PSH THEN LIFTS IT", nullptr}}, + {"MIXER CLIP:", {"A CLP SOFT CLIPPER", "B MNO MONO BELOW HZ", "C LUD LOUD: ONE KNOB", + "LUD MOVES PSH CLP", "MNO AND GLU TOGETHER", "OWN = ONE SET BY HAND", + "CLP ROUNDS PEAKS", "PSH THEN LIFTS IT", nullptr}}, {"MIXER DRUMS:", {"A DRV BUS DRIVE", "B BOM BOOM AT KICK", "C GLU GLUE COMP", "D OTT LIFT THE LOWS", "KCK SNR HAT PRC DRY", "ALL 0 = NO BUS", nullptr}}, {"MIXER MST:", {"A DJ DJ FILTER", "B CMP COMPRESSOR", "C LIM LIMITER", "D LVL LEVEL", diff --git a/core/loud.cpp b/core/loud.cpp new file mode 100644 index 00000000..43b7bb33 --- /dev/null +++ b/core/loud.cpp @@ -0,0 +1,79 @@ +#include "loud.hpp" + +namespace strata { + +namespace { + +// The curve, as corners joined by straight lines. PSH is the position itself (0 to +12 dB), so +// every position has its own PSH and loud_position reads one back without a search. The other +// three come in early and climb slower: +// - MNO, the lows in mono under about 85 Hz, is on by LOUD 16 and stays there: it makes room +// rather than level, and a club wants it from the first click. +// - CLP holds the peaks the push makes, and climbs slowest: it brings its drive back down, so +// a hard CLP spends the headroom PSH made (CLP 72 at the top gave -9 LUFS with the peaks at +// -6 dB; CLP 32 gives -7.2 with them at -2.7). +// - GLU follows PSH up to the factory's point and climbs slower above it, because a hard glue +// on top of a hard clip pumps. +// Measured on A01 by host render (docs/DESIGN_NOTES.md, "LOUD"). +struct Corner { + uint8_t at, clip, mono, glue; +}; +constexpr Corner kCorners[] = { + {0, 0, 0, 0}, + {16, 4, 60, 12}, + {40, 16, 60, 40}, + {80, 24, 64, 56}, + {127, 32, 70, 72}, +}; +constexpr int kCornerCount = int(sizeof(kCorners) / sizeof(kCorners[0])); +static_assert(kCorners[kCornerCount - 1].at == kLoudMax, "the curve ends at the top"); + +uint8_t between(int position, int at0, int at1, int v0, int v1) { + const int span = at1 - at0; + return uint8_t(v0 + ((v1 - v0) * (position - at0) * 2 + span) / (2 * span)); +} + +int clamp_position(int position) { + return position < 0 ? 0 : (position > kLoudMax ? kLoudMax : position); +} + +} // namespace + +LoudBytes loud_curve(int position) { + const int p = clamp_position(position); + int i = 0; + while (i + 2 < kCornerCount && p > kCorners[i + 1].at) i++; + const Corner &a = kCorners[i]; + const Corner &b = kCorners[i + 1]; + LoudBytes out; + out.push = uint8_t(p); + out.clip = between(p, a.at, b.at, a.clip, b.clip); + out.mono = between(p, a.at, b.at, a.mono, b.mono); + out.glue = between(p, a.at, b.at, a.glue, b.glue); + return out; +} + +void loud_apply(uint8_t *master, int position) { + const LoudBytes bytes = loud_curve(position); + master[kLoudPushField] = bytes.push; + master[kLoudClipField] = bytes.clip; + master[kLoudMonoField] = bytes.mono; + master[kLoudGlueField] = bytes.glue; +} + +int loud_position(const uint8_t *master) { + const int p = master[kLoudPushField]; + if (p > kLoudMax) return -1; + const LoudBytes bytes = loud_curve(p); + return bytes.clip == master[kLoudClipField] && bytes.mono == master[kLoudMonoField] && + bytes.glue == master[kLoudGlueField] + ? p + : -1; +} + +int loud_start(const uint8_t *master) { + const int exact = loud_position(master); + return exact >= 0 ? exact : clamp_position(master[kLoudPushField]); +} + +} // namespace strata diff --git a/core/loud.hpp b/core/loud.hpp new file mode 100644 index 00000000..bc96301d --- /dev/null +++ b/core/loud.hpp @@ -0,0 +1,54 @@ +// LOUD: one knob for the master's loudness (the second review's proposal 12, from 2026-11-29's +// "one LOUD macro"). It moves four master bytes together along one tuned curve: +// +// PSH the push into the soft clip and the limiter (MasterField::push) +// CLP the soft clipper's drive (MasterField::clip) +// MNO the lows in mono (MasterField::mono_low) +// GLU the drum bus's glue under the kick (MasterField::drum_glue) +// +// The four bytes stay the truth, on their own pages, in PROJECT.BIN as they always were. LOUD +// stores nothing: its position is read back from them (loud_position), and a byte moved by hand +// takes the four off the curve, which MIXER shows as OWN until LOUD is turned again. So a file +// from any build opens and sounds the same, and a project's own master is never overwritten +// until the knob is touched. +// +// The factory master (core/factory.cpp: PSH 40, CLP 16, MNO 60, GLU 40) is a point on the curve, +// LOUD 40, so the demo opens on it. A new project (all four 0) is LOUD 0, OFF. +// +// Here rather than in dsp/ so it is host-tested without Enaga (core/ never includes it). +#pragma once + +#include + +namespace strata { + +// dsp/buses.hpp's MasterField indices, which core/ cannot include (tests/test_loud.cpp checks +// them against the enum). +constexpr int kLoudPushField = 7; +constexpr int kLoudClipField = 8; +constexpr int kLoudMonoField = 9; +constexpr int kLoudGlueField = 12; + +constexpr int kLoudMax = 127; +constexpr int kLoudFactory = 40; // core/factory.cpp's master +constexpr int kLoudClick = 2; // one detent, as a master knob's (kMasterFieldClick) + +struct LoudBytes { + uint8_t push, clip, mono, glue; +}; + +// The four bytes at a LOUD position, 0..kLoudMax (clamped). +LoudBytes loud_curve(int position); + +// Writes loud_curve(position) into a ProjectSettings::master array. +void loud_apply(uint8_t *master, int position); + +// The position whose curve the master's four bytes are exactly, or -1 when they are off it (one +// was turned on its own page). +int loud_position(const uint8_t *master); + +// Where a turn of LOUD starts from: loud_position, or, off the curve, the position of the +// master's own PSH, so the first click lands near the level the master already has. +int loud_start(const uint8_t *master); + +} // namespace strata diff --git a/docs/CHEATSHEET.md b/docs/CHEATSHEET.md index c3587cf5..88a017c2 100644 --- a/docs/CHEATSHEET.md +++ b/docs/CHEATSHEET.md @@ -418,7 +418,7 @@ OFF-100% (SRC: the source, never ducked) · DUCK: SRC source track, ATK attack 1 FBK feedback, TON tone, LVL · DLY+: TYP CLAS/LONG (push A flips it), MUL X1-X8 (LONG: time x MUL, up to 12 s), WOW tape wobble, DIF diffusion · REV: DEC decay, DMP damping, HPF high-pass, LVL · REV+: TYP ROOM/HALL (push A), SIZ size, MOD sweep, SHM octave-up shimmer · ROUTE: PNG ping-pong, -D>R delay into reverb, LCT the LONG delay's low cut, RDK the reverb's return under the duck · CHO 1-4, CHO 5-8: each track's chorus send, OFF-127 (push A-D: OFF or 64; saved in the kit) · CHO: RAT sweep 0.05-5 Hz, DEP depth, LVL return, C>R chorus into the reverb · IN: the line input, LVL (100 = 0 dB), PAN, DLY, REV sends (push A: on/off) · IN+: CHO send, DCK duck depth, TON tone, SRC jack LINE/LINE L/MIC/DYN MIC/HI-Z/USB (push D: gain LOW/NORM/HIGH; saved in the project) · RUMBLE: RDR the reverb return's drive, RLP its 24 dB low-pass (both OFF = as before) · CLIP: CLP master soft clipper 0-12 dB, MNO mono below 40-200 Hz · DRUMS: the drum bus for KCK SNR HAT PRC tracks, DRV drive, BOM boom at the kick's note, GLU glue, OTT lift the lows (all 0 = no bus) · MST master: DJ filter, CMP compressor, LIM limiter, LVL · EQ master kill EQ (D: PSH, 0-12 dB into the limiter): +D>R delay into reverb, LCT the LONG delay's low cut, RDK the reverb's return under the duck · CHO 1-4, CHO 5-8: each track's chorus send, OFF-127 (push A-D: OFF or 64; saved in the kit) · CHO: RAT sweep 0.05-5 Hz, DEP depth, LVL return, C>R chorus into the reverb · IN: the line input, LVL (100 = 0 dB), PAN, DLY, REV sends (push A: on/off) · IN+: CHO send, DCK duck depth, TON tone, SRC jack LINE/LINE L/MIC/DYN MIC/HI-Z/USB (push D: gain LOW/NORM/HIGH; saved in the project) · RUMBLE: RDR the reverb return's drive, RLP its 24 dB low-pass (both OFF = as before) · CLIP: CLP master soft clipper 0-12 dB, MNO mono below 40-200 Hz, LUD the LOUD macro (PSH CLP MNO GLU together, OFF-127, 40 = factory; OWN after one is turned by hand) · DRUMS: the drum bus for KCK SNR HAT PRC tracks, DRV drive, BOM boom at the kick's note, GLU glue, OTT lift the lows (all 0 = no bus) · MST master: DJ filter, CMP compressor, LIM limiter, LVL · EQ master kill EQ (D: PSH, 0-12 dB into the limiter): LOW (below 250 Hz), MID, HI (above 2.5 kHz), each flat at centre, KILL at the bottom, +6 dB at the top. **Lists:** queue modes END (end of pattern), 16, 32 (steps), NOW · repeat 1/4 1/8 1/16 1/32 1/4T diff --git a/docs/DESIGN_NOTES.md b/docs/DESIGN_NOTES.md index 2a1d7843..e1558916 100644 --- a/docs/DESIGN_NOTES.md +++ b/docs/DESIGN_NOTES.md @@ -761,3 +761,40 @@ of key, for playing chords and lines without a keyboard player's hands. where the minor chords sit. - **Release by what was played.** A pad keeps the notes it started (`pad_chord_notes_`), so a key or octave change while it is held cannot strand a note. + +## LOUD + +The second review's proposal 12 (from 2026-11-29's "one LOUD macro"): the master's loudness +stages are spread over three pages (PSH on EQ, CLP and MNO on CLIP, GLU on DRUMS); one knob gives +the result and leaves the detail where it was. + +- **On CLIP, knob C.** MST's four knobs are taken. CLIP had two free slots and shows two of the + four stages LUD moves, so the player sees it work. Named `LUD` (knob names are three letters). +- **Stores nothing.** The four bytes are the setting; LUD reads its position back from them + (`loud_position`), and PSH is the position itself, so the read is one comparison. A stage + turned by hand takes the master off the curve: LUD shows `OWN`, and its next turn starts from + PSH. No file change, and an older or newer build sounds the same. +- **The curve** (core/loud.cpp), corners joined by straight lines, PSH = the position: + + | LUD | CLP | MNO | GLU | + | --- | --- | --- | --- | + | 0 | 0 | 0 | 0 | + | 16 | 4 | 60 | 12 | + | 40 | 16 | 60 | 40 | + | 80 | 24 | 64 | 56 | + | 127 | 32 | 70 | 72 | + + 40 is core/factory.cpp's master, so the demo opens on the curve. +- **Measured** on A01, 8 bars, host render (`make -C host render` writes A01_LOUD000.wav …), + integrated loudness and true peak by ffmpeg's ebur128: + + | LUD | 0 | 16 | 40 | 64 | 80 | 100 | 127 | + | --- | --- | --- | --- | --- | --- | --- | --- | + | LUFS | -15.1 | -14.3 | -13.0 | -11.3 | -10.1 | -8.8 | -7.2 | + | true peak dB | -0.3 | -0.9 | -1.5 | -2.0 | -2.2 | -2.4 | -2.7 | + + About 0.065 LU a position all the way, so equal turns sound like equal steps. A first curve + with CLP rising to 72 gave only -9.0 LUFS at the top with the peaks at -6 dB: the clipper + brings its drive back down, so a hard CLP spends the headroom PSH made. Hence CLP climbs + slowest. Measured on one beat; a sparse or a sustained mix moves differently, which is what + OWN is for. diff --git a/docs/FEATURES.md b/docs/FEATURES.md index d7846576..fb1e7886 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -245,6 +245,7 @@ FM4 and GRAIN machines. | --- | --- | --- | --- | | Follows the unit's clock: internal, MIDI clock, SYNC IN; refuses tempo/transport under external clock | v0.1.0 | ○ (M7) | STRATA cannot set CLOCK SRC (Enaga has no setter). SYNC polarity not selectable (Enaga) | | Tap tempo on VALUE, nudge on FUNC + push VALUE + turn | v0.6.0 | ○ (W72, W80) | Internal clock only; nothing set until three taps agree within 25%; the nudge is 4% for 250 ms a detent | +| LOUD (MIXER CLIP, knob C): PSH, CLP, MNO and GLU on one tuned curve | Unreleased | ○ (W115), E (scenario_loud.sh) | Stores nothing: read back from the four bytes, `OWN` when one was turned by hand. Curve measured on A01 only (host render) | | KEYS LAYOUT (FUNC menu): SCALE puts the key's degrees on the pads, triads on a chord track's lower pads | Unreleased | ○ (W114), E (scenario_keyslayout.sh) | PIANO by default; saved with the project (one byte on the end of PROJECT.BIN's MIDI section). The emulator has no pads, so the notes are host-tested | | TEMPO GUARD (FUNC menu): VALUE's plain turn and tap show the tempo and leave it | Unreleased | ○ (W99), E (scenario_tempoguard.sh) | Off by default; saved with the project (one byte on the end of PROJECT.BIN's MIDI section). Nudge, VariSpeed, swing and section BPMs still play | | **Song tempo kept apart from the project's**: a section's BPM plays without becoming the saved tempo; ARR REC writes BPM only where the tempo changed (and the take's start tempo on its first entry); VariSpeed held back near 300 BPM says so and returns at a slower tempo | v0.6.0 | ○ (W80), E (scenario_sections.sh, scenario_arrrec.sh) | The clock no longer jumps back for a moment after a section BPM, a VALUE turn or a tap | diff --git a/docs/MANUAL.md b/docs/MANUAL.md index 9924d09b..6d5d74a5 100644 --- a/docs/MANUAL.md +++ b/docs/MANUAL.md @@ -1904,6 +1904,14 @@ master stages: Both are `OFF` in a new project and in every older one, and cost nothing when off. +- **LUD**, LOUD (C: `OFF`, `1` to `127`), is the one knob for all of this. It turns PSH, CLP, MNO + and the drum bus's GLU together along one curve, tuned on the factory beat so each click is + about as much louder as the last: `OFF` is the master with none of them, `40` the factory + master (A01 at -13 LUFS), `127` about -7 LUFS with the peaks still under -2 dB. MNO comes in + first and stays near 85 Hz, CLP and GLU rise slower than PSH. Turn a stage on its own page and + LUD reads `OWN`: the next turn of LUD puts all four back on the curve, from where PSH is. LUD + stores nothing of its own, so a project sounds the same in any build. + **DRUMS**, the page between CLIP and MST, is the drum bus. Every KICK, SNARE, HAT and PERC track's dry sound (after its own insert chain, before the master) is summed there and treated as one instrument, the way a producer glues the drums together on a bus: diff --git a/docs/UNIT_CHECKLIST.md b/docs/UNIT_CHECKLIST.md index 1fc90f6a..da0eaf26 100644 --- a/docs/UNIT_CHECKLIST.md +++ b/docs/UNIT_CHECKLIST.md @@ -3679,3 +3679,12 @@ the key A minor (PROJECT page, B to A, C to MINOR), PLAY. REC on, a pad's chord lands on one step. `____` - SAVE, NEW PROJECT, reopen it: the row still reads `SCALE`. Back to `PIANO` (OK on the row, `KEYS PIANO`): the pads are a keyboard again. `____` + +**W115. LOUD on the master (4 min).** On headphones and then on speakers. LOAD DEMO, A01, PLAY. +- MIXER, LEFT to CLIP: C reads `LUD 40` (the factory master). Turn C down to `OFF`: quieter and + more open, the kick's front sharper. Turn it up one detent at a time to `127` (`LOUD 42`, + `LOUD 44` …): each step a little louder and denser, with no jump anywhere; at the top the + kick is softened but not pumping, and nothing crackles. `____` +- While LUD turns, EQ's D (PSH), CLIP's A and B, DRUMS's C move with it. Turn CLP on its own: + LUD reads `OWN`. Turn LUD one detent: all four are back on the curve. `____` +- SAVE, RELOAD PROJECT: LUD reads what it read before the save. `____` diff --git a/host/render.cpp b/host/render.cpp index 717b111d..2a3b260e 100644 --- a/host/render.cpp +++ b/host/render.cpp @@ -17,6 +17,7 @@ #include "fakehost.hpp" #include "sounds.hpp" #include "arppresets.hpp" +#include "loud.hpp" #include "pattern.hpp" #include @@ -188,6 +189,25 @@ int main(int argc, char **argv) { for (int i = 0; i < kSendFields; i++) q.settings.sends[i] = saved[i]; } + // A01 along MIXER's LOUD curve (core/loud.hpp), the master's four bytes set and put back, + // for the curve's loudness steps (docs/DESIGN_NOTES.md, "LOUD"): A01_LOUD000.wav ... + { + Project &p = g_engine.project_for_load(); + uint8_t saved[kMasterFields]; + for (int i = 0; i < kMasterFields; i++) saved[i] = p.settings.master[i]; + static const int kPoints[] = {0, 16, 40, 64, 80, 100, 127}; + for (int point : kPoints) { + loud_apply(g_engine.project_for_load().settings.master, point); + int frames = 0; + const Stats s = render(0, bars, -1, &frames); + std::snprintf(path, sizeof path, "%s/A01_LOUD%03d.wav", dir, point); + write_wav(path, frames); + std::printf("A01 LOUD %3d peak %6.1f dBFS rms %6.1f dBFS %s\n", point, db(s.peak), db(s.rms), path); + } + Project &q = g_engine.project_for_load(); + for (int i = 0; i < kMasterFields; i++) q.settings.master[i] = saved[i]; + } + // A05 PAD again with the reverb in HALL mode -- a project setting (MIXER, REV+), so the // factory leaves it at ROOM for A01-A04's sake, but the pad is what HALL is for. { diff --git a/tests/scenario_loud.sh b/tests/scenario_loud.sh new file mode 100755 index 00000000..7e1696ce --- /dev/null +++ b/tests/scenario_loud.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash +# LOUD in the emulator (MIXER's CLIP page, knob C; core/loud.hpp): the factory beat playing, +# LUD turned all the way up and then back to the factory's 40. What it proves is what the host +# cannot: the knob reaches the engine on the C674x and the master at the top of the curve (PSH, +# CLP and the drum bus's GLU all well up) runs without an overrun and inside the target. That +# the four bytes move together is host-tested (tests/test_ui.cpp, +# ui_loud_turns_the_four_master_bytes_together); the curve's loudness is in docs/DESIGN_NOTES.md. +# +# Observable through Enaga's log: `LOUD n` for each detent the UI saw (the figure the UI showed; +# the engine moves from its own bytes), `scr MIXER CLIP`, `run int`. +# +# CLIP is four SELECT_LEFT presses from TRK 1-4 going round (EQ, MST, DRUMS, CLIP), as in +# tests/scenario_shaping.sh. Keys (third_party/enaga/include/enaga/abi.h): F5 = 22, F7 = 21, +# SELECT_LEFT = 8. Encoder 2 is C. The first press must come LATE (tests/scenario_m1.sh). +set -euo pipefail + +cd "$(dirname "$0")/.." +# shellcheck source=tools/env.sh +source tools/env.sh + +if [ "${1:-}" != "" ]; then + echo "error: unknown argument: $1" >&2 + exit 2 +fi + +if [ ! -f "$ENAGA_EMULATOR/cpu.py" ]; then + echo "SKIP: no emulator at $ENAGA_EMULATOR" >&2 + exit 0 +fi + +strata_require_toolchain +strata_link_emulator_toolchain +tools/build.sh > /dev/null + +STAGE="$ENAGA_BUILD/stage/STRATA" +mkdir -p "$ENAGA_BUILD" +LOG="$ENAGA_BUILD/scenario_loud.log" +CYCLES=2400000000 + +echo "running the emulator for $CYCLES cycles: play, MIXER CLIP, LUD to the top and back ..." +python3 -B tools/enaga_cached.py emulate "$STAGE" --cycles "$CYCLES" \ + --key 22@300000000 \ + --key 21@380000000 \ + --key 8@600000000 --key 8@640000000 --key 8@680000000 --key 8@720000000 \ + --turn 2:50@800000000 \ + --turn 2:-44@1700000000 \ + > "$LOG" 2>&1 || { + echo "FAIL: emulate.py exited non-zero" >&2 + tail -30 "$LOG" >&2 + exit 1 +} + +rc=0 +python3 - "$LOG" <<'PY' || rc=$? +import json, re, sys + +CYCLES_PER_BLOCK = 496_000 + +text = open(sys.argv[1]).read() +match = re.search(r'^\{.*?^\}', text, re.S | re.M) +if not match: + print(" FAIL no JSON report in the emulator output") + sys.exit(1) +report = json.loads(match.group(0)) + +failures = [] + +def check(ok, label, detail=""): + print(f" {'ok ' if ok else 'FAIL'} {label}{' ' + detail if detail else ''}") + if not ok: + failures.append(label) + +log = report.get("log", []) + +check(report.get("app_status") == "APP RUNNING", "app is running", + f'status={report.get("app_status")!r}') +check(not report.get("crash_reason"), "no crash", f'reason={report.get("crash_reason")!r}') +check("run int" in log or any(l.startswith("LOUD") for l in log), "the transport started", f"log={log}") +check("scr MIXER CLIP" in log or any(l.startswith("LOUD") for l in log), "reached MIXER CLIP", f"log={log}") +# Enaga's log ring keeps the last 16 lines, so only the last of the LOUD lines may be there: +# the turn back down ends on the factory's 40 or near it, and somewhere the knob went up. +louds = [int(l.split()[1]) for l in log if re.fullmatch(r"LOUD \d+", l)] +check(bool(louds), "LUD was turned and said its position", f"log={log}") +if louds: + check(30 <= louds[-1] <= 60, "back down near the factory's 40", f"lines={louds}") + +blocks = report.get("audio_blocks", 0) +check(blocks > 1000, "audio ran throughout", f"blocks={blocks}") +check(report.get("audio_overruns", -1) == 0, "no audio overruns", + f'overruns={report.get("audio_overruns")}') + +peak = report.get("audio_cycles_peak", 0) +percent = 100.0 * peak / CYCLES_PER_BLOCK +check(percent > 5.0, "the beat was sounding", f"{percent:.2f}% peak") +check(percent < 60.0, "load is inside the target", f"{percent:.2f}% peak") + +print() +print(f"emulator peak load: {percent:.2f}% ({peak} of {CYCLES_PER_BLOCK} cycles, {blocks} blocks)") + +sys.exit(1 if failures else 0) +PY + +echo +if [ "$rc" -ne 0 ]; then + echo "SCENARIO FAILED; full log: $LOG" >&2 + exit 1 +fi +echo "SCENARIO OK (log: $LOG)" diff --git a/tests/test_loud.cpp b/tests/test_loud.cpp new file mode 100644 index 00000000..1dea41ce --- /dev/null +++ b/tests/test_loud.cpp @@ -0,0 +1,67 @@ +// LOUD (core/loud.hpp): the curve's shape, that the factory master is a point on it, and that a +// position reads back from the bytes it wrote. The knob on MIXER's CLIP page is in +// tests/test_ui.cpp (ui_loud_turns_the_four_master_bytes_together). +#include "check.hpp" + +#include "buses.hpp" +#include "factory.hpp" +#include "loud.hpp" +#include "project.hpp" + +using namespace strata; + +TEST(loud_fields_are_the_masters_push_clip_mono_and_glue) { + CHECK_EQ(kLoudPushField, int(MasterField::push)); + CHECK_EQ(kLoudClipField, int(MasterField::clip)); + CHECK_EQ(kLoudMonoField, int(MasterField::mono_low)); + CHECK_EQ(kLoudGlueField, int(MasterField::drum_glue)); +} + +TEST(loud_zero_is_a_new_projects_master_and_forty_the_factorys) { + const ProjectSettings fresh; + CHECK_EQ(loud_position(fresh.master), 0); + + static Project factory; + static SceneSet scenes; + static MacroSet macros; + factory_project(factory, scenes, macros); + CHECK_EQ(loud_position(factory.settings.master), kLoudFactory); +} + +TEST(loud_climbs_every_byte_and_never_drops_one) { + LoudBytes last = loud_curve(0); + CHECK_EQ(int(last.push) + last.clip + last.mono + last.glue, 0); + for (int p = 1; p <= kLoudMax; p++) { + const LoudBytes now = loud_curve(p); + CHECK_EQ(int(now.push), p); + CHECK(now.clip >= last.clip); + CHECK(now.mono >= last.mono); + CHECK(now.glue >= last.glue); + CHECK(now.clip <= 127 && now.mono <= 127 && now.glue <= 127); + last = now; + } + // Clamped at both ends. + CHECK_EQ(int(loud_curve(-5).push), 0); + CHECK_EQ(int(loud_curve(400).push), kLoudMax); +} + +TEST(loud_reads_back_what_it_wrote_and_knows_a_hand_turned_byte) { + uint8_t master[kMasterFields] = {}; + for (int p = 0; p <= kLoudMax; p++) { + loud_apply(master, p); + CHECK_EQ(loud_position(master), p); + CHECK_EQ(loud_start(master), p); + } + loud_apply(master, 64); + master[kLoudClipField] = uint8_t(master[kLoudClipField] + 6); // CLP turned on its page + CHECK_EQ(loud_position(master), -1); + CHECK_EQ(loud_start(master), 64); // from its PSH + // The other master bytes are LOUD's to leave alone. + uint8_t other[kMasterFields]; + for (int i = 0; i < kMasterFields; i++) other[i] = uint8_t(10 + i); + loud_apply(other, 90); + for (int i = 0; i < kMasterFields; i++) { + if (i == kLoudPushField || i == kLoudClipField || i == kLoudMonoField || i == kLoudGlueField) continue; + CHECK_EQ(int(other[i]), 10 + i); + } +} diff --git a/tests/test_storage.cpp b/tests/test_storage.cpp index 30624dbb..228a893c 100644 --- a/tests/test_storage.cpp +++ b/tests/test_storage.cpp @@ -526,6 +526,7 @@ const Expect kTable[] = { // from, so both dirty the project. {Cmd::set_sends, kDirtyProject, "set_sends"}, {Cmd::set_master, kDirtyProject, "set_master"}, + {Cmd::set_loud, kDirtyProject, "set_loud"}, {Cmd::set_duck, kDirtyKit, "set_duck"}, {Cmd::set_input, kDirtyProject, "set_input"}, // The kill EQ's switches, in the same section as the master bytes. diff --git a/tests/test_ui.cpp b/tests/test_ui.cpp index edcbdd0f..a2346ad2 100644 --- a/tests/test_ui.cpp +++ b/tests/test_ui.cpp @@ -97,6 +97,9 @@ struct UiProbe { static int page(const Strata &app) { return app.page_; } static int param_page(const Strata &app) { return app.param_page_; } static int mixer_bank(const Strata &app) { return app.mixer_bank_; } + static void mixer_knob(Strata &app, int slot, char *name, char *value, bool &empty) { + app.mixer_knob_parts(slot, name, value, empty); + } static void mixer_knob_parts(Strata &app, int slot, char *name, char *value, bool &empty) { app.mixer_knob_parts(slot, name, value, empty); } @@ -3325,6 +3328,54 @@ void press_key(Strata &app, int code) { app.on_key(code, false); } +// LUD, the CLIP page's knob C (core/loud.hpp): one turn moves PSH, CLP, MNO and GLU together, +// a hand-turned CLP takes the master off the curve (OWN), and LUD again puts all four back. +TEST(ui_loud_turns_the_four_master_bytes_together) { + Strata &app = fresh(); + Engine &engine = app_engine(); + const int clip_page = kMixerShapePage + 1; + mixer_page(app, clip_page); + CHECK_EQ(int(kMixerPages[clip_page].field[2]), int(kMixerLoudField)); + const uint8_t *master = engine.project().settings.master; + const int before = loud_start(master); + + app.on_encoder(2, +3); + pump(); + const int after = before + 3 * kLoudClick; + CHECK_EQ(loud_position(master), after); + const LoudBytes want = loud_curve(after); + CHECK_EQ(int(master[int(MasterField::push)]), int(want.push)); + CHECK_EQ(int(master[int(MasterField::clip)]), int(want.clip)); + CHECK_EQ(int(master[int(MasterField::mono_low)]), int(want.mono)); + CHECK_EQ(int(master[int(MasterField::drum_glue)]), int(want.glue)); + char said[24]; + std::snprintf(said, sizeof said, "LOUD %d", after); + CHECK_EQ(UiProbe::notice(app), static_cast(said)); + + // CLP by hand: off the curve, which LUD's value says. + app.on_encoder(0, +2); + pump(); + CHECK_EQ(loud_position(master), -1); + char name[8], value[8]; + bool empty = false; + UiProbe::mixer_knob(app, 2, name, value, empty); + CHECK(std::strcmp(name, "LUD") == 0); + CHECK(std::strcmp(value, "OWN") == 0); + + // LUD from there starts at the master's PSH and lands back on the curve. + app.on_encoder(2, -1); + pump(); + CHECK_EQ(loud_position(master), after - kLoudClick); + + // All the way down is OFF: the four at 0. + app.on_encoder(2, -100); + pump(); + CHECK_EQ(loud_position(master), 0); + CHECK_EQ(UiProbe::notice(app), "LOUD OFF"); + UiProbe::mixer_knob(app, 2, name, value, empty); + CHECK(std::strcmp(value, "OFF") == 0); +} + // SLAP: the selected track's echo, its four knobs and two pushes, said and logged. TEST(ui_the_slap_page_sets_the_selected_tracks_echo) { Strata &app = fresh();