Skip to content

feat(midi)!: add MIDI keybed, channel map and latch - #69

Open
google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/add-midi-keybed-channel-map-and-latch-jm0-1541bed2-9af0-43cf-af10-a10baceebf89
Open

google-labs-stitch[bot] wants to merge 8 commits into
mainfrom
stitch/add-midi-keybed-channel-map-and-latch-jm0-1541bed2-9af0-43cf-af10-a10baceebf89

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Target 0.4.0 Window (feat(midi)!) & Synced onto main (8880205): Preserve held 16-channel keybed notes across HarmonySource switches and release MidiOmni notes per channel rather than across all channels, while keeping HarmonyConfig::default() (MidiChannels, voices = 4, unison [0; 4] intervals, BaseWindow, midi_base_channel = 0), #104 Telemetry, and #61 ParameterControl / stage diff-guards intact.
  • Compact Heap-Backed 16x128 MidiKeybed & Narrowed Live Re-projection: Record every validated ControlEvent::Midi message in MidiKeybed (held: [u128; 16] inline, with velocity: Box<[[u8; 128]; 16]> and order: Box<[[u32; 128]; 16]> allocated directly on the heap and compacted at u32::MAX, keeping inline MidiKeybed at 280 bytes and zero post-construction allocations). Re-project held notes across live transitions among MidiOmni, ChordViaMidi, and MidiChannels (and active channel-map changes), while narrowing HarmonyState::apply_config so edits only to midi_channel_map or midi_base_channel skip setup_chord() and inactive channel-map edits make zero state or sample changes.
  • #[non_exhaustive] MidiChannelMap, ControlActivity Flags & Immediate MidiChannels NoteOff (#46 & #123 Alignment): Add #[non_exhaustive] MidiChannelMap (#[default] BaseWindow, WrapFour) and midi_base_channel (0..=12, default 0) to HarmonyConfig with serde(default, deserialize_with = ...) and tsify(optional, type = "... | undefined") so both omitted and undefined values decode to defaults under exactOptionalPropertyTypes. Expose harmony_midi_channel_map and harmony_midi_base_channel on ControlActivity (harmonyMidiChannelMap and harmonyMidiBaseChannel in TypeScript). Return control_due = true on NoteOff for mapped MidiChannels voices so voice release starts on frame 1 instead of waiting up to 99 frames.
  • 128-Note CorrectionTable & #[non_exhaustive] CorrectionMidiMode: Replace the boolean keyboard array in CorrectionTable with u128 bitmasks covering notes 0..=127 (127 -> PitchClass::G). Add #[non_exhaustive] CorrectionMidiMode (#[default] Momentary, Latch) to CorrectionConfig (serde(default, deserialize_with = ...), tsify(optional, type = "CorrectionMidiMode | undefined")), restoring CorrectionConfig::notes on full key release in Momentary mode, retaining simultaneous or rolled chords across key release in Latch mode until MidiEvent::AllNotesOff, Processor::reset(), or scale/mode updates, and preserving humanize dwell across latched NoteOff events.
  • Exports & Documentation: Export MidiChannelMap and CorrectionMidiMode in src/lib.rs and TypeScript declarations, and update rustdoc, normalized JSDoc, scripts/verify-pack.mjs, and README.md in ASD-STE100 Simplified Technical English.

Verification

Verification Summary

  • cargo rustc --locked --lib --release -- -D warnings
  • cargo fmt --check
  • cargo clippy --locked --lib -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo package --locked
  • npm run check:wasm
  • npm run verify:pack & npm run verify:pack -- --ignore-scripts
  • Verified sample-exact ProcessorConfig::default() (Choir) PCM output and Telemetry slices with ParameterControl at 44.1 kHz and 48 kHz against main (8880205), 0 post-construction heap allocations, external-crate #[non_exhaustive] enforcement on MidiChannelMap and CorrectionMidiMode, ControlActivity flags (harmony_midi_channel_map, harmony_midi_base_channel) and zero-sample-change contract when inactive, narrowed HarmonyState::apply_config skipping setup_chord() on channel-map edits, frame-1 MidiChannels NoteOff release, live MidiOmni / ChordViaMidi / MidiChannels keybed re-projection (0 / 4 stuck voices), WrapFour 0..=15 folding + 128-note legato fallback, BaseWindow 0..=12 validation, and Momentary / Latch scale control across notes 0..=127.

Automated PR initiated by user @byteland-app via Stitch Loop.

