-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No luck sending/receiving MIDI on iOS #85
Comments
Hmm, I have no further idea how I can get this working as I have no iOS device and there is no known MIDI device that works on iOSSimulator. Can you try your codebase on macOS native if is also usable there? I'll be super busy until this weekend so I'll revisit after that. Thanks for your patient experiment. |
I'm looking at the Apple sample app to compare it to what the library does atm. First find is, that |
Found an issue that needs to be addressed: ISSUE: The ids of all midi devices are This results in following lines not selecting the correct port: This seems to partially fix my issue, as receiving midi data seems to work now after applying a workaround. I'll keep digging. |
Thanks for investigating the issue!
I am aware of this API. I kept it to the old API because, use of this newer API would limit the target platform to "iOS 14.0+iPadOS 14.0+Mac Catalyst 14.0+macOS 11.0+visionOS 1.0+" (copypasting from the API reference). And I could not find any decent way to detect the run-time platform version in Kotlin-Native. (IIRC there was another piece of code that gave up run-time detection in the CoreMidi implementation...) |
Found that:
|
I assume this is the reason why you're sticking with Here's another thing I'm currently investigating:
|
And here's the way I'm doing OS detection. I'm using expect/actual functions to provide this information via the respective source set: commonMain:
androidMain:
iosMain:
desktopMain (JVM):
|
I created a separate issue for the device IDs so the scope is a bit more clear. Hope that's OK. This leaves us with working MIDI receive, but non-working MIDI send for this issue. |
Alright, making progress. This works for standard MIDI messages, my huge sysex chunks still fail because they are overloading the default buffer size when calling
About the timestamp: MIDISend docs say that the OS will schedule messages with future timestamps, which I suspect to be the reason why nothing was sent even after i set the correct size parameter. Now with a zero timestamp messages get sent. One other thing I noticed is that we're ignoring the result of both |
Alright, looks like we're sending now :) Here's my send function with customizable buffer size and error handling.
|
Thanks for all those investigation. I noticed that sending MIDI output did not get recognized by CoreMIDI service on macOS either and MIDIPacketListAdd() returned null, but somehow no further luck to get alloc() working well. Now it should be almost the same as what you suggested. Let me know if it is still problematic. |
Thanks for adding the fixes so quickly! I would, however, think about reducing the default send buffer size. As far as I understood the apple docs, the PacketList is meant to compile multiple messages if necessary and then send it as a batch. In our current implementation, a new packetList gets allocated for every message we send. Meaning we're potentially allocating 1024 Bytes for sending a Note On with 3 Bytes of actual payload. It shouldn't really make a difference, since it gets cleared right after sending (memScoped), but it's not the best practice and unnecessarily boosts the memory footprint imho. I played around with allocating the exactly needed amount of bytes only (we know how big our packets are), but this would require to know the exact internal structure of the MIDIPacketList struct. And let me add another thought for future reference here: |
I think my fix (based on your implementation but modified) answers to your concern on allocation by reusing 20f683d#diff-e07e9fbc42e5823c84b08c77e235ecd206c85fdd4788f386f40b7526c509f53bR121 |
Not sure that's the way to go, because we'd need to clear the packetlist before we add a new packet, but then we don't know if it was sent yet. I'd stick with the previoussolution. In general, I think of the packetList more like a one-time container, which (in a native ios application) just compiles a list of stuff before it gets passed to the send method and then cleaned up. |
Doesn't |
Yeah, you're right, the init function should be sufficient. I'm not 100 percent sure if the garbage collection will free up the allocated memory of the arena, though. Not sure how |
Good call, it would not be required anymore. |
Once it's set in stone, I will prepare for v0.9.1 release. |
done ^ |
Test setup:
What is working:
What's not working:
Alternate approaches tried:
Further investigation results:
Both input and output report CLOSED as their connectionState immediately after MidiAccess.openIn/Output
The text was updated successfully, but these errors were encountered: