Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e488cc3
Implement kit-profile persistence, chart consumption, live scoring, n…
cchacs Oct 7, 2026
388500c
fix(routes): skip reserved keys in _sanitise_kit_profiles
cchacs Oct 7, 2026
067afa7
fix(routes): skip reserved keys in _sanitise_song_overrides
cchacs Oct 7, 2026
24458a7
fix(settings): use hasOwnProperty for profile name check
cchacs Oct 7, 2026
55bdc9c
fix(settings): limit profile name to 99 chars to match server
cchacs Oct 7, 2026
1a8318f
docs(settings): correct comment about settings category
cchacs Oct 7, 2026
3e22779
fix(settings): refetch profiles when panel becomes visible
cchacs Oct 7, 2026
1a5eb68
fix(screen): reset score on profile create/delete
cchacs Oct 7, 2026
8e59844
fix(screen): refetch persisted kit state on every activation
cchacs Oct 7, 2026
a9827ae
fix(routes): reject reserved keys in settings validation
pullfrog[bot] Oct 7, 2026
bd7310d
fix(screen): reserved-name rejection, own-property checks, scoped del…
pullfrog[bot] Oct 7, 2026
1d2fd6f
fix(settings): reject reserved profile names in the panel
pullfrog[bot] Oct 7, 2026
d7f0fc7
fix(screen): cap new kit name input at 99 chars
pullfrog[bot] Oct 7, 2026
14c8a0c
settings.html: state the verified reason the script is standalone
cchacs Oct 7, 2026
db097c9
fix: reject reserved keys in active_kit; align 100-char name cap ever…
cchacs Oct 7, 2026
fc8adac
Update midi-drums/settings.html
cchacs Oct 7, 2026
0a44ed9
Update midi-drums/settings.html
cchacs Oct 7, 2026
7c1c576
fix(routes): correct reserved-name rationale on active_kit guard
pullfrog[bot] Oct 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `nav` field in `my-plugin/plugin.json` (`{ "label": "My Plugin", "screen": "plugin-my-plugin" }`) so the plugin registers a sidebar entry.
- `AGENTS.md` — reference guide for AI assistants/contributors covering the actual API shape, plugin conventions, known code notes, and a verification checklist.

