motiz88 / react-native-midi

[WIP] Web MIDI implementation for React Native using Expo Modules
MIT License
69 stars 1 forks source link

MIDI state changes are ignored on iOS #2

Closed motiz88 closed 1 year ago

motiz88 commented 1 year ago

Core MIDI provides a richer set of events than we currently handle. It's likely some of these are relevant and need to be translated to Web MIDI statechange events. The exact set of events we must handle is still TBD.

motiz88 commented 1 year ago

It turns out that we don't currently receive any MIDINotification events (not even the ones we do handle). This is because we violate Core MIDI's threading requirements. Expo's AsyncFunction puts us on a secondary thread automatically, but it seems that we must create the MIDIClient instance on the main thread, similarly to how Chrome does it: https://chromium.googlesource.com/chromium/src/+/54d256d1fc9c6a9e7438f6f51206d1f99b1ed6b4/media/midi/midi_manager_mac.cc#118

I was able to confirm that a MIDIClient created in a RCTExecuteOnMainQueue block does receive events as expected. Managing main-thread initialisation properly may require an overhaul of the current iOS implementation; I will look into doing that soon.

The main breadcrumb that pointed me in this direction was https://stackoverflow.com/questions/19002598/midiclientcreate-notifyproc-not-getting-called.