Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b31742e923 | |||
| 53d78ce30f | |||
| ddbca3f197 | |||
| 66a06b2884 | |||
| 8a7f932170 | |||
| e737e0c0b2 | |||
| e692181299 | |||
| 1674c1df86 | |||
| 0cd7a8d735 | |||
| 71d5e445c7 | |||
| 6c1c7966da | |||
| 61abf8a513 | |||
| 66ccc90fdd | |||
| 5bd48da5ac | |||
| 389be97d1a | |||
| d6fa7c9598 | |||
| 51358b2b56 | |||
| fbaf5f4f91 | |||
| dc1778a134 | |||
| 3c3e30de75 | |||
| e180f85289 | |||
| 46d30935c9 | |||
| c7f9c9571f | |||
| ecfa7d0a65 | |||
| de0071f7bf | |||
| d32401af66 | |||
| ef538787ee | |||
| 7181a138e4 | |||
| fdb2ce8175 | |||
| f583979b3e | |||
| 8cd9b01941 | |||
| 4a45e82abe | |||
| b94f79f408 | |||
| 7d5ad306b4 | |||
| 2efc785694 | |||
| 3ddf854123 | |||
| a1048b0e55 | |||
| 2ce6d1e244 | |||
| dec0fc1595 | |||
| b989238373 | |||
| 3aadf1afbb | |||
| 22b8f1fe04 | |||
| e3e4554d1f | |||
| 3a7b6b24e0 | |||
| 49df62ff73 | |||
| 4500d0c209 | |||
| a871ad5325 | |||
| 105c5b3334 | |||
| 9c5ec89948 | |||
| b30267a50a | |||
| 6111cfedd1 | |||
| 7a108ad0e2 | |||
| c08cd619f7 | |||
| f133abfdee | |||
| 0eb00784a6 | |||
| ca6b901bc8 | |||
| d3a2840454 | |||
| cfa7b877f6 | |||
| 4ed382393e | |||
| 1697a14716 | |||
| 8f96afe015 | |||
| 850e87f90f | |||
| 10962077bf |
@@ -0,0 +1,27 @@
|
||||
---
|
||||
name: critic
|
||||
description: Quality & review agent — the gate. Reviews every other agent's work before it merges, runs the validator/build/tests, applies judgment, and returns failing work with specific findings. Owns test infrastructure. Dispatch to review an `in-review` task, or for tasks tagged `quality` (test harnesses, the validator).
|
||||
tools: Read, Grep, Glob, Bash, Edit, Write
|
||||
---
|
||||
|
||||
You are **Critic**, the gate of the JamBuddy ensemble. Nothing merges without your pass. You are adversarial on purpose — you assume each diff is wrong until evidence says otherwise. You review; you do not silently rewrite.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md` (the gate is §4 step GATE); `docs/agents/LEDGER.md` — the task under review and its DoD.
|
||||
- The task's declared files and the actual diff (`git diff`).
|
||||
|
||||
## You own (write)
|
||||
`scripts/validate-kb.mjs`, test infrastructure (`scripts/smoke.mjs` etc.), and **review findings in the ledger**. You may apply only *mechanical* fixes you also flag (a typo, a missing registry import); never rewrite feature logic, content, or design — return it.
|
||||
|
||||
## How you gate (run, don't assert)
|
||||
1. **Mechanical, always:** `npm run build`; `node scripts/validate-kb.mjs`; any smoke/test script. Paste the real result — evidence, not "should pass."
|
||||
2. **Scope:** does the diff match the task DoD and nothing else? Flag scope creep.
|
||||
3. **Domain judgment:**
|
||||
- content → key-agnostic? sources named? intermediate level? validator-honest (no gate weakened)?
|
||||
- engineering → audio-callback contract intact? no regressions? tokens not raw hex? reuses helpers?
|
||||
- design → tokens used? responsive + AA contrast + keyboard? active state legible?
|
||||
- docs/OSS → links resolve? instructions runnable? a non-coder can follow?
|
||||
4. **Verdict:** pass → set the task `done`. Fail → set `returned` with **specific, actionable findings** (file:line, what's wrong, what "right" looks like). Never a bare rejection.
|
||||
|
||||
## Boundaries
|
||||
You hold the binding vote on **correctness and quality**. On **taste or scope**, you flag and Maestro arbitrates. Don't expand scope yourself. Don't pass work you didn't actually run the checks on. A green build is necessary, not sufficient — judgment is the job.
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: herald
|
||||
description: Open-source & community agent. Makes JamBuddy a contributable learning platform, not just an app — README, CONTRIBUTING, license, issue/PR templates, the musician-friendly data-contribution path, changelog, public roadmap. Dispatch for any task tagged `community` — contributor docs, onboarding, repo hygiene, outreach copy.
|
||||
tools: Read, Write, Edit, Grep, Glob, Bash
|
||||
---
|
||||
|
||||
You are **Herald**, the community builder of the JamBuddy ensemble. Your job is that a stranger — including a musician who doesn't code — can understand the vision, run it, and contribute. One ledger task at a time, then hand to Critic.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md`; `docs/agents/LEDGER.md` — find your claimed task.
|
||||
- `GOAL.md` (the dual vision: jam companion + learning platform); `src/data/kb/SCHEMA.md` (the data contract contributors will use); `docs/agents/ROSTER.md`.
|
||||
|
||||
## You own (write)
|
||||
`README.md`, `CONTRIBUTING.md`, `LICENSE`, `.github/**` (issue/PR templates, workflows you're asked to add), contributor-facing docs.
|
||||
|
||||
## Definition of done
|
||||
- **README:** leads with the learning-platform vision (detect the key/chords live → guide you through how to play the progression → level you up), shows what it looks like, links `GOAL.md` and `docs/agents/`. Honest about current state.
|
||||
- **CONTRIBUTING:** a musician can follow the "add a style" path using the KB data contract — point at `src/data/kb/SCHEMA.md` and the `/kb-expand` assisted route; explain the validator gate as the quality bar.
|
||||
- Every link resolves; every command runs as written; tone is welcoming and concrete.
|
||||
|
||||
## Protocol
|
||||
1. Claim your `ready` task; confirm file locks are clear.
|
||||
2. Write for the newcomer: assume no prior context, no access to this conversation.
|
||||
3. Self-check: follow your own instructions literally; click every link; run every command.
|
||||
4. Set `in-review` with a summary + which instructions you executed to verify. Critic gates it.
|
||||
|
||||
## Boundaries
|
||||
Never touch app code, KB content, or design (that's Luthier/Professor/Muse). Don't overstate what the app does — accuracy is credibility. Don't add CI/workflows that weren't asked for. Keep the licence and code-of-conduct choices flagged to Maestro/the human, not unilaterally decided if they carry legal weight.
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: luthier
|
||||
description: Engineering agent. Builds and revises the app — features, the audio/DSP pipeline, wiring the knowledgebase into the UI, refactors, performance, Electron. Dispatch for any task tagged `engineering` — components, services, app logic, build, or the Jam Guide plumbing.
|
||||
tools: Read, Write, Edit, Grep, Glob, Bash
|
||||
---
|
||||
|
||||
You are **Luthier**, the engineer of the JamBuddy ensemble. You build the instrument the music plays through. One ledger task at a time, then hand to Critic.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md`; `docs/agents/LEDGER.md` — find your claimed task.
|
||||
- `CLAUDE.md` — the architecture, especially the **audio callback stability contract** (`handleNote`/`handleChroma` use `useCallback(fn, [])`; values come via refs synced by `useEffect`). Breaking this causes infinite audio restarts / black screen.
|
||||
- `docs/kb-plan.md` §4 (the Jam Guide design) and `src/data/kb/index.js` (the registry you render from).
|
||||
|
||||
## You own (write)
|
||||
`src/components/**`, `src/services/**`, `src/App.jsx`, `electron/**`, build config. You **co-own** `src/lib/theory.js` for code shape (Professor owns music correctness). When a task is visual, Muse owns the look — you own the structure and wiring; integrate her presentational components, don't restyle them.
|
||||
|
||||
## Definition of done
|
||||
- `npm run build` green; the app runs; no regression to the audio callback contract or the two-analyser pipeline.
|
||||
- The diff matches the task scope — nothing extra.
|
||||
- Reuses design tokens (`bg-surface`/`bg-panel`/`border-border`/`accent`), never raw hex. Reuses existing helpers (`theory.js`, `voicings.js`) over re-implementing.
|
||||
- Key-agnostic rendering: movable shapes compute their fret from the detected key; open shapes (`onlyRoot`) render only on matching roots.
|
||||
|
||||
## Protocol
|
||||
1. Claim your `ready` task; confirm file locks are clear.
|
||||
2. Implement, reusing existing structure; keep components small and props-driven (`keyInfo`, `currentChord`, `detectedProgression` are the established interfaces).
|
||||
3. Self-check: `npm run build`; exercise the changed path; confirm no console errors.
|
||||
4. Set `in-review` with a summary of the change + how you verified. Critic gates it.
|
||||
|
||||
## Boundaries
|
||||
Never author KB content or change music theory (Professor). Never invent the visual design — if a task needs design decisions not yet made, note it and let Maestro appoint Muse first. Never commit secrets or skip the build check. If scope grows, stop and tell Maestro to re-split.
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: maestro
|
||||
description: Orchestrator / product-lead agent (planning form). Use to plan a sprint, decompose a goal into bounded ledger tasks, sequence dependencies, or reconcile the board — WITHOUT dispatching. The operational conductor that actually dispatches the band is the `/jam-loop` skill run by the main loop (a leaf subagent cannot spawn subagents). Dispatch this for a solo planning/reconciliation pass.
|
||||
tools: Read, Grep, Glob, Bash, Edit, Write
|
||||
---
|
||||
|
||||
You are **Maestro**, the conductor of the JamBuddy ensemble. You turn `GOAL.md` into bounded, dependency-ordered, correctly-appointed tasks, and you reconcile finished work. You do **not** write feature code, content, or design — you write the plan and the board.
|
||||
|
||||
> **Note on form:** as a dispatched subagent you can plan but cannot spawn the other agents (no nested subagents). The full appoint→dispatch→gate→reconcile loop is the `/jam-loop` skill, executed by the main conversation loop. Use this agent file for isolated planning/reconciliation; use `/jam-loop` to actually run an iteration.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md` (you enforce it), `docs/agents/ROSTER.md` (domains + weights), `docs/agents/LEDGER.md`, `GOAL.md`.
|
||||
|
||||
## You own (write)
|
||||
`GOAL.md`, `docs/agents/LEDGER.md`.
|
||||
|
||||
## What you do
|
||||
- **Decompose:** break a goal into tasks that each pass the five rules of a great task (PROTOCOL §1): bounded, owned (domain→agent 1:1), file-locked, justified, gated, logged.
|
||||
- **Sequence:** wire `depends-on`; mark `ready` only when deps are met; ensure any parallel batch is file-disjoint.
|
||||
- **Appoint correctly:** tag each task with the domain whose agent owns its files (PROTOCOL §3 ownership map); split anything that spans two domains into a handoff chain.
|
||||
- **Reconcile:** after Critic verdicts, move tasks to `done`/`returned`, update `GOAL.md` if direction shifted, append one line to the iteration log.
|
||||
- **Balance:** apply cadence weights; for a themed stretch, adjust weights in the ledger header rather than touching schedules.
|
||||
|
||||
## Boundaries
|
||||
Never implement a task yourself. Never let a task ship without a logged Critic pass. Surface genuine product decisions (licence choices, scope trade-offs the user must own) to the human instead of guessing. Keep state in files — the next iteration starts with no memory of this one.
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: muse
|
||||
description: Design & UX agent. Makes JamBuddy come to life on screen — visual design, layout, interaction, the "smart fit to screen" for the Jam Guide, SVG renderers' look, accessibility. Dispatch for any task tagged `design` — visual layer, tokens, diagrams, responsive layout, or UX flow.
|
||||
tools: Read, Write, Edit, Grep, Glob, Bash
|
||||
---
|
||||
|
||||
You are **Muse**, the designer of the JamBuddy ensemble. You make musicians *want* to look at it, and able to read it at a glance mid-jam. One ledger task at a time, then hand to Critic.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md`; `docs/agents/LEDGER.md` — find your claimed task.
|
||||
- `tailwind.config.js` — the design tokens you must use: `bg-surface` (#0f0f0f), `bg-panel` (#1a1a1a), `border-border` (#2a2a2a), `text-accent`/`bg-accent` (#a855f7).
|
||||
- `docs/kb-plan.md` §4 — the Jam Guide layout intent (columns = chords, rows = plays, active-chord highlight, smart fit).
|
||||
- Existing visualisers `src/components/Fretboard.jsx`, `Piano.jsx` for the established note-colour tiers (chord tone > pentatonic > scale).
|
||||
|
||||
## You own (write)
|
||||
`tailwind.config.js` (tokens), presentational components and their styling, the visual design of SVG renderers (`ChordDiagram`, `MiniPiano`). Luthier owns structure/wiring — you deliver clean presentational components he integrates.
|
||||
|
||||
## Definition of done
|
||||
- Uses the design tokens; **never** raw hex outside `tailwind.config.js`.
|
||||
- Responsive: fits the target viewport; the Jam Guide reflows to one play-per-row on narrow windows; diagrams scale to column width.
|
||||
- Accessible: WCAG-AA contrast, keyboard-reachable controls, focus states.
|
||||
- Reads at a glance: the active chord is unmistakable; tiers use the established colour language.
|
||||
|
||||
## Protocol
|
||||
1. Claim your `ready` task; confirm file locks are clear.
|
||||
2. Design in real components (not mockups) where possible; keep them pure/presentational and prop-driven so Luthier can wire them.
|
||||
3. Self-check: `npm run build`; eyeball the rendered result at narrow and wide widths; check contrast and focus.
|
||||
4. Set `in-review` with a summary + the viewport sizes you checked. Critic gates it.
|
||||
|
||||
## Boundaries
|
||||
Never change app logic, audio, or KB content. Don't introduce a new colour without adding it as a token and flagging it to Maestro. Keep dependencies out — prefer SVG + Tailwind over chart/UI libraries. If a layout needs data the components don't yet receive, note the prop you need and let Maestro sequence Luthier.
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: professor
|
||||
description: Music & pedagogy agent. Researches and authors knowledgebase content (style cells, voicings, progressions), learning curricula, drills, and ear-training design, and guards music-theory correctness. Dispatch for any task tagged `content` — KB style packs, curriculum, drills, or theory accuracy.
|
||||
tools: Read, Write, Edit, Grep, Glob, Bash, WebSearch, WebFetch
|
||||
---
|
||||
|
||||
You are **Professor**, the music brain of the JamBuddy ensemble. You make the app musically correct and pedagogically real — intermediate-level, never step-one. You work one ledger task at a time and hand it to Critic.
|
||||
|
||||
## Read first (every dispatch)
|
||||
- `docs/agents/PROTOCOL.md` — the rules; `docs/agents/LEDGER.md` — find your claimed task.
|
||||
- `docs/kb-plan.md`, `src/data/kb/SCHEMA.md`, and the gold standard `src/data/kb/jazz/guitar.js`.
|
||||
- `docs/learn-curriculum.md`, `docs/progression-repertoire.md` — your reference corpus.
|
||||
|
||||
## You own (write)
|
||||
`src/data/kb/**` (content), `docs/learn-curriculum.md`, `docs/progression-repertoire.md`. You **co-own** `src/lib/theory.js` for music correctness only (Luthier owns its code shape) — and only with a task that locks it.
|
||||
|
||||
## Definition of done
|
||||
- **KB cells:** ≥4 progressions × ≥2 idiomatically-different plays; key-agnostic (degrees + movable shapes only); qualities are keys of `CHORD_TYPES`; `node scripts/validate-kb.mjs` green; named sources for every voicing/lick; intermediate hands (fret span ≤4, no advanced-only voicing without an easier alternative). For a full cell, the `/kb-expand` skill IS your protocol — follow it.
|
||||
- **Curriculum/drills:** sequenced for the confident-jammer level; each drill states what it trains and why; sourced.
|
||||
|
||||
## Protocol
|
||||
1. Claim your `ready` task (set `claimed`, confirm files don't overlap a locked task).
|
||||
2. Research with web search where the task needs verified data; require named sources.
|
||||
3. Author conforming to SCHEMA.md; register new styles in `src/data/kb/index.js`.
|
||||
4. Self-check: run the validator + `npm run build`; run the musician checklist in SCHEMA.md.
|
||||
5. Set the task `in-review` with a one-paragraph summary (what, sources, validator result). Critic gates it.
|
||||
|
||||
## Boundaries
|
||||
Never weaken the validator to pass content — fix the content or flag the conflict to Maestro. Never touch components, services, or styling (that's Luthier/Muse). Never invent songs, licks, or sources. Honour research that contradicts a common assumption — store the verified truth, flag the correction.
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: jam-loop
|
||||
description: Run one orchestrated ensemble iteration — Maestro appoints the right agent(s) for the next ready ledger task(s), the workers do the work, Critic gates it, Maestro reconciles and commits. The multi-domain generalisation of /kb-expand. Use to advance JamBuddy (app + learning platform); schedule it via /loop or /schedule for standing iterations.
|
||||
---
|
||||
|
||||
# Jam Loop — one orchestrated ensemble iteration
|
||||
|
||||
You are the **main loop acting as Maestro** (a leaf subagent can't spawn subagents, so the conductor lives here). You appoint the five worker agents — **professor, luthier, muse, critic, herald** — via the Agent tool, gate with Critic, and reconcile. Do **one iteration** per invocation.
|
||||
|
||||
References: `docs/agents/PROTOCOL.md` (the rules), `docs/agents/ROSTER.md` (domains + cadence weights), `docs/agents/LEDGER.md` (the board). Single-domain content work can still use `/kb-expand` directly.
|
||||
|
||||
## Optional argument
|
||||
`--only <agent>` runs just that domain's next ready task (e.g. `/jam-loop --only professor`). No argument = full balanced iteration.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. PLAN
|
||||
- Read `LEDGER.md` + `GOAL.md`. Promote `backlog → ready` for any task whose `depends-on` are `done`.
|
||||
- If no sprint branch is cut yet, do task M-01 first (cut the sprint branch, set the ledger header).
|
||||
- Pick the next batch by `priority × cadence-weight` (ROSTER). For a parallel batch, **enforce file-disjointness** — never select two tasks whose `files` overlap. Respect locks: skip any task overlapping a `claimed`/`in-review` task.
|
||||
|
||||
### 2. APPOINT & DISPATCH
|
||||
For each chosen task, dispatch the agent whose `domain` matches (`content`→professor, `engineering`→luthier, `design`→muse, `community`→herald, `quality`→critic). Give the agent: its task id, the DoD, its locked files, and "read your agent file + PROTOCOL.md + your ledger task first."
|
||||
- **Serial (default):** one task → one `Agent` call. A dependent chain → run in dependency order, feeding each result forward.
|
||||
- **Parallel (independent, file-disjoint):** multiple `Agent` calls in one message.
|
||||
- **Sprint mode (only if the user opted into Workflow/"ultracode"):** use the Workflow tool — `pipeline()` for dependent chains, `parallel()` for independent batches, with `isolation: 'worktree'` for any agents writing in parallel.
|
||||
Mark each dispatched task `claimed` in the ledger.
|
||||
|
||||
### 3. GATE (Critic — mandatory)
|
||||
When a worker sets its task `in-review`, dispatch **critic** to review it: Critic runs `npm run build`, `node scripts/validate-kb.mjs`, any smoke test, and applies domain judgment (PROTOCOL §4).
|
||||
- Pass → Critic sets `done`.
|
||||
- Fail → Critic sets `returned` with specific findings; the task goes back to `ready` for a future iteration (or re-dispatch the owner now if the fix is small and you have budget).
|
||||
|
||||
### 4. RECONCILE (you, as Maestro)
|
||||
- Commit each passing task as its own commit on the sprint branch (`<area>: <what> (task <id>)`), ending messages with the Co-Authored-By line.
|
||||
- Update `LEDGER.md` (statuses, any new follow-up tasks Critic surfaced) and `GOAL.md` if direction shifted.
|
||||
- Append one line to the ledger's iteration log: `<date> · done: <ids> · returned: <ids> · next: <id>`.
|
||||
|
||||
### 5. REPORT & CONTINUE
|
||||
- Tell the user: what each agent did, Critic's verdicts, what's committed, and the next ready task.
|
||||
- If looping (`/loop`/`/schedule`), this iteration ends here — the next fire runs the next iteration.
|
||||
- **At sprint end** (no ready tasks left in the sprint): open one PR to `main` summarising every task + validator/build status. `gh` is not installed — use the GitHub API with `git credential fill` (see PROTOCOL §6).
|
||||
|
||||
## Rules
|
||||
- One iteration per invocation. Don't start work outside the selected batch.
|
||||
- Never skip the Critic gate. Never merge a `returned` task.
|
||||
- Never select a file-overlapping parallel batch — that's the conflict guardrail.
|
||||
- Keep all state in files (ledger, commits, GOAL) — the next iteration has no memory of this one.
|
||||
- If a task spans two domains, don't dispatch it — split it into a handoff chain first (you're Maestro; fix the board).
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: kb-expand
|
||||
description: Expand the JamBuddy jam knowledgebase by exactly one style × instrument cell — research, author, validate, commit. Run repeatedly (or via /loop) to fill the backlog in docs/kb-backlog.md.
|
||||
---
|
||||
|
||||
# KB Expand — one cell per session
|
||||
|
||||
You are expanding JamBuddy's jam knowledgebase: intermediate-level standard progressions and ways to play them, per style × instrument. **Do exactly one cell, end to end.** Small, validated, committed.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Orient (always, every session)
|
||||
Read, in this order:
|
||||
- `docs/kb-plan.md` — architecture, schema conventions, quality gates, success criteria
|
||||
- `docs/kb-backlog.md` — the queue
|
||||
- `src/data/kb/SCHEMA.md` and the gold standard `src/data/kb/jazz/guitar.js` — **if they exist**
|
||||
- `docs/progression-repertoire.md` §1 — cross-check progressions for the style
|
||||
- `docs/learn-curriculum.md` — the intermediate level definition for the instrument
|
||||
|
||||
### 2. Claim a cell
|
||||
Take the **first `todo` cell** in the backlog (respect the order: bootstrap → guitar → piano → bass). Mark it `in-progress` in `docs/kb-backlog.md`.
|
||||
|
||||
**If the foundation doesn't exist yet (no `src/data/kb/`), this session is Session 0:** build `src/data/kb/` with `index.js` registry, `SCHEMA.md` (formats from kb-plan.md §1, one fully-worked example, the musician checklist from §2), `scripts/validate-kb.mjs` (all mechanical checks from kb-plan.md §2 — especially the pitch-class verification of guitar shapes against chord qualities from `src/lib/theory.js` CHORD_TYPES), and the **jazz/guitar** cell as the gold standard. That is one full session; stop after it.
|
||||
|
||||
### 3. Research
|
||||
Dispatch 1-2 web-research subagents for the claimed style × instrument:
|
||||
- the style's standard progressions (verify against `docs/progression-repertoire.md`; add style-specific ones with named sources)
|
||||
- 2-3 genuinely different intermediate ways to play each progression on this instrument (voicings with exact frets/fingerings for guitar, degree recipes for piano, line patterns for bass)
|
||||
- comping rhythm(s) characteristic of the style, improv guidance (scales over each chord, target notes, 1-2 licks)
|
||||
- require named sources/URLs in the agent's report
|
||||
|
||||
### 4. Author
|
||||
Write `src/data/kb/<style>/progressions.js` (if new style) and `src/data/kb/<style>/<instrument>.js` per SCHEMA.md. Key-agnostic only: degrees and movable shapes (`rootStr` + `offsets`), open shapes with `onlyRoot`. Qualities must be keys of `CHORD_TYPES` in `src/lib/theory.js`. Register the style in `src/data/kb/index.js`.
|
||||
|
||||
### 5. Validate — hard gate
|
||||
- `node scripts/validate-kb.mjs` must pass. Fix content, don't weaken the validator.
|
||||
- Run the musician checklist in SCHEMA.md; cut or fix anything that fails it.
|
||||
- `npm run build` must pass.
|
||||
|
||||
### 6. Record and commit
|
||||
- Backlog: mark the cell `done (YYYY-MM-DD, N progressions × M plays)`.
|
||||
- Commit on the current branch: `kb: add <style> <instrument> pack` (or `kb: bootstrap foundation + jazz guitar gold standard`). Do not push unless asked.
|
||||
|
||||
### 7. Report
|
||||
Tell the user: what was added (progressions, plays, sources), validator result, and **the next cell in the queue**. If a UI milestone in the backlog just became unblocked (e.g. Jam Guide MVP after cell 0), say so explicitly.
|
||||
|
||||
## Rules
|
||||
- One cell per invocation. Never start a second cell, even if the first went quickly.
|
||||
- Never commit content that fails the validator; never relax a validator rule to make content pass — flag the conflict to the user instead.
|
||||
- Intermediate level: no 5+ fret stretches, no advanced-only voicings without an intermediate alternative in the same play set.
|
||||
- Plays per progression must be idiomatically different (register/density/technique), not transpositions of each other.
|
||||
@@ -1,10 +0,0 @@
|
||||
# AI mode: "offline" uses local Ollama, "online" uses Claude API
|
||||
AI_MODE=offline
|
||||
|
||||
# Online mode - Anthropic Claude
|
||||
ANTHROPIC_API_KEY=your_key_here
|
||||
CLAUDE_MODEL=claude-sonnet-4-6
|
||||
|
||||
# Offline mode - Ollama (run: ollama pull llama3.2:3b)
|
||||
OLLAMA_HOST=http://localhost:11434
|
||||
OLLAMA_MODEL=llama3.2:3b
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: Propose or contribute a style
|
||||
about: Suggest a genre for the knowledgebase, or offer to author one
|
||||
title: "[Style] "
|
||||
labels: ["style", "content"]
|
||||
---
|
||||
|
||||
<!--
|
||||
Style packs are data, not code — see CONTRIBUTING.md ("Add a music style without
|
||||
deep coding") and src/data/kb/SCHEMA.md. You can propose a style for someone else
|
||||
to build, or claim it yourself.
|
||||
-->
|
||||
|
||||
## Which style / genre?
|
||||
|
||||
<!-- e.g. Neo-soul, Bluegrass, Afrobeat, Surf rock… -->
|
||||
|
||||
## Signature progressions (3–5)
|
||||
|
||||
For each, give the **Roman numerals** and an **example song** that uses it.
|
||||
|
||||
<!--
|
||||
Example:
|
||||
1. ii–V–I (e.g. "Misty")
|
||||
2. I–vi–ii–V (1950s turnaround, e.g. "Stand By Me")
|
||||
3. i7–IV7 Dorian vamp (e.g. "Chameleon")
|
||||
-->
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
## What makes it sound like itself?
|
||||
|
||||
<!-- One or two sentences: the feel, the voicings, the rhythmic signature, the
|
||||
"tell" that a listener recognizes. -->
|
||||
|
||||
## Will you author the voicings, or want help?
|
||||
|
||||
- [ ] I'll author the pack myself (guitar voicings / comping / improv) and open a PR
|
||||
- [ ] I can supply the progressions and theory, but want help turning them into the data files
|
||||
- [ ] I'm proposing the style for someone else to build
|
||||
|
||||
## Anything else?
|
||||
|
||||
<!-- Instrument focus (guitar/piano/bass), sources, reference recordings, etc. -->
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Something isn't working as expected
|
||||
title: "[Bug] "
|
||||
labels: ["bug"]
|
||||
---
|
||||
|
||||
## What happened?
|
||||
|
||||
<!-- A clear, short description of the bug. -->
|
||||
|
||||
## Steps to reproduce
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
## What you expected instead
|
||||
|
||||
|
||||
|
||||
## Environment
|
||||
|
||||
- OS:
|
||||
- How you ran it: <!-- npm run electron:dev / npm run dev (browser) / installed build -->
|
||||
- Instrument / input: <!-- e.g. electric guitar into audio interface, acoustic into laptop mic -->
|
||||
|
||||
## Screenshots, console output, or audio notes
|
||||
|
||||
<!-- If it's a detection issue, what were you playing (chords, key, tempo) and
|
||||
what did the app show? -->
|
||||
@@ -0,0 +1,8 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: The roadmap & vision (GOAL.md)
|
||||
url: https://github.com/whattheflat/whattheflat/blob/main/GOAL.md
|
||||
about: Where JamBuddy is headed — read this before proposing a big feature.
|
||||
- name: How to contribute a style (CONTRIBUTING.md)
|
||||
url: https://github.com/whattheflat/whattheflat/blob/main/CONTRIBUTING.md
|
||||
about: Add a genre to the knowledgebase without deep coding.
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea or improvement
|
||||
title: "[Feature] "
|
||||
labels: ["enhancement"]
|
||||
---
|
||||
|
||||
<!-- For proposing a new music *style*, use the "Propose or contribute a style"
|
||||
template instead. -->
|
||||
|
||||
## The problem / the jam moment
|
||||
|
||||
<!-- What are you trying to do, and where does the app fall short today? -->
|
||||
|
||||
## What you'd like to see
|
||||
|
||||
|
||||
|
||||
## How it fits the roadmap
|
||||
|
||||
<!-- Optional: does this relate to something in GOAL.md (detection, the Jam Guide,
|
||||
the Progression Builder, the Learn drills)? -->
|
||||
|
||||
## Alternatives or references
|
||||
|
||||
<!-- Other tools that do this well, or workarounds you've tried. -->
|
||||
@@ -0,0 +1,77 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false # Ensures one OS failing doesn't kill the others
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-latest
|
||||
command: npm run electron:build:win
|
||||
artifact_pattern: "release/*.exe"
|
||||
- os: macos-latest
|
||||
# Added --universal here if you want to support both Intel and Apple Silicon
|
||||
command: npm run electron:build:mac -- --universal
|
||||
artifact_pattern: "release/*.dmg"
|
||||
- os: ubuntu-latest
|
||||
command: npm run electron:build:linux
|
||||
artifact_pattern: "release/*.AppImage"
|
||||
|
||||
env:
|
||||
# This fixes the "GitHub Personal Access Token is not set" error
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Prevents errors related to missing code-signing certificates
|
||||
CSC_IDENTITY_AUTO_DISCOVERY: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build Application
|
||||
run: ${{ matrix.command }}
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: artifacts-${{ matrix.os }}
|
||||
path: ${{ matrix.artifact_pattern }}
|
||||
if-no-files-found: error
|
||||
|
||||
publish:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
# This downloads all "artifacts-*" into a folder named 'all-outputs'
|
||||
path: all-outputs
|
||||
merge-multiple: true
|
||||
|
||||
- name: List files for debugging
|
||||
run: ls -R all-outputs
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
# Point directly to the folder where all OS builds are merged
|
||||
files: all-outputs/*
|
||||
generate_release_notes: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,17 +1,15 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[oc]
|
||||
build/
|
||||
# Dependencies
|
||||
node_modules/
|
||||
frontend/node_modules/
|
||||
|
||||
# Build output
|
||||
dist/
|
||||
wheels/
|
||||
*.egg-info
|
||||
.venv/
|
||||
.python-version
|
||||
build/
|
||||
|
||||
# Env
|
||||
.env
|
||||
debug.log
|
||||
|
||||
# Frontend
|
||||
frontend/node_modules/
|
||||
frontend/dist/
|
||||
releases/
|
||||
release/
|
||||
.DS_Store
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
# Development (Vite dev server + Electron window with hot reload)
|
||||
npm run electron:dev
|
||||
|
||||
# Browser-only dev (no Electron)
|
||||
npm run dev
|
||||
|
||||
# Build installers
|
||||
npm run electron:build:win # Windows NSIS installer → releases/
|
||||
npm run electron:build:mac # macOS DMG → releases/
|
||||
npm run electron:build:linux # Linux AppImage → releases/
|
||||
```
|
||||
|
||||
No test suite exists. There is no lint script — no ESLint config is present.
|
||||
|
||||
## Architecture
|
||||
|
||||
**Electron shell** (`electron/main.cjs`) loads `dist/index.html` in production or `localhost:5173` in dev. The renderer process has full Web Audio API access (`sandbox: false`). `preload.cjs` uses `contextIsolation: true` with no exposed IPC — Electron is purely a window host; all logic lives in the renderer.
|
||||
|
||||
**Two audio pipelines run in parallel** inside `AudioCapture.jsx`:
|
||||
|
||||
| Path | FFT | Purpose |
|
||||
|---|---|---|
|
||||
| Pitch | 4096 samples (~90ms, `smoothingTimeConstant=0.0`) | McLeod pitch detection via `pitchy` → feeds key detection |
|
||||
| Chord | 16384 samples (~370ms, `smoothingTimeConstant=0.5`) | Harmonic summation chroma → feeds chord detection |
|
||||
|
||||
The 16384 FFT gives 2.7 Hz/bin resolution, which is necessary to separate adjacent semitones on low guitar strings (~5-6 Hz apart). The chord analyser uses `computeChroma()` — a harmonic summation that folds each FFT bin back through 5 harmonics to cancel overtone contamination (prevents minor chords from reading as major).
|
||||
|
||||
**State and detection logic lives entirely in `App.jsx`:**
|
||||
|
||||
- `handleNote` (pitch callback) → accumulates `noteHistoryRef`, runs Krumhansl-Schmuckler key detection every 5 notes, votes in `keyVotesRef` (rolling window, requires strong consensus before committing)
|
||||
- `handleChroma` (chord callback) → averages a ring buffer of `chromaSmooth` frames, runs a **chroma stability gate** (per-bin variance check — bails if still in transition), then matches against chord templates via `matchChordFromChroma`, votes in `chordVotesRef`
|
||||
- `handleOnset` (onset callback from RMS spike detection) → builds a **tempo histogram** from pairwise inter-onset intervals, folding all intervals into 55–220 BPM range; the histogram peak drives BPM display
|
||||
|
||||
Both `handleNote` and `handleChroma` use `useCallback(fn, [])` (empty deps). All values they need from render scope are kept in refs synced via `useEffect` — this prevents `AudioCapture`'s `start` from recreating on every render.
|
||||
|
||||
**All music theory is in `src/lib/theory.js`:**
|
||||
|
||||
- `detectKey` / `detectTopKeys` — Krumhansl-Schmuckler correlation against major/minor profiles only (K-S cannot distinguish modes — Dorian vs natural minor look the same; user manually picks mode)
|
||||
- `matchChordFromChroma` — weighted coverage score (inEnergy / (inEnergy + outEnergy×0.7)), requires root presence (`chroma[r] >= 0.08`), margin over second-best, diatonic/bass bonuses
|
||||
- `MATCH_CHORD_TYPES` — the subset of chord types used in real-time detection (not all of `CHORD_TYPES`)
|
||||
- `detectRepeatingProgression` — non-overlapping pattern match over last 20 chords, length 2–6
|
||||
|
||||
**`src/services/audioService.js`** is a self-contained tuner hook (`useAudioTuner`) used only by `Tuner.jsx`. It uses its own separate `AudioContext` with simple autocorrelation — independent from the main pitch/chord pipeline.
|
||||
|
||||
## Design tokens (Tailwind)
|
||||
|
||||
Defined in `tailwind.config.js`: `bg-surface` (#0f0f0f), `bg-panel` (#1a1a1a), `border-border` (#2a2a2a), `text-accent` / `bg-accent` (#a855f7 purple). Use these rather than raw hex in components.
|
||||
|
||||
## Key configuration (`DEFAULTS` in `App.jsx`)
|
||||
|
||||
| Key | Purpose |
|
||||
|---|---|
|
||||
| `chromaSmooth` | Ring buffer size (frames averaged before chord check) |
|
||||
| `chordVoteThreshold` | Consecutive matching chord frames required to commit |
|
||||
| `chordMinScore` | Minimum coverage score from `matchChordFromChroma` |
|
||||
| `keyVoteWindow` / `keyVoteThreshold` | Rolling window size and consensus count for key lock |
|
||||
| `noteHistorySize` | Max pitch-class history kept for K-S key detection |
|
||||
|
||||
These are exposed in `Settings.jsx` as sliders. `configRef` keeps a ref in sync so stable callbacks can read current values.
|
||||
|
||||
## Instrument views
|
||||
|
||||
`Fretboard.jsx` and `Piano.jsx` are SVG-rendered visualisers. Both accept `keyInfo`, `currentChord`, and `monoColor`. They call `getPentatonicScale`, `getFullScale`, `getChordTones` from `theory.js` and colour notes by tier: chord tone (purple `#a855f7`) > pentatonic (amber or light purple in mono) > scale (dark gray or lightest purple in mono).
|
||||
|
||||
## GitHub Actions
|
||||
|
||||
`.github/workflows/release.yml` builds Windows and macOS installers on tagged pushes (`v*`) using `softprops/action-gh-release@v2`. Build scripts use `--publish never` to prevent electron-builder's own publish step.
|
||||
@@ -0,0 +1,163 @@
|
||||
# Contributing to JamBuddy
|
||||
|
||||
JamBuddy is two things at once: a live **jam companion** that hears your key and chords and shows you how to play over them, and an open **learning platform** for the style knowledge behind those changes. The full vision is in [`GOAL.md`](GOAL.md).
|
||||
|
||||
The best part: **the style packs are data, not code.** If you're a gigging musician who knows how a style is voiced and played, you can teach JamBuddy a new genre by filling in a structured file — no audio or detection internals required. This guide is about that path.
|
||||
|
||||
---
|
||||
|
||||
## Quick start (setup)
|
||||
|
||||
You'll need [Node.js](https://nodejs.org/) (18+) and, for the live app, a microphone.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/whattheflat/whattheflat.git
|
||||
cd whattheflat
|
||||
npm install
|
||||
|
||||
# Desktop app — Vite dev server + Electron window, hot reload, mic access
|
||||
npm run electron:dev
|
||||
|
||||
# Or browser-only (no Electron shell) — then open http://localhost:5173
|
||||
npm run dev
|
||||
```
|
||||
|
||||
You do **not** need the app running to add a style — adding a style is editing data files and running one validator command. But it's nice to see your pack light up live once it's in.
|
||||
|
||||
---
|
||||
|
||||
## Add a music style without deep coding
|
||||
|
||||
This is the heart of contributing. A "style" is a genre pack: the standard progressions of that style, plus idiomatic ways to play each one. One pack renders in **all 12 keys** automatically, because everything is stored key-agnostically (scale degrees, not chord names).
|
||||
|
||||
The data contract you're filling is [`src/data/kb/SCHEMA.md`](src/data/kb/SCHEMA.md) — read it; it's the source of truth. The steps below are the workflow around it.
|
||||
|
||||
### Step 1 — Copy an existing pack as your template
|
||||
|
||||
A style lives in `src/data/kb/<style>/` and has (at least) three files:
|
||||
|
||||
```
|
||||
src/data/kb/<style>/
|
||||
meta.js — the style's identity (label, feel, tempo, one-line character)
|
||||
progressions.js — the style's standard progressions (instrument-independent)
|
||||
guitar.js — how to play them on guitar (voicings, comping, improv)
|
||||
```
|
||||
|
||||
The cleanest way to start is to **mirror a finished pack**. The gospel pack is a good, complete reference to copy and edit:
|
||||
|
||||
- [`src/data/kb/gospel/meta.js`](src/data/kb/gospel/meta.js)
|
||||
- [`src/data/kb/gospel/progressions.js`](src/data/kb/gospel/progressions.js)
|
||||
- [`src/data/kb/gospel/guitar.js`](src/data/kb/gospel/guitar.js)
|
||||
|
||||
(`SCHEMA.md` names the `jazz/` pack as its canonical exemplar — gospel mirrors the same shape and is a good second model. Pick whichever style is closest to yours.)
|
||||
|
||||
Make a new folder named after your style (e.g. `src/data/kb/neosoul/`), copy those three files in, and rewrite the content.
|
||||
|
||||
### Step 2 — Fill in the fields (in plain musician language)
|
||||
|
||||
**`meta.js`** — the style's identity. `id` (must equal the folder name), `label` (display name), `feel` (`swing` / `straight` / `shuffle` / `16th` / `bossa`…), `tempoRange` (`[low, high]` BPM), and a one-sentence `character` of what makes the style sound like itself.
|
||||
|
||||
**`progressions.js`** — your style's signature progressions, 4–8 of them. Each one is written **key-agnostically** using these fields:
|
||||
|
||||
- `degrees` — the chord roots as **semitone offsets from the key root, 0–11**. So in any major key: I = `0`, ii = `2`, IV = `5`, V = `7`, vi = `9`. A ii–V–I is `[2, 7, 0]`. You write the *intervals*, JamBuddy fills in the actual chords once it knows the key.
|
||||
- `qualities` — the chord **quality** for each degree, e.g. `min7`, `dom7`, `maj7`, `maj`, `add9`, `sus4`, `dim7`. These must be one of the names JamBuddy knows: `maj`, `min`, `dom7`, `maj7`, `min7`, `dim`, `dim7`, `half_dim`, `aug`, `sus4`, `sus2`, `maj6`, `min6`, `add9`. (That list lives in `CHORD_TYPES` in `src/lib/theory.js`.)
|
||||
- `rn` — the Roman numerals you'd *write on a chart* (`['ii7', 'V7', 'Imaj7']`) — purely for display.
|
||||
- `bars` — how many bars each chord lasts.
|
||||
- `mode` — `major`, `minor`, `dorian`, `phrygian`, `lydian`, or `mixolydian`.
|
||||
- `songs` — real songs that use the progression. **Be honest here** (see the PR checklist).
|
||||
- `tip` — one transferable idea a player can take away.
|
||||
- `id` — a globally unique slug, prefixed with your style name (`neosoul-251`, `neosoul-vamp`…).
|
||||
|
||||
`degrees`, `qualities`, `rn`, and `bars` must all be the **same length** (one entry per chord in the loop).
|
||||
|
||||
**`guitar.js`** — the ways to play each progression. The key fields:
|
||||
|
||||
- `styleIntro` — 2–3 sentences on the guitar's role in this style.
|
||||
- `comping` — at least one named rhythm with a description.
|
||||
- `plays` — for each progression id, **at least two genuinely different ways to play it** (different register, density, or technique — not the same voicing moved up the neck).
|
||||
- `improv` — scales to solo over each chord, target notes, optional licks.
|
||||
|
||||
Each chord in a play carries a guitar **shape**, written in one of two formats:
|
||||
|
||||
- **Movable shape** (the common case) — fret offsets *relative to the root fret*, so the same grip works in every key:
|
||||
```js
|
||||
shape: {
|
||||
rootStr: 6, // which string carries the root (6 = low E)
|
||||
offsets: [0, 'x', 0, 1, 'x', 'x'], // always 6 entries, low-E string first; 'x' = muted
|
||||
fingers: [1, 0, 2, 3, 0, 0],
|
||||
}
|
||||
```
|
||||
- **Open shape** (open-string chords that only work in certain keys) — uses absolute `frets` plus `onlyRoot` (the pitch class, 0–11, the shape is built for) instead of `offsets`.
|
||||
|
||||
If a voicing **deliberately leaves a note out**, declare it so the data stays honest and the UI can show it:
|
||||
|
||||
- `extensions: ['9']` — colour tones you've added beyond the basic chord (the validator only allows notes you've declared).
|
||||
- `rootless: true` — the shape omits the root (e.g. guide-tone grips where the bass covers the root).
|
||||
- `omit3: true` — the shape omits the 3rd (e.g. power chords that work over major or minor).
|
||||
|
||||
### Step 3 — Register the style
|
||||
|
||||
Open [`src/data/kb/index.js`](src/data/kb/index.js) and add your pack the same way the others are wired: import its `meta`, `progressions`, and `guitar`, then add an entry to the exported registry. Mirror an existing block exactly — the UI reads only this registry.
|
||||
|
||||
### Step 4 — Run the validator until it's green
|
||||
|
||||
```bash
|
||||
node scripts/validate-kb.mjs
|
||||
```
|
||||
|
||||
A passing run looks like:
|
||||
|
||||
```
|
||||
✓ KB valid — 9 style(s), 45 progressions, 90 plays
|
||||
```
|
||||
|
||||
If it fails, it prints a specific line for each problem (which file, which chord, what's wrong). Fix the data and run again. **Never weaken the validator to make content pass** — if you think a rule is wrong, open an issue instead.
|
||||
|
||||
#### Why the validator exists (this is the important part)
|
||||
|
||||
The validator is the quality bar that lets us trust voicings we didn't author ourselves. For **every guitar shape**, it computes the **actual pitch classes** the grip would sound (from the string tuning, the root string, and your offsets) and checks two things:
|
||||
|
||||
1. **Every note you sound actually belongs to the chord** — the chord's own tones plus any `extensions` you declared. A misspelled grip (a wrong fret, a stray open string) sounds a note that isn't in the chord, and the validator rejects it.
|
||||
2. **The chord's defining tones are present** — unless you've honestly declared them omitted via `rootless` / `omit3`.
|
||||
|
||||
In plain terms: you can't accidentally ship an "Amaj7" that's secretly an A7, and you can't claim a voicing has a note it doesn't. That mechanical check is what makes a contributed pack trustworthy without a maintainer re-fingering every chord by hand.
|
||||
|
||||
---
|
||||
|
||||
## The assisted path: `/kb-expand`
|
||||
|
||||
If you're working with [Claude Code](https://claude.com/claude-code), the `/kb-expand` skill is an assisted authoring route. It does exactly **one style × instrument cell end to end** — researches the style's standard progressions and idiomatic voicings (with sources), drafts the files per `SCHEMA.md`, registers the style, and **self-validates** by running `node scripts/validate-kb.mjs` until green before stopping. It's the fastest way to go from "I know this genre" to a scaffolded, validated pack you can refine. You still own the musical judgment — check its voicings and attributions.
|
||||
|
||||
---
|
||||
|
||||
## Pull request checklist
|
||||
|
||||
Before you open a PR, confirm:
|
||||
|
||||
- [ ] **Validator green** — `node scripts/validate-kb.mjs` prints `✓ KB valid …`.
|
||||
- [ ] **Build green** — `npm run build` succeeds (your new file imports cleanly).
|
||||
- [ ] **Honest attributions** — every song listed actually uses the progression. Do **not** claim a specific recording uses an exact voicing unless you genuinely know it does; "standard in the tradition" or a hedged reference is better than a fabricated one. Licks and sources are real.
|
||||
- [ ] **Plays genuinely differ** — the 2+ ways to play each progression contrast in register, density, or technique (not transpositions of one another).
|
||||
- [ ] **One style per PR** — keeps review focused and easy to merge.
|
||||
|
||||
That's it. Open the PR, and a maintainer (the Critic in our [ensemble](docs/agents/ROSTER.md)) will run the same checks before merging.
|
||||
|
||||
---
|
||||
|
||||
## Reporting bugs and proposing styles
|
||||
|
||||
You don't have to write any code to help:
|
||||
|
||||
- **Propose or contribute a style** → use the [Propose / contribute a style](.github/ISSUE_TEMPLATE/add-style.md) issue template. Tell us the genre, its signature progressions, and whether you'll author the voicings or want help.
|
||||
- **Found a bug?** → [Bug report](.github/ISSUE_TEMPLATE/bug_report.md).
|
||||
- **Have an idea?** → [Feature request](.github/ISSUE_TEMPLATE/feature_request.md).
|
||||
|
||||
---
|
||||
|
||||
## Scope and ground rules
|
||||
|
||||
- Adding/editing **style data** under `src/data/kb/` and using the issue templates needs no special permission — that's exactly the contribution path this guide is for.
|
||||
- Changes to **app code, the audio pipeline, the schema, or the validator** are bigger — open an issue to discuss first so it fits the roadmap in [`GOAL.md`](GOAL.md).
|
||||
- **License:** the project doesn't have a license file yet, so reuse terms aren't settled. If that matters for your contribution, raise it in an issue before investing heavily.
|
||||
|
||||
Thanks for helping musicians hear, play, and *learn* the jam.
|
||||
@@ -0,0 +1,120 @@
|
||||
# GOAL — From Detection to Direction
|
||||
|
||||
WhatTheFlat already solves the hard live problem: **knowing what key and chords people are playing in a jam, in real time.** This document defines the next level, in two parts:
|
||||
|
||||
1. **Chord progressions** — make it easier to work with *different* progressions: a bigger genre repertoire, clearer "1-5-4"-style readout of the detected loop, a builder where you place chords yourself, and alternative voicings for every chord in a progression.
|
||||
2. **Learn** — expand the education section for the player who already knows the basics and is confident enough to jam, but wants to go next level.
|
||||
|
||||
Supporting research and full repertoires live in:
|
||||
|
||||
- [`docs/progression-repertoire.md`](docs/progression-repertoire.md) — genre-by-genre progression tables, substitution rules, voicing data sources, UX patterns from existing tools
|
||||
- [`docs/learn-curriculum.md`](docs/learn-curriculum.md) — intermediate training methods for guitar, piano, and bass, with drills and how app features map onto them
|
||||
- [`docs/kb-plan.md`](docs/kb-plan.md) — the **jam knowledgebase**: styles × instruments × progressions × voicings, the `/kb-expand` session loop that grows it ([`docs/kb-backlog.md`](docs/kb-backlog.md)), and the **Jam Guide** panel that renders it live at the bottom of the app
|
||||
|
||||
---
|
||||
|
||||
## Part 1 — Chord progressions
|
||||
|
||||
### Where we are
|
||||
|
||||
- `PROGRESSIONS` in `src/lib/theory.js` holds **14 hardcoded progressions across 7 genres** (Pop, Blues, Folk, Jazz, Rock, '50s, Flamenco). These drive `ProgressionSuggestions.jsx`.
|
||||
- `detectRepeatingProgression()` finds the repeating loop in chord history; `ProgressionBanner.jsx` already shows it with Roman numerals (I–V–IV) via `toRomanNumeral()`.
|
||||
- `EducationPanel.jsx` + `src/lib/education.js` carry 15 famous progressions with substitutions and style variations.
|
||||
- `src/lib/voicings.js` has ~50 guitar shapes (open + barre) across 14 chord types; no inversions, no triad string-sets, thin piano coverage.
|
||||
- There is **no way to enter or arrange a progression manually** — everything is detection-driven.
|
||||
|
||||
### Goals
|
||||
|
||||
**G1 — Expanded genre repertoire (data, not code).**
|
||||
Grow `PROGRESSIONS` from 7 to ~12 genres using the researched tables in `docs/progression-repertoire.md`: Funk (Dorian i7–IV7 vamps), Reggae (two-chord skanks), Country (V/V secondary dominant moves), R&B/Neo-soul (iii–vi–ii–V, 6-2-5-1), Gospel (chained 2-5-1s), plus blues variants (quick-change, minor blues) and the J-pop "Royal Road" (IV–V–iii–vi). Progressions stay in the existing `{ name, rn, degrees }` format so suggestions, Roman numerals and key mapping keep working unchanged.
|
||||
|
||||
**G2 — Numeral clarity ("is this 1-5-4?").**
|
||||
The loop banner already shows Roman numerals; add a **Nashville-number display option** (1-5-4 instead of I-V-IV) since that is how musicians call changes at a jam. One formatting layer over `toRomanNumeral`, toggled in Settings.
|
||||
|
||||
**G3 — Progression Builder (drag and drop).**
|
||||
A panel where the user assembles a progression by hand:
|
||||
- A **key-relative chord palette** (Hookpad's best idea): the diatonic chords of the current detected/locked key, one tap to add, with borrowed-chord palette (iv, ♭VII, ♭VI, V/V…) one level deeper.
|
||||
- Slots that can be **reordered by drag and drop**, with live Roman/Nashville numerals under each chord.
|
||||
- Tap any slot → **alternative voicings** for that chord (G4).
|
||||
- Seeded from the detected loop ("send loop to builder") so a jam can be captured, edited, and varied.
|
||||
- Variation buttons per chord powered by the substitution taxonomy (diatonic swap, borrow, secondary dominant, 7th/sus/add9 color) — the rules are in `docs/progression-repertoire.md` §2.
|
||||
|
||||
**G4 — Alternative voicings per progression chord.**
|
||||
- **Guitar:** extend `voicings.js` with CAGED positions and triads on string-sets (top-3 / middle-3), or adopt the MIT-licensed [`tombatossals/chords-db`](https://github.com/tombatossals/chords-db) dataset (multiple positions per chord, JSON, with a companion React SVG renderer).
|
||||
- **Piano:** generate voicings from interval recipes rather than data files — root position, inversions, shells (1-3-7), rootless A (3-5-7-9) / B (7-9-3-5) — choosing the inversion that minimizes movement from the previous chord (voice-leading distance).
|
||||
- Surface these in the Builder (G3) and in `CurrentJamPanel` voicing strips.
|
||||
|
||||
---
|
||||
|
||||
## Part 2 — Learn: basics → jam-ready next level
|
||||
|
||||
### Audience
|
||||
|
||||
Not step one. The target player already knows open/barre chords (guitar), triads and simple lead sheets (piano), roots and simple scales (bass) — and is confident enough to show up at a jam. The Learn section's job is to take them **from "can survive a jam" to "makes the jam better."**
|
||||
|
||||
### What the research says (full detail in `docs/learn-curriculum.md`)
|
||||
|
||||
Across guitar, piano, and bass pedagogy (Berklee methods, Justin Guitar grades 4–6, Tomo Fujita, Mark Levine, Open Studio, PianoGroove, Scott's Bass Lessons, TalkingBass, Ed Friedland), the intermediate-to-advanced jump converges on four pillars:
|
||||
|
||||
| Pillar | Guitar | Piano | Bass |
|
||||
|---|---|---|---|
|
||||
| **Fretboard/keyboard liberation** | CAGED, triads on string sets, connecting pentatonic boxes | Inversions in all keys, voice leading | Neck zones, chord-tone arpeggios everywhere |
|
||||
| **Playing the changes** | Chord-tone targeting, guide tones (3rds & 7ths) | Shell + rootless voicings, sus/add9 colors | Walking lines, chromatic approach notes |
|
||||
| **Ensemble skills** | Small voicings, register discipline, comping | Comping rhythms (Charleston…), "rule of 1", staying out of the bass lane | Pocket/drummer lock, ghost notes, subdivision switching |
|
||||
| **Functional ears** | Hearing I-IV-V / vi-IV-I-V by bass line | Nashville numbers, 12-key transposition | Singing root movement, predicting the V |
|
||||
|
||||
### Goals
|
||||
|
||||
**L1 — Practice drills tab.**
|
||||
Add a drills library to the Learn section: per instrument, per pillar, the concrete drills from the curriculum doc (e.g. "first note after every chord change = the 3rd", "Charleston comping ladder", "W|H|H chromatic walkup"). Keyed to the *current detected key and loop* so every drill is in today's jam context, not abstract C major.
|
||||
|
||||
**L2 — Detection-powered feedback (the unfair advantage).**
|
||||
No practice app can hear the player; this one can. Phased:
|
||||
- **Target-note highlighting:** on each detected chord change, highlight the new chord's 3rd/7th on the fretboard/piano for a beat (drill scaffold — uses existing tier rendering).
|
||||
- **Next-chord preview tier:** when a loop is detected, show the *upcoming* chord's root and its chromatic approach notes (the bassist's walking-line scaffold).
|
||||
- **Chord-tone hit rate:** classify detected notes against the current chord (chord tone / scale tone / outside) and show a session score.
|
||||
- **Pocket report:** extend the onset/BPM pipeline to show timing drift against the established grid.
|
||||
|
||||
**L3 — Ear training from your own jam.**
|
||||
A quiz mode that hides the chord banner and asks the user to name the progression in numbers before revealing — using the *user's own chord history* as the corpus. Converts the existing detection + `toRomanNumeral` into the functional ear training every method prescribes.
|
||||
|
||||
**L4 — Mode-difference teaching.**
|
||||
When the user manually switches mode (the documented K-S limitation — by design), briefly highlight the *difference notes* (e.g. the raised 6th going minor → Dorian) on the instrument views. Turns a limitation into a lesson.
|
||||
|
||||
---
|
||||
|
||||
## What we need to go next level — priorities
|
||||
|
||||
| # | Item | Effort | Why first |
|
||||
|---|---|---|---|
|
||||
| 1 | **G1** Genre repertoire expansion | S (data only) | Immediate value, zero architectural risk |
|
||||
| 2 | **G2** Nashville number toggle | S | Directly answers "is it 1-5-4", jam-native language |
|
||||
| 3 | **G3** Progression Builder MVP (palette + reorder + numerals) | M | The single most-requested workflow gap |
|
||||
| 4 | **L1** Drills tab seeded from curriculum doc | M (content + UI) | Makes Learn level-appropriate |
|
||||
| 5 | **G4** Voicing alternatives (guitar string-sets + piano recipes) | M | Feeds both Builder and Learn |
|
||||
| 6 | **L2** Target-note highlighting + next-chord preview | M | First detection-powered trainer, reuses tier rendering |
|
||||
| 7 | **L3** Ear-training quiz on own history | M | High pedagogical value, small surface |
|
||||
| 8 | **L2** Hit-rate scoring + pocket report | L | Needs tuning of pitch/onset classification |
|
||||
| 9 | **G3** Builder phase 2: borrowed palette, variation buttons, loop import | L | Builds on MVP + substitution rules |
|
||||
| 10 | **KB** Knowledgebase + Jam Guide panel (see `docs/kb-plan.md`) | L, but looped in S-sized sessions via `/kb-expand` | The style × instrument playbook that powers improv learning |
|
||||
|
||||
### How we execute
|
||||
|
||||
Knowledgebase work runs as **looped sessions**: `/kb-expand` does exactly one style × instrument cell (research → author → validate → commit), driven by the queue in `docs/kb-backlog.md`. Tranches run on a dedicated branch — e.g. an hourly `/loop /kb-expand` for a working day — and **end with a pull request** so a whole tranche is reviewed in one place. First tranche (started 2026-06-12, branch `kb-expansion`): Session 0 bootstrap + the first guitar style cells, hourly for 8 hours, PR to `main` at the end.
|
||||
|
||||
## How we build it — the ensemble
|
||||
|
||||
The work is carried by a six-agent team that collaborates through files (a shared ledger + the repo), conducted by one scheduled loop. Full design in [`docs/agents/`](docs/agents/):
|
||||
|
||||
- [`ROSTER.md`](docs/agents/ROSTER.md) — the six agents, their domains, file ownership, and cadence weights: 🎼 Maestro (orchestrator), 🎓 Professor (music & pedagogy), 🔧 Luthier (engineering), 🎨 Muse (design & UX), 🔍 Critic (the review gate), 📣 Herald (open-source & community).
|
||||
- [`PROTOCOL.md`](docs/agents/PROTOCOL.md) — how they collaborate: the task-locking rule that prevents file conflicts, the `backlog→ready→claimed→in-review→done` lifecycle, the appointment algorithm, scheduling (schedule the conductor, not the band), and PRs.
|
||||
- [`LEDGER.md`](docs/agents/LEDGER.md) — the live task board, seeded with the `sprint-jam-guide` starter sprint.
|
||||
|
||||
**Run it:** `/jam-loop` advances one orchestrated iteration (Maestro appoints → workers build → Critic gates → reconcile + commit). Schedule it with `/loop 1h /jam-loop` (session) or `/schedule` (durable). `/kb-expand` remains the single-domain content fast-path (Professor solo).
|
||||
|
||||
### Definition of "next level" (success criteria)
|
||||
|
||||
- A jammer can glance at the app and call the loop in numbers ("it's a 1-5-4").
|
||||
- Suggestions cover the genres people actually jam (funk/reggae/R&B/gospel included), not just pop/blues.
|
||||
- A user can lay out their own progression, drag chords around, and see 3+ ways to voice every chord on their instrument.
|
||||
- The Learn section gives an intermediate guitarist, pianist, or bassist a *specific* next drill in the key they're jamming in right now — and at least one drill where the app verifies them by listening.
|
||||
@@ -1,48 +1,122 @@
|
||||
# WhatTheFlat
|
||||
# JamBuddy
|
||||
|
||||
Real-time key and chord detection for musicians. Play guitar, bass, piano, or any instrument into your microphone and WhatTheFlat will identify the key you're in, the chords you're playing, and suggest progressions.
|
||||
**Hear the jam, learn the jam.** JamBuddy listens through your microphone, figures out the key and chords you're playing in real time, then shows you *how to play over them* — and helps you level up while you do it.
|
||||
|
||||
## Features
|
||||
It started as a live key/chord detector (you may know it as *WhatTheFlat*). It's growing into an open, contributable **learning platform** for the player who can already survive a jam and wants to make it better.
|
||||
|
||||
- Real-time chord detection from live audio
|
||||
- Automatic key detection (Krumhansl-Schmuckler profiles)
|
||||
- Chord history and repeating progression detection
|
||||
- Roman numeral analysis relative to detected key
|
||||
- Fretboard visualiser showing safe notes and chord tones
|
||||
- Beginner / Advanced modes
|
||||
- Manual key lock for jam sessions
|
||||
- AI chat assistant for music theory questions
|
||||
---
|
||||
|
||||
## Tech Stack
|
||||
## The idea: detect → guide → level up
|
||||
|
||||
- **Frontend**: React 18, Vite, Tailwind CSS
|
||||
- **Audio**: Web Audio API, [Pitchy](https://github.com/ianprime0509/pitchy) (McLeod pitch detection)
|
||||
- **Backend**: Python (Claude API for chat assistant)
|
||||
1. **Detect.** Point your mic at a guitar, piano, or a whole band. JamBuddy identifies the **key** and the **chords** as you play, finds the repeating **loop**, and reads it back in Roman numerals (ii–V–I, I–V–vi–IV).
|
||||
|
||||
## Getting Started
|
||||
2. **Guide.** Once it knows your loop, the **Roadmap Jam Guide** lays it out as an improv highway synced to what you're playing: **guide tones** (the 3rds and 7ths that carry the harmony), **voice-leading rails** showing how each chord resolves into the next, the **solo scale** to blow over each station, and the **chord voicings** to grab — all in your detected key, with a playhead tracking where the loop is.
|
||||
|
||||
### Frontend
|
||||
3. **Level up.** Style packs turn the same ii–V–I into *jazz* vs *bossa* vs *funk* — genuinely different voicings, rhythms, and improv advice — so you don't just play the changes, you learn the language. This is the on-ramp to the wider **Learn** direction (drills and detection-powered feedback) described in [`GOAL.md`](GOAL.md).
|
||||
|
||||
---
|
||||
|
||||
## What works today vs. what's in progress
|
||||
|
||||
This is an honest snapshot — it's an active project.
|
||||
|
||||
**Working today**
|
||||
|
||||
- **Real-time key detection** with top-3 candidate chips (click to lock) — works for guitar and piano.
|
||||
- **Real-time chord detection** from live audio, with chord history and repeating-progression detection.
|
||||
- **Roadmap Jam Guide** panel: matches your detected loop to a style progression and renders guide tones, voice-leading rails, solo-scale labels, and chord-voicing thumbnails synced to the loop position.
|
||||
- **8 guitar style packs** in the knowledgebase — jazz, blues, rock, bossa nova, funk, reggae, country, and R&B (gospel landing next).
|
||||
- **Fretboard and piano** visualisers that colour chord tones, pentatonic, and scale notes.
|
||||
- **Chromatic tuner** and a **loop station** for capturing and replaying phrases.
|
||||
- **Fully offline** — all audio and detection run locally in the desktop window; no server, no network calls.
|
||||
|
||||
**In progress**
|
||||
|
||||
- **Piano and bass** style packs (guitar is the first instrument rolled out).
|
||||
- The **Progression Builder** — lay out and rearrange your own progression by hand (GOAL §G3).
|
||||
- **Detection-powered drills** — practice exercises and feedback that use the fact that the app can actually *hear* you (GOAL Part 2).
|
||||
|
||||
---
|
||||
|
||||
## What it looks like
|
||||
|
||||
<!-- TODO: add a screenshot or GIF of the Roadmap Jam Guide tracking a live ii–V–I or 12-bar blues. -->
|
||||
<!-- Caption: "The Roadmap Jam Guide mid-jam — guide tones, voice-leading rails, and the next voicing, synced to the chord you're playing right now." -->
|
||||
|
||||
_(Screenshot coming — the Roadmap panel mid-jam.)_
|
||||
|
||||
---
|
||||
|
||||
## Quickstart
|
||||
|
||||
You'll need [Node.js](https://nodejs.org/) (18+) and a microphone.
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
git clone https://github.com/whattheflat/whattheflat.git
|
||||
cd whattheflat
|
||||
npm install
|
||||
npm run dev
|
||||
|
||||
# Desktop app (Vite dev server + Electron window, hot reload)
|
||||
npm run electron:dev
|
||||
```
|
||||
|
||||
Open `http://localhost:5173` in your browser and click **Start Listening**. Allow microphone access when prompted.
|
||||
|
||||
### Backend (chat assistant)
|
||||
Prefer the browser? Run the renderer on its own (no Electron shell):
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
python main.py
|
||||
npm run dev # then open http://localhost:5173
|
||||
```
|
||||
|
||||
## How It Works
|
||||
**To see the magic:** grant **microphone permission** when prompted, then play a **recognized loop** — a **ii–V–I** or a **12-bar blues** are the easiest ways to light up the Roadmap Jam Guide. JamBuddy needs to hear the loop repeat a couple of times to lock the key and match the progression.
|
||||
|
||||
Audio is processed in two parallel paths:
|
||||
### Building installers
|
||||
|
||||
1. **Pitch path** — small 4096-sample FFT with McLeod autocorrelation for fast, accurate single-note pitch detection. Feeds the key detection algorithm.
|
||||
2. **Chord path** — large 16384-sample FFT (2.7 Hz/bin resolution) with harmonic summation chroma extraction. The chroma vector is matched against chord templates (major, minor, dominant 7th, sus4, diminished) to identify the current chord.
|
||||
```bash
|
||||
npm run electron:build:win # Windows NSIS installer → release/
|
||||
npm run electron:build:mac # macOS DMG → release/
|
||||
npm run electron:build:linux # Linux AppImage → release/
|
||||
```
|
||||
|
||||
Key detection uses a rolling vote over the last 12 detections and requires 9/12 agreement before committing, keeping the display stable during transitions.
|
||||
---
|
||||
|
||||
## Contributing — add a style without deep coding
|
||||
|
||||
The style packs are **data, not code**. If you're a musician who knows how a style is voiced and played, you can add one by filling in a structured data file — no audio or detection internals required.
|
||||
|
||||
- The data contract lives in [`src/data/kb/SCHEMA.md`](src/data/kb/SCHEMA.md): progressions as key-agnostic scale degrees, plus 2+ idiomatic "ways to play" each (voicings, comping, improv). One entry renders in all 12 keys.
|
||||
- An **assisted path** is available: the `/kb-expand` workflow researches, drafts, and validates one style cell at a time, so you can start from a scaffold rather than a blank file.
|
||||
- Every contribution passes a **validator quality gate** (`node scripts/validate-kb.mjs`) that mechanically checks each voicing actually contains the chord's tones — that's the bar that keeps the knowledgebase trustworthy.
|
||||
|
||||
A full step-by-step **`CONTRIBUTING.md`** guide is **coming** (tracked as task H-02). Until then, `SCHEMA.md` is the source of truth, and the [jazz pack](src/data/kb/jazz) is the gold-standard example to imitate.
|
||||
|
||||
---
|
||||
|
||||
## How it's built — the ensemble
|
||||
|
||||
JamBuddy is built by a six-agent team (Maestro, Professor, Luthier, Muse, Critic, Herald) that collaborates entirely through files — a shared ledger and the repo — conducted by one scheduled loop. If you want to understand how the project plans and ships work, start in [`docs/agents/`](docs/agents/):
|
||||
|
||||
- [`ROSTER.md`](docs/agents/ROSTER.md) — the six agents and their domains.
|
||||
- [`PROTOCOL.md`](docs/agents/PROTOCOL.md) — how they collaborate (task locking, review gate, scheduling).
|
||||
- [`LEDGER.md`](docs/agents/LEDGER.md) — the live task board.
|
||||
|
||||
The product north star and full roadmap are in [`GOAL.md`](GOAL.md).
|
||||
|
||||
---
|
||||
|
||||
## Tech & how detection works
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **App shell** | Electron (window host only — all logic runs in the renderer) |
|
||||
| **UI** | React, Tailwind CSS, Vite |
|
||||
| **Audio** | Web Audio API, [Pitchy](https://github.com/ianprime0509/pitchy) (McLeod pitch detection) |
|
||||
| **Music theory** | Custom JS — Krumhansl-Schmuckler key detection, harmonic-summation chroma chord matching |
|
||||
|
||||
Two audio pipelines run in parallel: a fast **pitch path** (4096-sample FFT, McLeod autocorrelation) feeds Krumhansl-Schmuckler key detection over a voting window; a higher-resolution **chord path** (16384-sample FFT, ~2.7 Hz/bin) extracts a harmonic-summation chroma and matches it against chord templates. Architecture details are in [`CLAUDE.md`](CLAUDE.md).
|
||||
|
||||
> Note on modes: Krumhansl-Schmuckler distinguishes major vs. minor but not modes — Dorian and natural minor look the same to it. JamBuddy detects the tonal centre, and you pick the mode (the dropdown offers Dorian, Mixolydian, etc.). By design.
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
No license file is set yet. Until one is added, all rights are reserved by the authors — please open an issue before reusing the code.
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
from typing import Literal
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
||||
|
||||
ai_mode: Literal["online", "offline"] = "offline"
|
||||
|
||||
# Online (Claude) settings
|
||||
anthropic_api_key: str = ""
|
||||
claude_model: str = "claude-sonnet-4-6"
|
||||
|
||||
# Offline (Ollama) settings
|
||||
ollama_host: str = "http://localhost:11434"
|
||||
ollama_model: str = "llama3.2:3b"
|
||||
|
||||
cors_origins: list[str] = ["http://localhost:5173", "http://localhost:3000"]
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -1,32 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from api.services.ai import chat
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
role: str
|
||||
content: str
|
||||
|
||||
|
||||
class ChatRequest(BaseModel):
|
||||
messages: list[Message]
|
||||
context: dict | None = None
|
||||
|
||||
|
||||
class ChatResponse(BaseModel):
|
||||
reply: str
|
||||
|
||||
|
||||
@router.post("/chat", response_model=ChatResponse)
|
||||
async def chat_endpoint(request: ChatRequest):
|
||||
try:
|
||||
reply = await chat(
|
||||
messages=[m.model_dump() for m in request.messages],
|
||||
context=request.context,
|
||||
)
|
||||
return ChatResponse(reply=reply)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -1,50 +0,0 @@
|
||||
from api.config import settings
|
||||
|
||||
|
||||
SYSTEM_PROMPT = """You are a friendly, beginner-aware music theory assistant for WhatTheFlat — a live jam helper app.
|
||||
You help musicians understand what's happening harmonically during a jam session.
|
||||
Keep answers short, warm, and jargon-free. If you use a music term, briefly explain it.
|
||||
Never say someone played a "wrong" note — always frame it as "try these instead".
|
||||
When given context about the current key and chord, use it in your response."""
|
||||
|
||||
|
||||
async def chat(messages: list[dict], context: dict | None = None) -> str:
|
||||
system = SYSTEM_PROMPT
|
||||
if context:
|
||||
parts = []
|
||||
if context.get("key"):
|
||||
parts.append(f"Current key: {context['key']}")
|
||||
if context.get("chord"):
|
||||
parts.append(f"Current chord: {context['chord']}")
|
||||
if parts:
|
||||
system += "\n\nLive session context:\n" + "\n".join(parts)
|
||||
|
||||
if settings.ai_mode == "online":
|
||||
return await _chat_claude(messages, system)
|
||||
else:
|
||||
return await _chat_ollama(messages, system)
|
||||
|
||||
|
||||
async def _chat_claude(messages: list[dict], system: str) -> str:
|
||||
import anthropic
|
||||
|
||||
client = anthropic.AsyncAnthropic(api_key=settings.anthropic_api_key)
|
||||
response = await client.messages.create(
|
||||
model=settings.claude_model,
|
||||
max_tokens=512,
|
||||
system=system,
|
||||
messages=messages,
|
||||
)
|
||||
return response.content[0].text
|
||||
|
||||
|
||||
async def _chat_ollama(messages: list[dict], system: str) -> str:
|
||||
import ollama
|
||||
|
||||
client = ollama.AsyncClient(host=settings.ollama_host)
|
||||
full_messages = [{"role": "system", "content": system}] + messages
|
||||
response = await client.chat(
|
||||
model=settings.ollama_model,
|
||||
messages=full_messages,
|
||||
)
|
||||
return response.message.content
|
||||
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 1.5 MiB |
|
After Width: | Height: | Size: 1.5 MiB |
@@ -0,0 +1,76 @@
|
||||
# Ensemble Ledger — Live Task Board
|
||||
|
||||
The shared queue all agents read and write. Lifecycle and rules: [`PROTOCOL.md`](PROTOCOL.md). Roster + cadence weights: [`ROSTER.md`](ROSTER.md).
|
||||
|
||||
**Status:** `backlog` → `ready` → `claimed` → `in-review` → `done` / `returned`
|
||||
**Lock:** a task's `files` column is its lock — no two `claimed`/`in-review` tasks may overlap files.
|
||||
|
||||
---
|
||||
|
||||
## Active sprint: `sprint-jam-guide` (branch: `sprint-jam-guide`)
|
||||
|
||||
Emphasis this sprint: **ship the Jam Guide MVP** (put the 8 guitar style packs on screen, synced to live detection) + **reframe the repo as a learning platform**. Weights this sprint: Luthier 3, Muse 3 (design-heavy), Professor 2, Herald 2, Critic gate.
|
||||
|
||||
**Design-first gate (user directive 2026-06-14):** Muse explored three distinct concepts; **user chose "Roadmap"** (improv-first highway) on 2026-06-15. Implementation tasks below are re-planned to build Roadmap. Concept doc: `docs/design/jam-guide-concept-c.md`. Stage/Playbook (`-a`/`-b`) kept as reference for future modes.
|
||||
|
||||
**Roadmap build shape:** a horizontal timeline panel — stations (= loop chords) carry guide-tone lanes (3rd/7th), a solo-scale label, and voice-leading rails (7→3) between stations; a playhead + beat grid track loop position; the chosen voicing is a secondary thumbnail per station; tap a station → guide tones on the fretboard. Needs derived theory (`guideTones`, `voiceLeadingPairs`, default `soloScale`) — Luthier owns those.
|
||||
|
||||
| id | title | domain | status | depends-on | files (lock) | definition of done |
|
||||
|----|-------|--------|--------|-----------|--------------|--------------------|
|
||||
| M-01 | Cut `sprint-jam-guide` branch; seed sprint | maestro | done | — | (branch) | branch cut, ledger header set |
|
||||
| D-00a | Viz concept A — "Stage" | design | done | — | `docs/design/jam-guide-concept-a.md` | delivered; reference for future collapsed/glance mode |
|
||||
| D-00b | Viz concept B — "Playbook" | design | done | — | `docs/design/jam-guide-concept-b.md` | delivered; reference for future study mode |
|
||||
| D-00c | Viz concept C — "Roadmap" | design | done | — | `docs/design/jam-guide-concept-c.md` | delivered; **CHOSEN** |
|
||||
| D-SEL | User selects a concept | maestro | done | D-00a, D-00b, D-00c | `docs/agents/LEDGER.md` | **Roadmap chosen 2026-06-15**; tasks re-planned below |
|
||||
| L-01 | Shared matcher: extract/author `findLoopPosition` (which chord index the loop is on) + rotation-invariant degree-relative loop→progression-id matcher into `src/lib/match.js`; refactor `ProgressionBanner.jsx` to use it | engineering | done | M-01 | `src/lib/match.js`, `src/components/ProgressionBanner.jsx` | matcher maps detected loop → style progression id (rotation-invariant) AND returns current position index for the playhead; banner still works; build green — VERIFY: `npm run build` green; banner renders identically (findLoopPosition now imported from match.js); matchLoopToProgression rotation-invariant + quality tie-break (smoke: ii–V–I & its rotation → jazz-251-major rot 0/2; minor 251 → jazz-251-minor; chromatic → no match) |
|
||||
| L-01b | Derived theory for Roadmap: add `guideTones(chordRoot,quality)` (3rd & 7th pcs), `voiceLeadingPairs(chordA,chordB)` (7→3 / nearest-tone rails), and default `soloScale(quality,mode)` (Mixo/dom7, Dorian/m7, Ionian/maj7…) to `theory.js` — additive exports only | engineering | done | M-01 | `src/lib/theory.js` | pure functions, unit-sane (ii–V–I in C → C→B, F→E rails); reuses existing `getChordTones`; build green; no existing export changed |
|
||||
| L-02 | `JamGuide.jsx` panel shell: mounts last in `App.jsx`, reads `kb/index.js`, instrument+style tabs from registry, collapsed header → ~70vh; receives live loop + position props | engineering | done | L-01 | `src/components/JamGuide.jsx`, `src/App.jsx` | panel renders, tabs from KB, matched progression or fallback; build green |
|
||||
| D-01 | `RoadmapTrack.jsx` — the heart: horizontal stations (loop chords) with guide-tone lanes (3rd/7th dots), solo-scale label, voice-leading rails between stations, playhead + beat grid, lookahead highlight on the next station | design | done | L-01, L-01b | `src/components/RoadmapTrack.jsx` | renders a real ii–V–I & a 12-bar blues from KB; lanes computed from `guideTones`/`voiceLeadingPairs`/`soloScale`; design tokens; AA contrast |
|
||||
| D-01b | `ChordDiagram.jsx` — secondary per-station voicing thumbnail (movable `rootStr`+`offsets`, open `frets`+`onlyRoot`), key-aware fret placement, tap-to-enlarge | design | done | L-01 | `src/components/ChordDiagram.jsx` | renders any KB guitar shape in any key; chord-tone colour tier; compact thumbnail + enlarged states |
|
||||
| D-02 | Roadmap assembly & live polish in `JamGuide.jsx`: place `RoadmapTrack` + thumbnails, animate playhead against BPM/onset, narrow-viewport reflow, tap-station → fretboard guide tones | design | done | L-02, D-01, D-01b | `src/components/JamGuide.jsx` (assembly/styling), `tailwind.config.js` | playhead tracks position; reflows on narrow; keyboard-reachable; AA contrast |
|
||||
| D-03 | Finish the flagship: tap a Roadmap station → highlight that chord's guide tones (3rd/7th) on the **main Fretboard**. Lift a `jamFocusChord` state into `App.jsx`, `JamGuide` emits the selected station's `{rootPc, quality}` via a callback prop, `Fretboard` highlights those guide tones reusing its existing tier rendering. **Returned by Critic** → also fix root cause `guideTones` so 4-tone non-seventh chords (add9/maj6/min6) don't badge their 5th/6th as a "7" | engineering | done | D-02 | `src/App.jsx`, `src/components/JamGuide.jsx`, `src/components/Fretboard.jsx`, `src/lib/theory.js` | tapping a station lights its 3rd/7th (honest secondary anchor for non-7th chords); build green; smoke green; **audio-callback contract intact**; RoadmapTrack lane also corrected; keyboard-reachable; clears on deselect |
|
||||
| P-01 | Gospel guitar KB cell | content | done | — | `src/data/kb/gospel/**`, `src/data/kb/index.js` | 5 progressions × 2 plays, validator green (run `/kb-expand`) |
|
||||
| P-02 | Pop guitar KB cell | content | done | P-01 | `src/data/kb/pop/**`, `src/data/kb/index.js` | 5 progressions × 2 plays, validator green |
|
||||
| H-01 | README reframe: lead with the learning-platform vision (detect → guide → learn), screenshot/gif placeholder, link `GOAL.md` + `docs/agents/` | community | done | — | `README.md` | README states the dual vision; links resolve |
|
||||
| H-02 | `CONTRIBUTING.md` + issue templates: the data-contract path so a musician can PR a style without coding (point at `src/data/kb/SCHEMA.md`) | community | done | H-01 | `CONTRIBUTING.md`, `.github/ISSUE_TEMPLATE/**` | a non-coder can follow "add a style"; `/kb-expand` documented as the assisted path |
|
||||
| C-01 | Smoke-test harness: a `scripts/smoke.mjs` that imports `kb/index.js` + runs the matcher on sample loops, wired alongside `validate-kb.mjs` | quality | done | L-01 | `scripts/smoke.mjs` | catches a broken matcher/registry before merge; documented in PROTOCOL gate |
|
||||
|
||||
> Critic (C-) reviews every L-/D-/P-/H- task as it reaches `in-review` — those reviews are the gate, not separate ledger rows, except where new test infra is itself the deliverable (e.g. C-01).
|
||||
|
||||
> GATE 2026-06-15 (Critic) · **L-01 PASS** — build green, validator green (8 styles/40 progs/80 plays). `findLoopPosition` extracted byte-identical (verified by diff, no semantic change). matchLoopToProgression verified rotation-invariant with quality tie-break: `[Dm7,G7,Cmaj7]`→`jazz-251-major` rot 0; rotation `[G7,Cmaj7,Dm7]`→ rot 2; `[Dm7b5,G7,Cm7]`→`jazz-251-minor` (tie-break works); chromatic→clean `{matched:false}`. rotation index correctly points at the loop slot aligning with KB degrees[0]. `match.js` holds only matching/position logic + a small local chord-root parser (theory.js exposes no pc helper — acceptable). Note (non-blocking): banner refactor also adds `onChordClick` click affordances — beyond a pure extract but already wired to `setSelectedChord`/ChordDetailModal in App.jsx and behaviour-preserving for `findLoopPosition`. Minor: `match.js` uses extensionless `import … from './theory'` (works under Vite; matches existing `education.js` convention).
|
||||
> GATE 2026-06-15 (Critic) · **L-01b PASS** — build green. theory.js diff is purely additive (zero `-` lines; no existing export touched). Verified by running the real functions: ii–V–I in C → **Dm7→G7 = C→B (−1)** and **G7→Cmaj7 = F→E (−1)** rails (plus intentional 0-semitone common-tone rails). `guideTones` triad fallback flags `hasSeventh:false` and uses the 5th. `soloScale` defaults sane: dom7→mixolydian, min7→dorian, maj7→major(ionian), half_dim→locrian, dom7/minor→phrygian-dominant. Functions are pure and reuse CHORD_TYPES/SCALES.
|
||||
> GATE 2026-06-15 (Critic) · **L-02 PASS** — build green; validator green (8 styles/40 progs/80 plays). 🚨 **Audio contract INTACT**: `git diff HEAD -- src/App.jsx` is +10 lines, zero deletions — only the `import JamGuide` line and the `<JamGuide …/>` mount (placed last, after the tuner block). `handleNote`/`handleChroma`/`handleOnset` lines do not appear anywhere in the diff; no `useCallback` dep, ref-sync `useEffect`, or `AudioCapture` prop was touched. Black-screen/infinite-restart risk avoided. All 5 props passed (`detectedProgression`, `effectiveKey`, `chordHistory`, `bpm`, `currentChord`) exist in App scope. Tabs derive from the KB registry (instrument availability from `style.instruments` keys, style labels from `meta.label`); matched-progression vs. dashed-fallback both render. Disabled instrument tabs marked "soon" with `disabled` + title.
|
||||
> GATE 2026-06-15 (Critic) · **D-01 PASS** — RoadmapTrack renders from props only (pure/presentational). Verified against the real KB: guide-tone honesty confirmed by running `guideTones` — C-major **triad** returns `hasSeventh:false`, secondary anchor = the 5th (pc 7), and the Station labels it **"5th"** not "7th" (`seventhKind` gate at line 113). The headline rail picks `voiceLeadingPairs(...)[0]` = the 7→3: Dm7→G7 ⇒ C→B (−1), G7→Cmaj7 ⇒ F→E (−1). BeatGrid station-start indexing is canonical-order-consistent with the stations array; playhead `pct` clamps at 0 when `position=-1`. Tokens used; `aria-current`, `role=progressbar` + `aria-valuetext`, focus rings present. Malformed/empty progression → graceful "no loop to map" card, no crash.
|
||||
> GATE 2026-06-15 (Critic) · **D-01b PASS** — ChordDiagram movable base-fret formula verified independently: **E-shape A7 → fret 5** ✓ (rootStr 6, rootPc 9: `((9−4)%12)=5`); A-shape C → fret 3 ✓; open-string root → octave barre (12), a sane degradation. Root-tone coloured in accent tier (`isRoot` → `#a855f7`), non-root dots light-gray (AA on dark board). Both `thumb`/`full` sizes; `full` adds finger numbers + label. Undefined/unplaceable shape (root > fret 15 or `!shape`) → graceful "—" placeholder, no crash — covers the empty-thumbnail path. Open vs movable forms both handled.
|
||||
> GATE 2026-06-15 (Critic) · **P-01 PASS** — validator green: `✓ KB valid — 9 style(s), 45 progressions, 90 plays` (gospel now included); `npm run build` green (gospel imported by `kb/index.js`, 87 modules, built in 5.65s). Schema: 5 progressions × 2 plays = 10 plays, all ids `gospel-`-prefixed, rn/qualities/bars all length-consistent with degrees, qualities all in CHORD_TYPES (min7/dom7/maj7/maj/add9/sus4/dim7). No duplicate id across all 45. Registered in `index.js` mirroring the other 8 styles (no broken import). **Voicings hand-verified** (independent pc computation matching the validator's): SHELL_6.maj7 → {0,11,4}=R-7-3 ✓; SUS4_5 → {0,5,7}=R-4-5 ✓; DIM7_5 → {0,6,9,3}=R-♭5-𝄫7-♭3 symmetric ✓; ADD9_6 → {0,2,4,7} full add9 (9th present) ✓; MIN9_5 → {0,2,3,7,10} full min9 ✓ — confirms the validator genuinely exercises these shapes via `checkGuitarShape`. **Theory** sound: backdoor ♭VII7=pc10 rises a whole step to I; #iv°7=pc6 passing chord; 6-2-5-1 + plagal IV-I Amen tag; cascading cycle-of-dominants all correctly spelled. **Authenticity** honest: attributions hedged appropriately ("traditional gospel turnaround", "reharmonized", "Every Praise … vamp feel", "e.g. Tenderly bars 5-7" as a back-door reference) — no claim that a specific recording uses an exact voicing; no music-theory error in any tip (Dorian-over-min7, Mixo-over-dom7, sus-non-resolution advice all correct). *Non-blocking nit*: a few shape comments list tones in interval order, not low-to-high string order (e.g. MAJ9_6 "R–3–7–9" sounds R-9-3-7) — labeling nicety, all tones present and correctly spelled; not a defect.
|
||||
> GATE 2026-06-15 (Critic) · **H-01 PASS** — every relative link resolves on disk: `GOAL.md`, `CLAUDE.md`, `src/data/kb/SCHEMA.md`, `src/data/kb/jazz/` (dir), `docs/agents/` + ROSTER/PROTOCOL/LEDGER all exist; `CONTRIBUTING.md` is correctly referenced as **"coming (tracked as task H-02)"** and does NOT exist on disk — honest, not a dead live-link. Every command real: `electron:dev`, `dev`, `electron:build:win|mac|linux` all in `package.json`; `scripts/validate-kb.mjs` exists. **No `frontend/` path remains**; build output dir stated as `release/` matches electron-builder `directories.output: "release"`. git clone URL `whattheflat/whattheflat.git` matches actual `origin`. **Honesty verified**: gospel described as "landing next" (not shipped, still in-review at review time); Piano/bass packs, Progression Builder, detection-powered drills all under **In progress**, not today; Roadmap Jam Guide listed as working-today (true — D-02 passed, MVP live). Leads with detect → guide → level up; links GOAL.md + docs/agents/. No overstatement found.
|
||||
> GATE 2026-06-15 (Critic) · **P-02 PASS** — gated against the FINAL combined tree (P-02/H-02/C-01 merged). `node scripts/validate-kb.mjs` → `✓ KB valid — 10 style(s), 50 progressions, 100 plays` (pop registered in `index.js`; the transient "pop not registered" mid-batch failure is resolved — `index.js` imports popMeta/popProgressions/popGuitar and exports the `pop` block). Schema: 5 progressions × 2 plays = 10, all ids `pop-`-prefixed, no duplicate across all 50 (verified). **Voicings hand-computed** (independent pc calc): OPEN_CADD9 → {0,2,4,7} = R-9-3-5, the 9th (pc2) genuinely present (true add9, not plain C) ✓; OPEN_G/OPEN_F → {0,4,7} major ✓; BARRE_MAJ_6 (E-shape) {0,4,7}, BARRE_MIN_5 (Am-shape) {0,3,7}, BARRE_MAJ_5 (A-shape) {0,4,7} ✓ — confirms validator exercises the shapes. **Non-duplication judged ACCEPTABLE**: pop-axis (0-7-9-5 maj) shares shape with rock-axis/reggae-nwnc and pop-mixo-bVII (0-10-5 mixo) with rock-mixo-vamp, but ids differ, songs differ (No Woman No Cry/Adele/Beatles vs rock), and guitar plays are capo-and-open framed vs rock's barre framing — a real genre reuse with distinct content, not a duplication smell; differentiation rationale documented in the progressions.js header. **Honesty CONFIRMED**: every sus2/sus4 mention is prose (note/tips/styleIntro) framed as a hammer-on/pull-off fill over a held chord ("the chord stays major, your finger wiggles"); zero sus in the data — all pop-mixo chords are voiced plain `maj`; tips never claim a voicing the data lacks. Song attributions hedged (Clocks "♭VII colour", Royals "verse", Memories "Pachelbel, set in B").
|
||||
> GATE 2026-06-15 (Critic) · **H-02 PASS** — every relative link resolves on disk: GOAL.md, README.md, src/data/kb/SCHEMA.md, gospel/{meta,progressions,guitar}.js, index.js, src/lib/theory.js, scripts/validate-kb.mjs, docs/agents/ROSTER.md, and all three issue templates (add-style/bug_report/feature_request) + config.yml — verified via on-disk existence check. Every command real (npm install / electron:dev / dev / build / node scripts/validate-kb.mjs all in package.json). **Schema fidelity exact**: the quality list `maj,min,dom7,maj7,min7,dim,dim7,half_dim,aug,sus4,sus2,maj6,min6,add9` matches `CHORD_TYPES` keys byte-for-byte; modes list matches the validator's MODES; degrees-0-11, movable(rootStr/offsets) vs open(frets/onlyRoot), and extensions/rootless/omit3 explanations all match SCHEMA.md + validator logic — no invented field, no drift. LICENSE correctly NOT added (CONTRIBUTING honestly states "doesn't have a license file yet … reuse terms aren't settled"). Issue templates present and sane. *Non-blocking nit*: CONTRIBUTING's illustrative validator-output sample reads `9 style(s)/45/90` (true at authoring time, pre-pop) — it's a "what a passing run looks like" example, not a load-bearing claim; the instructions don't depend on the count. Worth a one-char refresh to 10/50/100 someday, not a return.
|
||||
> GATE 2026-06-15 (Critic) · **C-01 PASS** — `node scripts/smoke.mjs` → `✓ Smoke test passed — 71/71 checks green (10 styles, 50 progressions)`, exit 0; reports the FULL final KB (10 styles, derived from the loaded registry, not hardcoded). Imports the REAL `kb/index.js` + `match.js` (no mocks); asserts registry integrity (every style meta/progressions[]/instruments.guitar, per-prog degrees/qualities/rn/bars consistency, cross-KB id uniqueness) and matcher correctness (ii–V–I matched:true + structural rebased-degree-shape check, rotation invariance to the SAME derived id with non-zero rotation, axis match guarded with skip-if-absent, chromatic → matched:false/id:null, findLoopPosition in-range/-1/-1-on-empty). Exits non-zero on failure (mirrors validate-kb). **Adversarial proof**: sabotaged `matchLoopToProgression` to always return no-match → smoke FAILED 4 checks, **exit code 1** (assertions are NOT too weak — a broken matcher cannot pass). match.js restored, no diff. **Resolve hook judged SOUND**: the inline `module.register` ESM hook retries ONLY on `catch`, ONLY for relative+extensionless specifiers (`/^\.{1,2}\//` && `!/\.[mc]?js$/`) — verified the regex skips `./theory.js`, `react`, `node:url`, `./a.mjs` and retries only `./theory`/`../lib/match`; it cannot mask a genuine missing module (the `.js` retry itself surfaces the real ERR_MODULE_NOT_FOUND). Correctly chosen over editing match.js (locked to L-01). **No npm script added** (validate-kb has none) — `package.json` untouched (git: only `src/data/kb/index.js` is modified; smoke.mjs/pop/CONTRIBUTING/templates are new untracked). No hardcoded fragile ids — expected ids derived from the loaded KB; survives KB growth.
|
||||
> GATE 2026-06-15 (Critic) · **D-03 FAIL (returned)** — build green (vite, 90 modules, 10.66s); validator green (`✓ KB valid — 10 style(s), 50 progressions, 100 plays`, no KB change). 🚨 **Audio contract INTACT**: `git diff -- src/App.jsx` is purely additive — exactly (a) one new `useState(jamFocusChord/null)` placed in the UI-state block (outside all audio-callback/ref logic, with a comment that it is not read by any callback), (b) `jamFocusChord={jamFocusChord}` on the existing `<Fretboard>` mount, (c) `onFocusChord={setJamFocusChord}` on the existing `<JamGuide>` mount. Grep of the **changed lines** for `handleNote|handleChroma|handleOnset|useCallback|AudioCapture|Ref|useEffect` → **NO MATCHES**. No callback, ref, ref-sync useEffect, or AudioCapture prop touched. Black-screen/infinite-restart risk avoided. **Wiring correct**: JamGuide emits `{rootPc, quality:qualities[i]}` (station's actual KB quality) on select, `null` on deselect; the existing `selectedStation→null` reset effect (loop/style/instrument change) flows through the new cross-link effect and clears the highlight; an unmount-cleanup effect also clears; all guarded `onFocusChord?.` so JamGuide stays standalone. Fretboard **null path verified unchanged** (`hasFocus=false` ⇒ `tag` always null ⇒ `if(!color&&!tag)` collapses to original `if(!color)`; no halo/badge/legend). Emphasis is visually distinct (purple ring `DOT_R+3` + degree badge, accent token `#a855f7`). Triad labeling **correct** for maj/min/dim/aug/sus4/sus2 (all `hasSeventh:false` → badge/legend read "5"). **DEFECT (blocking)**: `guideTones`' secondary-anchor heuristic is `hasSeventh = ints.length >= 4`, so the **4-tone non-seventh** KB qualities `add9` `[0,2,4,7]`, `maj6`/`min6` `[0,4,7,9]` return `hasSeventh:true` with `seventh = ints[last]` = the **5th** (add9) or **6th** (maj6/min6). D-03's `focusLabel` trusts that boolean and badges those tones **"7"**, legend reads **"3 / 7"** — a perfect fifth / sixth rendered to the user as a seventh on the flagship Fretboard. **Reachable**: `add9` is in gospel progression qualities (×4), `min6` in bossa + rnb qualities — tapping those stations mislabels a non-7th. Verified by running `guideTones(0,'add9')→{third:4,seventh:7,hasSeventh:true}` (G badged "7"), `guideTones(0,'min6')→{third:3,seventh:9,hasSeventh:true}` (A badged "7"). The DoD's "the chord's guide tones (3rd/7th)" / "badge reads 5 not 7 for a triad" contract is violated for these KB-present qualities. **Fix direction (return to Luthier):** make the secondary anchor honest for extended non-7th chords — either tighten `guideTones` so a chord with no minor/major 7th reports `hasSeventh:false` and falls back to the 5th (root cause, L-01b owns theory.js), or have `focusLabel`/the badge derive the actual interval of `seventh` above root (10/11 ⇒ "7", 9 ⇒ "6", 7 ⇒ "5", 2 ⇒ "9") rather than trusting the boolean. Re-gate after fix.
|
||||
> GATE 2026-06-15 (Critic) · **D-03 PASS (re-gate)** — the returned defect is fixed at the root cause and hardened. `npm run build` green (vite, 90 modules, built in 3.25s); `node scripts/smoke.mjs` → `✓ Smoke test passed — 71/71 checks green (10 styles, 50 progressions)`, exit 0; `node scripts/validate-kb.mjs` → `✓ KB valid — 10 style(s), 50 progressions, 100 plays` (no KB change). **Root-cause fix VERIFIED by running the real `guideTones`**: `hasSeventh` now keys on the actual presence of interval 10 or 11 (`ints.find(i=>i===10||i===11)`), not `length>=4`. Independent truth table (root C): add9→{third:2,seventh:7,**hasSeventh:false**,anchor=5th G}; maj6→{4,7,false,5th}; min6→{3,7,false,5th}; dom7→{4,10,true,7=A♯}; maj7→{4,11,true,7=B}; min7→{3,10,true,7=A♯}; triads maj/min/sus4/sus2→false,anchor 5th(7); dim→anchor ♭5(6); aug→anchor #5(8); dim7→♭5(6); half_dim→true,10. Return shape `{third, seventh, root, hasSeventh}` **unchanged** (keys verified). **Badge hardening (Fretboard) VERIFIED**: `focusSeventhLabel` derives the label from the *actual* interval of the anchor pc above the chord root (10/11→"7", 9→"6", 8→"♭6", 7→"5", 6→"♭5"), so a wrong boolean can't mislabel — adversarial sweep of all 14 KB qualities × keys {3,7,11}: a "7" badge appears iff the interval is truly 10/11; **NO MISLABEL**. Unknown quality → `maj` fallback, no crash. **Null-focus path byte-equivalent**: `jamFocusChord=null` ⇒ `hasFocus=false` ⇒ `tag` always null ⇒ `if(!color&&!tag)` collapses to the original `if(!color) return null`; no halo/badge/legend; `focusSeventhLabel` is dead-but-harmless. **No collateral**: `voiceLeadingPairs`/`soloScale` signatures untouched (theory.js diff hits only `guideTones` body+jsdoc); ii–V–I rails still correct (Dm7→G7 C→B [0→11,−1]; G7→Cmaj7 F→E [5→4,−1]) and `voiceLeadingPairs` does NOT crash for the now-5th-anchored add9/maj6/min6 (Cadd9→G7, Cmaj6→F, Amin6→Dm7 all return smooth rails). match.js/RoadmapTrack/ChordDiagram/KB untouched (`git diff --name-only` = only the 4 declared D-03 files). 🚨 **Audio contract INTACT**: `git diff -- src/App.jsx` purely additive (one `useState(jamFocusChord/null)` outside the callback/ref block + an additive `jamFocusChord=` prop on `<Fretboard>` + `onFocusChord=setJamFocusChord` on `<JamGuide>`); grep of changed lines for `handleNote|handleChroma|handleOnset|useCallback|AudioCapture|Ref|configRef|useEffect` → NO MATCHES; the sole "−" line is the Fretboard mount being re-emitted with the added prop. *Non-blocking observation (pre-existing, out of D-03 scope):* `guideTones` uses `ints[1]` for the 3rd, so `add9` `[0,2,4,7]` reports its **9th (pc 2)** as `third`, not the major 3rd (pc 4) — true at L-01b time, unchanged by this fix, and D-03's bug was strictly the seventh/secondary anchor; worth a future tidy, not a return.
|
||||
> GATE 2026-06-15 (Critic) · **D-02 PASS** — the load-bearing integration is correct. **Independent rotation check**: `canonicalPos = ((position − rotation) % n + n) % n` translates a `findLoopPosition` index (which is into the *detected loop*) into the KB-canonical station RoadmapTrack/stationVoicings render. Worked a rotated [ii V I VI] of KB [I VI ii V] (rotation=2, n=4): playhead@detected-idx1(V)→canonical 3(V), @2(I)→0(I), @3(VI)→1(VI), @0(ii)→2(ii) — NOW lands on the chord actually playing. ✓ **rootPc parity** confirmed: thumbnail `rootPc` and RoadmapTrack station root are byte-identical `(((keyRoot+deg)%12)+12)%12`, and `keyInfo.root` (a note *name*, e.g. `detectKey`→"F#") is converted once via `chordRootPC` → pc, guarded `>=0`. stationVoicings `chords[i]` aligns 1:1 with `degrees[i]` (canonical). Auto-scroll is prop-driven off `position` (no rAF on the audio thread). Reflows (`flex-wrap`/`sm:flex-nowrap`), keyboard-reachable, AA contrast. NO_MATCH path → dashed fallback, never empty/crash. *Non-blocking deferral*: the DoD's "tap-station → **fretboard** guide tones" cross-link and `tailwind.config.js` edit were not delivered — the implementation cross-links via an inline enlarged ChordDiagram instead (flagged in-code as deferred). Panel is fully functional without it; recommend Maestro file the fretboard cross-link as a phase-2 follow-up.
|
||||
|
||||
---
|
||||
|
||||
## Backlog (future sprints)
|
||||
|
||||
- **Jam Guide phase 2:** `MiniPiano.jsx` + piano recipe resolver (unblocks piano packs); bass pattern renderer.
|
||||
- **Content:** piano packs (jazz → gospel → neo-soul first), then bass packs (blues → jazz → funk first) — see `docs/kb-backlog.md`.
|
||||
- **`guideTones` third bug (L-12, Luthier — small):** `guideTones` takes `ints[1]` as the "third", so `add9` `[0,2,4,7]` reports its **9th (pc 2)** as the 3rd instead of the major 3rd (pc 4) — wrong "3rd" lane/badge for add9 (live in gospel + pop-axis Cadd9). Pre-existing since L-01b; flagged by Critic during the D-03 re-gate. Fix: pick the actual 3rd/4th interval (3 or 4, or sus 2/5) rather than positional `ints[1]`. Smoke + a guideTones truth-table check.
|
||||
- **Learning features (Professor + Luthier):** drills tab seeded from `docs/learn-curriculum.md`; target-note highlighting; ear-training quiz on own chord history; pocket report from the onset pipeline.
|
||||
- **Progression Builder (GOAL G3):** key-relative palette, drag-reorder, Nashville-number toggle, voicing alternatives.
|
||||
- **Platform (Herald):** GitHub Pages docs site; "you're playing the Creep progression" engagement hook; contributor leaderboard for styles added.
|
||||
|
||||
---
|
||||
|
||||
## Iteration log
|
||||
|
||||
_(Maestro appends one line per completed iteration: `<date> · <task ids done> · <next>`.)_
|
||||
|
||||
- 2026-06-14 · done: M-01 · in-review (awaiting user pick): D-00a/b/c viz concepts · next: D-SEL (user chooses) → then L-01/D-01/D-02 implement chosen concept
|
||||
- 2026-06-15 · done: D-00a/b/c, D-SEL (Roadmap chosen), L-01 (match.js + banner refactor), L-01b (guideTones/voiceLeadingPairs/soloScale) — Critic PASS both · next: L-02 (JamGuide shell) → D-01 (RoadmapTrack) ‖ D-01b (ChordDiagram)
|
||||
- 2026-06-15 · done: L-02 (JamGuide shell + App mount), D-01 (RoadmapTrack), D-01b (ChordDiagram), D-02 (assembly + playhead rotation + thumbnails) — Critic PASS all 4, audio contract intact (App.jsx +10/−0) · **Roadmap Jam Guide MVP is live & builds green** · next: D-03 (fretboard cross-link, backlog) ‖ P-01 (gospel content) ‖ H-01 (README reframe)
|
||||
- 2026-06-15 · done: P-01 (gospel guitar pack — 5 progs × 2 plays, validator 9 styles/45/90), H-01 (README reframed as learning platform, stale frontend/ paths fixed) — Critic PASS both · next ready: P-02 (pop pack) ‖ H-02 (CONTRIBUTING) ‖ C-01 (smoke harness) ‖ D-03 (fretboard cross-link)
|
||||
- 2026-06-15 · done: P-02 (pop guitar pack — KB now 10 styles/50/100), H-02 (CONTRIBUTING.md + issue templates), C-01 (scripts/smoke.mjs — 71/71, adversarially proven to catch a broken matcher) — Critic PASS all 3 · **SPRINT `sprint-jam-guide` COMPLETE** → opening PR to main · remaining (next sprint): D-03 fretboard cross-link, piano/bass packs, drills
|
||||
- 2026-06-15 · done: D-03 (tap station → guide tones on the main Fretboard; root-cause fix to `guideTones` hasSeventh + badge hardening) — Critic **returned once** (add9/maj6/min6 mislabeled 5th/6th as "7"), fixed, **PASS on re-gate** · audio contract intact · folded into PR #2 (completes the flagship) · filed L-12 (guideTones third bug) to backlog · next: seed piano phase-2 sprint (resolver + MiniPiano + wire)
|
||||
@@ -0,0 +1,123 @@
|
||||
# Ensemble Protocol — How the Agents Collaborate
|
||||
|
||||
The operating system for the [six-agent ensemble](ROSTER.md). Agents are isolated subagents — they share **no memory**, only **files**: the live ledger ([`LEDGER.md`](LEDGER.md)) and the repo. Everything below makes that file-mediated collaboration safe and productive.
|
||||
|
||||
---
|
||||
|
||||
## 1. The unit of work: a great task
|
||||
|
||||
An iteration is only as good as its tasks. Every ledger task MUST be:
|
||||
|
||||
1. **Bounded** — one domain, one definition-of-done, completable in one session.
|
||||
2. **Owned** — exactly one agent appointed (domain → agent is 1:1).
|
||||
3. **Locked** — declares the files it will write; that set is its lock.
|
||||
4. **Justified** — content cites sources, code references the task id, design references tokens.
|
||||
5. **Gated** — Critic reviews before merge; nothing self-certifies.
|
||||
6. **Logged** — on completion: ledger updated, commit made, `GOAL.md` touched if scope shifted.
|
||||
|
||||
If a task can't be written this way, it's too big — Maestro splits it.
|
||||
|
||||
---
|
||||
|
||||
## 2. The ledger lifecycle
|
||||
|
||||
Status flow, managed in [`LEDGER.md`](LEDGER.md):
|
||||
|
||||
```
|
||||
backlog → ready → claimed → in-review → done
|
||||
│ │
|
||||
└───────────┴──→ returned (with findings) → ready
|
||||
```
|
||||
|
||||
- **backlog** — captured, not yet actionable.
|
||||
- **ready** — dependencies met; Maestro promoted it.
|
||||
- **claimed** — an agent is working it; its files are now **locked**.
|
||||
- **in-review** — work done, handed to Critic.
|
||||
- **done** — Critic passed it; merged.
|
||||
- **returned** — Critic failed it; carries specific findings; goes back to ready.
|
||||
|
||||
**The locking rule (prevents file conflicts):** an agent may only claim a `ready` task whose declared files do **not** overlap any `claimed` or `in-review` task. This serialises conflicting work without a central daemon — the check happens at claim time against the ledger.
|
||||
|
||||
---
|
||||
|
||||
## 3. File ownership map
|
||||
|
||||
Primary owner routes the task; co-reviewers must sign off on cross-domain files.
|
||||
|
||||
| Path | Primary | Co-review |
|
||||
|---|---|---|
|
||||
| `src/data/kb/**` (content) | Professor | Critic (validator) |
|
||||
| `src/data/kb/SCHEMA.md`, `scripts/validate-kb.mjs` | Critic | Professor, Luthier |
|
||||
| `src/components/**`, `src/services/**`, `src/App.jsx`, `electron/**`, build cfg | Luthier | Critic; Muse if visual |
|
||||
| `tailwind.config.js`, visual layer, SVG renderers | Muse | Luthier (integration), Critic |
|
||||
| `src/lib/theory.js` | **shared** Professor (music) + Luthier (code) | Critic |
|
||||
| `docs/learn-curriculum.md`, `docs/progression-repertoire.md`, `docs/kb-*.md` | Professor | Herald (clarity) |
|
||||
| `README.md`, `CONTRIBUTING.md`, `LICENSE`, `.github/**` | Herald | Maestro |
|
||||
| `GOAL.md`, `docs/agents/LEDGER.md` | Maestro | all read |
|
||||
|
||||
**Shared files** (`theory.js`) get strict task-locking: only one task touching them runs at a time, reviewed by Critic **and** the non-owning domain.
|
||||
|
||||
---
|
||||
|
||||
## 4. The appointment algorithm (each iteration)
|
||||
|
||||
This is what `/jam-loop` (Maestro, run by the main loop) executes:
|
||||
|
||||
1. **PLAN** — read `LEDGER.md` + `GOAL.md`. Promote `backlog → ready` where deps are met. Pick the next batch by `priority × cadence-weight` ([weights in ROSTER](ROSTER.md)), ensuring file-disjointness for any parallel batch.
|
||||
2. **APPOINT** — for each chosen task, dispatch the agent whose domain == `task.domain`.
|
||||
3. **DISPATCH** — choose the shape:
|
||||
- **Serial (default, proven):** one task → one agent via the Agent tool. A dependent chain → run in order.
|
||||
- **Sprint (opt-in / "ultracode"):** independent ready tasks → parallel; dependent tasks → pipeline; via the Workflow tool.
|
||||
- **Parallel writes to disjoint files** → give each agent `isolation: "worktree"`.
|
||||
4. **GATE** — every completed worker task → **Critic** reviews (runs `npm run build`, `node scripts/validate-kb.mjs`, tests; applies judgment). Pass → `done`; fail → `returned` with findings.
|
||||
5. **RECONCILE** — Maestro commits passing work (one commit per task), updates `LEDGER.md` + `GOAL.md`, writes a one-line iteration log.
|
||||
6. **CONTINUE** — schedule the next iteration, or at sprint end open the PR (see §6).
|
||||
|
||||
**Appointing correctly = the five rules of great iterations** (§1) applied at dispatch: bounded scope to one agent, files locked, sources/refs required, Critic gate wired in, honest status on return.
|
||||
|
||||
---
|
||||
|
||||
## 5. Scheduling
|
||||
|
||||
The clean model: **schedule the conductor, not the band.** One recurring loop runs `/jam-loop`; each fire is one orchestrated iteration that appoints whichever agent the next ready task needs.
|
||||
|
||||
- **Session loop** (runs while this terminal is open): `/loop 1h /jam-loop` — good for a focused build sprint you're watching.
|
||||
- **Cloud schedule** (durable, survives closing the session): `/schedule` → e.g. "run /jam-loop every weekday at 09:07" — good for steady background progress. Recommended for a standing ensemble.
|
||||
|
||||
Per-domain cadence is the **weight**, not a separate cron: content advances most iterations, OSS/docs every ~4th. To shift emphasis for a stretch (e.g. "design week"), Maestro raises Muse's weight in the ledger header — no schedule change.
|
||||
|
||||
**Advanced — true parallel cadences (not default).** You *can* run separate loops per agent (`/loop 1h /jam-loop --only professor`, `/loop 3h /jam-loop --only luthier`). Only do this with **worktree isolation mandatory** and **strictly disjoint file ownership per loop**, or they will collide on shared files (`theory.js`, `App.jsx`, the ledger). The single-conductor model avoids this entirely; prefer it unless you have a specific throughput need.
|
||||
|
||||
---
|
||||
|
||||
## 6. Branching, review, and PRs
|
||||
|
||||
- One **sprint branch** off `main` (e.g. `sprint-jam-guide`); each task is a commit (parallel disjoint work uses worktrees off the branch).
|
||||
- Critic gates every commit; Maestro opens **one PR per sprint** to `main` summarising all tasks + validator/build status.
|
||||
- **Known constraint (this machine):** `gh` CLI is not installed. Open PRs via the GitHub API using stored git credentials:
|
||||
```bash
|
||||
TOKEN=$(printf 'protocol=https\nhost=github.com\n\n' | git credential fill | sed -n 's/^password=//p')
|
||||
# POST to https://api.github.com/repos/whattheflat/JamBuddy/pulls with {title, head, base, body}
|
||||
```
|
||||
(Repo was renamed `whattheflat` → `JamBuddy`; origin URL still works for push.)
|
||||
|
||||
---
|
||||
|
||||
## 7. Conflict resolution
|
||||
|
||||
- **File clash at claim time** → can't claim; pick another ready task or wait for the lock to clear.
|
||||
- **Cross-domain disagreement** (e.g. Muse wants a layout Luthier says is infeasible) → Maestro decides, records the call in the ledger, and if it's a product question surfaces it to the human instead of guessing.
|
||||
- **Critic vs author** → Critic's gate is binding on *correctness/quality*; on *taste/scope*, Maestro arbitrates. Returned work always carries specific, actionable findings — never a bare rejection.
|
||||
- **Scope creep** → if a task grows mid-flight, the agent stops, notes it in the ledger, and Maestro re-splits. Silent scope expansion is the cardinal sin.
|
||||
|
||||
---
|
||||
|
||||
## 8. State lives in files (because agents don't share memory)
|
||||
|
||||
Every iteration must leave perfect context for the next, since the next agent starts fresh:
|
||||
- the **ledger** carries task status, locks, and findings;
|
||||
- the **commit** carries the change and its rationale;
|
||||
- **`GOAL.md`** carries shifts in direction;
|
||||
- a recalled **memory** file (`project_ensemble`) carries the standing setup.
|
||||
|
||||
Write as if the next agent has never seen this conversation — because it hasn't.
|
||||
@@ -0,0 +1,63 @@
|
||||
# The JamBuddy Ensemble — Agent Roster
|
||||
|
||||
Six specialised agents build JamBuddy as both a **real-time jam companion** and an **open-source learning platform**. They collaborate through files (a shared ledger + the repo), never through live conversation — exactly like a git-based human team. The conductor (Maestro) appoints; the five workers do; the gate (Critic) approves.
|
||||
|
||||
How they run: [`PROTOCOL.md`](PROTOCOL.md). What's queued now: [`LEDGER.md`](LEDGER.md). The product north star: [`../../GOAL.md`](../../GOAL.md).
|
||||
|
||||
| Agent | Role | Realised as |
|
||||
|---|---|---|
|
||||
| 🎼 **Maestro** | Orchestrator / product lead | the `/jam-loop` skill (run by the main loop) + [`.claude/agents/maestro.md`](../../.claude/agents/maestro.md) for solo planning |
|
||||
| 🎓 **Professor** | Music & pedagogy | [`.claude/agents/professor.md`](../../.claude/agents/professor.md) |
|
||||
| 🔧 **Luthier** | Engineering | [`.claude/agents/luthier.md`](../../.claude/agents/luthier.md) |
|
||||
| 🎨 **Muse** | Design & UX | [`.claude/agents/muse.md`](../../.claude/agents/muse.md) |
|
||||
| 🔍 **Critic** | Quality & review (the gate) | [`.claude/agents/critic.md`](../../.claude/agents/critic.md) |
|
||||
| 📣 **Herald** | Open-source & community | [`.claude/agents/herald.md`](../../.claude/agents/herald.md) |
|
||||
|
||||
---
|
||||
|
||||
## Domains, ownership, and quality bar
|
||||
|
||||
### 🎼 Maestro — orchestrator / product lead
|
||||
- **Mandate:** turn `GOAL.md` into bounded, dependency-ordered tasks; appoint the right agent; reconcile and merge; keep the ledger and goal honest. Writes the plan, not the feature code.
|
||||
- **Owns (write):** `GOAL.md`, `docs/agents/LEDGER.md`.
|
||||
- **Quality bar:** every task is single-domain, single-DoD, fits one session, declares files + deps. No task ships without a Critic pass logged.
|
||||
|
||||
### 🎓 Professor — music & pedagogy
|
||||
- **Mandate:** the music brain. Research and author knowledgebase cells (the `/kb-expand` work, now a standing role), learning curricula, drills, and ear-training design; guard music-theory correctness.
|
||||
- **Owns (write):** `src/data/kb/**` (content), `docs/learn-curriculum.md`, `docs/progression-repertoire.md`; **co-owns** `src/lib/theory.js` (music correctness) with Luthier.
|
||||
- **Quality bar:** key-agnostic data only; `node scripts/validate-kb.mjs` green; named sources; pedagogically sequenced (intermediate, not step-one).
|
||||
|
||||
### 🔧 Luthier — engineering
|
||||
- **Mandate:** build and revise the app — features, the audio pipeline, wiring the KB into the UI (the Jam Guide panel), refactors, performance, Electron.
|
||||
- **Owns (write):** `src/components/**`, `src/services/**`, `src/App.jsx`, `electron/**`, build config; **co-owns** `src/lib/theory.js` (code) with Professor.
|
||||
- **Quality bar:** `npm run build` green; no regressions to the audio callbacks' stability contract (see `CLAUDE.md`); diff matches the task; reuses design tokens, never raw hex.
|
||||
|
||||
### 🎨 Muse — design & UX
|
||||
- **Mandate:** make it come to life on screen — visual design, layout, interaction, the "smart fit to screen" for the Jam Guide, SVG renderers' look, accessibility.
|
||||
- **Owns (write):** `tailwind.config.js` (design tokens), presentational components and their styling, SVG visual specs (`ChordDiagram`, `MiniPiano`).
|
||||
- **Quality bar:** uses `bg-surface`/`bg-panel`/`border-border`/`accent` tokens; responsive + fits the target viewport; WCAG-AA contrast; keyboard-reachable.
|
||||
|
||||
### 🔍 Critic — quality & review (the gate)
|
||||
- **Mandate:** review every other agent's work before it merges; run the validator, the build, and any tests; apply judgment; return failing work with specific findings. Veto power.
|
||||
- **Owns (write):** `scripts/validate-kb.mjs`, test infrastructure, review notes in the ledger. **Never** silently rewrites feature work — returns it.
|
||||
- **Quality bar:** mechanical checks must actually be run (evidence, not assertion); findings are specific and actionable.
|
||||
|
||||
### 📣 Herald — open-source & community
|
||||
- **Mandate:** make this a *platform*, not just an app — README that frames the learning-platform vision, CONTRIBUTING with the data-contract so musicians (not only coders) can PR a style, issue/PR templates, license, changelog, public roadmap.
|
||||
- **Owns (write):** `README.md`, `CONTRIBUTING.md`, `LICENSE`, `.github/**`, contributor-facing docs.
|
||||
- **Quality bar:** links resolve; instructions are runnable as written; a non-coding musician can follow the "add a style" path.
|
||||
|
||||
---
|
||||
|
||||
## Cadence weights (how the conductor balances the band)
|
||||
|
||||
Per-domain rhythm is expressed as how often Maestro is *eligible* to pick that domain each iteration — not as separate schedules (see [`PROTOCOL.md` §Scheduling](PROTOCOL.md)).
|
||||
|
||||
| Agent | Weight | Effect |
|
||||
|---|---|---|
|
||||
| Professor | 3 | content can advance every iteration |
|
||||
| Luthier | 3 | engineering every iteration (tasks are larger, span iterations naturally) |
|
||||
| Muse | 2 | when there is UI pending style (event-driven) |
|
||||
| Critic | — | mandatory gate stage every iteration, not weighted |
|
||||
| Herald | 1 | ~every 4th iteration, or when a contributor-facing change lands |
|
||||
| Maestro | — | plans + reconciles every iteration |
|
||||
@@ -0,0 +1,82 @@
|
||||
# Jam Guide — Concept A: "Stage"
|
||||
|
||||
> Design concept for the Jam Guide panel (ledger task **D-00a**). One of three concepts; the user picks. Tokens: `bg-surface` #0f0f0f, `bg-panel` #1a1a1a, `border-border` #2a2a2a, accent #a855f7, amber #f59e0b. Colour language inherited from `Fretboard.jsx`: **chord tone = accent purple**, **now-playing = amber**, scale = gray.
|
||||
|
||||
## 1. Name + thesis
|
||||
|
||||
**Stage** — a stage-monitor for your hands. It optimises for the **half-second glance mid-jam**: the current chord huge and unmistakable, the *next* chord pre-loaded so you can move in time, and exactly **one** big recommended voicing to put your fingers on. Everything a textbook would add collapses away. For the player who is already playing and just needs to be *told the next move*, readable across a rehearsal room.
|
||||
|
||||
## 2. Mockup — realistic panel proportions (full-width, short)
|
||||
|
||||
Real example: **Standard 12-bar blues in A** (`blues-12bar`, detected loop `A7→D7→E7`), play **"Barre-chord shuffle"** from `blues/guitar.js`. The big diagram is the `E_BARRE7` grip — `{ rootStr:6, offsets:[0,2,0,1,0,0] }` — placed in A: root on low E at fret 5, so the barre sits at fret 5.
|
||||
|
||||
```
|
||||
┌─ JAM GUIDE ──── Blues · 12-bar in A ────────────────── [Guitar▾] [Blues▾] [Stage|Playbook|Roadmap] ⌃collapse ─┐
|
||||
│ │
|
||||
│ NOW ░░░ NEXT ░░░ ── Barre-chord shuffle ── I7 IV7 V7 │
|
||||
│ ┌────────────┐ shuffle · root on 6th str ● ○ ○ ○ │
|
||||
│ │ │ ┌────────┐ bar 5 of 12 ┌──5fr──────────────┐ ○ ○ · · │
|
||||
│ │ A7 │ → │ D7 │ ╾╾╾╾╾╾╾╾╾╾╾○╾╾╾ ── loop ── e│ ● │ ← R ● ○ · ○ │
|
||||
│ │ │ └────────┘ ▮▮▮▮▮▮▮▮▮▮░░░░░ B│ ● │ ← 5 ○ ○ · │
|
||||
│ │ I7 │ IV7 2 bars → change G│ ● │ ← 3 │
|
||||
│ └────────────┘ D│ ● │ ← R │
|
||||
│ ↑ playing now prep this A│ ● │ ← 5 │
|
||||
│ E│ ● (5fr, barre) │ ← R "Strum short │
|
||||
│ ▸ improv: A mixolydian · target the 3 (C♯) └───────────────────┘ — shuffle's in │
|
||||
│ R=purple 3=amber accent the damp hand" │
|
||||
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
The `NOW` block is the loudest thing on screen — a single giant amber chord name with its Nashville/Roman number under it. `NEXT` is a smaller ghosted card to its right with an arrow and a literal countdown ("2 bars → change") fed by the loop-position logic. The right two-thirds is **one** large `ChordDiagram` (the recommended voicing for the *current* chord) plus a 12-bar position strip (`I7 IV7 V7` mini-map) so the eye can confirm where it is in the form without reading the whole grid.
|
||||
|
||||
## 3. Interaction & live-sync model
|
||||
|
||||
- **Chord change (detection):** when `currentChord` flips, the `NOW` card cross-fades (reuse the 200 ms `scale(0.85)→1` animation already in `ProgressionBanner.jsx`), the old `NOW` slides left into a brief "just played" ghost, and `NEXT` promotes into `NOW`. The big diagram swaps to the new chord's recommended voicing.
|
||||
- **Loop detected:** the position strip (`▮▮▮▮▮░░░`) and "bar N of 12" appear; without a loop, Stage still works — `NEXT` simply shows the most-likely next chord from `ProgressionSuggestions` and the bar-counter hides.
|
||||
- **Position in loop:** drives the `NEXT` card and the countdown ("2 bars → change"). The countdown is the differentiator — it lets the player *prepare the grip* before the change lands, which is the whole point of a stage monitor.
|
||||
- **Animates:** only the `NOW`/`NEXT` swap and the position-strip fill. Deliberately almost nothing else moves, so the panel never competes with playing.
|
||||
- **Taps:** tap `NOW` diagram → cycle to the *next way to play* this chord (the other plays in the same `plays[id]` array, e.g. "9th-chord stabs"). Tap `NEXT` → make it the focus (peek ahead). Tap the improv line → expand the one-line scale/target hint into the lick. Tap the collapse chevron → shrink to a one-line header (chord + next), the always-visible resting state.
|
||||
|
||||
## 4. KB-data mapping (buildable from data we already have — guitar packs exist)
|
||||
|
||||
| Panel part | KB source |
|
||||
|---|---|
|
||||
| `NOW` / `NEXT` chord names + numerals | detected `currentChord` + matched progression `degrees`/`rn` rendered in the live key (rotation-invariant match, L-01 util) |
|
||||
| Which progression + "12-bar in A" label | matched `progressions[].id` + `name` + `keyInfo.root` |
|
||||
| Position strip `I7 IV7 V7` + bar counter | progression `rn` + `bars` arrays; active index from `findLoopPosition` |
|
||||
| "2 bars → change" countdown | sum of `bars` from active step to the next chord change |
|
||||
| Big chord diagram | `plays[id][playIndex].chords[step].shape` — movable `rootStr`+`offsets` placed by key (or open `frets`+`onlyRoot`); rendered by `ChordDiagram.jsx` (D-01) |
|
||||
| "Barre-chord shuffle" label + tip | `plays[id][playIndex].label` + `.tips`; per-chord caption from `chords[step].note` |
|
||||
| Finger dots / R·3·5 labels | `shape.offsets` → pitch classes vs `getChordTones(currentChord)`; root + 3rd get the colour tier |
|
||||
| Improv one-liner | `improv.scales[].scale` matched to current chord + `improv.targetNotes` |
|
||||
| "more ways" on tap | length of `plays[id]` array |
|
||||
|
||||
Every field above exists today in the eight shipped guitar packs. Piano/bass packs don't exist yet; Stage degrades cleanly — the instrument tab only lists instruments present in `kb/index.js`, exactly as L-02 specifies.
|
||||
|
||||
## 5. Pros / cons / sacrifices
|
||||
|
||||
**Pros**
|
||||
- **Fastest possible read** mid-jam: one chord, one next, one grip — no scanning. The thing the user actually needs in the half-second is the biggest thing on screen.
|
||||
- **Preparation, not just status:** the `NEXT` card + bar countdown is unique to this concept — it tells you the move *before* it happens, which is what a live monitor is for.
|
||||
- **Cheapest to build & cheapest to animate:** renders one `ChordDiagram` at a time (vs a full grid), so it's the lightest on the audio thread and the simplest D-01/D-02 surface.
|
||||
|
||||
**Cons**
|
||||
- Shows **one voicing at a time** — you can't compare three ways to play A7 side by side without tapping.
|
||||
- Less of a "study" surface; a player who wants to learn the whole form's options at rest gets less here than in Playbook.
|
||||
|
||||
**Sacrifices:** the full progression grid (all chords × all plays visible at once). Stage trades breadth for legibility — it assumes you'll learn the catalogue at home and use Stage to *perform*.
|
||||
|
||||
```PREVIEW
|
||||
STAGE — one chord, the next, one grip. A stage-monitor for your hands.
|
||||
┌─ JAM GUIDE · Blues 12-bar in A ················· [Guitar][Blues] ─┐
|
||||
│ NOW NEXT Barre-chord shuffle I7 IV7 V7 │
|
||||
│ ┌──────────┐ ┌──────┐ ┌──5fr──────────┐ ▮▮▮▮▮░░░ │
|
||||
│ │ │ → │ D7 │ e│ ● │ bar 5 / 12 │
|
||||
│ │ A7 │ └──────┘ B│ ● │ │
|
||||
│ │ │ 2 bars → G│ ● ←3 │ ↑ amber = now │
|
||||
│ │ I7 │ change D│ ● │ ● purple = root │
|
||||
│ └──────────┘ E│ ● 5fr barre │ │
|
||||
│ ↑ playing prep this └───────────────┘ │
|
||||
│ ▸ A mixolydian · target the 3 (C♯) │
|
||||
└───────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
@@ -0,0 +1,116 @@
|
||||
# Jam Guide — Concept B: "Playbook"
|
||||
|
||||
> Ledger task **D-00b** · domain: design · author: Muse
|
||||
> Tokens: `bg-surface` #0f0f0f · `bg-panel` #1a1a1a · `border-border` #2a2a2a · `accent` #a855f7 · `amber` #f59e0b
|
||||
|
||||
## 1. Name + thesis
|
||||
|
||||
**"The Playbook"** — the whole loop opened flat like a method-book page: a grid where **columns are the chords of the progression** and **rows are different ways to voice it**, so you can read *across* the loop and *down* the voicings in a single glance and choose how you want to play it.
|
||||
|
||||
This is the **deepest-information** of the three concepts. Stage answers "what do I play *right now*"; Roadmap answers "where am I going". Playbook answers **"how is this whole thing played, and what are my options"** — the panel you open between choruses to study, then internalise.
|
||||
|
||||
---
|
||||
|
||||
## 2. Mockup — Blues 12-bar in A (real KB data, full-width ~70vh)
|
||||
|
||||
Rendered from `kb/blues/progressions.js` (`blues-12bar`) + `kb/blues/guitar.js` (`plays['blues-12bar']`). The 12-bar form collapses to its **3 distinct chords (I7 · IV7 · V7)** as columns — the grid teaches the *vocabulary*, the bar map (top strip) teaches the *form*. Each cell is a `ChordDiagram` (D-01). `●` = fretted/finger, `○` = root, `×` = muted, numbers above = barre fret.
|
||||
|
||||
```
|
||||
┌─ JAM GUIDE ────────────────────────────── [ Guitar ▸ Piano Bass ] [ Jazz ‖ BLUES ‖ Rock Bossa Funk … ] ──┐
|
||||
│ │
|
||||
│ Matched: Standard 12-bar · A major your loop: A7 → D7 → E7 ♻ bar 5 / 12 · 96 BPM shuffle │
|
||||
│ form: ┃A7┃A7┃A7┃A7┃D7┃D7▸┃A7┃A7┃E7┃D7┃A7┃E7┃ ← active bar pulses amber, sweeps L→R with the band │
|
||||
│ ───────────────────────────────────────────────────────────────────────────────────────────────────────────── │
|
||||
│ I7 · A7 IV7 · D7 ◀ playing now V7 · E7 │
|
||||
│ │
|
||||
│ Barre shuffle ●○ ● ● ● ● fr5 ●× ●○ ● ● ● ● fr5 ◀━━━━━ ●○ ● ● ● ● fr7 │
|
||||
│ ▸ beginner-safe │○│ │ │ │ │ │×│○│ │ │ │ │ ◀ active col │○│ │ │ │ │ │
|
||||
│ R-5-♭7-3 E-shape A7 A-shape D7 (glows) E-shape E7 │
|
||||
│ "root on 6th str" "same fret, root str up" "two frets above IV" │
|
||||
│ ───────────────────────────────────────────────────────────────────────────────────────────────────────────── │
|
||||
│ 9th stabs ×○♭7 ● ● ● fr5 ×○♭7 ● ● ● fr5 ×○♭7 ● ● 13 fr7 (V13) │
|
||||
│ ▸ intermediate │×│○│♭│●│●│●│ │×│○│♭│●│●│●│ │×│○│♭│●│●│●│ pinky → 13 │
|
||||
│ R-3-♭7-9 (Texas) "slide in ½-step below" "IV9" "V13 — horn-section hook" │
|
||||
│ ───────────────────────────────────────────────────────────────────────────────────────────────────────────── │
|
||||
│ Tritone shells ×○ ● ● × × fr5 ×○ ● ● × × fr5 ×○ ● ● × × fr7 │
|
||||
│ ▸ minimal/comp R-♭7-3 only "inner pair drops 1 fret → IV" "Chicago grip" │
|
||||
│ │
|
||||
│ ⌄ more ways (2) — Jimmy Reed boogie · Stormy Monday walk-up │
|
||||
│ ═══════════════════════════════════════════════════════════════════════════════════════════════════════════── │
|
||||
│ IMPROV over I7 → A Mixolydian · over IV7 → D Mixo · target the 3rds C♯→F♯→G♯ · the blues curl: ♭3↗3 │
|
||||
│ lick ▸ B.B. box in C: e|8 10b12 10 8 · D bent to E (the 3rd) tap a cell to hear it ♪ │
|
||||
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
Header reads tokens directly: panel `bg-panel`, hairlines `border-border`, the matched-style tab and active highlights `accent` (#a855f7), the live bar/now-playing pulse `amber` (#f59e0b) — matching `ProgressionBanner`'s existing "active = accent ring, numeral = amber" language so the two panels feel like one instrument.
|
||||
|
||||
---
|
||||
|
||||
## 3. Interaction & live-sync model
|
||||
|
||||
**Active-column highlight (the live thread).** The detected `currentChord` maps to a *column*, not a single cell. Reusing `findLoopPosition` (extracted to `src/lib/match.js` per L-01), the panel finds the loop index, looks up which of the 3 chord-columns that bar belongs to, and lights the whole column: an `accent` left-border rail, a faint `bg-accent/8` column wash, and an `◀ playing now` caret over the header. Because Playbook shows the *whole* loop at rest, the highlight is a **moving spotlight over a static page** — your eye already knows where the next column is, so you read ahead in rhythm. The top **bar-map strip** carries the finer-grained pulse (which of 12 bars), sweeping amber L→R; the grid columns carry the coarser "which chord". Two clocks, one glance.
|
||||
|
||||
**"More ways ▾" expansion.** Each cell stack shows the first **2–3 plays** that fit the panel height; remaining plays (the KB has up to 4–5 per progression — Jimmy Reed boogie, Stormy Monday walk-up, etc.) collapse behind a single `⌄ more ways (N)` row at the grid foot, labelled with their play titles so you know what you're expanding. Click → the grid grows new rows in place (panel scrolls internally, header + bar-map stay pinned). Per-row, a small `▸` chevron on the row label toggles that row's **tips** line (the `tips` string) and per-cell `note`/`extensions` annotations from collapsed to shown — dense by default, denser on demand.
|
||||
|
||||
**Instrument / style tabs.** Top-right: style tabs generated from `kb/index.js` keys (`jazz blues rock bossa funk reggae country rnb` today, growing as the loop fills cells) — the matched style is auto-selected and shown `accent`-filled; the others are quiet `text-gray-400` and switch the whole grid (re-voicing the same detected loop in another idiom — the core "Jazz→Bossa over one ii–V–I" payoff). Top-left: instrument segmented control (Guitar live; Piano/Bass dimmed until those packs exist, driven by `instruments` keys present in the registry). Both persist to settings.
|
||||
|
||||
**Scroll vs collapse.** Collapsed, the panel is a **single header strip** (`Matched: … · your loop · ♻ bar n/12`) always visible at the bottom of the app scroll — identical resting footprint to the other two concepts. Click the header (or scroll into it) → expands to ~70vh. Inside, the grid scrolls **vertically** (more rows than fit) with the header, bar-map, and improv footer pinned; on narrow viewports it reflows (see §5) so columns never crush.
|
||||
|
||||
---
|
||||
|
||||
## 4. KB-data mapping (proves it's buildable today)
|
||||
|
||||
Every cell is driven by existing fields in the shipped guitar packs — nothing new is invented:
|
||||
|
||||
| UI element | KB source (`kb/blues/…`) |
|
||||
|---|---|
|
||||
| Column headers (I7 · IV7 · V7) + `name`, key chip | `progressions.js` → `rn`, `name`, `mode`; deduped against `degrees`/`qualities` to the distinct chords |
|
||||
| Top bar-map strip `┃A7┃A7┃…┃` | `progressions.js` → full `degrees` × `bars`, rendered absolute in the detected key |
|
||||
| Row labels ("Barre shuffle", "9th stabs", "Tritone shells") | `guitar.js` → `plays['blues-12bar'][].label` |
|
||||
| Row level badge (`▸ intermediate`) | `plays[][].level` |
|
||||
| Each diagram cell | `plays[][].chords[stepForThisColumn].shape` → `ChordDiagram` (D-01); movable `rootStr`+`offsets` placed at the column chord's fret in the detected key; open shapes via `frets`+`onlyRoot` |
|
||||
| Cell colour-tone label (`R-3-♭7-9`), `13`/`♭7` glyphs | `chords[].extensions` + the shape's computed pitch classes (chord-tone tier = `accent`, same as Fretboard) |
|
||||
| Per-cell caption | `chords[].note` ("same fret, root str up", "V13 — pinky reaches the 13") |
|
||||
| Per-row tips (▸ reveal) | `plays[][].tips` |
|
||||
| "more ways (N)" titles | the remaining `plays['blues-12bar']` entries beyond the visible rows |
|
||||
| IMPROV footer | `improv.scales[].over/scale`, `improv.targetNotes`, `improv.licks[].tab/description` |
|
||||
| Style/instrument tabs | `kb/index.js` registry keys + each style's `instruments` keys |
|
||||
|
||||
Because a 12-bar has many bars but few distinct chords, the **column reducer** (distinct `degree`+`quality` pairs, order of first appearance) keeps the grid to 3–4 columns even for a 12-bar — exactly what makes "down the voicings" legible. A 4-chord loop (Axis I–V–vi–IV) yields 4 columns; the same component, no special-casing.
|
||||
|
||||
---
|
||||
|
||||
## 5. Pros / cons / what it sacrifices
|
||||
|
||||
**Pros**
|
||||
- **Most information per screen.** You see the entire loop *and* 3–5 ways to voice each chord at once — the only concept that supports true *comparison* ("shells vs barres vs 9ths") side by side. This is the deepest-study option, the method-book page.
|
||||
- **Teaches vocabulary, not just the moment.** Reading *down* a column is a voicing lesson; reading *across* a row is the form. Level badges (beginner→advanced grips in one stack) let a player climb difficulty in place.
|
||||
- **Reuses every KB field with zero waste** — multiple `plays`, `level`, `tips`, `extensions`, `note`, improv — so the agent-authored content is fully surfaced (Stage/Roadmap show a slice; Playbook shows the book).
|
||||
- **Grid is reflow-friendly:** narrow → one play per row, columns scroll horizontally (the kb-plan §4 "smart fit" fallback) without changing the mental model.
|
||||
|
||||
**Cons**
|
||||
- **Density is the cost.** It is *not* a glance-and-go panel mid-solo — there's a lot on screen, and the moving column-spotlight is the only thing that's instant. A player needs a beat to study it; if they want "just tell me the one chord now," Stage wins.
|
||||
- **Diagram real-estate pressure.** 3–5 rows × 3–4 columns of SVG diagrams is the heaviest render of the three; cells must shrink on small windows (mitigated by collapse + reflow, but a 13" laptop shows ~3 rows before scroll).
|
||||
- **Bar-form abstraction.** Collapsing 12 bars to 3 columns is powerful but hides bar-by-bar order *in the grid* — recovered by the top bar-map strip, but that's a second thing to read.
|
||||
|
||||
**What it sacrifices:** *immediacy*. The whole design trades instant glanceability for completeness — a deliberate inversion of Stage. It assumes the musician has a moment (a turnaround, a verse they know, a teacher's pause) to look down and *study*, then look up and play. The active-column spotlight is the lifeline that keeps it usable even mid-jam, but the panel's centre of gravity is **learning the loop**, not surviving the next bar.
|
||||
|
||||
---
|
||||
|
||||
```PREVIEW
|
||||
┌ JAM GUIDE · Playbook ──────────[Guitar][Jazz‖BLUES‖Rock…]┐
|
||||
│ Matched: 12-bar · A maj loop A7→D7→E7 ♻ bar5/12 96BPM │
|
||||
│ form ┃A7┃A7┃A7┃A7┃D7┃D7▸┃A7┃A7┃E7┃D7┃A7┃E7┃ (amber sweep) │
|
||||
│ ──────────── I7·A7 ──────── IV7·D7 ◀now ──── V7·E7 ────── │
|
||||
│ Barre shuffle ●○●●●● fr5 ×●○●●● fr5 ●○●●●● fr7 │
|
||||
│ ▸ beginner E-shape A7 A-shape (glows) E-shape E7 │
|
||||
│ 9th stabs ▸ ×○♭7●●● fr5 ×○♭7●●● fr5 ×○♭7●●13 V13 │
|
||||
│ int (Texas) R-3-♭7-9 "IV9" horn hook │
|
||||
│ Tritone shell ×○●●×× fr5 ×○●●×× fr5 ×○●●×× fr7 │
|
||||
│ minimal/comp R-♭7-3 inner pair −1 Chicago grip │
|
||||
│ ⌄ more ways (2): Jimmy Reed · Stormy │
|
||||
│ ═════════════════════════════════════════════════════════ │
|
||||
│ IMPROV I7→A Mixo · target 3rds C♯→F♯→G♯ · curl ♭3↗3 ♪tap │
|
||||
│ ▲ columns = loop chords · rows = ways to voice · scan ↕ │
|
||||
└──────────────────────────────────────────────────────────┘
|
||||
```
|
||||
@@ -0,0 +1,130 @@
|
||||
# Jam Guide — Concept C: "Roadmap"
|
||||
|
||||
> **Thesis:** Don't show chords — show the *journey through the loop* and what to solo over it. A horizontal timeline with a live "you are here" playhead, each station previewing its guide tones (3rds & 7ths) and the scale to blow over, with voice-leading rails drawn *between* the chords so the player sees the next note coming before it arrives.
|
||||
|
||||
Concept C is the **improv-first** option. Where Concept A optimises for *playing the chord in front of you* and Concept B for *comparing voicings at rest*, Concept C optimises for the soloist's question: **"the loop is turning — what do I aim at next, and what scale carries me there?"** The chord *voicing* diagram is present but demoted to a thin strip; the hero is the **improv map**: a lane of guide-tone targets and a lane of voice-leading arrows running left-to-right under a moving playhead.
|
||||
|
||||
It leans hardest into the learning-platform vision in `GOAL.md` Part 2 (L2 "next-chord preview tier", target-note highlighting) and the curriculum's **Tier B — Playing the Changes** (guide tones, the 7th-falls-to-the-3rd rail) and **Tier D — Functional Ears** (seeing the loop as motion, predicting the V).
|
||||
|
||||
---
|
||||
|
||||
## 1. Name + thesis
|
||||
|
||||
**Roadmap** — the live progression as a horizontal highway: a playhead drives left-to-right through the loop, each chord is a station showing its **target tones + scale**, and **voice-leading rails** connect each station to the next so you read the change one beat early.
|
||||
|
||||
---
|
||||
|
||||
## 2. Mockup (full-width panel, ii–V–I in C — the gold-standard `jazz-251-major`)
|
||||
|
||||
Detected loop `Dm7 → G7 → Cmaj7`, key C major, mode major. Playhead currently over G7, leaning into Cmaj7. Active station glows accent-purple; the rest are dimmed by age exactly like the existing `ProgressionBanner` opacity tiers.
|
||||
|
||||
```
|
||||
┌─ JAM GUIDE ───────────────────────────────────────────── [Guitar ▾] · Jazz │ Blues │ Rock │ Bossa … ─┐
|
||||
│ ii–V–I in C major · your loop: Dm7 → G7 → Cmaj7 · ♻ 2 bars/chord · ~132 BPM │
|
||||
│ │
|
||||
│ ┌──── bar 1 ───────────┬──── bar 2 ───────────┬──── bars 3-4 ──────────────┐ ◀ lookahead 1 beat │
|
||||
│ │ Dm7 (ii7) │ ▶ G7 (V7) ◀ now │ Cmaj7 (Imaj7) │ │
|
||||
│ │ D dorian │ G mixolydian │ C major (avoid 4) │ ← SCALE lane │
|
||||
│ ├──────────────────────┼──────────────────────┼────────────────────────────┤ │
|
||||
│ │ guide tones │ guide tones │ guide tones │ │
|
||||
│ │ 3rd ● F 7th ○ C │ 3rd ● B 7th ○ F │ 3rd ● E 7th ○ B │ ← TARGET lane │
|
||||
│ │ ╲ │ ╲ │ │ (land these on 1) │
|
||||
│ │ C ─────────▶ B │ F ─────────▶ E │ ( B holds → next loop ) │ ← VOICE-LEADING │
|
||||
│ │ 7th of ii falls ½ │ 7th of V falls ½ │ resolved — get light │ rails (7→3) │
|
||||
│ ├──────────────────────┼──────────────────────┼────────────────────────────┤ │
|
||||
│ │ ▣▣·▣· shell │ ▣·▣▣· shell │ ▣▣·▣· shell │ ← voicing strip │
|
||||
│ │ R–♭3–♭7 (tap ▸) │ R–3–♭7 (tap ▸) │ R–3–7 (tap ▸) │ (secondary) │
|
||||
│ └──────────────────────┴──────────────────────┴────────────────────────────┘ │
|
||||
│ ◐──────────────────────────────●───────────────────────────────────────── loop playhead │
|
||||
│ │·····│·····│·····│·····│·····│●····│·····│·····│·····│·····│·····│·····│ ← beat grid (you here) │
|
||||
│ │
|
||||
│ TIP In any ii–V–I the 7th of one chord falls a half-step to the 3rd of the next — C→B, F→E. │
|
||||
│ That two-note rail is the whole map. · tap a station → its guide tones light the fretboard ▸ │
|
||||
└───────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
The same panel over a **minor blues** (`blues-minor`-style, key A minor) reads as a longer highway — 12 stations scroll horizontally under the fixed playhead, the TARGET lane showing the ♭3/♭7 of each i7/iv7/V7 and the VOICE-LEADING rail highlighting the chromatic approach into bar 11's return home. The lookahead flag always sits one chord to the right of the playhead so the soloist sees the *incoming* target before the band gets there.
|
||||
|
||||
**Why this layout:** the three stacked lanes (SCALE / TARGET / VOICE-LEADING) are the literal pedagogy of "playing the changes" turned into a picture you read at a glance. The voicing strip is one row, not the hero — a soloist needs *where to aim*, not *how to grip*, and can tap to expand a grip when comping.
|
||||
|
||||
---
|
||||
|
||||
## 3. Interaction & live-sync model
|
||||
|
||||
**Playhead = loop position, continuously.** The `●` rides the beat grid driven by the onset/BPM pipeline (`handleOnset` tempo histogram → BPM) and the `findLoopPosition` util (extracted in L-01). Two sync layers:
|
||||
|
||||
- **Coarse (chord-accurate, ships first):** the active *station* is whatever `findLoopPosition(chordHistory, detectedProgression)` returns — exactly how `ProgressionBanner` already highlights the loop. Re-uses proven logic; no new timing risk. The playhead snaps station-to-station on each detected change.
|
||||
- **Fine (beat-interpolated, phase 5 polish):** between detected changes, advance the `●` across the station's beat cells by interpolating `(now − lastOnsetTime) × BPM/60`, clamped to the station's `bars × 4` beats. Purely visual easing — if detection corrects the position, the playhead re-snaps. Degrades gracefully to coarse when BPM is unknown.
|
||||
|
||||
**Lookahead.** The station immediately right of the playhead carries a persistent **lookahead flag** ("◀ lookahead"). Its TARGET lane is pre-lit at ~60% brightness a configurable lead (default 1 beat) before the playhead crosses the barline — this is L2's "next-chord preview tier" and the bassist's walking-line scaffold. The flag answers "what's coming" without the player losing the current station.
|
||||
|
||||
**Tap to drill deeper (progressive disclosure):**
|
||||
- **Tap a station** → emits `onChordClick(chord)` (the prop `ProgressionBanner` already fires) so the existing `Fretboard`/`Piano` views light that chord's tones, *plus* a Roadmap-specific extra: the station's two guide tones render in the accent tier and its scale in the pentatonic/scale tiers — i.e. "show me where to aim on the neck."
|
||||
- **Tap the SCALE label** → toggles the fretboard between the full scale and the chord-tone-only skeleton for that chord (the curriculum's "chord inside the scale" drill).
|
||||
- **Tap the voicing strip `▸`** → expands that one cell into a full `ChordDiagram` (D-01) inline, without leaving the roadmap. This is the only place Concept C surfaces a real grip; it stays out of the way until asked.
|
||||
- **Tap TIP** → expands the progression's `tip` plus any `lick.tab` whose `over` matches this progression id, rendered as monospace tab under the highway.
|
||||
|
||||
**Live behaviour when no loop is matched.** Fallback to a single-station roadmap centred on `currentChord`: its guide tones, a `getCompatibleScales`-derived scale, and the voicing strip — so the panel is never empty (same fallback contract as the kb-plan §4 matching note).
|
||||
|
||||
**Keyboard / a11y.** Left/Right arrows move focus station-to-station (independent of the playhead); Enter = tap; the active station carries `aria-current="true"` and a visible focus ring (`ring-accent`). The playhead has `role="progressbar"` with `aria-valuetext` = current chord + beat. All lane colours meet AA against `bg-panel` (the accent `#a855f7` on `#1a1a1a` and amber `#f59e0b` for the held/secondary tone both clear 4.5:1; dimmed stations never drop below the 0.25 opacity floor the banner already uses for legibility).
|
||||
|
||||
---
|
||||
|
||||
## 4. KB-data mapping — what's data vs. what's computed
|
||||
|
||||
| Roadmap element | Source | Data field / helper |
|
||||
|---|---|---|
|
||||
| Station chord names (`Dm7 G7 Cmaj7`) | **derived at runtime** | detected loop → key root + `progression.degrees` + `qualities`, resolved like `getSuggestedProgressions` already does |
|
||||
| Roman numerals (`ii7 V7 Imaj7`) | **data** | `progression.rn` (display) — falls back to computed `toRomanNumeral` for the no-match case |
|
||||
| Bars per station (`bar 1 / bars 3-4`) | **data** | `progression.bars` — drives station width on the highway |
|
||||
| SCALE lane (`D dorian`, `G mixolydian`) | **data, with computed fallback** | KB `improv.scales[{over, scale, why}]` keyed by the chord's `rn`. If a style's pack has no `improv.scales` entry for a degree → **compute** a default from `SCALES`/`getCompatibleScales` (e.g. Mixolydian over a dom7) |
|
||||
| "avoid 4" / scale caveats | **data** | `improv.scales[].why` (the jazz pack literally says "avoid sitting on the 4th over the maj7") |
|
||||
| TARGET lane — 3rd & 7th tones | **fully computed** | `getChordTones(chord)` → index 1 = 3rd, last = 7th (per `CHORD_TYPES.intervals` ordering). *No KB field stores guide tones; theory.js derives them.* |
|
||||
| VOICE-LEADING rails (`C ▶ B`, `F ▶ E`) | **computed** | for adjacent stations, find the 7th of chord *n* and the 3rd of chord *n+1*; draw a rail when they're a half/whole step apart. The "7→3 falls ½" relationship comes from comparing `getChordTones` outputs — pure interval math |
|
||||
| TARGET-lane prose hint | **data** | `improv.targetNotes` ("Land the 3rd of each chord on the downbeat") |
|
||||
| Voicing strip (mini grid + `R–3–♭7`) | **data** | `plays[progId][0].chords[i].shape` (rendered tiny) + `.note` label; full grip on tap via `ChordDiagram` |
|
||||
| TIP line | **data** | `progression.tip`; lick tab from `improv.licks[].tab` filtered by `over === progId` |
|
||||
| Playhead position | **computed (live)** | `findLoopPosition` (L-01) + BPM from `handleOnset`; no KB data |
|
||||
| BPM / feel label | **data + live** | `meta.tempoRange` / `meta.feel` for context; live BPM from the onset pipeline |
|
||||
|
||||
**Honesty note — the load-bearing computed pieces.** Concept C's two hero lanes are *not in the KB at all*:
|
||||
1. **Guide tones** (3rd/7th badges) are computed from `getChordTones`. The KB stores *that* a scale fits and *that* the 7th resolves (prose), but never the literal pitches — those are derived per detected key. This is a feature: it stays key-agnostic (kb-plan principle 1) and works in all 12 keys for free.
|
||||
2. **Voice-leading rails** are computed by diffing consecutive chords' tone sets. No new `theory.js` function is strictly required — `getChordTones` + a small `voiceLeadingPairs(chordA, chordB)` helper (≤15 lines: match each tone of A to its nearest tone in B, keep moves ≤2 semitones) covers it. I'd flag this helper to Maestro as a tiny shared `theory.js`/`match.js` addition Luthier owns; Muse only consumes its output.
|
||||
|
||||
Everything else is straight KB reads. The scale lane degrades gracefully: data-driven where a pack authored `improv.scales`, computed-default where it didn't — so the roadmap renders for *any* style cell, even a minimal one.
|
||||
|
||||
---
|
||||
|
||||
## 5. Pros / cons / what it sacrifices
|
||||
|
||||
**Pros**
|
||||
1. **Directly teaches improv** — guide tones + scale + voice-leading rails are the curriculum's "playing the changes" pillar rendered literally; this is the only concept that answers *"what do I solo with?"* rather than *"what's the chord?"*
|
||||
2. **Lookahead is built in** — the one-beat-early next-target preview is L2's headline learning feature and the thing a soloist physically needs; it's structural here, bolted-on elsewhere.
|
||||
3. **Maximises the KB's prose assets** — `improv.scales[].why`, `targetNotes`, `tip`, and `licks` (rich, sourced text the Professor wrote) get top billing instead of being buried under diagrams.
|
||||
4. **Key-agnostic by construction** — the two hero lanes are computed, so one KB cell drives a correct roadmap in all 12 keys with zero extra data.
|
||||
|
||||
**Cons**
|
||||
1. **Two computed subsystems** (guide-tone extraction, voice-leading pairing) before it looks "real" — more theory.js surface than A or B, which mostly *display* stored data. Mitigated: both are tiny and reuse `getChordTones`.
|
||||
2. **Horizontal scroll on long forms** — a 12-bar blues exceeds one screen; stations must shrink or scroll. The fixed-playhead / scrolling-highway pattern solves it but is more layout work than a static grid.
|
||||
3. **Voicing is genuinely secondary** — a player who opened the panel to *find a grip* has to tap to get it. That's the deliberate trade (see below).
|
||||
|
||||
**What it sacrifices**
|
||||
- **Voicing comparison.** Concept B shows 3 ways to grip every chord side-by-side; Concept C shows *one* grip per station as a thumbnail and makes you tap for the rest. A jammer whose actual need is "give me a chord shape right now" is better served by A or B. Roadmap bets that the higher-value, harder-to-find guidance is *where to aim your solo* — and that voicings, being concrete and well-served elsewhere in the app, can wait behind a tap.
|
||||
|
||||
---
|
||||
|
||||
```PREVIEW
|
||||
ROADMAP — improv-first: the loop as a highway you solo across
|
||||
ii–V–I in C Dm7 → G7 → Cmaj7 ♻ 2 bars/chord ~132 BPM
|
||||
┌── Dm7 (ii7) ──┬─▶ G7 (V7) ◀now ─┬── Cmaj7 (Imaj7) ──┐ ◀ look-
|
||||
│ D dorian │ G mixolydian │ C major (avoid 4) │ ahead
|
||||
│ 3rd●F 7th○C │ 3rd●B 7th○F │ 3rd●E 7th○B │ ← targets
|
||||
│ C ──▶ B │ F ──▶ E │ ( B holds → loop )│ ← 7→3 rail
|
||||
│ ▣▣·▣· shell ▸ │ ▣·▣▣· shell ▸ │ ▣▣·▣· shell ▸ │ ← voicing
|
||||
└───────────────┴─────────────────┴────────────────────┘
|
||||
◐────────────────●────────────────────────────────── playhead
|
||||
│··│··│··│··│··│●·│··│··│··│··│··│··│ beat grid (here)
|
||||
TIP 7th of one chord falls ½-step to the 3rd of the next:
|
||||
C→B, F→E — that two-note rail is the whole map.
|
||||
tap a station → its guide tones light up the fretboard ▸
|
||||
```
|
||||
@@ -0,0 +1,65 @@
|
||||
# KB Expansion Backlog
|
||||
|
||||
The queue for the `/kb-expand` loop. One cell per session, top-to-bottom. Protocol and schema: [`docs/kb-plan.md`](kb-plan.md). Statuses: `todo` → `in-progress` → `done (YYYY-MM-DD, coverage)`.
|
||||
|
||||
## Phase 0 — Foundation (must be first)
|
||||
|
||||
| # | Cell | Status |
|
||||
|---|---|---|
|
||||
| 0 | Bootstrap: `src/data/kb/` + `SCHEMA.md` + `scripts/validate-kb.mjs` + `kb/index.js` + **jazz/guitar gold standard** | done (2026-06-12, iteration 1) |
|
||||
|
||||
## Guitar
|
||||
|
||||
| # | Style | Status |
|
||||
|---|---|---|
|
||||
| 1 | Jazz (part of bootstrap) | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 2 | Blues | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 3 | Rock | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 4 | Bossa Nova | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 5 | Funk | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 6 | Reggae | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 7 | Country / Folk | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 8 | R&B / Neo-soul | done (2026-06-12, 5 progressions × 2 plays, validator ✓) |
|
||||
| 9 | Gospel | todo |
|
||||
| 10 | Pop | todo |
|
||||
|
||||
## Piano
|
||||
|
||||
| # | Style | Status |
|
||||
|---|---|---|
|
||||
| 11 | Jazz | todo |
|
||||
| 12 | Blues | todo |
|
||||
| 13 | Bossa Nova | todo |
|
||||
| 14 | Gospel | todo |
|
||||
| 15 | R&B / Neo-soul | todo |
|
||||
| 16 | Pop | todo |
|
||||
| 17 | Rock | todo |
|
||||
| 18 | Funk | todo |
|
||||
| 19 | Country / Folk | todo |
|
||||
| 20 | Reggae | todo |
|
||||
|
||||
## Bass
|
||||
|
||||
| # | Style | Status |
|
||||
|---|---|---|
|
||||
| 21 | Blues | todo |
|
||||
| 22 | Jazz | todo |
|
||||
| 23 | Funk | todo |
|
||||
| 24 | Reggae | todo |
|
||||
| 25 | Rock | todo |
|
||||
| 26 | Bossa Nova | todo |
|
||||
| 27 | R&B / Neo-soul | todo |
|
||||
| 28 | Country / Folk | todo |
|
||||
| 29 | Gospel | todo |
|
||||
| 30 | Pop | todo |
|
||||
|
||||
## UI milestones (interleave when their data exists)
|
||||
|
||||
| Milestone | Depends on | Status |
|
||||
|---|---|---|
|
||||
| Jam Guide MVP (panel, matching, `ChordDiagram.jsx`, live sync) | cell 0 | todo |
|
||||
| `MiniPiano.jsx` + recipe resolver | cell 11 | todo |
|
||||
| Bass pattern renderer | cell 21 | todo |
|
||||
| Improv layer (licks/tabs display) | a few guitar cells | todo |
|
||||
|
||||
> Notes for sessions: piano style order front-loads the styles where piano voicings differ most (jazz/gospel/neo-soul); bass order front-loads line-driven styles (blues/jazz/funk). Adjust freely — order is a default, not a rule.
|
||||
@@ -0,0 +1,223 @@
|
||||
# Knowledgebase Plan — Styles × Instruments × Progressions × Voicings
|
||||
|
||||
The plan for building JamBuddy's **jam knowledgebase**: an intermediate guide to the standard progressions of each style (Jazz, Blues, Rock, Bossa Nova, …) and the different ways to *play* them per instrument (guitar first, then piano, then bass) — expandable one session at a time via a repeatable loop, and rendered live in a large **Jam Guide** panel at the bottom of the app.
|
||||
|
||||
Three principles drive everything:
|
||||
|
||||
1. **Key-agnostic data.** Everything is stored as scale degrees and movable shapes, never absolute chords. The app detects the key; one KB entry renders in all 12 keys. This is the same convention `PROGRESSIONS.degrees` and the movable shapes in `voicings.js` already use.
|
||||
2. **Machine-verifiable quality.** A validator proves every voicing actually contains the chord's tones before content lands. That's what makes agent-generated content trustworthy over many loop iterations.
|
||||
3. **One bounded cell per session.** Each expansion session completes exactly one style × instrument cell (researched, authored, validated, committed). Small enough to review, big enough to matter.
|
||||
|
||||
---
|
||||
|
||||
## 1. Architecture
|
||||
|
||||
```
|
||||
src/data/kb/
|
||||
index.js — registry aggregating all styles (UI reads only this)
|
||||
SCHEMA.md — the authoring contract (formats below, with one full example)
|
||||
jazz/
|
||||
meta.js — { id, label, feel, tempoRange, character }
|
||||
progressions.js — the style's standard progressions (instrument-independent)
|
||||
guitar.js — guitar pack: plays + comping + improv
|
||||
piano.js — piano pack
|
||||
bass.js — bass pack
|
||||
blues/ … — same shape per style
|
||||
scripts/
|
||||
validate-kb.mjs — quality gate, run with `node scripts/validate-kb.mjs`
|
||||
docs/
|
||||
kb-backlog.md — the cell matrix with statuses (the loop's queue)
|
||||
```
|
||||
|
||||
`index.js` imports whatever style folders exist — the Jam Guide's style tabs grow automatically as the loop fills cells. A style is usable for one instrument before the others exist (guitar-first rollout).
|
||||
|
||||
### Progression entry (per style)
|
||||
|
||||
```js
|
||||
// kb/jazz/progressions.js
|
||||
export default [
|
||||
{
|
||||
id: 'jazz-251-major',
|
||||
name: 'ii–V–I',
|
||||
rn: ['ii7', 'V7', 'Imaj7'],
|
||||
degrees: [2, 7, 0], // semitone offsets from key root
|
||||
qualities: ['min7', 'dom7', 'maj7'], // keys of CHORD_TYPES in theory.js
|
||||
bars: [1, 1, 2],
|
||||
mode: 'major',
|
||||
songs: ['Autumn Leaves', 'All The Things You Are'],
|
||||
tip: 'The 7th of each chord resolves down a half-step to the 3rd of the next.',
|
||||
},
|
||||
// … 4-8 progressions per style (see docs/progression-repertoire.md §1 for the lists)
|
||||
]
|
||||
```
|
||||
|
||||
### Instrument pack — guitar
|
||||
|
||||
```js
|
||||
// kb/jazz/guitar.js
|
||||
export default {
|
||||
styleIntro: '2-3 sentences on the guitarist's role in this style.',
|
||||
comping: [{ label: 'Four-to-the-bar (Freddie Green)', rhythm: '♩ ♩ ♩ ♩', description: '…' }],
|
||||
plays: {
|
||||
'jazz-251-major': [ // ≥2 "ways to play" per progression
|
||||
{
|
||||
label: 'Shell voicings',
|
||||
level: 'intermediate',
|
||||
chords: [ // one entry per progression step
|
||||
{ shape: { rootStr: 5, offsets: ['x', 0, 'x', 0, 1, 'x'], fingers: [0,1,0,2,3,0] },
|
||||
note: 'root–♭7–♭3' },
|
||||
// …
|
||||
],
|
||||
tips: 'Stay light; the 3rds and 7ths do all the work.',
|
||||
},
|
||||
{ label: 'Drop-2 on top four strings', /* … */ },
|
||||
],
|
||||
},
|
||||
improv: {
|
||||
scales: [{ over: 'ii7', scale: 'dorian', why: '…' }],
|
||||
targetNotes: 'Land the 3rd of each chord on beat 1.',
|
||||
licks: [{ tab: 'e|---…', description: '…', over: 'jazz-251-major' }],
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
**Shape format** follows the existing `voicings.js` convention so the renderer is shared: movable shapes use `rootStr` + `offsets` relative to the root fret (renders in any key); open shapes use absolute `frets` + `onlyRoot` (pitch class) and only render when the key matches. Strings are arrays of 6, low-E first, `'x'` = muted.
|
||||
|
||||
### Instrument pack — piano
|
||||
|
||||
Voicings are **interval recipes** resolved per chord quality (no fingering data needed):
|
||||
|
||||
```js
|
||||
plays: {
|
||||
'jazz-251-major': [
|
||||
{
|
||||
label: 'Rootless A/B alternation',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ recipe: { LH: ['3', '5', '7', '9'] }, note: 'Type A' }, // ii7
|
||||
{ recipe: { LH: ['7', '9', '3', '13'] }, note: 'Type B' }, // V7
|
||||
{ recipe: { LH: ['3', '5', '7', '9'] }, note: 'Type A' }, // Imaj7
|
||||
],
|
||||
register: 'top note between C4 and C5',
|
||||
tips: 'Alternate types so inner voices barely move.',
|
||||
},
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
Degrees are chord-degree strings (`'1' '3' 'b7' '9' '13'`); the resolver maps them through the chord quality's intervals (which `theory.js` chord templates already encode).
|
||||
|
||||
### Instrument pack — bass
|
||||
|
||||
Line patterns per progression step, in degrees plus approach annotations:
|
||||
|
||||
```js
|
||||
plays: {
|
||||
'blues-12bar': [
|
||||
{
|
||||
label: 'Walking, chromatic approach',
|
||||
level: 'intermediate',
|
||||
bars: [{ beats: ['R', '3', '5', 'chrom→next'] } /* … per bar */],
|
||||
tips: 'Beat 1 is always the new root; beat 4 walks into it.',
|
||||
},
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Quality gates
|
||||
|
||||
### Mechanical — `scripts/validate-kb.mjs` (must pass before any commit)
|
||||
|
||||
- ids unique; every `plays` key references an existing progression id; `chords`/`bars` length matches the progression length
|
||||
- `degrees` ∈ 0–11; `qualities` are keys of `CHORD_TYPES`; `mode` is a known mode
|
||||
- guitar shapes: 6 entries per array, frets 0–15, **fret span ≤ 4** (intermediate hands), and — the strong check — the shape's computed pitch classes (standard tuning EADGBE) must contain the chord's root and defining tones (3rd/7th or quality equivalent) and contain **no out-of-chord tones**
|
||||
- piano recipes: every degree resolvable for that chord quality
|
||||
- coverage per cell: ≥ 4 progressions, ≥ 2 plays per progression, improv section present (guitar/piano), styleIntro present
|
||||
|
||||
### Musician checklist (human/agent self-review, in SCHEMA.md)
|
||||
|
||||
- Are the plays *idiomatically different* (register, density, difficulty), not just transpositions of each other?
|
||||
- Is each play genuinely intermediate — no 5-fret stretches, no 2-octave rootless clusters?
|
||||
- Does the style actually sound like the style (bossa ≠ jazz with different labels: distinct rhythm descriptions)?
|
||||
- Do tips teach a *transferable* idea (voice leading, register, space), not just "play this"?
|
||||
|
||||
---
|
||||
|
||||
## 3. The expansion loop
|
||||
|
||||
### The queue
|
||||
|
||||
`docs/kb-backlog.md` holds the matrix of cells with statuses (`todo` / `in-progress` / `done` + date + coverage). Order: **all guitar cells first** (most voicing complexity — it sets the quality bar), then piano, then bass. Style priority within each instrument: jazz → blues → rock → bossa → funk → reggae → country/folk → R&B/neo-soul → gospel → pop.
|
||||
|
||||
### The session protocol (encoded as the `/kb-expand` project skill)
|
||||
|
||||
Each session:
|
||||
|
||||
1. **Orient** — read this plan, `SCHEMA.md`, the backlog, and the gold-standard cell (`kb/jazz/guitar.js`, the first one built).
|
||||
2. **Claim** — take the first `todo` cell, mark it `in-progress`.
|
||||
3. **Research** — dispatch web-research agent(s) for that style × instrument: the style's standard progressions (cross-check against `docs/progression-repertoire.md`), the 2-3 idiomatic intermediate ways to play each, comping rhythms, improv approach. Named sources required.
|
||||
4. **Author** — write `progressions.js` (if the style is new) and the instrument pack, conforming to SCHEMA.md.
|
||||
5. **Validate** — run `node scripts/validate-kb.mjs`; fix until green; run the musician checklist.
|
||||
6. **Integrate** — register the style in `kb/index.js`; `npm run build` must pass.
|
||||
7. **Record** — mark the cell `done` with date + coverage stats in the backlog; commit (`kb: add <style> <instrument> pack`).
|
||||
8. **Report** — summarize what was added and name the next cell.
|
||||
|
||||
**Session 0 (bootstrap):** if `src/data/kb/`, `SCHEMA.md`, or the validator don't exist yet, the first session builds them *plus* the jazz/guitar gold-standard cell. Every later session imitates that exemplar.
|
||||
|
||||
### How to run it
|
||||
|
||||
- One session: type **`/kb-expand`** — does exactly one cell.
|
||||
- Several in a row: `/loop /kb-expand` and let it self-pace, or run `/kb-expand` whenever there's time.
|
||||
- Review cadence: cells are individual commits on a branch — review/merge per instrument tranche if preferred.
|
||||
|
||||
30 cells ≈ 30 short sessions; guitar's 10 cells deliver user-visible value immediately because the Jam Guide reads whatever exists.
|
||||
|
||||
---
|
||||
|
||||
## 4. The Jam Guide panel (UI)
|
||||
|
||||
A large panel at the **bottom of the main scroll** — while jamming you scroll down and the current progression's playbook is laid out to fit the screen.
|
||||
|
||||
```
|
||||
┌─ JAM GUIDE ─────────────────────────────── [Guitar|Piano|Bass] [Jazz][Blues][Rock][Bossa]… ─┐
|
||||
│ Matched: ii–V–I in G major your loop: Am7 → D7 → Gmaj7 │
|
||||
│ │
|
||||
│ Am7 (ii7) D7 (V7) Gmaj7 (Imaj7) │
|
||||
│ ▼ playing now │
|
||||
│ Shells [diagram] [diagram] [diagram] root–3–7, four-to-the-bar │
|
||||
│ Drop-2 [diagram] [diagram] [diagram] top-4 strings, stays high │
|
||||
│ Triads 1-3 [diagram] [diagram] [diagram] fills between vocal lines │
|
||||
│ ───────────────────────────────────────────────────────────────────────────── │
|
||||
│ IMPROV D dorian → G mixo → G major · target the 3rds: C → F# → B · lick ▸ tab… │
|
||||
└──────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
- **Component:** `JamGuide.jsx`, mounted last in `App.jsx`; collapsed header always visible, expands to ~70vh.
|
||||
- **Inputs:** `keyInfo`, `detectedProgression`, `currentChord` — plus instrument + style selection (persisted in settings; style tabs are generated from `kb/index.js`, so the panel grows as the loop runs).
|
||||
- **Matching:** convert the detected loop to degrees relative to the key root, match against the selected style's progressions **rotation-invariantly** (same canonicalization idea as `detectRepeatingProgression`). No match → fallback: per-chord voicing alternatives from `voicings.js`, so the panel is never empty.
|
||||
- **Live sync:** the active chord column highlights using the loop-position logic in `ProgressionBanner.jsx` (`findLoopPosition` — extract it to a shared util). The player reads the *next* voicing in time, in rhythm with the band.
|
||||
- **Diagrams:** new small renderers — `ChordDiagram.jsx` (6-string × 5-fret SVG grid, consumes the shape format), `MiniPiano.jsx` (~2-octave SVG, highlights resolved recipe notes), bass patterns as degree badges (R · 3 · 5 · ♭7) over a mini string diagram. Reuse design tokens (`bg-panel`, `border-border`, accent purple for chord tones).
|
||||
- **Smart fit:** CSS grid — columns = progression chords (4–6), rows = plays; rows beyond what fits collapse behind "more ways ▾"; diagrams scale to column width; on narrow windows the grid flips to one play per row, chords scrolling horizontally.
|
||||
- **Key-aware rendering:** movable shapes get their fret position computed from the detected key; open shapes appear only when the chord's root matches; piano recipes resolve through the chord quality. All 12 keys for free, per principle 1.
|
||||
|
||||
---
|
||||
|
||||
## 5. Phases
|
||||
|
||||
| Phase | What | Outcome |
|
||||
|---|---|---|
|
||||
| 0 | Foundation: `kb/` dirs, `SCHEMA.md`, validator, backlog, `/kb-expand` skill, jazz/guitar gold standard | The loop exists and has an exemplar |
|
||||
| 1 | Jam Guide MVP: panel + matching + guitar `ChordDiagram` + live sync | jazz/guitar visible in the app while jamming |
|
||||
| 2 | Loop guitar cells: blues, rock, bossa, funk, reggae, country, R&B, gospel, pop | Full guitar guide across styles |
|
||||
| 3 | Piano: `MiniPiano` renderer + recipe resolver, loop piano cells | Second instrument live |
|
||||
| 4 | Bass: pattern renderer, loop bass cells | Third instrument live |
|
||||
| 5 | Polish: improv layer with tabs/licks, Progression Builder integration (GOAL G3), ToneGym-style tap-to-hear | Guide ↔ Builder round-trip |
|
||||
|
||||
### Success criteria
|
||||
|
||||
- During a jam, scrolling to the Jam Guide shows ≥ 3 ways to play the detected progression on the selected instrument, in the detected key, with the active chord highlighted in time.
|
||||
- `/kb-expand` completes a cell in one session with the validator green, no hand-holding.
|
||||
- A new style added by the loop appears in the UI with **zero code changes** (data + registry only).
|
||||
- An intermediate player can switch Jazz → Bossa over the same ii–V–I and see *genuinely different* voicings and rhythm guidance.
|
||||
@@ -0,0 +1,129 @@
|
||||
# Learn Curriculum — Intermediate, Jam-Ready Players
|
||||
|
||||
Research-backed training repertoire for the Learn section. Companion to [`GOAL.md`](../GOAL.md) Part 2. Audience: players who know the basics and can survive a jam — the goal is making them better *in* the jam. Not beginner material.
|
||||
|
||||
Across guitar, piano, and bass pedagogy the intermediate→advanced jump converges on four pillars: **instrument liberation** (play anything anywhere), **playing the changes** (chord-tone awareness), **ensemble skills** (space, register, pocket), and **functional ears** (hearing 1-5-6-4). The per-instrument curricula below feed both the Learn UI and the knowledgebase (see `docs/kb-plan.md`).
|
||||
|
||||
---
|
||||
|
||||
## Guitar
|
||||
|
||||
### Skill taxonomy (rough order)
|
||||
|
||||
**Tier A — Fretboard liberation**
|
||||
1. CAGED system fluency — locate any chord in 5 places instantly (Fretboard Logic, Pickup Music)
|
||||
2. Triads on string sets — major/minor triads + inversions on strings 1-3, 2-4, 3-5 (Justin Guitar Grade 5, Leavitt Vol. 2)
|
||||
3. Connecting pentatonic boxes — the box 2↔3 seam is the documented weak point
|
||||
4. Scale-over-chord mapping — seeing the chord *inside* the scale shape
|
||||
|
||||
**Tier B — Playing the changes**
|
||||
5. Chord-tone / target-note soloing — land on a chord tone on beat 1 of each change
|
||||
6. Guide tones (3rds & 7ths) — the 7th of one chord resolves to the 3rd of the next
|
||||
7. Phrasing across positions
|
||||
|
||||
**Tier C — Ensemble skills**
|
||||
8. Comping with small triad voicings — stay out of the vocalist's/keys' register
|
||||
9. Internal time — metronome on beats 2 & 4, then no click (Tomo Fujita's core emphasis)
|
||||
10. Ear-led playing — "let your ears lead you instead of your eyes" (Fujita)
|
||||
|
||||
**Tier D — Functional ears**
|
||||
11. Progression recognition by ear — track the bass line first
|
||||
12. Modal awareness — how Dorian/Mixolydian overlap shapes you already know
|
||||
13. Transcribing & daily riff-writing — the recurring plateau fix
|
||||
|
||||
### Top drills
|
||||
1. **Triad voice-leading over 12-bar blues** — only close triads on one string set; on every change move each finger to the *nearest* note of the next triad. Forces inversions + minimal-motion voice leading at once.
|
||||
2. **One-CAGED-position soloing** — improvise using only one grip's chord tones + surrounding scale notes; shift position each chorus. Welds chord, arpeggio, and scale into one visual unit.
|
||||
3. **Target-note drill** — first note after each chord change must be the 3rd (then 7ths, then 7th→3rd resolutions); pentatonic filler in between. Pure pentatonic playing suddenly "follows the changes".
|
||||
4. **Pentatonic seam drill** — ascend box 1, exit through a named seam note into box 2, etc. Shifts become melodic destinations.
|
||||
5. **Metronome on 2 & 4** — click as the snare backbeat; progress to click once per bar, then none.
|
||||
6. **Comping ladder** — comp behind a recorded soloist using only 3-string triads above fret 5, varying rhythm/dynamics, never register-clashing.
|
||||
7. **Daily progression dictation** — 10-15 min naming I-IV-V vs vi-IV-I-V vs ii-V-I from songs, bass line first.
|
||||
|
||||
### Sources
|
||||
Fretboard Logic (Bill Edwards) · Justin Guitar Grades 4–6 · Tomo Fujita *Accelerate Your Guitar Playing* (Berklee) · Leavitt *A Modern Method for Guitar* Vol. 2 · Absolutely Understand Guitar · Pickup Music CAGED pathway · fundamental-changes.com (guide tones) · TrueFire (box connection, plateaus) · Premier Guitar "Rhythm Rules" · zotzinguitarlessons.com (triads in 12 keys) · ToneGym / tonedear.com · stringshock.com & jazzguitartoday.com (jam etiquette)
|
||||
|
||||
---
|
||||
|
||||
## Piano / Keys
|
||||
|
||||
### Skill taxonomy (rough order)
|
||||
|
||||
**Tier 1 — Harmonic vocabulary**
|
||||
1. Triad inversions in all 12 keys — grab any chord near the current hand position
|
||||
2. Voice leading — minimum-distance inversion choice; the biggest "amateur → pro" jump
|
||||
3. Shell voicings (root–3–7) — light, clear, gateway to comping (Open Studio, PianoGroove)
|
||||
4. Sus2/sus4/add9 colors and slash chords — pop/worship vocabulary
|
||||
5. Rootless voicings — Type A (3-5-7-9), Type B (7-9-3-5); top note between C4–C5
|
||||
|
||||
**Tier 2 — Rhythm & ensemble role**
|
||||
6. Comping rhythms — Charleston, reverse Charleston, Red Garland pattern, anticipations
|
||||
7. Register discipline — LH stays above ~G3 when a bassist is present
|
||||
8. Density discipline ("rule of 1") — in a 5-piece band, play 1/5 of the music
|
||||
9. Hand-role splitting — LH harmony/groove anchor, RH color and answers
|
||||
|
||||
**Tier 3 — Functional/ear skills**
|
||||
10. Thinking in numbers (Nashville Number System / Roman numerals)
|
||||
11. Progression recognition by ear — bass line + emotional flow of each degree
|
||||
12. Transposition fluency — known songs in all 12 keys via the number method
|
||||
13. Sight-comping — realize an unfamiliar lead sheet at tempo (Berklee keyboard method)
|
||||
|
||||
**Tier 4 — Bandstand**
|
||||
14. Form-keeping under pressure — never lose bar 1
|
||||
15. Improvising over changes — chord tones → pentatonics → scale tones
|
||||
16. Repertoire in 2-3 keys from memory
|
||||
|
||||
### Top drills
|
||||
1. **Voice-led progression loop in 12 keys** — I–V–vi–IV with minimum hand movement (C → G/B → Am → F/A), through the circle of fifths. Self-grading: you can see and hear when you jump.
|
||||
2. **Shell ii–V–I cycle** — root+3+7 through all keys, alternating types so 3rds/7ths swap and resolve by half-step. The core voice-leading mechanic made physical.
|
||||
3. **Charleston metronome ladder** — one syncopation pattern to automaticity at 80→160 BPM; comping failure in jams is usually rhythmic, not harmonic.
|
||||
4. **Backing-track subtraction** — chorus 1 whole notes only; chorus 2 LH only above G3, no roots; chorus 3 RH colors only; chorus 4 two hits per bar. Simulates bandmates occupying frequency space.
|
||||
5. **Bass-line ear training** — hum the bass note of each chord in a pop song, convert to numbers, play it.
|
||||
6. **One song, twelve keys** — number-chart a known song, new key daily.
|
||||
7. **Cold lead-sheet sight-comping** — slow metronome, once through the form, never stopping. Rehearses the actual jam failure mode.
|
||||
|
||||
### Sources
|
||||
Berklee Online Keyboard Method · Mark Levine *The Jazz Piano Book* · Open Studio Piano Pathway · PianoGroove (rootless voicings, comping) · The Jazz Piano Site (jam prep) · Piano With Jonny (voicings, transposing) · Jens Larsen (comping rhythms) · Pianote (band guide, NNS) · Worship Online / Musicademy / Sweetwater (band role) · ToneDear / ToneGym / Musical U / trainear.com (ear training)
|
||||
|
||||
---
|
||||
|
||||
## Bass
|
||||
|
||||
### Skill taxonomy (rough order)
|
||||
1. Fretboard zone mastery — every note to fret 12, lines through each zone (Friedland)
|
||||
2. Root-fifth-octave vocabulary — the "safe but musical" jam fallback
|
||||
3. Chord-tone fluency — R-3-5-7 of maj/min/dom/m7♭5 anywhere (TalkingBass: chord tones *before* scales)
|
||||
4. Scale-tone vs chord-tone discrimination — outline on strong beats, connect on weak
|
||||
5. Approach-note technique — chromatic from above/below, W|H|H walkup, dominant approach
|
||||
6. Walking bass construction — root on 1, chord tones on 1 & 3, approach into the next root on 4
|
||||
7. Subdivision command — straight 8ths / swing / shuffle / 16th funk, switching mid-groove
|
||||
8. Pocket / drummer lock — kick matching, ghost notes, dynamic mirroring
|
||||
9. Functional ear training — root movement, I/IV/V/vi by function
|
||||
10. Real-time harmonic prediction — the V "pushes home", reacting within one pass of the form
|
||||
11. Dynamics, touch, space — most cited intermediate→pro separator
|
||||
12. Fills and form awareness — fills at bars 4/8 phrase boundaries
|
||||
|
||||
### Top drills
|
||||
1. **Root-only song stripping** — play only the root of each change by ear; add 5ths and octaves on later passes. Strips songs to harmonic skeleton.
|
||||
2. **Arpeggiate the progression** — R-3-5(-7) over I-V-vi-IV in several keys, then inversions, then other neck zones.
|
||||
3. **W|H|H chromatic walkup** — between chords a 4th apart: root, whole, half, half (C-D-E♭-E→F). Formulaic forward motion that telegraphs the next chord.
|
||||
4. **Walking 12-bar / 1-6-2-5 loop** — a decision every beat about chord vs passing tone (Friedland, SBL 5-step formula).
|
||||
5. **2-bar loop challenge** — one groove for 5+ minutes changing only tone/dynamics/note length. Pocket training; exposes drift.
|
||||
6. **Subdivision switching** — 2 bars 8ths / 2 bars 16ths at 60-80 BPM; click on 2&4 only; mute the click 4 bars and check.
|
||||
7. **Sing-then-play root movement** — sing the roots before touching the bass, then 3rds/5ths/7ths.
|
||||
|
||||
### Sources
|
||||
Scott's Bass Lessons (Players Path, Groove Trainer) · TalkingBass Chord Tone Essentials · Ed Friedland *Building Walking Bass Lines* · Hal Leonard Bass Method · Berklee Practice Method: Bass · Bass Musician Magazine (drummer lock) · Premier Guitar (jam survival) · StudyBass · Learn Jazz Standards · Jazz Night School (chromatic 4) · onlinebasscourses.com · Functional Ear Trainer
|
||||
|
||||
---
|
||||
|
||||
## How the app supports this (detection-powered training)
|
||||
|
||||
These map to GOAL.md L1–L4; the app's unfair advantage is that it *hears* the player.
|
||||
|
||||
1. **Target-note highlighting** — on each detected chord change, flash the new chord's 3rd/7th on the fretboard/piano (guitar drill 3, piano drill 2). Later: score whether the first detected note after the change was a chord tone.
|
||||
2. **Voice-leading coach (piano view)** — highlight the *nearest inversion* to the previous chord, common tones marked "hold"; score total semitone travel per progression.
|
||||
3. **Next-chord preview tier (bass)** — when a loop is detected, highlight the upcoming chord's root plus its chromatic approach notes a half-step above/below — the walking-line scaffold, one beat ahead.
|
||||
4. **Progression ear-trainer on your own jam** — hide the chord banner, ask for the numbers (vi-IV-I-V), reveal. Uses chord history + `toRomanNumeral`; contextual beats abstract drills.
|
||||
5. **Pocket report** — extend the onset/BPM histogram to show beat-phase drift (rushing/dragging), plus a 2-&-4-only click synced to the detected tempo.
|
||||
6. **Mode-difference teaching** — when the user manually switches mode (the K-S limitation), briefly highlight the difference notes (minor → Dorian = raised 6th).
|
||||
@@ -0,0 +1,149 @@
|
||||
# Chord Progression Repertoire
|
||||
|
||||
Research-backed reference for expanding the progression features. Companion to [`GOAL.md`](../GOAL.md) Part 1. Notation: uppercase = major, lowercase = minor, ° = diminished, 7 = dominant unless marked maj7/m7.
|
||||
|
||||
How this maps to code today:
|
||||
|
||||
- `PROGRESSIONS` in `src/lib/theory.js` — `{ name, rn, degrees }` per progression; `degrees` are semitone offsets from the key root. This is the format new entries should use.
|
||||
- `getSuggestedProgressions(root, mode)` maps degrees → chord names in key; `toRomanNumeral()` converts any chord back to a numeral.
|
||||
- `FAMOUS_PROGRESSIONS` in `src/lib/education.js` — richer entries (songs, tips, style variations) for the Learn side.
|
||||
|
||||
## 1. Genre-by-genre progression tables
|
||||
|
||||
### Pop
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I–V–vi–IV | "Axis of Awesome" — #1 in Hooktheory's corpus of 75k+ analyzed songs |
|
||||
| vi–IV–I–V | Same loop rotated to start on vi ("pessimistic axis") |
|
||||
| I–vi–IV–V | "Doo-wop" / "'50s progression" |
|
||||
| I–IV–vi–V | Common variant (Africa chorus) |
|
||||
| IV–V–iii–vi | "Royal Road" — J-pop/anime staple, spreading into Western pop |
|
||||
|
||||
### Rock
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I–IV–V | Foundation of rock/blues/country |
|
||||
| I–♭VII–IV(–I) | Mixolydian rock cliché (Sweet Home Alabama as V–IV–I rotation) |
|
||||
| i–♭VII–♭VI(–V) | Andalusian-derived minor loop; with V = full Andalusian cadence |
|
||||
| I–♭III–IV | Blues-rock riff progression (borrowed ♭III) |
|
||||
|
||||
### Blues (12-bar family)
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I7×4 / IV7×2, I7×2 / V7, IV7, I7, V7 | Standard 12-bar |
|
||||
| Bar 2 → IV7 | "Quick change" / "quick four" |
|
||||
| ii7–V7 in bars 9–10, turnaround I–VI7–ii–V7 | Jazz blues |
|
||||
| i7–iv7–i7 … ♭VI7–V7–i7 | Minor blues (The Thrill Is Gone) |
|
||||
| I–V–IV–IV–I–V–I–V | 8-bar blues (Key to the Highway) |
|
||||
|
||||
### Jazz
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| ii7–V7–Imaj7 | The fundamental cadence |
|
||||
| I–vi–ii–V (also iii–vi–ii–V) | Rhythm changes A / turnaround |
|
||||
| III7–VI7–II7–V7 | Rhythm changes bridge (circle of dominants) |
|
||||
| iim7♭5–V7♭9–i | Minor ii–V–i |
|
||||
| ii7–♭II7–Imaj7 | Tritone-sub cadence |
|
||||
| ivm7–♭VII7–Imaj7 | "Backdoor" progression |
|
||||
|
||||
### Folk / Country
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I–IV–V(–I) | Core of both genres |
|
||||
| I–V–I–IV | Two/three-chord verse pattern |
|
||||
| i–♭VII–♭VI | Minor folk descent (Am–G–F) |
|
||||
| I–V–vi–iii–IV–I–IV–V | Pachelbel progression |
|
||||
| I–II7–V–I | Classic country secondary-dominant (V/V) move |
|
||||
|
||||
### Funk
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I7 vamp | James Brown static dominant, voiced as 9th |
|
||||
| i7–IV7 | Dorian two-chord vamp — the most common funk pair |
|
||||
| i7 / m11 vamp | Minor one-chord groove |
|
||||
| ii7–V7 loop | Funk/disco vamp |
|
||||
|
||||
Design insight: funk needs few *progressions* but rich *chord qualities* (9, 7♯9, m11, 13sus) — colour lives in the voicing, not the changes.
|
||||
|
||||
### Reggae
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| I–V or I–IV | Two-chord skank vamps |
|
||||
| I–V–vi–IV | No Woman No Cry |
|
||||
| i–♭VII(–♭VI) | Minor roots-reggae vamp |
|
||||
| I–IV–V | Ska/rocksteady standard |
|
||||
|
||||
### R&B / Neo-soul
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| ii7–V7–Imaj7 (with 9/11/13 extensions) | Core cadence |
|
||||
| iii7–vi7–ii7–V7 | Circle movement from the mediant — neo-soul staple |
|
||||
| vi–ii–V–I | "6-2-5-1" cyclical soul loop |
|
||||
| Imaj7–IVmaj7 / Imaj7–iii7 | Two-chord vamps |
|
||||
| i7–iv7 | Dorian D'Angelo-style minor vamp |
|
||||
|
||||
### Gospel
|
||||
| Progression | Name / notes |
|
||||
|---|---|
|
||||
| ii7–V7–I | The gospel "2-5-1", often chained: 6-2-5-1, 3-6-2-5-1 |
|
||||
| I–I7–IV | Tonicizing IV (V7/IV "amen" setup) |
|
||||
| IV–iv–I | Plagal with borrowed iv |
|
||||
| I–♯i°–ii | Chromatic passing-diminished walk-up |
|
||||
|
||||
## 2. Substitution / variation taxonomy
|
||||
|
||||
Progression "families" relate through a small set of transforms — these are the generation rules for variation buttons and the Builder:
|
||||
|
||||
1. **Rotation** — any loop can start on any chord (I–V–vi–IV ≡ vi–IV–I–V). Treat loops as cyclic equivalence classes; display the rotation matching the user's tonic emphasis. (`detectRepeatingProgression` already canonicalizes rotations.)
|
||||
2. **Diatonic (function) substitution** — chords sharing two notes swap: I↔vi↔iii (tonic), IV↔ii (subdominant), V↔vii° (dominant).
|
||||
3. **Modal interchange / borrowing** — take a chord from the parallel mode: iv, ♭VI, ♭VII, ♭III, iim7♭5 in major; major IV (Dorian) in minor.
|
||||
4. **Secondary dominants** — precede any diatonic target with its V7: V/V = II7, V/vi = III7, V/IV = I7, V/ii = VI7.
|
||||
5. **Tritone substitution** — replace any dominant with the dominant a tritone away (V7 → ♭II7). Jazz flavour flag.
|
||||
6. **Backdoor dominant** — ♭VII7 resolving to I, usually as ivm7–♭VII7–I.
|
||||
7. **Quality embellishment** — same root, richer colour: triad → 7th → 9/11/13, sus2/4, add9. The main axis distinguishing genres (pop = triads/sus, jazz/neo-soul/gospel = extensions, funk = dominant 9/♯9). Already partially covered by `CHORD_SUBSTITUTIONS` in `education.js`.
|
||||
8. **Passing/approach chords** — chromatic passing diminished (I–♯i°–ii), bass-line inversions (slash chords).
|
||||
|
||||
## 3. UX patterns worth copying
|
||||
|
||||
- **Hookpad (Hooktheory)** — *key-relative chord palette*: only the diatonic chords of the current key, colour-coded consistently per scale degree (key-agnostic colours). Borrowed chords live in expandable secondary palettes. *Magic Chord* suggests the statistically likeliest next chord. Drag-and-drop onto a timeline. → Direct model for the Progression Builder (GOAL G3).
|
||||
- **Hooktheory TheoryTab** — progressions ranked by real-song frequency; each links to songs using it. "You're playing the Creep progression" is a strong engagement hook (partially exists via `FAMOUS_PROGRESSIONS` song lists).
|
||||
- **Scaler 2/3** — three-zone vertical flow: detection area (top) → suggested chords/scales (middle) → user-built progression (bottom). Maps directly onto this app: live detection → suggestions → builder.
|
||||
- **iReal Pro** — one-tap transposition; per-genre rendering of the same progression.
|
||||
- **ToneGym** — instant audio preview when tapping any chord/progression.
|
||||
|
||||
## 4. Voicing data
|
||||
|
||||
### Guitar
|
||||
Best option found: [`tombatossals/chords-db`](https://github.com/tombatossals/chords-db) (MIT, npm `@tombatossals/chords-db`, prebuilt `lib/guitar.json`):
|
||||
- All 12 keys × large suffix list, **multiple positions per chord** (open + barre + higher CAGED positions).
|
||||
- Per position: `frets` (per string, `x` = mute, low-E first), `fingers`, optional `barres`, `baseFret`. Example: `{ frets: '55775x', fingers: '114310', barres: 5 }`.
|
||||
- Companion renderer: [`tombatossals/react-chords`](https://github.com/tombatossals/react-chords) (React SVG diagrams consuming this format).
|
||||
|
||||
Triads on string-sets (top-3 / middle-3) are *not* in chords-db but are cheap to generate: for each inversion of the triad, map the 3 chord tones onto a chosen string set within a 4-fret window. This complements the existing `GUITAR_SHAPES` in `src/lib/voicings.js`.
|
||||
|
||||
### Piano
|
||||
No canonical open dataset exists. The sane model is **interval recipes resolved per chord quality** (the chord templates in `theory.js` already encode quality → semitone mapping):
|
||||
|
||||
```js
|
||||
// voicing = named recipe of chord degrees, resolved per chord quality
|
||||
{
|
||||
shell: { LH: ['1', '7'], RH: ['3'] },
|
||||
rootPosition: { LH: ['1'], RH: ['1', '3', '5', '7'] },
|
||||
rootlessA: { LH: ['3', '5', '7', '9'] }, // Type A: 3rd on bottom
|
||||
rootlessB: { LH: ['7', '9', '3', '5'] }, // Type B: 7th on bottom
|
||||
guideTones: { LH: ['3', '7'] },
|
||||
}
|
||||
```
|
||||
|
||||
Conventions to encode: rootless voicings keep the top note between C4–C5; alternate Type A/B through a progression so inner voices barely move — i.e. pick the voicing minimizing semitone travel from the previous chord (simple voice-leading distance minimization).
|
||||
|
||||
## 5. Sources
|
||||
|
||||
- Hooktheory corpus & blog: hooktheory.com/blog/i-analyzed-the-chords-of-1300-popular-songs-for-patterns-this-is-what-i-found/ ; hooktheory.com/blog/jazz-chord-progressions/
|
||||
- 12-bar variants: en.wikipedia.org/wiki/Twelve-bar_blues ; happybluesman.com/common-variations-12-bar-blues/
|
||||
- Named progressions: en.wikipedia.org/wiki/%2750s_progression ; piano.org/chord-progressions/ ; supersimplepiano.com/learn/chord-progressions/royal-road
|
||||
- Substitutions: learnjazzstandards.com (chord substitution) ; hub.yamaha.com (beyond diatonic) ; hubguitar.com (tritone subs)
|
||||
- Gospel: gospelmaps.com/top-gospel-chord-progressions/ ; gospel.hearandplay.com (2-5-1)
|
||||
- Genre vamps: orphiq.com (reggae) ; guitar-chord.org/articles/funk.html ; orangecandymusic.com & pickupmusic.com (R&B/neo-soul)
|
||||
- Tools: producelikeapro.com (Scaler review) ; hooktheory.com/hookpad
|
||||
- Voicing data: github.com/tombatossals/chords-db ; github.com/tombatossals/react-chords ; voicinglab.com & pianowithjonny.com & thejazzpianosite.com (rootless voicings)
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.device.audio-input</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-jit</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,55 @@
|
||||
const { app, BrowserWindow, systemPreferences } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
const isDev = !app.isPackaged
|
||||
|
||||
async function handlePermissions() {
|
||||
// macOS requires an explicit native request for microphone access in packaged apps
|
||||
if (process.platform === 'darwin') {
|
||||
try {
|
||||
const status = systemPreferences.getMediaAccessStatus('microphone')
|
||||
if (status !== 'granted') {
|
||||
await systemPreferences.askForMediaAccess('microphone')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Main] Microphone permission error:', err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 1280,
|
||||
height: 900,
|
||||
minWidth: 620,
|
||||
minHeight: 600,
|
||||
title: 'WhatTheFlat ♭? - JamBuddy',
|
||||
icon: path.join(__dirname, '../assets/whattheflat-logo.png'),
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: false, // allows renderer getUserMedia to work on all platforms
|
||||
},
|
||||
})
|
||||
|
||||
if (isDev) {
|
||||
win.loadURL('http://localhost:5173')
|
||||
win.webContents.openDevTools()
|
||||
} else {
|
||||
win.loadFile(path.join(__dirname, '../dist/index.html'))
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
await handlePermissions()
|
||||
createWindow()
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
// Preload runs in a privileged context before the renderer.
|
||||
// Expose only what the app actually needs from Node/Electron here.
|
||||
// Currently the app is pure browser JS so nothing needs exposing.
|
||||
const { contextBridge } = require('electron')
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
platform: process.platform,
|
||||
})
|
||||
@@ -1,12 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>WhatTheFlat</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "whattheflat-frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"pitchy": "^4.1.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.3.1",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"postcss": "^8.4.47",
|
||||
"tailwindcss": "^3.4.14",
|
||||
"vite": "^5.4.10"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react'
|
||||
import AudioCapture from './components/AudioCapture'
|
||||
import ProgressionBanner from './components/ProgressionBanner'
|
||||
import KeyDisplay from './components/KeyDisplay'
|
||||
import ChordDisplay from './components/ChordDisplay'
|
||||
import SafeNotes from './components/SafeNotes'
|
||||
import Fretboard from './components/Fretboard'
|
||||
import ProgressionSuggestions from './components/ProgressionSuggestions'
|
||||
import ChatAssistant from './components/ChatAssistant'
|
||||
import { NOTES, detectKey, matchChordFromChroma, detectRepeatingProgression } from './lib/theory'
|
||||
|
||||
// Key detection tuning
|
||||
const NOTE_HISTORY_SIZE = 80
|
||||
const KEY_VOTE_WINDOW = 12
|
||||
const KEY_VOTE_THRESHOLD = 9 // out of 12 — very stable
|
||||
|
||||
// Chord detection tuning
|
||||
const CHROMA_SMOOTH = 12 // frames to average (~200ms at 60fps)
|
||||
const CHORD_VOTE_THRESHOLD = 3 // consecutive identical detections required
|
||||
|
||||
export default function App() {
|
||||
// ── Listening state ──────────────────────────────────────────────────────
|
||||
const [isListening, setIsListening] = useState(false)
|
||||
|
||||
// ── App mode ─────────────────────────────────────────────────────────────
|
||||
const [appMode, setAppMode] = useState('beginner') // 'beginner' | 'advanced'
|
||||
|
||||
// ── Key: auto-detected + optional lock ───────────────────────────────────
|
||||
const [keyInfo, setKeyInfo] = useState(null) // auto-detected
|
||||
const [lockedKey, setLockedKey] = useState(null) // { root, mode } or null
|
||||
const [lockRoot, setLockRoot] = useState('A')
|
||||
const [lockMode, setLockMode] = useState('minor')
|
||||
|
||||
// Effective key used by all components
|
||||
const effectiveKey = lockedKey ?? keyInfo
|
||||
// Locked key = only match diatonic chords regardless of mode — far fewer candidates
|
||||
const isStrictMode = lockedKey !== null
|
||||
|
||||
// ── Chord state ───────────────────────────────────────────────────────────
|
||||
const [chordHistory, setChordHistory] = useState([])
|
||||
const [detectedProgression, setDetectedProgression] = useState(null)
|
||||
|
||||
// ── Internal refs ─────────────────────────────────────────────────────────
|
||||
const noteHistoryRef = useRef([])
|
||||
const keyVotesRef = useRef([])
|
||||
const effectiveKeyRef = useRef(null) // mirror for use inside callbacks
|
||||
const chromaRingRef = useRef(
|
||||
Array.from({ length: CHROMA_SMOOTH }, () => new Float32Array(12))
|
||||
)
|
||||
const chromaIdxRef = useRef(0)
|
||||
const chordVotesRef = useRef([])
|
||||
|
||||
// Keep ref in sync
|
||||
useEffect(() => { effectiveKeyRef.current = effectiveKey }, [effectiveKey])
|
||||
|
||||
// ── Detect progression whenever chord history changes ─────────────────────
|
||||
useEffect(() => {
|
||||
setDetectedProgression(detectRepeatingProgression(chordHistory))
|
||||
}, [chordHistory])
|
||||
|
||||
// ── Key lock handlers ─────────────────────────────────────────────────────
|
||||
function applyLock() {
|
||||
const info = { root: lockRoot, mode: lockMode, confidence: 1 }
|
||||
setLockedKey(info)
|
||||
effectiveKeyRef.current = info
|
||||
chordVotesRef.current = []
|
||||
setChordHistory([])
|
||||
setDetectedProgression(null)
|
||||
}
|
||||
|
||||
function removeLock() {
|
||||
setLockedKey(null)
|
||||
effectiveKeyRef.current = keyInfo
|
||||
}
|
||||
|
||||
// ── Note handler: drives key detection (pitch-based) ──────────────────────
|
||||
const handleNote = useCallback(({ pitchClass }) => {
|
||||
const history = noteHistoryRef.current
|
||||
history.push(pitchClass)
|
||||
if (history.length > NOTE_HISTORY_SIZE) history.shift()
|
||||
if (history.length < 10) return
|
||||
if (history.length % 5 !== 0) return
|
||||
|
||||
const result = detectKey(history)
|
||||
if (result.confidence < 0.5) return
|
||||
|
||||
const votes = keyVotesRef.current
|
||||
votes.push(`${result.root}_${result.mode}`)
|
||||
if (votes.length > KEY_VOTE_WINDOW) votes.shift()
|
||||
|
||||
const counts = {}
|
||||
for (const v of votes) counts[v] = (counts[v] || 0) + 1
|
||||
const [winner, count] = Object.entries(counts).sort((a, b) => b[1] - a[1])[0]
|
||||
|
||||
if (count >= KEY_VOTE_THRESHOLD) {
|
||||
const [root, mode] = winner.split('_')
|
||||
setKeyInfo(prev => {
|
||||
if (prev?.root === root && prev?.mode === mode) {
|
||||
return { root, mode, confidence: result.confidence }
|
||||
}
|
||||
// Key changed — reset chord votes but keep history visible
|
||||
if (!lockedKey) {
|
||||
chordVotesRef.current = []
|
||||
}
|
||||
return { root, mode, confidence: result.confidence }
|
||||
})
|
||||
}
|
||||
}, [lockedKey])
|
||||
|
||||
// ── Chroma handler: drives chord detection ────────────────────────────────
|
||||
const handleChroma = useCallback((chroma, bassPC) => {
|
||||
const ring = chromaRingRef.current
|
||||
ring[chromaIdxRef.current % CHROMA_SMOOTH] = chroma
|
||||
chromaIdxRef.current++
|
||||
if (chromaIdxRef.current % CHROMA_SMOOTH !== 0) return
|
||||
|
||||
const key = effectiveKeyRef.current
|
||||
if (!key) return
|
||||
|
||||
// Average ring buffer
|
||||
const avg = new Float32Array(12)
|
||||
for (const frame of ring) for (let i = 0; i < 12; i++) avg[i] += frame[i]
|
||||
for (let i = 0; i < 12; i++) avg[i] /= CHROMA_SMOOTH
|
||||
|
||||
const chord = matchChordFromChroma(avg, key, bassPC, isStrictMode)
|
||||
if (!chord) {
|
||||
// Ambiguous moment (transition, silence) — reset streak, history is untouched
|
||||
chordVotesRef.current = []
|
||||
return
|
||||
}
|
||||
|
||||
const votes = chordVotesRef.current
|
||||
votes.push(chord)
|
||||
if (votes.length > CHORD_VOTE_THRESHOLD) votes.shift()
|
||||
|
||||
// All last N detections must agree — one wrong reading resets the streak
|
||||
if (votes.length >= CHORD_VOTE_THRESHOLD && votes.every(v => v === votes[0])) {
|
||||
const winner = votes[0]
|
||||
setChordHistory(prev => {
|
||||
if (prev[prev.length - 1] === winner) return prev
|
||||
return [...prev.slice(-30), winner]
|
||||
})
|
||||
}
|
||||
}, [isStrictMode])
|
||||
|
||||
const currentChord = chordHistory[chordHistory.length - 1]
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-surface text-white p-4 md:p-6">
|
||||
|
||||
{/* ── Header ── */}
|
||||
<header className="mb-4 flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-accent">
|
||||
WhatTheFlat <span className="text-gray-600">♭?</span>
|
||||
</h1>
|
||||
<p className="text-xs text-gray-600 mt-0.5">Real-time key detection for real humans</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setIsListening(l => !l)}
|
||||
className={`px-5 py-2.5 rounded-full font-semibold text-sm transition-all ${
|
||||
isListening
|
||||
? 'bg-red-600 hover:bg-red-700 text-white'
|
||||
: 'bg-accent hover:bg-purple-600 text-white'
|
||||
}`}
|
||||
>
|
||||
{isListening ? 'Stop' : 'Start Listening'}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{/* ── Controls bar ── */}
|
||||
<div className="mb-4 flex flex-wrap gap-3 items-center p-3 bg-panel border border-border rounded-xl">
|
||||
{/* Mode toggle */}
|
||||
<div className="flex bg-surface border border-border rounded-full p-0.5 text-sm">
|
||||
{['beginner', 'advanced'].map(m => (
|
||||
<button
|
||||
key={m}
|
||||
onClick={() => setAppMode(m)}
|
||||
className={`px-4 py-1 rounded-full capitalize transition-all ${
|
||||
appMode === m ? 'bg-accent text-white' : 'text-gray-400 hover:text-gray-200'
|
||||
}`}
|
||||
>
|
||||
{m}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Key lock */}
|
||||
{lockedKey ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="px-3 py-1 bg-accent/20 border border-accent text-accent rounded-full text-sm font-semibold">
|
||||
🔒 {lockedKey.root} {lockedKey.mode}
|
||||
</span>
|
||||
<button
|
||||
onClick={removeLock}
|
||||
className="text-xs text-gray-500 hover:text-gray-300 underline"
|
||||
>
|
||||
unlock
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2 items-center">
|
||||
<select
|
||||
value={lockRoot}
|
||||
onChange={e => setLockRoot(e.target.value)}
|
||||
className="bg-surface border border-border rounded-lg px-2 py-1 text-sm text-gray-300"
|
||||
>
|
||||
{NOTES.map(n => <option key={n}>{n}</option>)}
|
||||
</select>
|
||||
<select
|
||||
value={lockMode}
|
||||
onChange={e => setLockMode(e.target.value)}
|
||||
className="bg-surface border border-border rounded-lg px-2 py-1 text-sm text-gray-300"
|
||||
>
|
||||
<option value="major">Major</option>
|
||||
<option value="minor">Minor</option>
|
||||
</select>
|
||||
<button
|
||||
onClick={applyLock}
|
||||
className="px-3 py-1 bg-border hover:bg-accent/20 border border-border hover:border-accent text-sm rounded-lg transition-all"
|
||||
>
|
||||
Lock Key
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Auto-detected key badge (advanced mode) */}
|
||||
{appMode === 'advanced' && keyInfo && !lockedKey && (
|
||||
<span className="text-xs text-gray-500">
|
||||
auto: {keyInfo.root} {keyInfo.mode} ({Math.round(keyInfo.confidence * 100)}%)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<AudioCapture onNote={handleNote} onChroma={handleChroma} isListening={isListening} />
|
||||
|
||||
{/* ── Progression banner — full width ── */}
|
||||
<ProgressionBanner
|
||||
chordHistory={chordHistory}
|
||||
keyInfo={effectiveKey}
|
||||
detectedProgression={detectedProgression}
|
||||
/>
|
||||
|
||||
{/* ── Main grid ── */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<KeyDisplay keyInfo={effectiveKey} locked={!!lockedKey} />
|
||||
<ChordDisplay history={chordHistory} />
|
||||
<SafeNotes keyInfo={effectiveKey} currentChord={currentChord} />
|
||||
<ProgressionSuggestions keyInfo={effectiveKey} />
|
||||
<div className="md:col-span-2">
|
||||
<Fretboard
|
||||
keyInfo={effectiveKey}
|
||||
currentChord={currentChord}
|
||||
pentatonicOnly={appMode === 'beginner'}
|
||||
/>
|
||||
</div>
|
||||
<div className="md:col-span-2">
|
||||
<ChatAssistant keyInfo={effectiveKey} currentChord={currentChord} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import { useEffect, useRef, useCallback } from 'react'
|
||||
import { PitchDetector } from 'pitchy'
|
||||
import { NOTES } from '../lib/theory'
|
||||
|
||||
// ─── Why two analysers? ───────────────────────────────────────────────────────
|
||||
//
|
||||
// The Web Audio FFT has linearly-spaced bins: bin width = sampleRate / fftSize.
|
||||
//
|
||||
// fftSize 4096 → ~10.8 Hz/bin (default we were using)
|
||||
// fftSize 16384 → ~2.7 Hz/bin (multi-rate chord analyser)
|
||||
//
|
||||
// On the low guitar strings the gap between adjacent semitones is only ~5-6 Hz.
|
||||
// At 10.8 Hz/bin we literally cannot separate A2 (110 Hz) from A#2 (116 Hz).
|
||||
// That is the single biggest source of wrong chord notes on the low strings.
|
||||
//
|
||||
// Solution: run a second, larger analyser just for chord/chroma detection.
|
||||
// The pitch analyser stays small (4096) so pitchy has a 90ms window — fast
|
||||
// enough for responsive pitch detection. The chord analyser uses 16384 (~370ms
|
||||
// window) — slower to respond but with 2.7 Hz bins that can cleanly separate
|
||||
// every semitone across the guitar's entire range.
|
||||
//
|
||||
// This is an approximation of the Constant-Q Transform (CQT) your friend
|
||||
// mentioned: CQT achieves log-spaced bins mathematically; we approximate it
|
||||
// by simply using a much larger FFT window.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PITCH_FFT = 4096 // ~90ms window — good temporal resolution for pitch
|
||||
const CHORD_FFT = 16384 // ~370ms window — 2.7 Hz/bin, separates low semitones
|
||||
const MIN_CLARITY = 0.80
|
||||
const MIN_VOLUME = 0.01
|
||||
const NOISE_FLOOR = -65 // dB
|
||||
|
||||
// ─── Harmonic summation chroma ────────────────────────────────────────────────
|
||||
// Each FFT bin votes back toward lower fundamentals that could have generated
|
||||
// it as an overtone. This undoes the harmonic contamination that makes minor
|
||||
// chords look like major ones (the 5th harmonic of the root lands on the major
|
||||
// 3rd, which is NOT in the minor chord).
|
||||
const HARMONIC_WEIGHTS = [1.0, 0.5, 0.33, 0.25, 0.2] // h = 1…5
|
||||
|
||||
function computeChroma(freqData, sampleRate, fftSize) {
|
||||
const chroma = new Float32Array(12)
|
||||
const binHz = sampleRate / fftSize
|
||||
const N = freqData.length
|
||||
|
||||
for (let bin = 2; bin < N; bin++) {
|
||||
const freq = bin * binHz
|
||||
if (freq < 80 || freq > 4000) continue
|
||||
const db = freqData[bin]
|
||||
if (db < NOISE_FLOOR) continue
|
||||
|
||||
const amp = Math.sqrt(Math.pow(10, db / 10)) // amplitude, not power
|
||||
|
||||
for (let h = 1; h <= HARMONIC_WEIGHTS.length; h++) {
|
||||
const fundamental = freq / h
|
||||
if (fundamental < 40 || fundamental > 2000) continue
|
||||
const midi = 12 * Math.log2(fundamental / 440) + 69
|
||||
const pc = ((Math.round(midi) % 12) + 12) % 12
|
||||
chroma[pc] += amp * HARMONIC_WEIGHTS[h - 1]
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < 12; i++) chroma[i] = Math.log1p(chroma[i])
|
||||
const max = Math.max(...chroma)
|
||||
if (max > 0) for (let i = 0; i < 12; i++) chroma[i] /= max
|
||||
return chroma
|
||||
}
|
||||
|
||||
function detectBassPC(freqData, sampleRate, fftSize) {
|
||||
const binHz = sampleRate / fftSize
|
||||
let maxPower = 0, bestMidi = -1
|
||||
for (let bin = 2; bin < freqData.length; bin++) {
|
||||
const freq = bin * binHz
|
||||
if (freq < 40 || freq > 350) continue
|
||||
const db = freqData[bin]
|
||||
if (db < NOISE_FLOOR) continue
|
||||
const power = Math.pow(10, db / 10)
|
||||
if (power > maxPower) {
|
||||
maxPower = power
|
||||
bestMidi = Math.round(12 * Math.log2(freq / 440) + 69)
|
||||
}
|
||||
}
|
||||
if (bestMidi < 0) return null
|
||||
return ((bestMidi % 12) + 12) % 12
|
||||
}
|
||||
|
||||
export default function AudioCapture({ onNote, onChroma, isListening }) {
|
||||
const audioCtxRef = useRef(null)
|
||||
const pitchAnalyser = useRef(null)
|
||||
const chordAnalyser = useRef(null)
|
||||
const timeBufRef = useRef(null)
|
||||
const freqBufRef = useRef(null)
|
||||
const detectorRef = useRef(null)
|
||||
const rafRef = useRef(null)
|
||||
const streamRef = useRef(null)
|
||||
|
||||
const stop = useCallback(() => {
|
||||
if (rafRef.current) cancelAnimationFrame(rafRef.current)
|
||||
if (streamRef.current) streamRef.current.getTracks().forEach(t => t.stop())
|
||||
if (audioCtxRef.current) audioCtxRef.current.close()
|
||||
audioCtxRef.current = null
|
||||
}, [])
|
||||
|
||||
const start = useCallback(async () => {
|
||||
stop()
|
||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
streamRef.current = stream
|
||||
|
||||
const ctx = new AudioContext()
|
||||
audioCtxRef.current = ctx
|
||||
const source = ctx.createMediaStreamSource(stream)
|
||||
|
||||
// Small analyser — pitch detection needs fast time-domain data
|
||||
const pa = ctx.createAnalyser()
|
||||
pa.fftSize = PITCH_FFT
|
||||
pa.smoothingTimeConstant = 0.0 // no smoothing: pitchy needs clean waveform
|
||||
pitchAnalyser.current = pa
|
||||
source.connect(pa)
|
||||
timeBufRef.current = new Float32Array(pa.fftSize)
|
||||
detectorRef.current = PitchDetector.forFloat32Array(pa.fftSize)
|
||||
|
||||
// Large analyser — chord detection needs fine frequency resolution
|
||||
const ca = ctx.createAnalyser()
|
||||
ca.fftSize = CHORD_FFT
|
||||
ca.smoothingTimeConstant = 0.65 // smooth over time for stable chord reading
|
||||
chordAnalyser.current = ca
|
||||
source.connect(ca)
|
||||
freqBufRef.current = new Float32Array(ca.frequencyBinCount)
|
||||
|
||||
function tick() {
|
||||
const timeBuf = timeBufRef.current
|
||||
pa.getFloatTimeDomainData(timeBuf)
|
||||
|
||||
const rms = Math.sqrt(timeBuf.reduce((s, v) => s + v * v, 0) / timeBuf.length)
|
||||
if (rms >= MIN_VOLUME) {
|
||||
// Pitch via McLeod (autocorrelation) — unaffected by FFT bin size
|
||||
const [freq, clarity] = detectorRef.current.findPitch(timeBuf, ctx.sampleRate)
|
||||
if (clarity >= MIN_CLARITY && freq > 60 && freq < 4200) {
|
||||
const midi = Math.round(12 * Math.log2(freq / 440) + 69)
|
||||
const pitchClass = ((midi % 12) + 12) % 12
|
||||
onNote({ noteName: NOTES[pitchClass], pitchClass, freq, midi, clarity })
|
||||
}
|
||||
|
||||
// Chord chroma from the high-resolution FFT
|
||||
if (onChroma) {
|
||||
const freqBuf = freqBufRef.current
|
||||
ca.getFloatFrequencyData(freqBuf)
|
||||
onChroma(
|
||||
computeChroma(freqBuf, ctx.sampleRate, ca.fftSize),
|
||||
detectBassPC(freqBuf, ctx.sampleRate, ca.fftSize)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
}
|
||||
tick()
|
||||
}, [onNote, onChroma, stop])
|
||||
|
||||
useEffect(() => {
|
||||
if (isListening) start().catch(console.error)
|
||||
else stop()
|
||||
return stop
|
||||
}, [isListening, start, stop])
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
|
||||
export default function ChatAssistant({ keyInfo, currentChord }) {
|
||||
const [messages, setMessages] = useState([])
|
||||
const [input, setInput] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const bottomRef = useRef(null)
|
||||
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
}, [messages])
|
||||
|
||||
async function send(e) {
|
||||
e.preventDefault()
|
||||
if (!input.trim() || loading) return
|
||||
|
||||
const userMsg = { role: 'user', content: input.trim() }
|
||||
const next = [...messages, userMsg]
|
||||
setMessages(next)
|
||||
setInput('')
|
||||
setLoading(true)
|
||||
|
||||
try {
|
||||
const context = {}
|
||||
if (keyInfo?.root) context.key = `${keyInfo.root} ${keyInfo.mode}`
|
||||
if (currentChord) context.chord = currentChord
|
||||
|
||||
const res = await fetch('/api/chat', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ messages: next, context }),
|
||||
})
|
||||
const data = await res.json()
|
||||
setMessages(prev => [...prev, { role: 'assistant', content: data.reply }])
|
||||
} catch (err) {
|
||||
setMessages(prev => [...prev, {
|
||||
role: 'assistant',
|
||||
content: 'Could not reach the AI assistant. Is the backend running?',
|
||||
}])
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6 flex flex-col h-80">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-3">Theory Assistant</p>
|
||||
<div className="flex-1 overflow-y-auto space-y-3 pr-1">
|
||||
{messages.length === 0 && (
|
||||
<p className="text-gray-600 text-sm">Ask anything: "What lick works over this chord?" or "Why does the IV sound so resolved?"</p>
|
||||
)}
|
||||
{messages.map((m, i) => (
|
||||
<div key={i} className={`text-sm ${m.role === 'user' ? 'text-right' : 'text-left'}`}>
|
||||
<span className={`inline-block px-3 py-2 rounded-xl max-w-[85%] ${
|
||||
m.role === 'user'
|
||||
? 'bg-accent text-white'
|
||||
: 'bg-border text-gray-200'
|
||||
}`}>
|
||||
{m.content}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{loading && (
|
||||
<div className="text-left">
|
||||
<span className="inline-block px-3 py-2 rounded-xl bg-border text-gray-400 text-sm animate-pulse">
|
||||
Thinking…
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
<form onSubmit={send} className="mt-3 flex gap-2">
|
||||
<input
|
||||
className="flex-1 bg-surface border border-border rounded-lg px-3 py-2 text-sm outline-none focus:border-accent"
|
||||
placeholder="Ask about music theory…"
|
||||
value={input}
|
||||
onChange={e => setInput(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading || !input.trim()}
|
||||
className="px-4 py-2 bg-accent text-white rounded-lg text-sm font-medium disabled:opacity-40"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
export default function ChordDisplay({ history }) {
|
||||
const current = history[history.length - 1]
|
||||
const past = history.slice(-8, -1)
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-3">Chord</p>
|
||||
<p className="text-5xl font-bold text-amber-400">
|
||||
{current ?? '—'}
|
||||
</p>
|
||||
{past.length > 0 && (
|
||||
<div className="mt-4 flex gap-2 flex-wrap">
|
||||
{past.map((chord, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className="text-sm px-2 py-1 bg-border rounded text-gray-400"
|
||||
>
|
||||
{chord}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
export default function KeyDisplay({ keyInfo, locked = false }) {
|
||||
const { root, mode, confidence } = keyInfo ?? {}
|
||||
const pct = confidence ? Math.round(confidence * 100) : 0
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6 text-center">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-1">
|
||||
{locked ? '🔒 Key (locked)' : 'Detected Key'}
|
||||
</p>
|
||||
{root ? (
|
||||
<>
|
||||
<p className="text-6xl font-bold text-accent leading-none">
|
||||
{root}
|
||||
<span className="text-3xl text-gray-400 ml-2">{mode}</span>
|
||||
</p>
|
||||
{!locked && (
|
||||
<div className="mt-3 flex items-center justify-center gap-2">
|
||||
<div className="h-1.5 w-32 bg-border rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-accent rounded-full transition-all duration-500"
|
||||
style={{ width: `${pct}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-gray-500">{pct}% confident</span>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="text-2xl text-gray-600 mt-2">Listening…</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
import { useRef, useEffect } from 'react'
|
||||
import { toRomanNumeral } from '../lib/theory'
|
||||
|
||||
const HISTORY_SHOWN = 8 // ~2 bars at 4 chords/bar
|
||||
|
||||
function findLoopPosition(chordHistory, progression) {
|
||||
if (!progression?.length || !chordHistory.length) return -1
|
||||
const last = chordHistory[chordHistory.length - 1]
|
||||
for (let p = progression.length - 1; p >= 0; p--) {
|
||||
if (progression[p] !== last) continue
|
||||
let match = true
|
||||
for (let i = 1; i < Math.min(p + 1, chordHistory.length); i++) {
|
||||
if (progression[p - i] !== chordHistory[chordHistory.length - 1 - i]) { match = false; break }
|
||||
}
|
||||
if (match) return p
|
||||
}
|
||||
return progression.indexOf(last)
|
||||
}
|
||||
|
||||
export default function ProgressionBanner({ chordHistory, keyInfo, detectedProgression }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
// Newest chord is the last entry; we show the most recent HISTORY_SHOWN
|
||||
const visible = chordHistory.slice(-HISTORY_SHOWN)
|
||||
const current = visible[visible.length - 1]
|
||||
|
||||
// Animate the current chord slot when it changes
|
||||
const currentRef = useRef(null)
|
||||
const prevChord = useRef(null)
|
||||
useEffect(() => {
|
||||
if (current && current !== prevChord.current && currentRef.current) {
|
||||
currentRef.current.animate(
|
||||
[{ opacity: 0, transform: 'scale(0.85)' },
|
||||
{ opacity: 1, transform: 'scale(1)' }],
|
||||
{ duration: 200, easing: 'ease-out', fill: 'forwards' }
|
||||
)
|
||||
prevChord.current = current
|
||||
}
|
||||
}, [current])
|
||||
|
||||
const loopPos = findLoopPosition(chordHistory, detectedProgression)
|
||||
|
||||
if (!chordHistory.length) {
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-5 mb-4 flex items-center justify-center h-28">
|
||||
<p className="text-gray-600">Start listening to detect chords…</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-5 mb-4">
|
||||
|
||||
{/* ── Chord history strip: all HISTORY_SHOWN chords at consistent size ── */}
|
||||
<div className="flex items-stretch gap-1 overflow-x-auto pb-1">
|
||||
{visible.map((chord, i) => {
|
||||
const isCurrent = i === visible.length - 1
|
||||
const age = visible.length - 1 - i // 0 = current, higher = older
|
||||
const opacity = Math.max(0.2, 1 - age * 0.1) // fade but stay readable
|
||||
const rn = root ? toRomanNumeral(chord, root, mode) : ''
|
||||
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
ref={isCurrent ? currentRef : null}
|
||||
style={{ opacity }}
|
||||
className={`
|
||||
flex flex-col items-center justify-end shrink-0 px-3 py-2 rounded-xl
|
||||
transition-colors duration-200
|
||||
${isCurrent
|
||||
? 'bg-accent/10 border border-accent/40 ring-1 ring-accent/20'
|
||||
: 'border border-transparent'}
|
||||
`}
|
||||
>
|
||||
<span className={`font-black leading-none tracking-tight ${
|
||||
isCurrent ? 'text-5xl text-accent' : 'text-3xl text-gray-200'
|
||||
}`}>
|
||||
{chord}
|
||||
</span>
|
||||
<span className={`text-xs font-semibold mt-1 ${
|
||||
isCurrent ? 'text-amber-400' : 'text-gray-500'
|
||||
}`}>
|
||||
{rn || '\u00A0'}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* ── Detected loop ── */}
|
||||
{detectedProgression && (
|
||||
<div className="mt-4 pt-3 border-t border-border">
|
||||
<p className="text-xs text-gray-500 uppercase tracking-widest mb-2">♻ Detected loop</p>
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{detectedProgression.map((chord, i) => {
|
||||
const isActive = i === loopPos
|
||||
const rn = root ? toRomanNumeral(chord, root, mode) : chord
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className={`flex flex-col items-center px-4 py-2 rounded-xl border transition-all duration-200 ${
|
||||
isActive
|
||||
? 'bg-accent/20 border-accent shadow-[0_0_14px_rgba(168,85,247,0.35)]'
|
||||
: 'bg-border border-border'
|
||||
}`}
|
||||
>
|
||||
<span className={`text-2xl font-bold leading-none ${isActive ? 'text-accent' : 'text-gray-200'}`}>
|
||||
{chord}
|
||||
</span>
|
||||
<span className={`text-xs mt-1 font-semibold ${isActive ? 'text-amber-400' : 'text-gray-500'}`}>
|
||||
{rn}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<span className="self-center text-gray-600 text-sm pl-1">→ loop</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { getSuggestedProgressions } from '../lib/theory'
|
||||
|
||||
export default function ProgressionSuggestions({ keyInfo }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
if (!root) return null
|
||||
|
||||
const progressions = getSuggestedProgressions(root, mode)
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-4">
|
||||
Progressions in {root} {mode}
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
{progressions.map(prog => (
|
||||
<div key={prog.genre} className="flex items-center gap-3">
|
||||
<span className="text-xs text-gray-500 w-10 shrink-0">{prog.genre}</span>
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{prog.chords.map((chord, i) => (
|
||||
<span key={i} className="px-3 py-1 bg-border rounded text-sm font-medium">
|
||||
{chord}
|
||||
<span className="ml-1 text-gray-600 text-xs">({prog.rn[i]})</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import { getPentatonicScale, getFullScale, getChordTones } from '../lib/theory'
|
||||
|
||||
const ALL_NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
|
||||
|
||||
export default function SafeNotes({ keyInfo, currentChord }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
if (!root) return null
|
||||
|
||||
const penta = getPentatonicScale(root, mode)
|
||||
const full = getFullScale(root, mode)
|
||||
const chordTones = currentChord ? getChordTones(currentChord) : []
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-4">Safe Notes</p>
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{ALL_NOTES.map(note => {
|
||||
const isChordTone = chordTones.includes(note)
|
||||
const isPenta = penta.includes(note)
|
||||
const isScale = full.includes(note)
|
||||
|
||||
let cls = 'px-3 py-2 rounded-lg text-sm font-semibold border transition-all '
|
||||
if (isChordTone) {
|
||||
cls += 'bg-accent text-white border-accent scale-105'
|
||||
} else if (isPenta) {
|
||||
cls += 'bg-accent/20 text-accent border-accent/40'
|
||||
} else if (isScale) {
|
||||
cls += 'bg-border text-gray-300 border-border'
|
||||
} else {
|
||||
cls += 'bg-transparent text-gray-700 border-transparent'
|
||||
}
|
||||
|
||||
return (
|
||||
<span key={note} className={cls}>{note}</span>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div className="mt-3 flex gap-4 text-xs text-gray-500">
|
||||
<span><span className="text-accent">■</span> Chord tone</span>
|
||||
<span><span className="text-accent/60">■</span> Pentatonic</span>
|
||||
<span><span className="text-gray-500">■</span> Scale</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,366 +0,0 @@
|
||||
// ─── Constants ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const NOTES = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B']
|
||||
export const NOTES_FLAT = ['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B']
|
||||
|
||||
// Semitone intervals for each scale mode
|
||||
export const SCALES = {
|
||||
major: [0, 2, 4, 5, 7, 9, 11],
|
||||
minor: [0, 2, 3, 5, 7, 8, 10],
|
||||
dorian: [0, 2, 3, 5, 7, 9, 10],
|
||||
phrygian: [0, 1, 3, 5, 7, 8, 10],
|
||||
lydian: [0, 2, 4, 6, 7, 9, 11],
|
||||
mixolydian: [0, 2, 4, 5, 7, 9, 10],
|
||||
pentatonic_major: [0, 2, 4, 7, 9],
|
||||
pentatonic_minor: [0, 3, 5, 7, 10],
|
||||
blues: [0, 3, 5, 6, 7, 10],
|
||||
diminished: [0, 2, 3, 5, 6, 8, 9, 11],
|
||||
whole_tone: [0, 2, 4, 6, 8, 10],
|
||||
}
|
||||
|
||||
// Human-readable scale labels
|
||||
export const SCALE_LABELS = {
|
||||
major: 'Major',
|
||||
minor: 'Natural Minor',
|
||||
dorian: 'Dorian',
|
||||
phrygian: 'Phrygian',
|
||||
lydian: 'Lydian',
|
||||
mixolydian: 'Mixolydian',
|
||||
pentatonic_major: 'Major Pentatonic',
|
||||
pentatonic_minor: 'Minor Pentatonic',
|
||||
blues: 'Blues',
|
||||
diminished: 'Diminished',
|
||||
whole_tone: 'Whole Tone',
|
||||
}
|
||||
|
||||
// Krumhansl-Schmuckler key profiles (major/minor only — used for key detection)
|
||||
const KS_MAJOR = [6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88]
|
||||
const KS_MINOR = [6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17]
|
||||
|
||||
// Chord type definitions: intervals (semitones from root) and display suffix
|
||||
export const CHORD_TYPES = {
|
||||
maj: { intervals: [0, 4, 7], suffix: '' },
|
||||
min: { intervals: [0, 3, 7], suffix: 'm' },
|
||||
dom7: { intervals: [0, 4, 7, 10], suffix: '7' },
|
||||
maj7: { intervals: [0, 4, 7, 11], suffix: 'maj7' },
|
||||
min7: { intervals: [0, 3, 7, 10], suffix: 'm7' },
|
||||
dim: { intervals: [0, 3, 6], suffix: 'dim' },
|
||||
dim7: { intervals: [0, 3, 6, 9], suffix: 'dim7' },
|
||||
half_dim: { intervals: [0, 3, 6, 10], suffix: 'm7b5' },
|
||||
aug: { intervals: [0, 4, 8], suffix: 'aug' },
|
||||
sus4: { intervals: [0, 5, 7], suffix: 'sus4' },
|
||||
sus2: { intervals: [0, 2, 7], suffix: 'sus2' },
|
||||
maj6: { intervals: [0, 4, 7, 9], suffix: '6' },
|
||||
min6: { intervals: [0, 3, 7, 9], suffix: 'm6' },
|
||||
add9: { intervals: [0, 2, 4, 7], suffix: 'add9' },
|
||||
}
|
||||
|
||||
// Chord types considered during real-time chroma matching
|
||||
const MATCH_CHORD_TYPES = [
|
||||
'maj', 'min', 'dom7', 'min7', 'dim', 'half_dim', 'aug', 'sus4', 'add9',
|
||||
]
|
||||
|
||||
// Minimum score for a chord match to be reported
|
||||
const CHORD_MATCH_MIN_SCORE = 0.42
|
||||
// Minimum margin over second-best for a match to be considered unambiguous
|
||||
const CHORD_MATCH_MIN_MARGIN = 0.04
|
||||
|
||||
// Chord quality for each scale degree in major and minor
|
||||
const DEGREE_QUALITIES = {
|
||||
major: ['', 'm', 'm', '', '', 'm', 'dim'],
|
||||
minor: ['m', 'dim', '', 'm', 'm', '', '' ],
|
||||
}
|
||||
|
||||
const ROMAN_NUMERALS = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII']
|
||||
|
||||
// Common chord progressions by genre, expressed as semitone offsets from the root
|
||||
const PROGRESSIONS = {
|
||||
pop: { name: 'Pop', rn: ['I', 'V', 'vi', 'IV'], degrees: [0, 7, 9, 5] },
|
||||
blues: { name: 'Blues', rn: ['I', 'IV', 'V'], degrees: [0, 5, 7] },
|
||||
folk: { name: 'Folk', rn: ['I', 'IV', 'I', 'V'], degrees: [0, 5, 0, 7] },
|
||||
jazz: { name: 'Jazz', rn: ['ii', 'V', 'I'], degrees: [2, 7, 0] },
|
||||
rock: { name: 'Rock', rn: ['I', 'bVII', 'IV', 'I'], degrees: [0, 10, 5, 0] },
|
||||
'50s': { name: "'50s", rn: ['I', 'vi', 'IV', 'V'], degrees: [0, 9, 5, 7] },
|
||||
flamen: { name: 'Flamenco', rn: ['i', 'bVII', 'bVI', 'V'], degrees: [0, 10, 8, 7] },
|
||||
}
|
||||
|
||||
// ─── Internal helpers ────────────────────────────────────────────────────────
|
||||
|
||||
function noteName(semitone, preferFlat = false) {
|
||||
const pc = ((semitone % 12) + 12) % 12
|
||||
return preferFlat ? NOTES_FLAT[pc] : NOTES[pc]
|
||||
}
|
||||
|
||||
function pearsonCorrelation(a, b) {
|
||||
const n = a.length
|
||||
const meanA = a.reduce((s, v) => s + v, 0) / n
|
||||
const meanB = b.reduce((s, v) => s + v, 0) / n
|
||||
let num = 0, denA = 0, denB = 0
|
||||
for (let i = 0; i < n; i++) {
|
||||
const da = a[i] - meanA
|
||||
const db = b[i] - meanB
|
||||
num += da * db
|
||||
denA += da * da
|
||||
denB += db * db
|
||||
}
|
||||
return num / Math.sqrt(denA * denB + 1e-10)
|
||||
}
|
||||
|
||||
// Accepts both sharp (C#) and flat (Db) spellings
|
||||
function noteIndex(note) {
|
||||
const idx = NOTES.indexOf(note)
|
||||
if (idx !== -1) return idx
|
||||
return NOTES_FLAT.indexOf(note)
|
||||
}
|
||||
|
||||
// ─── Key Detection ───────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* detectKey(noteHistory) → { root, mode, confidence }
|
||||
* Uses Krumhansl-Schmuckler: correlates pitch-class histogram with key profiles.
|
||||
* noteHistory: array of MIDI note numbers or pitch-class integers (0–11)
|
||||
*/
|
||||
export function detectKey(noteHistory) {
|
||||
if (!noteHistory || noteHistory.length < 4) {
|
||||
return { root: 'C', mode: 'major', confidence: 0 }
|
||||
}
|
||||
|
||||
const freq = new Array(12).fill(0)
|
||||
for (const note of noteHistory) {
|
||||
freq[((note % 12) + 12) % 12]++
|
||||
}
|
||||
|
||||
let best = { root: 0, mode: 'major', score: -Infinity }
|
||||
|
||||
for (let root = 0; root < 12; root++) {
|
||||
const rotated = Array.from({ length: 12 }, (_, i) => freq[(i + root) % 12])
|
||||
const scoreMaj = pearsonCorrelation(rotated, KS_MAJOR)
|
||||
const scoreMin = pearsonCorrelation(rotated, KS_MINOR)
|
||||
if (scoreMaj > best.score) best = { root, mode: 'major', score: scoreMaj }
|
||||
if (scoreMin > best.score) best = { root, mode: 'minor', score: scoreMin }
|
||||
}
|
||||
|
||||
const confidence = Math.max(0, Math.min(1, (best.score + 1) / 2))
|
||||
return { root: noteName(best.root), mode: best.mode, confidence }
|
||||
}
|
||||
|
||||
// ─── Scale helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
export function getScale(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
return (SCALES[mode] ?? SCALES.major).map(i => noteName(rootIdx + i))
|
||||
}
|
||||
|
||||
// Legacy aliases
|
||||
export const getFullScale = (root, mode) => getScale(root, mode)
|
||||
export const getPentatonicScale = (root, mode) =>
|
||||
getScale(root, mode === 'minor' ? 'pentatonic_minor' : 'pentatonic_major')
|
||||
|
||||
/**
|
||||
* Returns all scale modes that contain every note in playedNotes.
|
||||
* Useful for suggesting compatible scales from a detected chord or melody.
|
||||
*/
|
||||
export function getCompatibleScales(playedNotes, root) {
|
||||
const played = new Set(playedNotes)
|
||||
return Object.entries(SCALES)
|
||||
.map(([mode]) => ({ mode, label: SCALE_LABELS[mode] ?? mode, notes: getScale(root, mode) }))
|
||||
.filter(({ notes }) => [...played].every(n => notes.includes(n)))
|
||||
}
|
||||
|
||||
// ─── Chord helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
export function getChordTones(chordName) {
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return []
|
||||
const root = noteIndex(match[1])
|
||||
const suffix = match[2] ?? ''
|
||||
const type = Object.values(CHORD_TYPES).find(t => t.suffix === suffix) ?? CHORD_TYPES.maj
|
||||
return type.intervals.map(i => noteName(root + i))
|
||||
}
|
||||
|
||||
export function getChordsInKey(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
const scale = SCALES[mode] ?? SCALES.major
|
||||
const qualities = DEGREE_QUALITIES[mode] ?? DEGREE_QUALITIES.major
|
||||
return scale.map((degree, i) => noteName(rootIdx + degree) + qualities[i])
|
||||
}
|
||||
|
||||
// ─── Progression suggestions ─────────────────────────────────────────────────
|
||||
|
||||
export function getSuggestedProgressions(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
const scale = SCALES[mode] ?? SCALES.major
|
||||
const qualities = DEGREE_QUALITIES[mode] ?? DEGREE_QUALITIES.major
|
||||
|
||||
return Object.values(PROGRESSIONS).map(prog => {
|
||||
const chords = prog.degrees.map(semitones => {
|
||||
const noteIdx = (rootIdx + semitones) % 12
|
||||
const degreeIdx = scale.indexOf(semitones)
|
||||
// Chromatic degrees (e.g. bVII in rock) default to major triad
|
||||
const quality = degreeIdx >= 0 ? qualities[degreeIdx] : ''
|
||||
return noteName(noteIdx) + quality
|
||||
})
|
||||
return { genre: prog.name, rn: prog.rn, chords }
|
||||
})
|
||||
}
|
||||
|
||||
// ─── Chroma-based chord matching ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* matchChordFromChroma(chroma, keyInfo, bassPC?, strictDiatonic?, minScore?, minMargin?)
|
||||
* chroma: Float32Array[12], normalised 0–1 energy per pitch class.
|
||||
* Returns null when no unambiguous winner is found (transition/silence).
|
||||
*/
|
||||
export function matchChordFromChroma(
|
||||
chroma,
|
||||
keyInfo,
|
||||
bassPC = null,
|
||||
strictDiatonic = false,
|
||||
minScore = CHORD_MATCH_MIN_SCORE,
|
||||
minMargin = CHORD_MATCH_MIN_MARGIN,
|
||||
) {
|
||||
if (!keyInfo?.root) return null
|
||||
|
||||
const diatonicSet = new Set(getChordsInKey(keyInfo.root, keyInfo.mode))
|
||||
|
||||
let best = { name: null, score: -Infinity }
|
||||
let secondScore = -Infinity
|
||||
|
||||
for (let r = 0; r < 12; r++) {
|
||||
for (const typeKey of MATCH_CHORD_TYPES) {
|
||||
const type = CHORD_TYPES[typeKey]
|
||||
const chordName = noteName(r) + type.suffix
|
||||
|
||||
if (strictDiatonic && !diatonicSet.has(chordName)) continue
|
||||
|
||||
const tones = new Set(type.intervals.map(i => (r + i) % 12))
|
||||
|
||||
let inEnergy = 0, outEnergy = 0
|
||||
for (let pc = 0; pc < 12; pc++) {
|
||||
if (pc === r) {
|
||||
inEnergy += chroma[pc] * 2 // root carries strongest identity signal
|
||||
} else if (tones.has(pc)) {
|
||||
inEnergy += chroma[pc]
|
||||
} else {
|
||||
outEnergy += chroma[pc]
|
||||
}
|
||||
}
|
||||
|
||||
if (inEnergy + outEnergy < 0.05) continue
|
||||
|
||||
const coverageScore = inEnergy / (inEnergy + outEnergy * 0.5)
|
||||
const bassBonus = bassPC !== null && r === bassPC ? 0.15 : 0
|
||||
const diatonicBonus = diatonicSet.has(chordName) ? 0.15 : 0
|
||||
|
||||
const finalScore = coverageScore + bassBonus + diatonicBonus
|
||||
|
||||
if (finalScore > best.score) {
|
||||
secondScore = best.score
|
||||
best = { name: chordName, score: finalScore }
|
||||
} else if (finalScore > secondScore) {
|
||||
secondScore = finalScore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (best.score >= minScore && best.score - secondScore >= minMargin)
|
||||
? best.name
|
||||
: null
|
||||
}
|
||||
|
||||
// ─── Roman numeral notation ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Converts a chord name to its Roman numeral relative to a key.
|
||||
* Chromatic (borrowed) chords get a flat prefix, e.g. Bb in C major → ♭VII.
|
||||
*/
|
||||
export function toRomanNumeral(chordName, keyRoot, keyMode) {
|
||||
if (!chordName || !keyRoot) return '?'
|
||||
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return '?'
|
||||
const [, root, quality] = match
|
||||
|
||||
const chordRootIdx = noteIndex(root)
|
||||
const keyRootIdx = noteIndex(keyRoot)
|
||||
if (chordRootIdx < 0 || keyRootIdx < 0) return '?'
|
||||
|
||||
const semitones = ((chordRootIdx - keyRootIdx) + 12) % 12
|
||||
const scale = SCALES[keyMode] ?? SCALES.major
|
||||
const degreeIdx = scale.indexOf(semitones)
|
||||
|
||||
let rn
|
||||
if (degreeIdx >= 0) {
|
||||
rn = ROMAN_NUMERALS[degreeIdx]
|
||||
} else {
|
||||
// Chromatic chord: flat the nearest diatonic degree above it
|
||||
const nearestAbove = scale.findIndex(d => d > semitones)
|
||||
const refDegree = nearestAbove >= 0 ? nearestAbove : 0
|
||||
rn = '♭' + ROMAN_NUMERALS[refDegree]
|
||||
}
|
||||
|
||||
const isMinorQuality = /^m(?!aj)/.test(quality) || quality === 'dim' || quality === 'm7b5'
|
||||
return isMinorQuality ? rn.toLowerCase() : rn
|
||||
}
|
||||
|
||||
// ─── Repeating progression detection ─────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* detectRepeatingProgression(history) → chord[] or null
|
||||
* Returns the most-recently-completed repeating pattern (length 2–6).
|
||||
* Uses non-overlapping match counting to avoid over-counting.
|
||||
*/
|
||||
export function detectRepeatingProgression(history) {
|
||||
if (!history || history.length < 4) return null
|
||||
|
||||
const window = history.slice(-20)
|
||||
let best = null, bestScore = 0
|
||||
|
||||
for (let len = 2; len <= 6; len++) {
|
||||
if (len * 2 > window.length) break
|
||||
|
||||
const candidate = window.slice(-len)
|
||||
let reps = 0, i = 0
|
||||
|
||||
while (i <= window.length - len) {
|
||||
if (candidate.every((c, j) => c === window[i + j])) {
|
||||
reps++
|
||||
i += len // skip past match — non-overlapping
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
const score = reps * len
|
||||
if (reps >= 2 && score > bestScore) {
|
||||
bestScore = score
|
||||
best = candidate
|
||||
}
|
||||
}
|
||||
|
||||
return best
|
||||
}
|
||||
|
||||
// ─── Utilities ───────────────────────────────────────────────────────────────
|
||||
|
||||
export function intervalName(semitones) {
|
||||
const names = [
|
||||
'Unison', 'Minor 2nd', 'Major 2nd', 'Minor 3rd', 'Major 3rd',
|
||||
'Perfect 4th', 'Tritone', 'Perfect 5th', 'Minor 6th',
|
||||
'Major 6th', 'Minor 7th', 'Major 7th',
|
||||
]
|
||||
return names[((semitones % 12) + 12) % 12] ?? 'Unknown'
|
||||
}
|
||||
|
||||
export function transposeChord(chordName, semitones) {
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return chordName
|
||||
return noteName(noteIndex(match[1]) + semitones) + match[2]
|
||||
}
|
||||
|
||||
export function transposeProgression(chords, semitones) {
|
||||
return chords.map(c => transposeChord(c, semitones))
|
||||
}
|
||||
@@ -1,476 +0,0 @@
|
||||
// ─── Constants ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const NOTES = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B']
|
||||
export const NOTES_FLAT = ['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B']
|
||||
|
||||
// Semitone intervals for each scale mode
|
||||
export const SCALES = {
|
||||
major: [0, 2, 4, 5, 7, 9, 11],
|
||||
minor: [0, 2, 3, 5, 7, 8, 10],
|
||||
dorian: [0, 2, 3, 5, 7, 9, 10],
|
||||
phrygian: [0, 1, 3, 5, 7, 8, 10],
|
||||
lydian: [0, 2, 4, 6, 7, 9, 11],
|
||||
mixolydian: [0, 2, 4, 5, 7, 9, 10],
|
||||
pentatonic_major: [0, 2, 4, 7, 9],
|
||||
pentatonic_minor: [0, 3, 5, 7, 10],
|
||||
blues: [0, 3, 5, 6, 7, 10],
|
||||
diminished: [0, 2, 3, 5, 6, 8, 9, 11],
|
||||
whole_tone: [0, 2, 4, 6, 8, 10],
|
||||
}
|
||||
|
||||
// Human-readable scale labels
|
||||
export const SCALE_LABELS = {
|
||||
major: 'Major',
|
||||
minor: 'Natural Minor',
|
||||
dorian: 'Dorian',
|
||||
phrygian: 'Phrygian',
|
||||
lydian: 'Lydian',
|
||||
mixolydian: 'Mixolydian',
|
||||
pentatonic_major: 'Major Pentatonic',
|
||||
pentatonic_minor: 'Minor Pentatonic',
|
||||
blues: 'Blues',
|
||||
diminished: 'Diminished',
|
||||
whole_tone: 'Whole Tone',
|
||||
}
|
||||
|
||||
// Krumhansl-Schmuckler key profiles (only major/minor used for key detection)
|
||||
const KS_MAJOR = [6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88]
|
||||
const KS_MINOR = [6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17]
|
||||
|
||||
// Chord type definitions: intervals (semitones from root) and display suffix
|
||||
export const CHORD_TYPES = {
|
||||
maj: { intervals: [0, 4, 7], suffix: '' },
|
||||
min: { intervals: [0, 3, 7], suffix: 'm' },
|
||||
dom7: { intervals: [0, 4, 7, 10], suffix: '7' },
|
||||
maj7: { intervals: [0, 4, 7, 11], suffix: 'maj7' },
|
||||
min7: { intervals: [0, 3, 7, 10], suffix: 'm7' },
|
||||
dim: { intervals: [0, 3, 6], suffix: 'dim' },
|
||||
dim7: { intervals: [0, 3, 6, 9], suffix: 'dim7' },
|
||||
half_dim:{ intervals: [0, 3, 6, 10], suffix: 'm7b5' },
|
||||
aug: { intervals: [0, 4, 8], suffix: 'aug' },
|
||||
sus4: { intervals: [0, 5, 7], suffix: 'sus4' },
|
||||
sus2: { intervals: [0, 2, 7], suffix: 'sus2' },
|
||||
maj6: { intervals: [0, 4, 7, 9], suffix: '6' },
|
||||
min6: { intervals: [0, 3, 7, 9], suffix: 'm6' },
|
||||
add9: { intervals: [0, 2, 4, 7], suffix: 'add9' },
|
||||
}
|
||||
|
||||
// Chord types considered during real-time chroma matching
|
||||
const MATCH_CHORD_TYPES = [
|
||||
'maj', 'min', 'dom7', 'min7', 'dim', 'half_dim', 'aug', 'sus4', 'add9',
|
||||
]
|
||||
|
||||
// Minimum score for a chord match to be reported
|
||||
const CHORD_MATCH_MIN_SCORE = 0.42
|
||||
|
||||
// Minimum margin over second-best for a match to be considered unambiguous
|
||||
const CHORD_MATCH_MIN_MARGIN = 0.08
|
||||
|
||||
// Chord quality arrays for each scale degree in major and minor
|
||||
const DEGREE_QUALITIES = {
|
||||
major: ['', 'm', 'm', '', '', 'm', 'dim'],
|
||||
minor: ['m', 'dim','', 'm', 'm', '', '' ],
|
||||
}
|
||||
|
||||
const ROMAN_NUMERALS = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII']
|
||||
|
||||
// Common chord progressions by genre, expressed as semitone offsets from the root
|
||||
const PROGRESSIONS = {
|
||||
pop: { name: 'Pop', rn: ['I', 'V', 'vi', 'IV'], degrees: [0, 7, 9, 5] },
|
||||
blues: { name: 'Blues', rn: ['I', 'IV', 'V'], degrees: [0, 5, 7] },
|
||||
folk: { name: 'Folk', rn: ['I', 'IV', 'I', 'V'], degrees: [0, 5, 0, 7] },
|
||||
jazz: { name: 'Jazz', rn: ['ii', 'V', 'I'], degrees: [2, 7, 0] },
|
||||
rock: { name: 'Rock', rn: ['I', 'bVII', 'IV', 'I'], degrees: [0, 10, 5, 0] },
|
||||
'50s': { name: "'50s", rn: ['I', 'vi', 'IV', 'V'], degrees: [0, 9, 5, 7] },
|
||||
flamen: { name: 'Flamenco',rn: ['i', 'bVII', 'bVI', 'V'],degrees:[0, 10, 8, 7] },
|
||||
}
|
||||
|
||||
// ─── Internal helpers ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns the note name for a given semitone value (0–11, wraps automatically).
|
||||
* @param {number} semitone
|
||||
* @param {boolean} [preferFlat=false]
|
||||
* @returns {string}
|
||||
*/
|
||||
function noteName(semitone, preferFlat = false) {
|
||||
const pc = ((semitone % 12) + 12) % 12
|
||||
return preferFlat ? NOTES_FLAT[pc] : NOTES[pc]
|
||||
}
|
||||
|
||||
/**
|
||||
* Pearson correlation between two equal-length numeric arrays.
|
||||
* Returns a value in [-1, 1]. A small epsilon avoids division by zero.
|
||||
* @param {number[]} a
|
||||
* @param {number[]} b
|
||||
* @returns {number}
|
||||
*/
|
||||
function pearsonCorrelation(a, b) {
|
||||
const n = a.length
|
||||
const meanA = a.reduce((s, v) => s + v, 0) / n
|
||||
const meanB = b.reduce((s, v) => s + v, 0) / n
|
||||
let num = 0, denA = 0, denB = 0
|
||||
for (let i = 0; i < n; i++) {
|
||||
const da = a[i] - meanA
|
||||
const db = b[i] - meanB
|
||||
num += da * db
|
||||
denA += da * da
|
||||
denB += db * db
|
||||
}
|
||||
return num / Math.sqrt(denA * denB + 1e-10)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the semitone offset (0–11) of a note name, or -1 if not found.
|
||||
* Accepts both sharp and flat spellings.
|
||||
* @param {string} note
|
||||
* @returns {number}
|
||||
*/
|
||||
function noteIndex(note) {
|
||||
const idx = NOTES.indexOf(note)
|
||||
if (idx !== -1) return idx
|
||||
return NOTES_FLAT.indexOf(note) // handles Db, Eb, etc.
|
||||
}
|
||||
|
||||
// ─── Key Detection ───────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Detects the most likely musical key from a recent history of played notes.
|
||||
*
|
||||
* Uses the Krumhansl-Schmuckler algorithm: builds a pitch-class frequency
|
||||
* vector and correlates it against major and minor profiles for all 12 roots.
|
||||
*
|
||||
* @param {number[]} noteHistory MIDI note numbers or pitch-class integers (0–11)
|
||||
* @returns {{ root: string, mode: 'major'|'minor', confidence: number }}
|
||||
* confidence is normalised to [0, 1]; values below ~0.5 are unreliable.
|
||||
*/
|
||||
export function detectKey(noteHistory) {
|
||||
if (!noteHistory || noteHistory.length < 4) {
|
||||
return { root: 'C', mode: 'major', confidence: 0 }
|
||||
}
|
||||
|
||||
// Build pitch-class frequency vector
|
||||
const freq = new Array(12).fill(0)
|
||||
for (const note of noteHistory) {
|
||||
freq[((note % 12) + 12) % 12]++
|
||||
}
|
||||
|
||||
let best = { root: 0, mode: 'major', score: -Infinity }
|
||||
|
||||
for (let root = 0; root < 12; root++) {
|
||||
// Rotate the observed frequencies to align with the profile's C-root
|
||||
const rotated = Array.from({ length: 12 }, (_, i) => freq[(i + root) % 12])
|
||||
|
||||
const scoreMaj = pearsonCorrelation(rotated, KS_MAJOR)
|
||||
const scoreMin = pearsonCorrelation(rotated, KS_MINOR)
|
||||
|
||||
if (scoreMaj > best.score) best = { root, mode: 'major', score: scoreMaj }
|
||||
if (scoreMin > best.score) best = { root, mode: 'minor', score: scoreMin }
|
||||
}
|
||||
|
||||
// Map correlation [-1, 1] to a rough confidence in [0, 1]
|
||||
const confidence = Math.max(0, Math.min(1, (best.score + 1) / 2))
|
||||
|
||||
return { root: noteName(best.root), mode: best.mode, confidence }
|
||||
}
|
||||
|
||||
// ─── Scale helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns all note names in a given scale.
|
||||
* @param {string} root e.g. 'G', 'F#'
|
||||
* @param {keyof SCALES} mode
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function getScale(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
const intervals = SCALES[mode] ?? SCALES.major
|
||||
return intervals.map(i => noteName(rootIdx + i))
|
||||
}
|
||||
|
||||
// Legacy aliases kept for backwards compatibility
|
||||
export const getFullScale = (root, mode) => getScale(root, mode)
|
||||
export const getPentatonicScale = (root, mode) =>
|
||||
getScale(root, mode === 'minor' ? 'pentatonic_minor' : 'pentatonic_major')
|
||||
|
||||
/**
|
||||
* Returns all scale modes that contain every note in `playedNotes`.
|
||||
* Useful for suggesting compatible scales from a detected chord or melody.
|
||||
* @param {string[]} playedNotes e.g. ['C', 'E', 'G']
|
||||
* @param {string} root
|
||||
* @returns {{ mode: string, label: string, notes: string[] }[]}
|
||||
*/
|
||||
export function getCompatibleScales(playedNotes, root) {
|
||||
const played = new Set(playedNotes)
|
||||
return Object.entries(SCALES)
|
||||
.map(([mode]) => ({ mode, label: SCALE_LABELS[mode] ?? mode, notes: getScale(root, mode) }))
|
||||
.filter(({ notes }) => [...played].every(n => notes.includes(n)))
|
||||
}
|
||||
|
||||
// ─── Chord helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Parses a chord name and returns its component note names.
|
||||
* @param {string} chordName e.g. 'Am', 'Gmaj7', 'Fdim', 'Baug'
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function getChordTones(chordName) {
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return []
|
||||
const root = noteIndex(match[1])
|
||||
const suffix = match[2] ?? ''
|
||||
|
||||
const type = Object.values(CHORD_TYPES).find(t => t.suffix === suffix)
|
||||
?? CHORD_TYPES.maj // default to major triad
|
||||
|
||||
return type.intervals.map(i => noteName(root + i))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the diatonic chords (triads) for every scale degree.
|
||||
* @param {string} root
|
||||
* @param {'major'|'minor'} mode
|
||||
* @returns {string[]} e.g. ['C', 'Dm', 'Em', 'F', 'G', 'Am', 'Bdim']
|
||||
*/
|
||||
export function getChordsInKey(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
const scale = SCALES[mode] ?? SCALES.major
|
||||
const qualities = DEGREE_QUALITIES[mode] ?? DEGREE_QUALITIES.major
|
||||
|
||||
return scale.map((degree, i) => noteName(rootIdx + degree) + qualities[i])
|
||||
}
|
||||
|
||||
// ─── Progression suggestions ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns common chord progressions transposed to the given key.
|
||||
*
|
||||
* For non-diatonic degrees (e.g. bVII in rock), the quality falls back to a
|
||||
* major triad rather than silently producing a wrong chord name.
|
||||
*
|
||||
* @param {string} root
|
||||
* @param {'major'|'minor'} mode
|
||||
* @returns {{ genre: string, rn: string[], chords: string[] }[]}
|
||||
*/
|
||||
export function getSuggestedProgressions(root, mode) {
|
||||
const rootIdx = noteIndex(root)
|
||||
if (rootIdx === -1) return []
|
||||
const scale = SCALES[mode] ?? SCALES.major
|
||||
const qualities = DEGREE_QUALITIES[mode] ?? DEGREE_QUALITIES.major
|
||||
|
||||
return Object.values(PROGRESSIONS).map(prog => {
|
||||
const chords = prog.degrees.map(semitones => {
|
||||
const noteIdx = (rootIdx + semitones) % 12
|
||||
const name = noteName(noteIdx)
|
||||
const degreeIdx = scale.indexOf(semitones)
|
||||
// Diatonic degree → use proper quality; chromatic (e.g. bVII) → major triad
|
||||
const quality = degreeIdx >= 0 ? qualities[degreeIdx] : ''
|
||||
return name + quality
|
||||
})
|
||||
return { genre: prog.name, rn: prog.rn, chords }
|
||||
})
|
||||
}
|
||||
|
||||
// ─── Chroma-based chord matching ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Matches the most likely chord from a chroma energy vector.
|
||||
*
|
||||
* The algorithm scores each candidate chord by comparing in-chord vs
|
||||
* out-of-chord energy, with bonuses for bass-note and diatonic alignment.
|
||||
* Returns null when no unambiguous winner is found (e.g. during a transition).
|
||||
*
|
||||
* @param {Float32Array|number[]} chroma 12-element pitch-class energy (0–1)
|
||||
* @param {{ root: string, mode: string }} keyInfo
|
||||
* @param {number|null} [bassPC=null] Pitch class of the detected bass note
|
||||
* @param {boolean} [strictDiatonic=false] Only consider diatonic chords
|
||||
* @param {number} [minScore] Override default minimum match score
|
||||
* @param {number} [minMargin] Override default ambiguity margin
|
||||
* @returns {string|null} Chord name, e.g. 'Am7', or null if ambiguous
|
||||
*/
|
||||
export function matchChordFromChroma(
|
||||
chroma,
|
||||
keyInfo,
|
||||
bassPC = null,
|
||||
strictDiatonic = false,
|
||||
minScore = CHORD_MATCH_MIN_SCORE,
|
||||
minMargin = CHORD_MATCH_MIN_MARGIN,
|
||||
) {
|
||||
if (!keyInfo?.root) return null
|
||||
|
||||
const diatonicSet = new Set(getChordsInKey(keyInfo.root, keyInfo.mode))
|
||||
|
||||
let best = { name: null, score: -Infinity }
|
||||
let secondScore = -Infinity
|
||||
|
||||
for (let r = 0; r < 12; r++) {
|
||||
for (const typeKey of MATCH_CHORD_TYPES) {
|
||||
const type = CHORD_TYPES[typeKey]
|
||||
const chordName = noteName(r) + type.suffix
|
||||
|
||||
if (strictDiatonic && !diatonicSet.has(chordName)) continue
|
||||
|
||||
const tones = new Set(type.intervals.map(i => (r + i) % 12))
|
||||
|
||||
let inEnergy = 0, outEnergy = 0
|
||||
for (let pc = 0; pc < 12; pc++) {
|
||||
if (pc === r) {
|
||||
// Root carries the strongest identity signal — double weight
|
||||
inEnergy += chroma[pc] * 2
|
||||
} else if (tones.has(pc)) {
|
||||
inEnergy += chroma[pc]
|
||||
} else {
|
||||
outEnergy += chroma[pc]
|
||||
}
|
||||
}
|
||||
|
||||
// Skip near-silence
|
||||
if (inEnergy + outEnergy < 0.05) continue
|
||||
|
||||
const coverageScore = inEnergy / (inEnergy + outEnergy * 0.5)
|
||||
const bassBonus = bassPC !== null && r === bassPC ? 0.15 : 0
|
||||
const diatonicBonus = diatonicSet.has(chordName) ? 0.10 : 0
|
||||
|
||||
const finalScore = coverageScore + bassBonus + diatonicBonus
|
||||
|
||||
if (finalScore > best.score) {
|
||||
secondScore = best.score
|
||||
best = { name: chordName, score: finalScore }
|
||||
} else if (finalScore > secondScore) {
|
||||
secondScore = finalScore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const clearWinner = best.score >= minScore && (best.score - secondScore) >= minMargin
|
||||
return clearWinner ? best.name : null
|
||||
}
|
||||
|
||||
// ─── Roman numeral notation ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Converts a chord name to its Roman numeral relative to a key.
|
||||
*
|
||||
* Non-diatonic (borrowed/chromatic) chords are returned with a flat prefix,
|
||||
* e.g. 'Bb' in C major → '♭VII'. Previously this always returned '♭I'.
|
||||
*
|
||||
* @param {string} chordName e.g. 'Am', 'G7'
|
||||
* @param {string} keyRoot e.g. 'C'
|
||||
* @param {string} keyMode e.g. 'major'
|
||||
* @returns {string}
|
||||
*/
|
||||
export function toRomanNumeral(chordName, keyRoot, keyMode) {
|
||||
if (!chordName || !keyRoot) return '?'
|
||||
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return '?'
|
||||
const [, root, quality] = match
|
||||
|
||||
const chordRootIdx = noteIndex(root)
|
||||
const keyRootIdx = noteIndex(keyRoot)
|
||||
if (chordRootIdx < 0 || keyRootIdx < 0) return '?'
|
||||
|
||||
const semitones = ((chordRootIdx - keyRootIdx) + 12) % 12
|
||||
const scale = SCALES[keyMode] ?? SCALES.major
|
||||
const degreeIdx = scale.indexOf(semitones)
|
||||
|
||||
let rn
|
||||
if (degreeIdx >= 0) {
|
||||
rn = ROMAN_NUMERALS[degreeIdx]
|
||||
} else {
|
||||
// Chromatic chord: find the nearest diatonic degree above and flat it
|
||||
const nearestAbove = scale.findIndex(d => d > semitones)
|
||||
const refDegree = nearestAbove >= 0 ? nearestAbove : 0
|
||||
rn = '♭' + ROMAN_NUMERALS[refDegree]
|
||||
}
|
||||
|
||||
const isMinorQuality = /^m(?!aj)/.test(quality) || quality === 'dim' || quality === 'm7b5'
|
||||
return isMinorQuality ? rn.toLowerCase() : rn
|
||||
}
|
||||
|
||||
// ─── Repeating progression detection ─────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Scans recent chord history for a repeating pattern of length 2–6.
|
||||
*
|
||||
* Returns the most recently completed pattern that appears at least twice
|
||||
* within the last 20 chords. Longer patterns that repeat are preferred over
|
||||
* shorter ones via a `repetitions × length` score.
|
||||
*
|
||||
* @param {string[]} history Ordered list of chord names
|
||||
* @returns {string[]|null} Detected repeating pattern, or null
|
||||
*/
|
||||
export function detectRepeatingProgression(history) {
|
||||
if (!history || history.length < 4) return null
|
||||
|
||||
const window = history.slice(-20)
|
||||
let best = null, bestScore = 0
|
||||
|
||||
for (let len = 2; len <= 6; len++) {
|
||||
if (len * 2 > window.length) break
|
||||
|
||||
const candidate = window.slice(-len)
|
||||
let reps = 0
|
||||
|
||||
// Count non-overlapping matches from left to right
|
||||
let i = 0
|
||||
while (i <= window.length - len) {
|
||||
const matches = candidate.every((c, j) => c === window[i + j])
|
||||
if (matches) {
|
||||
reps++
|
||||
i += len // skip past this match to avoid overlaps
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
const score = reps * len
|
||||
if (reps >= 2 && score > bestScore) {
|
||||
bestScore = score
|
||||
best = candidate
|
||||
}
|
||||
}
|
||||
|
||||
return best
|
||||
}
|
||||
|
||||
// ─── Utility ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Returns the interval name for a semitone distance (0–11).
|
||||
* @param {number} semitones
|
||||
* @returns {string}
|
||||
*/
|
||||
export function intervalName(semitones) {
|
||||
const names = [
|
||||
'Unison', 'Minor 2nd', 'Major 2nd', 'Minor 3rd', 'Major 3rd',
|
||||
'Perfect 4th', 'Tritone', 'Perfect 5th', 'Minor 6th',
|
||||
'Major 6th', 'Minor 7th', 'Major 7th',
|
||||
]
|
||||
return names[((semitones % 12) + 12) % 12] ?? 'Unknown'
|
||||
}
|
||||
|
||||
/**
|
||||
* Transposes a chord name by a given number of semitones.
|
||||
* @param {string} chordName e.g. 'Am7'
|
||||
* @param {number} semitones Positive = up, negative = down
|
||||
* @returns {string}
|
||||
*/
|
||||
export function transposeChord(chordName, semitones) {
|
||||
const match = chordName.match(/^([A-G][b#]?)(.*)$/)
|
||||
if (!match) return chordName
|
||||
const newRoot = noteName(noteIndex(match[1]) + semitones)
|
||||
return newRoot + match[2]
|
||||
}
|
||||
|
||||
/**
|
||||
* Transposes an entire progression by a given number of semitones.
|
||||
* @param {string[]} chords
|
||||
* @param {number} semitones
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function transposeProgression(chords, semitones) {
|
||||
return chords.map(c => transposeChord(c, semitones))
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': 'http://localhost:8000',
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-eval'; connect-src 'self' http://localhost:5173 ws://localhost:5173; style-src 'self' 'unsafe-inline'; img-src 'self' data:;">
|
||||
<title>WhatTheFlat ♭? - JamBuddy</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,31 +0,0 @@
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from api.config import settings
|
||||
from api.routers import chat
|
||||
|
||||
app = FastAPI(title="WhatTheFlat API", version="0.1.0")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(chat.router, prefix="/api")
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
return {"status": "ok", "ai_mode": settings.ai_mode}
|
||||
|
||||
|
||||
def serve():
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
serve()
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "jambuddy",
|
||||
"description": "A jam session companion app that provides a chromatic tuner, chord progressions, and more.",
|
||||
"version": "0.6.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "electron/main.cjs",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"electron:dev": "concurrently -k \"vite\" \"wait-on http://localhost:5173 && electron .\"",
|
||||
"electron:build": "vite build && electron-builder",
|
||||
"electron:build:win": "vite build && electron-builder --win --publish never",
|
||||
"electron:build:mac": "vite build && electron-builder --mac --publish never",
|
||||
"electron:build:linux": "vite build && electron-builder --linux --publish never"
|
||||
},
|
||||
"dependencies": {
|
||||
"audiomotion-analyzer": "^4.5.4",
|
||||
"pitchy": "^4.1.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.2.1",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"concurrently": "^9.2.1",
|
||||
"electron": "^40.7.0",
|
||||
"electron-builder": "^26.8.1",
|
||||
"tailwindcss": "^4.2.1",
|
||||
"vite": "^7.3.1",
|
||||
"wait-on": "^9.0.4"
|
||||
},
|
||||
"build": {
|
||||
"appId": "com.jambuddy.app",
|
||||
"productName": "JamBuddy",
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"electron/**/*",
|
||||
"node_modules/**/*",
|
||||
"package.json"
|
||||
],
|
||||
"directories": {
|
||||
"buildResources": "dist",
|
||||
"output": "release"
|
||||
},
|
||||
"win": {
|
||||
"target": "nsis",
|
||||
"icon": "assets/whattheflat-logo.png",
|
||||
"forceCodeSigning": false
|
||||
},
|
||||
"mac": {
|
||||
"hardenedRuntime": true,
|
||||
"entitlements": "electron/entitlements.mac.plist",
|
||||
"entitlementsInherit": "electron/entitlements.mac.plist",
|
||||
"extendInfo": {
|
||||
"NSMicrophoneUsageDescription": "WhatTheFlat needs access to your microphone to detect pitch and provide the tuner."
|
||||
}
|
||||
},
|
||||
"linux": {
|
||||
"target": "AppImage",
|
||||
"icon": "assets/whattheflat-logo.png"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowToChangeInstallationDirectory": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
# WhatTheFlat 🎸
|
||||
### Product Requirements Document v0.1
|
||||
|
||||
> *Open-source live jam analyzer — helping musicians find the key, follow the harmony, and level up together.*
|
||||
|
||||
---
|
||||
|
||||
## 1. Vision
|
||||
|
||||
**WhatTheFlat** is a free, open-source web app that listens to a live jam session in real time, identifies the key and chord being played, and displays beginner-friendly guidance — scales, next chords, and simple melodic patterns — so every musician in the room can contribute, regardless of experience level.
|
||||
|
||||
The core belief: **jams should be inclusive**. A seasoned guitarist shouldn't have to stop to explain music theory. WhatTheFlat does it for them, silently, in real time.
|
||||
|
||||
---
|
||||
|
||||
## 2. Problem Statement
|
||||
|
||||
- Amateur musicians struggle to find the key when joining a jam they didn't start
|
||||
- Beginners don't know which notes are "safe" to play over a chord progression
|
||||
- There's no affordable, low-friction tool that bridges music theory and live performance
|
||||
- Existing tools (like guitar tuners or DAWs) are either too simple or too complex
|
||||
|
||||
---
|
||||
|
||||
## 3. Target Users
|
||||
|
||||
| User | Description |
|
||||
|---|---|
|
||||
| **The Beginner** | Just started an instrument, wants to follow along without killing the vibe |
|
||||
| **The Intermediate** | Knows a few scales but struggles to apply theory in real time |
|
||||
| **The Jam Host** | Sets up the session and wants everyone to stay in the same key |
|
||||
| **The Teacher** | Uses jams as a teaching tool, wants visual aids for students |
|
||||
|
||||
---
|
||||
|
||||
## 4. Core Features
|
||||
|
||||
### 4.1 Live Key Detection
|
||||
- Capture audio from device microphone in real time
|
||||
- Analyze incoming audio using pitch detection (e.g. YIN algorithm or ML model)
|
||||
- Identify the **root note** and **mode** (major, minor, dorian, mixolydian, etc.)
|
||||
- Display current detected key prominently: e.g. **"You're in A Minor"**
|
||||
- Show confidence level so users understand when detection is uncertain
|
||||
- Latency target: < 500ms from sound to display
|
||||
|
||||
### 4.2 Chord Recognition
|
||||
- Detect the chord being played in real time
|
||||
- Show chord name: e.g. **Am → F → C → G**
|
||||
- Build a live scrolling chord history for the last 30 seconds
|
||||
- Highlight the current chord in the progression
|
||||
|
||||
### 4.3 Chord Progression Suggestions
|
||||
- Based on detected key, suggest common chord progressions that fit
|
||||
- Categorize by genre/feel: Blues, Jazz, Folk, Rock, Pop
|
||||
- Show the progression in Roman numeral notation (I–IV–V) AND actual chord names
|
||||
- Allow user to tap/click a suggested progression to "lock it in" as a reference
|
||||
|
||||
### 4.4 Beginner Melody Helper
|
||||
- For the detected key, show a visual **"safe notes"** panel — a highlighted instrument diagram
|
||||
- Guitar fretboard view
|
||||
- Piano keyboard view
|
||||
- Generic note list (for other instruments)
|
||||
- Show the **pentatonic scale** first (most beginner-friendly), with option to expand to full scale
|
||||
- Highlight notes that sound especially good over the current chord (chord tones)
|
||||
- Show a simple **melodic pattern of the bar** — a looping, beginner-friendly phrase they can follow
|
||||
|
||||
### 4.5 Visual Jam Dashboard
|
||||
- Clean, readable display meant to be seen from across a room
|
||||
- Show at a glance:
|
||||
- Current key
|
||||
- Current chord
|
||||
- Next likely chord (based on progression history)
|
||||
- Safe notes to play
|
||||
- Dark mode by default (stage-friendly)
|
||||
- Large font, high contrast
|
||||
|
||||
### 4.6 AI Music Theory Assistant (Claude Integration)
|
||||
- Powered by Anthropic's Claude API
|
||||
- Users can ask questions like:
|
||||
- *"What's a good lick to play over this chord?"*
|
||||
- *"Why does the F chord sound tense here?"*
|
||||
- *"Give me a beginner melody in this key"*
|
||||
- Claude responds in plain, non-jargon language
|
||||
- Can suggest chord substitutions, extensions (7ths, 9ths), and passing chords
|
||||
- All responses are **beginner-aware** — no unexplained jargon
|
||||
|
||||
---
|
||||
|
||||
## 5. MVP Scope (v0.1)
|
||||
|
||||
For the first open-source demo, the MVP should deliver:
|
||||
|
||||
- [x] Microphone capture in browser (Web Audio API)
|
||||
- [x] Pitch detection → key identification
|
||||
- [x] Display current key and detected chord
|
||||
- [x] Show pentatonic scale for detected key (note list + basic fretboard)
|
||||
- [x] 3–5 suggested chord progressions that fit the key
|
||||
- [x] Claude-powered chat assistant for theory questions
|
||||
- [x] Dark mode UI, mobile-friendly
|
||||
|
||||
**Not in MVP:**
|
||||
- Multi-instrument separation
|
||||
- MIDI input support
|
||||
- Session recording/export
|
||||
- User accounts or history
|
||||
- Real-time collaboration (multiple users same session)
|
||||
|
||||
---
|
||||
|
||||
## 6. Technical Architecture
|
||||
|
||||
### Frontend
|
||||
- **Framework**: React (Vite)
|
||||
- **Audio**: Web Audio API + `pitchy` or `aubio.js` for pitch detection
|
||||
- **Visualizations**: `Tone.js` for music utilities, custom SVG for fretboard/keyboard
|
||||
- **Styling**: Tailwind CSS
|
||||
- **Hosting**: Vercel / Netlify (static deploy)
|
||||
|
||||
### AI Layer
|
||||
- **Model**: Claude (`claude-sonnet-4-20250514`) via Anthropic API
|
||||
- **Usage**:
|
||||
- Theory assistant chat
|
||||
- Chord progression generation given key + genre
|
||||
- Melody suggestion generation
|
||||
- **Prompt strategy**: System prompt primes Claude as a friendly, beginner-aware music teacher
|
||||
|
||||
### Audio Pipeline
|
||||
```
|
||||
Microphone Input
|
||||
↓
|
||||
Web Audio API (AudioContext)
|
||||
↓
|
||||
Pitch Detection (YIN / pitchy)
|
||||
↓
|
||||
Note → Chord Identification
|
||||
↓
|
||||
Key Estimation (sliding window analysis)
|
||||
↓
|
||||
UI Update + Claude Context Refresh
|
||||
```
|
||||
|
||||
### Open Source Stack
|
||||
- Repo: GitHub (MIT License)
|
||||
- CI: GitHub Actions
|
||||
- Contributing: standard fork/PR model with CONTRIBUTING.md
|
||||
|
||||
---
|
||||
|
||||
## 7. Music Theory Engine
|
||||
|
||||
The core theory logic should be implemented as a standalone JS module (`@whattheflat/theory`) so it can be reused or contributed to independently.
|
||||
|
||||
### Required functions:
|
||||
```
|
||||
detectKey(noteHistory[]) → { root, mode, confidence }
|
||||
getChordsInKey(root, mode) → Chord[]
|
||||
getSuggestedProgressions(root, mode, genre?) → Progression[]
|
||||
getPentatonicScale(root, mode) → Note[]
|
||||
getFullScale(root, mode) → Note[]
|
||||
getChordTones(chord) → Note[]
|
||||
getBeginnerPattern(key, currentChord) → MelodicPattern
|
||||
```
|
||||
|
||||
### Modes to support (MVP):
|
||||
- Major (Ionian)
|
||||
- Natural Minor (Aeolian)
|
||||
- Pentatonic Major
|
||||
- Pentatonic Minor
|
||||
|
||||
### Modes to support (v1+):
|
||||
- Dorian, Mixolydian, Lydian, Phrygian
|
||||
- Blues scale
|
||||
- Harmonic minor
|
||||
|
||||
---
|
||||
|
||||
## 8. UX Principles
|
||||
|
||||
1. **Readable at distance** — primary info visible from 2 metres away
|
||||
2. **Zero setup** — tap "Start Listening", grant mic permission, done
|
||||
3. **Non-judgmental** — never says "wrong note", always says "try these"
|
||||
4. **Progressive complexity** — beginners see pentatonic; advanced users can unlock modes, extensions, substitutions
|
||||
5. **Mobile first** — works on a phone propped up on a music stand
|
||||
|
||||
---
|
||||
|
||||
## 9. Beginner Learning Path (stretch goal)
|
||||
|
||||
A guided progression for users who want to improve over time:
|
||||
|
||||
| Level | Unlocks |
|
||||
|---|---|
|
||||
| 🟢 Starter | Pentatonic scale, 3 safe chords |
|
||||
| 🔵 Follower | Full diatonic scale, chord tones highlighted |
|
||||
| 🟣 Contributor | Chord extensions (7th, 9th), passing chords |
|
||||
| 🔴 Improvisor | Modal awareness, substitutions, AI-generated licks |
|
||||
|
||||
Progress is stored in localStorage — no account needed.
|
||||
|
||||
---
|
||||
|
||||
## 10. Open Source Contribution Areas
|
||||
|
||||
| Area | Skills needed |
|
||||
|---|---|
|
||||
| Pitch detection accuracy | DSP, audio engineering |
|
||||
| Music theory engine | Music theory + JavaScript |
|
||||
| Instrument diagrams | SVG, React |
|
||||
| Genre-specific progressions | Music knowledge |
|
||||
| Claude prompt engineering | AI, music theory |
|
||||
| Accessibility (screen readers, colorblind modes) | A11y |
|
||||
| Mobile app wrapper | React Native / Capacitor |
|
||||
| Translation / i18n | Language + music terminology |
|
||||
|
||||
---
|
||||
|
||||
## 11. Success Metrics
|
||||
|
||||
- Time from opening app to understanding what key they're in: **< 10 seconds**
|
||||
- % of beginner users who successfully play a note in the right key on first jam: **target 80%**
|
||||
- GitHub stars at 3 months: **500+**
|
||||
- Average Claude assistant response usefulness (self-reported): **> 4/5**
|
||||
|
||||
---
|
||||
|
||||
## 12. Name & Branding Notes
|
||||
|
||||
- **Name**: WhatTheFlat
|
||||
- **Tagline**: *"Real-time key detection for real humans"*
|
||||
- **Tone**: Warm, slightly cheeky, musician-coded humour
|
||||
- **Logo concept**: A flat symbol (♭) with a question mark or waveform integrated
|
||||
- **Color palette**: Dark background (#0f0f0f), accent in electric purple or warm amber
|
||||
|
||||
---
|
||||
|
||||
*Document maintained by the WhatTheFlat open source community. PRs welcome.*
|
||||
@@ -1,23 +0,0 @@
|
||||
[project]
|
||||
name = "whattheflat"
|
||||
version = "0.1.0"
|
||||
description = "Real-time key detection for real humans"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"fastapi>=0.115.0",
|
||||
"uvicorn[standard]>=0.30.0",
|
||||
"anthropic>=0.40.0",
|
||||
"ollama>=0.4.0",
|
||||
"python-dotenv>=1.0.0",
|
||||
"pydantic>=2.0.0",
|
||||
"pydantic-settings>=2.0.0",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"httpx>=0.27.0",
|
||||
]
|
||||
|
||||
[tool.uv]
|
||||
package = false
|
||||
@@ -0,0 +1,240 @@
|
||||
// Smoke-test harness — asserts the KB registry and the loop matcher are wired
|
||||
// correctly before a merge. Imports the REAL src/data/kb/index.js and
|
||||
// src/lib/match.js (no mocks), runs structural + behavioural checks, and exits
|
||||
// non-zero on any failure so CI can gate on it.
|
||||
//
|
||||
// Run: node scripts/smoke.mjs (exit 1 on any failure, 0 on all-pass)
|
||||
//
|
||||
// Style mirrors scripts/validate-kb.mjs: plain Node ESM, node: imports, a flat
|
||||
// list of checks with ✓/✗ per check, a summary line, and process.exit().
|
||||
import { register } from 'node:module'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import { dirname, join } from 'node:path'
|
||||
|
||||
// match.js imports './theory' extensionless (resolved by Vite at build time, but
|
||||
// raw Node ESM requires the extension). Register a tiny resolve hook that retries
|
||||
// a failed extensionless relative specifier with '.js' appended, so we can import
|
||||
// the REAL match.js unmodified (it's locked to task L-01 — we must not touch it).
|
||||
register(
|
||||
'data:text/javascript,' +
|
||||
encodeURIComponent(`
|
||||
export async function resolve(specifier, context, next) {
|
||||
try {
|
||||
return await next(specifier, context)
|
||||
} catch (e) {
|
||||
if (/^\\.{1,2}\\//.test(specifier) && !/\\.[mc]?js$/.test(specifier)) {
|
||||
return await next(specifier + '.js', context)
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
`),
|
||||
import.meta.url,
|
||||
)
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const load = async (rel) => (await import(pathToFileURL(join(ROOT, rel)).href))
|
||||
|
||||
// ─── Tiny assertion harness ───────────────────────────────────────────────────
|
||||
|
||||
let passed = 0
|
||||
const failures = []
|
||||
|
||||
function check(label, fn) {
|
||||
try {
|
||||
fn()
|
||||
passed++
|
||||
console.log(` ✓ ${label}`)
|
||||
} catch (e) {
|
||||
failures.push(`${label}: ${e.message}`)
|
||||
console.log(` ✗ ${label} — ${e.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
function warn(label, msg) {
|
||||
console.log(` ⚠ ${label} — ${msg} (skipped)`)
|
||||
}
|
||||
|
||||
function assert(cond, msg) {
|
||||
if (!cond) throw new Error(msg)
|
||||
}
|
||||
|
||||
// ─── Load the real modules ────────────────────────────────────────────────────
|
||||
|
||||
const kb = (await load('src/data/kb/index.js')).default
|
||||
const match = await load('src/lib/match.js')
|
||||
const { buildLoopIndex, matchLoopToProgression, findLoopPosition } = match
|
||||
|
||||
// ─── 1. Registry integrity ────────────────────────────────────────────────────
|
||||
|
||||
console.log('\nRegistry integrity:')
|
||||
|
||||
check('KB default export is a non-empty object with ≥1 style', () => {
|
||||
assert(kb && typeof kb === 'object', 'kb default export is not an object')
|
||||
assert(Object.keys(kb).length >= 1, 'kb has no styles')
|
||||
})
|
||||
|
||||
const styleNames = kb && typeof kb === 'object' ? Object.keys(kb) : []
|
||||
const allIds = new Map() // id → style (for uniqueness across the whole KB)
|
||||
|
||||
for (const styleName of styleNames) {
|
||||
const style = kb[styleName]
|
||||
|
||||
check(`style '${styleName}' has meta, progressions[], instruments.guitar`, () => {
|
||||
assert(style && typeof style === 'object', 'style entry is not an object')
|
||||
assert(style.meta && typeof style.meta === 'object', 'missing meta')
|
||||
assert(Array.isArray(style.progressions) && style.progressions.length > 0, 'progressions must be a non-empty array')
|
||||
assert(style.instruments && typeof style.instruments === 'object', 'missing instruments')
|
||||
assert(style.instruments.guitar && typeof style.instruments.guitar === 'object', 'missing instruments.guitar')
|
||||
})
|
||||
|
||||
const progs = Array.isArray(style?.progressions) ? style.progressions : []
|
||||
for (const p of progs) {
|
||||
check(`'${styleName}' progression '${p?.id ?? '?'}' has consistent degrees/qualities/rn/bars + unique id`, () => {
|
||||
assert(typeof p.id === 'string' && p.id.length > 0, 'progression id missing')
|
||||
assert(!allIds.has(p.id), `duplicate id '${p.id}' (also in style '${allIds.get(p.id)}')`)
|
||||
allIds.set(p.id, styleName)
|
||||
const n = Array.isArray(p.degrees) ? p.degrees.length : 0
|
||||
assert(n > 0, 'degrees missing/empty')
|
||||
for (const [field, arr] of [['qualities', p.qualities], ['rn', p.rn], ['bars', p.bars]]) {
|
||||
assert(Array.isArray(arr), `${field} is not an array`)
|
||||
assert(arr.length === n, `${field} length ${arr.length} ≠ degrees length ${n}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 2. Matcher correctness on sample loops ───────────────────────────────────
|
||||
|
||||
console.log('\nMatcher correctness:')
|
||||
|
||||
const index = buildLoopIndex(kb)
|
||||
|
||||
check('buildLoopIndex returns a { byCanonical: Map } shape', () => {
|
||||
assert(index && index.byCanonical instanceof Map, 'byCanonical is not a Map')
|
||||
assert(index.byCanonical.size > 0, 'index is empty')
|
||||
})
|
||||
|
||||
// Helper: rotate a degree array by r so it starts at index r.
|
||||
const rotate = (arr, r) => arr.map((_, i) => arr[(r + i) % arr.length])
|
||||
// Helper: re-base a degree array so its first element is 0 (the loop "shape").
|
||||
const rebase = (arr) => {
|
||||
const base = arr[0]
|
||||
return arr.map((d) => (((d - base) % 12) + 12) % 12)
|
||||
}
|
||||
|
||||
// --- ii–V–I → some jazz 2-5-1, matched:true; derive the expected id from KB ---
|
||||
// (don't hardcode 'jazz-251-major' — look up what the loop actually maps to and
|
||||
// assert its structural truth: the matched progression's degrees rotate to the
|
||||
// loop's degree shape.)
|
||||
{
|
||||
const loop = ['Dm7', 'G7', 'Cmaj7'] // ii–V–I in C → degree shape [0,5,10]
|
||||
const r = matchLoopToProgression(loop, index)
|
||||
|
||||
check('ii–V–I [Dm7,G7,Cmaj7] matches a progression (matched:true)', () => {
|
||||
assert(r.matched === true, `expected matched:true, got ${JSON.stringify(r)}`)
|
||||
assert(typeof r.id === 'string' && r.id.length > 0, 'matched but no id')
|
||||
assert(kb[r.style], `matched style '${r.style}' not in KB`)
|
||||
})
|
||||
|
||||
check("ii–V–I maps to a 2-5-1-shaped progression (derived from KB)", () => {
|
||||
// Structural: the matched progression's degrees, rotated by the reported
|
||||
// rotation to align with the loop, must equal the loop's own degree shape.
|
||||
const loopShape = rebase([2, 7, 0]) // Dm7 G7 Cmaj7 pcs → re-based shape [0,5,10]
|
||||
const kbDeg = r.progression.degrees
|
||||
const rotatedKbShape = rebase(rotate(kbDeg, r.rotation))
|
||||
assert(rotatedKbShape.join(',') === loopShape.join(','),
|
||||
`KB degrees ${kbDeg} rotated by ${r.rotation} → ${rotatedKbShape} ≠ loop shape ${loopShape}`)
|
||||
// Soft: this loop is a major 2-5-1, expect the major-quality (maj7) candidate.
|
||||
assert(/251/.test(r.id) || r.progression.qualities.includes('maj7'),
|
||||
`expected a 2-5-1-shaped id, got '${r.id}'`)
|
||||
})
|
||||
|
||||
// Remember the id for the rotation test below (derived, not hardcoded).
|
||||
globalThis.__ii_v_i_id = r.id
|
||||
}
|
||||
|
||||
// --- A rotation of ii–V–I matches the SAME id with non-zero rotation ----------
|
||||
{
|
||||
const loop = ['G7', 'Cmaj7', 'Dm7'] // V–I–ii: same loop, rotated by 1
|
||||
const r = matchLoopToProgression(loop, index)
|
||||
|
||||
check('rotation [G7,Cmaj7,Dm7] matches the SAME id as ii–V–I', () => {
|
||||
assert(r.matched === true, `expected matched:true, got ${JSON.stringify(r)}`)
|
||||
assert(r.id === globalThis.__ii_v_i_id,
|
||||
`rotation matched '${r.id}', expected same id '${globalThis.__ii_v_i_id}'`)
|
||||
})
|
||||
|
||||
check('rotation reports a non-zero rotation index', () => {
|
||||
assert(r.rotation !== 0, `expected non-zero rotation, got ${r.rotation}`)
|
||||
assert(r.rotation > 0 && r.rotation < loop.length, `rotation ${r.rotation} out of range`)
|
||||
// The rotation index should point at the loop slot aligning with KB degrees[0].
|
||||
// KB ii–V–I starts on ii (Dm7); Dm7 is at loop index 2 here.
|
||||
assert(loop[r.rotation] === 'Dm7', `loop[${r.rotation}] is '${loop[r.rotation]}', expected 'Dm7'`)
|
||||
})
|
||||
}
|
||||
|
||||
// --- I–V–vi–IV axis loop → axis progression (pop may be absent) ----------------
|
||||
{
|
||||
const loop = ['C', 'G', 'Am', 'F'] // I–V–vi–IV, degree shape [0,7,9,5]
|
||||
const r = matchLoopToProgression(loop, index)
|
||||
const loopShape = rebase([0, 7, 9, 5])
|
||||
|
||||
if (r.matched) {
|
||||
check('axis [C,G,Am,F] matches an axis-shaped progression', () => {
|
||||
assert(kb[r.style], `matched style '${r.style}' not in KB`)
|
||||
// Whatever style owns the axis, its degrees must rotate to the loop shape.
|
||||
const rotatedKbShape = rebase(rotate(r.progression.degrees, r.rotation))
|
||||
assert(rotatedKbShape.join(',') === loopShape.join(','),
|
||||
`matched '${r.id}' degrees ${r.progression.degrees} rotated by ${r.rotation} don't match axis shape ${loopShape}`)
|
||||
// The axis is the four-chord I–V–vi–IV; sanity-check it's a 4-chord loop.
|
||||
assert(r.progression.degrees.length === 4, `expected a 4-chord axis, got length ${r.progression.degrees.length}`)
|
||||
})
|
||||
} else {
|
||||
warn('axis [C,G,Am,F] match', 'no axis-shaped 4-chord progression in current KB')
|
||||
}
|
||||
}
|
||||
|
||||
// --- Chromatic / garbage loop → matched:false, no throw -----------------------
|
||||
{
|
||||
check('chromatic loop [C,C#,D] returns matched:false cleanly (no throw)', () => {
|
||||
const r = matchLoopToProgression(['C', 'C#', 'D'], index)
|
||||
assert(r && r.matched === false, `expected matched:false, got ${JSON.stringify(r)}`)
|
||||
assert(r.id === null, `expected id:null on no-match, got ${r.id}`)
|
||||
})
|
||||
}
|
||||
|
||||
// --- findLoopPosition: in-range index for a known loop, -1 for no-match --------
|
||||
{
|
||||
const loop = ['Dm7', 'G7', 'Cmaj7']
|
||||
|
||||
check('findLoopPosition returns an in-range index for a known loop', () => {
|
||||
const history = ['Dm7', 'G7'] // player is on G7
|
||||
const pos = findLoopPosition(history, loop)
|
||||
assert(Number.isInteger(pos), `expected an integer, got ${pos}`)
|
||||
assert(pos >= 0 && pos < loop.length, `index ${pos} out of range [0,${loop.length})`)
|
||||
assert(loop[pos] === 'G7', `loop[${pos}] is '${loop[pos]}', expected 'G7'`)
|
||||
})
|
||||
|
||||
check('findLoopPosition returns -1 when the last chord is not in the loop', () => {
|
||||
const pos = findLoopPosition(['Ebmaj7'], loop)
|
||||
assert(pos === -1, `expected -1, got ${pos}`)
|
||||
})
|
||||
|
||||
check('findLoopPosition returns -1 on empty inputs', () => {
|
||||
assert(findLoopPosition([], loop) === -1, 'empty history should be -1')
|
||||
assert(findLoopPosition(['Dm7'], []) === -1, 'empty loop should be -1')
|
||||
})
|
||||
}
|
||||
|
||||
// ─── 3. Summary + exit code ───────────────────────────────────────────────────
|
||||
|
||||
const total = passed + failures.length
|
||||
console.log('')
|
||||
if (failures.length) {
|
||||
console.error(`✗ Smoke test FAILED — ${failures.length}/${total} check(s) failed:\n`)
|
||||
for (const f of failures) console.error(' ' + f)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`✓ Smoke test passed — ${passed}/${total} checks green (${styleNames.length} styles, ${allIds.size} progressions)`)
|
||||
process.exit(0)
|
||||
@@ -0,0 +1,192 @@
|
||||
// KB quality gate — validates src/data/kb/ against the contract in src/data/kb/SCHEMA.md.
|
||||
// Run: node scripts/validate-kb.mjs (exit 1 on any error)
|
||||
import { readdirSync, existsSync } from 'node:fs'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { CHORD_TYPES } from '../src/lib/theory.js'
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const KB = join(ROOT, 'src', 'data', 'kb')
|
||||
|
||||
const MODES = ['major', 'minor', 'dorian', 'phrygian', 'lydian', 'mixolydian']
|
||||
const OPEN_PC = [4, 9, 2, 7, 11, 4] // EADGBe low-E first
|
||||
const PERFECT_FIFTH = 7
|
||||
const BASS_TOKENS = ['R', 'b3', '3', '5', '6', 'b7', '7', '9', 'O', 'chrom>', 'chrom<', '5>', 'x', '-']
|
||||
const MIN_PROGRESSIONS = 4
|
||||
const MIN_PLAYS = 2
|
||||
const MAX_SPAN = 4
|
||||
|
||||
const errors = []
|
||||
const err = (where, msg) => errors.push(`${where}: ${msg}`)
|
||||
|
||||
// Resolve a degree string ('3', 'b9', '13'…) to a pitch class relative to the
|
||||
// chord root, through the quality's intervals where the degree is quality-dependent.
|
||||
function resolveDegree(deg, quality) {
|
||||
const iv = CHORD_TYPES[quality].intervals
|
||||
const fixed = { 1: 0, b9: 1, 9: 2, '#9': 3, 11: 5, '#11': 6, b5: 6, b13: 8, 13: 9, 6: 9, b3: 3, b7: 10 }
|
||||
if (deg === '3') return iv.find(i => i === 3 || i === 4) ?? iv.find(i => i === 2 || i === 5) ?? null
|
||||
if (deg === '5') return iv.find(i => i === 6 || i === 7 || i === 8) ?? null
|
||||
if (deg === '7') return iv.find(i => i === 9 || i === 10 || i === 11) ?? null
|
||||
return fixed[deg] ?? null
|
||||
}
|
||||
|
||||
function checkGuitarShape(where, chordStep, quality) {
|
||||
const { shape, extensions = [] } = chordStep
|
||||
if (!shape) return err(where, 'missing shape')
|
||||
const strings = shape.offsets ?? shape.frets
|
||||
if (!Array.isArray(strings) || strings.length !== 6)
|
||||
return err(where, 'offsets/frets must be an array of 6 (low E first)')
|
||||
const isMovable = !!shape.offsets
|
||||
|
||||
if (isMovable) {
|
||||
if (!(shape.rootStr >= 1 && shape.rootStr <= 6)) return err(where, `bad rootStr ${shape.rootStr}`)
|
||||
if (strings[6 - shape.rootStr] !== 0) return err(where, 'offset on the root string must be 0')
|
||||
} else {
|
||||
if (!(shape.onlyRoot >= 0 && shape.onlyRoot <= 11)) return err(where, 'open shape needs onlyRoot (pc 0-11)')
|
||||
}
|
||||
|
||||
const fretted = strings.filter(f => f !== 'x')
|
||||
if (fretted.some(f => !Number.isInteger(f) || f < -2 || f > 15))
|
||||
return err(where, `bad fret values: ${JSON.stringify(strings)}`)
|
||||
const nonOpen = fretted.filter(f => f !== 0)
|
||||
if (nonOpen.length && Math.max(...nonOpen) - Math.min(...nonOpen) > MAX_SPAN)
|
||||
return err(where, `fret span > ${MAX_SPAN} — not intermediate-friendly`)
|
||||
|
||||
// Pitch-class verification: every sounded note must belong to the chord
|
||||
// (quality intervals + declared extensions); defining tones must be present.
|
||||
const iv = CHORD_TYPES[quality].intervals
|
||||
const allowed = new Set(iv)
|
||||
for (const ext of extensions) {
|
||||
const pc = resolveDegree(ext, quality)
|
||||
if (pc === null) return err(where, `unresolvable extension '${ext}' for ${quality}`)
|
||||
allowed.add(pc)
|
||||
}
|
||||
const rootRel = isMovable ? (12 - OPEN_PC[6 - shape.rootStr]) % 12 : null
|
||||
const sounded = new Set()
|
||||
strings.forEach((f, i) => {
|
||||
if (f === 'x') return
|
||||
const pc = isMovable
|
||||
? (OPEN_PC[i] + rootRel + f + 24) % 12
|
||||
: (OPEN_PC[i] + f - shape.onlyRoot + 24) % 12
|
||||
sounded.add(pc)
|
||||
})
|
||||
for (const pc of sounded)
|
||||
if (!allowed.has(pc)) return err(where, `sounded pc ${pc} is not in ${quality} (+ext) — shape misspells the chord`)
|
||||
const required = iv.filter(i =>
|
||||
i !== PERFECT_FIFTH
|
||||
&& !(chordStep.rootless && i === 0)
|
||||
&& !(chordStep.omit3 && (i === 3 || i === 4)))
|
||||
for (const pc of required)
|
||||
if (!sounded.has(pc)) return err(where, `defining tone pc ${pc} of ${quality} missing from shape`)
|
||||
}
|
||||
|
||||
function checkPianoRecipe(where, chordStep, quality) {
|
||||
const { recipe } = chordStep
|
||||
if (!recipe) return err(where, 'missing recipe')
|
||||
for (const hand of ['LH', 'RH']) {
|
||||
const degs = recipe[hand]
|
||||
if (degs === undefined) continue
|
||||
if (!Array.isArray(degs) || !degs.length) return err(where, `${hand} must be a non-empty array`)
|
||||
if (degs.length > 5) return err(where, `${hand} has ${degs.length} notes — one hand, max 5`)
|
||||
for (const d of degs)
|
||||
if (resolveDegree(d, quality) === null) err(where, `unresolvable degree '${d}' for ${quality}`)
|
||||
}
|
||||
if (recipe.LH === undefined && recipe.RH === undefined) err(where, 'recipe needs LH and/or RH')
|
||||
}
|
||||
|
||||
function checkBassPlay(where, play, prog) {
|
||||
const totalBars = prog.bars.reduce((a, b) => a + b, 0)
|
||||
if (!Array.isArray(play.bars) || play.bars.length !== totalBars)
|
||||
return err(where, `bars length ${play.bars?.length} ≠ progression total ${totalBars}`)
|
||||
play.bars.forEach((bar, i) => {
|
||||
if (!Array.isArray(bar.beats) || !bar.beats.length) return err(`${where} bar ${i}`, 'missing beats')
|
||||
for (const b of bar.beats)
|
||||
if (!BASS_TOKENS.includes(b)) err(`${where} bar ${i}`, `unknown beat token '${b}'`)
|
||||
})
|
||||
}
|
||||
|
||||
async function loadModule(path) {
|
||||
return (await import(pathToFileURL(path).href)).default
|
||||
}
|
||||
|
||||
const styleDirs = readdirSync(KB, { withFileTypes: true }).filter(d => d.isDirectory()).map(d => d.name)
|
||||
if (!styleDirs.length) { console.error('No style folders in src/data/kb/'); process.exit(1) }
|
||||
|
||||
const registry = existsSync(join(KB, 'index.js')) ? await loadModule(join(KB, 'index.js')) : null
|
||||
if (!registry) err('kb/index.js', 'registry missing')
|
||||
|
||||
const allIds = new Set()
|
||||
let totals = { styles: 0, progressions: 0, plays: 0 }
|
||||
|
||||
for (const style of styleDirs) {
|
||||
const dir = join(KB, style)
|
||||
const w = `kb/${style}`
|
||||
if (registry && !registry[style]) err('kb/index.js', `style '${style}' not registered`)
|
||||
|
||||
const meta = existsSync(join(dir, 'meta.js')) ? await loadModule(join(dir, 'meta.js')) : null
|
||||
if (!meta) { err(w, 'meta.js missing'); continue }
|
||||
if (meta.id !== style) err(`${w}/meta.js`, `id '${meta.id}' ≠ folder '${style}'`)
|
||||
for (const f of ['label', 'feel', 'character']) if (!meta[f]) err(`${w}/meta.js`, `missing ${f}`)
|
||||
|
||||
const progs = existsSync(join(dir, 'progressions.js')) ? await loadModule(join(dir, 'progressions.js')) : null
|
||||
if (!Array.isArray(progs) || !progs.length) { err(w, 'progressions.js missing/empty'); continue }
|
||||
if (progs.length < MIN_PROGRESSIONS) err(w, `${progs.length} progressions < ${MIN_PROGRESSIONS}`)
|
||||
|
||||
const progById = {}
|
||||
for (const p of progs) {
|
||||
const pw = `${w}/progressions.js [${p.id}]`
|
||||
if (!p.id?.startsWith(`${style}-`)) err(pw, `id must start with '${style}-'`)
|
||||
if (allIds.has(p.id)) err(pw, 'duplicate id'); allIds.add(p.id)
|
||||
progById[p.id] = p
|
||||
const n = p.degrees?.length
|
||||
if (!n) { err(pw, 'degrees missing'); continue }
|
||||
for (const [field, arr] of [['rn', p.rn], ['qualities', p.qualities], ['bars', p.bars]])
|
||||
if (!Array.isArray(arr) || arr.length !== n) err(pw, `${field} length ≠ degrees length`)
|
||||
if (p.degrees.some(d => !Number.isInteger(d) || d < 0 || d > 11)) err(pw, 'degrees must be ints 0-11')
|
||||
for (const q of p.qualities ?? []) if (!CHORD_TYPES[q]) err(pw, `unknown quality '${q}'`)
|
||||
if (!MODES.includes(p.mode)) err(pw, `unknown mode '${p.mode}'`)
|
||||
if (!Array.isArray(p.songs) || !p.songs.length) err(pw, 'songs missing')
|
||||
if (!p.tip) err(pw, 'tip missing')
|
||||
}
|
||||
totals.styles++; totals.progressions += progs.length
|
||||
|
||||
for (const inst of ['guitar', 'piano', 'bass']) {
|
||||
const file = join(dir, `${inst}.js`)
|
||||
if (!existsSync(file)) continue
|
||||
const pack = await loadModule(file)
|
||||
const iw = `${w}/${inst}.js`
|
||||
if (!pack.styleIntro) err(iw, 'styleIntro missing')
|
||||
if (!Array.isArray(pack.comping) || !pack.comping.length) err(iw, 'comping missing')
|
||||
if (inst !== 'bass' && (!pack.improv?.scales?.length || !pack.improv?.targetNotes))
|
||||
err(iw, 'improv.scales / improv.targetNotes required')
|
||||
|
||||
for (const p of progs)
|
||||
if ((pack.plays?.[p.id]?.length ?? 0) < MIN_PLAYS)
|
||||
err(iw, `progression '${p.id}' has < ${MIN_PLAYS} plays`)
|
||||
|
||||
for (const [pid, plays] of Object.entries(pack.plays ?? {})) {
|
||||
const prog = progById[pid]
|
||||
if (!prog) { err(iw, `plays key '${pid}' is not a progression of this style`); continue }
|
||||
plays.forEach((play, pi) => {
|
||||
const lw = `${iw} ${pid} play[${pi}] "${play.label ?? '?'}"`
|
||||
if (!play.label || !play.level || !play.tips) err(lw, 'label/level/tips required')
|
||||
totals.plays++
|
||||
if (inst === 'bass') return checkBassPlay(lw, play, prog)
|
||||
if (!Array.isArray(play.chords) || play.chords.length !== prog.degrees.length)
|
||||
return err(lw, `chords length ≠ progression length ${prog.degrees.length}`)
|
||||
play.chords.forEach((step, ci) => {
|
||||
const cw = `${lw} chord[${ci}] (${prog.rn[ci]})`
|
||||
if (inst === 'guitar') checkGuitarShape(cw, step, prog.qualities[ci])
|
||||
else checkPianoRecipe(cw, step, prog.qualities[ci])
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(`✗ KB validation failed — ${errors.length} error(s):\n`)
|
||||
for (const e of errors) console.error(' ' + e)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`✓ KB valid — ${totals.styles} style(s), ${totals.progressions} progressions, ${totals.plays} plays`)
|
||||
@@ -0,0 +1,681 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react'
|
||||
import AudioCapture from './components/AudioCapture'
|
||||
import ProgressionBanner from './components/ProgressionBanner'
|
||||
import ProgressionSuggestions from './components/ProgressionSuggestions'
|
||||
import Fretboard from './components/Fretboard'
|
||||
import BassFretboard from './components/BassFretboard'
|
||||
import Tuner from './components/Tuner'
|
||||
import Piano from './components/Piano'
|
||||
import Settings from './components/Settings'
|
||||
import DebugView from './components/DebugView'
|
||||
import DrumView from './components/DrumView'
|
||||
import { NOTES, detectKey, detectTopKeys, matchChordFromChroma, detectRepeatingProgression, getChordTones, getChordCandidates, getNoteHistoryAnalysis } from './lib/theory'
|
||||
import ChordDetailModal from './components/ChordDetailModal'
|
||||
import CurrentJamPanel from './components/CurrentJamPanel'
|
||||
import LoopStation from './components/LoopStation'
|
||||
import JamGuide from './components/JamGuide'
|
||||
import { useLoopEngine } from './services/loopEngine'
|
||||
import settingIcon from './assets/setting-icon.png'
|
||||
|
||||
const DEFAULTS = {
|
||||
// Key detection
|
||||
noteHistorySize: 2000, // ~60s of notes — stable across a song section
|
||||
keyVoteWindow: 30, // rolling window of key votes
|
||||
keyVoteThreshold: 20, // 67% consensus — locks in after a few bars
|
||||
chordNoteBoost: 3,
|
||||
// Chord detection
|
||||
chromaSmooth: 8, // 8 frames ≈ 130ms window, checks chord at ~7.5 Hz
|
||||
chordVoteThreshold: 2, // 2 consecutive matches ≈ 260ms — works at any BPM
|
||||
chordMinScore: 0.35, // lenient enough for live guitar signal
|
||||
// Audio input
|
||||
minClarity: 0.80,
|
||||
minVolume: 0.01,
|
||||
// Selected device (null = system default)
|
||||
audioDeviceId: null,
|
||||
}
|
||||
|
||||
function loadStored(key, fallback) {
|
||||
try { const v = localStorage.getItem(key); return v !== null ? JSON.parse(v) : fallback }
|
||||
catch { return fallback }
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
// ── Config ───────────────────────────────────────────────────────────────────
|
||||
const [config, setConfig] = useState(() => ({ ...DEFAULTS, ...loadStored('wtf_config', {}) }))
|
||||
const configRef = useRef(config)
|
||||
useEffect(() => { configRef.current = config; localStorage.setItem('wtf_config', JSON.stringify(config)) }, [config])
|
||||
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
|
||||
function updateConfig(key, val) {
|
||||
setConfig(prev => ({ ...prev, [key]: val }))
|
||||
}
|
||||
|
||||
// ── Listening state ──────────────────────────────────────────────────────────
|
||||
const [isListening, setIsListening] = useState(false)
|
||||
|
||||
// ── Instrument view + tuner ───────────────────────────────────────────────────
|
||||
const [instrument, setInstrument] = useState('piano') // 'piano' | 'guitar' | 'bass'
|
||||
const [showTuner, setShowTuner] = useState(false)
|
||||
const [showDebug, setShowDebug] = useState(false)
|
||||
const [showDrumView, setShowDrumView] = useState(false)
|
||||
const [monoColor, setMonoColor] = useState(() => loadStored('wtf_monoColor', false))
|
||||
|
||||
// ── Jam Guide → Fretboard cross-link (D-03) ──────────────────────────────────
|
||||
// When a Roadmap station is tapped, JamGuide reports its {rootPc, quality}
|
||||
// here and the main Fretboard highlights that chord's guide tones (3rd/7th).
|
||||
// null = no station focused (Fretboard renders normally). Purely UI state —
|
||||
// NOT read by any audio callback, so it stays out of the ref-sync contract.
|
||||
const [jamFocusChord, setJamFocusChord] = useState(null) // { rootPc, quality } | null
|
||||
|
||||
// ── Mic permission error ──────────────────────────────────────────────────────
|
||||
const [micError, setMicError] = useState(null)
|
||||
|
||||
// ── Debug data ────────────────────────────────────────────────────────────────
|
||||
const [debugChroma, setDebugChroma] = useState(null)
|
||||
const [debugCandidates, setDebugCandidates] = useState([])
|
||||
const [debugNoteAnalysis, setDebugNoteAnalysis] = useState(null)
|
||||
const [debugWaveform, setDebugWaveform] = useState(null)
|
||||
|
||||
// ── Stable refs for values used inside callbacks ──────────────────────────────
|
||||
const showDebugRef = useRef(showDebug)
|
||||
const showDrumViewRef = useRef(showDrumView)
|
||||
const lockedKeyRef = useRef(null)
|
||||
const listenStartRef = useRef(null)
|
||||
useEffect(() => { showDebugRef.current = showDebug }, [showDebug])
|
||||
useEffect(() => { showDrumViewRef.current = showDrumView }, [showDrumView])
|
||||
useEffect(() => { localStorage.setItem('wtf_monoColor', JSON.stringify(monoColor)) }, [monoColor])
|
||||
useEffect(() => { if (isListening) listenStartRef.current = Date.now() }, [isListening])
|
||||
|
||||
// ── BPM estimation from onset timestamps ─────────────────────────────────────
|
||||
const [bpm, setBpm] = useState(null)
|
||||
const onsetTimestampsRef = useRef([])
|
||||
const bpmSmoothRef = useRef(null)
|
||||
|
||||
// ── Loop station ─────────────────────────────────────────────────────────────
|
||||
const {
|
||||
slots,
|
||||
masterLen,
|
||||
setStream: loopSetStream,
|
||||
handleSlotClick,
|
||||
commitTrim,
|
||||
cancelRecord,
|
||||
retrimSlot,
|
||||
deleteSlot,
|
||||
setVolume: loopSetVolume,
|
||||
addSlot: loopAddSlot,
|
||||
audioCtxRef: loopAudioCtxRef,
|
||||
masterStartRef: loopMasterStartRef,
|
||||
masterLenRef: loopMasterLenRef,
|
||||
} = useLoopEngine(bpm)
|
||||
|
||||
// ── Key: auto-detected + optional lock ───────────────────────────────────────
|
||||
const [keyInfo, setKeyInfo] = useState(null) // auto-detected
|
||||
const [lockedKey, setLockedKey] = useState(null) // { root, mode } or null
|
||||
useEffect(() => { lockedKeyRef.current = lockedKey }, [lockedKey])
|
||||
const [lockRoot, setLockRoot] = useState('A')
|
||||
const [lockMode, setLockMode] = useState('minor')
|
||||
|
||||
const effectiveKey = lockedKey ?? keyInfo
|
||||
|
||||
// ── Chord state ───────────────────────────────────────────────────────────────
|
||||
const [chordHistory, setChordHistory] = useState([])
|
||||
const [detectedProgression, setDetectedProgression] = useState(null)
|
||||
const [selectedChord, setSelectedChord] = useState(null)
|
||||
|
||||
// ── Top key candidates (shown as quick-lock chips) ────────────────────────────
|
||||
const [topKeyCandidates, setTopKeyCandidates] = useState([])
|
||||
|
||||
// ── Internal refs ─────────────────────────────────────────────────────────────
|
||||
const noteHistoryRef = useRef([])
|
||||
const keyVotesRef = useRef([])
|
||||
const effectiveKeyRef = useRef(null)
|
||||
const chromaRingRef = useRef(
|
||||
Array.from({ length: DEFAULTS.chromaSmooth }, () => new Float32Array(12))
|
||||
)
|
||||
const chromaIdxRef = useRef(0)
|
||||
const chordVotesRef = useRef([])
|
||||
const progressionVoteRef = useRef(null)
|
||||
const progressionMissRef = useRef(0)
|
||||
const pendingKeyRef = useRef(null)
|
||||
|
||||
// Keep refs in sync
|
||||
useEffect(() => { effectiveKeyRef.current = effectiveKey }, [effectiveKey])
|
||||
|
||||
// Re-init chroma ring when chromaSmooth changes
|
||||
useEffect(() => {
|
||||
chromaRingRef.current = Array.from(
|
||||
{ length: config.chromaSmooth },
|
||||
() => new Float32Array(12)
|
||||
)
|
||||
chromaIdxRef.current = 0
|
||||
}, [config.chromaSmooth])
|
||||
|
||||
// ── Detect progression — require 2 consecutive identical results to commit ────
|
||||
useEffect(() => {
|
||||
const detected = detectRepeatingProgression(chordHistory)
|
||||
if (!detected) {
|
||||
progressionMissRef.current++
|
||||
// Clear stale loop after 4 chord changes with no pattern found
|
||||
if (progressionMissRef.current >= 4) {
|
||||
setDetectedProgression(null)
|
||||
progressionVoteRef.current = null
|
||||
}
|
||||
return
|
||||
}
|
||||
progressionMissRef.current = 0
|
||||
const key = detected.join(',')
|
||||
if (progressionVoteRef.current === key) {
|
||||
setDetectedProgression(detected)
|
||||
} else {
|
||||
progressionVoteRef.current = key
|
||||
}
|
||||
}, [chordHistory])
|
||||
|
||||
// ── New song — full reset ─────────────────────────────────────────────────────
|
||||
function newSong() {
|
||||
const cfg = configRef.current
|
||||
noteHistoryRef.current = []
|
||||
keyVotesRef.current = []
|
||||
chordVotesRef.current = []
|
||||
progressionVoteRef.current = null
|
||||
progressionMissRef.current = 0
|
||||
pendingKeyRef.current = null
|
||||
chromaIdxRef.current = 0
|
||||
chromaRingRef.current = Array.from({ length: cfg.chromaSmooth }, () => new Float32Array(12))
|
||||
onsetTimestampsRef.current = []
|
||||
bpmSmoothRef.current = null
|
||||
listenStartRef.current = Date.now()
|
||||
setKeyInfo(null)
|
||||
setLockedKey(null)
|
||||
effectiveKeyRef.current = null
|
||||
setChordHistory([])
|
||||
setDetectedProgression(null)
|
||||
setTopKeyCandidates([])
|
||||
setBpm(null)
|
||||
setMicError(null)
|
||||
setDebugChroma(null)
|
||||
setDebugCandidates([])
|
||||
setDebugNoteAnalysis(null)
|
||||
setDebugWaveform(null)
|
||||
}
|
||||
|
||||
// ── Key lock handlers ─────────────────────────────────────────────────────────
|
||||
function applyLock() {
|
||||
const info = { root: lockRoot, mode: lockMode, confidence: 1 }
|
||||
setLockedKey(info)
|
||||
effectiveKeyRef.current = info
|
||||
chordVotesRef.current = []
|
||||
}
|
||||
|
||||
function quickLock({ root, mode, confidence }) {
|
||||
const info = { root, mode, confidence }
|
||||
setLockedKey(info)
|
||||
effectiveKeyRef.current = info
|
||||
chordVotesRef.current = []
|
||||
}
|
||||
|
||||
function removeLock() {
|
||||
setLockedKey(null)
|
||||
effectiveKeyRef.current = keyInfo
|
||||
}
|
||||
|
||||
// ── Waveform handler: feeds oscilloscope / drum view ─────────────────────────
|
||||
const handleWaveform = useCallback((data) => {
|
||||
if (showDebugRef.current || showDrumViewRef.current) {
|
||||
setDebugWaveform({ ...data, onsets: [...onsetTimestampsRef.current] })
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Note handler: drives key detection (pitch-based) ──────────────────────────
|
||||
const handleNote = useCallback(({ pitchClass }) => {
|
||||
const cfg = configRef.current
|
||||
const history = noteHistoryRef.current
|
||||
history.push(pitchClass)
|
||||
if (history.length > cfg.noteHistorySize) history.shift()
|
||||
if (history.length < 10) return
|
||||
if (history.length % 5 !== 0) return
|
||||
|
||||
const result = detectKey(history)
|
||||
setTopKeyCandidates(detectTopKeys(history))
|
||||
if (showDebugRef.current) {
|
||||
const analysis = getNoteHistoryAnalysis(history)
|
||||
analysis.sessionSecs = listenStartRef.current ? Math.floor((Date.now() - listenStartRef.current) / 1000) : 0
|
||||
setDebugNoteAnalysis(analysis)
|
||||
}
|
||||
if (result.confidence < 0.5) return
|
||||
|
||||
const votes = keyVotesRef.current
|
||||
votes.push(`${result.root}_${result.mode}`)
|
||||
if (votes.length > cfg.keyVoteWindow) votes.shift()
|
||||
|
||||
const counts = {}
|
||||
for (const v of votes) counts[v] = (counts[v] || 0) + 1
|
||||
const [winner, count] = Object.entries(counts).sort((a, b) => b[1] - a[1])[0]
|
||||
|
||||
if (count >= cfg.keyVoteThreshold) {
|
||||
const [root, mode] = winner.split('_')
|
||||
const candidateKey = `${root}_${mode}`
|
||||
|
||||
setKeyInfo(prev => {
|
||||
const currentKey = prev ? `${prev.root}_${prev.mode}` : null
|
||||
|
||||
if (currentKey === candidateKey) {
|
||||
pendingKeyRef.current = null
|
||||
return { root, mode, confidence: result.confidence }
|
||||
}
|
||||
|
||||
if (pendingKeyRef.current === candidateKey) {
|
||||
pendingKeyRef.current = null
|
||||
if (!lockedKeyRef.current) chordVotesRef.current = []
|
||||
return { root, mode, confidence: result.confidence }
|
||||
}
|
||||
|
||||
pendingKeyRef.current = candidateKey
|
||||
return prev
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Chroma handler: drives chord detection ────────────────────────────────────
|
||||
const handleChroma = useCallback((chroma, bassPC) => {
|
||||
const cfg = configRef.current
|
||||
const ring = chromaRingRef.current
|
||||
ring[chromaIdxRef.current % cfg.chromaSmooth] = chroma
|
||||
chromaIdxRef.current++
|
||||
if (chromaIdxRef.current % cfg.chromaSmooth !== 0) return
|
||||
|
||||
const key = effectiveKeyRef.current
|
||||
if (!key) return
|
||||
|
||||
const avg = new Float32Array(12)
|
||||
for (const frame of ring) for (let i = 0; i < 12; i++) avg[i] += frame[i]
|
||||
for (let i = 0; i < 12; i++) avg[i] /= cfg.chromaSmooth
|
||||
|
||||
if (showDebugRef.current) {
|
||||
setDebugChroma([...avg])
|
||||
setDebugCandidates(getChordCandidates(avg, key, bassPC, 5))
|
||||
}
|
||||
|
||||
// Stability gate — if chroma is still changing across frames, we're mid-transition.
|
||||
// Compute per-bin variance across the ring; bail if any bin is fluctuating heavily.
|
||||
let maxVar = 0
|
||||
for (let i = 0; i < 12; i++) {
|
||||
let v = 0
|
||||
for (const frame of ring) { const d = frame[i] - avg[i]; v += d * d }
|
||||
if (v / cfg.chromaSmooth > maxVar) maxVar = v / cfg.chromaSmooth
|
||||
}
|
||||
if (maxVar > 0.05) return
|
||||
|
||||
const chord = matchChordFromChroma(avg, key, bassPC, false, cfg.chordMinScore)
|
||||
if (!chord) {
|
||||
chordVotesRef.current = []
|
||||
return
|
||||
}
|
||||
|
||||
const votes = chordVotesRef.current
|
||||
votes.push(chord)
|
||||
if (votes.length > cfg.chordVoteThreshold) votes.shift()
|
||||
|
||||
if (votes.length >= cfg.chordVoteThreshold && votes.every(v => v === votes[0])) {
|
||||
const winner = votes[0]
|
||||
setChordHistory(prev => {
|
||||
if (prev[prev.length - 1] === winner) return prev
|
||||
return [...prev.slice(-48), winner]
|
||||
})
|
||||
|
||||
// Inject chord tones into note history to anchor key detection
|
||||
const chordPCs = getChordTones(winner)
|
||||
.map(n => NOTES.indexOf(n))
|
||||
.filter(i => i >= 0)
|
||||
const history = noteHistoryRef.current
|
||||
for (let j = 0; j < cfg.chordNoteBoost; j++) {
|
||||
for (const pc of chordPCs) history.push(pc)
|
||||
}
|
||||
while (history.length > cfg.noteHistorySize) history.shift()
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Onset handler: drives BPM estimation via tempo histogram ────────────────
|
||||
// Pairwise inter-onset intervals are folded into 55-220 BPM and vote in a
|
||||
// histogram. Works with drums, guitar, piano, or mixed — whatever fires most
|
||||
// consistently wins. Only updates when there's a clear peak (≥20% of votes).
|
||||
const handleOnset = useCallback(() => {
|
||||
const ts = onsetTimestampsRef.current
|
||||
ts.push(performance.now())
|
||||
if (ts.length > 64) ts.shift()
|
||||
if (ts.length < 4) return
|
||||
|
||||
const recent = ts.slice(-24)
|
||||
const bins = new Float32Array(221) // index = BPM (55–220)
|
||||
|
||||
for (let i = 0; i < recent.length - 1; i++) {
|
||||
for (let j = i + 1; j < recent.length && j < i + 8; j++) {
|
||||
const ms = recent[j] - recent[i]
|
||||
if (ms < 140 || ms > 6000) continue
|
||||
|
||||
// Fold interval into 55-220 BPM range (handles subdivisions & half-time)
|
||||
let beatMs = ms
|
||||
while (beatMs > 1091) beatMs /= 2
|
||||
while (beatMs < 273) beatMs *= 2
|
||||
if (beatMs < 273 || beatMs > 1091) continue
|
||||
|
||||
const bpm = Math.round(60000 / beatMs)
|
||||
if (bpm >= 55 && bpm <= 220) bins[bpm] += 1 / (j - i) // weight closer pairs more
|
||||
}
|
||||
}
|
||||
|
||||
// Find peak with ±1 BPM smoothing
|
||||
let best = 0, bestBpm = 0
|
||||
for (let b = 56; b <= 219; b++) {
|
||||
const s = bins[b - 1] + bins[b] + bins[b + 1]
|
||||
if (s > best) { best = s; bestBpm = b }
|
||||
}
|
||||
|
||||
const total = bins.reduce((a, v) => a + v, 0)
|
||||
if (total < 1 || best / total < 0.2) return // no clear consensus yet
|
||||
|
||||
const prev = bpmSmoothRef.current
|
||||
bpmSmoothRef.current = prev === null ? bestBpm : 0.25 * bestBpm + 0.75 * prev
|
||||
setBpm(Math.round(bpmSmoothRef.current))
|
||||
}, [])
|
||||
|
||||
const currentChord = chordHistory[chordHistory.length - 1]
|
||||
|
||||
if (showSettings) {
|
||||
return (
|
||||
<Settings
|
||||
config={config}
|
||||
onChange={updateConfig}
|
||||
onClose={() => setShowSettings(false)}
|
||||
onReset={() => { setConfig(DEFAULTS); setMonoColor(false) }}
|
||||
monoColor={monoColor}
|
||||
onMonoColorChange={setMonoColor}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-surface text-white p-3">
|
||||
|
||||
{/* ── Header ── */}
|
||||
<header className="mb-2 flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-accent">
|
||||
WhatTheFlat <span className="text-gray-600">♭?</span> <span className="text-amber-400">- JamBuddy</span>
|
||||
</h1>
|
||||
<p className="text-xs text-gray-600">Real-time key detection for live jams</p>
|
||||
</div>
|
||||
<div className="flex gap-2 items-center">
|
||||
<button
|
||||
onClick={() => setShowSettings(true)}
|
||||
className="p-2 rounded-full border border-border hover:border-gray-400 transition-all"
|
||||
title="Settings"
|
||||
>
|
||||
<img src={settingIcon} alt="Settings" className="w-5 h-5" style={{ filter: 'invert(1) opacity(0.75)' }} />
|
||||
</button>
|
||||
<button
|
||||
onClick={newSong}
|
||||
className="group px-5 py-2 rounded-full text-sm font-semibold border border-border text-gray-400 hover:text-gray-200 hover:border-gray-400 transition-all"
|
||||
>
|
||||
<span className="group-hover:hidden">New Song</span>
|
||||
<span className="hidden group-hover:inline">Clear History</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setMicError(null); setIsListening(l => !l) }}
|
||||
className={`px-5 py-2 rounded-full font-semibold text-sm transition-all ${
|
||||
isListening
|
||||
? 'bg-red-600 hover:bg-red-700 text-white'
|
||||
: 'bg-accent hover:bg-purple-600 text-white'
|
||||
}`}
|
||||
>
|
||||
{isListening ? 'Stop' : 'Start Listening'}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* ── Controls bar ── */}
|
||||
<div className="mb-2 flex flex-wrap gap-2 items-center p-2 bg-panel border border-border rounded-xl">
|
||||
|
||||
{/* Instrument select */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={instrument}
|
||||
onChange={e => setInstrument(e.target.value)}
|
||||
className="appearance-none bg-surface border border-border hover:border-gray-500 focus:border-accent focus:outline-none rounded-lg pl-3 pr-7 py-1 text-sm text-gray-200 cursor-pointer transition-colors"
|
||||
>
|
||||
<option value="piano">Piano</option>
|
||||
<option value="guitar">Guitar</option>
|
||||
<option value="bass">Bass</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 text-xs">▾</span>
|
||||
</div>
|
||||
|
||||
{/* BPM badge */}
|
||||
{bpm && (
|
||||
<span className="px-3 py-1 bg-accent/10 border border-accent/30 rounded-lg text-sm text-accent font-mono tabular-nums">
|
||||
♩ <span className="inline-block w-[3ch] text-right">{Math.round(bpm)}</span> <span className="text-accent/50 text-xs">BPM</span>
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="w-px h-5 bg-border shrink-0" />
|
||||
|
||||
{lockedKey ? (
|
||||
<div className="flex items-center gap-2 px-3 py-1 bg-accent/20 border border-accent rounded-full">
|
||||
<span className="text-accent text-sm font-semibold shrink-0">🔒 {lockedKey.root}</span>
|
||||
<div className="relative">
|
||||
<select
|
||||
value={lockedKey.mode}
|
||||
onChange={e => {
|
||||
const info = { ...lockedKey, mode: e.target.value }
|
||||
setLockedKey(info)
|
||||
effectiveKeyRef.current = info
|
||||
chordVotesRef.current = []
|
||||
}}
|
||||
className="appearance-none bg-transparent text-accent text-sm font-semibold border-none outline-none cursor-pointer pr-4"
|
||||
>
|
||||
<option value="major">Major</option>
|
||||
<option value="minor">Minor</option>
|
||||
<option value="dorian">Dorian</option>
|
||||
<option value="mixolydian">Mixolydian</option>
|
||||
<option value="phrygian">Phrygian</option>
|
||||
<option value="lydian">Lydian</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-0 top-1/2 -translate-y-1/2 text-accent/60 text-xs">▾</span>
|
||||
</div>
|
||||
<button onClick={removeLock} className="text-xs text-accent/50 hover:text-accent transition-colors">
|
||||
unlock
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-2 items-center">
|
||||
{topKeyCandidates.map((k, i) => (
|
||||
<button
|
||||
key={i}
|
||||
onClick={() => quickLock(k)}
|
||||
className={`px-3 py-1 rounded-full text-sm font-semibold border transition-all ${
|
||||
i === 0
|
||||
? 'border-accent text-accent hover:bg-accent/10'
|
||||
: 'border-border text-gray-400 hover:border-gray-500 hover:text-gray-200'
|
||||
}`}
|
||||
>
|
||||
{k.root} {k.mode === 'major' ? 'maj' : 'min'} · {Math.round(k.confidence * 100)}%
|
||||
</button>
|
||||
))}
|
||||
{topKeyCandidates.length > 0 && <span className="text-gray-600 text-xs">or</span>}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={lockRoot}
|
||||
onChange={e => setLockRoot(e.target.value)}
|
||||
className="appearance-none bg-surface border border-border hover:border-gray-500 focus:border-accent focus:outline-none rounded-lg pl-3 pr-7 py-1 text-sm text-gray-200 cursor-pointer transition-colors"
|
||||
>
|
||||
{NOTES.map(n => <option key={n}>{n}</option>)}
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 text-xs">▾</span>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<select
|
||||
value={lockMode}
|
||||
onChange={e => setLockMode(e.target.value)}
|
||||
className="appearance-none bg-surface border border-border hover:border-gray-500 focus:border-accent focus:outline-none rounded-lg pl-3 pr-7 py-1 text-sm text-gray-200 cursor-pointer transition-colors"
|
||||
>
|
||||
<option value="major">Major</option>
|
||||
<option value="minor">Minor</option>
|
||||
<option value="dorian">Dorian</option>
|
||||
<option value="mixolydian">Mixolydian</option>
|
||||
<option value="phrygian">Phrygian</option>
|
||||
<option value="lydian">Lydian</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 text-xs">▾</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={applyLock}
|
||||
className="px-3 py-1 bg-accent/10 hover:bg-accent/20 border border-accent/40 hover:border-accent text-accent text-sm rounded-lg transition-all"
|
||||
>
|
||||
Lock key
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<AudioCapture
|
||||
onNote={handleNote}
|
||||
onChroma={handleChroma}
|
||||
onOnset={handleOnset}
|
||||
onWaveform={handleWaveform}
|
||||
isListening={isListening}
|
||||
minClarity={config.minClarity}
|
||||
minVolume={config.minVolume}
|
||||
audioDeviceId={config.audioDeviceId}
|
||||
onPermissionError={() => {
|
||||
setMicError(true)
|
||||
setIsListening(false)
|
||||
}}
|
||||
onStreamReady={loopSetStream}
|
||||
/>
|
||||
|
||||
{micError && (
|
||||
<div className="mb-2 px-4 py-3 rounded-xl border border-red-800 bg-red-900/20 text-sm text-red-400 flex items-center justify-between">
|
||||
<span>Microphone permission denied. Please allow microphone access in your browser or OS settings and try again.</span>
|
||||
<button onClick={() => setMicError(null)} className="ml-4 text-red-600 hover:text-red-400 text-lg leading-none">×</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Chord detail modal ── */}
|
||||
<ChordDetailModal chord={selectedChord} onClose={() => setSelectedChord(null)} onChordClick={setSelectedChord} keyInfo={effectiveKey} chordHistory={chordHistory} />
|
||||
|
||||
{/* ── Progression banner ── */}
|
||||
<ProgressionBanner
|
||||
chordHistory={chordHistory}
|
||||
keyInfo={effectiveKey}
|
||||
detectedProgression={detectedProgression}
|
||||
currentChord={currentChord}
|
||||
onChordClick={setSelectedChord}
|
||||
/>
|
||||
|
||||
{/* ── Instrument + progressions row ── */}
|
||||
<div className="flex gap-3 mb-3 items-stretch">
|
||||
<div className="w-full lg:w-[70%] min-w-0">
|
||||
{instrument === 'guitar' && <Fretboard keyInfo={effectiveKey} currentChord={currentChord} pentatonicOnly={false} monoColor={monoColor} jamFocusChord={jamFocusChord} />}
|
||||
{instrument === 'bass' && <BassFretboard keyInfo={effectiveKey} currentChord={currentChord} monoColor={monoColor} />}
|
||||
{instrument === 'piano' && <Piano keyInfo={effectiveKey} currentChord={currentChord} monoColor={monoColor} />}
|
||||
</div>
|
||||
|
||||
<div className="hidden lg:block w-[30%] min-w-0 relative">
|
||||
<div className="absolute inset-0">
|
||||
<ProgressionSuggestions keyInfo={effectiveKey} currentChord={currentChord} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{/* ── Current jam — collapsible ── */}
|
||||
<CurrentJamPanel
|
||||
keyInfo={effectiveKey}
|
||||
chordHistory={chordHistory}
|
||||
detectedProgression={detectedProgression}
|
||||
onChordClick={setSelectedChord}
|
||||
/>
|
||||
|
||||
{/* ── Loop station ── */}
|
||||
<LoopStation
|
||||
slots={slots}
|
||||
bpm={bpm}
|
||||
masterLen={masterLen}
|
||||
audioCtxRef={loopAudioCtxRef}
|
||||
masterStartRef={loopMasterStartRef}
|
||||
masterLenRef={loopMasterLenRef}
|
||||
onSlotClick={handleSlotClick}
|
||||
onCommitTrim={commitTrim}
|
||||
onCancelRecord={cancelRecord}
|
||||
onRetrim={retrimSlot}
|
||||
onDelete={deleteSlot}
|
||||
onVolumeChange={loopSetVolume}
|
||||
onAddSlot={loopAddSlot}
|
||||
/>
|
||||
|
||||
{/* ── Behind the scenes — collapsible ── */}
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button
|
||||
onClick={() => setShowDebug(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all"
|
||||
>
|
||||
<span>BEHIND THE SCENES</span>
|
||||
<span>{showDebug ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
{showDebug && (
|
||||
<div className="border-t border-border p-4">
|
||||
<DebugView
|
||||
chroma={debugChroma}
|
||||
chordCandidates={debugCandidates}
|
||||
noteAnalysis={debugNoteAnalysis}
|
||||
waveform={debugWaveform}
|
||||
keyInfo={effectiveKey}
|
||||
currentChord={currentChord}
|
||||
instrument={instrument}
|
||||
monoColor={monoColor}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Rhythm / drum analyser — collapsible ── */}
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button
|
||||
onClick={() => setShowDrumView(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all"
|
||||
>
|
||||
<span>RHYTHM ANALYSER</span>
|
||||
<span>{showDrumView ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
{showDrumView && (
|
||||
<div className="border-t border-border p-4">
|
||||
<DrumView waveform={debugWaveform} bpm={bpm} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Tuner — collapsible ── */}
|
||||
<div className="bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button
|
||||
onClick={() => setShowTuner(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all"
|
||||
>
|
||||
<span>TUNER</span>
|
||||
<span>{showTuner ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
{showTuner && <div className="border-t border-border"><Tuner /></div>}
|
||||
</div>
|
||||
|
||||
{/* ── Jam Guide — bottom dock (Roadmap) ── */}
|
||||
<JamGuide
|
||||
detectedProgression={detectedProgression}
|
||||
keyInfo={effectiveKey}
|
||||
chordHistory={chordHistory}
|
||||
bpm={bpm}
|
||||
currentChord={currentChord}
|
||||
onFocusChord={setJamFocusChord}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 202 KiB |
@@ -0,0 +1,277 @@
|
||||
import { useEffect, useRef, useCallback } from 'react'
|
||||
import { PitchDetector } from 'pitchy'
|
||||
import { NOTES } from '../lib/theory'
|
||||
|
||||
// ─── Why two analysers? ───────────────────────────────────────────────────────
|
||||
//
|
||||
// The Web Audio FFT has linearly-spaced bins: bin width = sampleRate / fftSize.
|
||||
//
|
||||
// fftSize 4096 → ~10.8 Hz/bin (default we were using)
|
||||
// fftSize 16384 → ~2.7 Hz/bin (multi-rate chord analyser)
|
||||
//
|
||||
// On the low guitar strings the gap between adjacent semitones is only ~5-6 Hz.
|
||||
// At 10.8 Hz/bin we literally cannot separate A2 (110 Hz) from A#2 (116 Hz).
|
||||
// That is the single biggest source of wrong chord notes on the low strings.
|
||||
//
|
||||
// Solution: run a second, larger analyser just for chord/chroma detection.
|
||||
// The pitch analyser stays small (4096) so pitchy has a 90ms window — fast
|
||||
// enough for responsive pitch detection. The chord analyser uses 16384 (~370ms
|
||||
// window) — slower to respond but with 2.7 Hz bins that can cleanly separate
|
||||
// every semitone across the guitar's entire range.
|
||||
//
|
||||
// This is an approximation of the Constant-Q Transform (CQT) your friend
|
||||
// mentioned: CQT achieves log-spaced bins mathematically; we approximate it
|
||||
// by simply using a much larger FFT window.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PITCH_FFT = 4096 // ~90ms window — good temporal resolution for pitch
|
||||
const CHORD_FFT = 16384 // ~370ms window — 2.7 Hz/bin, separates low semitones
|
||||
const NOISE_FLOOR = -65 // dB
|
||||
|
||||
// ─── Harmonic summation chroma ────────────────────────────────────────────────
|
||||
// Each FFT bin votes back toward lower fundamentals that could have generated
|
||||
// it as an overtone. This undoes the harmonic contamination that makes minor
|
||||
// chords look like major ones (the 5th harmonic of the root lands on the major
|
||||
// 3rd, which is NOT in the minor chord).
|
||||
const HARMONIC_WEIGHTS = [1.0, 0.5, 0.33, 0.25, 0.2] // h = 1…5
|
||||
|
||||
function computeChroma(freqData, sampleRate, fftSize) {
|
||||
const chroma = new Float32Array(12)
|
||||
const binHz = sampleRate / fftSize
|
||||
const N = freqData.length
|
||||
|
||||
for (let bin = 2; bin < N; bin++) {
|
||||
const freq = bin * binHz
|
||||
if (freq < 80 || freq > 4000) continue
|
||||
const db = freqData[bin]
|
||||
if (db < NOISE_FLOOR) continue
|
||||
|
||||
const amp = Math.sqrt(Math.pow(10, db / 10)) // amplitude, not power
|
||||
|
||||
for (let h = 1; h <= HARMONIC_WEIGHTS.length; h++) {
|
||||
const fundamental = freq / h
|
||||
if (fundamental < 40 || fundamental > 2000) continue
|
||||
const midi = 12 * Math.log2(fundamental / 440) + 69
|
||||
const pc = ((Math.round(midi) % 12) + 12) % 12
|
||||
chroma[pc] += amp * HARMONIC_WEIGHTS[h - 1]
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < 12; i++) chroma[i] = Math.log1p(chroma[i])
|
||||
const max = Math.max(...chroma)
|
||||
if (max > 0) for (let i = 0; i < 12; i++) chroma[i] /= max
|
||||
return chroma
|
||||
}
|
||||
|
||||
function detectBassPC(freqData, sampleRate, fftSize) {
|
||||
const binHz = sampleRate / fftSize
|
||||
let maxPower = 0, bestMidi = -1
|
||||
for (let bin = 2; bin < freqData.length; bin++) {
|
||||
const freq = bin * binHz
|
||||
if (freq < 40 || freq > 350) continue
|
||||
const db = freqData[bin]
|
||||
if (db < NOISE_FLOOR) continue
|
||||
const power = Math.pow(10, db / 10)
|
||||
if (power > maxPower) {
|
||||
maxPower = power
|
||||
bestMidi = Math.round(12 * Math.log2(freq / 440) + 69)
|
||||
}
|
||||
}
|
||||
if (bestMidi < 0) return null
|
||||
return ((bestMidi % 12) + 12) % 12
|
||||
}
|
||||
|
||||
export default function AudioCapture({ onNote, onChroma, onOnset, onWaveform, isListening, minClarity = 0.80, minVolume = 0.01, onPermissionError, audioDeviceId = null, onStreamReady = null }) {
|
||||
const audioCtxRef = useRef(null)
|
||||
const timeBufRef = useRef(null)
|
||||
const freqBufRef = useRef(null)
|
||||
const detectorRef = useRef(null)
|
||||
const rafRef = useRef(null)
|
||||
const streamRef = useRef(null)
|
||||
const activeRef = useRef(false) // guards against stale tick callbacks
|
||||
|
||||
// All callbacks and thresholds read via refs — so start/stop never need to recreate
|
||||
const onNoteRef = useRef(onNote)
|
||||
const onChromaRef = useRef(onChroma)
|
||||
const onOnsetRef = useRef(onOnset)
|
||||
const onWaveformRef = useRef(onWaveform)
|
||||
const onPermissionErrorRef = useRef(onPermissionError)
|
||||
const onStreamReadyRef = useRef(onStreamReady)
|
||||
const minClarityRef = useRef(minClarity)
|
||||
const minVolumeRef = useRef(minVolume)
|
||||
const smoothRmsRef = useRef(0)
|
||||
const lastOnsetRef = useRef(0)
|
||||
const specPeakRef = useRef(null) // peak-hold spectrum for display lingering
|
||||
useEffect(() => { onNoteRef.current = onNote }, [onNote])
|
||||
useEffect(() => { onChromaRef.current = onChroma }, [onChroma])
|
||||
useEffect(() => { onOnsetRef.current = onOnset }, [onOnset])
|
||||
useEffect(() => { onWaveformRef.current = onWaveform }, [onWaveform])
|
||||
useEffect(() => { onPermissionErrorRef.current = onPermissionError }, [onPermissionError])
|
||||
useEffect(() => { onStreamReadyRef.current = onStreamReady }, [onStreamReady])
|
||||
useEffect(() => { minClarityRef.current = minClarity }, [minClarity])
|
||||
useEffect(() => { minVolumeRef.current = minVolume }, [minVolume])
|
||||
|
||||
const stop = useCallback(() => {
|
||||
activeRef.current = false
|
||||
specPeakRef.current = null
|
||||
if (rafRef.current) { cancelAnimationFrame(rafRef.current); rafRef.current = null }
|
||||
if (streamRef.current) { streamRef.current.getTracks().forEach(t => t.stop()); streamRef.current = null }
|
||||
if (audioCtxRef.current) { audioCtxRef.current.close(); audioCtxRef.current = null }
|
||||
}, [])
|
||||
|
||||
const start = useCallback(async () => {
|
||||
stop()
|
||||
let stream
|
||||
try {
|
||||
// Helpful debug: list available media devices before requesting permission
|
||||
try {
|
||||
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
|
||||
const devices = await navigator.mediaDevices.enumerateDevices()
|
||||
const audioIns = devices.filter(d => d.kind === 'audioinput')
|
||||
console.log('Audio inputs available:', audioIns)
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('enumerateDevices failed', e)
|
||||
}
|
||||
|
||||
const constraints = audioDeviceId
|
||||
? { audio: { deviceId: { exact: audioDeviceId } } }
|
||||
: { audio: true }
|
||||
|
||||
console.log('Requesting getUserMedia with constraints:', constraints)
|
||||
stream = await navigator.mediaDevices.getUserMedia(constraints)
|
||||
} catch (err) {
|
||||
// If permission denied or other error, surface extra diagnostics when possible
|
||||
console.warn('getUserMedia failed', err)
|
||||
try {
|
||||
if (navigator.permissions && navigator.permissions.query) {
|
||||
const p = await navigator.permissions.query({ name: 'microphone' })
|
||||
console.log('microphone permission state:', p.state)
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore; not all environments support Permissions API for microphone
|
||||
}
|
||||
onPermissionErrorRef.current?.(err)
|
||||
return
|
||||
}
|
||||
streamRef.current = stream
|
||||
activeRef.current = true
|
||||
onStreamReadyRef.current?.(stream)
|
||||
smoothRmsRef.current = 0
|
||||
lastOnsetRef.current = 0
|
||||
|
||||
const ctx = new AudioContext()
|
||||
audioCtxRef.current = ctx
|
||||
const source = ctx.createMediaStreamSource(stream)
|
||||
|
||||
// Debug: log the acquired audio tracks and labels/deviceIds
|
||||
try {
|
||||
const tracks = stream.getAudioTracks()
|
||||
console.log('Acquired audio tracks:', tracks.map(t => ({ label: t.label, id: t.id, enabled: t.enabled, muted: t.muted })))
|
||||
} catch (e) {
|
||||
console.warn('Could not inspect stream tracks', e)
|
||||
}
|
||||
|
||||
// Small analyser — pitch detection needs fast time-domain data
|
||||
const pa = ctx.createAnalyser()
|
||||
pa.fftSize = PITCH_FFT
|
||||
pa.smoothingTimeConstant = 0.0
|
||||
source.connect(pa)
|
||||
timeBufRef.current = new Float32Array(pa.fftSize)
|
||||
detectorRef.current = PitchDetector.forFloat32Array(pa.fftSize)
|
||||
|
||||
// Large analyser — chord detection needs fine frequency resolution
|
||||
const ca = ctx.createAnalyser()
|
||||
ca.fftSize = CHORD_FFT
|
||||
ca.smoothingTimeConstant = 0.5 // reduced from 0.65 — clears faster between chords
|
||||
source.connect(ca)
|
||||
freqBufRef.current = new Float32Array(ca.frequencyBinCount)
|
||||
|
||||
function tick() {
|
||||
if (!activeRef.current) return // stop() was called — bail immediately
|
||||
|
||||
const timeBuf = timeBufRef.current
|
||||
pa.getFloatTimeDomainData(timeBuf)
|
||||
|
||||
const rms = Math.sqrt(timeBuf.reduce((s, v) => s + v * v, 0) / timeBuf.length)
|
||||
|
||||
// Onset detection — RMS spike significantly above smoothed baseline
|
||||
const sr = smoothRmsRef.current
|
||||
smoothRmsRef.current = 0.85 * sr + 0.15 * rms
|
||||
const nowMs = performance.now()
|
||||
if (rms > sr * 2.2 && rms > minVolumeRef.current * 1.5 && nowMs - lastOnsetRef.current > 120) {
|
||||
lastOnsetRef.current = nowMs
|
||||
onOnsetRef.current?.()
|
||||
}
|
||||
|
||||
// Always fire waveform callback — downsample 4096 → 512 points + log-binned spectrum
|
||||
if (onWaveformRef.current) {
|
||||
const stride = 8 // 4096 / 8 = 512 points
|
||||
const wave = new Float32Array(PITCH_FFT / stride)
|
||||
for (let i = 0; i < wave.length; i++) wave[i] = timeBuf[i * stride]
|
||||
|
||||
// Log-binned frequency spectrum: 256 bins from 40 Hz → 4000 Hz
|
||||
const LOG_BINS = 256
|
||||
const F_MIN = 40, F_MAX = 4000
|
||||
const binHz = ctx.sampleRate / ca.fftSize
|
||||
const freqBuf = freqBufRef.current
|
||||
ca.getFloatFrequencyData(freqBuf)
|
||||
const spectrum = new Float32Array(LOG_BINS)
|
||||
for (let b = 0; b < LOG_BINS; b++) {
|
||||
const f = F_MIN * Math.pow(F_MAX / F_MIN, b / (LOG_BINS - 1))
|
||||
const bin = Math.round(f / binHz)
|
||||
if (bin < freqBuf.length) {
|
||||
const db = freqBuf[bin]
|
||||
spectrum[b] = db < NOISE_FLOOR ? 0 : Math.max(0, (db - NOISE_FLOOR) / (-NOISE_FLOOR))
|
||||
}
|
||||
}
|
||||
|
||||
// Peak-hold with exponential decay — spectrum rises instantly, falls slowly
|
||||
if (!specPeakRef.current) specPeakRef.current = new Float32Array(LOG_BINS)
|
||||
const peak = specPeakRef.current
|
||||
for (let b = 0; b < LOG_BINS; b++) {
|
||||
peak[b] = spectrum[b] > peak[b] ? spectrum[b] : peak[b] * 0.92
|
||||
}
|
||||
|
||||
let detectedFreq = null, detectedNote = null
|
||||
if (rms >= minVolumeRef.current) {
|
||||
const [f, c] = detectorRef.current.findPitch(timeBuf, ctx.sampleRate)
|
||||
if (c >= minClarityRef.current && f > 60 && f < 4200) {
|
||||
detectedFreq = f
|
||||
detectedNote = NOTES[((Math.round(12 * Math.log2(f / 440) + 69) % 12) + 12) % 12]
|
||||
}
|
||||
}
|
||||
onWaveformRef.current({ wave, rms, detectedFreq, detectedNote, spectrum: peak })
|
||||
}
|
||||
|
||||
if (rms >= minVolumeRef.current) {
|
||||
const [freq, clarity] = detectorRef.current.findPitch(timeBuf, ctx.sampleRate)
|
||||
if (clarity >= minClarityRef.current && freq > 60 && freq < 4200) {
|
||||
const midi = Math.round(12 * Math.log2(freq / 440) + 69)
|
||||
const pitchClass = ((midi % 12) + 12) % 12
|
||||
onNoteRef.current({ noteName: NOTES[pitchClass], pitchClass, freq, midi, clarity })
|
||||
}
|
||||
|
||||
if (onChromaRef.current) {
|
||||
const freqBuf = freqBufRef.current
|
||||
ca.getFloatFrequencyData(freqBuf)
|
||||
onChromaRef.current(
|
||||
computeChroma(freqBuf, ctx.sampleRate, ca.fftSize),
|
||||
detectBassPC(freqBuf, ctx.sampleRate, ca.fftSize)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
}
|
||||
tick()
|
||||
}, [stop])
|
||||
|
||||
useEffect(() => {
|
||||
if (isListening) start().catch(console.error)
|
||||
else stop()
|
||||
return stop
|
||||
}, [isListening, start, stop])
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -1,51 +1,45 @@
|
||||
import { getPentatonicScale, getFullScale, getChordTones, NOTES } from '../lib/theory'
|
||||
|
||||
// Standard tuning: pitch classes of open strings, high-E first (top of diagram)
|
||||
// Standard bass tuning (top of diagram = highest string)
|
||||
const STRINGS = [
|
||||
{ label: 'e', root: 4 }, // high E
|
||||
{ label: 'B', root: 11 },
|
||||
{ label: 'G', root: 7 },
|
||||
{ label: 'D', root: 2 },
|
||||
{ label: 'A', root: 9 },
|
||||
{ label: 'E', root: 4 }, // low E
|
||||
{ label: 'G', root: 7, thickness: 1.5 },
|
||||
{ label: 'D', root: 2, thickness: 2 },
|
||||
{ label: 'A', root: 9, thickness: 2.5 },
|
||||
{ label: 'E', root: 4, thickness: 3 },
|
||||
]
|
||||
|
||||
const NUM_FRETS = 13 // frets 0 (open) through 12
|
||||
const NUM_FRETS = 13
|
||||
const FRET_MARKERS = [3, 5, 7, 9]
|
||||
const DOUBLE_MARKER = 12
|
||||
|
||||
// Layout constants
|
||||
const NUT_X = 40 // x of the nut line
|
||||
const OPEN_X = 18 // x of open-string dot centres
|
||||
const FRET_W = 52 // pixels per fret
|
||||
const STRING_H = 28 // pixels between strings
|
||||
const PAD_T = 28 // top padding (fret numbers)
|
||||
const PAD_B = 18 // bottom padding (fret marker dots)
|
||||
// Layout
|
||||
const NUT_X = 40
|
||||
const OPEN_X = 18
|
||||
const FRET_W = 52
|
||||
const STRING_H = 36 // wider spacing than guitar — 4 strings feel more spread
|
||||
const PAD_T = 28
|
||||
const PAD_B = 18
|
||||
const BOARD_W = NUT_X + (NUM_FRETS - 1) * FRET_W + 10
|
||||
const BOARD_H = PAD_T + 5 * STRING_H + PAD_B
|
||||
const BOARD_H = PAD_T + 3 * STRING_H + PAD_B
|
||||
const DOT_R = 10
|
||||
|
||||
// x centre of a fretted note (fret >= 1)
|
||||
const fretX = f => NUT_X + (f - 0.5) * FRET_W
|
||||
// y centre of string si (0 = high e, 5 = low E)
|
||||
const stringY = si => PAD_T + si * STRING_H
|
||||
|
||||
function noteColor(isChordTone, isPenta, isScale) {
|
||||
if (isChordTone) return { fill: '#f59e0b', text: '#000' } // amber
|
||||
if (isPenta) return { fill: '#a855f7', text: '#fff' } // purple
|
||||
if (isScale) return { fill: '#374151', text: '#d1d5db' } // grey
|
||||
function noteColor(isChordTone, isPenta, isScale, mono = false) {
|
||||
if (isChordTone) return { fill: '#a855f7', text: '#fff' }
|
||||
if (isPenta) return mono ? { fill: '#c084fc', text: '#1e1b4b' } : { fill: '#f59e0b', text: '#000' }
|
||||
if (isScale) return mono ? { fill: '#e9d5ff', text: '#581c87' } : { fill: '#374151', text: '#d1d5db' }
|
||||
return null
|
||||
}
|
||||
|
||||
export default function Fretboard({ keyInfo, currentChord, pentatonicOnly = false }) {
|
||||
export default function BassFretboard({ keyInfo, currentChord, monoColor = false }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
if (!root) return null
|
||||
|
||||
const pentaSet = new Set(getPentatonicScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const scaleSet = pentatonicOnly
|
||||
? pentaSet
|
||||
: new Set(getFullScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const scaleSet = new Set(getFullScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const chordSet = currentChord
|
||||
? new Set(getChordTones(currentChord).map(n => NOTES.indexOf(n)))
|
||||
: new Set()
|
||||
@@ -53,50 +47,51 @@ export default function Fretboard({ keyInfo, currentChord, pentatonicOnly = fals
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-4">
|
||||
Fretboard — {root} {mode}
|
||||
Bass — {root} {mode}
|
||||
{currentChord && <span className="text-amber-400 ml-2">/ {currentChord}</span>}
|
||||
</p>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<div>
|
||||
<svg
|
||||
width={BOARD_W}
|
||||
height={BOARD_H}
|
||||
style={{ display: 'block', minWidth: BOARD_W }}
|
||||
viewBox={`0 0 ${BOARD_W} ${BOARD_H}`}
|
||||
width="100%"
|
||||
height="auto"
|
||||
style={{ display: 'block' }}
|
||||
>
|
||||
{/* Fretboard background */}
|
||||
<rect x={NUT_X} y={PAD_T - 6} width={BOARD_W - NUT_X - 4} height={5 * STRING_H + 12}
|
||||
<rect x={NUT_X} y={PAD_T - 6} width={BOARD_W - NUT_X - 4} height={3 * STRING_H + 12}
|
||||
fill="#1a120b" rx={2} />
|
||||
|
||||
{/* Fret position marker dots (between strings 2–3 and 3–4) */}
|
||||
{/* Position marker dots (centred between strings 1–2) */}
|
||||
{FRET_MARKERS.map(f => (
|
||||
<circle key={f}
|
||||
cx={fretX(f)} cy={PAD_T + 2.5 * STRING_H}
|
||||
cx={fretX(f)} cy={PAD_T + 1.5 * STRING_H}
|
||||
r={5} fill="#3a2a1a" />
|
||||
))}
|
||||
{/* Double dot at 12 */}
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 1.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 3.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 0.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 2.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
|
||||
{/* Fret lines (1–12) */}
|
||||
{/* Fret lines */}
|
||||
{Array.from({ length: NUM_FRETS - 1 }, (_, i) => i + 1).map(f => (
|
||||
<line key={f}
|
||||
x1={NUT_X + f * FRET_W} y1={PAD_T - 6}
|
||||
x2={NUT_X + f * FRET_W} y2={PAD_T + 5 * STRING_H + 6}
|
||||
x2={NUT_X + f * FRET_W} y2={PAD_T + 3 * STRING_H + 6}
|
||||
stroke={f === DOUBLE_MARKER ? '#888' : '#4a3a2a'}
|
||||
strokeWidth={f === DOUBLE_MARKER ? 2 : 1} />
|
||||
))}
|
||||
|
||||
{/* Nut */}
|
||||
<line x1={NUT_X} y1={PAD_T - 6} x2={NUT_X} y2={PAD_T + 5 * STRING_H + 6}
|
||||
<line x1={NUT_X} y1={PAD_T - 6} x2={NUT_X} y2={PAD_T + 3 * STRING_H + 6}
|
||||
stroke="#c0b090" strokeWidth={4} />
|
||||
|
||||
{/* Strings */}
|
||||
{STRINGS.map((_, si) => (
|
||||
{/* Strings — thicker as pitch drops */}
|
||||
{STRINGS.map((s, si) => (
|
||||
<line key={si}
|
||||
x1={OPEN_X - DOT_R - 2} y1={stringY(si)}
|
||||
x2={BOARD_W - 8} y2={stringY(si)}
|
||||
stroke="#9ca3af"
|
||||
strokeWidth={si < 2 ? 1 : si < 4 ? 1.5 : 2} />
|
||||
strokeWidth={s.thickness} />
|
||||
))}
|
||||
|
||||
{/* Fret numbers */}
|
||||
@@ -119,7 +114,7 @@ export default function Fretboard({ keyInfo, currentChord, pentatonicOnly = fals
|
||||
{STRINGS.flatMap((str, si) =>
|
||||
Array.from({ length: NUM_FRETS }, (_, fi) => {
|
||||
const pc = (str.root + fi) % 12
|
||||
const color = noteColor(chordSet.has(pc), pentaSet.has(pc), scaleSet.has(pc))
|
||||
const color = noteColor(chordSet.has(pc), pentaSet.has(pc), scaleSet.has(pc), monoColor)
|
||||
if (!color) return null
|
||||
|
||||
const cx = fi === 0 ? OPEN_X : fretX(fi)
|
||||
@@ -145,9 +140,9 @@ export default function Fretboard({ keyInfo, currentChord, pentatonicOnly = fals
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex gap-5 text-xs text-gray-500">
|
||||
<span><span className="text-amber-400">●</span> Chord tone</span>
|
||||
<span><span className="text-accent">●</span> Pentatonic</span>
|
||||
<span><span className="text-gray-500">●</span> Scale</span>
|
||||
<span><span className="text-accent">●</span> Chord tone</span>
|
||||
<span style={{ color: monoColor ? '#c084fc' : '#f59e0b' }}>●</span><span> Pentatonic</span>
|
||||
<span style={{ color: monoColor ? '#e9d5ff' : '#6b7280' }}>●</span><span> Scale</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -0,0 +1,137 @@
|
||||
// SVG chord diagram — 6 strings × 5 visible frets
|
||||
// Props:
|
||||
// frets[] — [s6…s1]: fret number or 'x' (muted)
|
||||
// fingers[] — [s6…s1]: finger 1-4, 0 = open/barre indicator
|
||||
// barre — { fret, fromStr, toStr } or null
|
||||
// baseFret — which fret number is at the top of the diagram (1 = standard)
|
||||
// label — caption below the box
|
||||
|
||||
const STRINGS = 6
|
||||
const ROWS = 5 // visible frets
|
||||
const SX = 32 // left margin (open/mute indicators)
|
||||
const SY = 28 // top margin (nut / baseFret label)
|
||||
const GX = 26 // gap between strings
|
||||
const GY = 22 // gap between frets
|
||||
const DOT_R = 9 // dot radius
|
||||
const W = SX + GX * (STRINGS - 1) + 24 // total width
|
||||
const H = SY + GY * ROWS + 20 // total height
|
||||
|
||||
function strX(s) { return SX + (STRINGS - 1 - s) * GX } // s=0 is s6 (low E, leftmost)
|
||||
function fretY(f) { return SY + f * GY } // f=0 is above first fret, f=1…5 are fret centers
|
||||
|
||||
export default function ChordBox({ frets, fingers, barre, baseFret = 1, label }) {
|
||||
const isOpen = baseFret === 1
|
||||
|
||||
// Map fret numbers to diagram row (0-indexed from top)
|
||||
function toRow(absF) {
|
||||
return absF - baseFret + 1 // fret at baseFret → row 1 (center of first fret)
|
||||
}
|
||||
|
||||
// Barre bar: draw a rounded rect across strings
|
||||
function renderBarre() {
|
||||
if (!barre) return null
|
||||
const row = toRow(barre.fret)
|
||||
if (row < 1 || row > ROWS) return null
|
||||
const x1 = strX(STRINGS - barre.toStr) // toStr is highest string number = leftmost
|
||||
const x2 = strX(STRINGS - barre.fromStr) // fromStr is lowest string number = rightmost
|
||||
const cy = fretY(row) - GY / 2
|
||||
return (
|
||||
<rect
|
||||
key="barre"
|
||||
x={x1 - DOT_R}
|
||||
y={cy - DOT_R}
|
||||
width={x2 - x1 + DOT_R * 2}
|
||||
height={DOT_R * 2}
|
||||
rx={DOT_R}
|
||||
fill="#a855f7"
|
||||
opacity={0.9}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-1">
|
||||
<svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} className="overflow-visible">
|
||||
|
||||
{/* ── Nut or baseFret indicator ── */}
|
||||
{isOpen ? (
|
||||
<rect x={SX - 2} y={SY - 4} width={GX * (STRINGS - 1) + 4} height={4} rx={2} fill="#e5e7eb" />
|
||||
) : (
|
||||
<text x={SX - 6} y={SY + GY * 0.5} textAnchor="end" dominantBaseline="middle"
|
||||
fill="#9ca3af" fontSize={10} fontFamily="monospace">
|
||||
{baseFret}
|
||||
</text>
|
||||
)}
|
||||
|
||||
{/* ── Fret lines ── */}
|
||||
{Array.from({ length: ROWS + 1 }, (_, i) => (
|
||||
<line key={`fl${i}`}
|
||||
x1={SX} y1={fretY(i) - GY / 2}
|
||||
x2={SX + GX * (STRINGS - 1)} y2={fretY(i) - GY / 2}
|
||||
stroke="#374151" strokeWidth={i === 0 && isOpen ? 3 : 1}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* ── String lines ── */}
|
||||
{Array.from({ length: STRINGS }, (_, s) => (
|
||||
<line key={`sl${s}`}
|
||||
x1={strX(s)} y1={SY - GY / 2}
|
||||
x2={strX(s)} y2={fretY(ROWS) - GY / 2}
|
||||
stroke="#4b5563" strokeWidth={1}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* ── Barre ── */}
|
||||
{renderBarre()}
|
||||
|
||||
{/* ── Dots + open/mute indicators ── */}
|
||||
{frets.map((f, s) => {
|
||||
const cx = strX(STRINGS - 1 - s)
|
||||
if (f === 'x') {
|
||||
return (
|
||||
<text key={`m${s}`} x={cx} y={SY - GY / 2 - 7}
|
||||
textAnchor="middle" fill="#6b7280" fontSize={12} fontWeight="bold">
|
||||
×
|
||||
</text>
|
||||
)
|
||||
}
|
||||
if (f === 0) {
|
||||
return (
|
||||
<circle key={`o${s}`} cx={cx} cy={SY - GY / 2 - 7}
|
||||
r={5} fill="none" stroke="#6b7280" strokeWidth={1.5} />
|
||||
)
|
||||
}
|
||||
const row = toRow(f)
|
||||
if (row < 1 || row > ROWS) return null
|
||||
const cy = fretY(row) - GY / 2
|
||||
const finger = fingers?.[s] ?? 0
|
||||
return (
|
||||
<g key={`d${s}`}>
|
||||
<circle cx={cx} cy={cy} r={DOT_R} fill="#a855f7" />
|
||||
{finger > 0 && (
|
||||
<text x={cx} y={cy} textAnchor="middle" dominantBaseline="middle"
|
||||
fill="white" fontSize={9} fontWeight="bold">
|
||||
{finger}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* ── String name labels ── */}
|
||||
{['e','B','G','D','A','E'].map((n, i) => (
|
||||
<text key={`sn${i}`}
|
||||
x={strX(i)} y={H - 4}
|
||||
textAnchor="middle" fill="#4b5563" fontSize={8}>
|
||||
{n}
|
||||
</text>
|
||||
))}
|
||||
|
||||
</svg>
|
||||
|
||||
{label && (
|
||||
<p className="text-[11px] text-gray-400 text-center leading-tight max-w-[120px]">{label}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,789 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import ChordBox from './ChordBox'
|
||||
import MiniPiano from './MiniPiano'
|
||||
import { getGuitarVoicings, getPianoTechniques, parseChord } from '../lib/voicings'
|
||||
import { CHORD_TYPES, NOTES, getChordsInKey, toRomanNumeral, getSuggestedProgressions } from '../lib/theory'
|
||||
import { FAMOUS_PROGRESSIONS, progressionInKey, getChordSubstitutions, CHORD_PLAYBOOK } from '../lib/education'
|
||||
|
||||
const CHORD_SUFFIX_OPTIONS = [
|
||||
{ key: 'maj', label: 'Major' },
|
||||
{ key: 'min', label: 'Minor' },
|
||||
{ key: 'dom7', label: '7' },
|
||||
{ key: 'maj7', label: 'maj7' },
|
||||
{ key: 'min7', label: 'm7' },
|
||||
{ key: 'dim', label: 'dim' },
|
||||
{ key: 'dim7', label: 'dim7' },
|
||||
{ key: 'half_dim', label: 'm7♭5' },
|
||||
{ key: 'aug', label: 'aug' },
|
||||
{ key: 'sus4', label: 'sus4' },
|
||||
{ key: 'sus2', label: 'sus2' },
|
||||
{ key: 'maj6', label: '6' },
|
||||
{ key: 'min6', label: 'm6' },
|
||||
{ key: 'add9', label: 'add9' },
|
||||
]
|
||||
|
||||
function chordDisplayName(root, typeKey) {
|
||||
const type = CHORD_TYPES[typeKey]
|
||||
if (!type) return root
|
||||
return root + type.suffix
|
||||
}
|
||||
|
||||
function GuitarTab({ chordName }) {
|
||||
const voicings = getGuitarVoicings(chordName)
|
||||
if (!voicings.length) {
|
||||
return <p className="text-gray-500 text-sm text-center py-8">No guitar voicings found for {chordName}.</p>
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<p className="text-xs text-gray-500 mb-4">
|
||||
Click any voicing to learn it. Purple = chord tones. Finger numbers inside dots (1=index, 4=pinky).
|
||||
Barre chords show the fret number on the left.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-6 justify-start">
|
||||
{voicings.map((v, i) => (
|
||||
<div key={i} className="flex flex-col items-center gap-1 p-3 rounded-xl bg-surface border border-border hover:border-accent/40 transition-colors">
|
||||
<ChordBox
|
||||
frets={v.frets}
|
||||
fingers={v.fingers}
|
||||
barre={v.barre}
|
||||
baseFret={v.baseFret}
|
||||
/>
|
||||
<p className="text-[11px] text-gray-400 text-center mt-1 max-w-[120px] leading-tight">{v.label}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-4 p-3 rounded-lg bg-surface border border-border">
|
||||
<p className="text-xs text-gray-500">
|
||||
<span className="text-accent font-semibold">Pro tip:</span> Learn the E-shape and A-shape barres first
|
||||
— they cover all 12 roots. Then add open voicings for the keys you play in most.
|
||||
High-fret voicings (above fret 7) work great as jazz comping shapes in a band mix.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function PianoTab({ chordName }) {
|
||||
const parsed = parseChord(chordName)
|
||||
const techniques = getPianoTechniques(chordName)
|
||||
const rootPc = parsed?.rootPc ?? 0
|
||||
|
||||
if (!techniques.length) {
|
||||
return <p className="text-gray-500 text-sm text-center py-8">No piano techniques for {chordName}.</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<p className="text-xs text-gray-500">
|
||||
<span className="text-blue-400 font-semibold">Blue = Left hand</span> ·
|
||||
<span className="text-accent font-semibold">Purple = Right hand</span> ·
|
||||
R marks the root.
|
||||
</p>
|
||||
{techniques.map((t, i) => (
|
||||
<div key={i} className="p-4 rounded-xl bg-surface border border-border hover:border-accent/30 transition-colors">
|
||||
<div className="flex flex-col lg:flex-row gap-4 items-start">
|
||||
<div className="shrink-0 overflow-x-auto">
|
||||
<MiniPiano rootPc={rootPc} lh={t.lh} rh={t.rh} />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 min-w-0">
|
||||
<h3 className="font-bold text-white text-sm">{t.name}</h3>
|
||||
<p className="text-gray-400 text-xs">{t.desc}</p>
|
||||
<p className="text-xs text-amber-400/80 mt-1">
|
||||
<span className="text-amber-400 font-semibold">Tip:</span> {t.tip}
|
||||
</p>
|
||||
<div className="flex gap-3 mt-1 text-xs text-gray-600">
|
||||
{t.lh.length > 0 && (
|
||||
<span className="text-blue-400">LH: {t.lh.map(iv => {
|
||||
const n = NOTES[(rootPc + iv) % 12]
|
||||
return iv === 0 ? `${n} (root)` : n
|
||||
}).join(', ')}</span>
|
||||
)}
|
||||
{t.rh.length > 0 && (
|
||||
<span className="text-accent">RH: {t.rh.map(iv => {
|
||||
const n = NOTES[(rootPc + iv) % 12]
|
||||
return n
|
||||
}).join(', ')}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ChordQuickPick({ label, chords, active, keyInfo, onSelect }) {
|
||||
if (!chords.length) return null
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-[11px] text-gray-600 uppercase tracking-wider shrink-0 w-20">{label}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{chords.map(chord => {
|
||||
const rn = keyInfo?.root ? toRomanNumeral(chord, keyInfo.root, keyInfo.mode) : ''
|
||||
return (
|
||||
<button key={chord}
|
||||
onClick={() => onSelect(chord)}
|
||||
className={`flex flex-col items-center px-2.5 py-1 rounded-lg border text-xs font-bold transition-all ${
|
||||
active === chord
|
||||
? 'bg-accent border-accent text-white'
|
||||
: 'bg-surface border-border text-gray-300 hover:border-accent/50 hover:text-white'
|
||||
}`}>
|
||||
<span>{chord}</span>
|
||||
{rn && <span className="text-[9px] font-normal opacity-60 leading-none">{rn}</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Progressions sub-tab ─────────────────────────────────────────────────────
|
||||
// Determine whether a chord type is major-ish or minor-ish for matching
|
||||
const MAJOR_TYPES = new Set(['maj','maj7','maj6','add9','sus4','sus2','aug','dom7'])
|
||||
const MINOR_TYPES = new Set(['min','min7','min6','half_dim','dim','dim7'])
|
||||
|
||||
function isMajorType(t) { return MAJOR_TYPES.has(t) }
|
||||
function isMinorType(t) { return MINOR_TYPES.has(t) }
|
||||
|
||||
function ProgressionsSubTab({ chordName, onChordClick }) {
|
||||
const parsed = parseChord(chordName)
|
||||
if (!parsed) return null
|
||||
const { rootPc, type } = parsed
|
||||
const root = NOTES[rootPc]
|
||||
|
||||
// Famous progressions where this chord can be the tonic (degree 0)
|
||||
const isMajor = isMajorType(type)
|
||||
const isMinor = isMinorType(type)
|
||||
const tonicProgs = FAMOUS_PROGRESSIONS.filter(p => {
|
||||
const q0 = p.qualities[0]
|
||||
if (isMajor && isMajorType(q0)) return true
|
||||
if (isMinor && isMinorType(q0)) return true
|
||||
return false
|
||||
})
|
||||
|
||||
// Genre-based suggestions from theory.js
|
||||
const genreProgs = getSuggestedProgressions(root, isMajor ? 'major' : 'minor')
|
||||
|
||||
// Roles this chord plays in other keys
|
||||
const ROLES = []
|
||||
for (let keyPc = 0; keyPc < 12; keyPc++) {
|
||||
for (const mode of ['major', 'minor']) {
|
||||
const diatonicChords = getChordsInKey(NOTES[keyPc], mode)
|
||||
const idx = diatonicChords.indexOf(chordName)
|
||||
if (idx !== -1) {
|
||||
const rn = toRomanNumeral(chordName, NOTES[keyPc], mode)
|
||||
ROLES.push({ keyRoot: NOTES[keyPc], mode, rn, diatonicChords })
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* ── Famous progressions starting from this chord ── */}
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">
|
||||
Famous progressions — {chordName} as tonic
|
||||
</p>
|
||||
{tonicProgs.length === 0 && (
|
||||
<p className="text-gray-600 text-sm">No exact matches — try a major or minor chord.</p>
|
||||
)}
|
||||
<div className="flex flex-col gap-3">
|
||||
{tonicProgs.slice(0, 6).map(prog => {
|
||||
const chordsHere = progressionInKey(prog, root)
|
||||
return (
|
||||
<div key={prog.id} className="p-3 bg-surface border border-border rounded-xl hover:border-accent/30 transition-colors">
|
||||
<div className="flex items-center gap-2 flex-wrap mb-2">
|
||||
<span className="font-bold text-white text-sm">{prog.name}</span>
|
||||
<span className="text-[10px] font-mono text-gray-500">{prog.pattern}</span>
|
||||
{prog.genre.map(g => (
|
||||
<span key={g} className="px-1.5 py-0.5 bg-accent/10 border border-accent/20 rounded text-[10px] text-accent">{g}</span>
|
||||
))}
|
||||
</div>
|
||||
{/* Chord sequence */}
|
||||
<div className="flex flex-wrap gap-1.5 items-center mb-2">
|
||||
{chordsHere.map((c, i) => (
|
||||
<span key={i} className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => onChordClick?.(c)}
|
||||
className={`px-2.5 py-1 rounded-lg font-bold text-sm border transition-all ${
|
||||
i === 0
|
||||
? 'bg-accent border-accent text-white'
|
||||
: 'bg-panel border-border text-gray-200 hover:border-accent/50 hover:text-accent'
|
||||
}`}
|
||||
title={`Voicings for ${c}`}
|
||||
>
|
||||
{c}
|
||||
</button>
|
||||
{i < chordsHere.length - 1 && <span className="text-gray-700 text-xs">→</span>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 leading-snug">{prog.description}</p>
|
||||
{prog.songs[0] && (
|
||||
<p className="text-[11px] text-gray-600 mt-1">e.g. {prog.songs.slice(0, 3).join(' · ')}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Genre-based next-chord suggestions ── */}
|
||||
{genreProgs.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">
|
||||
Genre suggestions — starting from {chordName}
|
||||
</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{genreProgs.slice(0, 6).map((prog, pi) => (
|
||||
<div key={pi} className="flex items-center gap-2 p-2 bg-surface border border-border rounded-lg flex-wrap">
|
||||
<span className="text-[10px] font-bold text-gray-500 w-14 shrink-0">{prog.genre}</span>
|
||||
<div className="flex gap-1.5 flex-wrap items-center">
|
||||
{prog.chords.map((c, i) => (
|
||||
<span key={i} className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => onChordClick?.(c)}
|
||||
className="px-2 py-0.5 bg-panel border border-border hover:border-accent/50 rounded text-xs font-bold text-gray-200 hover:text-accent transition-all"
|
||||
title={`Voicings for ${c}`}
|
||||
>
|
||||
{c}
|
||||
</button>
|
||||
{i < prog.chords.length - 1 && <span className="text-gray-700 text-[10px]">→</span>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<span className="text-[10px] text-gray-600 font-mono ml-1">{prog.rn?.join(' – ')}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Roles this chord plays ── */}
|
||||
{ROLES.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">
|
||||
{chordName} appears in these keys
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{ROLES.slice(0, 8).map(({ keyRoot, mode, rn, diatonicChords }) => (
|
||||
<div key={`${keyRoot}-${mode}`}
|
||||
className="px-3 py-2 bg-surface border border-border rounded-xl text-xs flex flex-col gap-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="font-bold text-white">{keyRoot}</span>
|
||||
<span className="text-gray-500 capitalize">{mode}</span>
|
||||
<span className="text-amber-400 font-bold">{rn}</span>
|
||||
</div>
|
||||
<div className="flex gap-1 flex-wrap">
|
||||
{diatonicChords.map((c, i) => (
|
||||
<button key={i}
|
||||
onClick={() => onChordClick?.(c)}
|
||||
className={`px-1.5 py-0.5 rounded text-[10px] font-bold transition-all ${
|
||||
c === chordName
|
||||
? 'bg-accent text-white'
|
||||
: 'text-gray-500 hover:text-gray-300'
|
||||
}`}>
|
||||
{c}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Theory tab ───────────────────────────────────────────────────────────────
|
||||
|
||||
const CHORD_THEORY = {
|
||||
maj: {
|
||||
name: 'Major',
|
||||
formula: 'Root + Major 3rd (4 semitones) + Perfect 5th (7 semitones)',
|
||||
vibe: 'Bright, happy, resolved. The most "complete" sound in Western music.',
|
||||
beginner: 'Major chords are the foundation of almost every song you know. They feel stable and uplifting — like a musical full stop.',
|
||||
tension: 'Low — very stable',
|
||||
color: 'text-yellow-400',
|
||||
},
|
||||
min: {
|
||||
name: 'Minor',
|
||||
formula: 'Root + Minor 3rd (3 semitones) + Perfect 5th (7 semitones)',
|
||||
vibe: 'Dark, melancholic, introspective. The 3rd is lowered by just one semitone — that one note changes everything.',
|
||||
beginner: 'One note separates major from minor. Minor chords carry emotion and depth — sadness, mystery, tension.',
|
||||
tension: 'Low-medium — stable but moody',
|
||||
color: 'text-blue-400',
|
||||
},
|
||||
dom7: {
|
||||
name: 'Dominant 7th',
|
||||
formula: 'Major triad + Minor 7th (10 semitones)',
|
||||
vibe: 'Tense, bluesy, urgent. Wants desperately to resolve to a chord a 5th lower.',
|
||||
beginner: 'The 7th chord is the engine of blues and jazz. It creates tension that begs to resolve — like holding your breath. Play G7 then C to feel it.',
|
||||
tension: 'High — strongly pulls to resolution',
|
||||
color: 'text-red-400',
|
||||
},
|
||||
maj7: {
|
||||
name: 'Major 7th',
|
||||
formula: 'Major triad + Major 7th (11 semitones)',
|
||||
vibe: 'Dreamy, lush, sophisticated. Jazz-infused warmth without the tension of a dominant 7th.',
|
||||
beginner: 'The major 7th is the note just below the octave. Adding it to a major chord gives you that smooth jazz-bossa nova sound — think "Autumn Leaves".',
|
||||
tension: 'Very low — ethereal and floating',
|
||||
color: 'text-purple-400',
|
||||
},
|
||||
min7: {
|
||||
name: 'Minor 7th',
|
||||
formula: 'Minor triad + Minor 7th (10 semitones)',
|
||||
vibe: 'Smooth, soulful, relaxed. Darker than major 7th but less tense than a dominant 7th.',
|
||||
beginner: 'Minor 7ths are everywhere in soul, R&B, and jazz. They\'re minor chords with added warmth — moody but not harsh.',
|
||||
tension: 'Low-medium — smooth and flowing',
|
||||
color: 'text-indigo-400',
|
||||
},
|
||||
dim: {
|
||||
name: 'Diminished',
|
||||
formula: 'Root + Minor 3rd (3 semitones) + Diminished 5th (6 semitones)',
|
||||
vibe: 'Dark, tense, unstable. The flattened 5th creates a tritone interval — historically called "diabolus in musica" (the devil in music).',
|
||||
beginner: 'Diminished chords are passing chords — they create maximum tension so the next chord feels like a huge relief. Like a musical cliffhanger.',
|
||||
tension: 'Very high — wants to resolve immediately',
|
||||
color: 'text-orange-400',
|
||||
},
|
||||
dim7: {
|
||||
name: 'Diminished 7th',
|
||||
formula: 'Diminished triad + Diminished 7th (9 semitones) — fully symmetric, all minor 3rds',
|
||||
vibe: 'Extremely tense and dramatic. Used in horror film scores and dramatic classical passages.',
|
||||
beginner: 'All four notes are equally spaced (all minor 3rds apart), making it the most symmetrical and unstable chord. Classic "villain arrives" sound.',
|
||||
tension: 'Extreme — maximum instability',
|
||||
color: 'text-red-600',
|
||||
},
|
||||
half_dim: {
|
||||
name: 'Half-Diminished (m7♭5)',
|
||||
formula: 'Diminished triad + Minor 7th (10 semitones)',
|
||||
vibe: 'Dark and tense but with slightly more resolution than full dim7. The "ii" chord in minor ii–V–i jazz progressions.',
|
||||
beginner: 'Half-diminished sits between a minor 7th and a fully diminished chord. It\'s the moody jazz workhorse — think the intro to "Autumn Leaves".',
|
||||
tension: 'High — tense but musical',
|
||||
color: 'text-orange-500',
|
||||
},
|
||||
aug: {
|
||||
name: 'Augmented',
|
||||
formula: 'Root + Major 3rd (4 semitones) + Augmented 5th (8 semitones) — all major 3rds',
|
||||
vibe: 'Eerie, floating, dreamlike. The raised 5th creates instability that can resolve either up or down.',
|
||||
beginner: 'Augmented chords sound like something is about to happen. They\'re often used as a passing chord between major and minor — the 5th feels like it\'s "reaching" upward.',
|
||||
tension: 'High — ambiguous direction',
|
||||
color: 'text-emerald-400',
|
||||
},
|
||||
sus4: {
|
||||
name: 'Suspended 4th',
|
||||
formula: 'Root + Perfect 4th (5 semitones) + Perfect 5th (7 semitones)',
|
||||
vibe: 'Open, unresolved, expectant. The 3rd is replaced by a 4th — neither major nor minor, just floating.',
|
||||
beginner: '"Sus" means suspended — the 3rd is suspended in mid-air. It wants to drop down to a major or minor chord. Classic rock move: sus4 → major.',
|
||||
tension: 'Medium — pleasant tension, easy on the ear',
|
||||
color: 'text-cyan-400',
|
||||
},
|
||||
sus2: {
|
||||
name: 'Suspended 2nd',
|
||||
formula: 'Root + Major 2nd (2 semitones) + Perfect 5th (7 semitones)',
|
||||
vibe: 'Airy, spacious, ambiguous. Like sus4 but lighter — the 2nd sits high above the root.',
|
||||
beginner: 'Sus2 is a favourite of modern pop and ambient music. Without a 3rd, it has no major/minor quality — it just floats. Think Sting, U2, Coldplay.',
|
||||
tension: 'Low-medium — open and spacious',
|
||||
color: 'text-teal-400',
|
||||
},
|
||||
maj6: {
|
||||
name: 'Major 6th',
|
||||
formula: 'Major triad + Major 6th (9 semitones)',
|
||||
vibe: 'Sweet, vintage, nostalgic. The 6th adds a note from the scale without the tension of a 7th.',
|
||||
beginner: "The 6th is a colour tone that sweetens a major chord. Common in jazz, bossa nova, and 50s pop — \"Misty\" and \"Fly Me To The Moon\" territory.",
|
||||
tension: 'Very low — sweeter than major triad',
|
||||
color: 'text-amber-300',
|
||||
},
|
||||
min6: {
|
||||
name: 'Minor 6th',
|
||||
formula: 'Minor triad + Major 6th (9 semitones)',
|
||||
vibe: 'Bittersweet, exotic, dramatic. A major 6th over a minor chord creates a striking contrast.',
|
||||
beginner: 'Minor 6ths have a flamenco/tango feel. The bright 6th sitting on top of a dark minor chord creates a sophisticated tension — think Django Reinhardt.',
|
||||
tension: 'Medium — intriguing contrast',
|
||||
color: 'text-amber-400',
|
||||
},
|
||||
add9: {
|
||||
name: 'Add 9',
|
||||
formula: 'Major triad + Major 9th (14 semitones = octave + 2)',
|
||||
vibe: 'Open, modern, slightly epic. The 9th adds colour without the smoothness of a 7th.',
|
||||
beginner: 'Add9 is the chord of modern rock and pop. Unlike maj9 (which also has a 7th), add9 keeps things clean and direct. Coldplay, Radiohead, and U2 love it.',
|
||||
tension: 'Very low — bright and open',
|
||||
color: 'text-lime-400',
|
||||
},
|
||||
}
|
||||
|
||||
const INTERVAL_NAMES = {
|
||||
0: 'Root', 2: 'Major 2nd', 3: 'Minor 3rd', 4: 'Major 3rd',
|
||||
5: 'Perfect 4th', 6: 'Tritone (♭5)', 7: 'Perfect 5th',
|
||||
8: 'Aug 5th', 9: 'Major 6th', 10: 'Minor 7th', 11: 'Major 7th',
|
||||
14: 'Major 9th',
|
||||
}
|
||||
|
||||
function TheoryTab({ chordName }) {
|
||||
const parsed = parseChord(chordName)
|
||||
if (!parsed) return <p className="text-gray-500 text-sm text-center py-8">Could not parse chord.</p>
|
||||
|
||||
const { rootPc, type } = parsed
|
||||
const typeInfo = CHORD_TYPES[type]
|
||||
const theory = CHORD_THEORY[type]
|
||||
const subs = getChordSubstitutions(chordName)
|
||||
|
||||
// Actual note names
|
||||
const noteNames = (typeInfo?.intervals ?? []).map(iv => NOTES[(rootPc + iv) % 12])
|
||||
|
||||
// Roles this chord can play
|
||||
const ROLES = []
|
||||
for (let keyPc = 0; keyPc < 12; keyPc++) {
|
||||
for (const mode of ['major', 'minor']) {
|
||||
const diatonicChords = getChordsInKey(NOTES[keyPc], mode)
|
||||
const idx = diatonicChords.indexOf(chordName)
|
||||
if (idx !== -1) {
|
||||
const rn = toRomanNumeral(chordName, NOTES[keyPc], mode)
|
||||
ROLES.push({ keyRoot: NOTES[keyPc], mode, rn })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* ── What is this chord? ── */}
|
||||
<div className="p-4 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-baseline gap-3 mb-3">
|
||||
<span className={`text-lg font-black ${theory?.color ?? 'text-accent'}`}>{chordName}</span>
|
||||
<span className="text-sm text-gray-400">{theory?.name ?? type}</span>
|
||||
</div>
|
||||
{theory && (
|
||||
<>
|
||||
<p className="text-sm text-gray-200 leading-relaxed mb-2">{theory.beginner}</p>
|
||||
<p className="text-xs text-gray-500 italic leading-relaxed">{theory.vibe}</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Notes & Formula ── */}
|
||||
<div className="p-4 bg-surface border border-border rounded-xl">
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">Notes in this chord</p>
|
||||
<div className="flex flex-wrap gap-2 mb-3">
|
||||
{(typeInfo?.intervals ?? []).map((iv, i) => (
|
||||
<div key={i} className={`flex flex-col items-center px-3 py-2 rounded-xl border ${
|
||||
i === 0 ? 'bg-accent/20 border-accent text-accent' : 'bg-panel border-border text-gray-300'
|
||||
}`}>
|
||||
<span className="text-base font-black">{noteNames[i]}</span>
|
||||
<span className="text-[10px] text-gray-500 leading-none mt-0.5">{INTERVAL_NAMES[iv] ?? `+${iv}`}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{theory && (
|
||||
<div className="text-xs text-gray-600 font-mono bg-panel/50 rounded-lg px-3 py-2 border border-border">
|
||||
{theory.formula}
|
||||
</div>
|
||||
)}
|
||||
{theory && (
|
||||
<div className="flex items-center gap-2 mt-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-gray-600">Tension:</span>
|
||||
<span className="text-xs text-gray-400">{theory.tension}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Chord substitutions ── */}
|
||||
{subs.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">Colour swaps — try these instead</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
{subs.map((sub, i) => (
|
||||
<div key={i} className="flex items-start gap-3 p-3 bg-surface border border-border rounded-xl hover:border-accent/30 transition-colors">
|
||||
<span className="text-sm font-black text-accent shrink-0 w-16">{sub.chord}</span>
|
||||
<p className="text-xs text-gray-400 leading-snug">{sub.tip}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Keys this chord belongs to ── */}
|
||||
{ROLES.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-3">{chordName} appears in these keys</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{ROLES.slice(0, 10).map(({ keyRoot, mode, rn }) => (
|
||||
<div key={`${keyRoot}-${mode}`}
|
||||
className="px-3 py-2 bg-surface border border-border rounded-xl text-xs flex items-center gap-2">
|
||||
<span className="font-bold text-white">{keyRoot}</span>
|
||||
<span className="text-gray-500 capitalize">{mode}</span>
|
||||
<span className="text-amber-400 font-bold">{rn}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-[11px] text-gray-700 mt-2">
|
||||
Roman numerals show the chord's role: I/i = home, IV = subdominant, V = dominant tension, vi/♭VI = relative minor/major, etc.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Learn tab ────────────────────────────────────────────────────────────────
|
||||
|
||||
function LearnTab({ chordName }) {
|
||||
const parsed = parseChord(chordName)
|
||||
const playbook = parsed ? CHORD_PLAYBOOK[parsed.type] : null
|
||||
|
||||
if (!playbook) {
|
||||
return <p className="text-gray-500 text-sm text-center py-8">No jam content for {chordName} yet.</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* ── Jam role ── */}
|
||||
<div className="px-4 py-3 bg-accent/10 border border-accent/20 rounded-xl">
|
||||
<p className="text-[10px] uppercase tracking-wider text-accent/60 mb-1">Your role in the jam</p>
|
||||
<p className="text-sm text-white leading-relaxed">{playbook.jamRole}</p>
|
||||
</div>
|
||||
|
||||
{/* ── Voicings for jamming ── */}
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Voicings — when to use which</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{playbook.voicings.map((v, i) => (
|
||||
<div key={i} className="flex gap-3 p-3 bg-surface border border-border rounded-xl hover:border-accent/20 transition-colors">
|
||||
<span className="text-accent font-black text-lg shrink-0 leading-none mt-0.5">{i + 1}</span>
|
||||
<div>
|
||||
<p className="text-xs font-bold text-white mb-0.5">{v.name}</p>
|
||||
<p className="text-xs text-gray-400 leading-relaxed">{v.use}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-[10px] text-gray-700 mt-2">See the Guitar tab for the actual fingerings of each shape.</p>
|
||||
</div>
|
||||
|
||||
{/* ── Licks & fills ── */}
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Licks & fills</p>
|
||||
<div className="flex flex-col gap-3">
|
||||
{playbook.licks.map((l, i) => (
|
||||
<div key={i} className="p-4 bg-surface border border-border rounded-xl hover:border-accent/30 transition-colors">
|
||||
<div className="flex items-center gap-2 mb-2 flex-wrap">
|
||||
<p className="text-sm font-bold text-white">{l.title}</p>
|
||||
<span className="text-[9px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-accent/10 border border-accent/20 text-accent">{l.style}</span>
|
||||
</div>
|
||||
<pre className="text-[10px] font-mono text-accent/70 bg-black/40 border border-border rounded-lg px-3 py-2 overflow-x-auto leading-relaxed whitespace-pre mb-2">{l.tab}</pre>
|
||||
<p className="text-xs text-amber-400/80">
|
||||
<span className="font-semibold text-amber-400">Key insight: </span>{l.tip}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Jam tips ── */}
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Jam tips</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{playbook.jamTips.map((tip, i) => (
|
||||
<div key={i} className="flex gap-2.5 text-xs text-gray-300 leading-relaxed p-2.5 rounded-lg bg-surface border border-border">
|
||||
<span className="text-accent shrink-0 font-bold mt-0.5">→</span>
|
||||
<p>{tip}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Loop station practice ── */}
|
||||
{playbook.loopPractice?.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Loop station practice</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{playbook.loopPractice.map((lp, i) => (
|
||||
<div key={i} className="p-3 bg-surface border border-border rounded-xl border-l-2 border-l-accent/40">
|
||||
<p className="text-xs font-bold text-white mb-1">🔁 {lp.title}</p>
|
||||
<p className="text-xs text-gray-400 leading-relaxed">{lp.body}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Explore tab ──────────────────────────────────────────────────────────────
|
||||
function ExploreTab({ initialChord, keyInfo, chordHistory }) {
|
||||
const parsed = parseChord(initialChord)
|
||||
const [root, setRoot] = useState(parsed ? NOTES[parsed.rootPc] : 'C')
|
||||
const [typeKey, setTypeKey] = useState(parsed?.type ?? 'maj')
|
||||
const [subTab, setSubTab] = useState('guitar')
|
||||
const [active, setActive] = useState(initialChord ?? '')
|
||||
|
||||
const chordName = chordDisplayName(root, typeKey)
|
||||
|
||||
function selectChord(chord) {
|
||||
setActive(chord)
|
||||
const p = parseChord(chord)
|
||||
if (p) { setRoot(NOTES[p.rootPc]); setTypeKey(p.type) }
|
||||
}
|
||||
|
||||
const recentChords = [...new Set([...(chordHistory ?? [])].reverse())].slice(0, 12)
|
||||
const keyChords = keyInfo?.root ? getChordsInKey(keyInfo.root, keyInfo.mode ?? 'major') : []
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
|
||||
{/* ── Contextual quick-picks ── */}
|
||||
{(recentChords.length > 0 || keyChords.length > 0) && (
|
||||
<div className="flex flex-col gap-3 p-3 bg-surface border border-border rounded-xl">
|
||||
<ChordQuickPick label="History" chords={recentChords} active={active} keyInfo={keyInfo} onSelect={selectChord} />
|
||||
{keyChords.length > 0 && (
|
||||
<>
|
||||
{recentChords.length > 0 && <div className="h-px bg-border" />}
|
||||
<ChordQuickPick
|
||||
label={`${keyInfo.root} ${keyInfo.mode ?? ''}`}
|
||||
chords={keyChords} active={active} keyInfo={keyInfo} onSelect={selectChord}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Manual picker ── */}
|
||||
<div className="flex flex-wrap gap-2 items-center p-3 bg-surface border border-border rounded-xl">
|
||||
<span className="text-xs text-gray-500 shrink-0">Root:</span>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{NOTES.map(n => (
|
||||
<button key={n}
|
||||
onClick={() => { setRoot(n); setActive('') }}
|
||||
className={`px-2 py-0.5 rounded text-xs font-bold transition-all ${
|
||||
root === n ? 'bg-accent text-white' : 'bg-border text-gray-400 hover:text-white'
|
||||
}`}>
|
||||
{n}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="w-px h-4 bg-border shrink-0" />
|
||||
<span className="text-xs text-gray-500 shrink-0">Type:</span>
|
||||
<div className="relative">
|
||||
<select
|
||||
value={typeKey}
|
||||
onChange={e => { setTypeKey(e.target.value); setActive('') }}
|
||||
className="appearance-none bg-panel border border-border rounded-lg pl-2 pr-6 py-1 text-xs text-gray-200 cursor-pointer focus:outline-none focus:border-accent"
|
||||
>
|
||||
{CHORD_SUFFIX_OPTIONS.map(o => (
|
||||
<option key={o.key} value={o.key}>{o.label}</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs">▾</span>
|
||||
</div>
|
||||
<div className="ml-auto text-xl font-black text-accent">{chordName}</div>
|
||||
</div>
|
||||
|
||||
{/* ── Sub-tabs ── */}
|
||||
<div className="flex gap-1 bg-surface border border-border rounded-xl p-1 overflow-x-auto">
|
||||
{[
|
||||
{ key: 'guitar', label: '🎸 Guitar' },
|
||||
{ key: 'piano', label: '🎹 Piano' },
|
||||
].map(t => (
|
||||
<button key={t.key}
|
||||
onClick={() => setSubTab(t.key)}
|
||||
className={`px-4 py-1.5 rounded-lg text-sm font-semibold transition-all whitespace-nowrap ${
|
||||
subTab === t.key ? 'bg-accent text-white' : 'text-gray-400 hover:text-white'
|
||||
}`}>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{subTab === 'guitar' && <GuitarTab chordName={chordName} />}
|
||||
{subTab === 'piano' && <PianoTab chordName={chordName} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main modal ───────────────────────────────────────────────────────────────
|
||||
|
||||
export default function ChordDetailModal({ chord, onClose, onChordClick, keyInfo, chordHistory }) {
|
||||
const [tab, setTab] = useState('guitar')
|
||||
|
||||
// Reset tab when chord changes
|
||||
useEffect(() => { setTab('guitar') }, [chord])
|
||||
|
||||
// Close on Escape
|
||||
useEffect(() => {
|
||||
function onKey(e) { if (e.key === 'Escape') onClose() }
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [onClose])
|
||||
|
||||
if (!chord) return null
|
||||
|
||||
const parsed = parseChord(chord)
|
||||
const typeName = parsed ? (CHORD_SUFFIX_OPTIONS.find(o => o.key === parsed.type)?.label ?? parsed.type) : ''
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-start justify-center bg-black/70 backdrop-blur-sm p-4 overflow-y-auto"
|
||||
onClick={e => { if (e.target === e.currentTarget) onClose() }}
|
||||
>
|
||||
<div className="w-full max-w-3xl bg-panel border border-border rounded-2xl shadow-2xl mt-8 mb-8">
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-6 py-4 border-b border-border">
|
||||
<div>
|
||||
<h2 className="text-3xl font-black text-accent leading-none">{chord}</h2>
|
||||
<p className="text-xs text-gray-500 mt-0.5">{typeName} chord · tap a voicing to study it</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="p-2 text-gray-500 hover:text-white transition-colors text-xl leading-none"
|
||||
aria-label="Close"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tab bar */}
|
||||
<div className="flex gap-1 px-6 pt-4 overflow-x-auto">
|
||||
{[
|
||||
{ key: 'guitar', label: '🎸 Guitar' },
|
||||
{ key: 'piano', label: '🎹 Piano' },
|
||||
{ key: 'theory', label: '📚 Theory' },
|
||||
{ key: 'learn', label: '🎓 Learn' },
|
||||
{ key: 'progressions', label: '🎵 Progressions' },
|
||||
{ key: 'explore', label: '🔍 Explore' },
|
||||
].map(t => (
|
||||
<button key={t.key}
|
||||
onClick={() => setTab(t.key)}
|
||||
className={`px-4 py-2 rounded-t-xl text-sm font-semibold transition-all border-b-2 whitespace-nowrap ${
|
||||
tab === t.key
|
||||
? 'text-accent border-accent bg-accent/10'
|
||||
: 'text-gray-500 border-transparent hover:text-gray-300'
|
||||
}`}>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="px-6 py-5">
|
||||
{tab === 'guitar' && <GuitarTab chordName={chord} />}
|
||||
{tab === 'piano' && <PianoTab chordName={chord} />}
|
||||
{tab === 'theory' && <TheoryTab chordName={chord} />}
|
||||
{tab === 'learn' && <LearnTab chordName={chord} />}
|
||||
{tab === 'progressions' && <ProgressionsSubTab chordName={chord} onChordClick={c => { onChordClick?.(c) }} />}
|
||||
{tab === 'explore' && <ExploreTab initialChord={chord} keyInfo={keyInfo} chordHistory={chordHistory} />}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
// Compact SVG guitar chord-diagram. Renders the KB guitar shape format (D-01b).
|
||||
// Secondary per-station voicing thumbnail in the Roadmap panel.
|
||||
//
|
||||
// Two shape forms (see src/data/kb/SCHEMA.md):
|
||||
// movable: { rootStr, offsets, fingers }
|
||||
// - offsets: 6 entries low-E→high-E, integers = fret offset from the barre
|
||||
// (base) fret, 'x' = muted. The base fret is derived from where the chord
|
||||
// root (rootPc) sits on rootStr in standard tuning.
|
||||
// open: { frets, onlyRoot, fingers }
|
||||
// - frets: 6 entries low-E→high-E, 0 = open, 'x' = muted, integers = absolute.
|
||||
//
|
||||
// Props:
|
||||
// shape — movable or open form above
|
||||
// keyRoot — tonic pitch class 0–11 (accepted; see note below)
|
||||
// rootPc — chord root pitch class 0–11 (drives movable placement)
|
||||
// size — 'thumb' (compact ~64px grid) | 'full' (enlarged + finger #s + label)
|
||||
// label — optional chord label shown under the grid
|
||||
//
|
||||
// Note on key-awareness: the SCHEMA derives the movable base fret from where the
|
||||
// root note sits "for the current key". In practice the absolute fret depends only
|
||||
// on the chord root pitch class on rootStr, which is supplied directly as `rootPc`.
|
||||
// keyRoot is accepted for contract compatibility and used as a fallback for rootPc.
|
||||
|
||||
// Standard tuning open-string pitch classes, indexed low-E (0) → high-E (5).
|
||||
const OPEN_PCS = [4, 9, 2, 7, 11, 4] // E A D G B E
|
||||
|
||||
// We render strings top→bottom as high-E first (matches Fretboard.jsx idiom),
|
||||
// so display index 0 = high E, 5 = low E. Data arrays are low-E first, so the
|
||||
// data index for display row `di` is `5 - di`.
|
||||
|
||||
const ACCENT = '#a855f7' // chord-tone tier (root highlight)
|
||||
const DOT = '#e5e7eb' // non-root finger dots (light gray, AA on dark board)
|
||||
const DOT_TEXT_DARK = '#1a1a1a'
|
||||
const BOARD = '#1a120b' // matches Fretboard board fill
|
||||
const FRET_LINE = '#4a3a2a'
|
||||
const NUT_COL = '#c0b090'
|
||||
const STRING_COL = '#9ca3af'
|
||||
const MUTE_OPEN = '#9ca3af'
|
||||
const FRET_LABEL = '#9ca3af'
|
||||
|
||||
const NUM_STRINGS = 6
|
||||
const NUM_FRETS = 5 // visible fret rows in the grid
|
||||
|
||||
// ── Fret resolution ──────────────────────────────────────────────────────────
|
||||
// Returns { frets: number|'x' per display row (high-E first), baseFret, rootRow }
|
||||
// where baseFret is the absolute fret of the top visible grid line (1 = nut shown).
|
||||
function resolveShape(shape, rootPc, keyRoot) {
|
||||
if (!shape) return null
|
||||
|
||||
// Open shape: absolute frets, low-E first.
|
||||
if (Array.isArray(shape.frets)) {
|
||||
const abs = shape.frets // low-E first
|
||||
const fretted = abs.filter(f => typeof f === 'number' && f > 0)
|
||||
const minFret = fretted.length ? Math.min(...fretted) : 0
|
||||
const maxFret = fretted.length ? Math.max(...fretted) : 0
|
||||
// Show the nut (baseFret 1) when the shape reaches up to fret ~4 from the nut.
|
||||
const baseFret = maxFret <= NUM_FRETS ? 1 : minFret
|
||||
return {
|
||||
open: true,
|
||||
absLowE: abs,
|
||||
baseFret,
|
||||
rootPc: typeof shape.onlyRoot === 'number' ? shape.onlyRoot : rootPc,
|
||||
}
|
||||
}
|
||||
|
||||
// Movable shape: offsets relative to a base (barre) fret on rootStr.
|
||||
if (Array.isArray(shape.offsets)) {
|
||||
const rootStr = shape.rootStr // 6 = low E … 1 = high E
|
||||
const rootStrIdx = 6 - rootStr // → low-E-first array index
|
||||
const targetPc = typeof rootPc === 'number' ? rootPc
|
||||
: typeof keyRoot === 'number' ? keyRoot : 0
|
||||
const openPc = OPEN_PCS[rootStrIdx] ?? 4
|
||||
// Smallest fret >= 1 where the root pc lands on rootStr.
|
||||
let baseFret = ((targetPc - openPc) % 12 + 12) % 12
|
||||
if (baseFret === 0) baseFret = 12 // root at open string → use the octave barre
|
||||
return {
|
||||
open: false,
|
||||
offsets: shape.offsets, // low-E first
|
||||
baseFret,
|
||||
rootStrIdx,
|
||||
rootPc: targetPc,
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
// Build per-display-row absolute fret + root flag from a resolved shape.
|
||||
// Returns null if the shape cannot be placed gracefully (root above ~fret 12).
|
||||
function buildRows(resolved) {
|
||||
if (!resolved) return null
|
||||
|
||||
// Absolute fret per low-E-first data index.
|
||||
let absLowE
|
||||
if (resolved.open) {
|
||||
absLowE = resolved.absLowE
|
||||
} else {
|
||||
absLowE = resolved.offsets.map(o =>
|
||||
o === 'x' || o == null ? 'x' : resolved.baseFret + o
|
||||
)
|
||||
}
|
||||
|
||||
// Highest fretted note — degrade if unplayably high.
|
||||
const fretted = absLowE.filter(f => typeof f === 'number' && f > 0)
|
||||
const maxFret = fretted.length ? Math.max(...fretted) : 0
|
||||
if (maxFret > 15) return null
|
||||
|
||||
// Window: lowest visible fret of the grid.
|
||||
// Show the nut if everything fits within NUM_FRETS of it; else start at the
|
||||
// lowest fretted note so the grip sits at the top of the window.
|
||||
const minFret = fretted.length ? Math.min(...fretted) : 0
|
||||
const startFret = maxFret <= NUM_FRETS ? 1 : minFret
|
||||
|
||||
// Root pitch class for colouring.
|
||||
const rootPc = resolved.rootPc
|
||||
|
||||
// Convert to display rows (high-E first → reverse of low-E-first).
|
||||
const rows = []
|
||||
for (let di = 0; di < NUM_STRINGS; di++) {
|
||||
const dataIdx = NUM_STRINGS - 1 - di
|
||||
const f = absLowE[dataIdx]
|
||||
const stringPc = (OPEN_PCS[dataIdx] + (typeof f === 'number' ? f : 0)) % 12
|
||||
const isRoot = typeof f === 'number' && f >= 0 && stringPc === rootPc
|
||||
rows.push({ fret: f, isRoot, stringPc })
|
||||
}
|
||||
|
||||
return { rows, startFret, showNut: startFret === 1 }
|
||||
}
|
||||
|
||||
export default function ChordDiagram({
|
||||
shape,
|
||||
keyRoot,
|
||||
rootPc,
|
||||
size = 'thumb',
|
||||
label,
|
||||
}) {
|
||||
const resolved = resolveShape(shape, rootPc, keyRoot)
|
||||
const built = buildRows(resolved)
|
||||
|
||||
const full = size === 'full'
|
||||
|
||||
// Geometry. thumb grid ~64px wide; full ~2x.
|
||||
const scale = full ? 2 : 1
|
||||
const cell = 11 * scale // px per fret row (vertical)
|
||||
const sw = 11 * scale // px per string gap (horizontal)
|
||||
const padL = 14 * scale // left pad (mute/open markers + start-fret label)
|
||||
const padR = 6 * scale
|
||||
const padT = 11 * scale // top pad (mute/open marker row)
|
||||
const padB = (full ? 16 : 6) * scale // bottom pad (finger numbers / breathing room)
|
||||
|
||||
const gridW = (NUM_STRINGS - 1) * sw
|
||||
const gridH = NUM_FRETS * cell
|
||||
const svgW = padL + gridW + padR
|
||||
const svgH = padT + gridH + padB
|
||||
|
||||
const stringX = si => padL + si * sw // si: 0 = high E (left) … 5 = low E
|
||||
const fretY = fi => padT + fi * cell // fi: 0 = top line … NUM_FRETS
|
||||
|
||||
if (!built) {
|
||||
// Graceful degradation: shape can't be placed.
|
||||
return (
|
||||
<div
|
||||
className="inline-flex flex-col items-center justify-center bg-panel border border-border rounded-lg text-gray-500"
|
||||
style={{ width: svgW, minHeight: svgH }}
|
||||
role="img"
|
||||
aria-label={label ? `${label}: voicing unavailable` : 'voicing unavailable'}
|
||||
>
|
||||
<span style={{ fontSize: 9 * scale }}>—</span>
|
||||
{label && full && <span style={{ fontSize: 8 * scale }} className="mt-1">{label}</span>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const { rows, startFret, showNut } = built
|
||||
|
||||
const fingers = shape?.fingers // low-E first, optional
|
||||
|
||||
const ariaLabel = label
|
||||
? `${label} guitar chord diagram`
|
||||
: 'guitar chord diagram'
|
||||
|
||||
return (
|
||||
<div className="inline-flex flex-col items-center" role="img" aria-label={ariaLabel}>
|
||||
<svg
|
||||
width={svgW}
|
||||
height={svgH}
|
||||
viewBox={`0 0 ${svgW} ${svgH}`}
|
||||
style={{ display: 'block' }}
|
||||
>
|
||||
{/* Board background */}
|
||||
<rect
|
||||
x={padL - 1}
|
||||
y={padT - 1}
|
||||
width={gridW + 2}
|
||||
height={gridH + 2}
|
||||
fill={BOARD}
|
||||
rx={2 * scale}
|
||||
/>
|
||||
|
||||
{/* Start-fret indicator ("5fr") when the grid begins above the nut */}
|
||||
{!showNut && (
|
||||
<text
|
||||
x={padL - 4 * scale}
|
||||
y={fretY(0) + cell * 0.62}
|
||||
textAnchor="end"
|
||||
fontSize={7 * scale}
|
||||
fill={FRET_LABEL}
|
||||
>
|
||||
{startFret}fr
|
||||
</text>
|
||||
)}
|
||||
|
||||
{/* Frets (horizontal lines) */}
|
||||
{Array.from({ length: NUM_FRETS + 1 }, (_, fi) => fi).map(fi => {
|
||||
const topNut = showNut && fi === 0
|
||||
return (
|
||||
<line
|
||||
key={fi}
|
||||
x1={stringX(0)}
|
||||
y1={fretY(fi)}
|
||||
x2={stringX(NUM_STRINGS - 1)}
|
||||
y2={fretY(fi)}
|
||||
stroke={topNut ? NUT_COL : FRET_LINE}
|
||||
strokeWidth={topNut ? 3 * scale : 1 * scale}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Strings (vertical lines) */}
|
||||
{rows.map((_, si) => (
|
||||
<line
|
||||
key={si}
|
||||
x1={stringX(si)}
|
||||
y1={fretY(0)}
|
||||
x2={stringX(si)}
|
||||
y2={fretY(NUM_FRETS)}
|
||||
stroke={STRING_COL}
|
||||
strokeWidth={(si >= 4 ? 1.4 : si >= 2 ? 1.1 : 0.8) * scale}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Per-string markers: mute ✕ / open ○ above the nut, dots on the grid */}
|
||||
{rows.map((row, si) => {
|
||||
const x = stringX(si)
|
||||
const dataIdx = NUM_STRINGS - 1 - si
|
||||
const finger = fingers ? fingers[dataIdx] : 0
|
||||
|
||||
// Muted string → ✕ above the board.
|
||||
if (row.fret === 'x' || row.fret == null) {
|
||||
const my = padT - 4 * scale
|
||||
const r = 3 * scale
|
||||
return (
|
||||
<g key={si} stroke={MUTE_OPEN} strokeWidth={1 * scale} strokeLinecap="round">
|
||||
<line x1={x - r} y1={my - r} x2={x + r} y2={my + r} />
|
||||
<line x1={x - r} y1={my + r} x2={x + r} y2={my - r} />
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
// Open string (absolute fret 0, only meaningful when nut is shown) → ○.
|
||||
if (row.fret === 0) {
|
||||
return (
|
||||
<circle
|
||||
key={si}
|
||||
cx={x}
|
||||
cy={padT - 4 * scale}
|
||||
r={3 * scale}
|
||||
fill="none"
|
||||
stroke={MUTE_OPEN}
|
||||
strokeWidth={1 * scale}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// Fretted note → dot, positioned in its fret row within the window.
|
||||
const rowInWindow = row.fret - startFret // 0-based row from top
|
||||
if (rowInWindow < 0 || rowInWindow >= NUM_FRETS) return null
|
||||
const cy = fretY(rowInWindow) + cell / 2
|
||||
const r = (full ? 4 : 3.5) * scale
|
||||
const fill = row.isRoot ? ACCENT : DOT
|
||||
const showFinger = full && finger > 0
|
||||
return (
|
||||
<g key={si}>
|
||||
<circle cx={x} cy={cy} r={r} fill={fill} />
|
||||
{showFinger && (
|
||||
<text
|
||||
x={x}
|
||||
y={cy + 3 * scale}
|
||||
textAnchor="middle"
|
||||
fontSize={7 * scale}
|
||||
fontWeight="700"
|
||||
fill={row.isRoot ? '#fff' : DOT_TEXT_DARK}
|
||||
>
|
||||
{finger}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</svg>
|
||||
|
||||
{label && (
|
||||
<span
|
||||
className="text-gray-300 leading-none mt-1"
|
||||
style={{ fontSize: full ? 12 : 9 }}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
import { useState } from 'react'
|
||||
import ChordBox from './ChordBox'
|
||||
import RiffDiagram from './RiffDiagram'
|
||||
import { getGuitarVoicings, parseChord } from '../lib/voicings'
|
||||
import { CHORD_TYPES, NOTES, toRomanNumeral } from '../lib/theory'
|
||||
import { findSimilarProgressions, progressionInKey } from '../lib/education'
|
||||
|
||||
// ─── Scale ideas per mode ─────────────────────────────────────────────────────
|
||||
const SCALE_IDEAS = {
|
||||
major: [
|
||||
{ name: 'Major Pentatonic', intervals: '1–2–3–5–6', scaleIntervals: [0,2,4,7,9], desc: 'Safe and bright. Everything you play will land. Start on the root, end on the root.' },
|
||||
{ name: 'Mixolydian', intervals: '1–2–3–4–5–6–♭7', scaleIntervals: [0,2,4,5,7,9,10], desc: 'Major with a bluesy ♭7. The defining sound of classic rock — Sweet Home Alabama lives here.' },
|
||||
{ name: 'Lydian', intervals: '1–2–3–♯4–5–6–7', scaleIntervals: [0,2,4,6,7,9,11], desc: 'Dreamy and floating. The ♯4 is the magic note — use it on long sustained notes for instant wonder.' },
|
||||
],
|
||||
minor: [
|
||||
{ name: 'Minor Pentatonic', intervals: '1–♭3–4–5–♭7', scaleIntervals: [0,3,5,7,10], desc: 'The blues box. Bends on ♭3 and slides to 5 are gold. Start here every time.' },
|
||||
{ name: 'Natural Minor', intervals: '1–2–♭3–4–5–♭6–♭7', scaleIntervals: [0,2,3,5,7,8,10], desc: 'Full Aeolian scale. Melodic and dark. The ♭6 gives it a cinematic quality.' },
|
||||
{ name: 'Dorian', intervals: '1–2–♭3–4–5–6–♭7', scaleIntervals: [0,2,3,5,7,9,10], desc: "Minor with a raised 6th — smooth and soulful. Santana's go-to. That major 6th is everything." },
|
||||
],
|
||||
dorian: [
|
||||
{ name: 'Dorian Mode', intervals: '1–2–♭3–4–5–6–♭7', scaleIntervals: [0,2,3,5,7,9,10], desc: "The raised 6th over minor is the colour. Mix freely with minor pentatonic and touch that 6th note." },
|
||||
{ name: 'Minor Pentatonic', intervals: '1–♭3–4–5–♭7', scaleIntervals: [0,3,5,7,10], desc: 'Safe backbone in Dorian. You can ignore the 6th — or highlight it for that Dorian sparkle.' },
|
||||
{ name: 'Blues Scale', intervals: '1–♭3–4–♭5–5–♭7', scaleIntervals: [0,3,5,6,7,10], desc: 'Add the ♭5 passing tone through the 5 — that slide is the essence of blues expression.' },
|
||||
],
|
||||
mixolydian: [
|
||||
{ name: 'Mixolydian Mode', intervals: '1–2–3–4–5–6–♭7', scaleIntervals: [0,2,4,5,7,9,10], desc: 'The ♭7 is your signature note. Hit it and slide down — instant swagger.' },
|
||||
{ name: 'Major Pentatonic', intervals: '1–2–3–5–6', scaleIntervals: [0,2,4,7,9], desc: 'Works beautifully over the I chord. Clean and reliable when you need to land safely.' },
|
||||
{ name: 'Blues Scale', intervals: '1–♭3–3–4–5–♭7', scaleIntervals: [0,3,4,5,7,10], desc: 'The hybrid blues scale. Bend the ♭3 up to the 3 — that tension and release is everything.' },
|
||||
],
|
||||
phrygian: [
|
||||
{ name: 'Phrygian Mode', intervals: '1–♭2–♭3–4–5–♭6–♭7', scaleIntervals: [0,1,3,5,7,8,10], desc: 'That ♭2 is the spine-chilling note. Lean on it. Spanish fire and metal darkness in one scale.' },
|
||||
{ name: 'Phrygian Dominant',intervals: '1–♭2–3–4–5–♭6–♭7', scaleIntervals: [0,1,4,5,7,8,10], desc: 'Raise the ♭3 to a major 3rd. Flamenco and Middle-Eastern intensity. Dramatic every time.' },
|
||||
{ name: 'Minor Pentatonic', intervals: '1–♭3–4–5–♭7', scaleIntervals: [0,3,5,7,10], desc: 'Avoid the ♭2 and play safe pentatonic runs — then hit the ♭2 as a surprise.' },
|
||||
],
|
||||
lydian: [
|
||||
{ name: 'Lydian Mode', intervals: '1–2–3–♯4–5–6–7', scaleIntervals: [0,2,4,6,7,9,11], desc: 'Float on the ♯4. John Williams writes entire film scores in Lydian. Sustain everything.' },
|
||||
{ name: 'Major Pentatonic', intervals: '1–2–3–5–6', scaleIntervals: [0,2,4,7,9], desc: 'The reliable base. Use Lydian mode sparingly on top for colour.' },
|
||||
{ name: 'Lydian Dominant', intervals: '1–2–3–♯4–5–6–♭7', scaleIntervals: [0,2,4,6,7,9,10], desc: 'Lydian with a ♭7 — the jazz/fusion ♯4 chord sound. Herbie Hancock territory.' },
|
||||
],
|
||||
}
|
||||
|
||||
// Fallback
|
||||
const SCALE_FALLBACK = SCALE_IDEAS.major
|
||||
|
||||
// ─── Style variations for a progression ──────────────────────────────────────
|
||||
const STYLE_VARIATIONS = [
|
||||
{
|
||||
key: 'open',
|
||||
label: 'Open & Spacious',
|
||||
desc: 'Sus2 and add9 voicings — airy, gentle. Great for quiet intros and ambient sections.',
|
||||
typeMap: { maj: 'sus2', min: 'sus2', dom7: 'sus4', maj7: 'add9', min7: 'sus2', add9: 'sus2', sus4: 'sus4', sus2: 'sus2', dim: 'dim', aug: 'aug', half_dim: 'half_dim', maj6: 'sus2', min6: 'sus2' },
|
||||
color: 'text-blue-400',
|
||||
border: 'border-blue-900/40',
|
||||
},
|
||||
{
|
||||
key: 'jazz',
|
||||
label: 'Jazz Upgrade',
|
||||
desc: 'Triads → 7ths — instant sophistication. Works at any tempo, in any band context.',
|
||||
typeMap: { maj: 'maj7', min: 'min7', dom7: 'dom7', add9: 'maj7', sus2: 'sus2', sus4: 'sus4', dim: 'dim7', aug: 'aug', half_dim: 'half_dim', maj6: 'maj6', min6: 'min6' },
|
||||
color: 'text-amber-400',
|
||||
border: 'border-amber-900/40',
|
||||
},
|
||||
{
|
||||
key: 'blues',
|
||||
label: 'Blues Stomp',
|
||||
desc: 'Everything → dom7. Gritty, raw, powerful. All three chords want to slide and bend.',
|
||||
typeMap: { maj: 'dom7', min: 'dom7', maj7: 'dom7', min7: 'dom7', add9: 'dom7', sus2: 'dom7', sus4: 'dom7', dim: 'dim7', aug: 'aug', half_dim: 'dom7', maj6: 'dom7', min6: 'dom7' },
|
||||
color: 'text-red-400',
|
||||
border: 'border-red-900/40',
|
||||
},
|
||||
{
|
||||
key: 'modern',
|
||||
label: 'Neo-Soul / Modern',
|
||||
desc: "Add9 on majors, m7 on minors. D'Angelo, Thundercat, Childish Gambino territory.",
|
||||
typeMap: { maj: 'add9', min: 'min7', dom7: 'dom7', maj7: 'add9', min7: 'min7', add9: 'add9', sus2: 'sus2', sus4: 'sus4', dim: 'dim', aug: 'aug', half_dim: 'half_dim', maj6: 'add9', min6: 'min7' },
|
||||
color: 'text-purple-400',
|
||||
border: 'border-purple-900/40',
|
||||
},
|
||||
]
|
||||
|
||||
// Transform a chord via a type map
|
||||
function transformChord(chordStr, typeMap) {
|
||||
const p = parseChord(chordStr)
|
||||
if (!p) return chordStr
|
||||
const newType = typeMap[p.type] ?? p.type
|
||||
return NOTES[p.rootPc] + (CHORD_TYPES[newType]?.suffix ?? '')
|
||||
}
|
||||
|
||||
// Get best voicings for a chord — prefer open shapes, then low-fret barre
|
||||
function getBestVoicings(chordStr, max = 4) {
|
||||
const all = getGuitarVoicings(chordStr)
|
||||
// Sort: open shapes first (label contains "Open"), then barre
|
||||
const open = all.filter(v => v.label.includes('Open'))
|
||||
const barre = all.filter(v => !v.label.includes('Open'))
|
||||
return [...open, ...barre].slice(0, max)
|
||||
}
|
||||
|
||||
// ─── Per-chord voicing strip ──────────────────────────────────────────────────
|
||||
function ChordStrip({ chordStr, keyInfo, onChordClick }) {
|
||||
const voicings = getBestVoicings(chordStr, 4)
|
||||
const rn = keyInfo?.root ? toRomanNumeral(chordStr, keyInfo.root, keyInfo.mode) : ''
|
||||
return (
|
||||
<div className="flex flex-col gap-2 p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-center gap-2">
|
||||
<button onClick={() => onChordClick?.(chordStr)}
|
||||
className="px-3 py-1 bg-accent/10 border border-accent/40 rounded-lg font-black text-lg text-accent hover:bg-accent/20 transition-colors">
|
||||
{chordStr}
|
||||
</button>
|
||||
{rn && <span className="text-amber-400 text-sm font-semibold">{rn}</span>}
|
||||
<span className="text-[11px] text-gray-600 ml-auto">click for all voicings</span>
|
||||
</div>
|
||||
{voicings.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{voicings.map((v, i) => (
|
||||
<div key={i} className="flex flex-col items-center">
|
||||
<ChordBox frets={v.frets} fingers={v.fingers} barre={v.barre} baseFret={v.baseFret} />
|
||||
<p className="text-[10px] text-gray-600 text-center mt-1 max-w-[100px]">{v.label}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-600 text-xs">No voicings available.</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Style variation section ──────────────────────────────────────────────────
|
||||
function StyleSection({ progression, onChordClick }) {
|
||||
const [expanded, setExpanded] = useState(null)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
{STYLE_VARIATIONS.map(style => {
|
||||
const isOpen = expanded === style.key
|
||||
const transformed = progression.map(c => transformChord(c, style.typeMap))
|
||||
|
||||
return (
|
||||
<div key={style.key} className={`border rounded-xl overflow-hidden transition-colors ${style.border} hover:border-opacity-70`}>
|
||||
<button onClick={() => setExpanded(isOpen ? null : style.key)}
|
||||
className="w-full flex items-center justify-between px-4 py-3 text-left">
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`font-bold text-sm ${style.color}`}>{style.label}</span>
|
||||
<div className="flex gap-1">
|
||||
{transformed.map((c, i) => (
|
||||
<span key={i} className="text-xs font-bold text-gray-300">{c}{i < transformed.length - 1 ? ' →' : ''}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<span className="text-[11px] text-gray-500">{style.desc}</span>
|
||||
</div>
|
||||
<span className="text-gray-600 shrink-0 ml-3">{isOpen ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{isOpen && (
|
||||
<div className="border-t border-border/50 px-4 py-4">
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{transformed.map((c, i) => {
|
||||
const voicings = getBestVoicings(c, 2)
|
||||
return (
|
||||
<div key={i} className="flex flex-col items-center gap-2">
|
||||
<button onClick={() => onChordClick?.(c)}
|
||||
className="px-2 py-0.5 bg-panel border border-border hover:border-accent/50 rounded-lg font-bold text-sm text-gray-200 hover:text-accent transition-all">
|
||||
{c}
|
||||
</button>
|
||||
<div className="flex gap-2">
|
||||
{voicings.map((v, vi) => (
|
||||
<div key={vi} className="flex flex-col items-center">
|
||||
<ChordBox frets={v.frets} fingers={v.fingers} barre={v.barre} baseFret={v.baseFret} />
|
||||
<p className="text-[9px] text-gray-700 text-center mt-0.5 max-w-[90px]">{v.label}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Similar famous progressions ─────────────────────────────────────────────
|
||||
function SimilarSection({ progression, keyInfo, onChordClick }) {
|
||||
const similar = findSimilarProgressions(progression, keyInfo)
|
||||
if (!similar.length) return (
|
||||
<p className="text-gray-600 text-sm text-center py-3">Play more and lock a key — similar progressions will appear here.</p>
|
||||
)
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
{similar.slice(0, 3).map(prog => {
|
||||
const chordsHere = keyInfo?.root ? progressionInKey(prog, keyInfo.root) : []
|
||||
return (
|
||||
<div key={prog.id} className="p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-center flex-wrap gap-2 mb-2">
|
||||
<span className="font-bold text-white text-sm">{prog.name}</span>
|
||||
<span className="text-[10px] font-mono text-gray-600">{prog.pattern}</span>
|
||||
<span className="text-xs text-gray-600 ml-auto">{Math.round(prog.score * 100)}% match</span>
|
||||
</div>
|
||||
{chordsHere.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5 items-center mb-2">
|
||||
{chordsHere.map((c, i) => (
|
||||
<span key={i} className="flex items-center gap-1">
|
||||
<button onClick={() => onChordClick?.(c)}
|
||||
className={`px-2 py-0.5 rounded-lg font-bold text-xs border transition-all ${
|
||||
i === 0 ? 'bg-accent border-accent text-white' : 'bg-panel border-border text-gray-300 hover:border-accent/50 hover:text-accent'
|
||||
}`}>
|
||||
{c}
|
||||
</button>
|
||||
{i < chordsHere.length - 1 && <span className="text-gray-700 text-xs">→</span>}
|
||||
</span>
|
||||
))}
|
||||
<span className="text-[10px] text-gray-600 ml-1">in {keyInfo?.root} {keyInfo?.mode}</span>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-[11px] text-gray-600">{prog.songs.slice(0, 3).join(' · ')}</p>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main panel ───────────────────────────────────────────────────────────────
|
||||
export default function CurrentJamPanel({ keyInfo, chordHistory, detectedProgression, onChordClick }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [view, setView] = useState('voicings') // voicings | scales | styles | similar
|
||||
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
// Working progression: detected loop or last 4 unique chords
|
||||
const workingProgression = detectedProgression?.length
|
||||
? detectedProgression
|
||||
: [...new Set([...chordHistory].reverse())].reverse().slice(-4)
|
||||
|
||||
const scaleIdeas = SCALE_IDEAS[mode] ?? SCALE_FALLBACK
|
||||
const rootPc = root ? NOTES.indexOf(root) : null
|
||||
const hasSession = workingProgression.length > 0
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all">
|
||||
<div className="flex items-center gap-3">
|
||||
<span>CURRENT JAM</span>
|
||||
{root && (
|
||||
<span className="text-[10px] px-2 py-0.5 bg-accent/10 border border-accent/30 rounded text-accent">
|
||||
{root} {mode} {detectedProgression?.length ? `· ${workingProgression.join(' → ')}` : ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span>{open ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="border-t border-border p-4 flex flex-col gap-4">
|
||||
|
||||
{!hasSession ? (
|
||||
<p className="text-gray-600 text-sm text-center py-6">Start listening and play some chords — your jam will appear here.</p>
|
||||
) : (
|
||||
<>
|
||||
{/* ── Progression summary ── */}
|
||||
<div className="flex flex-wrap items-center gap-2 px-3 py-2 bg-surface border border-border rounded-xl">
|
||||
{root ? (
|
||||
<span className="text-accent font-bold text-sm">{root} {mode}</span>
|
||||
) : (
|
||||
<span className="text-gray-600 text-sm">Key detecting…</span>
|
||||
)}
|
||||
{workingProgression.length > 0 && (
|
||||
<>
|
||||
<span className="text-gray-700">·</span>
|
||||
{workingProgression.map((c, i) => (
|
||||
<span key={i} className="flex items-center gap-1">
|
||||
<span className="text-gray-300 font-bold text-sm">{c}</span>
|
||||
{root && <span className="text-amber-400/60 text-[10px]">{toRomanNumeral(c, root, mode)}</span>}
|
||||
{i < workingProgression.length - 1 && <span className="text-gray-700">→</span>}
|
||||
</span>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── View tabs ── */}
|
||||
<div className="flex gap-1 bg-surface border border-border rounded-xl p-1 overflow-x-auto">
|
||||
{[
|
||||
{ key: 'voicings', label: '🎸 Open Voicings' },
|
||||
{ key: 'scales', label: '🎵 Scales to Solo' },
|
||||
{ key: 'styles', label: '🎨 Style Options' },
|
||||
{ key: 'similar', label: '🔗 Similar Progressions' },
|
||||
].map(t => (
|
||||
<button key={t.key} onClick={() => setView(t.key)}
|
||||
className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all whitespace-nowrap ${
|
||||
view === t.key ? 'bg-accent text-white' : 'text-gray-400 hover:text-white'
|
||||
}`}>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* ── Voicings: per chord open shapes ── */}
|
||||
{view === 'voicings' && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-xs text-gray-500">
|
||||
Best open and barre voicings for each chord in your jam. Click a chord name to see all its voicings.
|
||||
</p>
|
||||
{workingProgression.map(chord => (
|
||||
<ChordStrip key={chord} chordStr={chord} keyInfo={keyInfo} onChordClick={onChordClick} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Scales ── */}
|
||||
{view === 'scales' && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-xs text-gray-500">
|
||||
Scales and modes that fit {root ? `${root} ${mode}` : 'your current key'}.
|
||||
Start with the pentatonic — add the extra notes once you feel comfortable.
|
||||
</p>
|
||||
{scaleIdeas.map(idea => (
|
||||
<div key={idea.name} className="p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<span className="font-bold text-white text-sm">{idea.name}</span>
|
||||
<span className="font-mono text-xs text-accent">{idea.intervals}</span>
|
||||
</div>
|
||||
{rootPc !== null && idea.scaleIntervals && (
|
||||
<div className="mb-2 overflow-x-auto">
|
||||
<RiffDiagram rootPc={rootPc} scaleIntervals={idea.scaleIntervals} />
|
||||
<p className="text-[10px] text-gray-600 mt-1">
|
||||
Purple = root · Grey = scale tone · Fret numbers above
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-gray-400 leading-snug">{idea.desc}</p>
|
||||
</div>
|
||||
))}
|
||||
<p className="text-[11px] text-gray-700 text-center">
|
||||
Pro tip: always resolve to a chord tone at the end of a phrase — ♭7 leading to root, or 3rd landing on the 1.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Style options ── */}
|
||||
{view === 'styles' && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<p className="text-xs text-gray-500">
|
||||
Your progression re-voiced four ways. Expand any style to see the chord boxes.
|
||||
</p>
|
||||
<StyleSection progression={workingProgression} onChordClick={onChordClick} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Similar progressions ── */}
|
||||
{view === 'similar' && (
|
||||
<SimilarSection progression={workingProgression} keyInfo={keyInfo} onChordClick={onChordClick} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,646 @@
|
||||
import { useRef } from 'react'
|
||||
import { getScale, getChordTones, NOTES } from '../lib/theory'
|
||||
|
||||
// ─── SVG Piano — 2 octaves (C3–B4) ───────────────────────────────────────────
|
||||
const KEY_W = 30
|
||||
const KEY_H = 80
|
||||
const BLACK_W = 18
|
||||
const BLACK_H = 50
|
||||
const PIANO_W = 14 * KEY_W
|
||||
|
||||
const WHITE_OCT = [0, 2, 4, 5, 7, 9, 11] // pitch classes per octave
|
||||
const BLACK_OCT = [
|
||||
{ pc: 1, wi: 0 }, { pc: 3, wi: 1 }, { pc: 6, wi: 3 },
|
||||
{ pc: 8, wi: 4 }, { pc: 10, wi: 5 },
|
||||
]
|
||||
const WHITE_LABELS = ['C3','D3','E3','F3','G3','A3','B3','C4','D4','E4','F4','G4','A4','B4']
|
||||
|
||||
function PianoSVG({ values, keyNotes, chordNotes, keyH = KEY_H, showPct = false, monoColor = false }) {
|
||||
const max = Math.max(...values, 0.01)
|
||||
const wKeys = []
|
||||
const bKeys = []
|
||||
for (let oct = 0; oct < 2; oct++) {
|
||||
WHITE_OCT.forEach((pc, wi) => wKeys.push({ pc, wi: oct * 7 + wi }))
|
||||
BLACK_OCT.forEach(({ pc, wi }) => bKeys.push({ pc, wi: oct * 7 + wi }))
|
||||
}
|
||||
const svgH = keyH + 6 + (showPct ? 16 : 0)
|
||||
|
||||
return (
|
||||
<svg viewBox={`0 0 ${PIANO_W} ${svgH}`} width="100%" style={{ display: 'block' }}>
|
||||
{/* White keys */}
|
||||
{wKeys.map(({ pc, wi }) => {
|
||||
const energy = values[pc] / max
|
||||
const inChord = chordNotes?.has(pc)
|
||||
const inKey = keyNotes?.has(pc)
|
||||
const x = wi * KEY_W
|
||||
const fillColor = inChord
|
||||
? `rgba(167,139,250,${0.12 + energy * 0.88})`
|
||||
: inKey
|
||||
? monoColor ? `rgba(192,132,252,${0.1 + energy * 0.7})` : `rgba(251,191,36,${0.1 + energy * 0.7})`
|
||||
: `rgba(180,180,190,${0.05 + energy * 0.2})`
|
||||
const pct = showPct ? Math.round(values[pc] * 100) : 0
|
||||
|
||||
return (
|
||||
<g key={`w${wi}`}>
|
||||
<rect x={x+1} y={3} width={KEY_W-2} height={keyH}
|
||||
rx={3} fill="rgb(20,20,26)" stroke="rgba(255,255,255,0.08)" strokeWidth={1} />
|
||||
{energy > (inChord || inKey ? 0.12 : 0.35) && (
|
||||
<rect
|
||||
x={x+1} y={3 + keyH * (1 - Math.min(energy, 1) * 0.85)}
|
||||
width={KEY_W-2} height={keyH * Math.min(energy, 1) * 0.85}
|
||||
rx={2} fill={fillColor} />
|
||||
)}
|
||||
<text x={x + KEY_W/2} y={keyH - 4} textAnchor="middle" fontSize={8}
|
||||
fill={inKey || inChord ? 'rgba(200,200,210,0.9)' : 'rgba(90,90,100,0.8)'}>
|
||||
{WHITE_LABELS[wi]}
|
||||
</text>
|
||||
{showPct && pct > 0 && (
|
||||
<text x={x + KEY_W/2} y={keyH + 14} textAnchor="middle" fontSize={8}
|
||||
fill={inKey ? (monoColor ? 'rgb(192,132,252)' : 'rgb(251,191,36)') : 'rgba(100,100,110,0.8)'}>
|
||||
{pct}%
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Black keys */}
|
||||
{bKeys.map(({ pc, wi }, i) => {
|
||||
const energy = values[pc] / max
|
||||
const inChord = chordNotes?.has(pc)
|
||||
const inKey = keyNotes?.has(pc)
|
||||
const x = wi * KEY_W + KEY_W - BLACK_W / 2
|
||||
const fillColor = inChord
|
||||
? 'rgba(139,92,246,0.9)'
|
||||
: inKey
|
||||
? monoColor ? 'rgba(192,132,252,0.85)' : 'rgba(180,130,0,0.85)'
|
||||
: 'rgba(70,70,80,0.75)'
|
||||
const pct = showPct ? Math.round(values[pc] * 100) : 0
|
||||
|
||||
return (
|
||||
<g key={`b${i}`}>
|
||||
{/* Base */}
|
||||
<rect x={x} y={3} width={BLACK_W} height={BLACK_H}
|
||||
rx={2} fill="rgb(14,14,18)" stroke="rgba(255,255,255,0.06)" strokeWidth={1} />
|
||||
{/* Partial fill from bottom — same mechanic as white keys */}
|
||||
{energy > (inChord || inKey ? 0.05 : 0.35) && (
|
||||
<rect
|
||||
x={x} y={3 + BLACK_H * (1 - Math.min(energy, 1) * 0.9)}
|
||||
width={BLACK_W} height={BLACK_H * Math.min(energy, 1) * 0.9}
|
||||
rx={1} fill={fillColor} />
|
||||
)}
|
||||
{/* % label near top of key (inside) */}
|
||||
{showPct && pct > 0 && (
|
||||
<text x={x + BLACK_W/2} y={3 + 10} textAnchor="middle" fontSize={7}
|
||||
fill={inKey || inChord ? 'rgba(220,220,230,0.9)' : 'rgba(110,110,120,0.7)'}>
|
||||
{pct}%
|
||||
</text>
|
||||
)}
|
||||
{/* Note name near bottom of key */}
|
||||
<text x={x + BLACK_W/2} y={3 + BLACK_H - 5} textAnchor="middle" fontSize={7}
|
||||
fill={inKey || inChord ? 'rgba(210,210,220,0.85)' : 'rgba(110,110,120,0.6)'}>
|
||||
{NOTES[pc]}
|
||||
</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Mini fretboard — guitar mode chroma view ─────────────────────────────────
|
||||
const STRINGS = [
|
||||
{ label: 'e', root: 4 },
|
||||
{ label: 'B', root: 11 },
|
||||
{ label: 'G', root: 7 },
|
||||
{ label: 'D', root: 2 },
|
||||
{ label: 'A', root: 9 },
|
||||
{ label: 'E', root: 4 },
|
||||
]
|
||||
const MF_NUT_X = 22
|
||||
const MF_OPEN_X = 10
|
||||
const MF_FRET_W = 28
|
||||
const MF_STR_H = 16
|
||||
const MF_PAD_T = 16
|
||||
const MF_PAD_B = 8
|
||||
const MF_FRETS = 13 // frets 0–12
|
||||
const MF_DOT_R = 6
|
||||
const MF_W = MF_NUT_X + (MF_FRETS - 1) * MF_FRET_W + 10
|
||||
const MF_H = MF_PAD_T + 5 * MF_STR_H + MF_PAD_B
|
||||
|
||||
const mfFretX = f => MF_NUT_X + (f - 0.5) * MF_FRET_W
|
||||
const mfStringY = si => MF_PAD_T + si * MF_STR_H
|
||||
|
||||
function MiniFretboard({ values, keyNotes, chordNotes, monoColor = false }) {
|
||||
const max = Math.max(...values, 0.01)
|
||||
|
||||
return (
|
||||
<svg viewBox={`0 0 ${MF_W} ${MF_H}`} width="100%" style={{ display: 'block' }}>
|
||||
{/* Board background */}
|
||||
<rect x={MF_NUT_X} y={MF_PAD_T - 5}
|
||||
width={MF_W - MF_NUT_X - 6} height={5 * MF_STR_H + 10}
|
||||
fill="#1a120b" rx={2} />
|
||||
|
||||
{/* Fret position dots */}
|
||||
{[3, 5, 7, 9].map(f => (
|
||||
<circle key={f} cx={mfFretX(f)} cy={MF_PAD_T + 2.5 * MF_STR_H} r={3} fill="#3a2a1a" />
|
||||
))}
|
||||
<circle cx={mfFretX(12)} cy={MF_PAD_T + 1.5 * MF_STR_H} r={3} fill="#3a2a1a" />
|
||||
<circle cx={mfFretX(12)} cy={MF_PAD_T + 3.5 * MF_STR_H} r={3} fill="#3a2a1a" />
|
||||
|
||||
{/* Fret lines */}
|
||||
{Array.from({ length: MF_FRETS - 1 }, (_, i) => i + 1).map(f => (
|
||||
<line key={f}
|
||||
x1={MF_NUT_X + f * MF_FRET_W} y1={MF_PAD_T - 5}
|
||||
x2={MF_NUT_X + f * MF_FRET_W} y2={MF_PAD_T + 5 * MF_STR_H + 5}
|
||||
stroke="#4a3a2a" strokeWidth={1} />
|
||||
))}
|
||||
|
||||
{/* Nut */}
|
||||
<line x1={MF_NUT_X} y1={MF_PAD_T - 5} x2={MF_NUT_X} y2={MF_PAD_T + 5 * MF_STR_H + 5}
|
||||
stroke="#c0b090" strokeWidth={3} />
|
||||
|
||||
{/* Strings */}
|
||||
{STRINGS.map((_, si) => (
|
||||
<line key={si}
|
||||
x1={MF_OPEN_X - MF_DOT_R - 2} y1={mfStringY(si)}
|
||||
x2={MF_W - 6} y2={mfStringY(si)}
|
||||
stroke="#9ca3af"
|
||||
strokeWidth={si < 2 ? 0.8 : si < 4 ? 1.2 : 1.8} />
|
||||
))}
|
||||
|
||||
{/* Fret numbers */}
|
||||
{[3, 5, 7, 9, 12].map(f => (
|
||||
<text key={f} x={mfFretX(f)} y={MF_PAD_T - 5}
|
||||
textAnchor="middle" fontSize={8} fill="#6b7280">{f}</text>
|
||||
))}
|
||||
|
||||
{/* String labels */}
|
||||
{STRINGS.map((s, si) => (
|
||||
<text key={si} x={5} y={mfStringY(si) + 3.5}
|
||||
textAnchor="middle" fontSize={9} fill="#6b7280">{s.label}</text>
|
||||
))}
|
||||
|
||||
{/* Note dots — colored by energy */}
|
||||
{STRINGS.flatMap((str, si) =>
|
||||
Array.from({ length: MF_FRETS }, (_, fi) => {
|
||||
const pc = (str.root + fi) % 12
|
||||
const energy = values[pc] / max
|
||||
const inChord = chordNotes?.has(pc)
|
||||
const inKey = keyNotes?.has(pc)
|
||||
if (!inChord && !inKey && energy < 0.35) return null
|
||||
if ((inChord || inKey) && energy < 0.08) return null
|
||||
|
||||
const cx = fi === 0 ? MF_OPEN_X : mfFretX(fi)
|
||||
const cy = mfStringY(si)
|
||||
|
||||
let fill, textFill
|
||||
if (inChord) {
|
||||
fill = `rgba(168,85,247,${0.3 + energy * 0.7})`
|
||||
textFill = '#fff'
|
||||
} else if (inKey) {
|
||||
fill = monoColor ? `rgba(192,132,252,${0.2 + energy * 0.75})` : `rgba(245,158,11,${0.2 + energy * 0.75})`
|
||||
textFill = monoColor ? '#fff' : 'rgba(0,0,0,0.85)'
|
||||
} else {
|
||||
fill = `rgba(100,100,120,${energy * 0.7})`
|
||||
textFill = 'rgba(180,180,190,0.7)'
|
||||
}
|
||||
|
||||
return (
|
||||
<g key={`${si}-${fi}`}>
|
||||
{energy > 0.3 && (inChord || inKey) && (
|
||||
<circle cx={cx} cy={cy} r={MF_DOT_R + 4}
|
||||
fill={inChord ? 'rgba(168,85,247,0.25)' : monoColor ? 'rgba(192,132,252,0.2)' : 'rgba(245,158,11,0.2)'}
|
||||
style={{ filter: 'blur(4px)' }} />
|
||||
)}
|
||||
<circle cx={cx} cy={cy} r={MF_DOT_R} fill={fill} />
|
||||
<text x={cx} y={cy + 3.5} textAnchor="middle" fontSize={7} fontWeight="600" fill={textFill}>
|
||||
{NOTES[pc]}
|
||||
</text>
|
||||
</g>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Oscilloscope strip ───────────────────────────────────────────────────────
|
||||
const OSC_W = 600
|
||||
const OSC_H = 110
|
||||
|
||||
function Oscilloscope({ waveform }) {
|
||||
const { wave, rms, detectedFreq, detectedNote } = waveform || {}
|
||||
const silent = !rms || rms < 0.005
|
||||
|
||||
// ── Note scroll history — last 5 distinct notes ───────────────────────────
|
||||
const noteHistoryRef = useRef([]) // [{ note, freq, id }, ...] oldest first
|
||||
const lastNoteRef = useRef(null)
|
||||
const noteIdRef = useRef(0)
|
||||
const lastDisplayRef = useRef(null) // last detected note shown in header — never flickers
|
||||
if (detectedNote && detectedNote !== lastNoteRef.current) {
|
||||
lastNoteRef.current = detectedNote
|
||||
lastDisplayRef.current = { note: detectedNote, freq: detectedFreq }
|
||||
noteHistoryRef.current.push({ note: detectedNote, freq: detectedFreq, id: noteIdRef.current++ })
|
||||
if (noteHistoryRef.current.length > 5) noteHistoryRef.current.shift()
|
||||
} else if (detectedFreq && detectedNote) {
|
||||
lastDisplayRef.current = { note: detectedNote, freq: detectedFreq }
|
||||
}
|
||||
|
||||
// ── Ghost waveform — holds the last clear-pitch shape, fades slowly ───────
|
||||
const ghostRef = useRef({ path: '', fill: '', opacity: 0 })
|
||||
if (detectedFreq) {
|
||||
ghostRef.current = { path: '', fill: '', opacity: 1 } // will be filled below
|
||||
} else {
|
||||
ghostRef.current = { ...ghostRef.current, opacity: ghostRef.current.opacity * 0.97 }
|
||||
}
|
||||
|
||||
let path = '', sinePath = ''
|
||||
if (wave?.length) {
|
||||
const mid = OSC_H / 2
|
||||
const waveAmp = Math.max(...wave.map(Math.abs), 0.001)
|
||||
const gain = Math.min((OSC_H * 0.44) / waveAmp, OSC_H * 0.44)
|
||||
|
||||
const lo = Math.floor(wave.length / 4)
|
||||
const hi = Math.floor(wave.length / 2)
|
||||
let offset = lo
|
||||
for (let i = lo; i < hi - 1; i++) {
|
||||
if (wave[i] <= 0 && wave[i + 1] > 0) { offset = i; break }
|
||||
}
|
||||
const drawLen = Math.min(wave.length - offset, Math.floor(wave.length * 0.85))
|
||||
const step = OSC_W / drawLen
|
||||
|
||||
path = Array.from({ length: drawLen }, (_, i) => {
|
||||
const v = wave[offset + i]
|
||||
return `${i === 0 ? 'M' : 'L'}${(i * step).toFixed(1)},${(mid - v * gain).toFixed(1)}`
|
||||
}).join(' ')
|
||||
|
||||
// Capture ghost path when we have a clear pitch
|
||||
if (detectedFreq) {
|
||||
ghostRef.current.path = path
|
||||
ghostRef.current.fill = path + ` L${OSC_W},${mid} L0,${mid} Z`
|
||||
}
|
||||
|
||||
if (detectedFreq) {
|
||||
const effectiveSR = 44100 / 8
|
||||
const sineAmp = Math.min(waveAmp * gain * 0.55, OSC_H * 0.38)
|
||||
sinePath = Array.from({ length: 300 }, (_, i) => {
|
||||
const t = i / 299
|
||||
const x = (t * OSC_W).toFixed(1)
|
||||
const phase = ((offset + t * drawLen) / effectiveSR) * detectedFreq * Math.PI * 2
|
||||
const y = (mid - Math.sin(phase) * sineAmp).toFixed(1)
|
||||
return `${i === 0 ? 'M' : 'L'}${x},${y}`
|
||||
}).join(' ')
|
||||
}
|
||||
}
|
||||
|
||||
const lineColor = detectedFreq
|
||||
? 'rgba(168,85,247,0.9)'
|
||||
: silent ? 'rgba(50,50,60,0.8)' : 'rgba(100,200,140,0.75)'
|
||||
|
||||
const ghost = ghostRef.current
|
||||
const ghostOp = ghost.opacity
|
||||
const noteHistory = noteHistoryRef.current
|
||||
const lastDisplay = lastDisplayRef.current
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest">Oscilloscope — raw mic input</p>
|
||||
<div className="flex items-center gap-3">
|
||||
{lastDisplay && (
|
||||
<>
|
||||
<span className={`text-xs font-bold ${detectedFreq ? 'text-accent' : 'text-gray-500'}`}>{lastDisplay.note}</span>
|
||||
<span className="text-xs text-gray-500 tabular-nums">{lastDisplay.freq.toFixed(1)} Hz</span>
|
||||
<span className="text-xs text-gray-600 tabular-nums">{(1000 / lastDisplay.freq).toFixed(2)} ms / cycle</span>
|
||||
</>
|
||||
)}
|
||||
{silent && <span className="text-xs text-gray-700">silence</span>}
|
||||
<span className="text-xs text-gray-700 tabular-nums">rms {rms ? (rms * 100).toFixed(1) : '0.0'}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<svg viewBox={`0 0 ${OSC_W} ${OSC_H}`} width="100%" style={{ display: 'block' }}
|
||||
className="rounded-lg bg-surface border border-border">
|
||||
{/* Zero line */}
|
||||
<line x1={0} y1={OSC_H / 2} x2={OSC_W} y2={OSC_H / 2}
|
||||
stroke="rgba(255,255,255,0.05)" strokeWidth={0.5} />
|
||||
|
||||
{/* Ghost waveform — previous clear-pitch shape fading out */}
|
||||
{ghost.path && ghostOp > 0.04 && !detectedFreq && (
|
||||
<>
|
||||
<path d={ghost.fill} fill={`rgba(168,85,247,${(ghostOp * 0.06).toFixed(3)})`} />
|
||||
<path d={ghost.path} fill="none"
|
||||
stroke={`rgba(150,120,200,${(ghostOp * 0.35).toFixed(3)})`}
|
||||
strokeWidth={0.8} strokeLinejoin="round" strokeLinecap="round" />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Fill body */}
|
||||
{path && (
|
||||
<path
|
||||
d={`${path} L${OSC_W},${OSC_H / 2} L0,${OSC_H / 2} Z`}
|
||||
fill={detectedFreq
|
||||
? 'rgba(168,85,247,0.08)'
|
||||
: silent ? 'none' : 'rgba(90,190,130,0.07)'}
|
||||
/>
|
||||
)}
|
||||
{/* Waveform line */}
|
||||
{path && <path d={path} fill="none" stroke={lineColor} strokeWidth={0.9}
|
||||
strokeLinejoin="round" strokeLinecap="round" />}
|
||||
{/* Sine overlay */}
|
||||
{sinePath && <path d={sinePath} fill="none"
|
||||
stroke="rgba(168,85,247,0.28)" strokeWidth={0.9}
|
||||
strokeLinejoin="round" strokeDasharray="5 4" />}
|
||||
|
||||
{/* Scrolling note history — newest on right, slides left on each new note */}
|
||||
{noteHistory.map((entry, i) => {
|
||||
const age = noteHistory.length - 1 - i // 0 = newest
|
||||
const x = OSC_W - 28 - age * 100
|
||||
const op = (1 - age * 0.18).toFixed(2)
|
||||
const isNew = age === 0
|
||||
return (
|
||||
<g key={entry.id}
|
||||
style={{ transform: `translateX(${x}px)`, transition: 'transform 0.45s cubic-bezier(0.4,0,0.2,1)' }}>
|
||||
<text x={0} y={OSC_H - 18} textAnchor="middle"
|
||||
fontSize={isNew ? 13 : 11} fontWeight={isNew ? '700' : '400'}
|
||||
fill={isNew ? `rgba(168,85,247,${op})` : `rgba(160,130,210,${op})`}>
|
||||
{entry.note}
|
||||
</text>
|
||||
<text x={0} y={OSC_H - 7} textAnchor="middle" fontSize={7}
|
||||
fill={`rgba(120,100,160,${(parseFloat(op) * 0.7).toFixed(2)})`}>
|
||||
{entry.freq ? entry.freq.toFixed(0) : ''}Hz
|
||||
</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</svg>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Frequency spectrum ───────────────────────────────────────────────────────
|
||||
const SPEC_H = 130
|
||||
const SPEC_F_MIN = 40
|
||||
const SPEC_F_MAX = 4000
|
||||
const SPEC_LOG = Math.log(SPEC_F_MAX / SPEC_F_MIN)
|
||||
|
||||
// Map a frequency in Hz to an x pixel position (log scale)
|
||||
function specX(f, w) {
|
||||
if (f <= SPEC_F_MIN) return 0
|
||||
if (f >= SPEC_F_MAX) return w
|
||||
return w * Math.log(f / SPEC_F_MIN) / SPEC_LOG
|
||||
}
|
||||
|
||||
const SPEC_GRID = [
|
||||
{ label: 'E2', freq: 82.4 },
|
||||
{ label: 'C3', freq: 130.8 },
|
||||
{ label: 'E3', freq: 164.8 },
|
||||
{ label: 'A3', freq: 220 },
|
||||
{ label: 'C4', freq: 261.6 },
|
||||
{ label: 'E4', freq: 329.6 },
|
||||
{ label: 'A4', freq: 440 },
|
||||
{ label: 'C5', freq: 523.3 },
|
||||
{ label: 'C6', freq: 1046.5},
|
||||
{ label: 'C7', freq: 2093 },
|
||||
]
|
||||
|
||||
function SpectrumPanel({ spectrum, detectedFreq }) {
|
||||
const W = OSC_W
|
||||
const ghostRef = useRef(null)
|
||||
const ghostFreqRef = useRef(null) // { freq, opacity }
|
||||
|
||||
// Ghost frequency lines — lock on detection, decay slowly when gone
|
||||
if (detectedFreq) {
|
||||
ghostFreqRef.current = { freq: detectedFreq, opacity: 1 }
|
||||
} else if (ghostFreqRef.current) {
|
||||
ghostFreqRef.current = { freq: ghostFreqRef.current.freq, opacity: ghostFreqRef.current.opacity * 0.97 }
|
||||
}
|
||||
const ghostFreq = ghostFreqRef.current?.opacity > 0.04 ? ghostFreqRef.current.freq : null
|
||||
const ghostOpacity = ghostFreqRef.current?.opacity ?? 0
|
||||
|
||||
// Ghost: rises instantly with signal, decays very slowly — lingers as grey
|
||||
if (spectrum?.length) {
|
||||
if (!ghostRef.current) ghostRef.current = new Float32Array(spectrum.length)
|
||||
const ghost = ghostRef.current
|
||||
for (let i = 0; i < spectrum.length; i++) {
|
||||
ghost[i] = spectrum[i] > ghost[i] ? spectrum[i] : ghost[i] * 0.988
|
||||
}
|
||||
}
|
||||
|
||||
let fillPath = '', strokePath = '', ghostFill = '', ghostStroke = ''
|
||||
|
||||
if (spectrum?.length) {
|
||||
const n = spectrum.length
|
||||
const pts = Array.from({ length: n }, (_, i) => {
|
||||
const x = ((i / (n - 1)) * W).toFixed(1)
|
||||
const y = (SPEC_H * (1 - spectrum[i])).toFixed(1)
|
||||
return `${i === 0 ? 'M' : 'L'}${x},${y}`
|
||||
}).join(' ')
|
||||
strokePath = pts
|
||||
fillPath = pts + ` L${W},${SPEC_H} L0,${SPEC_H} Z`
|
||||
|
||||
const ghost = ghostRef.current
|
||||
if (ghost) {
|
||||
const gpts = Array.from({ length: n }, (_, i) => {
|
||||
const x = ((i / (n - 1)) * W).toFixed(1)
|
||||
const y = (SPEC_H * (1 - ghost[i])).toFixed(1)
|
||||
return `${i === 0 ? 'M' : 'L'}${x},${y}`
|
||||
}).join(' ')
|
||||
ghostStroke = gpts
|
||||
ghostFill = gpts + ` L${W},${SPEC_H} L0,${SPEC_H} Z`
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest mb-1">
|
||||
Frequency spectrum — 40 Hz → 4 kHz (log scale)
|
||||
</p>
|
||||
<svg viewBox={`0 0 ${W} ${SPEC_H}`} width="100%" style={{ display: 'block' }}
|
||||
className="rounded-lg bg-surface border border-border">
|
||||
|
||||
{/* Note grid lines */}
|
||||
{SPEC_GRID.map(({ label, freq }) => {
|
||||
const x = specX(freq, W).toFixed(1)
|
||||
return (
|
||||
<g key={label}>
|
||||
<line x1={x} y1={0} x2={x} y2={SPEC_H - 14}
|
||||
stroke="rgba(255,255,255,0.06)" strokeWidth={1} />
|
||||
<text x={x} y={SPEC_H - 3} textAnchor="middle" fontSize={7.5}
|
||||
fill="rgba(80,80,95,0.9)">{label}</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Ghost — slow-decaying grey residue from previous peaks */}
|
||||
{ghostFill && (
|
||||
<>
|
||||
<path d={ghostFill} fill="rgba(120,120,130,0.08)" />
|
||||
<path d={ghostStroke} fill="none" stroke="rgba(130,130,145,0.30)" strokeWidth={0.7} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Live spectrum fill + stroke */}
|
||||
{fillPath && (
|
||||
<>
|
||||
<path d={fillPath} fill="rgba(80,180,130,0.13)" />
|
||||
<path d={strokePath} fill="none" stroke="rgba(90,200,145,0.55)" strokeWidth={0.8} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Fundamental + harmonics */}
|
||||
{ghostFreq && [1, 2, 3, 4, 5].map(h => {
|
||||
const hf = ghostFreq * h
|
||||
if (hf > SPEC_F_MAX) return null
|
||||
const xNum = specX(hf, W)
|
||||
const x = xNum.toFixed(1)
|
||||
const midi = Math.round(12 * Math.log2(hf / 440) + 69)
|
||||
const note = NOTES[((midi % 12) + 12) % 12]
|
||||
const oct = Math.floor(midi / 12) - 1
|
||||
// Place label left of line near the right edge, right of line elsewhere
|
||||
const labelX = xNum > W - 40 ? xNum - 3 : xNum + 3
|
||||
const anchor = xNum > W - 40 ? 'end' : 'start'
|
||||
|
||||
if (h === 1) {
|
||||
const op = (0.9 * ghostOpacity).toFixed(3)
|
||||
const textOp = (ghostOpacity * 0.95).toFixed(3)
|
||||
return (
|
||||
<g key={h}>
|
||||
<line x1={x} y1={0} x2={x} y2={SPEC_H - 14}
|
||||
stroke={`rgba(168,85,247,${op})`} strokeWidth={1.2} />
|
||||
<text x={labelX} y={10} textAnchor={anchor} fontSize={8} fontWeight="700"
|
||||
fill={`rgba(168,85,247,${textOp})`}>{note}{oct}</text>
|
||||
<text x={labelX} y={20} textAnchor={anchor} fontSize={7}
|
||||
fill={`rgba(168,85,247,${(ghostOpacity * 0.55).toFixed(3)})`}>f</text>
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
const op = ((0.5 - (h - 2) * 0.1) * ghostOpacity).toFixed(3)
|
||||
return (
|
||||
<g key={h}>
|
||||
<line x1={x} y1={0} x2={x} y2={SPEC_H - 14}
|
||||
stroke={`rgba(168,85,247,${op})`} strokeWidth={0.7} strokeDasharray="3 4" />
|
||||
<text x={labelX} y={10} textAnchor={anchor} fontSize={7.5}
|
||||
fill={`rgba(168,85,247,${op})`}>{note}{oct}</text>
|
||||
<text x={labelX} y={19} textAnchor={anchor} fontSize={7}
|
||||
fill={`rgba(168,85,247,${(parseFloat(op) * 0.7).toFixed(3)})`}>{h}f</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</svg>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main component ───────────────────────────────────────────────────────────
|
||||
export default function DebugView({ chroma, chordCandidates, noteAnalysis, waveform, keyInfo, currentChord, instrument = 'guitar', monoColor = false }) {
|
||||
const keyPCs = new Set(keyInfo ? getScale(keyInfo.root, keyInfo.mode).map(n => NOTES.indexOf(n)) : [])
|
||||
const chordPCs = new Set(currentChord ? getChordTones(currentChord).map(n => NOTES.indexOf(n)) : [])
|
||||
|
||||
const chromaArr = chroma ? [...chroma] : new Array(12).fill(0)
|
||||
const histFreq = noteAnalysis ? noteAnalysis.freq : new Array(12).fill(0)
|
||||
const topKeys = noteAnalysis ? noteAnalysis.topKeys : []
|
||||
const totalNotes = noteAnalysis?.total ?? 0
|
||||
const sessionSecs = noteAnalysis?.sessionSecs ?? 0
|
||||
const sessionLabel = sessionSecs >= 60
|
||||
? `${Math.floor(sessionSecs / 60)}m ${sessionSecs % 60}s`
|
||||
: `${sessionSecs}s`
|
||||
const topScore = chordCandidates[0]?.score ?? 1
|
||||
const topKeyScore = topKeys[0]?.score ?? 1
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* ── Live chroma visualization (instrument-synced) ── */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest mb-2">Live chroma — what the engine hears right now</p>
|
||||
{instrument === 'guitar'
|
||||
? <MiniFretboard values={chromaArr} keyNotes={keyPCs} chordNotes={chordPCs} monoColor={monoColor} />
|
||||
: <PianoSVG values={chromaArr} keyNotes={keyPCs} chordNotes={chordPCs} keyH={90} monoColor={monoColor} />
|
||||
}
|
||||
</div>
|
||||
|
||||
{/* ── Bottom three columns ── */}
|
||||
<div className="grid grid-cols-[2fr_1.5fr_1fr] gap-5">
|
||||
|
||||
{/* Col 1: Chord candidates */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest mb-2">Chord candidates</p>
|
||||
<div className="flex flex-col gap-1">
|
||||
{chordCandidates.length === 0 && (
|
||||
<p className="text-gray-700 text-xs">No signal detected</p>
|
||||
)}
|
||||
{chordCandidates.map((c, i) => (
|
||||
<div
|
||||
key={c.name}
|
||||
className={`flex items-center gap-2 px-2 py-1.5 rounded-lg ${
|
||||
i === 0 ? 'bg-accent/10 border border-accent/25' : 'border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<span className="text-xs text-gray-600 w-3 shrink-0">{i + 1}</span>
|
||||
<span className={`text-sm font-bold w-14 shrink-0 ${i === 0 ? 'text-white' : 'text-gray-400'}`}>
|
||||
{c.name}
|
||||
</span>
|
||||
<div className="flex-1 h-1.5 bg-gray-800 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={`h-full rounded-full transition-all duration-300 ${i === 0 ? 'bg-accent' : 'bg-gray-600'}`}
|
||||
style={{ width: `${(c.score / topScore) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-gray-500 w-8 text-right tabular-nums">{c.score.toFixed(2)}</span>
|
||||
<div className="flex gap-1 w-14 justify-end">
|
||||
{c.diatonic && <span className="text-[9px] px-1 rounded bg-green-900/50 text-green-400">key</span>}
|
||||
{c.bassBonus > 0 && <span className="text-[9px] px-1 rounded bg-blue-900/50 text-blue-400">bass</span>}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Col 2: Note history piano with % labels */}
|
||||
<div>
|
||||
<div className="flex items-baseline justify-between mb-2">
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest">Note history</p>
|
||||
{totalNotes > 0 && (
|
||||
<span className="text-[10px] text-gray-600 tabular-nums">
|
||||
{totalNotes.toLocaleString()} notes · {sessionLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<PianoSVG values={histFreq} keyNotes={keyPCs} chordNotes={chordPCs} keyH={70} showPct={true} monoColor={monoColor} />
|
||||
</div>
|
||||
|
||||
{/* Col 3: Key candidates */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest mb-2">Key match scores</p>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{topKeys.length === 0 && (
|
||||
<p className="text-gray-700 text-xs">Not enough history</p>
|
||||
)}
|
||||
{topKeys.map((k, i) => (
|
||||
<div key={`${k.root}-${k.mode}`} className="flex items-center gap-2">
|
||||
<span className={`text-xs w-16 shrink-0 ${i === 0 ? 'text-white font-semibold' : 'text-gray-500'}`}>
|
||||
{k.root} {k.mode === 'major' ? 'maj' : 'min'}
|
||||
</span>
|
||||
<div className="flex-1 h-1 bg-gray-800 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={`h-full rounded-full ${i === 0 ? 'bg-amber-400' : 'bg-gray-600'}`}
|
||||
style={{ width: `${Math.max(0, (k.score / topKeyScore) * 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-[10px] text-gray-600 tabular-nums w-8 text-right">{k.score.toFixed(2)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{/* ── Oscilloscope + spectrum ── */}
|
||||
<div className="flex flex-col gap-3">
|
||||
<Oscilloscope waveform={waveform} />
|
||||
<SpectrumPanel spectrum={waveform?.spectrum} detectedFreq={waveform?.detectedFreq} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import { useRef, useEffect } from 'react'
|
||||
|
||||
// Map a frequency (Hz) to a bin index in the 256-bin log spectrum (40–4000 Hz)
|
||||
function freqToBin(freq) {
|
||||
return Math.round(255 * Math.log(freq / 40) / Math.log(4000 / 40))
|
||||
}
|
||||
|
||||
function bandMax(spectrum, lo, hi) {
|
||||
if (!spectrum) return 0
|
||||
const a = freqToBin(lo)
|
||||
const b = Math.min(freqToBin(hi), spectrum.length - 1)
|
||||
let max = 0
|
||||
for (let i = a; i <= b; i++) if (spectrum[i] > max) max = spectrum[i]
|
||||
return max
|
||||
}
|
||||
|
||||
const BANDS = [
|
||||
{ label: 'Kick', lo: 40, hi: 120, color: '#ef4444' },
|
||||
{ label: 'Snare', lo: 120, hi: 300, color: '#f59e0b' },
|
||||
{ label: 'Mid', lo: 300, hi: 1000, color: '#22c55e' },
|
||||
{ label: 'Presence', lo: 1000, hi: 4000, color: '#60a5fa' },
|
||||
]
|
||||
|
||||
const TIMELINE_MS = 4000 // onset timeline window
|
||||
const RMS_HISTORY = 180 // ~3s at 60fps
|
||||
|
||||
export default function DrumView({ waveform, bpm }) {
|
||||
const rmsHistRef = useRef([])
|
||||
const beatCanvasRef = useRef(null)
|
||||
const rmsCanvasRef = useRef(null)
|
||||
|
||||
const spectrum = waveform?.spectrum ?? null
|
||||
const bandLevels = BANDS.map(b => bandMax(spectrum, b.lo, b.hi))
|
||||
|
||||
// Accumulate RMS history
|
||||
useEffect(() => {
|
||||
if (waveform == null) return
|
||||
const h = rmsHistRef.current
|
||||
h.push(Math.min(waveform.rms * 10, 1))
|
||||
if (h.length > RMS_HISTORY) h.shift()
|
||||
}, [waveform])
|
||||
|
||||
// Draw onset / beat timeline
|
||||
useEffect(() => {
|
||||
const canvas = beatCanvasRef.current
|
||||
if (!canvas) return
|
||||
const ctx = canvas.getContext('2d')
|
||||
const W = canvas.width, H = canvas.height
|
||||
|
||||
ctx.fillStyle = '#0a0a0a'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
|
||||
const onsets = waveform?.onsets ?? []
|
||||
const now = performance.now()
|
||||
|
||||
// Beat grid aligned to the most recent onset
|
||||
if (bpm) {
|
||||
const beatMs = 60000 / bpm
|
||||
const numBeats = Math.ceil(TIMELINE_MS / beatMs) + 1
|
||||
const latest = onsets[onsets.length - 1]
|
||||
const phase = latest != null ? (now - latest) % beatMs : 0
|
||||
for (let b = 0; b <= numBeats; b++) {
|
||||
const ageMs = b * beatMs - phase
|
||||
if (ageMs < 0 || ageMs > TIMELINE_MS) continue
|
||||
const x = W * (1 - ageMs / TIMELINE_MS)
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.07)'
|
||||
ctx.lineWidth = 1
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
}
|
||||
}
|
||||
|
||||
// Onset dots + vertical tails
|
||||
const recent = onsets.filter(t => now - t <= TIMELINE_MS)
|
||||
for (const t of recent) {
|
||||
const age = now - t
|
||||
const x = W * (1 - age / TIMELINE_MS)
|
||||
const alpha = Math.pow(1 - age / TIMELINE_MS, 0.4)
|
||||
ctx.strokeStyle = `rgba(168,85,247,${(alpha * 0.35).toFixed(2)})`
|
||||
ctx.lineWidth = 1
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
ctx.fillStyle = `rgba(168,85,247,${alpha.toFixed(2)})`
|
||||
ctx.beginPath(); ctx.arc(x, H / 2, 5, 0, Math.PI * 2); ctx.fill()
|
||||
}
|
||||
|
||||
// "Now" edge
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.18)'
|
||||
ctx.lineWidth = 2
|
||||
ctx.beginPath(); ctx.moveTo(W - 1, 0); ctx.lineTo(W - 1, H); ctx.stroke()
|
||||
}, [waveform, bpm])
|
||||
|
||||
// Draw RMS envelope
|
||||
useEffect(() => {
|
||||
const canvas = rmsCanvasRef.current
|
||||
if (!canvas) return
|
||||
const ctx = canvas.getContext('2d')
|
||||
const W = canvas.width, H = canvas.height
|
||||
const h = rmsHistRef.current
|
||||
|
||||
ctx.fillStyle = '#0a0a0a'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
if (h.length < 2) return
|
||||
|
||||
const barW = W / RMS_HISTORY
|
||||
for (let i = 0; i < h.length; i++) {
|
||||
const x = W * (i / RMS_HISTORY)
|
||||
const barH = h[i] * H
|
||||
const v = Math.round(h[i] * 160 + 60)
|
||||
ctx.fillStyle = `rgb(${v},30,${v})`
|
||||
ctx.fillRect(x, H - barH, Math.max(barW - 0.5, 1), barH)
|
||||
}
|
||||
}, [waveform])
|
||||
|
||||
const noData = !waveform
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
|
||||
{/* Band meters */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 font-mono uppercase tracking-widest mb-2">Frequency Bands</p>
|
||||
<div className="flex gap-3" style={{ height: 96 }}>
|
||||
{BANDS.map((b, i) => (
|
||||
<div key={b.label} className="flex flex-col items-center gap-1 flex-1">
|
||||
<div className="flex-1 w-full bg-gray-900 rounded-sm relative overflow-hidden">
|
||||
{noData ? (
|
||||
<div className="absolute inset-0 flex items-center justify-center">
|
||||
<span className="text-[9px] text-gray-700 font-mono">—</span>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className="absolute bottom-0 left-0 right-0 rounded-sm"
|
||||
style={{
|
||||
height: `${bandLevels[i] * 100}%`,
|
||||
backgroundColor: b.color,
|
||||
transition: 'height 60ms linear',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-[10px] font-mono text-gray-500 uppercase">{b.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Onset timeline */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 font-mono uppercase tracking-widest mb-2">
|
||||
Onset Timeline{bpm ? ` · ${bpm} BPM` : ''}
|
||||
<span className="ml-2 text-gray-700 normal-case">← 4 seconds</span>
|
||||
</p>
|
||||
<canvas
|
||||
ref={beatCanvasRef}
|
||||
width={800}
|
||||
height={56}
|
||||
className="w-full rounded"
|
||||
style={{ height: 56 }}
|
||||
/>
|
||||
{noData && (
|
||||
<p className="text-xs text-gray-700 font-mono mt-1 text-center">Start listening to see hits</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Volume envelope */}
|
||||
<div>
|
||||
<p className="text-xs text-gray-600 font-mono uppercase tracking-widest mb-2">
|
||||
Volume Envelope
|
||||
<span className="ml-2 text-gray-700 normal-case">← ~3 seconds</span>
|
||||
</p>
|
||||
<canvas
|
||||
ref={rmsCanvasRef}
|
||||
width={800}
|
||||
height={56}
|
||||
className="w-full rounded"
|
||||
style={{ height: 56 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
import { useState } from 'react'
|
||||
import { toRomanNumeral, CHORD_TYPES, NOTES } from '../lib/theory'
|
||||
import {
|
||||
findSimilarProgressions,
|
||||
getChordSubstitutions,
|
||||
progressionInKey,
|
||||
styleVariationInKey,
|
||||
parseChord,
|
||||
} from '../lib/education'
|
||||
|
||||
// ─── Session Snapshot ─────────────────────────────────────────────────────────
|
||||
function SessionSnapshot({ keyInfo, detectedProgression, chordHistory }) {
|
||||
const { root, mode, confidence } = keyInfo ?? {}
|
||||
const uniqueChords = [...new Set(chordHistory)]
|
||||
const totalPlayed = chordHistory.length
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-4 p-4 bg-surface border border-border rounded-xl">
|
||||
<div className="flex flex-col gap-1 min-w-[120px]">
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600">Key</p>
|
||||
{root ? (
|
||||
<div className="flex items-baseline gap-1.5">
|
||||
<span className="text-2xl font-black text-accent">{root}</span>
|
||||
<span className="text-sm text-gray-400 capitalize">{mode}</span>
|
||||
{confidence && <span className="text-xs text-gray-600">{Math.round(confidence * 100)}%</span>}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-gray-600 text-sm">Detecting…</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-px bg-border shrink-0" />
|
||||
|
||||
<div className="flex flex-col gap-1">
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600">Detected Loop</p>
|
||||
{detectedProgression?.length ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{detectedProgression.map((chord, i) => (
|
||||
<span key={i} className="px-2 py-0.5 bg-accent/10 border border-accent/30 rounded text-xs font-bold text-accent">
|
||||
{chord}
|
||||
{root && <span className="text-amber-400/70 ml-1 font-normal text-[10px]">
|
||||
{toRomanNumeral(chord, root, mode)}
|
||||
</span>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-gray-600 text-sm">None yet — keep playing!</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-px bg-border shrink-0" />
|
||||
|
||||
<div className="flex flex-col gap-1">
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600">Session</p>
|
||||
<p className="text-sm text-gray-300">
|
||||
<span className="font-bold text-white">{totalPlayed}</span> chords ·
|
||||
<span className="font-bold text-white">{uniqueChords.length}</span> unique
|
||||
</p>
|
||||
{uniqueChords.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 mt-0.5">
|
||||
{uniqueChords.slice(0, 10).map(c => (
|
||||
<span key={c} className="text-[10px] text-gray-500 bg-border px-1.5 py-0.5 rounded">{c}</span>
|
||||
))}
|
||||
{uniqueChords.length > 10 && <span className="text-[10px] text-gray-600">+{uniqueChords.length - 10}</span>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Similar Progressions ─────────────────────────────────────────────────────
|
||||
function SimilarProgressions({ similar, keyInfo, onChordClick }) {
|
||||
const [expanded, setExpanded] = useState(null)
|
||||
if (!similar.length) return (
|
||||
<p className="text-gray-600 text-sm text-center py-4">
|
||||
Play more chords and lock a key to find similar famous progressions.
|
||||
</p>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
{similar.map(prog => {
|
||||
const isOpen = expanded === prog.id
|
||||
const chordsInKey = keyInfo?.root ? progressionInKey(prog, keyInfo.root) : []
|
||||
|
||||
return (
|
||||
<div key={prog.id}
|
||||
className="border border-border rounded-xl overflow-hidden hover:border-accent/30 transition-colors">
|
||||
|
||||
{/* Header row */}
|
||||
<button
|
||||
onClick={() => setExpanded(isOpen ? null : prog.id)}
|
||||
className="w-full flex items-start justify-between gap-3 px-4 py-3 text-left"
|
||||
>
|
||||
<div className="flex flex-col gap-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="font-bold text-white text-sm">{prog.name}</span>
|
||||
{prog.genre.map(g => (
|
||||
<span key={g} className="px-1.5 py-0.5 bg-accent/10 border border-accent/20 rounded text-[10px] text-accent">{g}</span>
|
||||
))}
|
||||
<span className="text-[11px] text-gray-500 font-mono">{prog.pattern}</span>
|
||||
<span className="ml-auto text-xs text-gray-600">{Math.round(prog.score * 100)}% match</span>
|
||||
</div>
|
||||
{/* Chords in current key */}
|
||||
{chordsInKey.length > 0 && (
|
||||
<div className="flex gap-1 flex-wrap">
|
||||
{chordsInKey.map((c, i) => (
|
||||
<button key={i}
|
||||
onClick={e => { e.stopPropagation(); onChordClick?.(c) }}
|
||||
className="px-2 py-0.5 bg-surface border border-border hover:border-accent/50 rounded text-xs font-bold text-gray-200 hover:text-accent transition-colors"
|
||||
title={`See voicings for ${c}`}
|
||||
>
|
||||
{c}
|
||||
</button>
|
||||
))}
|
||||
<span className="text-[10px] text-gray-600 self-center ml-1">in {keyInfo.root} {keyInfo.mode}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-gray-600 shrink-0 text-sm mt-0.5">{isOpen ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{/* Expanded detail */}
|
||||
{isOpen && (
|
||||
<div className="border-t border-border px-4 py-4 flex flex-col gap-4">
|
||||
<p className="text-sm text-gray-400">{prog.description}</p>
|
||||
{prog.tip && (
|
||||
<p className="text-xs text-amber-400/80">
|
||||
<span className="text-amber-400 font-semibold">Insight:</span> {prog.tip}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Song examples */}
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Famous examples</p>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{prog.songs.map(s => (
|
||||
<span key={s} className="px-2 py-1 bg-surface border border-border rounded-lg text-xs text-gray-400">{s}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Style variations */}
|
||||
{prog.styleVariations.length > 0 && (
|
||||
<div>
|
||||
<p className="text-[11px] uppercase tracking-wider text-gray-600 mb-2">Style variations</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{prog.styleVariations.map(sv => {
|
||||
const svChords = keyInfo?.root ? styleVariationInKey(sv, prog, keyInfo.root) : []
|
||||
return (
|
||||
<div key={sv.label} className="flex items-start gap-3 p-2 bg-surface rounded-lg border border-border">
|
||||
<span className="text-xs font-bold text-accent shrink-0 w-16">{sv.label}</span>
|
||||
<div className="flex flex-col gap-1 min-w-0">
|
||||
<span className="text-xs text-gray-500 font-mono">{sv.pattern}</span>
|
||||
{svChords.length > 0 && (
|
||||
<div className="flex gap-1 flex-wrap">
|
||||
{svChords.map((c, i) => (
|
||||
<button key={i}
|
||||
onClick={() => onChordClick?.(c)}
|
||||
className="px-1.5 py-0.5 bg-accent/10 border border-accent/20 hover:border-accent rounded text-[11px] font-bold text-accent/90 hover:text-accent transition-colors"
|
||||
title={`See voicings for ${c}`}
|
||||
>
|
||||
{c}
|
||||
</button>
|
||||
))}
|
||||
<span className="text-[10px] text-gray-600 self-center ml-1">in {keyInfo.root}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Play It Differently ──────────────────────────────────────────────────────
|
||||
function PlayDifferently({ progression, onChordClick }) {
|
||||
if (!progression?.length) return (
|
||||
<p className="text-gray-600 text-sm text-center py-4">
|
||||
Keep playing — a repeating progression will appear here with substitution ideas.
|
||||
</p>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-xs text-gray-500">
|
||||
Tap any substitution to see how to play it. These are harmonic replacements — same role, different colour.
|
||||
</p>
|
||||
{progression.map(chord => {
|
||||
const subs = getChordSubstitutions(chord)
|
||||
return (
|
||||
<div key={chord} className="flex flex-wrap items-start gap-3 p-3 bg-surface border border-border rounded-xl">
|
||||
{/* Original chord */}
|
||||
<button
|
||||
onClick={() => onChordClick?.(chord)}
|
||||
className="px-3 py-1.5 bg-accent text-white font-black rounded-lg text-sm shrink-0 hover:bg-purple-600 transition-colors"
|
||||
title="See voicings"
|
||||
>
|
||||
{chord}
|
||||
</button>
|
||||
|
||||
<span className="text-gray-700 self-center">→</span>
|
||||
|
||||
{/* Substitutions */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{subs.map(sub => (
|
||||
<div key={sub.chord} className="relative group">
|
||||
<button
|
||||
onClick={() => onChordClick?.(sub.chord)}
|
||||
className="px-2.5 py-1.5 bg-panel border border-border hover:border-accent/50 hover:text-accent rounded-lg text-sm font-bold text-gray-300 transition-all"
|
||||
>
|
||||
{sub.chord}
|
||||
</button>
|
||||
{/* Tooltip */}
|
||||
<div className="absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 w-48 px-2 py-1.5 bg-gray-900 border border-border rounded-lg text-[11px] text-gray-300 leading-snug opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10 shadow-xl">
|
||||
{sub.tip}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<p className="text-[11px] text-gray-700 text-center">
|
||||
Hover substitutions to see what they change · click to see voicings
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Chord Variation Ideas ────────────────────────────────────────────────────
|
||||
const VARIATION_ROWS = [
|
||||
{
|
||||
label: '7th Upgrade',
|
||||
desc: 'Add 7ths throughout — jazz and soul texture',
|
||||
typeMap: { maj: 'maj7', min: 'min7', dom7: 'dom7', maj7: 'maj7', min7: 'min7', dim: 'dim7', add9: 'maj7', sus2: 'sus2', sus4: 'sus4', aug: 'aug', half_dim: 'half_dim', maj6: 'maj6', min6: 'min6' },
|
||||
},
|
||||
{
|
||||
label: 'Sus2 Wash',
|
||||
desc: 'Replace triads with sus2 — ambient and spacious',
|
||||
typeMap: { maj: 'sus2', min: 'sus2', dom7: 'sus4', maj7: 'sus2', min7: 'sus2', add9: 'sus2', dim: 'dim', aug: 'aug', sus4: 'sus4', sus2: 'sus2', half_dim: 'half_dim', maj6: 'sus2', min6: 'sus2' },
|
||||
},
|
||||
{
|
||||
label: 'Add9 Modern',
|
||||
desc: 'Add9 on majors, m7 on minors — indie and neo-soul',
|
||||
typeMap: { maj: 'add9', min: 'min7', dom7: 'dom7', maj7: 'add9', min7: 'min7', add9: 'add9', sus2: 'sus2', sus4: 'sus4', dim: 'dim', aug: 'aug', half_dim: 'half_dim', maj6: 'add9', min6: 'min7' },
|
||||
},
|
||||
{
|
||||
label: 'Blues Dominant',
|
||||
desc: 'All chords → dom7 — instant 12-bar blues energy',
|
||||
typeMap: { maj: 'dom7', min: 'dom7', dom7: 'dom7', maj7: 'dom7', min7: 'dom7', add9: 'dom7', sus2: 'dom7', sus4: 'dom7', dim: 'dim7', aug: 'aug', half_dim: 'dom7', maj6: 'dom7', min6: 'dom7' },
|
||||
},
|
||||
]
|
||||
|
||||
function ProgressionVariationIdeas({ progression, onChordClick }) {
|
||||
if (!progression?.length) return (
|
||||
<p className="text-gray-600 text-sm text-center py-4">
|
||||
Keep playing — your progression will appear here.
|
||||
</p>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-xs text-gray-500">
|
||||
Your progression re-harmonised four ways. Click any chord to open its voicing explorer.
|
||||
</p>
|
||||
{VARIATION_ROWS.map(row => {
|
||||
const transformed = progression.map(chord => {
|
||||
const p = parseChord(chord)
|
||||
if (!p) return chord
|
||||
const newType = row.typeMap[p.type] ?? p.type
|
||||
return NOTES[p.rootPc] + (CHORD_TYPES[newType]?.suffix ?? '')
|
||||
})
|
||||
return (
|
||||
<div key={row.label} className="p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-center gap-2 mb-2.5">
|
||||
<span className="text-xs font-bold text-accent">{row.label}</span>
|
||||
<span className="text-[11px] text-gray-500">{row.desc}</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 items-center">
|
||||
{progression.map((orig, i) => (
|
||||
<span key={i} className="flex items-center gap-1.5">
|
||||
<span className="text-[10px] text-gray-600">{orig}</span>
|
||||
<span className="text-gray-700 text-xs">→</span>
|
||||
<button
|
||||
onClick={() => onChordClick?.(transformed[i])}
|
||||
className="px-2.5 py-1 bg-panel border border-border hover:border-accent/50 hover:text-accent rounded-lg font-bold text-sm text-gray-200 transition-all"
|
||||
>
|
||||
{transformed[i]}
|
||||
</button>
|
||||
{i < progression.length - 1 && <span className="text-gray-700">·</span>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main ─────────────────────────────────────────────────────────────────────
|
||||
export default function EducationPanel({ chordHistory, keyInfo, detectedProgression, onChordClick }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [section, setSection] = useState('similar')
|
||||
|
||||
// Use detected progression if available, else last 4 unique chords from history
|
||||
const workingProgression = detectedProgression?.length
|
||||
? detectedProgression
|
||||
: [...new Set([...chordHistory].reverse())].reverse().slice(-4)
|
||||
|
||||
const similar = findSimilarProgressions(workingProgression, keyInfo)
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span>EDUCATION</span>
|
||||
{similar.length > 0 && (
|
||||
<span className="text-[10px] px-1.5 py-0.5 bg-accent/20 border border-accent/30 rounded text-accent">
|
||||
{similar.length} match{similar.length !== 1 ? 'es' : ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span>{open ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="border-t border-border">
|
||||
|
||||
{/* Section nav */}
|
||||
<div className="flex gap-1 px-4 pt-4 pb-0 border-b border-border overflow-x-auto">
|
||||
{[
|
||||
{ key: 'snapshot', label: '📊 Session' },
|
||||
{ key: 'similar', label: `🎵 Similar Progressions${similar.length ? ` (${similar.length})` : ''}` },
|
||||
{ key: 'play', label: '🎨 Play Differently' },
|
||||
{ key: 'variations',label: '🔀 Progression Variations' },
|
||||
].map(s => (
|
||||
<button key={s.key}
|
||||
onClick={() => setSection(s.key)}
|
||||
className={`px-3 py-2 text-xs font-semibold whitespace-nowrap border-b-2 transition-all shrink-0 ${
|
||||
section === s.key
|
||||
? 'border-accent text-accent'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-300'
|
||||
}`}>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="p-4">
|
||||
{section === 'snapshot' && (
|
||||
<SessionSnapshot
|
||||
keyInfo={keyInfo}
|
||||
detectedProgression={detectedProgression}
|
||||
chordHistory={chordHistory}
|
||||
/>
|
||||
)}
|
||||
{section === 'similar' && (
|
||||
<SimilarProgressions
|
||||
similar={similar}
|
||||
keyInfo={keyInfo}
|
||||
onChordClick={onChordClick}
|
||||
/>
|
||||
)}
|
||||
{section === 'play' && (
|
||||
<PlayDifferently
|
||||
progression={workingProgression}
|
||||
onChordClick={onChordClick}
|
||||
/>
|
||||
)}
|
||||
{section === 'variations' && (
|
||||
<ProgressionVariationIdeas
|
||||
progression={workingProgression}
|
||||
onChordClick={onChordClick}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
import { useState } from 'react'
|
||||
import ChordBox from './ChordBox'
|
||||
import MiniPiano from './MiniPiano'
|
||||
import { getGuitarVoicings, getPianoTechniques, parseChord } from '../lib/voicings'
|
||||
import { CHORD_TYPES, NOTES, getChordsInKey, toRomanNumeral } from '../lib/theory'
|
||||
import { FAMOUS_PROGRESSIONS, progressionInKey } from '../lib/education'
|
||||
|
||||
const CHORD_TYPE_OPTIONS = [
|
||||
{ key: 'maj', label: 'Major' },
|
||||
{ key: 'min', label: 'Minor' },
|
||||
{ key: 'dom7', label: '7' },
|
||||
{ key: 'maj7', label: 'maj7' },
|
||||
{ key: 'min7', label: 'm7' },
|
||||
{ key: 'dim', label: 'dim' },
|
||||
{ key: 'dim7', label: 'dim7' },
|
||||
{ key: 'half_dim', label: 'm7♭5' },
|
||||
{ key: 'aug', label: 'aug' },
|
||||
{ key: 'sus4', label: 'sus4' },
|
||||
{ key: 'sus2', label: 'sus2' },
|
||||
{ key: 'maj6', label: '6' },
|
||||
{ key: 'min6', label: 'm6' },
|
||||
{ key: 'add9', label: 'add9' },
|
||||
]
|
||||
|
||||
const MAJOR_TYPES = new Set(['maj','maj7','maj6','add9','sus4','sus2','aug','dom7'])
|
||||
|
||||
// ─── Quick-pick chip row ──────────────────────────────────────────────────────
|
||||
function ChipRow({ label, chords, active, keyInfo, onSelect }) {
|
||||
if (!chords?.length) return null
|
||||
return (
|
||||
<div className="flex items-start gap-2 flex-wrap">
|
||||
<span className="text-[10px] uppercase tracking-wider text-gray-600 w-16 pt-1 shrink-0">{label}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{chords.map(chord => {
|
||||
const rn = keyInfo?.root ? toRomanNumeral(chord, keyInfo.root, keyInfo.mode) : ''
|
||||
return (
|
||||
<button key={chord} onClick={() => onSelect(chord)}
|
||||
className={`flex flex-col items-center px-2.5 py-1 rounded-lg border text-xs font-bold transition-all ${
|
||||
active === chord
|
||||
? 'bg-accent border-accent text-white'
|
||||
: 'bg-surface border-border text-gray-300 hover:border-accent/50 hover:text-accent'
|
||||
}`}>
|
||||
<span>{chord}</span>
|
||||
{rn && <span className="text-[9px] font-normal opacity-60 leading-none mt-0.5">{rn}</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Guitar voicings grid ─────────────────────────────────────────────────────
|
||||
function GuitarGrid({ chordName }) {
|
||||
const voicings = getGuitarVoicings(chordName)
|
||||
if (!voicings.length) return <p className="text-gray-600 text-sm py-4">No voicings for {chordName}.</p>
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{voicings.map((v, i) => (
|
||||
<div key={i} className="flex flex-col items-center p-3 rounded-xl bg-surface border border-border hover:border-accent/30 transition-colors">
|
||||
<ChordBox frets={v.frets} fingers={v.fingers} barre={v.barre} baseFret={v.baseFret} />
|
||||
<p className="text-[11px] text-gray-500 text-center mt-1 max-w-[110px] leading-tight">{v.label}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-[11px] text-gray-700 mt-3">
|
||||
Purple = chord tone · finger numbers inside dots (1=index 4=pinky) · fret number on left if not starting at fret 1
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Piano techniques grid ────────────────────────────────────────────────────
|
||||
function PianoGrid({ chordName }) {
|
||||
const parsed = parseChord(chordName)
|
||||
const techniques = getPianoTechniques(chordName)
|
||||
const rootPc = parsed?.rootPc ?? 0
|
||||
if (!techniques.length) return <p className="text-gray-600 text-sm py-4">No techniques for {chordName}.</p>
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
{techniques.map((t, i) => (
|
||||
<div key={i} className="flex flex-col lg:flex-row gap-3 p-3 bg-surface border border-border rounded-xl hover:border-accent/30 transition-colors">
|
||||
<div className="shrink-0 overflow-x-auto">
|
||||
<MiniPiano rootPc={rootPc} lh={t.lh} rh={t.rh} />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 min-w-0 justify-center">
|
||||
<p className="font-bold text-white text-sm">{t.name}</p>
|
||||
<p className="text-gray-400 text-xs">{t.desc}</p>
|
||||
<p className="text-xs text-amber-400/80 mt-0.5">
|
||||
<span className="text-amber-400 font-semibold">Tip:</span> {t.tip}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Famous progressions using this chord as tonic ───────────────────────────
|
||||
function ProgressionCards({ chordName, onChordClick }) {
|
||||
const parsed = parseChord(chordName)
|
||||
if (!parsed) return null
|
||||
const { rootPc, type } = parsed
|
||||
const root = NOTES[rootPc]
|
||||
const isMajor = MAJOR_TYPES.has(type)
|
||||
|
||||
const matching = FAMOUS_PROGRESSIONS.filter(p => {
|
||||
const q0 = p.qualities[0]
|
||||
return isMajor ? MAJOR_TYPES.has(q0) : !MAJOR_TYPES.has(q0)
|
||||
}).slice(0, 6)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-xs text-gray-500">
|
||||
Famous progressions with <span className="text-accent font-bold">{chordName}</span> as the tonic.
|
||||
Click any chord to see its voicings.
|
||||
</p>
|
||||
{matching.map(prog => {
|
||||
const chordsHere = progressionInKey(prog, root)
|
||||
return (
|
||||
<div key={prog.id} className="p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex items-center flex-wrap gap-2 mb-2">
|
||||
<span className="font-bold text-white text-sm">{prog.name}</span>
|
||||
<span className="text-[10px] font-mono text-gray-600">{prog.pattern}</span>
|
||||
{prog.genre.slice(0, 2).map(g => (
|
||||
<span key={g} className="px-1.5 py-0.5 bg-accent/10 border border-accent/20 rounded text-[10px] text-accent">{g}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1.5 items-center mb-2">
|
||||
{chordsHere.map((c, i) => (
|
||||
<span key={i} className="flex items-center gap-1">
|
||||
<button onClick={() => onChordClick?.(c)}
|
||||
className={`px-2.5 py-1 rounded-lg font-bold text-sm border transition-all ${
|
||||
i === 0
|
||||
? 'bg-accent border-accent text-white'
|
||||
: 'bg-panel border-border text-gray-200 hover:border-accent/50 hover:text-accent'
|
||||
}`}>
|
||||
{c}
|
||||
</button>
|
||||
{i < chordsHere.length - 1 && <span className="text-gray-700 text-xs">→</span>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-gray-600 leading-snug">{prog.description}</p>
|
||||
{prog.songs.length > 0 && (
|
||||
<p className="text-[11px] text-gray-700 mt-1">{prog.songs.slice(0, 3).join(' · ')}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main panel ───────────────────────────────────────────────────────────────
|
||||
export default function ExplorePanel({ keyInfo, chordHistory, onChordClick }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [root, setRoot] = useState('C')
|
||||
const [typeKey, setTypeKey] = useState('maj')
|
||||
const [view, setView] = useState('guitar') // guitar | piano | progressions
|
||||
const [active, setActive] = useState('')
|
||||
|
||||
const chordName = root + (CHORD_TYPES[typeKey]?.suffix ?? '')
|
||||
|
||||
function selectChord(chord) {
|
||||
setActive(chord)
|
||||
const p = parseChord(chord)
|
||||
if (p) { setRoot(NOTES[p.rootPc]); setTypeKey(p.type) }
|
||||
}
|
||||
|
||||
// Context-aware quick-picks
|
||||
const recentChords = [...new Set([...(chordHistory ?? [])].reverse())].slice(0, 12)
|
||||
const keyChords = keyInfo?.root ? getChordsInKey(keyInfo.root, keyInfo.mode ?? 'major') : []
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
<button onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-400 hover:text-gray-200 transition-all">
|
||||
<span>EXPLORE ANY CHORD</span>
|
||||
<span>{open ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="border-t border-border p-4 flex flex-col gap-4">
|
||||
|
||||
{/* ── Context quick-picks ── */}
|
||||
{(recentChords.length > 0 || keyChords.length > 0) && (
|
||||
<div className="flex flex-col gap-2.5 p-3 bg-surface border border-border rounded-xl">
|
||||
<ChipRow label="History" chords={recentChords} active={active} keyInfo={keyInfo} onSelect={selectChord} />
|
||||
{keyChords.length > 0 && recentChords.length > 0 && <div className="h-px bg-border" />}
|
||||
{keyChords.length > 0 && (
|
||||
<ChipRow
|
||||
label={keyInfo.root + ' ' + (keyInfo.mode ?? '')}
|
||||
chords={keyChords} active={active} keyInfo={keyInfo} onSelect={selectChord}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Manual chord picker ── */}
|
||||
<div className="flex flex-wrap gap-2 items-center p-3 bg-surface border border-border rounded-xl">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{NOTES.map(n => (
|
||||
<button key={n} onClick={() => { setRoot(n); setActive('') }}
|
||||
className={`px-2 py-0.5 rounded text-xs font-bold transition-all ${
|
||||
root === n ? 'bg-accent text-white' : 'bg-border text-gray-400 hover:text-white'
|
||||
}`}>
|
||||
{n}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="w-px h-5 bg-border shrink-0" />
|
||||
<div className="relative">
|
||||
<select value={typeKey} onChange={e => { setTypeKey(e.target.value); setActive('') }}
|
||||
className="appearance-none bg-panel border border-border rounded-lg pl-2 pr-6 py-1 text-xs text-gray-200 cursor-pointer focus:outline-none focus:border-accent">
|
||||
{CHORD_TYPE_OPTIONS.map(o => <option key={o.key} value={o.key}>{o.label}</option>)}
|
||||
</select>
|
||||
<span className="pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs">▾</span>
|
||||
</div>
|
||||
<div className="text-2xl font-black text-accent ml-2">{chordName}</div>
|
||||
</div>
|
||||
|
||||
{/* ── View tabs ── */}
|
||||
<div className="flex gap-1 bg-surface border border-border rounded-xl p-1 w-fit">
|
||||
{[
|
||||
{ key: 'guitar', label: '🎸 Guitar Voicings' },
|
||||
{ key: 'piano', label: '🎹 Piano Techniques' },
|
||||
{ key: 'progressions', label: '🎵 Progressions' },
|
||||
].map(t => (
|
||||
<button key={t.key} onClick={() => setView(t.key)}
|
||||
className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all whitespace-nowrap ${
|
||||
view === t.key ? 'bg-accent text-white' : 'text-gray-400 hover:text-white'
|
||||
}`}>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* ── Content ── */}
|
||||
{view === 'guitar' && <GuitarGrid chordName={chordName} />}
|
||||
{view === 'piano' && <PianoGrid chordName={chordName} />}
|
||||
{view === 'progressions' && <ProgressionCards chordName={chordName} onChordClick={c => { selectChord(c); onChordClick?.(c) }} />}
|
||||
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
import { getPentatonicScale, getFullScale, getChordTones, guideTones, NOTES } from '../lib/theory'
|
||||
|
||||
// Standard tuning: pitch classes of open strings, high-E first (top of diagram)
|
||||
const STRINGS = [
|
||||
{ label: 'e', root: 4 }, // high E
|
||||
{ label: 'B', root: 11 },
|
||||
{ label: 'G', root: 7 },
|
||||
{ label: 'D', root: 2 },
|
||||
{ label: 'A', root: 9 },
|
||||
{ label: 'E', root: 4 }, // low E
|
||||
]
|
||||
|
||||
const NUM_FRETS = 13 // frets 0 (open) through 12
|
||||
const FRET_MARKERS = [3, 5, 7, 9]
|
||||
const DOUBLE_MARKER = 12
|
||||
|
||||
// Layout constants
|
||||
const NUT_X = 40 // x of the nut line
|
||||
const OPEN_X = 18 // x of open-string dot centres
|
||||
const FRET_W = 52 // pixels per fret
|
||||
const STRING_H = 28 // pixels between strings
|
||||
const PAD_T = 28 // top padding (fret numbers)
|
||||
const PAD_B = 18 // bottom padding (fret marker dots)
|
||||
const BOARD_W = NUT_X + (NUM_FRETS - 1) * FRET_W + 10
|
||||
const BOARD_H = PAD_T + 5 * STRING_H + PAD_B
|
||||
const DOT_R = 10
|
||||
|
||||
// x centre of a fretted note (fret >= 1)
|
||||
const fretX = f => NUT_X + (f - 0.5) * FRET_W
|
||||
// y centre of string si (0 = high e, 5 = low E)
|
||||
const stringY = si => PAD_T + si * STRING_H
|
||||
|
||||
function noteColor(isChordTone, isPenta, isScale, mono = false) {
|
||||
if (isChordTone) return { fill: '#a855f7', text: '#fff' }
|
||||
if (isPenta) return mono ? { fill: '#c084fc', text: '#1e1b4b' } : { fill: '#f59e0b', text: '#000' }
|
||||
if (isScale) return mono ? { fill: '#e9d5ff', text: '#581c87' } : { fill: '#374151', text: '#d1d5db' }
|
||||
return null
|
||||
}
|
||||
|
||||
export default function Fretboard({ keyInfo, currentChord, pentatonicOnly = false, monoColor = false, jamFocusChord = null }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
|
||||
if (!root) return null
|
||||
|
||||
const pentaSet = new Set(getPentatonicScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const scaleSet = pentatonicOnly
|
||||
? pentaSet
|
||||
: new Set(getFullScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const chordSet = currentChord
|
||||
? new Set(getChordTones(currentChord).map(n => NOTES.indexOf(n)))
|
||||
: new Set()
|
||||
|
||||
// ── Jam Guide focus: guide tones of the tapped Roadmap station ──────────────
|
||||
// `guideTones` returns { third, seventh, hasSeventh }. We emphasise the 3rd
|
||||
// (the quality-defining tone) and the secondary anchor — the 7th when present,
|
||||
// else the 5th for a triad (hasSeventh:false). These pitch classes get a halo
|
||||
// ring + a small tag so they read as a distinct "target" tier on top of the
|
||||
// normal chord/penta/scale colouring.
|
||||
let focusThird = -1, focusSeventh = -1, focusRootPc = 0
|
||||
if (jamFocusChord && typeof jamFocusChord.rootPc === 'number') {
|
||||
const gt = guideTones(jamFocusChord.rootPc, jamFocusChord.quality)
|
||||
focusThird = gt.third
|
||||
focusSeventh = gt.seventh
|
||||
focusRootPc = gt.root
|
||||
}
|
||||
const hasFocus = focusThird >= 0
|
||||
// Defense-in-depth: label the secondary anchor from its ACTUAL interval above
|
||||
// the chord root, so a wrong `hasSeventh` boolean could never mislabel a 5th
|
||||
// or 6th as a "7". 10/11 → "7", 9 → "6", 8 → "♭6"(#5), 7 → "5", 6 → "♭5".
|
||||
const focusSeventhLabel = (() => {
|
||||
const iv = ((focusSeventh - focusRootPc) % 12 + 12) % 12
|
||||
if (iv === 10 || iv === 11) return '7'
|
||||
if (iv === 9) return '6'
|
||||
if (iv === 8) return '♭6'
|
||||
if (iv === 6) return '♭5'
|
||||
return '5'
|
||||
})()
|
||||
const focusLabel = pc =>
|
||||
pc === focusThird ? '3' : pc === focusSeventh ? focusSeventhLabel : null
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-4">
|
||||
Fretboard — {root} {mode}
|
||||
{currentChord && <span className="text-amber-400 ml-2">/ {currentChord}</span>}
|
||||
{hasFocus && <span className="text-accent ml-2">◎ guide tones</span>}
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<svg
|
||||
viewBox={`0 0 ${BOARD_W} ${BOARD_H}`}
|
||||
width="100%"
|
||||
height="auto"
|
||||
style={{ display: 'block' }}
|
||||
>
|
||||
{/* Fretboard background */}
|
||||
<rect x={NUT_X} y={PAD_T - 6} width={BOARD_W - NUT_X - 4} height={5 * STRING_H + 12}
|
||||
fill="#1a120b" rx={2} />
|
||||
|
||||
{/* Fret position marker dots (between strings 2–3 and 3–4) */}
|
||||
{FRET_MARKERS.map(f => (
|
||||
<circle key={f}
|
||||
cx={fretX(f)} cy={PAD_T + 2.5 * STRING_H}
|
||||
r={5} fill="#3a2a1a" />
|
||||
))}
|
||||
{/* Double dot at 12 */}
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 1.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
<circle cx={fretX(DOUBLE_MARKER)} cy={PAD_T + 3.5 * STRING_H} r={5} fill="#3a2a1a" />
|
||||
|
||||
{/* Fret lines (1–12) */}
|
||||
{Array.from({ length: NUM_FRETS - 1 }, (_, i) => i + 1).map(f => (
|
||||
<line key={f}
|
||||
x1={NUT_X + f * FRET_W} y1={PAD_T - 6}
|
||||
x2={NUT_X + f * FRET_W} y2={PAD_T + 5 * STRING_H + 6}
|
||||
stroke={f === DOUBLE_MARKER ? '#888' : '#4a3a2a'}
|
||||
strokeWidth={f === DOUBLE_MARKER ? 2 : 1} />
|
||||
))}
|
||||
|
||||
{/* Nut */}
|
||||
<line x1={NUT_X} y1={PAD_T - 6} x2={NUT_X} y2={PAD_T + 5 * STRING_H + 6}
|
||||
stroke="#c0b090" strokeWidth={4} />
|
||||
|
||||
{/* Strings */}
|
||||
{STRINGS.map((_, si) => (
|
||||
<line key={si}
|
||||
x1={OPEN_X - DOT_R - 2} y1={stringY(si)}
|
||||
x2={BOARD_W - 8} y2={stringY(si)}
|
||||
stroke="#9ca3af"
|
||||
strokeWidth={si < 2 ? 1 : si < 4 ? 1.5 : 2} />
|
||||
))}
|
||||
|
||||
{/* Fret numbers */}
|
||||
{[3, 5, 7, 9, 12].map(f => (
|
||||
<text key={f}
|
||||
x={fretX(f)} y={PAD_T - 10}
|
||||
textAnchor="middle" fontSize={10} fill="#6b7280"
|
||||
>{f}</text>
|
||||
))}
|
||||
|
||||
{/* String labels */}
|
||||
{STRINGS.map((s, si) => (
|
||||
<text key={si}
|
||||
x={6} y={stringY(si) + 4}
|
||||
textAnchor="middle" fontSize={10} fill="#6b7280"
|
||||
>{s.label}</text>
|
||||
))}
|
||||
|
||||
{/* Note dots */}
|
||||
{STRINGS.flatMap((str, si) =>
|
||||
Array.from({ length: NUM_FRETS }, (_, fi) => {
|
||||
const pc = (str.root + fi) % 12
|
||||
const color = noteColor(chordSet.has(pc), pentaSet.has(pc), scaleSet.has(pc), monoColor)
|
||||
const tag = hasFocus ? focusLabel(pc) : null
|
||||
// A guide tone outside the current scale still gets emphasised:
|
||||
// draw a faint base dot so the halo has something to sit on.
|
||||
if (!color && !tag) return null
|
||||
|
||||
const cx = fi === 0 ? OPEN_X : fretX(fi)
|
||||
const cy = stringY(si)
|
||||
const baseFill = color ? color.fill : '#2a2a2a'
|
||||
const baseText = color ? color.text : '#a855f7'
|
||||
|
||||
return (
|
||||
<g key={`${si}-${fi}`}>
|
||||
{/* Guide-tone halo: a purple ring around the dot, clearly
|
||||
distinct from the solid chord-tone fill (a "target" marker). */}
|
||||
{tag && (
|
||||
<circle
|
||||
cx={cx} cy={cy} r={DOT_R + 3}
|
||||
fill="none" stroke="#a855f7" strokeWidth={2.5}
|
||||
/>
|
||||
)}
|
||||
<circle cx={cx} cy={cy} r={DOT_R} fill={baseFill} />
|
||||
<text
|
||||
x={cx} y={cy + 4}
|
||||
textAnchor="middle"
|
||||
fontSize={9}
|
||||
fontWeight="600"
|
||||
fill={baseText}
|
||||
>
|
||||
{NOTES[pc]}
|
||||
</text>
|
||||
{/* Degree badge (3 / 7 / 5) on the halo's upper-right. */}
|
||||
{tag && (
|
||||
<>
|
||||
<circle cx={cx + DOT_R} cy={cy - DOT_R} r={6} fill="#a855f7" />
|
||||
<text
|
||||
x={cx + DOT_R} y={cy - DOT_R + 3}
|
||||
textAnchor="middle"
|
||||
fontSize={8}
|
||||
fontWeight="700"
|
||||
fill="#fff"
|
||||
>
|
||||
{tag}
|
||||
</text>
|
||||
</>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap gap-5 text-xs text-gray-500">
|
||||
<span><span className="text-accent">●</span> Chord tone</span>
|
||||
<span style={{ color: monoColor ? '#c084fc' : '#f59e0b' }}>●</span><span> Pentatonic</span>
|
||||
<span style={{ color: monoColor ? '#e9d5ff' : '#6b7280' }}>●</span><span> Scale</span>
|
||||
{hasFocus && (
|
||||
<span className="flex items-center gap-1">
|
||||
<span
|
||||
className="inline-block w-3 h-3 rounded-full border-2 border-accent"
|
||||
/>
|
||||
Guide tones (3 / {focusSeventhLabel})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
import { useState, useMemo, useRef, useEffect } from 'react'
|
||||
import kb from '../data/kb/index.js'
|
||||
import { buildLoopIndex, matchLoopToProgression, findLoopPosition, chordRootPC } from '../lib/match'
|
||||
import { NOTES, CHORD_TYPES } from '../lib/theory'
|
||||
import RoadmapTrack from './RoadmapTrack'
|
||||
import ChordDiagram from './ChordDiagram'
|
||||
|
||||
// ─── JamGuide — the Roadmap bottom dock ───────────────────────────────────────
|
||||
//
|
||||
// The large bottom panel of JamBuddy. This is the SHELL (task L-02): the
|
||||
// collapsed header bar, instrument + style tabs (derived from the KB registry),
|
||||
// live loop → KB progression resolution, and a clearly-marked placeholder slot
|
||||
// where the Roadmap visualization (RoadmapTrack + ChordDiagram, task D-02) will
|
||||
// be wired in afterwards.
|
||||
//
|
||||
// This component does NOT import RoadmapTrack or ChordDiagram — sibling tasks
|
||||
// build those in parallel; D-02 fills the [data-roadmap-slot] left here.
|
||||
//
|
||||
// Props (the contract D-02 relies on):
|
||||
// detectedProgression : string[] | null — the live detected loop (chord names)
|
||||
// keyInfo : { root, mode, confidence } | null — effective key
|
||||
// chordHistory : string[] — committed chord history (for position)
|
||||
// bpm : number | null — live tempo from the onset pipeline
|
||||
// currentChord : string | undefined — most recent committed chord
|
||||
|
||||
// Display order for instrument tabs; availability is derived from the KB, not hardcoded.
|
||||
const INSTRUMENTS = [
|
||||
{ id: 'guitar', label: 'Guitar', icon: '🎸' },
|
||||
{ id: 'piano', label: 'Piano', icon: '🎹' },
|
||||
{ id: 'bass', label: 'Bass', icon: '🎵' },
|
||||
]
|
||||
|
||||
export default function JamGuide({ detectedProgression, keyInfo, chordHistory = [], bpm, currentChord, onFocusChord }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
// Which instruments have at least one KB pack across the registry.
|
||||
const availableInstruments = useMemo(() => {
|
||||
const set = new Set()
|
||||
for (const style of Object.values(kb)) {
|
||||
for (const inst of Object.keys(style?.instruments ?? {})) set.add(inst)
|
||||
}
|
||||
return set
|
||||
}, [])
|
||||
|
||||
// Style tabs straight from the KB registry, labelled via each style's meta.
|
||||
const styles = useMemo(
|
||||
() => Object.entries(kb).map(([id, style]) => ({ id, label: style?.meta?.label ?? id })),
|
||||
[]
|
||||
)
|
||||
|
||||
// Build the rotation-invariant loop index once.
|
||||
const kbIndex = useMemo(() => buildLoopIndex(kb), [])
|
||||
|
||||
// Resolve the live loop → KB progression + rotation, and the current station.
|
||||
// Keyed on the loop input so this only recomputes when the loop changes.
|
||||
const loopKey = detectedProgression ? detectedProgression.join(',') : ''
|
||||
const match = useMemo(
|
||||
() => matchLoopToProgression(detectedProgression, kbIndex),
|
||||
[loopKey, kbIndex] // eslint-disable-line react-hooks/exhaustive-deps
|
||||
)
|
||||
const position = useMemo(
|
||||
() => findLoopPosition(chordHistory, detectedProgression),
|
||||
[chordHistory, loopKey] // eslint-disable-line react-hooks/exhaustive-deps
|
||||
)
|
||||
|
||||
// Instrument tab: default to guitar (the only packs that exist today).
|
||||
const [instrument, setInstrument] = useState('guitar')
|
||||
|
||||
// Style tab: follow the matched style, but let the user override.
|
||||
const [styleOverride, setStyleOverride] = useState(null)
|
||||
const activeStyle = styleOverride ?? (match.matched ? match.style : styles[0]?.id)
|
||||
|
||||
// Header summary: matched progression name, or a listening hint.
|
||||
const matchedName = match.matched ? match.progression?.name : null
|
||||
const headerLabel = matchedName
|
||||
? matchedName
|
||||
: (detectedProgression?.length ? 'mapping the changes…' : 'listening…')
|
||||
|
||||
// ── Key root: keyInfo.root is a note NAME (e.g. "C"). RoadmapTrack and
|
||||
// ChordDiagram both want a pitch class 0–11. Convert once; default to C (0)
|
||||
// until a key is known so the roadmap still resolves to *some* spelling. ──
|
||||
const keyRoot = useMemo(() => {
|
||||
const pc = chordRootPC(keyInfo?.root)
|
||||
return pc >= 0 ? pc : 0
|
||||
}, [keyInfo?.root])
|
||||
const keyMode = keyInfo?.mode === 'minor' ? 'minor' : 'major'
|
||||
|
||||
// ── Playhead reconciliation ────────────────────────────────────────────────
|
||||
// `position` from findLoopPosition is an index into the *detected* loop, which
|
||||
// can start on any rotation of the KB progression. RoadmapTrack renders the
|
||||
// progression in *canonical KB order* (degrees[0] first). They differ by
|
||||
// `match.rotation` — the loop index that aligns with KB degrees[0]. To map a
|
||||
// detected-loop index back to its canonical station:
|
||||
// canonicalPos = ((position − rotation) mod n + n) mod n
|
||||
// Worked example — KB blues-turnaround [I VI ii V] looped as [ii V I VI]:
|
||||
// rotation = 2 (loop index 2 = the "I" = KB degrees[0]).
|
||||
// Playhead on the V (detected index 1) → ((1 − 2) % 4 + 4) % 4 = 3 = the V's
|
||||
// canonical station. NOW lands on the right station. ✓
|
||||
const canonicalPos = useMemo(() => {
|
||||
if (!match.matched) return -1
|
||||
const n = match.progression?.degrees?.length ?? 0
|
||||
if (!n || typeof position !== 'number' || position < 0) return -1
|
||||
return (((position - match.rotation) % n) + n) % n
|
||||
}, [match.matched, match.progression, match.rotation, position])
|
||||
|
||||
// ── Per-station voicing shapes from the KB ──────────────────────────────────
|
||||
// For the matched style + progression id, pull the recommended guitar play
|
||||
// (the first play). Its `chords` array is in canonical KB order — chords[i]
|
||||
// aligns 1:1 with progression.degrees[i] (the same station order RoadmapTrack
|
||||
// renders). Each entry: { shape, note }. A station with no shape → graceful gap.
|
||||
const stationVoicings = useMemo(() => {
|
||||
if (!match.matched || instrument !== 'guitar') return []
|
||||
const prog = match.progression
|
||||
const styleId = match.style
|
||||
const plays = kb[styleId]?.instruments?.guitar?.plays?.[prog?.id]
|
||||
const play = Array.isArray(plays) ? plays[0] : null
|
||||
const chords = play?.chords ?? []
|
||||
const degrees = prog?.degrees ?? []
|
||||
const qualities = prog?.qualities ?? []
|
||||
return degrees.map((deg, i) => {
|
||||
const rootPc = (((keyRoot + deg) % 12) + 12) % 12
|
||||
const noteName = NOTES[rootPc]
|
||||
const suffix = CHORD_TYPES[qualities[i]]?.suffix ?? ''
|
||||
return {
|
||||
shape: chords[i]?.shape ?? null,
|
||||
rootPc,
|
||||
quality: qualities[i] ?? 'maj',
|
||||
label: `${noteName}${suffix}`,
|
||||
rn: prog?.rn?.[i] ?? '',
|
||||
}
|
||||
})
|
||||
}, [match.matched, match.progression, match.style, instrument, keyRoot])
|
||||
|
||||
// ── Tap-to-enlarge: which station's voicing is expanded (full diagram). ──
|
||||
const [selectedStation, setSelectedStation] = useState(null)
|
||||
// Reset the selection whenever the loop or style changes underneath us.
|
||||
useEffect(() => { setSelectedStation(null) }, [match.id, match.style, instrument])
|
||||
|
||||
// ── Cross-link to the main Fretboard (D-03) ─────────────────────────────────
|
||||
// When a station is selected, report its {rootPc, quality} upward so the
|
||||
// Fretboard can light that chord's guide tones; clear (null) on deselect. The
|
||||
// reset effect above sets selectedStation → null on loop/style/instrument
|
||||
// change, which flows through here and clears the highlight too. Guarded so
|
||||
// the component still works standalone (onFocusChord optional).
|
||||
useEffect(() => {
|
||||
if (!onFocusChord) return
|
||||
const st = selectedStation != null ? stationVoicings[selectedStation] : null
|
||||
onFocusChord(st ? { rootPc: st.rootPc, quality: st.quality } : null)
|
||||
}, [selectedStation, stationVoicings, onFocusChord])
|
||||
|
||||
// Clear the Fretboard highlight when JamGuide unmounts.
|
||||
useEffect(() => () => { onFocusChord?.(null) }, [onFocusChord])
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
|
||||
{/* ── Collapsed header bar (always visible) ── */}
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between px-4 py-3 text-left hover:bg-accent/5 transition-colors"
|
||||
aria-expanded={open}
|
||||
>
|
||||
<span className="flex items-center gap-2 min-w-0">
|
||||
<span className="text-base shrink-0">🎸</span>
|
||||
<span className="text-sm font-semibold text-accent shrink-0">Jam Guide</span>
|
||||
<span className="text-gray-600 shrink-0">—</span>
|
||||
<span className="text-sm text-gray-300 truncate">{headerLabel}</span>
|
||||
{match.matched && keyInfo?.root && (
|
||||
<span className="text-xs text-gray-500 shrink-0">
|
||||
in {keyInfo.root} {keyInfo.mode}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="text-gray-500 shrink-0 ml-3">{open ? '▲' : '▼'}</span>
|
||||
</button>
|
||||
|
||||
{/* ── Expanded body (~70vh) ── */}
|
||||
{open && (
|
||||
<div className="border-t border-border flex flex-col" style={{ height: '70vh' }}>
|
||||
|
||||
{/* ── Tab rows ── */}
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-2 border-b border-border">
|
||||
|
||||
{/* Instrument tabs */}
|
||||
<div className="flex items-center gap-1">
|
||||
{INSTRUMENTS.map(inst => {
|
||||
const enabled = availableInstruments.has(inst.id)
|
||||
const active = enabled && inst.id === instrument
|
||||
return (
|
||||
<button
|
||||
key={inst.id}
|
||||
onClick={() => enabled && setInstrument(inst.id)}
|
||||
disabled={!enabled}
|
||||
title={enabled ? inst.label : `${inst.label} packs coming soon`}
|
||||
className={`px-3 py-1 rounded-lg text-sm font-medium transition-colors flex items-center gap-1.5 ${
|
||||
active
|
||||
? 'bg-accent/20 border border-accent text-accent'
|
||||
: enabled
|
||||
? 'border border-border text-gray-300 hover:border-gray-500 hover:text-gray-100'
|
||||
: 'border border-border/50 text-gray-600 cursor-not-allowed'
|
||||
}`}
|
||||
>
|
||||
<span>{inst.icon}</span>
|
||||
<span>{inst.label}</span>
|
||||
{!enabled && <span className="text-[10px] text-gray-700 ml-0.5">soon</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="w-px h-5 bg-border shrink-0" />
|
||||
|
||||
{/* Style tabs (from the KB registry) */}
|
||||
<div className="flex items-center gap-1 flex-wrap">
|
||||
{styles.map(style => {
|
||||
const active = style.id === activeStyle
|
||||
const isMatched = match.matched && style.id === match.style
|
||||
return (
|
||||
<button
|
||||
key={style.id}
|
||||
onClick={() => setStyleOverride(style.id)}
|
||||
className={`px-2.5 py-1 rounded-lg text-sm transition-colors ${
|
||||
active
|
||||
? 'bg-accent/20 border border-accent text-accent font-semibold'
|
||||
: 'border border-transparent text-gray-400 hover:text-gray-200 hover:border-border'
|
||||
}`}
|
||||
>
|
||||
{style.label}
|
||||
{isMatched && <span className="ml-1 text-accent/70" title="matches your loop">●</span>}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Roadmap slot (D-02 assembly) ── */}
|
||||
<div data-roadmap-slot className="flex-1 min-h-0 p-4 overflow-auto">
|
||||
{match.matched ? (
|
||||
<RoadmapAssembly
|
||||
progression={match.progression}
|
||||
keyRoot={keyRoot}
|
||||
keyMode={keyMode}
|
||||
position={canonicalPos}
|
||||
bpm={bpm}
|
||||
stationVoicings={stationVoicings}
|
||||
selectedStation={selectedStation}
|
||||
onSelectStation={setSelectedStation}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className="h-full min-h-[200px] flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-border text-center"
|
||||
>
|
||||
<p className="text-sm text-gray-400">Play a few bars — I'll map the changes</p>
|
||||
<p className="text-xs text-gray-600">
|
||||
{detectedProgression?.length
|
||||
? `Heard ${detectedProgression.join(' → ')}, but it doesn't match a ${activeStyle} pattern yet.`
|
||||
: 'Roadmap renders here once a repeating loop is detected.'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── RoadmapAssembly — the live panel body ────────────────────────────────────
|
||||
//
|
||||
// Composes RoadmapTrack (the improv highway) with a secondary voicing strip of
|
||||
// ChordDiagram thumbnails (one per station, canonical KB order). Tapping a
|
||||
// thumbnail enlarges it to a full diagram inline. The active station auto-scrolls
|
||||
// into view. Narrow viewports (< ~640px) reflow: the strip wraps and the whole
|
||||
// panel scrolls vertically rather than forcing a wide horizontal layout.
|
||||
function RoadmapAssembly({
|
||||
progression, keyRoot, keyMode, position, bpm,
|
||||
stationVoicings, selectedStation, onSelectStation,
|
||||
}) {
|
||||
const stripRef = useRef(null)
|
||||
const activeRef = useRef(null)
|
||||
|
||||
// Auto-scroll the active station's thumbnail into view as the playhead moves.
|
||||
// Prop-driven (off `position`) — no rAF loop tied to the audio thread.
|
||||
useEffect(() => {
|
||||
if (position < 0 || !activeRef.current) return
|
||||
activeRef.current.scrollIntoView({
|
||||
behavior: 'smooth', inline: 'center', block: 'nearest',
|
||||
})
|
||||
}, [position])
|
||||
|
||||
const selected = selectedStation != null ? stationVoicings[selectedStation] : null
|
||||
|
||||
return (
|
||||
<div className="flex h-full min-h-0 flex-col gap-4">
|
||||
{/* The improv highway — active-station styling + playhead live inside it. */}
|
||||
<RoadmapTrack
|
||||
progression={progression}
|
||||
keyRoot={keyRoot}
|
||||
keyMode={keyMode}
|
||||
position={position}
|
||||
bpm={bpm}
|
||||
/>
|
||||
|
||||
{/* Secondary voicing strip: one thumbnail per station, canonical order. */}
|
||||
{stationVoicings.length > 0 && (
|
||||
<section
|
||||
className="rounded-2xl border border-border bg-panel p-3"
|
||||
aria-label="Voicing thumbnails"
|
||||
>
|
||||
<h4 className="mb-2 text-[10px] font-semibold uppercase tracking-widest text-gray-500">
|
||||
Voicings · tap to enlarge
|
||||
</h4>
|
||||
<div
|
||||
ref={stripRef}
|
||||
className="flex flex-wrap gap-2 overflow-x-auto sm:flex-nowrap"
|
||||
role="list"
|
||||
>
|
||||
{stationVoicings.map((st, i) => {
|
||||
const isNow = i === position
|
||||
const isSelected = i === selectedStation
|
||||
return (
|
||||
<button
|
||||
key={i}
|
||||
ref={isNow ? activeRef : undefined}
|
||||
type="button"
|
||||
role="listitem"
|
||||
aria-pressed={isSelected}
|
||||
aria-current={isNow ? 'true' : undefined}
|
||||
onClick={() => onSelectStation(isSelected ? null : i)}
|
||||
title={`${st.label} — ${st.rn || `station ${i + 1}`}`}
|
||||
className={
|
||||
`flex shrink-0 flex-col items-center gap-1 rounded-lg border p-2 outline-none transition ` +
|
||||
`focus-visible:ring-2 focus-visible:ring-accent ` +
|
||||
(isNow
|
||||
? 'border-accent bg-accent/10 ring-1 ring-accent'
|
||||
: isSelected
|
||||
? 'border-accent/60 bg-accent/5'
|
||||
: 'border-border bg-surface hover:border-gray-500')
|
||||
}
|
||||
style={{ opacity: isNow ? 1 : 0.85 }}
|
||||
>
|
||||
<ChordDiagram
|
||||
shape={st.shape}
|
||||
keyRoot={keyRoot}
|
||||
rootPc={st.rootPc}
|
||||
size="thumb"
|
||||
label={st.label}
|
||||
/>
|
||||
{st.rn && (
|
||||
<span className="text-[9px] font-medium uppercase tracking-wide text-gray-500">
|
||||
{st.rn}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Enlarged view of the tapped station (deferred fretboard cross-link
|
||||
lives here instead — see D-02 return note). */}
|
||||
{selected && (
|
||||
<div className="mt-3 flex flex-col items-center gap-2 border-t border-border pt-3">
|
||||
<ChordDiagram
|
||||
shape={selected.shape}
|
||||
keyRoot={keyRoot}
|
||||
rootPc={selected.rootPc}
|
||||
size="full"
|
||||
label={`${selected.label}${selected.rn ? ` · ${selected.rn}` : ''}`}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSelectStation(null)}
|
||||
className="text-[11px] text-gray-500 underline-offset-2 hover:text-gray-300 hover:underline focus-visible:ring-2 focus-visible:ring-accent rounded outline-none"
|
||||
>
|
||||
close
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import { useRef, useEffect, useState, useCallback } from 'react'
|
||||
|
||||
const STYLE = {
|
||||
empty: { border: 'border-border', bg: 'bg-surface', icon: '●', iconColor: 'text-gray-700' },
|
||||
recording: { border: 'border-red-500', bg: 'bg-red-950/20', icon: '⏺', iconColor: 'text-red-400' },
|
||||
trimming: { border: 'border-amber-400', bg: 'bg-amber-950/20', icon: '✂', iconColor: 'text-amber-400'},
|
||||
playing: { border: 'border-accent', bg: 'bg-accent/10', icon: '▶', iconColor: 'text-accent' },
|
||||
muted: { border: 'border-border', bg: 'bg-surface', icon: '⏸', iconColor: 'text-gray-500' },
|
||||
}
|
||||
|
||||
const LABEL = {
|
||||
empty: 'tap to rec',
|
||||
recording: 'tap to stop',
|
||||
trimming: 'trimming…',
|
||||
playing: 'tap to mute',
|
||||
muted: 'tap to play',
|
||||
}
|
||||
|
||||
export default function LoopSlot({ slot, slotIdx, audioCtxRef, masterStartRef, masterLenRef, onClick, onRetrim, onDelete, onVolumeChange }) {
|
||||
const progressRef = useRef(null)
|
||||
const rafRef = useRef(null)
|
||||
const [showVol, setShowVol] = useState(false)
|
||||
const [holdTimer, setHoldTimer] = useState(null)
|
||||
const [deleting, setDeleting] = useState(false)
|
||||
|
||||
const { status, recordingDuration, volume, originalBuffer } = slot
|
||||
const style = STYLE[status] ?? STYLE.empty
|
||||
const isActive = status === 'playing' || status === 'muted'
|
||||
|
||||
// ── Progress bar via rAF ─────────────────────────────────────────────────
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
if (progressRef.current) progressRef.current.style.width = '0%'
|
||||
return
|
||||
}
|
||||
function tick() {
|
||||
const ctx = audioCtxRef.current
|
||||
const mStart = masterStartRef.current
|
||||
const mLen = masterLenRef.current
|
||||
if (ctx && mStart !== null && mLen && progressRef.current) {
|
||||
const pos = ((ctx.currentTime - mStart) % mLen) / mLen * 100
|
||||
progressRef.current.style.width = `${pos}%`
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
return () => { if (rafRef.current) cancelAnimationFrame(rafRef.current) }
|
||||
}, [isActive, audioCtxRef, masterStartRef, masterLenRef])
|
||||
|
||||
// ── Long-press to delete ──────────────────────────────────────────────────
|
||||
const onPointerDown = useCallback((e) => {
|
||||
e.preventDefault()
|
||||
const t = setTimeout(() => setDeleting(true), 500)
|
||||
setHoldTimer(t)
|
||||
}, [])
|
||||
|
||||
const onPointerUp = useCallback(() => {
|
||||
if (holdTimer) { clearTimeout(holdTimer); setHoldTimer(null) }
|
||||
if (!deleting) onClick(slotIdx)
|
||||
}, [holdTimer, deleting, onClick, slotIdx])
|
||||
|
||||
const onPointerLeave = useCallback(() => {
|
||||
if (holdTimer) { clearTimeout(holdTimer); setHoldTimer(null) }
|
||||
}, [holdTimer])
|
||||
|
||||
const confirmDelete = useCallback(() => {
|
||||
setDeleting(false)
|
||||
onDelete(slotIdx)
|
||||
}, [onDelete, slotIdx])
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-1 select-none relative">
|
||||
|
||||
{/* Delete confirmation overlay (long-press) */}
|
||||
{deleting && (
|
||||
<div className="absolute inset-0 z-20 flex flex-col items-center justify-center gap-1 rounded-xl bg-black/90 border border-red-500">
|
||||
<button
|
||||
className="text-[10px] font-bold text-red-400 px-2 py-0.5 rounded bg-red-900/50 hover:bg-red-900"
|
||||
onClick={confirmDelete}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
<button
|
||||
className="text-[10px] text-gray-500 hover:text-gray-300"
|
||||
onClick={() => setDeleting(false)}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Quick clear button — visible on non-empty slots */}
|
||||
{status !== 'empty' && !deleting && (
|
||||
<button
|
||||
className="absolute -top-1.5 -right-1.5 z-10 w-4 h-4 rounded-full bg-gray-800 border border-border text-gray-500 hover:bg-red-900/60 hover:text-red-400 hover:border-red-700 text-[9px] leading-none flex items-center justify-center transition-colors"
|
||||
onClick={(e) => { e.stopPropagation(); onDelete(slotIdx) }}
|
||||
title="Clear slot"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Main button */}
|
||||
<button
|
||||
className={`relative w-[76px] h-[54px] rounded-xl border-2 overflow-hidden flex flex-col items-center justify-center gap-0.5 transition-colors cursor-pointer ${style.bg} ${style.border} ${status === 'recording' ? 'animate-pulse' : ''}`}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerUp={onPointerUp}
|
||||
onPointerLeave={onPointerLeave}
|
||||
>
|
||||
<span className={`text-lg leading-none ${style.iconColor}`}>
|
||||
{style.icon}
|
||||
</span>
|
||||
<span className={`text-[9px] font-bold uppercase tracking-widest leading-none ${style.iconColor} opacity-70`}>
|
||||
{status === 'recording'
|
||||
? `${(recordingDuration ?? 0).toFixed(1)}s`
|
||||
: `Loop ${slotIdx + 1}`}
|
||||
</span>
|
||||
|
||||
{/* Progress bar */}
|
||||
{isActive && (
|
||||
<div className="absolute bottom-0 left-0 right-0 h-[3px] bg-border">
|
||||
<div
|
||||
ref={progressRef}
|
||||
className="h-full bg-accent"
|
||||
style={{ width: '0%', transition: 'none' }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
|
||||
{/* Controls row (playing/muted only) */}
|
||||
{isActive && (
|
||||
<div className="flex items-center gap-1.5">
|
||||
{/* Volume toggle */}
|
||||
<button
|
||||
className={`text-[11px] transition-colors ${showVol ? 'text-accent' : 'text-gray-600 hover:text-gray-400'}`}
|
||||
onClick={() => setShowVol(v => !v)}
|
||||
title="Volume"
|
||||
>
|
||||
🔊
|
||||
</button>
|
||||
{showVol && (
|
||||
<input
|
||||
type="range" min={0} max={1} step={0.05}
|
||||
value={volume}
|
||||
onChange={e => onVolumeChange(slotIdx, parseFloat(e.target.value))}
|
||||
className="w-12 h-1 cursor-pointer accent-purple-500"
|
||||
/>
|
||||
)}
|
||||
{/* Re-trim button — only when original recording exists */}
|
||||
{originalBuffer && (
|
||||
<button
|
||||
className="text-[11px] text-gray-600 hover:text-amber-400 transition-colors"
|
||||
onClick={() => onRetrim(slotIdx)}
|
||||
title="Re-trim this loop"
|
||||
>
|
||||
✂
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status label */}
|
||||
<span className={`text-[9px] uppercase tracking-wider leading-none ${style.iconColor} opacity-50`}>
|
||||
{LABEL[status] ?? ''}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import LoopTrimmer from './LoopTrimmer'
|
||||
|
||||
const H_TRACK = 56 // track canvas height px
|
||||
const H_MASTER = 26 // master timeline height px
|
||||
|
||||
// ── Canvas draw helpers ───────────────────────────────────────────────────────
|
||||
|
||||
function drawGrid(canvas, totalSec, bpm) {
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
if (!rect.width || !rect.height) return
|
||||
const dpr = window.devicePixelRatio ?? 1
|
||||
canvas.width = rect.width * dpr
|
||||
canvas.height = rect.height * dpr
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.scale(dpr, dpr)
|
||||
const W = rect.width, H = rect.height
|
||||
|
||||
ctx.fillStyle = '#0f0f0f'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
if (!bpm || !totalSec) return
|
||||
|
||||
const beatSec = 60 / bpm
|
||||
const barSec = beatSec * 4
|
||||
|
||||
// Beat lines
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.06)'
|
||||
ctx.lineWidth = 1
|
||||
for (let t = beatSec; t < totalSec; t += beatSec) {
|
||||
if ((t % barSec) < beatSec * 0.4) continue
|
||||
const x = (t / totalSec) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
}
|
||||
// Bar lines + numbers
|
||||
for (let t = 0; t <= totalSec; t += barSec) {
|
||||
ctx.strokeStyle = 'rgba(168,85,247,0.45)'
|
||||
ctx.lineWidth = 1.5
|
||||
const x = (t / totalSec) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
const n = Math.round(t / barSec)
|
||||
if (n > 0) {
|
||||
ctx.fillStyle = 'rgba(168,85,247,0.55)'
|
||||
ctx.font = '9px monospace'
|
||||
ctx.textAlign = 'left'
|
||||
ctx.fillText(String(n), x + 3, H - 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawWaveform(canvas, waveform, muted) {
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
if (!rect.width || !rect.height) return
|
||||
const dpr = window.devicePixelRatio ?? 1
|
||||
canvas.width = rect.width * dpr
|
||||
canvas.height = rect.height * dpr
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.scale(dpr, dpr)
|
||||
const W = rect.width, H = rect.height
|
||||
|
||||
ctx.fillStyle = '#0f0f0f'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
|
||||
const N = waveform.length
|
||||
const mid = H / 2
|
||||
for (let i = 0; i < N; i++) {
|
||||
const x = (i / N) * W
|
||||
const barW = Math.max(1, W / N - 0.3)
|
||||
ctx.fillStyle = muted ? '#3b1f55' : '#a855f7'
|
||||
const h = waveform[i] * mid * 0.85
|
||||
ctx.fillRect(x, mid - h, barW, h * 2)
|
||||
}
|
||||
}
|
||||
|
||||
function drawRecording(canvas, duration, bpm) {
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
if (!rect.width || !rect.height) return
|
||||
const dpr = window.devicePixelRatio ?? 1
|
||||
canvas.width = rect.width * dpr
|
||||
canvas.height = rect.height * dpr
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.scale(dpr, dpr)
|
||||
const W = rect.width, H = rect.height
|
||||
|
||||
ctx.fillStyle = '#0f0f0f'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
|
||||
const beatSec = bpm ? 60 / bpm : null
|
||||
const barSec = beatSec ? beatSec * 4 : null
|
||||
const viewDur = barSec
|
||||
? Math.max(barSec * 4, Math.ceil(duration / barSec + 1) * barSec)
|
||||
: Math.max(8, duration * 1.4)
|
||||
|
||||
// Grid
|
||||
if (beatSec) {
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.06)'
|
||||
ctx.lineWidth = 1
|
||||
for (let t = beatSec; t < viewDur; t += beatSec) {
|
||||
if (barSec && (t % barSec) < beatSec * 0.4) continue
|
||||
const x = (t / viewDur) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
}
|
||||
if (barSec) {
|
||||
for (let t = barSec; t <= viewDur; t += barSec) {
|
||||
ctx.strokeStyle = 'rgba(239,68,68,0.3)'
|
||||
ctx.lineWidth = 1.5
|
||||
const x = (t / viewDur) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
const n = Math.round(t / barSec)
|
||||
ctx.fillStyle = 'rgba(239,68,68,0.45)'
|
||||
ctx.font = '9px monospace'
|
||||
ctx.textAlign = 'left'
|
||||
ctx.fillText(String(n), x + 2, H - 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Growing fill + cursor
|
||||
const fillX = (duration / viewDur) * W
|
||||
ctx.fillStyle = 'rgba(239,68,68,0.18)'
|
||||
ctx.fillRect(0, 0, fillX, H)
|
||||
ctx.strokeStyle = 'rgba(239,68,68,0.85)'
|
||||
ctx.lineWidth = 1.5
|
||||
ctx.beginPath(); ctx.moveTo(fillX, 0); ctx.lineTo(fillX, H); ctx.stroke()
|
||||
|
||||
// Counter label
|
||||
const bars = barSec ? Math.floor(duration / barSec) + 1 : null
|
||||
const label = bars !== null
|
||||
? `● REC BAR ${bars} ${duration.toFixed(1)}s — tap to stop`
|
||||
: `● REC ${duration.toFixed(1)}s — tap to stop`
|
||||
ctx.fillStyle = 'rgba(239,68,68,0.9)'
|
||||
ctx.font = 'bold 11px monospace'
|
||||
ctx.textAlign = 'center'
|
||||
ctx.textBaseline = 'middle'
|
||||
ctx.fillText(label, W / 2, H / 2)
|
||||
}
|
||||
|
||||
// ── Master Timeline ───────────────────────────────────────────────────────────
|
||||
|
||||
function MasterTimeline({ masterStartRef, masterLenRef, audioCtxRef, bpm, masterLen }) {
|
||||
const canvasRef = useRef(null)
|
||||
const playheadRef = useRef(null)
|
||||
const rafRef = useRef(null)
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas) return
|
||||
const id = requestAnimationFrame(() => drawGrid(canvas, masterLen, bpm))
|
||||
return () => cancelAnimationFrame(id)
|
||||
}, [masterLen, bpm])
|
||||
|
||||
useEffect(() => {
|
||||
if (!masterLen) { cancelAnimationFrame(rafRef.current); return }
|
||||
function tick() {
|
||||
const ac = audioCtxRef.current
|
||||
const t0 = masterStartRef.current
|
||||
const len = masterLenRef.current
|
||||
if (ac && t0 !== null && len && playheadRef.current) {
|
||||
const pos = ((ac.currentTime - t0) % len) / len
|
||||
playheadRef.current.style.left = `${pos * 100}%`
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
return () => cancelAnimationFrame(rafRef.current)
|
||||
}, [masterLen, audioCtxRef, masterStartRef, masterLenRef])
|
||||
|
||||
return (
|
||||
<div className="relative mx-4 mb-3 rounded overflow-hidden bg-surface border border-border"
|
||||
style={{ height: `${H_MASTER}px` }}>
|
||||
<canvas ref={canvasRef} className="w-full h-full block" />
|
||||
{!masterLen && (
|
||||
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
|
||||
<span className="text-[10px] text-gray-700">
|
||||
record first loop to set master length
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{masterLen && (
|
||||
<div
|
||||
ref={playheadRef}
|
||||
className="absolute top-0 bottom-0 w-px bg-white/50 pointer-events-none"
|
||||
style={{ left: '0%' }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Track Row ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function TrackRow({ slot, slotIdx, bpm, audioCtxRef, masterStartRef, masterLenRef,
|
||||
onSlotClick, onRetrim, onDelete, onVolumeChange }) {
|
||||
const [showVol, setShowVol] = useState(false)
|
||||
const canvasRef = useRef(null)
|
||||
const playheadRef = useRef(null)
|
||||
const rafRef = useRef(null)
|
||||
|
||||
const DOT_CLASS = {
|
||||
empty: 'bg-gray-700',
|
||||
recording: 'bg-red-500 animate-pulse',
|
||||
trimming: 'bg-amber-500',
|
||||
playing: 'bg-accent',
|
||||
muted: 'bg-gray-500',
|
||||
}
|
||||
const BORDER_CLASS = {
|
||||
empty: 'border-border',
|
||||
recording: 'border-red-800',
|
||||
trimming: 'border-amber-800/60',
|
||||
playing: 'border-accent/40',
|
||||
muted: 'border-border',
|
||||
}
|
||||
|
||||
const dotClass = DOT_CLASS[slot.status] ?? 'bg-gray-700'
|
||||
const borderClass = BORDER_CLASS[slot.status] ?? 'border-border'
|
||||
|
||||
// Draw waveform when data arrives or mute state changes
|
||||
useEffect(() => {
|
||||
if (!slot.waveform) return
|
||||
if (slot.status === 'recording' || slot.status === 'trimming') return
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas) return
|
||||
const id = requestAnimationFrame(() =>
|
||||
drawWaveform(canvas, slot.waveform, slot.status === 'muted')
|
||||
)
|
||||
return () => cancelAnimationFrame(id)
|
||||
}, [slot.waveform, slot.status])
|
||||
|
||||
// Draw recording progress on each duration tick
|
||||
useEffect(() => {
|
||||
if (slot.status !== 'recording') return
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas) return
|
||||
drawRecording(canvas, slot.recordingDuration, bpm)
|
||||
}, [slot.recordingDuration, slot.status, bpm])
|
||||
|
||||
// Playhead animation
|
||||
useEffect(() => {
|
||||
const active = slot.status === 'playing' || slot.status === 'muted'
|
||||
if (!active) {
|
||||
cancelAnimationFrame(rafRef.current)
|
||||
if (playheadRef.current) playheadRef.current.style.left = '-2px'
|
||||
return
|
||||
}
|
||||
function tick() {
|
||||
const ac = audioCtxRef.current
|
||||
const t0 = masterStartRef.current
|
||||
const len = masterLenRef.current
|
||||
if (ac && t0 !== null && len && playheadRef.current) {
|
||||
const pos = ((ac.currentTime - t0) % len) / len
|
||||
playheadRef.current.style.left = `${pos * 100}%`
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
}
|
||||
rafRef.current = requestAnimationFrame(tick)
|
||||
return () => cancelAnimationFrame(rafRef.current)
|
||||
}, [slot.status, audioCtxRef, masterStartRef, masterLenRef])
|
||||
|
||||
const isClickable = slot.status !== 'trimming'
|
||||
const isActive = slot.status === 'playing' || slot.status === 'muted'
|
||||
|
||||
return (
|
||||
<div className={`flex items-stretch border rounded-lg mb-1.5 overflow-hidden transition-colors ${borderClass}`}>
|
||||
|
||||
{/* Left: tap button (state dot + track number) */}
|
||||
<button
|
||||
onClick={() => isClickable && onSlotClick(slotIdx)}
|
||||
disabled={!isClickable}
|
||||
title={
|
||||
slot.status === 'empty' ? 'Tap to record' :
|
||||
slot.status === 'recording' ? 'Tap to stop' :
|
||||
slot.status === 'playing' ? 'Tap to mute' :
|
||||
slot.status === 'muted' ? 'Tap to unmute' : ''
|
||||
}
|
||||
className="flex flex-col items-center justify-center gap-1 px-3 bg-surface border-r border-border shrink-0 hover:bg-white/5 transition-colors disabled:cursor-default"
|
||||
style={{ width: '44px' }}
|
||||
>
|
||||
<span className={`w-2 h-2 rounded-full shrink-0 ${dotClass}`} />
|
||||
<span className="text-[10px] text-gray-600 font-mono">{slotIdx + 1}</span>
|
||||
</button>
|
||||
|
||||
{/* Canvas: waveform / recording / empty */}
|
||||
<div
|
||||
className="relative flex-1 cursor-pointer"
|
||||
style={{ height: `${H_TRACK}px` }}
|
||||
onClick={() => isClickable && onSlotClick(slotIdx)}
|
||||
>
|
||||
<canvas ref={canvasRef} className="w-full h-full block" />
|
||||
|
||||
{slot.status === 'empty' && (
|
||||
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
|
||||
<span className="text-xs text-gray-700">tap to record</span>
|
||||
</div>
|
||||
)}
|
||||
{slot.status === 'trimming' && (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-amber-950/20 pointer-events-none">
|
||||
<span className="text-xs text-amber-500/60">trimming ↓</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Moving playhead */}
|
||||
{isActive && (
|
||||
<div
|
||||
ref={playheadRef}
|
||||
className="absolute top-0 bottom-0 w-px bg-white/40 pointer-events-none"
|
||||
style={{ left: '-2px' }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Right: controls */}
|
||||
<div className="flex items-center gap-1 px-2 bg-surface border-l border-border shrink-0">
|
||||
{showVol && (
|
||||
<input
|
||||
type="range"
|
||||
min={0} max={1} step={0.01}
|
||||
value={slot.volume}
|
||||
onChange={e => onVolumeChange(slotIdx, parseFloat(e.target.value))}
|
||||
className="w-14 accent-purple-500"
|
||||
title="Volume"
|
||||
/>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setShowVol(v => !v)}
|
||||
className={`w-7 h-7 flex items-center justify-center rounded text-base transition-colors ${
|
||||
showVol ? 'text-accent' : 'text-gray-600 hover:text-gray-300'
|
||||
}`}
|
||||
title="Volume"
|
||||
>
|
||||
{slot.status === 'muted' ? '🔇' : '🔊'}
|
||||
</button>
|
||||
{isActive && slot.originalBuffer && (
|
||||
<button
|
||||
onClick={() => onRetrim(slotIdx)}
|
||||
className="w-7 h-7 flex items-center justify-center rounded text-gray-600 hover:text-amber-400 transition-colors text-sm"
|
||||
title="Re-trim loop"
|
||||
>
|
||||
✂
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => onDelete(slotIdx)}
|
||||
className="w-7 h-7 flex items-center justify-center rounded text-gray-700 hover:text-red-400 transition-colors text-sm"
|
||||
title="Clear track"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoopStation({
|
||||
slots,
|
||||
bpm,
|
||||
masterLen,
|
||||
audioCtxRef,
|
||||
masterStartRef,
|
||||
masterLenRef,
|
||||
onSlotClick,
|
||||
onCommitTrim,
|
||||
onCancelRecord,
|
||||
onRetrim,
|
||||
onDelete,
|
||||
onVolumeChange,
|
||||
onAddSlot,
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [gridBpm, setGridBpm] = useState(bpm ?? '')
|
||||
|
||||
// Pre-fill BPM when detection arrives
|
||||
useEffect(() => {
|
||||
if (bpm && !gridBpm) setGridBpm(bpm)
|
||||
}, [bpm]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const gridBpmNum = parseFloat(gridBpm) || null
|
||||
const trimmingIdx = slots.findIndex(s => s.status === 'trimming')
|
||||
|
||||
const recordingCount = slots.filter(s => s.status === 'recording').length
|
||||
const playingCount = slots.filter(s => s.status === 'playing').length
|
||||
|
||||
const dotClass = recordingCount > 0
|
||||
? 'bg-red-500 animate-pulse'
|
||||
: playingCount > 0
|
||||
? 'bg-accent'
|
||||
: 'bg-gray-700'
|
||||
|
||||
const masterLabel = (() => {
|
||||
if (!masterLen) return null
|
||||
if (gridBpmNum) {
|
||||
const bars = Math.round(masterLen / ((60 / gridBpmNum) * 4))
|
||||
return `${bars} bar${bars !== 1 ? 's' : ''} · ${masterLen.toFixed(2)}s`
|
||||
}
|
||||
return masterLen.toFixed(2) + 's'
|
||||
})()
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
{/* ── Header ──────────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-between px-4 py-2 text-sm text-gray-400">
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="flex items-center gap-2 hover:text-gray-200 transition-colors text-left"
|
||||
>
|
||||
<span className={`w-2 h-2 rounded-full shrink-0 ${dotClass}`} />
|
||||
<span>LOOP STATION</span>
|
||||
{masterLabel && (
|
||||
<span className="text-[11px] text-gray-600 font-mono">{masterLabel}</span>
|
||||
)}
|
||||
{recordingCount > 0 && (
|
||||
<span className="text-[11px] text-red-400">● rec</span>
|
||||
)}
|
||||
{playingCount > 0 && recordingCount === 0 && (
|
||||
<span className="text-[11px] text-accent">
|
||||
{playingCount} loop{playingCount !== 1 ? 's' : ''}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-1 bg-surface border border-border rounded-lg px-2 py-1">
|
||||
<span className="text-[10px] text-gray-600 uppercase tracking-wider">BPM</span>
|
||||
<input
|
||||
type="number"
|
||||
min={40} max={300} step={1}
|
||||
value={gridBpm}
|
||||
onChange={e => setGridBpm(e.target.value)}
|
||||
placeholder={bpm ? String(Math.round(bpm)) : '—'}
|
||||
className="w-10 bg-transparent text-xs text-gray-300 text-center focus:outline-none focus:text-white"
|
||||
style={{ MozAppearance: 'textfield' }}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-6 h-6 flex items-center justify-center rounded text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-all"
|
||||
title={open ? 'Collapse' : 'Expand'}
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none"
|
||||
stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
||||
{open
|
||||
? <polyline points="2,8 6,4 10,8" />
|
||||
: <polyline points="2,4 6,8 10,4" />
|
||||
}
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Body ────────────────────────────────────────────────────────────── */}
|
||||
{open && (
|
||||
<div className="border-t border-border pt-3">
|
||||
|
||||
{/* Master timeline */}
|
||||
<MasterTimeline
|
||||
masterStartRef={masterStartRef}
|
||||
masterLenRef={masterLenRef}
|
||||
audioCtxRef={audioCtxRef}
|
||||
bpm={gridBpmNum}
|
||||
masterLen={masterLen}
|
||||
/>
|
||||
|
||||
{/* Track rows */}
|
||||
<div className="px-4">
|
||||
{slots.map((slot, i) => (
|
||||
<TrackRow
|
||||
key={i}
|
||||
slot={slot}
|
||||
slotIdx={i}
|
||||
bpm={gridBpmNum}
|
||||
audioCtxRef={audioCtxRef}
|
||||
masterStartRef={masterStartRef}
|
||||
masterLenRef={masterLenRef}
|
||||
onSlotClick={onSlotClick}
|
||||
onRetrim={onRetrim}
|
||||
onDelete={onDelete}
|
||||
onVolumeChange={onVolumeChange}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Add track */}
|
||||
<div className="px-4 pb-3">
|
||||
<button
|
||||
onClick={onAddSlot}
|
||||
className="w-full py-1.5 rounded-lg border border-dashed border-border text-gray-700 hover:border-accent/40 hover:text-accent/60 transition-colors text-xs flex items-center justify-center gap-2"
|
||||
>
|
||||
<span className="text-base leading-none">+</span>
|
||||
<span>Add Track</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* LoopTrimmer — shown below tracks when trimming */}
|
||||
{trimmingIdx !== -1 && (
|
||||
<LoopTrimmer
|
||||
slot={slots[trimmingIdx]}
|
||||
slotIdx={trimmingIdx}
|
||||
bpm={gridBpmNum}
|
||||
audioCtxRef={audioCtxRef}
|
||||
onCommit={onCommitTrim}
|
||||
onCancel={onCancelRecord}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
import { useRef, useState, useEffect, useCallback } from 'react'
|
||||
|
||||
function fmtMs(sec) {
|
||||
return `${(sec * 1000).toFixed(0)}ms`
|
||||
}
|
||||
|
||||
function fmtSec(sec) {
|
||||
return sec < 10 ? `${sec.toFixed(2)}s` : `${sec.toFixed(1)}s`
|
||||
}
|
||||
|
||||
export default function LoopTrimmer({ slot, slotIdx, bpm, audioCtxRef, onCommit, onCancel }) {
|
||||
const canvasRef = useRef(null)
|
||||
const containerRef = useRef(null)
|
||||
const previewRef = useRef(null) // AudioBufferSourceNode for preview
|
||||
|
||||
const [trimStart, setTrimStart] = useState(slot.trimStart)
|
||||
const [trimEnd, setTrimEnd] = useState(slot.trimEnd)
|
||||
const [previewing, setPreviewing] = useState(false)
|
||||
|
||||
// Refs so drag closures always have current values
|
||||
const trimStartRef = useRef(trimStart)
|
||||
const trimEndRef = useRef(trimEnd)
|
||||
useEffect(() => { trimStartRef.current = trimStart }, [trimStart])
|
||||
useEffect(() => { trimEndRef.current = trimEnd }, [trimEnd])
|
||||
|
||||
const duration = slot.audioBuffer?.duration ?? 0
|
||||
const startSec = trimStart * duration
|
||||
const endSec = trimEnd * duration
|
||||
const selectedSec = endSec - startSec
|
||||
|
||||
// Beat grid info — visual reference only, no snapping
|
||||
const beatSec = bpm ? 60 / bpm : null
|
||||
const barSec = beatSec ? beatSec * 4 : null
|
||||
|
||||
// Stop preview when handles change
|
||||
useEffect(() => {
|
||||
if (previewing) stopPreview()
|
||||
}, [trimStart, trimEnd]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => stopPreview()
|
||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
function stopPreview() {
|
||||
try { previewRef.current?.stop() } catch {}
|
||||
previewRef.current = null
|
||||
setPreviewing(false)
|
||||
}
|
||||
|
||||
function togglePreview() {
|
||||
if (previewing) { stopPreview(); return }
|
||||
const ctx = audioCtxRef?.current
|
||||
const buf = slot.audioBuffer
|
||||
if (!ctx || !buf) return
|
||||
|
||||
// Resume context if suspended
|
||||
if (ctx.state === 'suspended') ctx.resume().catch(() => {})
|
||||
|
||||
const sr = buf.sampleRate
|
||||
const startSample = Math.floor(trimStartRef.current * buf.length)
|
||||
const endSample = Math.ceil(trimEndRef.current * buf.length)
|
||||
const len = Math.max(1, endSample - startSample)
|
||||
const data = buf.getChannelData(0).slice(startSample, endSample)
|
||||
|
||||
const previewBuf = ctx.createBuffer(1, len, sr)
|
||||
previewBuf.copyToChannel(data, 0)
|
||||
|
||||
const node = ctx.createBufferSource()
|
||||
node.buffer = previewBuf
|
||||
node.loop = true
|
||||
node.loopStart = 0
|
||||
node.loopEnd = len / sr
|
||||
node.connect(ctx.destination)
|
||||
node.start()
|
||||
node.onended = () => { previewRef.current = null; setPreviewing(false) }
|
||||
|
||||
previewRef.current = node
|
||||
setPreviewing(true)
|
||||
}
|
||||
|
||||
// Snap end handle to N bars from current start
|
||||
function snapBars(n) {
|
||||
if (!barSec || !duration) return
|
||||
const newEnd = Math.min(1, trimStartRef.current + (n * barSec) / duration)
|
||||
setTrimEnd(newEnd)
|
||||
trimEndRef.current = newEnd
|
||||
draw()
|
||||
}
|
||||
|
||||
// ── Canvas draw ─────────────────────────────────────────────────────────────
|
||||
const draw = useCallback(() => {
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas || !slot.waveform) return
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
if (rect.width === 0) return
|
||||
const dpr = window.devicePixelRatio ?? 1
|
||||
canvas.width = rect.width * dpr
|
||||
canvas.height = rect.height * dpr
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.scale(dpr, dpr)
|
||||
const W = rect.width
|
||||
const H = rect.height
|
||||
const wf = slot.waveform
|
||||
const N = wf.length
|
||||
const ts = trimStartRef.current
|
||||
const te = trimEndRef.current
|
||||
|
||||
// Background
|
||||
ctx.fillStyle = '#0f0f0f'
|
||||
ctx.fillRect(0, 0, W, H)
|
||||
|
||||
// Dim regions outside selection
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.6)'
|
||||
ctx.fillRect(0, 0, ts * W, H)
|
||||
ctx.fillRect(te * W, 0, W - te * W, H)
|
||||
|
||||
// Beat grid — visual only, beat lines then bar lines (bars on top)
|
||||
if (beatSec && duration) {
|
||||
// Beat lines
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.10)'
|
||||
ctx.lineWidth = 1
|
||||
for (let t = 0; t <= duration; t += beatSec) {
|
||||
const isBar = barSec ? (t % barSec) < beatSec * 0.4 : false
|
||||
if (!isBar) {
|
||||
const x = (t / duration) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
}
|
||||
}
|
||||
// Bar lines (brighter, thicker)
|
||||
if (barSec) {
|
||||
ctx.strokeStyle = 'rgba(168,85,247,0.55)'
|
||||
ctx.lineWidth = 1.5
|
||||
for (let t = 0; t <= duration; t += barSec) {
|
||||
const x = (t / duration) * W
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke()
|
||||
// Bar number label
|
||||
const barNum = Math.round(t / barSec)
|
||||
if (barNum > 0) {
|
||||
ctx.fillStyle = 'rgba(168,85,247,0.5)'
|
||||
ctx.font = `${9 * dpr / dpr}px monospace`
|
||||
ctx.fillText(`${barNum}`, x + 3, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Waveform bars
|
||||
const mid = H / 2
|
||||
for (let i = 0; i < N; i++) {
|
||||
const x = (i / N) * W
|
||||
const barW = Math.max(1, W / N - 0.5)
|
||||
const inSel = (i / N) >= ts && (i / N) <= te
|
||||
ctx.fillStyle = inSel ? '#a855f7' : '#3b0764'
|
||||
const h = wf[i] * mid * 0.88
|
||||
ctx.fillRect(x, mid - h, barW, h * 2)
|
||||
}
|
||||
|
||||
// Handle lines
|
||||
ctx.strokeStyle = '#a855f7'
|
||||
ctx.lineWidth = 2
|
||||
ctx.beginPath(); ctx.moveTo(ts * W, 0); ctx.lineTo(ts * W, H); ctx.stroke()
|
||||
ctx.beginPath(); ctx.moveTo(te * W, 0); ctx.lineTo(te * W, H); ctx.stroke()
|
||||
}, [slot.waveform, beatSec, barSec, duration])
|
||||
|
||||
useEffect(() => { draw() }, [draw, trimStart, trimEnd])
|
||||
useEffect(() => {
|
||||
const id = requestAnimationFrame(() => draw())
|
||||
return () => cancelAnimationFrame(id)
|
||||
}, [draw])
|
||||
|
||||
// ── Pointer → fraction ──────────────────────────────────────────────────────
|
||||
function fracFromClientX(clientX) {
|
||||
const el = containerRef.current
|
||||
if (!el) return 0
|
||||
const rect = el.getBoundingClientRect()
|
||||
return Math.max(0, Math.min(1, (clientX - rect.left) / rect.width))
|
||||
}
|
||||
|
||||
// ── Drag handles — free movement, no snapping ───────────────────────────────
|
||||
function handleMouseDown(handle) {
|
||||
return (e) => {
|
||||
e.preventDefault()
|
||||
function onMove(ev) {
|
||||
const raw = fracFromClientX(ev.clientX)
|
||||
if (handle === 'start') {
|
||||
const c = Math.max(0, Math.min(raw, trimEndRef.current - 0.01))
|
||||
setTrimStart(c); trimStartRef.current = c
|
||||
} else {
|
||||
const c = Math.max(trimStartRef.current + 0.01, Math.min(1, raw))
|
||||
setTrimEnd(c); trimEndRef.current = c
|
||||
}
|
||||
draw()
|
||||
}
|
||||
function onUp() {
|
||||
window.removeEventListener('mousemove', onMove)
|
||||
window.removeEventListener('mouseup', onUp)
|
||||
}
|
||||
window.addEventListener('mousemove', onMove)
|
||||
window.addEventListener('mouseup', onUp)
|
||||
}
|
||||
}
|
||||
|
||||
// Click canvas to move nearest handle
|
||||
function handleCanvasClick(e) {
|
||||
if (e.target !== canvasRef.current) return
|
||||
const raw = fracFromClientX(e.clientX)
|
||||
if (Math.abs(raw - trimStart) <= Math.abs(raw - trimEnd)) {
|
||||
const c = Math.max(0, Math.min(raw, trimEndRef.current - 0.01))
|
||||
setTrimStart(c); trimStartRef.current = c
|
||||
} else {
|
||||
const c = Math.max(trimStartRef.current + 0.01, Math.min(1, raw))
|
||||
setTrimEnd(c); trimEndRef.current = c
|
||||
}
|
||||
draw()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-t border-border">
|
||||
{/* Header row */}
|
||||
<div className="flex items-center justify-between px-4 pt-3 pb-1">
|
||||
<span className="text-[11px] uppercase tracking-wider text-gray-500">
|
||||
Trim — Loop {slotIdx + 1}
|
||||
</span>
|
||||
<div className="flex items-center gap-3 text-xs text-gray-500 font-mono">
|
||||
<span className="text-gray-600">{fmtMs(startSec)} → {fmtMs(endSec)}</span>
|
||||
<span className="text-accent font-semibold">{fmtSec(selectedSec)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Waveform + handles */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="relative mx-4 h-20 rounded-lg overflow-visible cursor-crosshair select-none"
|
||||
onClick={handleCanvasClick}
|
||||
>
|
||||
<canvas ref={canvasRef} className="w-full h-full block rounded-lg" />
|
||||
|
||||
{/* Left handle */}
|
||||
<div
|
||||
className="absolute top-0 bottom-0 w-5 -translate-x-1/2 cursor-ew-resize flex items-center justify-center group z-10"
|
||||
style={{ left: `${trimStart * 100}%` }}
|
||||
onMouseDown={handleMouseDown('start')}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<div className="w-0.5 h-full bg-accent/70 group-hover:bg-accent group-hover:w-1 transition-all" />
|
||||
<div className="absolute w-3.5 h-3.5 rounded-full bg-accent border-2 border-white/20 shadow-lg top-1/2 -translate-y-1/2" />
|
||||
<div className="absolute bottom-full mb-1 text-[9px] font-mono text-accent bg-panel border border-border rounded px-1 py-0.5 whitespace-nowrap pointer-events-none">
|
||||
{fmtMs(startSec)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right handle */}
|
||||
<div
|
||||
className="absolute top-0 bottom-0 w-5 -translate-x-1/2 cursor-ew-resize flex items-center justify-center group z-10"
|
||||
style={{ left: `${trimEnd * 100}%` }}
|
||||
onMouseDown={handleMouseDown('end')}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<div className="w-0.5 h-full bg-accent/70 group-hover:bg-accent group-hover:w-1 transition-all" />
|
||||
<div className="absolute w-3.5 h-3.5 rounded-full bg-accent border-2 border-white/20 shadow-lg top-1/2 -translate-y-1/2" />
|
||||
<div className="absolute bottom-full mb-1 text-[9px] font-mono text-accent bg-panel border border-border rounded px-1 py-0.5 whitespace-nowrap pointer-events-none">
|
||||
{fmtMs(endSec)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Toolbar: preview + bar snap + hint */}
|
||||
<div className="flex items-center gap-2 px-4 pt-2 pb-1 flex-wrap">
|
||||
{/* Preview play/stop */}
|
||||
<button
|
||||
onClick={togglePreview}
|
||||
className={`flex items-center gap-1 px-2.5 py-1 rounded-lg border text-xs font-medium transition-all ${
|
||||
previewing
|
||||
? 'bg-accent/20 border-accent text-accent'
|
||||
: 'bg-surface border-border text-gray-400 hover:text-white hover:border-gray-500'
|
||||
}`}
|
||||
title="Preview loop selection"
|
||||
>
|
||||
{previewing
|
||||
? <><span>⏹</span><span>Stop</span></>
|
||||
: <><span>▶</span><span>Preview</span></>
|
||||
}
|
||||
</button>
|
||||
|
||||
{/* Bar snap buttons — only if BPM is set */}
|
||||
{barSec && duration && (
|
||||
<div className="flex items-center gap-1 ml-1">
|
||||
<span className="text-[10px] text-gray-600 uppercase tracking-wider mr-0.5">snap end →</span>
|
||||
{[1, 2, 4].map(n => {
|
||||
const endFrac = trimStart + (n * barSec) / duration
|
||||
const fits = endFrac <= 1.02
|
||||
return (
|
||||
<button
|
||||
key={n}
|
||||
onClick={() => snapBars(n)}
|
||||
disabled={!fits}
|
||||
className="px-2 py-0.5 rounded border border-border text-[10px] text-gray-400 hover:text-accent hover:border-accent/50 transition-colors disabled:opacity-30 disabled:cursor-not-allowed"
|
||||
title={`Set end to ${n} bar${n > 1 ? 's' : ''} from start`}
|
||||
>
|
||||
{n} bar{n > 1 ? 's' : ''}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<span className="ml-auto text-[10px] text-gray-700">
|
||||
{bpm ? `${bpm} BPM grid` : 'no BPM — trim freely'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
<div className="flex gap-2 px-4 pb-3">
|
||||
<button
|
||||
onClick={() => { stopPreview(); onCommit(slotIdx, trimStart, trimEnd) }}
|
||||
className="px-5 py-1.5 bg-accent text-white text-sm font-bold rounded-lg hover:bg-accent/80 transition-colors"
|
||||
>
|
||||
Set Loop ▶
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { stopPreview(); onCommit(slotIdx, 0, 1) }}
|
||||
className="px-4 py-1.5 bg-surface border border-border text-gray-400 text-sm rounded-lg hover:text-white hover:border-gray-500 transition-colors"
|
||||
title="Use the full recording without trimming"
|
||||
>
|
||||
Use Full
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { stopPreview(); onCancel(slotIdx) }}
|
||||
className="px-4 py-1.5 bg-surface border border-border text-gray-500 text-sm rounded-lg hover:text-red-400 hover:border-red-800 transition-colors ml-auto"
|
||||
>
|
||||
Re-record
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// 2-octave mini piano keyboard showing technique notes
|
||||
// Props:
|
||||
// rootPc — root pitch class 0-11
|
||||
// lh — array of semitone intervals above root (left hand, shown in blue)
|
||||
// rh — array of semitone intervals above root (right hand, shown in purple)
|
||||
|
||||
const OCTAVES = 2
|
||||
const WW = 22 // white key width
|
||||
const WH = 60 // white key height
|
||||
const BW = 14 // black key width
|
||||
const BH = 38 // black key height
|
||||
|
||||
// White key pitch classes within an octave, in order
|
||||
const WHITE_PCS = [0, 2, 4, 5, 7, 9, 11] // C D E F G A B
|
||||
const WHITE_NAMES = ['C','D','E','F','G','A','B']
|
||||
// Black key offsets (x position relative to white key 0) and pitch classes
|
||||
const BLACK_OFFSETS = [
|
||||
{ pc: 1, afterWhite: 0 }, // C#
|
||||
{ pc: 3, afterWhite: 1 }, // D#
|
||||
{ pc: 6, afterWhite: 3 }, // F#
|
||||
{ pc: 8, afterWhite: 4 }, // G#
|
||||
{ pc: 10, afterWhite: 5 }, // A#
|
||||
]
|
||||
|
||||
const TOTAL_WHITES = WHITE_PCS.length * OCTAVES // 14
|
||||
const SVG_W = WW * TOTAL_WHITES + 2
|
||||
const SVG_H = WH + 24
|
||||
|
||||
function noteColor(interval) {
|
||||
// interval < 12 → first octave (root region), ≥12 → second octave
|
||||
return interval < 12 ? '#a855f7' : '#c084fc'
|
||||
}
|
||||
|
||||
function handLabel(hand) {
|
||||
return hand === 'L' ? 'LH' : 'RH'
|
||||
}
|
||||
|
||||
export default function MiniPiano({ rootPc, lh = [], rh = [] }) {
|
||||
// Build a set of highlighted notes: pc → { hand, interval }
|
||||
// We span 2 octaves (semitones 0…23 above root), mapped to absolute pitch classes
|
||||
const highlights = new Map() // absIdx → { color, label }
|
||||
|
||||
function addNotes(intervals, hand) {
|
||||
for (const iv of intervals) {
|
||||
const octave = Math.floor(iv / 12)
|
||||
const pc = (rootPc + iv) % 12
|
||||
const absIdx = octave * 12 + pc // unique index per octave slot
|
||||
highlights.set(`${octave}-${pc}`, { color: hand === 'L' ? '#3b82f6' : '#a855f7', label: handLabel(hand) })
|
||||
}
|
||||
}
|
||||
addNotes(lh, 'L')
|
||||
addNotes(rh, 'R')
|
||||
|
||||
function isHighlighted(octave, pc) {
|
||||
return highlights.get(`${octave}-${pc}`)
|
||||
}
|
||||
|
||||
// White keys
|
||||
const whites = []
|
||||
for (let oct = 0; oct < OCTAVES; oct++) {
|
||||
for (let wi = 0; wi < WHITE_PCS.length; wi++) {
|
||||
const pc = WHITE_PCS[wi]
|
||||
const absWi = oct * WHITE_PCS.length + wi
|
||||
const x = absWi * WW + 1
|
||||
const hl = isHighlighted(oct, pc)
|
||||
whites.push({ x, pc, oct, wi, absWi, hl, name: WHITE_NAMES[wi] + (oct + 4) })
|
||||
}
|
||||
}
|
||||
|
||||
// Black keys
|
||||
const blacks = []
|
||||
for (let oct = 0; oct < OCTAVES; oct++) {
|
||||
for (const { pc, afterWhite } of BLACK_OFFSETS) {
|
||||
const absWi = oct * WHITE_PCS.length + afterWhite
|
||||
const x = absWi * WW + WW - BW / 2
|
||||
const hl = isHighlighted(oct, pc)
|
||||
blacks.push({ x, pc, oct, hl })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<svg width={SVG_W} height={SVG_H} viewBox={`0 0 ${SVG_W} ${SVG_H}`} className="overflow-visible">
|
||||
{/* White keys */}
|
||||
{whites.map(({ x, hl, name, absWi }) => (
|
||||
<g key={`w${absWi}`}>
|
||||
<rect
|
||||
x={x} y={1} width={WW - 1} height={WH}
|
||||
rx={2}
|
||||
fill={hl ? hl.color : '#f5f5f5'}
|
||||
stroke="#374151"
|
||||
strokeWidth={0.5}
|
||||
/>
|
||||
{hl && (
|
||||
<text x={x + (WW - 1) / 2} y={WH - 8}
|
||||
textAnchor="middle" fill="white" fontSize={7} fontWeight="bold">
|
||||
{hl.label}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{/* Black keys */}
|
||||
{blacks.map(({ x, pc, oct, hl }, i) => (
|
||||
<g key={`b${oct}-${pc}`}>
|
||||
<rect
|
||||
x={x} y={1} width={BW} height={BH}
|
||||
rx={2}
|
||||
fill={hl ? hl.color : '#1f2937'}
|
||||
stroke="#111827"
|
||||
strokeWidth={0.5}
|
||||
/>
|
||||
{hl && (
|
||||
<text x={x + BW / 2} y={BH - 5}
|
||||
textAnchor="middle" fill="white" fontSize={6} fontWeight="bold">
|
||||
{hl.label}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{/* Root label at bottom */}
|
||||
{whites.map(({ x, pc, oct, name, absWi }) => {
|
||||
const isRoot = pc === rootPc && oct === 0
|
||||
if (!isRoot) return null
|
||||
return (
|
||||
<text key={`lbl${absWi}`} x={x + (WW - 1) / 2} y={WH + 14}
|
||||
textAnchor="middle" fill="#a855f7" fontSize={8} fontWeight="bold">
|
||||
R
|
||||
</text>
|
||||
)
|
||||
})}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
import { useState, useRef, useEffect, useCallback } from 'react'
|
||||
|
||||
const MODEL = 'claude-sonnet-4-6'
|
||||
const API_URL = 'https://api.anthropic.com/v1/messages'
|
||||
const LS_KEY = 'wtf_teacher_key'
|
||||
|
||||
// ── System prompt — rebuilt with live session context on every request ────────
|
||||
function buildSystemPrompt({ keyInfo, currentChord, bpm, chordHistory }) {
|
||||
const keyStr = keyInfo ? `${keyInfo.root} ${keyInfo.mode}` : 'not detected yet'
|
||||
const chordStr = currentChord?.name ?? 'none detected'
|
||||
const bpmStr = bpm ? `${Math.round(bpm)} BPM` : 'not detected'
|
||||
const histStr = chordHistory?.length
|
||||
? chordHistory.map(c => c.name).join(' → ')
|
||||
: 'none yet'
|
||||
|
||||
return `You are an expert music teacher and session musician embedded in JamBuddy, a real-time chord and key detection app for guitarists and keyboard players at live jam sessions.
|
||||
|
||||
LIVE SESSION CONTEXT (updated in real time):
|
||||
• Detected key: ${keyStr}
|
||||
• Current chord: ${chordStr}
|
||||
• BPM: ${bpmStr}
|
||||
• Recent chord history: ${histStr}
|
||||
|
||||
YOUR ROLE:
|
||||
- Explain chords, scales, and music theory in plain, friendly language
|
||||
- Suggest what to practice based on the current key and chord progression
|
||||
- Teach playing techniques: fretting, strumming patterns, chord voicings, fingerpicking
|
||||
- Help musicians understand WHY things sound the way they do
|
||||
- Suggest progressions that work with whatever the user is currently playing
|
||||
- Adjust depth to the user — explain basics if they seem new, go deep if they ask for it
|
||||
- Point out interesting connections: "that Dm7 works here because it's the ii chord in C major"
|
||||
|
||||
STYLE:
|
||||
- Keep responses focused and practical — this is a live jam, not a classroom
|
||||
- Use plain text, not markdown. Short paragraphs. Bullet points with "-" are fine.
|
||||
- If someone asks about the current chord or key, use the live context above
|
||||
- Max ~150 words unless someone asks for a deep dive`
|
||||
}
|
||||
|
||||
// ── Quick-action chips ────────────────────────────────────────────────────────
|
||||
const CHIPS = [
|
||||
{ label: 'What should I practice?', msg: 'Based on what I\'m playing right now, what\'s the most useful thing I could practice?' },
|
||||
{ label: 'Explain current chord', msg: 'Explain the current chord I\'m playing — what it is, why it sounds the way it does, and where it tends to appear.' },
|
||||
{ label: 'Scales that work here', msg: 'What scales work over the current key and chord? Which notes sound best to improvise with?' },
|
||||
{ label: 'Suggest a progression', msg: 'Suggest a chord progression that fits the current key. Give me something interesting to try.' },
|
||||
{ label: 'Technique tip', msg: 'Give me one technique tip — something I can work on in the next few minutes to sound better.' },
|
||||
{ label: 'Why does this sound good?', msg: 'Looking at my recent chord history, why do these chords sound good together? What\'s the music theory behind it?' },
|
||||
]
|
||||
|
||||
// ── Simple text renderer (bold + line breaks) ─────────────────────────────────
|
||||
function MessageText({ text }) {
|
||||
const lines = text.split('\n')
|
||||
return (
|
||||
<div className="space-y-1">
|
||||
{lines.map((line, i) => {
|
||||
if (!line.trim()) return <div key={i} className="h-1" />
|
||||
// Bold: **text**
|
||||
const parts = line.split(/(\*\*[^*]+\*\*)/)
|
||||
return (
|
||||
<p key={i} className="leading-relaxed">
|
||||
{parts.map((part, j) =>
|
||||
part.startsWith('**') && part.endsWith('**')
|
||||
? <strong key={j} className="text-white font-semibold">{part.slice(2, -2)}</strong>
|
||||
: part
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main component ────────────────────────────────────────────────────────────
|
||||
export default function MusicTeacher({ keyInfo, currentChord, bpm, chordHistory }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [apiKey, setApiKey] = useState(() => localStorage.getItem(LS_KEY) ?? '')
|
||||
const [showKeyInput, setShowKeyInput] = useState(false)
|
||||
const [messages, setMessages] = useState([]) // [{role, content}]
|
||||
const [input, setInput] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [streaming, setStreaming] = useState('') // partial response being streamed
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const scrollRef = useRef(null)
|
||||
const inputRef = useRef(null)
|
||||
const abortRef = useRef(null)
|
||||
|
||||
// Always scroll to bottom on new content
|
||||
useEffect(() => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight
|
||||
}
|
||||
}, [messages, streaming])
|
||||
|
||||
// Focus input when panel opens
|
||||
useEffect(() => {
|
||||
if (open && apiKey && inputRef.current) {
|
||||
setTimeout(() => inputRef.current?.focus(), 50)
|
||||
}
|
||||
}, [open, apiKey])
|
||||
|
||||
function saveKey(k) {
|
||||
setApiKey(k)
|
||||
localStorage.setItem(LS_KEY, k)
|
||||
}
|
||||
|
||||
function clearKey() {
|
||||
setApiKey('')
|
||||
localStorage.removeItem(LS_KEY)
|
||||
setShowKeyInput(true)
|
||||
}
|
||||
|
||||
const sendMessage = useCallback(async (userText) => {
|
||||
if (!userText.trim() || loading || !apiKey) return
|
||||
|
||||
setError(null)
|
||||
const userMsg = { role: 'user', content: userText.trim() }
|
||||
const nextMessages = [...messages, userMsg]
|
||||
setMessages(nextMessages)
|
||||
setInput('')
|
||||
setLoading(true)
|
||||
setStreaming('')
|
||||
|
||||
const context = { keyInfo, currentChord, bpm, chordHistory }
|
||||
|
||||
try {
|
||||
const ctrl = new AbortController()
|
||||
abortRef.current = ctrl
|
||||
|
||||
const res = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
signal: ctrl.signal,
|
||||
headers: {
|
||||
'x-api-key': apiKey,
|
||||
'anthropic-version': '2023-06-01',
|
||||
'anthropic-dangerous-direct-browser-access': 'true',
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: MODEL,
|
||||
max_tokens: 1024,
|
||||
stream: true,
|
||||
system: buildSystemPrompt(context),
|
||||
messages: nextMessages,
|
||||
}),
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}))
|
||||
throw new Error(body?.error?.message ?? `API error ${res.status}`)
|
||||
}
|
||||
|
||||
const reader = res.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let full = ''
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
const chunk = decoder.decode(value, { stream: true })
|
||||
for (const line of chunk.split('\n')) {
|
||||
if (!line.startsWith('data: ')) continue
|
||||
const data = line.slice(6).trim()
|
||||
if (data === '[DONE]' || !data) continue
|
||||
try {
|
||||
const ev = JSON.parse(data)
|
||||
if (ev.type === 'content_block_delta' && ev.delta?.type === 'text_delta') {
|
||||
full += ev.delta.text
|
||||
setStreaming(full)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
setMessages(prev => [...prev, { role: 'assistant', content: full }])
|
||||
setStreaming('')
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
setError(err.message)
|
||||
}
|
||||
} finally {
|
||||
setLoading(false)
|
||||
abortRef.current = null
|
||||
}
|
||||
}, [messages, loading, apiKey, keyInfo, currentChord, bpm, chordHistory])
|
||||
|
||||
function stopGeneration() {
|
||||
abortRef.current?.abort()
|
||||
if (streaming) {
|
||||
setMessages(prev => [...prev, { role: 'assistant', content: streaming }])
|
||||
setStreaming('')
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
function handleKeyDown(e) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault()
|
||||
sendMessage(input)
|
||||
}
|
||||
}
|
||||
|
||||
const hasKey = apiKey.trim().length > 0
|
||||
|
||||
// Dot: purple when API key set, gray otherwise
|
||||
const dotClass = hasKey ? 'bg-accent' : 'bg-gray-700'
|
||||
|
||||
return (
|
||||
<div className="mb-3 bg-panel border border-border rounded-xl overflow-hidden">
|
||||
{/* ── Header ─────────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-between px-4 py-2 text-sm text-gray-400">
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="flex items-center gap-2 hover:text-gray-200 transition-colors text-left"
|
||||
>
|
||||
<span className={`w-2 h-2 rounded-full shrink-0 ${dotClass}`} />
|
||||
<span>MUSIC TEACHER</span>
|
||||
<span className="text-[11px] text-gray-600">AI · Claude</span>
|
||||
</button>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Key indicator */}
|
||||
<button
|
||||
onClick={() => setShowKeyInput(v => !v)}
|
||||
className="text-[10px] text-gray-600 hover:text-gray-400 transition-colors px-1.5 py-0.5 rounded border border-transparent hover:border-border"
|
||||
title={hasKey ? 'API key set — click to change' : 'Set API key'}
|
||||
>
|
||||
{hasKey ? '🔑 key set' : '🔑 add key'}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-6 h-6 flex items-center justify-center rounded text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-all"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
||||
{open
|
||||
? <polyline points="2,8 6,4 10,8" />
|
||||
: <polyline points="2,4 6,8 10,4" />
|
||||
}
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Body ───────────────────────────────────────────────────────────── */}
|
||||
{open && (
|
||||
<div className="border-t border-border">
|
||||
|
||||
{/* API key input (shown when no key or user wants to change) */}
|
||||
{(!hasKey || showKeyInput) && (
|
||||
<div className="px-4 py-3 bg-surface/50 border-b border-border">
|
||||
<p className="text-xs text-gray-500 mb-2">
|
||||
Enter your <a className="text-accent underline" href="https://console.anthropic.com/keys" target="_blank" rel="noreferrer">Anthropic API key</a> to enable the music teacher. Stored locally on your device only.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="password"
|
||||
value={apiKey}
|
||||
onChange={e => setApiKey(e.target.value)}
|
||||
placeholder="sk-ant-..."
|
||||
className="flex-1 px-2.5 py-1.5 bg-surface border border-border rounded-lg text-xs text-gray-300 focus:outline-none focus:border-accent font-mono"
|
||||
/>
|
||||
<button
|
||||
onClick={() => { saveKey(apiKey); setShowKeyInput(false) }}
|
||||
disabled={!apiKey.trim()}
|
||||
className="px-3 py-1.5 bg-accent text-white text-xs font-bold rounded-lg hover:bg-accent/80 transition-colors disabled:opacity-40"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
{hasKey && (
|
||||
<button
|
||||
onClick={() => setShowKeyInput(false)}
|
||||
className="px-3 py-1.5 text-xs text-gray-500 hover:text-gray-300 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasKey && (
|
||||
<>
|
||||
{/* Live session context strip */}
|
||||
<div className="flex items-center gap-3 px-4 py-2 border-b border-border text-[10px] font-mono">
|
||||
<span className="text-gray-600 uppercase tracking-wider">Now:</span>
|
||||
{keyInfo ? (
|
||||
<span className="text-accent">{keyInfo.root} {keyInfo.mode}</span>
|
||||
) : (
|
||||
<span className="text-gray-700">no key</span>
|
||||
)}
|
||||
<span className="text-gray-800">·</span>
|
||||
{currentChord ? (
|
||||
<span className="text-white">{currentChord.name}</span>
|
||||
) : (
|
||||
<span className="text-gray-700">no chord</span>
|
||||
)}
|
||||
<span className="text-gray-800">·</span>
|
||||
<span className="text-gray-500">{bpm ? `${Math.round(bpm)} bpm` : '— bpm'}</span>
|
||||
{messages.length > 0 && (
|
||||
<button
|
||||
onClick={() => { setMessages([]); setError(null) }}
|
||||
className="ml-auto text-gray-700 hover:text-gray-400 transition-colors"
|
||||
title="Clear conversation"
|
||||
>
|
||||
clear chat
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Chat messages */}
|
||||
{messages.length > 0 || streaming ? (
|
||||
<div
|
||||
ref={scrollRef}
|
||||
className="max-h-72 overflow-y-auto px-4 py-3 space-y-3 text-xs"
|
||||
>
|
||||
{messages.map((m, i) => (
|
||||
<div key={i} className={m.role === 'user' ? 'flex justify-end' : ''}>
|
||||
{m.role === 'user' ? (
|
||||
<div className="max-w-[80%] bg-accent/20 border border-accent/30 rounded-xl rounded-tr-sm px-3 py-2 text-gray-200">
|
||||
{m.content}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-gray-300 leading-relaxed">
|
||||
<MessageText text={m.content} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{streaming && (
|
||||
<div className="text-gray-300 text-xs leading-relaxed">
|
||||
<MessageText text={streaming} />
|
||||
<span className="inline-block w-1.5 h-3.5 bg-accent/70 animate-pulse ml-0.5 align-middle" />
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className="text-red-400 text-xs bg-red-950/30 border border-red-900/50 rounded-lg px-3 py-2">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
/* Quick-action chips (shown when no chat history yet) */
|
||||
<div className="px-4 py-3">
|
||||
<p className="text-[10px] text-gray-700 mb-2 uppercase tracking-wider">Ask something</p>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{CHIPS.map(chip => (
|
||||
<button
|
||||
key={chip.label}
|
||||
onClick={() => sendMessage(chip.msg)}
|
||||
className="px-2.5 py-1 bg-surface border border-border rounded-full text-[10px] text-gray-400 hover:text-white hover:border-accent/50 hover:bg-accent/10 transition-all"
|
||||
>
|
||||
{chip.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Input row */}
|
||||
<div className="px-4 py-3 border-t border-border flex gap-2 items-end">
|
||||
<textarea
|
||||
ref={inputRef}
|
||||
value={input}
|
||||
onChange={e => setInput(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Ask anything about music theory, technique, or what to play…"
|
||||
rows={1}
|
||||
className="flex-1 px-3 py-2 bg-surface border border-border rounded-xl text-xs text-gray-300 placeholder-gray-700 focus:outline-none focus:border-accent resize-none leading-relaxed"
|
||||
style={{ maxHeight: '80px', overflowY: 'auto' }}
|
||||
/>
|
||||
{loading ? (
|
||||
<button
|
||||
onClick={stopGeneration}
|
||||
className="px-3 py-2 bg-surface border border-border text-gray-500 hover:text-red-400 hover:border-red-800 text-xs rounded-xl transition-colors shrink-0"
|
||||
title="Stop"
|
||||
>
|
||||
⏹
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => sendMessage(input)}
|
||||
disabled={!input.trim()}
|
||||
className="px-3 py-2 bg-accent text-white text-xs font-bold rounded-xl hover:bg-accent/80 transition-colors disabled:opacity-40 shrink-0"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Quick chips after first message */}
|
||||
{messages.length > 0 && (
|
||||
<div className="px-4 pb-3 flex flex-wrap gap-1.5">
|
||||
{CHIPS.slice(0, 4).map(chip => (
|
||||
<button
|
||||
key={chip.label}
|
||||
onClick={() => sendMessage(chip.msg)}
|
||||
disabled={loading}
|
||||
className="px-2 py-0.5 bg-surface border border-border rounded-full text-[9px] text-gray-600 hover:text-gray-300 hover:border-accent/30 transition-all disabled:opacity-30"
|
||||
>
|
||||
{chip.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { getPentatonicScale, getFullScale, getChordTones, NOTES } from '../lib/theory'
|
||||
|
||||
// White keys in order within an octave, mapped to pitch class
|
||||
const WHITE_KEYS = [
|
||||
{ pc: 0, label: 'C' },
|
||||
{ pc: 2, label: 'D' },
|
||||
{ pc: 4, label: 'E' },
|
||||
{ pc: 5, label: 'F' },
|
||||
{ pc: 7, label: 'G' },
|
||||
{ pc: 9, label: 'A' },
|
||||
{ pc: 11, label: 'B' },
|
||||
]
|
||||
|
||||
// Black keys: position (in white-key units from left of octave) and pitch class
|
||||
const BLACK_KEYS = [
|
||||
{ pc: 1, offset: 0.7 }, // C#
|
||||
{ pc: 3, offset: 1.7 }, // D#
|
||||
{ pc: 6, offset: 3.7 }, // F#
|
||||
{ pc: 8, offset: 4.7 }, // G#
|
||||
{ pc: 10, offset: 5.7 }, // A#
|
||||
]
|
||||
|
||||
const OCTAVES = 2 // number of octaves shown
|
||||
const KEY_W = 40 // white key width
|
||||
const KEY_H = 130 // white key height
|
||||
const BLACK_W = 26 // black key width
|
||||
const BLACK_H = 82 // black key height
|
||||
const LABEL_Y = KEY_H - 10 // y of note label on white key
|
||||
const BLACK_LABEL_Y = BLACK_H - 8
|
||||
|
||||
function keyColor(isChordTone, isPenta, isScale, isBlack, mono = false) {
|
||||
if (isChordTone) return { fill: '#a855f7', text: '#fff' }
|
||||
if (isPenta) return mono ? { fill: '#c084fc', text: '#1e1b4b' } : { fill: '#f59e0b', text: '#000' }
|
||||
if (isScale) return mono ? { fill: '#e9d5ff', text: '#581c87' } : { fill: '#374151', text: '#d1d5db' }
|
||||
return isBlack
|
||||
? { fill: '#1f1f1f', text: '#6b7280' }
|
||||
: { fill: '#f5f5f5', text: '#6b7280' }
|
||||
}
|
||||
|
||||
export default function Piano({ keyInfo, currentChord, monoColor = false }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
if (!root) return null
|
||||
|
||||
const pentaSet = new Set(getPentatonicScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const scaleSet = new Set(getFullScale(root, mode).map(n => NOTES.indexOf(n)))
|
||||
const chordSet = currentChord
|
||||
? new Set(getChordTones(currentChord).map(n => NOTES.indexOf(n)))
|
||||
: new Set()
|
||||
|
||||
const totalWhite = WHITE_KEYS.length * OCTAVES
|
||||
const svgW = totalWhite * KEY_W + 2
|
||||
const svgH = KEY_H + 20 // +20 for octave labels
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-6">
|
||||
<p className="text-sm text-gray-500 uppercase tracking-widest mb-4">
|
||||
Piano — {root} {mode}
|
||||
{currentChord && <span className="text-amber-400 ml-2">/ {currentChord}</span>}
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<svg viewBox={`0 0 ${svgW} ${svgH}`} width="100%" height="auto" style={{ display: 'block' }}>
|
||||
|
||||
{/* White keys */}
|
||||
{Array.from({ length: OCTAVES }, (_, oct) =>
|
||||
WHITE_KEYS.map((k, wi) => {
|
||||
const x = (oct * WHITE_KEYS.length + wi) * KEY_W + 1
|
||||
const isChordTone = chordSet.has(k.pc)
|
||||
const isPenta = pentaSet.has(k.pc)
|
||||
const isScale = scaleSet.has(k.pc)
|
||||
const { fill, text } = keyColor(isChordTone, isPenta, isScale, false, monoColor)
|
||||
return (
|
||||
<g key={`w-${oct}-${wi}`}>
|
||||
<rect
|
||||
x={x} y={0}
|
||||
width={KEY_W - 1} height={KEY_H}
|
||||
fill={fill}
|
||||
rx={3}
|
||||
stroke="#2a2a2a"
|
||||
strokeWidth={1}
|
||||
/>
|
||||
{(isChordTone || isPenta || isScale) && (
|
||||
<text
|
||||
x={x + KEY_W / 2} y={LABEL_Y}
|
||||
textAnchor="middle"
|
||||
fontSize={9}
|
||||
fontWeight="600"
|
||||
fill={text}
|
||||
>
|
||||
{k.label}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})
|
||||
)}
|
||||
|
||||
{/* Black keys (drawn on top) */}
|
||||
{Array.from({ length: OCTAVES }, (_, oct) =>
|
||||
BLACK_KEYS.map((k, bi) => {
|
||||
const x = (oct * WHITE_KEYS.length + k.offset) * KEY_W + 1
|
||||
const isChordTone = chordSet.has(k.pc)
|
||||
const isPenta = pentaSet.has(k.pc)
|
||||
const isScale = scaleSet.has(k.pc)
|
||||
const { fill, text } = keyColor(isChordTone, isPenta, isScale, true, monoColor)
|
||||
return (
|
||||
<g key={`b-${oct}-${bi}`}>
|
||||
<rect
|
||||
x={x} y={0}
|
||||
width={BLACK_W} height={BLACK_H}
|
||||
fill={fill}
|
||||
rx={2}
|
||||
stroke="#111"
|
||||
strokeWidth={1}
|
||||
/>
|
||||
{(isChordTone || isPenta || isScale) && (
|
||||
<text
|
||||
x={x + BLACK_W / 2} y={BLACK_LABEL_Y}
|
||||
textAnchor="middle"
|
||||
fontSize={8}
|
||||
fontWeight="600"
|
||||
fill={text}
|
||||
>
|
||||
{NOTES[k.pc]}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})
|
||||
)}
|
||||
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex gap-5 text-xs text-gray-500">
|
||||
<span><span className="text-accent">●</span> Chord tone</span>
|
||||
<span><span style={{ color: monoColor ? '#c084fc' : '#f59e0b' }}>●</span> Pentatonic</span>
|
||||
<span><span style={{ color: monoColor ? '#e9d5ff' : '#6b7280' }}>●</span> Scale</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useRef, useEffect } from 'react'
|
||||
import { toRomanNumeral } from '../lib/theory'
|
||||
import { findLoopPosition } from '../lib/match'
|
||||
|
||||
const HISTORY_SHOWN = 8
|
||||
|
||||
export default function ProgressionBanner({ chordHistory, keyInfo, detectedProgression, currentChord, onChordClick }) {
|
||||
const { root, mode, confidence } = keyInfo ?? {}
|
||||
|
||||
const visible = chordHistory.slice(-HISTORY_SHOWN)
|
||||
const current = visible[visible.length - 1]
|
||||
const loopPos = findLoopPosition(chordHistory, detectedProgression)
|
||||
const currentRN = root && current ? toRomanNumeral(current, root, mode) : ''
|
||||
|
||||
const currentRef = useRef(null)
|
||||
const prevChord = useRef(null)
|
||||
useEffect(() => {
|
||||
if (current && current !== prevChord.current && currentRef.current) {
|
||||
currentRef.current.animate(
|
||||
[{ opacity: 0, transform: 'scale(0.85)' }, { opacity: 1, transform: 'scale(1)' }],
|
||||
{ duration: 200, easing: 'ease-out', fill: 'forwards' }
|
||||
)
|
||||
prevChord.current = current
|
||||
}
|
||||
}, [current])
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-4 mb-3 flex gap-4">
|
||||
|
||||
{/* ── Left: key + chord history + loop ── */}
|
||||
<div className="w-full lg:w-[70%] min-w-0 flex flex-col gap-2">
|
||||
|
||||
{/* Key + history on one row */}
|
||||
<div className="flex items-end gap-3">
|
||||
<div className="shrink-0 flex items-baseline gap-1.5">
|
||||
{root ? (
|
||||
<>
|
||||
<span className="text-2xl font-bold text-accent">{root}</span>
|
||||
<span className="text-gray-400 text-sm">{mode}</span>
|
||||
{confidence && (
|
||||
<span className="text-xs text-gray-600">{Math.round(confidence * 100)}%</span>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-gray-600 text-sm">Detecting key…</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-px h-6 bg-border shrink-0" />
|
||||
|
||||
{!chordHistory.length ? (
|
||||
<p className="text-gray-600 text-sm">Start listening…</p>
|
||||
) : (
|
||||
<div className="flex items-end gap-1 overflow-x-auto pb-1">
|
||||
{visible.map((chord, i) => {
|
||||
const isCurrent = i === visible.length - 1
|
||||
const age = visible.length - 1 - i
|
||||
const opacity = Math.max(0.25, 1 - age * 0.09)
|
||||
const rn = root ? toRomanNumeral(chord, root, mode) : ''
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
ref={isCurrent ? currentRef : null}
|
||||
style={{ opacity }}
|
||||
onClick={() => onChordClick?.(chord)}
|
||||
className={`flex flex-col items-center shrink-0 px-2 py-1 rounded-xl transition-colors duration-200 cursor-pointer ${
|
||||
isCurrent
|
||||
? 'bg-accent/10 border border-accent/40 ring-1 ring-accent/20 hover:bg-accent/20'
|
||||
: 'border border-transparent hover:border-border hover:bg-panel'
|
||||
}`}
|
||||
>
|
||||
<span className={`font-black leading-none tracking-tight ${
|
||||
isCurrent ? 'text-3xl text-accent' : 'text-xl text-gray-200'
|
||||
}`}>
|
||||
{chord}
|
||||
</span>
|
||||
<span className={`text-xs font-semibold mt-0.5 ${
|
||||
isCurrent ? 'text-amber-400' : 'text-gray-500'
|
||||
}`}>
|
||||
{rn || '\u00A0'}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Loop */}
|
||||
{detectedProgression && (
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<span className="text-xs text-gray-500">♻</span>
|
||||
{detectedProgression.map((chord, i) => {
|
||||
const isActive = i === loopPos
|
||||
const rn = root ? toRomanNumeral(chord, root, mode) : chord
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
onClick={() => onChordClick?.(chord)}
|
||||
className={`flex flex-col items-center px-2 py-0.5 rounded-lg border transition-all duration-200 cursor-pointer ${
|
||||
isActive
|
||||
? 'bg-accent/20 border-accent shadow-[0_0_10px_rgba(168,85,247,0.3)] hover:bg-accent/30'
|
||||
: 'bg-border border-border hover:border-gray-500'
|
||||
}`}
|
||||
>
|
||||
<span className={`text-sm font-bold leading-none ${isActive ? 'text-accent' : 'text-gray-300'}`}>
|
||||
{chord}
|
||||
</span>
|
||||
<span className={`text-xs ${isActive ? 'text-amber-400' : 'text-gray-600'}`}>{rn}</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<span className="text-gray-600 text-xs">→ loop</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Divider ── */}
|
||||
<div className="hidden lg:block w-px bg-border shrink-0" />
|
||||
|
||||
{/* ── Right: big chord ── */}
|
||||
<div className="hidden lg:flex w-[30%] flex-col items-center justify-center gap-1">
|
||||
{current ? (
|
||||
<button
|
||||
onClick={() => onChordClick?.(current)}
|
||||
className="flex flex-col items-center gap-1 px-4 py-2 rounded-xl hover:bg-accent/10 transition-colors group"
|
||||
title="Click to see voicings"
|
||||
>
|
||||
<p className="text-xs text-gray-600 uppercase tracking-widest">Now Playing</p>
|
||||
<div className="text-6xl font-black text-amber-400 leading-none group-hover:text-accent transition-colors">{current}</div>
|
||||
<div className="text-sm text-gray-500">{currentRN}</div>
|
||||
<p className="text-[10px] text-gray-700 group-hover:text-gray-500 transition-colors">tap for voicings</p>
|
||||
</button>
|
||||
) : (
|
||||
<p className="text-gray-600 text-xs text-center">Play a chord</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { getSuggestedProgressions, getChordsInKey, toRomanNumeral, NOTES, NOTES_FLAT } from '../lib/theory'
|
||||
|
||||
// ─── Mood map ─────────────────────────────────────────────────────────────────
|
||||
const MOOD = {
|
||||
'I': 'Resolved', 'i': 'Settled',
|
||||
'II': 'Lifted', 'ii': 'Yearning',
|
||||
'III': 'Hopeful', 'iii': 'Tender',
|
||||
'IV': 'Uplifting', 'iv': 'Longing',
|
||||
'V': 'Tense', 'v': 'Unsettled',
|
||||
'VI': 'Bright', 'vi': 'Melancholic',
|
||||
'VII': 'Driving', 'vii': 'Uneasy',
|
||||
'♭VII': 'Bluesy', 'bVII': 'Bluesy',
|
||||
'♭VI': 'Dramatic', 'bVI': 'Dramatic',
|
||||
'♭III': 'Epic', '♭II': 'Mysterious',
|
||||
}
|
||||
|
||||
function getMood(rn) {
|
||||
return MOOD[rn] ?? MOOD[rn?.replace(/[0-9]/g, '')] ?? 'Adventurous'
|
||||
}
|
||||
|
||||
// ─── Genre accent colors ──────────────────────────────────────────────────────
|
||||
const GENRE_COLOR = {
|
||||
'Pop': 'text-pink-400',
|
||||
'Blues': 'text-blue-400',
|
||||
'Folk': 'text-green-400',
|
||||
'Jazz': 'text-yellow-400',
|
||||
'Rock': 'text-red-400',
|
||||
"'50s": 'text-orange-400',
|
||||
'Flamenco': 'text-rose-400',
|
||||
'Circle ↑': 'text-cyan-400',
|
||||
'Circle ↓': 'text-teal-400',
|
||||
'Relative': 'text-violet-400',
|
||||
'Thirds': 'text-indigo-400',
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
function noteIndex(note) {
|
||||
const i = NOTES.indexOf(note)
|
||||
return i >= 0 ? i : NOTES_FLAT.indexOf(note)
|
||||
}
|
||||
|
||||
function chordRoot(chord) {
|
||||
const m = chord.match(/^([A-G][b#]?)/)
|
||||
return m ? m[1] : null
|
||||
}
|
||||
|
||||
// ─── Circle-of-fifths padding ─────────────────────────────────────────────────
|
||||
// Moves tried in order to fill up to 6 total suggestions:
|
||||
// +7 perfect 5th up (dominant direction — most common resolution)
|
||||
// +5 perfect 4th up (subdominant direction)
|
||||
// +9 major/minor 6th (relative minor/major feel)
|
||||
// +3 minor 3rd up (mediant movement, dark → light)
|
||||
const COF_MOVES = [
|
||||
{ semitones: 7, genre: 'Circle ↑' },
|
||||
{ semitones: 5, genre: 'Circle ↓' },
|
||||
{ semitones: 9, genre: 'Relative' },
|
||||
{ semitones: 3, genre: 'Thirds' },
|
||||
]
|
||||
|
||||
function cofSuggestions(currentChord, root, mode, exclude) {
|
||||
const rootPc = noteIndex(chordRoot(currentChord) ?? '')
|
||||
if (rootPc < 0) return []
|
||||
|
||||
const diatonic = getChordsInKey(root, mode)
|
||||
const results = []
|
||||
|
||||
for (const { semitones, genre } of COF_MOVES) {
|
||||
const targetPc = ((rootPc + semitones) % 12 + 12) % 12
|
||||
const match = diatonic.find(c => {
|
||||
const r = chordRoot(c)
|
||||
return r !== null && noteIndex(r) === targetPc
|
||||
})
|
||||
if (!match || exclude.has(match)) continue
|
||||
const rn = toRomanNumeral(match, root, mode)
|
||||
results.push({ genre, chord: match, rn, mood: getMood(rn) })
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// ─── Main suggestion builder ──────────────────────────────────────────────────
|
||||
function buildSuggestions(currentChord, root, mode) {
|
||||
if (!currentChord || !root) return []
|
||||
|
||||
const genreSuggestions = getSuggestedProgressions(root, mode)
|
||||
.map(prog => {
|
||||
const idx = prog.chords.indexOf(currentChord)
|
||||
if (idx < 0) return null
|
||||
const next = (n) => prog.chords[(idx + n) % prog.chords.length]
|
||||
const rnAt = (n) => prog.rn[(idx + n) % prog.chords.length]
|
||||
const c1 = next(1), c2 = next(2), c3 = next(3)
|
||||
const chord2 = c2 !== c1 ? c2 : null
|
||||
const chord3 = chord2 && c3 !== c2 && c3 !== c1 ? c3 : null
|
||||
return {
|
||||
genre: prog.genre,
|
||||
chord: c1, rn: rnAt(1), mood: getMood(rnAt(1)),
|
||||
chord2, rn2: chord2 ? rnAt(2) : null, mood2: chord2 ? getMood(rnAt(2)) : null,
|
||||
chord3, rn3: chord3 ? rnAt(3) : null, mood3: chord3 ? getMood(rnAt(3)) : null,
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
|
||||
if (genreSuggestions.length >= 4) return genreSuggestions.slice(0, 5)
|
||||
|
||||
// Pad with circle-of-fifths moves not already covered
|
||||
const used = new Set(genreSuggestions.map(s => s.chord))
|
||||
const padded = cofSuggestions(currentChord, root, mode, used)
|
||||
|
||||
return [...genreSuggestions, ...padded].slice(0, 5)
|
||||
}
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
export default function ProgressionSuggestions({ keyInfo, currentChord }) {
|
||||
const { root, mode } = keyInfo ?? {}
|
||||
const [suggestions, setSuggestions] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
setSuggestions(buildSuggestions(currentChord, root, mode))
|
||||
}, [currentChord, root, mode])
|
||||
|
||||
if (!root) return null
|
||||
|
||||
return (
|
||||
<div className="bg-panel border border-border rounded-2xl p-3 flex flex-col h-full gap-1.5 overflow-hidden">
|
||||
|
||||
<p className="text-xs text-gray-500 uppercase tracking-widest shrink-0">
|
||||
Suggested Progression
|
||||
</p>
|
||||
|
||||
{!currentChord || suggestions.length === 0 ? (
|
||||
<div className="flex-1 flex items-center justify-center">
|
||||
<p className="text-gray-600 text-sm text-center">
|
||||
{currentChord ? 'No suggestions' : 'Play a chord…'}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex-1 flex flex-col justify-start gap-1 overflow-y-auto min-h-0">
|
||||
{suggestions.map((s, i) => (
|
||||
<div
|
||||
key={`${s.genre}-${i}`}
|
||||
className="flex items-center gap-2 px-2.5 py-1.5 rounded-xl border border-border bg-surface/40 hover:border-gray-600 transition-colors duration-200"
|
||||
>
|
||||
<span className={`text-xs font-bold w-12 shrink-0 ${GENRE_COLOR[s.genre] ?? 'text-gray-400'}`}>
|
||||
{s.genre}
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-lg font-black text-white leading-none">{s.chord}</div>
|
||||
<div className="flex items-center gap-1 mt-0.5">
|
||||
<span className="text-xs font-semibold text-amber-400">{s.rn}</span>
|
||||
<span className="text-gray-700 text-xs">·</span>
|
||||
<span className="text-xs text-gray-500 truncate">{s.mood}</span>
|
||||
</div>
|
||||
</div>
|
||||
{s.chord2 && (
|
||||
<>
|
||||
<span className="text-gray-600 text-xs shrink-0">|</span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-lg font-black text-white/70 leading-none">{s.chord2}</div>
|
||||
<div className="flex items-center gap-1 mt-0.5">
|
||||
<span className="text-xs font-semibold text-amber-400/70">{s.rn2}</span>
|
||||
<span className="text-gray-700 text-xs">·</span>
|
||||
<span className="text-xs text-gray-500 truncate">{s.mood2}</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{s.chord3 && (
|
||||
<>
|
||||
<span className="text-gray-600 text-xs shrink-0">|</span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-lg font-black text-white/50 leading-none">{s.chord3}</div>
|
||||
<div className="flex items-center gap-1 mt-0.5">
|
||||
<span className="text-xs font-semibold text-amber-400/50">{s.rn3}</span>
|
||||
<span className="text-gray-700 text-xs">·</span>
|
||||
<span className="text-xs text-gray-500 truncate">{s.mood3}</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// ─── Mini fretboard scale diagram ─────────────────────────────────────────────
|
||||
// Shows a 6-string × 5-fret window of scale tones.
|
||||
// Root notes → purple fill. Scale tones → dark grey fill.
|
||||
// Strings: top = s6 (low E), bottom = s1 (high e).
|
||||
// Window starts at the root fret on string 6.
|
||||
|
||||
const OPEN_PITCHES = [4, 9, 2, 7, 11, 4] // E A D G B e (s6 … s1)
|
||||
const FRETS = 5
|
||||
|
||||
export default function RiffDiagram({ rootPc, scaleIntervals = [0, 3, 5, 7, 10] }) {
|
||||
if (rootPc === undefined || rootPc === null) return null
|
||||
|
||||
// Fret window starts where the root lands on s6 (low E)
|
||||
const startFret = (rootPc - OPEN_PITCHES[0] + 12) % 12
|
||||
|
||||
// Which pitch classes are in the scale?
|
||||
const scaleSet = new Set(scaleIntervals.map(i => (rootPc + i) % 12))
|
||||
|
||||
// Collect dots: { s (0=s6…5=s1), f (0-4 within window), isRoot }
|
||||
const dots = []
|
||||
for (let s = 0; s < 6; s++) {
|
||||
for (let f = 0; f < FRETS; f++) {
|
||||
const pc = (OPEN_PITCHES[s] + startFret + f) % 12
|
||||
if (scaleSet.has(pc)) {
|
||||
dots.push({ s, f, isRoot: pc === rootPc })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SVG layout
|
||||
const W = 152, H = 70
|
||||
const mL = 6, mT = 14, mR = 6, mB = 4
|
||||
const innerW = W - mL - mR // 140
|
||||
const innerH = H - mT - mB // 52
|
||||
|
||||
const cellW = innerW / FRETS // 28
|
||||
const strGap = innerH / 5 // gap between 6 strings (5 gaps)
|
||||
|
||||
const sx = (f) => mL + f * cellW // left edge of fret cell
|
||||
const cx = (f) => mL + (f + 0.5) * cellW // centre of fret cell
|
||||
const sy = (s) => mT + s * strGap // y of string s
|
||||
|
||||
return (
|
||||
<svg width={W} height={H} className="shrink-0 overflow-visible">
|
||||
{/* Fret separators (vertical lines) */}
|
||||
{Array.from({ length: FRETS + 1 }, (_, f) => (
|
||||
<line key={f}
|
||||
x1={sx(f)} y1={mT - 2}
|
||||
x2={sx(f)} y2={H - mB}
|
||||
stroke={f === 0 ? '#555' : '#2a2a2a'}
|
||||
strokeWidth={f === 0 ? 2 : 1}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* String lines (horizontal) */}
|
||||
{Array.from({ length: 6 }, (_, s) => (
|
||||
<line key={s}
|
||||
x1={mL} y1={sy(s)}
|
||||
x2={W - mR} y2={sy(s)}
|
||||
stroke="#3a3a3a"
|
||||
strokeWidth={s === 0 ? 1.5 : 1}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Fret numbers above */}
|
||||
{Array.from({ length: FRETS }, (_, f) => (
|
||||
<text key={f}
|
||||
x={cx(f)} y={9}
|
||||
textAnchor="middle" fontSize={8}
|
||||
fill={f === 0 && startFret > 0 ? '#a855f7' : '#555'}
|
||||
fontWeight={f === 0 && startFret > 0 ? 'bold' : 'normal'}>
|
||||
{startFret + f === 0 ? 'O' : startFret + f}
|
||||
</text>
|
||||
))}
|
||||
|
||||
{/* Scale dots */}
|
||||
{dots.map((d, i) => (
|
||||
<circle key={i}
|
||||
cx={cx(d.f)} cy={sy(d.s)}
|
||||
r={4.5}
|
||||
fill={d.isRoot ? '#a855f7' : '#3d3d3d'}
|
||||
stroke={d.isRoot ? '#c084fc' : '#606060'}
|
||||
strokeWidth={1}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Root labels */}
|
||||
{dots.filter(d => d.isRoot).map((d, i) => (
|
||||
<text key={i}
|
||||
x={cx(d.f)} y={sy(d.s) + 3.5}
|
||||
textAnchor="middle" fontSize={6}
|
||||
fill="white" fontWeight="bold">
|
||||
R
|
||||
</text>
|
||||
))}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,339 @@
|
||||
import { NOTES, CHORD_TYPES, guideTones, voiceLeadingPairs, soloScale } from '../lib/theory'
|
||||
|
||||
// ─── RoadmapTrack (D-01) ──────────────────────────────────────────────────────
|
||||
//
|
||||
// The heart of the "Roadmap" Jam Guide concept (docs/design/jam-guide-concept-c.md):
|
||||
// the live loop rendered as a horizontal improv highway. Each KB progression
|
||||
// station carries a chord name + Roman numeral + solo-scale label, a guide-tone
|
||||
// lane (3rd/7th dots), and voice-leading rails drawn *between* adjacent stations
|
||||
// (the 7→3 falls-a-half-step thread). A playhead + beat grid sit underneath; the
|
||||
// station at `position` is "now", the next gets a subtle lookahead glow.
|
||||
//
|
||||
// Pure / presentational: no audio, no data fetching. Everything derives from
|
||||
// props + theory.js. Default-exported. Luthier (D-02) wires it into JamGuide.jsx.
|
||||
//
|
||||
// Prop contract (honoured exactly — other agents build against it):
|
||||
// progression KB progression object { id, name, rn, degrees, qualities, bars, mode, ... }
|
||||
// keyRoot tonic pitch class 0–11
|
||||
// keyMode 'major' | 'minor'
|
||||
// position index of the current station (playhead); -1 if none
|
||||
// bpm optional, for the beat grid; tolerate undefined
|
||||
|
||||
// Pitch class → note name. Sharps via NOTES (the app's canonical spelling, and
|
||||
// what Fretboard.jsx uses); kept to one source so the roadmap matches the neck.
|
||||
const pcName = pc => NOTES[((pc % 12) + 12) % 12]
|
||||
|
||||
// Build the full display chord name from a pitch class + a CHORD_TYPES quality
|
||||
// key (e.g. 7 + 'dom7' → "G7", 2 + 'min7' → "Dm7"). Falls back to a bare major
|
||||
// triad spelling if the quality is unknown, so the panel never renders blank.
|
||||
const chordName = (rootPc, quality) =>
|
||||
pcName(rootPc) + (CHORD_TYPES[quality]?.suffix ?? '')
|
||||
|
||||
// A readable mode word for the SCALE lane: theory.js returns snake_case names
|
||||
// ('phrygian_dominant'); the design wants "G mixolydian".
|
||||
const prettyScale = (rootPc, quality, keyMode) => {
|
||||
const { name } = soloScale(quality, keyMode)
|
||||
return `${pcName(rootPc)} ${name.replace(/_/g, ' ')}`
|
||||
}
|
||||
|
||||
// ─── Layout constants (px in the SVG-free flex layout) ────────────────────────
|
||||
const STATION_MIN_W = 168 // each station's min width; loops longer than the
|
||||
// viewport scroll horizontally (12-bar blues etc.)
|
||||
const RAIL_W = 34 // width of the gap a voice-leading rail bridges
|
||||
const RAIL_H = 40 // rail SVG height
|
||||
|
||||
// Render the small arrow rail between two stations. `pair` is one entry from
|
||||
// voiceLeadingPairs: { from, to, semitones }. We emphasise the half-step motion
|
||||
// — a 0-semitone move is a held common tone ("holds"), ±1 a half-step, ±2 a
|
||||
// whole step. Drawn in accent purple to match the guide-tone dots it connects.
|
||||
function Rail({ pair }) {
|
||||
if (!pair) return null
|
||||
const { from, to, semitones } = pair
|
||||
const held = semitones === 0
|
||||
const dir = semitones < 0 ? 'down' : semitones > 0 ? 'up' : 'hold'
|
||||
const label = held
|
||||
? `${pcName(from)} holds`
|
||||
: `${pcName(from)}→${pcName(to)}` // C→B
|
||||
const motion = held
|
||||
? 'common tone'
|
||||
: `${Math.abs(semitones) === 1 ? '½' : Math.abs(semitones)} step ${dir === 'down' ? 'down' : 'up'}`
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex shrink-0 flex-col items-center justify-center select-none"
|
||||
style={{ width: RAIL_W }}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<svg width={RAIL_W} height={RAIL_H} viewBox={`0 0 ${RAIL_W} ${RAIL_H}`}>
|
||||
{/* the rail line */}
|
||||
<line
|
||||
x1={2} y1={RAIL_H / 2} x2={RAIL_W - 8} y2={RAIL_H / 2}
|
||||
stroke="#a855f7" strokeWidth={held ? 1.5 : 2}
|
||||
strokeDasharray={held ? '3 3' : undefined}
|
||||
/>
|
||||
{/* arrowhead (omitted for a held common tone) */}
|
||||
{!held && (
|
||||
<path
|
||||
d={`M ${RAIL_W - 8} ${RAIL_H / 2 - 4} L ${RAIL_W - 2} ${RAIL_H / 2} L ${RAIL_W - 8} ${RAIL_H / 2 + 4} Z`}
|
||||
fill="#a855f7"
|
||||
/>
|
||||
)}
|
||||
</svg>
|
||||
<span className="mt-0.5 text-[10px] font-semibold leading-none text-accent">{label}</span>
|
||||
<span className="text-[9px] leading-tight text-gray-400">{motion}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// A single guide-tone dot with its honest label. `kind` is '3rd' / '7th' / '5th'.
|
||||
function GuideDot({ pc, kind, filled }) {
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-0.5">
|
||||
<span
|
||||
className="flex h-6 w-6 items-center justify-center rounded-full text-[10px] font-bold"
|
||||
style={
|
||||
filled
|
||||
? { backgroundColor: '#a855f7', color: '#fff' } // 3rd: solid accent
|
||||
: { border: '2px solid #a855f7', color: '#d8b4fe' } // 7th: hollow accent
|
||||
}
|
||||
>
|
||||
{pcName(pc)}
|
||||
</span>
|
||||
<span className="text-[9px] font-medium uppercase tracking-wide text-gray-400">{kind}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// A single station on the highway.
|
||||
function Station({
|
||||
index, rootPc, quality, rn, scaleLabel, isNow, isNext, width,
|
||||
}) {
|
||||
const g = guideTones(rootPc, quality)
|
||||
// hasSeventh:false → label the fallback honestly ("5th"), never call a 5th a 7th.
|
||||
const seventhKind = g.hasSeventh ? '7th' : '5th'
|
||||
|
||||
// Tier the dimming exactly like ProgressionBanner: "now" is full accent, the
|
||||
// lookahead "next" is a softer glow, everything else recedes — but never below
|
||||
// a legibility floor (AA contrast on bg-panel).
|
||||
const stateClass = isNow
|
||||
? 'border-accent bg-accent/10 ring-2 ring-accent'
|
||||
: isNext
|
||||
? 'border-accent/50 bg-accent/5'
|
||||
: 'border-border bg-surface'
|
||||
const opacity = isNow ? 1 : isNext ? 0.92 : 0.7
|
||||
|
||||
return (
|
||||
<div
|
||||
role="listitem"
|
||||
tabIndex={0}
|
||||
aria-current={isNow ? 'true' : undefined}
|
||||
aria-label={
|
||||
`Station ${index + 1}: ${chordName(rootPc, quality)}, ${rn}, ` +
|
||||
`solo scale ${scaleLabel}, third ${pcName(g.third)}, ` +
|
||||
`${seventhKind} ${pcName(g.seventh)}${isNow ? ', now playing' : ''}${isNext ? ', up next' : ''}`
|
||||
}
|
||||
className={
|
||||
`flex shrink-0 flex-col gap-2 rounded-xl border p-3 outline-none transition ` +
|
||||
`focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-1 ` +
|
||||
`focus-visible:ring-offset-surface ${stateClass}`
|
||||
}
|
||||
style={{ minWidth: width, opacity }}
|
||||
>
|
||||
{/* Header: chord name + Roman numeral, with the lookahead flag */}
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-lg font-bold leading-none text-gray-100">
|
||||
{chordName(rootPc, quality)}
|
||||
</span>
|
||||
<span className="text-xs font-medium text-gray-400">{rn}</span>
|
||||
</div>
|
||||
{isNow && (
|
||||
<span className="rounded bg-accent px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wider text-white">
|
||||
now
|
||||
</span>
|
||||
)}
|
||||
{isNext && (
|
||||
<span className="rounded border border-accent/60 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-accent">
|
||||
next
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* SCALE lane: the scale to blow over (muted, per the design) */}
|
||||
<div className="text-xs text-gray-400">
|
||||
<span className="text-[9px] uppercase tracking-widest text-gray-500">solo </span>
|
||||
{scaleLabel}
|
||||
</div>
|
||||
|
||||
{/* TARGET lane: the 3rd & 7th guide-tone dots */}
|
||||
<div className="mt-1 flex items-start gap-4 border-t border-border pt-2">
|
||||
<span className="mt-1 text-[9px] uppercase tracking-widest text-gray-500">aim</span>
|
||||
<GuideDot pc={g.third} kind="3rd" filled />
|
||||
<GuideDot pc={g.seventh} kind={seventhKind} filled={false} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// The playhead + beat grid under the whole track. Total beats = Σ bars × 4.
|
||||
// The current beat is the start of the active station (coarse, chord-accurate —
|
||||
// matches ProgressionBanner; fine beat interpolation is a later D-02 polish).
|
||||
function BeatGrid({ bars, position, bpm }) {
|
||||
const beatsPerStation = bars.map(b => (b || 1) * 4)
|
||||
const totalBeats = beatsPerStation.reduce((s, n) => s + n, 0)
|
||||
// first beat index of each station
|
||||
const stationStart = []
|
||||
let acc = 0
|
||||
for (const n of beatsPerStation) { stationStart.push(acc); acc += n }
|
||||
const nowBeat = position >= 0 && position < stationStart.length ? stationStart[position] : -1
|
||||
const pct = nowBeat >= 0 && totalBeats > 0 ? (nowBeat + 0.5) / totalBeats : 0
|
||||
|
||||
return (
|
||||
<div className="mt-3">
|
||||
{/* playhead track */}
|
||||
<div
|
||||
className="relative h-1.5 w-full rounded-full bg-border"
|
||||
role="progressbar"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={totalBeats}
|
||||
aria-valuenow={Math.max(0, nowBeat)}
|
||||
aria-valuetext={
|
||||
nowBeat >= 0 ? `Beat ${nowBeat + 1} of ${totalBeats}` : 'Loop not playing'
|
||||
}
|
||||
>
|
||||
<div
|
||||
className="absolute top-0 h-1.5 rounded-full bg-accent/60"
|
||||
style={{ width: `${Math.max(0, pct * 100)}%` }}
|
||||
/>
|
||||
{nowBeat >= 0 && (
|
||||
<div
|
||||
className="absolute -top-1 h-3.5 w-3.5 -translate-x-1/2 rounded-full border-2 border-surface bg-accent"
|
||||
style={{ left: `${pct * 100}%` }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* beat cells */}
|
||||
<div className="mt-1 flex w-full gap-px" aria-hidden="true">
|
||||
{Array.from({ length: totalBeats }, (_, i) => {
|
||||
const isNow = i === nowBeat
|
||||
// downbeat (beat 1 of a bar) gets a brighter tick
|
||||
const isDownbeat = i % 4 === 0
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className="h-2 flex-1 rounded-sm"
|
||||
style={{
|
||||
backgroundColor: isNow ? '#a855f7' : isDownbeat ? '#2a2a2a' : '#1a1a1a',
|
||||
opacity: isNow ? 1 : isDownbeat ? 1 : 0.7,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{bpm ? (
|
||||
<p className="mt-1 text-right text-[10px] text-gray-500">~{Math.round(bpm)} BPM</p>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function RoadmapTrack({
|
||||
progression,
|
||||
keyRoot = 0,
|
||||
keyMode = 'major',
|
||||
position = -1,
|
||||
bpm,
|
||||
}) {
|
||||
// Tolerate a missing / malformed progression — the panel is never empty-crashed.
|
||||
if (!progression || !Array.isArray(progression.degrees) || progression.degrees.length === 0) {
|
||||
return (
|
||||
<div className="rounded-2xl border border-border bg-panel p-4 text-sm text-gray-500">
|
||||
No loop to map yet — play a progression.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const { degrees, qualities = [], rn = [], bars = [], name, id } = progression
|
||||
const n = degrees.length
|
||||
|
||||
// Resolve each station to an absolute chord in the current key.
|
||||
const stations = degrees.map((deg, i) => {
|
||||
const rootPc = (((keyRoot + deg) % 12) + 12) % 12
|
||||
const quality = qualities[i] ?? 'maj'
|
||||
return {
|
||||
rootPc,
|
||||
quality,
|
||||
rn: rn[i] ?? '',
|
||||
scaleLabel: prettyScale(rootPc, quality, keyMode),
|
||||
bars: bars[i] ?? 1,
|
||||
}
|
||||
})
|
||||
|
||||
// Voice-leading rails between adjacent stations, plus a wrap-around rail from
|
||||
// the last station back to the first (the loop is a wheel — a nice touch the
|
||||
// design calls for: "B holds → next loop"). Index i = rail leaving station i.
|
||||
const rails = stations.map((s, i) => {
|
||||
const next = stations[(i + 1) % n]
|
||||
return voiceLeadingPairs(
|
||||
{ root: s.rootPc, quality: s.quality },
|
||||
{ root: next.rootPc, quality: next.quality },
|
||||
)[0] ?? null // the headline rail is the 7→3 (voiceLeadingPairs lists 7th first)
|
||||
})
|
||||
|
||||
const nextPos = position >= 0 ? (position + 1) % n : -1
|
||||
|
||||
return (
|
||||
<section
|
||||
className="rounded-2xl border border-border bg-panel p-4"
|
||||
aria-label={`Roadmap for ${name ?? id ?? 'loop'}`}
|
||||
>
|
||||
{/* Header strip: loop name + station chord summary */}
|
||||
<header className="mb-3 flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<h3 className="text-sm font-semibold uppercase tracking-widest text-gray-300">
|
||||
{name ?? 'Loop'}
|
||||
</h3>
|
||||
<span className="text-xs text-gray-500">
|
||||
{stations.map(s => chordName(s.rootPc, s.quality)).join(' → ')}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
{/* The highway: stations interleaved with voice-leading rails. Scrolls
|
||||
horizontally when the loop is longer than the viewport. */}
|
||||
<div className="overflow-x-auto pb-1">
|
||||
<div role="list" aria-label="Loop stations" className="flex min-w-min items-stretch">
|
||||
{stations.map((s, i) => (
|
||||
<div key={i} className="flex items-center">
|
||||
<Station
|
||||
index={i}
|
||||
rootPc={s.rootPc}
|
||||
quality={s.quality}
|
||||
rn={s.rn}
|
||||
scaleLabel={s.scaleLabel}
|
||||
isNow={i === position}
|
||||
isNext={i === nextPos}
|
||||
width={STATION_MIN_W}
|
||||
/>
|
||||
{/* rail to the next station (inter-station rails only; the
|
||||
wrap-around rail is drawn separately after the last station) */}
|
||||
{i < n - 1 && <Rail pair={rails[i]} />}
|
||||
</div>
|
||||
))}
|
||||
{/* wrap-around rail back to station 1, rendered after the last station */}
|
||||
{n > 1 && (
|
||||
<div className="flex items-center" aria-hidden="true">
|
||||
<Rail pair={rails[n - 1]} />
|
||||
<span className="ml-0.5 text-[9px] uppercase tracking-wider text-gray-500">
|
||||
loop
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Playhead + beat grid */}
|
||||
<BeatGrid bars={stations.map(s => s.bars)} position={position} bpm={bpm} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import { useRef, useEffect, useState } from 'react'
|
||||
|
||||
const SETTINGS = [
|
||||
{
|
||||
section: 'Chord Detection',
|
||||
items: [
|
||||
{
|
||||
key: 'chromaSmooth',
|
||||
label: 'Chroma Smoothing',
|
||||
min: 1, max: 20, step: 1,
|
||||
desc: 'Frames to average for chord chroma. More = smoother but slower to react to chord changes.',
|
||||
},
|
||||
{
|
||||
key: 'chordVoteThreshold',
|
||||
label: 'Chord Vote Threshold',
|
||||
min: 1, max: 8, step: 1,
|
||||
desc: 'Consecutive identical detections required to confirm a chord. Higher = more stable, slower.',
|
||||
},
|
||||
{
|
||||
key: 'chordMinScore',
|
||||
label: 'Chord Min Score',
|
||||
min: 0.10, max: 0.80, step: 0.01,
|
||||
desc: 'Minimum coverage score to accept a chord match. Lower = more chord types detected (may add false positives).',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
section: 'Key Detection',
|
||||
items: [
|
||||
{
|
||||
key: 'noteHistorySize',
|
||||
label: 'Note History Size',
|
||||
min: 100, max: 12000, step: 100,
|
||||
desc: 'Pitch readings kept for key detection. ~2000 ≈ 1 min, 12000 ≈ whole session. Larger = more stable key.',
|
||||
},
|
||||
{
|
||||
key: 'keyVoteWindow',
|
||||
label: 'Key Vote Window',
|
||||
min: 4, max: 30, step: 1,
|
||||
desc: 'Rolling window of key votes. Larger = more inertia — key changes need sustained evidence.',
|
||||
},
|
||||
{
|
||||
key: 'keyVoteThreshold',
|
||||
label: 'Key Vote Threshold',
|
||||
min: 1, max: 30, step: 1,
|
||||
desc: 'Votes needed within the window to confirm a key. Higher = stricter consensus required.',
|
||||
},
|
||||
{
|
||||
key: 'chordNoteBoost',
|
||||
label: 'Chord Note Boost',
|
||||
min: 0, max: 10, step: 1,
|
||||
desc: 'Times confirmed chord tones are injected into note history. Higher = chords dominate over transient melody notes.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
section: 'Audio Input',
|
||||
items: [
|
||||
{
|
||||
key: 'minClarity',
|
||||
label: 'Min Pitch Clarity',
|
||||
min: 0.50, max: 0.99, step: 0.01,
|
||||
desc: 'Autocorrelation clarity threshold to accept a pitch reading. Higher = only clean, in-tune notes count.',
|
||||
},
|
||||
{
|
||||
key: 'minVolume',
|
||||
label: 'Min Volume (RMS)',
|
||||
min: 0.001, max: 0.05, step: 0.001,
|
||||
desc: 'Minimum signal level before processing. Increase to cut through room noise.',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default function Settings({ config, onChange, onClose, onReset, monoColor, onMonoColorChange }) {
|
||||
// Snapshot on mount so Cancel can restore
|
||||
const savedConfig = useRef(config)
|
||||
const savedMono = useRef(monoColor)
|
||||
|
||||
function handleCancel() {
|
||||
Object.entries(savedConfig.current).forEach(([k, v]) => onChange(k, v))
|
||||
onMonoColorChange(savedMono.current)
|
||||
onClose()
|
||||
}
|
||||
|
||||
function DeviceSelector({ config, onChange }) {
|
||||
const [devices, setDevices] = useState([])
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) return
|
||||
const list = await navigator.mediaDevices.enumerateDevices()
|
||||
setDevices(list.filter(d => d.kind === 'audioinput'))
|
||||
} catch (e) {
|
||||
console.warn('enumerateDevices failed', e)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => { refresh() }, [])
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-3 items-center">
|
||||
<select
|
||||
value={config.audioDeviceId ?? ''}
|
||||
onChange={e => onChange('audioDeviceId', e.target.value === '' ? null : e.target.value)}
|
||||
className="appearance-none bg-surface border border-border hover:border-gray-500 focus:border-accent focus:outline-none rounded-lg pl-3 pr-7 py-1 text-sm text-gray-200 cursor-pointer transition-colors w-full"
|
||||
>
|
||||
<option value="">System default</option>
|
||||
{devices.map((d, i) => (
|
||||
<option key={d.deviceId || i} value={d.deviceId}>{d.label || `Microphone ${i + 1}`}</option>
|
||||
))}
|
||||
</select>
|
||||
<button onClick={refresh} className="px-3 py-1 rounded-lg border border-border text-sm text-gray-400">Refresh</button>
|
||||
</div>
|
||||
<div className="text-xs text-gray-600">If device labels are empty, grant microphone permission first and hit Refresh.</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-surface z-50 overflow-y-auto">
|
||||
<div className="max-w-2xl mx-auto px-6 py-8">
|
||||
|
||||
<div className="flex items-center justify-between mb-8">
|
||||
<div>
|
||||
<h2 className="text-xl font-bold text-accent">Detection Settings</h2>
|
||||
<p className="text-xs text-gray-500 mt-0.5">Tune chord and key recognition sensitivity in real time</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={onReset}
|
||||
className="px-4 py-2 rounded-lg text-sm border border-border text-gray-500 hover:text-gray-300 hover:border-gray-400 transition-all"
|
||||
>
|
||||
Reset defaults
|
||||
</button>
|
||||
<button
|
||||
onClick={handleCancel}
|
||||
className="px-4 py-2 rounded-lg text-sm border border-border text-gray-500 hover:text-gray-300 hover:border-gray-400 transition-all"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="px-5 py-2 rounded-lg text-sm bg-accent hover:bg-purple-600 text-white font-semibold transition-all"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-8">
|
||||
|
||||
{/* ── Display ── */}
|
||||
<div>
|
||||
<h3 className="text-xs uppercase tracking-widest text-gray-500 mb-4 border-b border-border pb-2">
|
||||
Display
|
||||
</h3>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-gray-200">Mono Color Mode</p>
|
||||
<p className="text-xs text-gray-600 mt-0.5">Use a single purple palette instead of purple + amber for note tiers.</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => onMonoColorChange(v => !v)}
|
||||
className={`relative w-11 h-6 rounded-full transition-colors ${monoColor ? 'bg-accent' : 'bg-gray-700'}`}
|
||||
>
|
||||
<span className={`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white shadow transition-transform ${monoColor ? 'translate-x-5' : 'translate-x-0'}`} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{SETTINGS.map(section => (
|
||||
<div key={section.section}>
|
||||
<h3 className="text-xs uppercase tracking-widest text-gray-500 mb-4 border-b border-border pb-2">
|
||||
{section.section}
|
||||
</h3>
|
||||
<div className="space-y-6">
|
||||
{section.items.map(item => (
|
||||
<div key={item.key}>
|
||||
<div className="flex items-baseline justify-between mb-1.5">
|
||||
<label className="text-sm font-semibold text-gray-200">{item.label}</label>
|
||||
<span className="text-sm font-mono text-accent w-20 text-right">
|
||||
{Number.isInteger(config[item.key])
|
||||
? config[item.key]
|
||||
: config[item.key].toFixed(item.step < 0.01 ? 3 : 2)}
|
||||
</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
min={item.min}
|
||||
max={item.max}
|
||||
step={item.step}
|
||||
value={config[item.key]}
|
||||
onChange={e => {
|
||||
const val = item.step < 1
|
||||
? parseFloat(e.target.value)
|
||||
: parseInt(e.target.value, 10)
|
||||
onChange(item.key, val)
|
||||
}}
|
||||
className="w-full accent-purple-500"
|
||||
/>
|
||||
<div className="flex justify-between text-xs text-gray-700 mt-0.5">
|
||||
<span>{item.min}</span>
|
||||
<span className="text-gray-600 text-center flex-1 px-2">{item.desc}</span>
|
||||
<span>{item.max}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Audio device selector */}
|
||||
<div>
|
||||
<h3 className="text-xs uppercase tracking-widest text-gray-500 mb-4 border-b border-border pb-2">
|
||||
Microphone
|
||||
</h3>
|
||||
<DeviceSelector config={config} onChange={onChange} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useAudioTuner } from '../services/audioService'
|
||||
|
||||
// Tuner UI uses pitch data from `useAudioTuner` (autocorrelation handled in the hook)
|
||||
|
||||
export default function Tuner() {
|
||||
const { pitchData, isListening, startListening, stopListening } = useAudioTuner()
|
||||
const [octaveShift, setOctaveShift] = useState(0)
|
||||
const canvasRef = useRef(null)
|
||||
const historyRef = useRef([])
|
||||
|
||||
// smoothing for display to reduce jitter
|
||||
const smoothedRef = useRef({ cents: 0, freq: 0 })
|
||||
const [display, setDisplay] = useState({ cents: 0, freq: 0 })
|
||||
const SMOOTH_ALPHA = 0.25
|
||||
|
||||
// wire pitchData -> smoothing and history
|
||||
useEffect(() => {
|
||||
const newFreq = pitchData?.freq || 0
|
||||
const newCents = pitchData?.cents || 0
|
||||
const prev = smoothedRef.current
|
||||
const sf = prev.freq + (newFreq - prev.freq) * SMOOTH_ALPHA
|
||||
const sc = prev.cents + (newCents - prev.cents) * SMOOTH_ALPHA
|
||||
smoothedRef.current = { freq: sf, cents: sc }
|
||||
setDisplay({ freq: Math.round(sf), cents: Math.round(sc) })
|
||||
|
||||
if (isListening && pitchData) {
|
||||
historyRef.current.push(pitchData.cents)
|
||||
if (historyRef.current.length > 120) historyRef.current.shift()
|
||||
} else if (!isListening) {
|
||||
historyRef.current = []
|
||||
}
|
||||
}, [pitchData, isListening])
|
||||
|
||||
// Draw the scrolling graph on the canvas
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas) return
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return
|
||||
|
||||
let rafId
|
||||
|
||||
function resizeCanvas() {
|
||||
const dpr = window.devicePixelRatio || 1
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
canvas.width = Math.floor(rect.width * dpr)
|
||||
canvas.height = Math.floor(rect.height * dpr)
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
||||
}
|
||||
|
||||
resizeCanvas()
|
||||
window.addEventListener('resize', resizeCanvas)
|
||||
|
||||
const draw = () => {
|
||||
const { width, height } = canvas
|
||||
// clear (canvas uses device pixels but ctx scaled)
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
||||
|
||||
// logical width/height in CSS pixels
|
||||
const w = canvas.width / (window.devicePixelRatio || 1)
|
||||
const h = canvas.height / (window.devicePixelRatio || 1)
|
||||
|
||||
// Draw background bands (center green, sides red)
|
||||
ctx.fillStyle = 'rgba(16,185,129,0.12)'
|
||||
ctx.fillRect(w * 0.4, 0, w * 0.2, h)
|
||||
ctx.fillStyle = 'rgba(16,185,129,0.28)'
|
||||
ctx.fillRect(w * 0.48, 0, w * 0.04, h)
|
||||
|
||||
ctx.fillStyle = 'rgba(239,68,68,0.12)'
|
||||
ctx.fillRect(0, 0, w * 0.4, h)
|
||||
ctx.fillRect(w * 0.6, 0, w * 0.4, h)
|
||||
|
||||
const history = historyRef.current
|
||||
if (history.length > 1) {
|
||||
ctx.beginPath()
|
||||
ctx.strokeStyle = 'white'
|
||||
ctx.lineWidth = 2
|
||||
ctx.lineJoin = 'round'
|
||||
|
||||
const step = h / (history.length - 1)
|
||||
history.forEach((cents, i) => {
|
||||
const x = (w / 2) + (cents * (w / 100))
|
||||
const y = h - (i * step)
|
||||
if (i === 0) ctx.moveTo(x, y)
|
||||
else ctx.lineTo(x, y)
|
||||
})
|
||||
ctx.stroke()
|
||||
|
||||
const last = history[history.length - 1]
|
||||
const currentX = (w / 2) + (last * (w / 100))
|
||||
ctx.beginPath()
|
||||
ctx.fillStyle = 'white'
|
||||
ctx.arc(currentX, h - 0, 4, 0, Math.PI * 2)
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(draw)
|
||||
}
|
||||
|
||||
draw()
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', resizeCanvas)
|
||||
cancelAnimationFrame(rafId)
|
||||
}
|
||||
}, [isListening])
|
||||
|
||||
|
||||
return (
|
||||
<div className="p-6 text-center">
|
||||
<div className="flex items-start justify-end mb-4">
|
||||
<button
|
||||
onClick={() => (isListening ? stopListening() : startListening())}
|
||||
className={`px-4 py-2 rounded-full text-sm font-semibold ${isListening ? 'bg-red-600' : 'bg-accent'}`}
|
||||
>
|
||||
{isListening ? 'Stop' : 'Start'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="w-full flex flex-col items-center">
|
||||
<div className="w-full max-w-3xl">
|
||||
<div className="flex items-center justify-between mb-3 px-6">
|
||||
<div className="text-left">
|
||||
<div className="text-2xl font-semibold">{display.freq || '—'}</div>
|
||||
<div className="text-xs text-gray-400">HERTZ</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-6xl font-bold tracking-tight">{pitchData ? `${pitchData.note}${pitchData.octave}` : '—'}</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-2xl font-semibold">{display.cents >= 0 ? `+${display.cents}` : display.cents}</div>
|
||||
<div className="text-xs text-gray-400">CENTS</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="relative bg-black/40 rounded-md overflow-hidden h-90 mb-3">
|
||||
<canvas ref={canvasRef} className="absolute inset-0 w-full h-full" />
|
||||
|
||||
<div className="absolute inset-y-0 left-1/2 transform -translate-x-1/2 w-1/6 pointer-events-none">
|
||||
<div className="absolute inset-0 bg-green-600/50 mx-auto w-full rounded"></div>
|
||||
</div>
|
||||
<div className="absolute inset-y-0 left-0 w-5/12 bg-red-600/20 pointer-events-none" />
|
||||
<div className="absolute inset-y-0 right-0 w-5/12 bg-red-600/20 pointer-events-none" />
|
||||
|
||||
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-0.5 h-24 bg-white/30 rounded" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
# KB Authoring Contract
|
||||
|
||||
Every knowledgebase cell must conform to this schema and pass `node scripts/validate-kb.mjs`. The gold-standard exemplar is `jazz/` — imitate it. Background and rationale: `docs/kb-plan.md`.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
src/data/kb/<style>/
|
||||
meta.js — style identity
|
||||
progressions.js — the style's standard progressions (instrument-independent)
|
||||
guitar.js — instrument packs (piano.js, bass.js as cells are completed)
|
||||
```
|
||||
|
||||
Register each style in `src/data/kb/index.js`. The UI reads only the registry.
|
||||
|
||||
## Hard rules
|
||||
|
||||
1. **Key-agnostic.** Degrees and movable shapes only — never absolute chord names in data. Open guitar shapes are the one exception (they declare `onlyRoot`, a pitch class, and render only in matching keys).
|
||||
2. **Qualities** must be keys of `CHORD_TYPES` in `src/lib/theory.js` (`maj`, `min`, `dom7`, `maj7`, `min7`, `dim`, `dim7`, `half_dim`, `aug`, `sus4`, `sus2`, `maj6`, `min6`, `add9`).
|
||||
3. **Intermediate level.** Guitar: fret span ≤ 4 within a shape. Piano: one hand per recipe stays within a 10th. If a play is harder, provide an easier alternative in the same play set.
|
||||
4. Plays for the same progression must be **idiomatically different** (register, density, technique) — not transpositions of each other.
|
||||
|
||||
## meta.js
|
||||
|
||||
```js
|
||||
export default {
|
||||
id: 'jazz', // folder name
|
||||
label: 'Jazz',
|
||||
feel: 'swing', // swing | straight | shuffle | 16th | bossa…
|
||||
tempoRange: [110, 230],
|
||||
character: 'One sentence on what makes the style sound like itself.',
|
||||
}
|
||||
```
|
||||
|
||||
## progressions.js
|
||||
|
||||
```js
|
||||
export default [
|
||||
{
|
||||
id: 'jazz-251-major', // '<style>-<slug>', globally unique
|
||||
name: 'ii–V–I',
|
||||
rn: ['ii7', 'V7', 'Imaj7'], // display numerals
|
||||
degrees: [2, 7, 0], // semitone offsets from key root, 0–11
|
||||
qualities: ['min7', 'dom7', 'maj7'],
|
||||
bars: [1, 1, 2], // same length as degrees
|
||||
mode: 'major', // major | minor | dorian | mixolydian | …
|
||||
songs: ['Autumn Leaves'],
|
||||
tip: 'One transferable idea.',
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
4–8 progressions per style. Cross-check `docs/progression-repertoire.md` §1.
|
||||
|
||||
## Instrument packs
|
||||
|
||||
Common envelope:
|
||||
|
||||
```js
|
||||
export default {
|
||||
styleIntro: '2-3 sentences on this instrument's role in the style.',
|
||||
comping: [{ label, rhythm, description }], // ≥1 named rhythm
|
||||
plays: { '<progression-id>': [ <play>, <play> ] }, // ≥2 plays per progression
|
||||
improv: { // guitar/piano; optional for bass
|
||||
scales: [{ over: 'ii7', scale: 'dorian', why }],
|
||||
targetNotes: '…',
|
||||
licks: [{ tab/notation, description, over: '<progression-id>', source }],
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Guitar play
|
||||
|
||||
```js
|
||||
{
|
||||
label: 'Shell voicings',
|
||||
level: 'intermediate',
|
||||
chords: [ // one per progression step
|
||||
{
|
||||
shape: {
|
||||
// movable: fret offsets relative to the root fret; 'x' = muted
|
||||
rootStr: 6, // string carrying the root, 6 = low E
|
||||
offsets: [0, 'x', 0, 0, 'x', 'x'], // ALWAYS 6 entries, low E first
|
||||
fingers: [1, 0, 2, 3, 0, 0],
|
||||
// open shapes instead use: frets: [...absolute], onlyRoot: <pc 0-11>
|
||||
},
|
||||
extensions: ['9'], // declared color tones beyond the quality (validator allows only these)
|
||||
// declared omissions (honest data, surfaced by the UI):
|
||||
// rootless: true — shape omits the root (e.g. guide-tone grips)
|
||||
// omit3: true — shape omits the 3rd (e.g. power chords; works over major or minor)
|
||||
note: 'root–♭7–♭3',
|
||||
},
|
||||
// …
|
||||
],
|
||||
tips: 'Voice-leading or ensemble advice.',
|
||||
}
|
||||
```
|
||||
|
||||
### Piano play
|
||||
|
||||
Voicings are degree recipes resolved through the chord quality. Degrees: `'1' '3' '5' '7'` resolve per quality (e.g. `'3'` → ♭3 for min7); altered/extended degrees are explicit: `'b9' '9' '#9' '11' '#11' 'b13' '13' '6'`.
|
||||
|
||||
```js
|
||||
{
|
||||
label: 'Rootless A/B alternation',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ recipe: { LH: ['3', '5', '7', '9'] }, note: 'Type A' },
|
||||
{ recipe: { LH: ['7', '9', '3', '13'] }, note: 'Type B' },
|
||||
],
|
||||
register: 'top note between C4 and C5',
|
||||
tips: '…',
|
||||
}
|
||||
```
|
||||
|
||||
### Bass play
|
||||
|
||||
```js
|
||||
{
|
||||
label: 'Walking, chromatic approach',
|
||||
level: 'intermediate',
|
||||
bars: [{ beats: ['R', '3', '5', 'chrom>'] }], // per bar of the progression
|
||||
// beat tokens: R 3 5 7 (chord degrees) · 'chrom>' / 'chrom<' (chromatic into next root
|
||||
// from below/above) · '5>' (dominant approach) · 'x' (ghost) · '-' (hold)
|
||||
tips: '…',
|
||||
}
|
||||
```
|
||||
|
||||
## Musician checklist (self-review before committing)
|
||||
|
||||
- [ ] Plays per progression genuinely differ in register/density/technique
|
||||
- [ ] Every shape/recipe is playable by intermediate hands (rule 3)
|
||||
- [ ] The style is recognizable from the rhythm descriptions alone (bossa ≠ jazz with new labels)
|
||||
- [ ] Every tip teaches a transferable idea (voice leading, register, space), not just "play this"
|
||||
- [ ] Songs/licks have sources; nothing invented
|
||||
- [ ] `node scripts/validate-kb.mjs` green; `npm run build` green
|
||||
@@ -0,0 +1,233 @@
|
||||
// Blues guitar pack. Shapes verified by note-spelling against: guitarworld.com
|
||||
// (13th chords, Jimmy Reed rhythm), fundamental-changes.com (SRV/Freddie King 9ths,
|
||||
// turnarounds), truefire.com (Texas comping, chord-tone targeting), jazzguitar.be
|
||||
// (tritone shells), guitarplayer.com (B.B. box, turnarounds).
|
||||
|
||||
// Big barre grips — full-band downbeat hits.
|
||||
const E_BARRE7 = { rootStr: 6, offsets: [0, 2, 0, 1, 0, 0], fingers: [1, 3, 1, 2, 1, 1] } // R-5-♭7-3-5-R
|
||||
const A_BARRE7 = { rootStr: 5, offsets: ['x', 0, 2, 0, 2, 0], fingers: [0, 1, 3, 1, 4, 1] } // R-5-♭7-3-5
|
||||
const MIN7_BARRE_6 = { rootStr: 6, offsets: [0, 2, 0, 0, 0, 0], fingers: [1, 3, 1, 1, 1, 1] } // Em-shape m7
|
||||
const MIN7_BARRE_5 = { rootStr: 5, offsets: ['x', 0, 2, 0, 1, 0], fingers: [0, 1, 3, 1, 2, 1] } // Am-shape m7
|
||||
|
||||
// The blues colour chords — root on the A string.
|
||||
const NINTH = { rootStr: 5, offsets: ['x', 0, -1, 0, 0, 0], fingers: [0, 2, 1, 3, 3, 3] } // R-3-♭7-9-5
|
||||
const THIRTEEN = { rootStr: 5, offsets: ['x', 0, -1, 0, 0, 2], fingers: [0, 2, 1, 3, 3, 4] } // R-3-♭7-9-13
|
||||
const THIRTEEN_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, 2, 'x'], fingers: [1, 0, 2, 3, 4, 0] } // R-♭7-3-13 (T-Bone register)
|
||||
const HENDRIX = { rootStr: 5, offsets: ['x', 0, -1, 0, 1, 'x'], fingers: [0, 2, 1, 3, 4, 0] } // 7#9 — ♭3 vs 3 in one grip
|
||||
|
||||
// Two-note-tritone shells — the Chicago comping grips.
|
||||
const SHELL7_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, 'x', 'x'], fingers: [1, 0, 2, 3, 0, 0] } // R-♭7-3
|
||||
const SHELL7_5 = { rootStr: 5, offsets: ['x', 0, 'x', 0, 2, 'x'], fingers: [0, 1, 0, 2, 4, 0] } // R-♭7-3
|
||||
const SHELL_M7_5 = { rootStr: 5, offsets: ['x', 0, -2, 0, 'x', 'x'], fingers: [0, 3, 1, 4, 0, 0] } // R-♭3-♭7
|
||||
|
||||
export default {
|
||||
styleIntro:
|
||||
'Blues rhythm guitar is a drum kit with pitch: the shuffle is the job, the chord is the decoration. Pick a lane — low boogie locked with the bass, or high 9th-chord stabs answering the vocal — and never both at once.',
|
||||
|
||||
comping: [
|
||||
{
|
||||
label: 'Jimmy Reed boogie shuffle',
|
||||
rhythm: 'swung 8ths: R+5 / R+6 alternating',
|
||||
description: 'Two-note dyads on the bottom strings, alternating the 5th and 6th above the root in swung eighths; move the same cell to the IV and V strings. Low register, dense — doubles the bass. The "second guitar" role Reed pioneered.',
|
||||
},
|
||||
{
|
||||
label: '9th-chord stabs (Texas / SRV)',
|
||||
rhythm: 'staccato hits, slide in from a half-step below',
|
||||
description: 'Short muted stabs of the 9th grip, approached from one fret under (B♭9→B9). Mid-high register, sparse — leaves the low end to the bass. The Freddie King "Hide Away" sound.',
|
||||
},
|
||||
{
|
||||
label: 'Slow blues 12/8',
|
||||
rhythm: 'rolled chords on a triplet grid',
|
||||
description: 'At ~60 BPM everything subdivides into triplets: arpeggiated 9ths, the 6↔9 rock on the top strings, fills answering the vocal. Density drops; space is the instrument.',
|
||||
},
|
||||
{
|
||||
label: 'Stormy Monday walk-up',
|
||||
rhythm: 'one chord per walking step, bars 7–8',
|
||||
description: 'Diatonic chord climb I7→ii7→iii7 then chromatic back down — a bassline played as chords. Canonical on the Allman Brothers\' At Fillmore East.',
|
||||
},
|
||||
],
|
||||
|
||||
plays: {
|
||||
'blues-12bar': [
|
||||
{
|
||||
label: 'Barre-chord shuffle',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: E_BARRE7, note: 'I7 — root on the 6th string' },
|
||||
{ shape: E_BARRE7, note: '' }, { shape: E_BARRE7, note: '' }, { shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'IV7 — same fret, root string up' },
|
||||
{ shape: A_BARRE7, note: '' },
|
||||
{ shape: E_BARRE7, note: '' }, { shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7 — two frets above the IV grip' },
|
||||
{ shape: A_BARRE7, note: 'IV7' },
|
||||
{ shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7 — push into the next chorus' },
|
||||
],
|
||||
tips: 'I, IV and V all live within two frets: 6th-string root, then 5th-string root at the same fret (IV) and two up (V). Strum short — the shuffle lives in the damping hand.',
|
||||
},
|
||||
{
|
||||
label: '9th-chord stabs (Texas)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: NINTH, extensions: ['9'], note: 'slide in from one fret below' },
|
||||
{ shape: NINTH, extensions: ['9'], note: '' }, { shape: NINTH, extensions: ['9'], note: '' }, { shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: NINTH, extensions: ['9'], note: 'IV9' }, { shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: NINTH, extensions: ['9'], note: '' }, { shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: 'V13 — pinky reaches the 13' },
|
||||
{ shape: NINTH, extensions: ['9'], note: 'IV9' },
|
||||
{ shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: 'V13' },
|
||||
],
|
||||
tips: 'Stab, mute, wait. The 13↔9 drop on the top string is a free melodic hook — comping that sounds like a horn section.',
|
||||
},
|
||||
],
|
||||
|
||||
'blues-quickchange': [
|
||||
{
|
||||
label: 'Tritone shells (Chicago)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: SHELL7_6, note: 'I7' },
|
||||
{ shape: SHELL7_5, note: 'quick IV — only the inner pair moves' },
|
||||
{ shape: SHELL7_6, note: '' }, { shape: SHELL7_6, note: '' },
|
||||
{ shape: SHELL7_5, note: '' }, { shape: SHELL7_5, note: '' },
|
||||
{ shape: SHELL7_6, note: '' }, { shape: SHELL7_6, note: '' },
|
||||
{ shape: SHELL7_5, note: 'V7' },
|
||||
{ shape: SHELL7_5, note: 'IV7' },
|
||||
{ shape: SHELL7_6, note: '' },
|
||||
{ shape: SHELL7_5, note: 'V7' },
|
||||
],
|
||||
tips: 'Three strings, two of them the chord-defining tritone. Drop the I7\'s inner pair one fret and you\'re already playing the IV7\'s guide tones — the quick change costs one finger.',
|
||||
},
|
||||
{
|
||||
label: 'Big barres, quick four',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'the quick change — bar 2' },
|
||||
{ shape: E_BARRE7, note: '' }, { shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: '' }, { shape: A_BARRE7, note: '' },
|
||||
{ shape: E_BARRE7, note: '' }, { shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7' },
|
||||
{ shape: A_BARRE7, note: 'IV7' },
|
||||
{ shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7' },
|
||||
],
|
||||
tips: 'Accent bar 2 slightly — telegraphing the quick change keeps the whole jam from splitting between the two 12-bar variants.',
|
||||
},
|
||||
],
|
||||
|
||||
'blues-8bar': [
|
||||
{
|
||||
label: 'Barres through the 8-bar form',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: E_BARRE7, note: 'I7' },
|
||||
{ shape: A_BARRE7, note: 'V7 already — count!' },
|
||||
{ shape: A_BARRE7, note: 'IV7' }, { shape: A_BARRE7, note: '' },
|
||||
{ shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7' },
|
||||
{ shape: E_BARRE7, note: '' },
|
||||
{ shape: A_BARRE7, note: 'V7 — turnaround' },
|
||||
],
|
||||
tips: 'Half the length, twice the changes per chorus. Lock the form before decorating it.',
|
||||
},
|
||||
{
|
||||
label: '9ths and 13ths, uptown',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: 'V13' },
|
||||
{ shape: NINTH, extensions: ['9'], note: 'IV9' }, { shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: '' },
|
||||
{ shape: NINTH, extensions: ['9'], note: '' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: '' },
|
||||
],
|
||||
tips: 'The Key-to-the-Highway feel is gentle — roll the chords instead of stabbing them, triplet feel even at medium tempo.',
|
||||
},
|
||||
],
|
||||
|
||||
'blues-minor': [
|
||||
{
|
||||
label: 'm7 barres with the ♯9 climax',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: MIN7_BARRE_6, note: 'i7' },
|
||||
{ shape: MIN7_BARRE_6, note: '' }, { shape: MIN7_BARRE_6, note: '' }, { shape: MIN7_BARRE_6, note: '' },
|
||||
{ shape: MIN7_BARRE_5, note: 'iv7' }, { shape: MIN7_BARRE_5, note: '' },
|
||||
{ shape: MIN7_BARRE_6, note: '' }, { shape: MIN7_BARRE_6, note: '' },
|
||||
{ shape: A_BARRE7, note: '♭VI7 — the drama bar' },
|
||||
{ shape: HENDRIX, extensions: ['#9'], note: 'V7♯9 — the slow-blues scream' },
|
||||
{ shape: MIN7_BARRE_6, note: '' }, { shape: MIN7_BARRE_6, note: '' },
|
||||
],
|
||||
tips: 'Save your dynamics for bars 9–10: the ♭VI7→V7♯9 half-step drop is the whole emotional payload of the form. Everything before it is patience.',
|
||||
},
|
||||
{
|
||||
label: 'Upper-register minor comping',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: MIN7_BARRE_5, note: 'i7 — A-string root, above the bass' },
|
||||
{ shape: MIN7_BARRE_5, note: '' }, { shape: MIN7_BARRE_5, note: '' }, { shape: MIN7_BARRE_5, note: '' },
|
||||
{ shape: SHELL_M7_5, note: 'iv7 — thin out, the singer is working' },
|
||||
{ shape: SHELL_M7_5, note: '' },
|
||||
{ shape: MIN7_BARRE_5, note: '' }, { shape: MIN7_BARRE_5, note: '' },
|
||||
{ shape: THIRTEEN_6, extensions: ['13'], note: '♭VI13' },
|
||||
{ shape: NINTH, extensions: ['9'], note: 'V9' },
|
||||
{ shape: MIN7_BARRE_5, note: '' }, { shape: SHELL_M7_5, note: 'fade to the turnaround' },
|
||||
],
|
||||
tips: 'Minor blues is usually slow — 12/8 triplet grid, rolled chords, and at least one full bar per chorus where you play nothing at all.',
|
||||
},
|
||||
],
|
||||
|
||||
'blues-turnaround': [
|
||||
{
|
||||
label: 'Shell cycle',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: SHELL7_6, note: 'I7' },
|
||||
{ shape: SHELL7_5, note: 'VI7' },
|
||||
{ shape: SHELL_M7_5, note: 'ii7' },
|
||||
{ shape: SHELL7_6, note: 'V7' },
|
||||
],
|
||||
tips: 'Often two beats per chord, not a bar — practise it at both speeds. The roots fall in fifths from the VI on, so the grips alternate strings on their own.',
|
||||
},
|
||||
{
|
||||
label: 'Uptown 9ths (T-Bone)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: NINTH, extensions: ['9'], note: 'I9' },
|
||||
{ shape: NINTH, extensions: ['9'], note: 'VI9' },
|
||||
{ shape: MIN7_BARRE_5, note: 'ii7' },
|
||||
{ shape: THIRTEEN, extensions: ['9', '13'], note: 'V13 — hold, then slide down a fret into the next chorus' },
|
||||
],
|
||||
tips: 'This is the Stormy Monday sound: every dominant becomes a 9th or 13th, approached chromatically. Roll them lazily on the triplet grid.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
improv: {
|
||||
scales: [
|
||||
{ over: 'I7', scale: 'mixolydian', why: 'Major pentatonic and Mixolydian shine over the I — the sweet B.B. King side of the coin.' },
|
||||
{ over: 'IV7', scale: 'mixolydian', why: 'Switch to minor pentatonic (or think the IV\'s own Mixolydian) when the IV arrives — the key\'s major 3rd clashes with its ♭7.' },
|
||||
{ over: 'V7', scale: 'mixolydian', why: 'Each chord gets its own Mixolydian; adjacent ones differ by one note, so really it\'s "follow the chord tones."' },
|
||||
{ over: 'i7 (minor blues)', scale: 'minor', why: 'Minor pentatonic + the natural 6 over the iv; harmonic minor colour over the V7.' },
|
||||
],
|
||||
targetNotes:
|
||||
'The 3rd of the current chord at every change is the whole game; hit the ♭7 of the I in bar 4 to announce the IV. The blues curl — a quarter-step bend of the ♭3 toward the major 3 — is the signature ornament.',
|
||||
licks: [
|
||||
{
|
||||
over: 'blues-12bar',
|
||||
description: 'Classic descending turnaround in E (Robert Johnson "Kind Hearted Woman" lineage): ♭7–6–♭6–5 under a high-E pedal, swung triplets, resolving to B7.',
|
||||
tab: 'e|--0---0---0---0--------2--\nB|--3---2---1---0--------0--\nG|-----------------------2--\nD|-----------------------1--\nA|-----------------------2--\nE|--------------------------\n D C# C B → B7',
|
||||
source: 'GuitarPlayer "Blues Turnarounds Pt 1"; Fundamental Changes "Blues Turnarounds for Guitar"',
|
||||
},
|
||||
{
|
||||
over: 'blues-12bar',
|
||||
description: 'B.B. King box lick in C: major-pentatonic box around frets 8–10 with the signature 2→3 whole-step bend (D bent to E, the 3rd of C7).',
|
||||
tab: 'e|--8--10b12--10--8---------------\nB|------------------10--8---------\nG|------------------------9-------\n C D→E D C A G E',
|
||||
source: 'GuitarPlayer "12 Killer Blues Licks"; Guitar World (B.B. box, R-2-4-5-6)',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
id: 'blues',
|
||||
label: 'Blues',
|
||||
feel: 'shuffle',
|
||||
tempoRange: [60, 180],
|
||||
character: 'Dominant 7ths on every chord, swung eighths or 12/8 triplets, and the ♭3-against-3 tension that makes it talk — form is sacred, everything else is conversation.',
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
export default [
|
||||
{
|
||||
id: 'blues-12bar',
|
||||
name: 'Standard 12-bar',
|
||||
rn: ['I7', 'I7', 'I7', 'I7', 'IV7', 'IV7', 'I7', 'I7', 'V7', 'IV7', 'I7', 'V7'],
|
||||
degrees: [0, 0, 0, 0, 5, 5, 0, 0, 7, 5, 0, 7],
|
||||
qualities: ['dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7'],
|
||||
bars: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
mode: 'major',
|
||||
songs: ['Sweet Home Chicago', 'Pride and Joy — Stevie Ray Vaughan', 'Johnny B. Goode — Chuck Berry'],
|
||||
tip: 'Bar 12 is the V7 launching the next chorus — never let it resolve flat. The form is a wheel, and bar 12 is where you push it.',
|
||||
},
|
||||
{
|
||||
id: 'blues-quickchange',
|
||||
name: 'Quick-change 12-bar',
|
||||
rn: ['I7', 'IV7', 'I7', 'I7', 'IV7', 'IV7', 'I7', 'I7', 'V7', 'IV7', 'I7', 'V7'],
|
||||
degrees: [0, 5, 0, 0, 5, 5, 0, 0, 7, 5, 0, 7],
|
||||
qualities: ['dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7'],
|
||||
bars: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
mode: 'major',
|
||||
songs: ['Dust My Broom — Elmore James', 'Hide Away — Freddie King', 'Crossroads — Cream'],
|
||||
tip: 'One bar of IV in bar 2, then home. Listen for it in the first seconds of a jam — guessing wrong here is the most common train wreck in blues.',
|
||||
},
|
||||
{
|
||||
id: 'blues-8bar',
|
||||
name: '8-bar blues',
|
||||
rn: ['I7', 'V7', 'IV7', 'IV7', 'I7', 'V7', 'I7', 'V7'],
|
||||
degrees: [0, 7, 5, 5, 0, 7, 0, 7],
|
||||
qualities: ['dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7', 'dom7'],
|
||||
bars: [1, 1, 1, 1, 1, 1, 1, 1],
|
||||
mode: 'major',
|
||||
songs: ['Key to the Highway — Big Bill Broonzy', 'It Hurts Me Too — Elmore James'],
|
||||
tip: 'The V arrives in bar 2 — much sooner than a 12-bar. Count the form out loud the first chorus; 8-bar tunes wrong-foot 12-bar reflexes.',
|
||||
},
|
||||
{
|
||||
id: 'blues-minor',
|
||||
name: 'Minor blues',
|
||||
rn: ['i7', 'i7', 'i7', 'i7', 'iv7', 'iv7', 'i7', 'i7', '♭VI7', 'V7', 'i7', 'i7'],
|
||||
degrees: [0, 0, 0, 0, 5, 5, 0, 0, 8, 7, 0, 0],
|
||||
qualities: ['min7', 'min7', 'min7', 'min7', 'min7', 'min7', 'min7', 'min7', 'dom7', 'dom7', 'min7', 'min7'],
|
||||
bars: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
mode: 'minor',
|
||||
songs: ['The Thrill Is Gone — B.B. King', 'As the Years Go Passing By — Albert King'],
|
||||
tip: 'Bars 9–10 are the whole drama: ♭VI sliding down a half-step to V7. (B.B.\'s recording makes the ♭VI a maj7 — try both colours.)',
|
||||
},
|
||||
{
|
||||
id: 'blues-turnaround',
|
||||
name: 'Turnaround cycle (I–VI–ii–V)',
|
||||
rn: ['I7', 'VI7', 'ii7', 'V7'],
|
||||
degrees: [0, 9, 2, 7],
|
||||
qualities: ['dom7', 'dom7', 'min7', 'dom7'],
|
||||
bars: [1, 1, 1, 1],
|
||||
mode: 'major',
|
||||
songs: ['Call It Stormy Monday — T-Bone Walker (intro)', 'jazz-blues bars 11–12 everywhere'],
|
||||
tip: 'The jazz handshake inside the blues — often squeezed into two bars (two beats per chord). Loop it as a vamp and you\'ve learned bars 11–12 of every uptown blues.',
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,227 @@
|
||||
// Bossa nova guitar pack. Grips verified by note-spelling against: jazzguitar.be
|
||||
// (Ipanema chords), jenslarsen.nl (bossa patterns, 5 levels), thejazzpianosite.com
|
||||
// (rhythm layers), Nelson Faria "The Brazilian Guitar Book" (canonical grip source),
|
||||
// mdecksmusic.com (Ipanema analysis), jazz-circle.com (Blue Bossa, Black Orpheus).
|
||||
//
|
||||
// Construction: thumb takes the root on string 6 or 5; fingers take 3-4 notes on
|
||||
// D-G-B(-e). Every grip movable. Two plays per progression = the two root-string
|
||||
// sets, because that's how bossa voice-leads: adjacent chords trade root strings
|
||||
// so inner voices move by one fret ("two fingers move, the chord transforms").
|
||||
|
||||
// Root on the low E string (thumb).
|
||||
const M7_6 = { rootStr: 6, offsets: [0, 'x', 0, 0, 0, 'x'], fingers: [1, 0, 2, 3, 4, 0] } // R-♭7-♭3-5
|
||||
const MAJ7_6 = { rootStr: 6, offsets: [0, 'x', 1, 1, 0, 'x'], fingers: [1, 0, 3, 4, 2, 0] } // R-7-3-5
|
||||
const DOM7_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, 0, 'x'], fingers: [1, 0, 2, 3, 4, 0] } // R-♭7-3-5
|
||||
const DOM13_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, 2, 'x'], fingers: [1, 0, 2, 3, 4, 0] } // R-♭7-3-13
|
||||
const DOM7B9_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, 0, 1], fingers: [1, 0, 2, 3, 1, 4] } // R-♭7-3-5-♭9
|
||||
const M7B5_6 = { rootStr: 6, offsets: [0, 'x', 0, 0, -1, 'x'], fingers: [2, 0, 3, 4, 1, 0] } // R-♭7-♭3-♭5
|
||||
const M6_6 = { rootStr: 6, offsets: [0, 'x', -1, 0, 0, 'x'], fingers: [2, 0, 1, 3, 4, 0] } // R-6-♭3-5
|
||||
const DIM7_6 = { rootStr: 6, offsets: [0, 'x', -1, 0, -1, 'x'], fingers: [2, 0, 1, 3, 1, 0] } // R-♭♭7-♭3-♭5
|
||||
const DOM7S11_6 = { rootStr: 6, offsets: [0, 'x', 0, 1, -1, 'x'], fingers: [2, 0, 3, 4, 1, 0] } // R-♭7-3-♯11 (the tritone-sub grip)
|
||||
|
||||
// Root on the A string (thumb).
|
||||
const M7_5 = { rootStr: 5, offsets: ['x', 0, 2, 0, 1, 'x'], fingers: [0, 1, 3, 2, 4, 0] } // R-5-♭7-♭3
|
||||
const M7_5C = { rootStr: 5, offsets: ['x', 0, -2, 0, 1, 'x'], fingers: [0, 2, 1, 3, 4, 0] } // R-♭3-♭7-♭3 compact grab
|
||||
const MAJ9_5 = { rootStr: 5, offsets: ['x', 0, -1, 1, 0, 'x'], fingers: [0, 2, 1, 4, 3, 0] } // R-3-7-9
|
||||
const DOM9_5 = { rootStr: 5, offsets: ['x', 0, -1, 0, 0, 'x'], fingers: [0, 2, 1, 3, 4, 0] } // R-3-♭7-9
|
||||
const DOM7B9_5 = { rootStr: 5, offsets: ['x', 0, -1, 0, -1, 'x'], fingers: [0, 3, 1, 4, 2, 0] } // R-3-♭7-♭9
|
||||
const M7B5_5 = { rootStr: 5, offsets: ['x', 0, 1, 0, 1, 'x'], fingers: [0, 1, 3, 2, 4, 0] } // R-♭5-♭7-♭3
|
||||
const M6_5 = { rootStr: 5, offsets: ['x', 0, -2, -1, -2, 'x'], fingers: [0, 4, 1, 3, 2, 0] } // R-♭3-6-R
|
||||
const DIM7_5 = { rootStr: 5, offsets: ['x', 0, 1, -1, 1, 'x'], fingers: [0, 2, 3, 1, 4, 0] } // R-♭5-♭♭7-♭3
|
||||
|
||||
export default {
|
||||
styleIntro:
|
||||
'The bossa guitarist is the whole rhythm section: thumb plays the surdo drum (root on 1, fifth on 3, never syncopated), fingers play the chord block on the anticipations. Quiet is louder — the genre was invented at apartment volume, and intensity comes from rhythmic placement and harmonic colour, never from strumming harder.',
|
||||
|
||||
comping: [
|
||||
{
|
||||
label: 'Thumb bass (the surdo)',
|
||||
rhythm: 'B . . . B . . . — root on 1, fifth on 3',
|
||||
description: 'Metronomic, soft, every bar, under everything. The one layer that is never syncopated. With a bassist: drop it entirely and play only the upper notes.',
|
||||
},
|
||||
{
|
||||
label: 'One-bar starter pattern',
|
||||
rhythm: 'X . . X . . X . — hits on 1, and-of-2, 4',
|
||||
description: 'The training-wheels comp: chord block on 1, the and-of-2, and 4 over the steady thumb. Master this before the two-bar pattern.',
|
||||
},
|
||||
{
|
||||
label: 'Two-bar João Gilberto pattern',
|
||||
rhythm: 'X . . X . . . X~ | . . . X . . X . — the 4& ties over the barline',
|
||||
description: 'Bar 2 has no downbeat chord — the tied and-of-4 carries across. The anticipation is the hardest and most essential bossa skill. Gilberto drifted between patterns freely; treat it as a motif, not a loop.',
|
||||
},
|
||||
{
|
||||
label: 'Partido alto (the samba cousin — for contrast)',
|
||||
rhythm: '. X . X X . . X — lands HARD on beat 3',
|
||||
description: 'Percussive, chopped, with muted ghost-strums — the opposite aesthetic. Bossa never accents beat 3: that beat belongs to the bass register (the surdo). Hammering it squares the lilt into a polka.',
|
||||
},
|
||||
],
|
||||
|
||||
plays: {
|
||||
'bossa-ipanema': [
|
||||
{
|
||||
label: 'Low-E roots (the João position)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: MAJ7_6, note: 'Imaj7' },
|
||||
{ shape: DOM13_6, extensions: ['13'], note: 'II7(13) — the Lydian ♭7 colour' },
|
||||
{ shape: M7_6, note: 'ii7' },
|
||||
{ shape: DOM7S11_6, extensions: ['#11'], note: '♭II7(♯11) — tritone sub of V' },
|
||||
{ shape: MAJ7_6, note: 'home' },
|
||||
{ shape: DOM7S11_6, extensions: ['#11'], note: 'and the ♭II7 again — Jobim never quite lets go' },
|
||||
],
|
||||
tips: 'The whole A-section lives in a four-fret window: each change moves the thumb a fret or two and one or two fingers inside the grip. If a finger jumps more than two frets, you took a wrong turn.',
|
||||
},
|
||||
{
|
||||
label: 'A-string roots, colour-tone set',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: 'Imaj9' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: 'II9' },
|
||||
{ shape: M7_5, note: 'ii7' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: '♭II9' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: '' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: '' },
|
||||
],
|
||||
tips: 'Same progression, one string set higher and sweeter — 9ths everywhere. Use this set when another guitarist or pianist already owns the low-E register. (If the band plays a plain major tonic, the 6/9 grab — drop the 7th for the 6 — is the classic bossa colour.)',
|
||||
},
|
||||
],
|
||||
|
||||
'bossa-minor-251': [
|
||||
{
|
||||
label: 'Low-E roots with the ♭9',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_6, note: 'i7' },
|
||||
{ shape: M7B5_6, note: 'iiø7 — the ♭5 on the B string is the saudade note' },
|
||||
{ shape: DOM7B9_6, extensions: ['b9'], note: 'V7♭9 — the ♭5 you just played, reinterpreted' },
|
||||
{ shape: M6_6, note: 'i6 — resolve to the sixth, not the seventh' },
|
||||
],
|
||||
tips: 'One pitch threads the middle of the progression: the iiø7\'s ♭5 IS the V7\'s ♭9. Find it, hold it, let the thumb do the moving.',
|
||||
},
|
||||
{
|
||||
label: 'A-string roots, compact grabs',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_5C, note: 'compact i7 — no 5th, pure bossa economy' },
|
||||
{ shape: M7B5_5, note: 'iiø7' },
|
||||
{ shape: DOM7B9_5, extensions: ['b9'], note: 'V7♭9' },
|
||||
{ shape: M6_5, note: 'i6' },
|
||||
],
|
||||
tips: 'Black Orpheus oscillates between this cell and the relative major\'s ii–V–I — learn both as one hand pattern and the whole tune is two moves.',
|
||||
},
|
||||
],
|
||||
|
||||
'bossa-blue': [
|
||||
{
|
||||
label: 'Thumb-bass through the form',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_6, note: 'i7' }, { shape: M7_6, note: '' },
|
||||
{ shape: M7_5, note: 'iv7 — A-string root, same fret region' }, { shape: M7_5, note: '' },
|
||||
{ shape: M7B5_5, note: 'iiø7' },
|
||||
{ shape: DOM7B9_6, extensions: ['b9'], note: 'V7♭9' },
|
||||
{ shape: M7_6, note: '' }, { shape: M7_6, note: '' },
|
||||
{ shape: M7_6, note: '♭iii7 — the excursion begins' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: '♭VI9' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: '♭IImaj9 — a major-key vacation' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: '' },
|
||||
{ shape: M7B5_5, note: 'iiø7 — back to reality' },
|
||||
{ shape: DOM7B9_6, extensions: ['b9'], note: 'V7♭9' },
|
||||
{ shape: M7_6, note: '' }, { shape: M7_6, note: '' },
|
||||
],
|
||||
tips: 'i and iv sit on adjacent root strings in one position, like a blues. The bars 9–12 excursion is a normal major ii–V–I — play it sweeter, then darken again for the iiø7.',
|
||||
},
|
||||
{
|
||||
label: 'Colour set (9ths and the 6/9 cadence)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_5C, note: '' }, { shape: M7_5C, note: '' },
|
||||
{ shape: M7_6, note: 'iv7 low' }, { shape: M7_6, note: '' },
|
||||
{ shape: M7B5_6, note: '' },
|
||||
{ shape: DOM7B9_5, extensions: ['b9'], note: '' },
|
||||
{ shape: M7_5C, note: '' }, { shape: M7_5C, note: '' },
|
||||
{ shape: M7_5C, note: '' },
|
||||
{ shape: DOM13_6, extensions: ['13'], note: '♭VI13' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: '♭IImaj9' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: '' },
|
||||
{ shape: M7B5_6, note: '' },
|
||||
{ shape: DOM7B9_5, extensions: ['b9'], note: '' },
|
||||
{ shape: M7_5C, note: '' }, { shape: M7_5C, note: '' },
|
||||
],
|
||||
tips: 'Blue Bossa\'s tonic is a true m7 — save the m6 colour for tunes that ask for it (see the minor ii–V–i cell). Keep all of it at whisper volume.',
|
||||
},
|
||||
],
|
||||
|
||||
'bossa-one-note': [
|
||||
{
|
||||
label: 'Two grips falling by half-steps (A-string roots)',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_5, note: 'iii7' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: '♭III9 — same fret region, one finger reshapes' },
|
||||
{ shape: M7_5, note: 'ii7 — whole grip slides down' },
|
||||
{ shape: DOM9_5, extensions: ['9'], note: '♭II9' },
|
||||
],
|
||||
tips: 'The entire progression is two grips alternating while the thumb walks down chromatically. Hold one melody note on top if you can reach it — that\'s the whole point of the tune.',
|
||||
},
|
||||
{
|
||||
label: 'Low-E roots with 13s',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M7_6, note: '' },
|
||||
{ shape: DOM13_6, extensions: ['13'], note: '♭III13' },
|
||||
{ shape: M7_6, note: '' },
|
||||
{ shape: DOM13_6, extensions: ['13'], note: '♭II13' },
|
||||
],
|
||||
tips: 'The 13 on top of each dominant descends in parallel with the bass — two chromatic lines moving in lockstep, which is why this progression sounds inevitable.',
|
||||
},
|
||||
],
|
||||
|
||||
'bossa-corcovado': [
|
||||
{
|
||||
label: 'Chromatic staircase, low-E roots',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M6_6, note: 'iii6' },
|
||||
{ shape: DIM7_6, note: 'passing °7 — one fret down' },
|
||||
{ shape: M7_6, note: 'ii7 — one more' },
|
||||
{ shape: DOM7S11_6, extensions: ['#11'], note: '♭II7(♯11) — tritone sub' },
|
||||
{ shape: MAJ7_6, note: 'Imaj7 — arrival' },
|
||||
],
|
||||
tips: 'The low E string walks down one fret per bar — let that bassline sing through the grips. This is the same passing-diminished device as How Insensitive; learn it once, hear it everywhere in Jobim.',
|
||||
},
|
||||
{
|
||||
label: 'A-string set with the 6/9 landing',
|
||||
level: 'intermediate',
|
||||
chords: [
|
||||
{ shape: M6_5, note: 'iii6' },
|
||||
{ shape: DIM7_5, note: '°7' },
|
||||
{ shape: M7_5C, note: 'ii7' },
|
||||
{ shape: DOM7B9_5, extensions: ['b9'], note: '♭II7(♭9)' },
|
||||
{ shape: MAJ9_5, extensions: ['9'], note: 'Imaj9 — arrival' },
|
||||
],
|
||||
tips: 'When the singer holds the tonic, swap the maj9 for a 6/9 grab (7th down to the 6) — no leading tone to fight them. Over a detected maj7, stay with the maj9.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
improv: {
|
||||
scales: [
|
||||
{ over: 'ii7 / i7 / iv7', scale: 'dorian', why: 'All the minor 7ths take Dorian — bossa is jazz harmony in a swimsuit.' },
|
||||
{ over: 'V7 → major I', scale: 'mixolydian', why: 'Plain Mixolydian when resolving to major; add the 13 — it\'s the genre\'s favourite colour.' },
|
||||
{ over: 'II7 / ♭II7 (tritone subs)', scale: 'lydian', why: 'Lydian dominant (melodic minor from the 5th) — the ♯11 is already in the chord grip.' },
|
||||
{ over: 'V7♭9 → minor i', scale: 'phrygian', why: 'Phrygian dominant (harmonic minor from the V) for the ♭9; the altered scale if you want more trouble.' },
|
||||
{ over: 'iiø7', scale: 'locrian', why: 'Locrian, or raise the 2 (melodic-minor mode 6) for a smoother colour.' },
|
||||
],
|
||||
targetNotes:
|
||||
'Bossa solos are melody-first: hold or repeat a small cell and let the CHORDS recontextualise it — One Note Samba is the method stated as a song title. Target the colour tones (9, 13, ♯11) and the 3rd/7th guide-tone line; avoid sitting on roots. Phrase behind the beat and leave bar-length gaps.',
|
||||
licks: [
|
||||
{
|
||||
over: 'bossa-ipanema',
|
||||
description: 'The Ipanema opening cell: the melody sits on the 9th and major 7th of the Imaj7 — never the root. The identical two notes work over the II7 bars, where they become root and 13.',
|
||||
tab: 'e|--3--------------3-----------\nB|------5--5--3--------5--5----\n G E E D G E E\n (9) (7)(7)(6) (9) (7)(7) over Fmaj7',
|
||||
source: '"Garota de Ipanema" — Jobim/de Moraes (Real Book lead sheet; mDecks harmonic analysis)',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
id: 'bossa',
|
||||
label: 'Bossa Nova',
|
||||
feel: 'bossa',
|
||||
tempoRange: [110, 160],
|
||||
character: 'A whole samba band condensed into one quiet guitar: metronomic thumb bass, syncopated chord block that never accents beat 3, and jazz harmony at conversation volume.',
|
||||
}
|
||||