- Set SmartInterval as the default harmony source with two voices
- Set musical default intervals for diatonic and chromatic harmony
- Record all 16 MIDI channels and 128 notes in a fixed-size keybed
- Project held keybed notes across live MIDI source transitions
- Add MidiChannelMap and midi_base_channel with legato note fallback
- Add ignored_midi_events and correction_midi_active to Telemetry
- Use a u128 bitmask for correction MIDI notes 0..=127
- Add CorrectionMidiMode with Momentary and Latch scale control
- Export the new types and optional fields to WebAssembly and README
@byteland-app

Copy link
Copy Markdown
Contributor

Review: The u128 128-key CorrectionTable, Momentary/Latch correction MIDI modes, and cross-mode keybed reprojection are very useful. However, this PR needs splitting and rework:

  1. It bundles breaking default changes (HarmonyConfig::default(), default_voices 4 -> 2) and non-exhaustive Telemetry additions without a '!' marker.
  2. Defaulting MidiChannelMap to WrapFour routes DAW channels 4–15 into harmony voices; BaseWindow (base 0) is a safer, backward-compatible default.
  3. MidiKeybed adds +18.7 KB inline in HarmonyState (u64 order matrix); switching to u32 sequence counters or boxing avoids stack bloat during construction.

- Keep HarmonyConfig::default() and default_voices() at four voices.
- Remove ignored_midi_events and correction_midi_active from Telemetry.
- Set MidiChannelMap::BaseWindow with base channel 0 as the default.
- Store MidiKeybed velocity and u32 order tables on the heap.
- Compact held note orders at u32::MAX.
- Accumulate rolled chords in CorrectionMidiMode::Latch.
- Update the rustdoc and README.md for the default settings.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Merged main (v0.3.3, resolving the conflicts in src/harmony.rs and src/scale.rs) and reworked PR #69 as requested (5d16e7a):

  1. Unbundled breaking defaults & exhaustive Telemetry additions: Restored HarmonyConfig::default() (HarmonySource::MidiChannels, unison [0; 4] intervals, voices = 4, and default_voices() -> 4) and reverted the ignored_midi_events and correction_midi_active additions on Telemetry so this PR introduces zero breaking changes.
  2. Safer backward-compatible channel map default: Changed MidiChannelMap::default() from WrapFour to BaseWindow (with midi_base_channel = 0), keeping channels 0..=3 mapped to voices 0..=3 and ignoring DAW channels 4..=15 unless configured otherwise.
  3. Eliminated MidiKeybed stack bloat: Switched note sequence counters from u64 to u32 (with deterministic order compaction at u32::MAX) and moved the velocity (Box<[[u8; 128]; 16]>) and order (Box<[[u32; 128]; 16]>) matrices onto the heap via direct boxed-slice initialization (prepare_keybed_table). Inline MidiKeybed drops from 18,696 bytes to 280 bytes (with the heap order matrix halved from 16 KB to 8 KB) and keeps zero post-construction allocations.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Thank you for restoring the defaults, boxing u32 keybed tables, defaulting to BaseWindow, and removing breaking Telemetry fields. Because #46 is landing as the clean 0.3.x MIDI bug fix, please rebase onto updated main after #46 and #123 and address three remaining items:

  1. Mark the new MidiChannelMap and CorrectionMidiMode enums as #[non_exhaustive].
  2. Align MidiChannels NoteOff behavior with fix(midi): reset harmony on source change and fix correction keys #46 (returning control_due = true when releasing a voice so release starts immediately instead of waiting up to 99 frames).
  3. Since preserving keybed notes across HarmonySource switches and per-channel MidiOmni NoteOff change documented v0.3.x runtime behavior, let's target the 0.4.0 window.

- Merge main v0.3.4 into the MIDI keybed branch.
- Mark MidiChannelMap and CorrectionMidiMode as #[non_exhaustive].
- Return true on Note Off for active MidiChannels channels.
- Decode undefined optional MIDI fields to their defaults in Wasm.