- `midi-drums` kit-profile persistence (#5) — `kit_updated_at` stamps, `per_song_overrides`, bounded server validation, and `settings.server_files` in `plugin.json` for Host-side export/import.
- `midi-drums` drum-chart consumption (#6) — the plugin holds its own listener on the highway WS (core exposes the chart to renderer bundles only, with no bus event or `getDrumTab()` getter), a `?drum_part=` picker for multi-part packs, and "no chart — scoring off" degradation for legacy packs.
- `midi-drums` live scoring engine (#7) — ±50 ms hit matching with EARLY/OK/LATE split, per-frame miss sweep with a connect-time floor and seek-back re-arm, streak/accuracy/streak counters, and bounded surfacing of unmapped strikes/missing chart pieces (mirrors `drum_highway_3d`).
- `midi-drums` note-state provider integration (#8) — a function provider `(note, chartTime) => state` registered on `window.highway` only while a device session is open, cleared with `setNoteStateProvider(null)` on exit/disposal.
- `midi-drums` kit-profile settings panel (#9) — `settings.html` with profile CRUD, active-profile switching, per-profile coverage chips, last-updated stamps, and remap deep-links into the player screen's single-piece remap path.
- `midi-drums` active-kit picker and profile creation on the plugin screen; part picker, chart status, streak/extras and unmapped readouts on the screen.

### Fixed
- `midi-drums` piece vocabulary drifted from the host's `lib/drums.py` (`tom1`/`floor_tom`/`rim`… were invented ids) — now the canonical 18-id set; unknown ids round-trip with a title-cased fallback.
- `midi-drums` registered an object wrapper with `highway.setNoteStateProvider` (the contract takes a function `(note, chartTime)` and was never invoked) and never cleared the slot — rewritten per feedBack#254, cleared on teardown.
- `midi-drums` calibrated against bus events `drum-tab`/`drum-hits`/`drum-part` that no host component emits; replaced with the plugin's own chart WS.
- `midi-drums` dead code removed: `onDrumTabChanged` runner, the unused note-state wrapper, and an unreachable view-scope `registerWithHighway()` call.

<!-- Add entries under Added, Changed, Deprecated, Removed, Fixed, or Security as changes land. -->
49 changes: 42 additions & 7 deletions midi-drums/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# midi-drums

Device-access layer for MIDI drum controllers. Scans for input devices, opens
several at once, and merges their note-ons into a single tagged stream — the
foundation the kit-profile work builds on.
Input + scoring plugin for MIDI drum controllers. Scans for input devices,
opens several at once, merges their note-ons into a single tagged stream, then
calibrates them into kit profiles, consumes the loaded song's drum chart, and
scores live hits against it — feeding the active highway renderer through
`highway.setNoteStateProvider`.

This plugin never touches the Web MIDI API. It goes through the Host's
capability layer, `window.feedBack.midiInput`, and is written to work when that
Expand All @@ -12,10 +14,11 @@ domain is absent or mid-version.

| File | Purpose |
|---|---|
| `plugin.json` | Manifest — capability declaration, `type: "input"`, nav entry, no settings panel |
| `screen.html` | Device list, rescan control, saved-device status, bounded hit log |
| `screen.js` | Device layer (`window.midiDrumsDevices`) + screen lifecycle |
| `routes.py` | Server-persisted selection (`source_keys`) at `/api/plugins/midi-drums/settings` |
| `plugin.json` | Manifest — capability declaration, `type: "input"`, nav entry, settings panel, server_files |
| `screen.html` | Device list, kit-profile picker, calibration wizard, chart status (+ part picker), scoring panel, bounded hit log |
| `screen.js` | Device layer + kit-profile CRUD + drum-chart consumption (own WS) + live scoring engine + note-state provider |
| `settings.html` | Kit-profile management panel (list/create/rename/delete/set-active, coverage chips, piece remap deep-links) |
| `routes.py` | Server persistence at `/api/plugins/midi-drums/settings` and `/api/plugins/midi-drums/kit-profiles` |
| `assets/plugin.css` | Styling scoped to the plugin |

## How it talks to MIDI
Expand Down Expand Up @@ -78,6 +81,38 @@ offHits();
stream across every open source; each hit carries the `logicalSourceKey` it came
from, so a consumer never has to track connections itself.

## Kit profiles and scoring

Beyond device identity, the layer stores `kit_profiles` (piece-id →
`{note, channel, logicalSourceKey}` per named profile), `kit_updated_at`
(per-profile last-modified stamps), and `per_song_overrides` (sparse song-key →
piece → mapping overlays), all validated and salvaged key-by-key server-side.

- **Kit pieces come from `lib/drums.py`.** The 18-id canonical vocabulary is
mirrored in `screen.js`; ids a newer pack references beyond it round-trip
with a title-cased display fallback.
- **The wizard calibrates the active profile.** `Settings → Plugins → MIDI
Drums` owns full CRUD (create/rename/delete/set-active, coverage chips);
piece chips there deep-link into the player screen's single-piece remap
path via nav params.
- **The drum chart comes over the plugin's own WebSocket.** Core's highway
hands `drum_tab`/`drum_hits` only to renderer bundles — no bus event, no
public getter — so the plugin listens on the same `/ws/highway/<file>`
endpoint itself (the server's extraction caches make the second connection
cheap). `?drum_part=` selects the streaming part; multi-part packs surface
a picker. Legacy packs that encode drums as guitar notes stream no
`drum_tab` and are treated as "no chart — scoring off" for this song.
- **Scoring mirrors `drum_highway_3d`.** ±50 ms matching window with an
EARLY/OK/LATE split at 40%, misses swept per animation frame with a
connect-time floor (and re-armed on seek-back), per-hit judgments keyed on
`t|piece`, streak/accuracy readouts, and bounded surfacing of strikes that
match no mapped piece.
- **Renderer feedback goes through `setNoteStateProvider`.** The layer
registers a function provider `(note, chartTime) => state` on
`window.highway` only while a device session is open (the contract is
last-call-wins, so squatters lose), returns decaying `alpha` glows, and
clears with `setNoteStateProvider(null)` on screen exit and disposal.

## Device identity

Sources are keyed by `logicalSourceKey` (`web-midi::<stable-id>`), never by a
Expand Down
150 changes: 149 additions & 1 deletion midi-drums/assets/plugin.css
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,152 @@
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
}
/* Kit profile row (active-profile picker + inline create) */
.midi-drums__profiles {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-top: 0.75rem;
}

.midi-drums__profiles-row {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
align-items: center;
}

.midi-drums__select,
.midi-drums__input {
padding: 0.35rem 0.5rem;
border: 1px solid rgba(128, 128, 128, 0.4);
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
}

/* Drum-part picker row */
.midi-drums__part-row {
display: flex;
gap: 0.5rem;
align-items: center;
margin: 0.5rem 0;
}

.midi-drums__part-row[hidden] {
display: none;
}

/* Settings-panel kit profile management (scoped to .midi-drums-settings) */
.midi-drums-settings fieldset {
display: flex;
flex-direction: column;
gap: 0.75rem;
}

.midi-drums-settings__hint,
.midi-drums-settings__count,
.midi-drums-settings__status {
margin: 0;
font-size: 0.85rem;
opacity: 0.8;
}

.midi-drums-settings__status {
color: #e0a040;
}

.midi-drums-settings__create {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}

.midi-drums-settings__input {
flex: 1 1 12rem;
padding: 0.35rem 0.5rem;
border: 1px solid rgba(128, 128, 128, 0.4);
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
}

.midi-drums-settings__button {
padding: 0.3rem 0.7rem;
border: 1px solid rgba(128, 128, 128, 0.4);
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
cursor: pointer;
}

.midi-drums-settings__button:hover {
border-color: currentColor;
}

.midi-drums-settings__button--danger {
border-color: rgba(200, 70, 70, 0.6);
color: #d08080;
}

.midi-drums-settings__list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 0.75rem;
}

.midi-drums-settings__profile {
padding: 0.65rem;
border: 1px solid rgba(128, 128, 128, 0.3);
border-radius: 8px;
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.midi-drums-settings__profile-head {
display: flex;
gap: 0.75rem;
align-items: baseline;
flex-wrap: wrap;
}

.midi-drums-settings__updated {
font-size: 0.8rem;
opacity: 0.7;
}

.midi-drums-settings__chips {
display: flex;
flex-wrap: wrap;
gap: 0.3rem;
}

.midi-drums-settings__chip {
padding: 0.15rem 0.5rem;
font-size: 0.78rem;
border: 1px solid rgba(128, 128, 128, 0.35);
border-radius: 999px;
background: transparent;
color: inherit;
opacity: 0.55;
cursor: pointer;
}

.midi-drums-settings__chip.is-mapped {
opacity: 1;
border-color: rgba(90, 180, 120, 0.8);
}

.midi-drums-settings__actions {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
4 changes: 4 additions & 0 deletions midi-drums/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"scriptType": "classic",
"styles": "assets/plugin.css",
"routes": "routes.py",
"settings": {
"html": "settings.html",
"server_files": ["midi-drums.json"]
},
"category": "practice",
"standards": [
"capability-pipelines.v1",
Expand Down
Loading