Skip to content

Device access via the core midi-input capability domain #3

Closed as not planned

Description

@cchacs

Part of #2.

Wire the plugin up to window.feedBack.midiInput (core's midi-input capability domain) instead of calling navigator.requestMIDIAccess() directly. This is the shared device-access boundary already used by plugins/input_setup and plugins/drum_highway_3d — one permission prompt, one source list, works uniformly across a MIDI keyboard, a generic pad controller, or an e-kit module (Web MIDI abstracts them identically at this layer).

API to use (confirmed from plugins/input_setup/screen.js and plugins/drum_highway_3d/screen.js):

  • mi.discover() — the permission boundary; records denied/unavailable outcomes.
  • mi.listSources() — { sourceId, logicalSourceKey, label, kind, availability, selected }[].
  • mi.select(logicalSourceKey) / mi.open({ requester, logicalSourceKey }) → { handle }.
  • handle.addListener(cb) / handle.removeListener(cb) — cb(data) receives raw MIDI bytes; note-on is (data[0] & 0xf0) === 0x90 && data[2] > 0, note number in data[1], velocity in data[2].
  • mi.close({ requester, logicalSourceKey }) when done. Close on every exit path (teardown, screen change), mirroring input_setup's _activeCleanup.
  • Subscribe to midi-input:sources-changed (via window.feedBack.on) for device replug/unplug, mirroring drum_highway_3d's _midiStateSub pattern — reconnect the saved device on recovery, no fallback-switch on a transient unplug.
  • Support multiple simultaneous open sources merged into one logical input stream (e.g. a kick pedal on one device, pads on another), tagging each captured event with its logicalSourceKey so the calibration step can disambiguate.

Gate on domain presence, not browser API presence — midiAvailable = !!(mi && mi.version === 1), exactly as input_setup does, so a non-Web-MIDI native provider registered with the domain isn't hidden.

Acceptance:

  • Plugin requests midi-input capability in plugin.json (roles: ["requester"], requests: ["discover", "list-sources", "select-source", "open-source", "close-source"], compatibility: "degrade-noop", ownership: "requester-only", safety: "sensitive" — mirror input_setup's declaration).
  • Works with the domain absent (fail-soft empty state, no crash).
  • Device list refreshes on replug without a page reload.

Activity

  1. pullfrog commented on Oct 4, 2026

    @pullfrog
    Contributor
  2. pullfrog commented on Oct 5, 2026

    @pullfrog
    Contributor

    PR: #10

    Adds the midi-drums plugin: it scans for input devices through window.feedBack.midiInput, opens several at once, and merges their note-ons into one stream tagged by logicalSourceKey. Ticked keys persist server-side via routes.py.

    Key decisions, and why:

    • Availability is gated on the domain (mi && mi.version === 1), never on navigator.requestMIDIAccess. Gating on the browser API would hide a usable non-Web-MIDI provider before discover() had ever run, and would claim a Host was capable when its domain is absent.
    • discover() is the permission boundary, called 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.
    • Ticks are logicalSourceKeys, never labels, and a missing device is never silently substituted. It keeps its tick and reopens on return.
    • Opens/closes for a source are serialised. The domain refcounts an open session by requester name, so two concurrent opens add one reference while two closes remove it twice, orphaning the surviving handle. This was a real bug the review caught — the first draft left two listeners installed and delivered every hit twice.
    • Only the five declared verbs are called; getSelected() is an optional optimisation, since a Host may implement only what the manifest declares.

    A pre-commit self-review surfaced four more genuine bugs, all fixed: an open() racing past the screen going inactive (stranding a session nothing would close), an unguarded getSelected() that could freeze the UI on a conforming Host, a one-shot bus subscription that silently killed replug recovery when window.feedBack appeared late, and overlapping POSTs that could roll the saved selection back.

    Verification: 89 jsdom checks and 27 FastAPI route checks against throwaway harnesses outside the tree (the repo has no build, lint, or test tooling), plus node --check and py_compile. The plugin has not been exercised against a real Host build with hardware attached — that manual pass is still outstanding, and the PR body says so.

    Settings UI and kit profiles remain in the epic (#2) as separate sub-issues.

    Task list (2/8 completed)
    • Create branch pullfrog/3-midi-input-device-access
    • Add midi-drums/plugin.json with midi-input capability declaration
    • Add midi-drums/screen.html device-setup markup
    • Add midi-drums/screen.js device layer (discover/open/close/merge/sources-changed)
    • Add midi-drums/assets/plugin.css scoped styles
    • Add midi-drums/routes.py persisting selected logicalSourceKeys
    • Add midi-drums/README.md, update root README.md + CHANGELOG.md
    • Self-review with reviewfrog subagent, verify, commit, push, open PR

    Pullfrog  | View workflow run | via Pullfrog | Using big-pickle (free) | 𝕏

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions