Skip to content

webmidi: do not call an observer callback that was not set - #259

Merged
jcelerier merged 2 commits into
masterfrom
webmidi-observer-callbacks
Sep 20, 2026
Merged

jcelerier merged 2 commits into
masterfrom
webmidi-observer-callbacks

Conversation

@jcelerier

Copy link
Copy Markdown
Member

observer_emscripten::update() calls configuration.input_added and
configuration.output_added unconditionally. Every other backend guards them
(alsa_seq/observer.hpp:272, and the rest), so an observer that only wants
inputs works everywhere except in a browser, where it throws
std::bad_function_call as soon as Web MIDI reports an output port.

Found from ossia score's device enumerator, which installs one observer per
direction: adding a MIDI input device in the web build aborted.

Also: midi1::default_api() guarded its branch on __emscripten__, which is
never defined — the macro is __EMSCRIPTEN__ — so wasm fell through to
API::DUMMY. The branch also named API::EMSCRIPTEN_WEBMIDI, which does not
exist in the enum; it is API::WEBMIDI, as observer_emscripten::get_current_api()
already returns.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SCvayD61okH7PATstw4whi

jcelerier and others added 2 commits September 20, 2026 00:35
Every other backend checks first; the browser one did not, so an observer
watching only inputs threw std::bad_function_call as soon as an output port
showed up. Also fixes the emscripten guard of midi1::default_api(), which
never matched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SCvayD61okH7PATstw4whi
stop_stream() passes one argument and read it as $1, so closing a Web MIDI
input threw a TypeError out of the destructor and aborted the program.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SCvayD61okH7PATstw4whi
@jcelerier
jcelerier merged commit fd1ecab into master Sep 20, 2026
39 of 90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant