Connecting a MIDI Endpoint Destination Ref to a MIDI Output port in iOS using Swift

I am setting up an app to send MIDI data to another app using the CoreMIDI framework. I will not be using the AudioKit framework in this app.

Code Block // Get destination Endpoint Ref
var destRef = MIDIEndpointRef()
destRef = MIDIGetDestination(destIndex)
// Create Client
var midiClientRef = MIDIClientRef()
MIDIClientCreate("Source App" as CFString, nil, nil, &midiClientRef)
// Create MIDI Source Endpoint Ref
var virtualSrcEndpointRef = MIDIEndpointRef()
MIDISourceCreate(midiClientRef, "Source App Endpoint" as CFString, &virtualSrcEndpointRef)
// Create MIDI Output port
var outputPortRef = MIDIPortRef()
MIDIOutputPortCreate(midiClientRef, "Source App Output Port" as CFString, &outputPortRef)





After that I use the MIDIReceived function to send MIDI packets to the Source Endpoint. This works, but the issue is that if there are several destination apps open, the MIDI gets played in all of them. This makes sense because there isn't an explicit connection between the client's output port and the destination endpoint. When it is the opposite, when you create a Destination Endpoint and you are receiving MIDI there is a function called MIDIPortConnectSource which establishes a connection from a source to a client's input port. I cannot find an equivalent MIDIPortConnectDestination in the CoreMIDI MIDI services APIs.

How does one make that direct connection?

Again, I will not be using AudioKit in this app.

Accepted Reply

I had been misled in my research on how to do this, that you had to use the MIDIReceived method (which was strange) to send MIDI packets to the source and then these would be sent out on the output port. Well, turns out that the answer was to use the MIDISend method which actually sends the MIDI data from an output port to the destination ref.

Replies

I had been misled in my research on how to do this, that you had to use the MIDIReceived method (which was strange) to send MIDI packets to the source and then these would be sent out on the output port. Well, turns out that the answer was to use the MIDISend method which actually sends the MIDI data from an output port to the destination ref.