jazz-midi icon indicating copy to clipboard operation
jazz-midi copied to clipboard

fix: devices not updating when running in node.js

Open dopry opened this issue 7 months ago • 2 comments

fixes #8

When running in node there is no CFRunLoop to drive CoreMIDI internal updates. see: https://developer.apple.com/documentation/corefoundation/cfrunloop

There are two ways to address the issue.

  1. start the loop in a separate thread when needed
  2. drive the loop manually with CFRunLoop

This implementation is 2. It's a brute force and probably has some minor performance impact since we yield to the loop on each call to MidiInfo MidiList and a few other places. It would probably be far better to spawn a thread but I'm not a very strong C++ developer and my skills with low level threading are super rusty. It looks like some code was started to enable this external threading. I'm hoping the brute force approach is acceptable as a bug fix, until someone with more experience in native module development and OSX is able to do something better or I find some time to bang on this again.

dopry avatar Jun 01 '25 22:06 dopry

Could this potentially address #5 also?

@matthewjumpsoffbuildings not really. I'm not that good of a C developer. Feel free to have it yourself if it's a problem for you. I switched to https://www.npmjs.com/package/@julusian/midi since it seems to be the most actively maintained of the node.js midi modules currently.

dopry avatar Jul 02 '25 23:07 dopry