为什么这个简单的CoreMIDI程序不能产生MIDI输出? [英] Why doesn't this simple CoreMIDI program produce MIDI output?
问题描述
这是一个非常简单的CoreMIDI OS X应用程序,可以发送MIDI数据.问题是它不起作用.它可以很好地编译并运行.它不会报告任何错误,并且不会崩溃.创建的源在MIDI监视器中变为可见.但是,没有MIDI数据出.
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 not crash. The Source created becomes visible in MIDI Monitor. However, no MIDI data comes out.
有人可以让我知道我在做什么错吗?
Could somebody let me know what I'm doing wrong here?
#include <CoreMIDI/CoreMIDI.h>
int main(int argc, char *args[])
{
MIDIClientRef theMidiClient;
MIDIEndpointRef midiOut;
MIDIPortRef outPort;
char pktBuffer[1024];
MIDIPacketList* pktList = (MIDIPacketList*) pktBuffer;
MIDIPacket *pkt;
Byte midiDataToSend[] = {0x91, 0x3c, 0x40};
int i;
MIDIClientCreate(CFSTR("Magical MIDI"), NULL, NULL,
&theMidiClient);
MIDISourceCreate(theMidiClient, CFSTR("Magical MIDI Source"),
&midiOut);
MIDIOutputPortCreate(theMidiClient, CFSTR("Magical MIDI Out Port"),
&outPort);
pkt = MIDIPacketListInit(pktList);
pkt = MIDIPacketListAdd(pktList, 1024, pkt, 0, 3, midiDataToSend);
for (i = 0; i < 100; i++) {
if (pkt == NULL || MIDISend(outPort, midiOut, pktList)) {
printf("failed to send the midi.\n");
} else {
printf("sent!\n");
}
sleep(1);
}
return 0;
}
推荐答案
您正在调用MIDISourceCreate
来创建虚拟MIDI源.
You're calling MIDISourceCreate
to create a virtual MIDI source.
这意味着您的音源将出现在其他应用程序的MIDI设置UI中,并且这些应用程序可以选择是否收听您的音源.您的MIDI不会发送到任何物理MIDI端口,除非有其他应用程序将其引导到那里.这也意味着您的应用程序无法选择发送到MIDI的位置.我假设这就是您想要的.
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.