Get iOS Core MIDI client name to show in list of devices

拈花ヽ惹草 提交于 2020-01-23 19:00:47

问题


I have successfully got MIDI in working in my iOS app using Core MIDI. However, if I open up an app which outputs MIDI (for example, the free app Little MIDI Machine) my app does not show up in the list of possible devices (in the case of LMM, in the list named "CoreMIDI Outputs"), even though my app receives the MIDI notes anyway. Other apps do show up by name (i.e. iMS-20) How can I "advertise" my app to other MIDI apps on the same system?


回答1:


OK, after messing around for a while I've worked it out. I will do my best to explain, and if there are any errors in this info, I hope some experts feel free to chime in.

There are two ways to receive MIDI messages with Core MIDI. Either you create a MIDIPortRef as an input port with MIDIInputPortCreate, and then iterate over all possible sources, connecting with each one in turn with MIDIPortConnectSource. Or you can just create a MIDIEndpointRef as a MIDI destination with MIDIDestinationCreate - then there is no need to iterate over all the sources, and in both cases a MIDIReadProc is needed - i.e. the function you will use to read the incoming messages has exactly the same signature in both scenarios.

When you use MIDIDestinationCreate, your app shows up in other apps as a destination which can be selected. This makes much more sense than selecting input sources within your app, especially since at any given time these sources may or may not exist. But it also relies on the other app being able to select yours as a destination. Maybe both things are needed, to cover all scenarios.

I did not find any example code using MIDIDestinationCreate for inter-app communication on iOS, so I hope this info is of some use.

Anyway beware that your app needs to be set up for background audio, as per this question:

CoreMIDI/PGMidi Virtual midi error in iOS6



来源:https://stackoverflow.com/questions/15743150/get-ios-core-midi-client-name-to-show-in-list-of-devices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!