BREAKING CHANGE: Source changes keep held notes in the MIDI keybed.
@google-labs-stitch google-labs-stitch Bot changed the title feat(midi): add MIDI keybed, channel map and latch feat(midi)!: add MIDI keybed, channel map and latch Nov 25, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Thanks for the Round 2 review! Synced onto updated main (v0.3.4, after #46, #123, and #135, resolving conflicts across README.md and the MIDI/scale/harmony modules) and addressed all remaining items (3fb9932):

  1. #[non_exhaustive] on new public enums: Marked both MidiChannelMap (src/harmony.rs) and CorrectionMidiMode (src/scale.rs) as #[non_exhaustive]. Also aligned midi_channel_map, midi_base_channel, and midi_mode with #123 (deserialize_default + | undefined tsify types) so both omitted and explicit undefined values decode to defaults under exactOptionalPropertyTypes: true.
  2. Immediate MidiChannels NoteOff release (#46 alignment): Updated HarmonyState::apply_validated_midi so HarmonySource::MidiChannels updates reproject_channels() and returns control_due = true for every NoteOn and NoteOff on a mapped channel (starting voice gain release on frame 1 instead of waiting up to 99 frames), while unmapped channels still return false.
  3. Target 0.4.0 window: Updated the PR title (feat(midi)!: add MIDI keybed, channel map and latch) and commit (feat(midi)!: + BREAKING CHANGE: footer) so release-please (bump-minor-pre-major: true) targets the 0.4.0 release window for keeping held keybed notes across HarmonySource switches and per-channel MidiOmni NoteOff.

- Merge main into the feature branch and resolve conflicts.
- Keep humanize dwell across latched correction Note Off events.
- Normalize the new MIDI rustdoc links in scripts/normalize-jsdoc.mjs.
- Check absent and undefined MIDI fields in scripts/verify-pack.mjs.
@byteland-app

Copy link
Copy Markdown
Contributor

Review: MidiKeybed, order compaction, bitmask CorrectionTable, and Latch logic look solid. Three items before merge:

  1. Expose new conditional controls in ControlActivity (src/config.rs): Add flags for HarmonyConfig::midi_channel_map (active when mode == Harmony && source == MidiChannels) and HarmonyConfig::midi_base_channel (active when mode == Harmony && source == MidiChannels && midi_channel_map == BaseWindow), and update rustdoc, Wasm/TS, and README.md to match the other conditional HarmonyConfig fields.
  2. Narrow HarmonyState::apply_config (src/harmony.rs): Avoid calling setup_chord() when only midi_channel_map or midi_base_channel changes.
  3. Sync onto updated main (build(cargo): bump the cargo group with 2 updates #139, ci: deny compiler and rustdoc warnings in scripts and docs #131, feat!: add pitch fields to Telemetry and trim Wasm voice slices #104, feat(events)!: add scalar parameter control events #61): Preserve feat(events)!: add scalar parameter control events #61's ParameterControl / diff-guards and feat!: add pitch fields to Telemetry and trim Wasm voice slices #104's Telemetry. (We plan to merge feat(midi)!: add MIDI keybed, channel map and latch #69 ahead of feat(midi)!: add pitch bend and sustain support #56 so feat(midi)!: add pitch bend and sustain support #56 can build on MidiKeybed and MidiChannelMap.)

…-jm0-1541bed2-9af0-43cf-af10-a10baceebf89

- Resolve merge conflicts with scalar parameters and Wasm checks.
- Add harmony MIDI channel map flags to ControlActivity.
- Narrow HarmonyState::apply_config to skip extra chord setup.
- Update Rustdoc, README and pack verification for ControlActivity.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Synced onto updated main (8880205, including #139, #131, #104, and #61) and addressed all three items in d32fa1b:

  1. Exposed conditional MIDI controls in ControlActivity (src/config.rs): Added ControlActivity::harmony_midi_channel_map (harmonyMidiChannelMap in TypeScript, active when mode == MultiVoiceMode::Harmony && source == HarmonySource::MidiChannels) and ControlActivity::harmony_midi_base_channel (harmonyMidiBaseChannel in TypeScript, active when mode == MultiVoiceMode::Harmony && source == HarmonySource::MidiChannels && midi_channel_map == MidiChannelMap::BaseWindow). Updated rustdoc across src/config.rs, src/harmony.rs, src/processor.rs, and src/wasm.rs, normalized JSDoc in scripts/normalize-jsdoc.mjs, runtime/TypeScript/JSDoc checks in scripts/verify-pack.mjs, and README.md.
  2. Narrowed HarmonyState::apply_config (src/harmony.rs): Kept the exact chord-affecting diff-guard on setup_chord() so changes only to midi_channel_map or midi_base_channel skip setup_chord(), and narrowed keybed re-projection so reproject_channels() runs only when source == HarmonySource::MidiChannels and the active channel map (midi_channel_map, or midi_base_channel under BaseWindow) changes.
  3. Synced onto main (8880205): Merged #139, #131, #104, and #61 without rewriting commit history, preserving #61's ParameterControl events and stage diff-guards, #104's Telemetry pitch fields and active-voice Float32Array slices, and #131's -D warnings compiler/rustdoc gates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant