# DESIGN SPECIFICATION & IMPLEMENTATION ROADMAP: FLOATING VIRTUAL MIDI KEYBOARD & CHORDS PANEL ENGINE
This document specifies the technical architecture, UI/UX design, data flow diagrams, and interaction matrices for integrating two core features into the DAW system:
1. **Floating Virtual MIDI Keyboard:** A draggable floating virtual keyboard window that receives input from computer QWERTY keys, supporting both live preview and real-time recording of MIDI notes directly into the Timeline / Piano Roll.
2. **Comprehensive Scale & Chords System / Insert Chords Panel:** A multi-genre chord theory engine, automated chord progression insertion panel, custom chord builder/storage, and internet/AI chord lookup system.
---
## I. SYSTEM ARCHITECTURE OVERVIEW
```text
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CLIENT FRONTEND STUDIO │
│ │
│ ┌─────────────────────────────────────────┐ ┌─────────────────────────────────────┐ │
│ │ Menu: Tools -> Virtual MIDI Keyboard │ │ Menu: Insert -> Chords panel │ │
│ │ Shortcut: [F2] │ │ Shortcut: [Shift + K] │ │
│ └────────────────────┬────────────────────┘ └──────────────────┬──────────────────┘ │
└────────────────────────┼─────────────────────────────────────────────────┼──────────────────────┘
│ │
▼ ▼
┌──────────────────────────────────────────────────┐ ┌────────────────────────────────────────┐
│ FLOATING VIRTUAL MIDI KEYBOARD (UI OVERLAY) │ │ INSERT CHORDS PANEL (MODAL / SIDEBAR) │
│ - Visual 25/49-Keybed Rendering │ │ - Style Catalog (Pop, Jazz, Epic...) │
│ - QWERTY Key Mapping Engine │ │ - Custom Chord Builder & LocalStorage │
│ - Octave Shift (-4 to +4) & Velocity Adjuster │ │ - Internet / AI Chord Search Engine │
└────────────────────────┬─────────────────────────┘ └─────────────────┬──────────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│ UNIFIED MIDI ROUTER & DISPATCHER │
│ - Normalizes to `UnifiedMidiEvent`: { command, channel, pitch, velocity, timestamp } │
└────────────────────────┬─────────────────────────────────────────────────┬──────────────────────┘
│ │
├─────────────────────────────────┐ │
▼ ▼ ▼
┌──────────────────────────────────────────────────┐ ┌────────────────────────────────────────────┐
│ REAL-TIME SYNTH ENGINE (CLIENT WASM / BRIDGE) │ │ CLIENT MIDI RECORDER & TIMELINE INGESTION │
│ - Real-time Audio Preview (< 5ms Latency) │ │ - Live Recording to active `MIDIItem` │
│ - FluidSynth WASM / Native VSTi Bridge │ │ - Direct Canvas Redraw on Piano Roll │
└──────────────────────────────────────────────────┘ └────────────────────────────────────────────┘
```
---
## II. PART I: FLOATING VIRTUAL MIDI KEYBOARD SYSTEM
### 1. Activation & Floating Window Management
* **Activation Triggers:**
* **System Shortcut:** **F2** (Toggle On/Off).
* **Menu Bar:** **Tools ▾ -> Virtual MIDI Keyboard**.
* **Window Properties:**
* **Floating & Draggable:** Allows dynamic positioning across MAIN SESSION, SECTION-TAB, and PIANO ROLL TAB views.
* **Always-on-Top / Z-Index Isolation:** Renders above all Timeline Canvases without capturing global Transport hotkeys (**Space** for Play/Stop, **R** for Record).
* **State Persistence:** Saves coordinates ($x, y$), active toggle state, current octave offset, and default velocity to `localStorage`.
---
### 2. Virtual Keyboard User Interface Layout
```text
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ 🎹 VIRTUAL MIDI KEYBOARD [–] [X] │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ [ Octave: -1 ] [ Octave: +1 ] │ Octave Shift: 4 (C4-C6) │ Velocity: [ 100 ] [Slider---|] │
│ [ Channel: 1 ▾ ] │ Transpose: 0 semitones │ Scale Highlight: [ C Minor ▾ ] │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | │
│ | |W| |E | |T| |Y| |U | |2| |3 | |5| |6| |7 | | | | | | | | | | | │
│ | |_| |_| | |_| |_| |_| | |_| |_| | |_| |_| |_| | |_| |_| | |_| |_| |_| | │
│ | A | S | D | F | G | H | J | K | Q | W | E | R | T | Y | U | I | O | P | | | | │
│ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ │
└────────────────────────────────────────────────────────────────────────────────────────┘
```
#### Keyboard Control Bar Components:
* **Octave Down / Up (`[Oct -]`, `[Oct +]`):** Shifts pitch octave range (Shortcuts: **Shift + Z** / **Shift + X** or **[** / **]**).
* **Velocity Slider:** Adjusts note velocity from **1 to 127** (Default: **100**).
* **Target MIDI Channel:** Selects MIDI Channel from **1 to 16** (Defaults automatically to the currently selected/armed track's channel).
* **Scale Highlight Toggle:** Visual keybed guide highlighting keys that belong to the active musical scale.
---
### 3. Computer QWERTY Keyboard Mapping Matrix
Uses two rows of QWERTY keys to span two continuous octaves:
#### Lower Octave (Root Base):
| Computer Key | Relative Pitch | Note Name | Key Type |
| --- | --- | --- | --- |
| **Z** | $\text{Root} + 0$ | C | White Key |
| **S** | $\text{Root} + 1$ | C# / Db | Black Key |
| **X** | $\text{Root} + 2$ | D | White Key |
| **D** | $\text{Root} + 3$ | D# / Eb | Black Key |
| **C** | $\text{Root} + 4$ | E | White Key |
| **V** | $\text{Root} + 5$ | F | White Key |
| **G** | $\text{Root} + 6$ | F# / Gb | Black Key |
| **B** | $\text{Root} + 7$ | G | White Key |
| **H** | $\text{Root} + 8$ | G# / Ab | Black Key |
| **N** | $\text{Root} + 9$ | A | White Key |
| **J** | $\text{Root} + 10$ | A# / Bb | Black Key |
| **M** | $\text{Root} + 11$ | B | White Key |
#### Upper Octave ($+12$ Semitones):
| Computer Key | Relative Pitch | Note Name | Key Type |
| --- | --- | --- | --- |
| **Q** | $\text{Root} + 12$ | C (+1 Oct) | White Key |
| **2** | $\text{Root} + 13$ | C# (+1 Oct) | Black Key |
| **W** | $\text{Root} + 14$ | D (+1 Oct) | White Key |
| **3** | $\text{Root} + 15$ | D# (+1 Oct) | Black Key |
| **E** | $\text{Root} + 16$ | E (+1 Oct) | White Key |
| **R** | $\text{Root} + 17$ | F (+1 Oct) | White Key |
| **5** | $\text{Root} + 18$ | F# (+1 Oct) | Black Key |
| **T** | $\text{Root} + 19$ | G (+1 Oct) | White Key |
| **6** | $\text{Root} + 20$ | G# (+1 Oct) | Black Key |
| **Y** | $\text{Root} + 21$ | A (+1 Oct) | White Key |
| **7** | $\text{Root} + 22$ | A# (+1 Oct) | Black Key |
| **U** | $\text{Root} + 23$ | B (+1 Oct) | White Key |
| **I** | $\text{Root} + 24$ | C (+2 Oct) | White Key |
---
### 4. Audio Playback & Recording Event Pipeline
#### Key Press Handler (`KeyDown` Event):
1. Verifies `e.repeat` is false to prevent event flood on key holds.
2. If the active DOM element is a text input field (``, `