Why doesn't this simple CoreMIDI program produce MIDI output?

后端 未结 4 546
独厮守ぢ
独厮守ぢ 2020-12-23 23:56

Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn\'t work. It compiles fine, and runs. It reports no errors, and does

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 00:42

    You're calling MIDISourceCreate to create a virtual MIDI source.

    This means that your source will appear in other apps' MIDI setup UI, and that those apps can choose whether or not to listen to your source. Your MIDI will not get sent to any physical MIDI ports, unless some other app happens to channel it there. It also means that your app has no choice as to where the MIDI it's sending goes. I'm assuming that's what you want.

    The documentation for MIDISourceCreate says:

    After creating a virtual source, use MIDIReceived to transmit MIDI messages from your virtual source to any clients connected to the virtual source.

    So, do two things:

    • Remove the code that creates the output port. You don't need it.
    • change MIDISend(outPort, midiOut, pktList) to: MIDIReceived(midiOut, pktlist).

    That should solve your problem.

    So what are output ports good for? If you wanted to direct your MIDI data to a specific destination -- maybe a physical MIDI port -- you would NOT create a virtual MIDI source. Instead:

    1. Call MIDIOutputPortCreate() to make an output port
    2. Use MIDIGetNumberOfDestinations() and MIDIGetDestination() to get the list of destinations and find the one you're interested in.
    3. To send MIDI to one destination, call MIDISend(outputPort, destination, packetList).

提交回复
热议问题