Repository navigation
feat: add midi-drums device-access layer - #10
Conversation
Scans for MIDI input devices through the Host's window.feedBack.midiInput capability, opens several at once, and merges their note-ons into one stream tagged by logicalSourceKey. Exposes window.midiDrumsDevices and persists the ticked selection server-side. Notes on a few decisions: - Availability is gated on the midi-input domain being present at version 1, not on navigator.requestMIDIAccess. A missing or mid-version domain is a no-op rather than an error. - discover() is the permission boundary and runs only once the screen is active, so the prompt never appears on someone else's screen. A denied result is recorded but never latched, so Rescan can retry it. - Ticked keys are stored, not labels. A missing device keeps its tick and reopens when it returns; no substitute is ever switched in. - Opens and closes for one source are serialised. The domain refcounts an open session by requester name, so two concurrent opens add a single reference while two closes would remove it twice and orphan the surviving handle. - Device labels are written with textContent throughout: a MIDI device name is user-controlled hardware text. Verified with throwaway jsdom and FastAPI harnesses outside the tree; the repo has no build, lint, or test tooling.
| // the only thing that re-opens devices: returning to the screen (or | ||
| // re-binding after a re-hydration) has to restore them here too. | ||
| // restore() skips sources that are already open. | ||
| await restore(); |
There was a problem hiding this comment.
WARNING: Double restore() call on first activation
activate() calls discover() (line 455) which internally calls restore() (line 141), then activate() calls restore() again here. While idempotent, this does unnecessary work on the first activation. Remove this line since discover() already restores after a successful discovery.
There was a problem hiding this comment.
Not redundant, and removing it would regress a behaviour. discover() short-circuits with if (discovered && !force) return before it reaches its internal restore(), so on every activation after the first it opens nothing. This call is the only thing that re-opens devices when the user returns to the screen, or after the Host re-hydrates the layer — without it, leaving and re-entering the screen would leave every ticked device closed. The duplicate pass on the first activation is a loop over the saved keys that openSource() skips for anything already open, so it costs nothing.
big-pickle (free) | 𝕏
There was a problem hiding this comment.
Fixed in bc99dda. The extra restore now only runs when the devices were already found, so returning to the screen still reopens them.
| to stream the request body above.""" | ||
| with write_lock: | ||
| merged = {**_read(), **incoming} | ||
| config_dir.mkdir(parents=True, exist_ok=True) |
There was a problem hiding this comment.
WARNING: Redundant config_dir.mkdir() call
config_dir.mkdir(parents=True, exist_ok=True) is already called in setup() at line 117 before routes are registered. The call here in _merge_and_persist() is redundant (though harmless).
There was a problem hiding this comment.
Keeping this one. The mkdir() in setup() does a different job from this one: it is the fail-fast validation that surfaces an unusable config_dir at load time, before any route is registered (see the comment at routes.py:114). This one makes the write path self-sufficient, so a config_dir that disappears or is rotated mid-session degrades to the existing 500 failed to save settings rather than raising FileNotFoundError out of the tmp-file write. It is also the convention the template sets (my-plugin/routes.py:144 does the same, and there is no setup-time mkdir() there to make it redundant).
big-pickle (free) | 𝕏
There was a problem hiding this comment.
Fixed in 9ddf2fc. setup() already makes the config folder before the routes exist.
|
Addressed all three threads from the review on #10. Fixed — Kept, with reasoning — the other two:
Both are explained in-thread and left open. The re-hydration thread is resolved; a fresh read of the review turned up no new comments. Task list (7/7 completed)
|
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Previous Review Summary (commit 78e184a)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 78e184a)Status: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (4 files)
Reviewed by free · Input: 42.4K · Output: 8K · Cached: 219.4K |
setActive() already binds midi-input:sources-changed on the first boot call, and no session can exist without setActive(true), so the extra call at layer construction only repeated work.

Implements #3 (part of #2): the MIDI drum controller device-access layer.
The plugin scans for input devices through the Host's
window.feedBack.midiInputcapability, opens several at once, and merges their note-ons into a single stream tagged bylogicalSourceKey— the foundation the calibration and kit-profile sub-issues build on.What it does
window.midiDrumsDevices—getState,subscribe,discover,setEnabled,setActive,onHit,dispose.onHityields{logicalSourceKey, note, velocity, channel, at}across every open source, so a consumer never tracks connections itself.routes.pyat/api/plugins/midi-drums/settings.Decisions worth flagging
mi && mi.version === 1, nevernavigator.requestMIDIAccess. Gating on the browser API would hide a usable non-Web-MIDI provider (a native adapter) beforediscover()had ever run, and would claim a Host was capable when its domain is absent.getSelected()is treated as an optional optimisation, since a Host may implement only what is declared.discover()is the permission boundary, invoked only once the screen is active so the prompt never appears on someone else's screen. A denied result is recorded but never latched — Rescan retries it.textContent. A MIDI device name is user-controlled hardware text and is never parsed as markup.Verification
The repo has no build, lint, or test tooling, so this was verified with throwaway harnesses outside the tree (jsdom + a fake MIDI domain, FastAPI +
httpxagainstroutes.py):getSelected(), and a bus that appears after the script runs.node --checkandpy_compilepass. The plugin has not been exercised against a real Host build with hardware attached — that manual pass is still outstanding.Closes the device-access portion of #2. Settings UI and kit profiles are separate sub-issues and are not in scope here.
🤖 Generated with Pullfrog
big-pickle(free) | 𝕏