您的描述也正是我发送 MIDI 数据的方式,而且效果很好。也许你可以发布你的源代码,没有它就很难猜出哪里出了问题。
另外,为了测试,尝试将时间戳设置为零,以确保您能够发送 MIDI,之后您可以将时间戳放回以单独调试它们。
代替源代码,这是一个发送 MIDI 的简单方法,我确实从 NSTimer 调用它,它基于一些 Apple 示例并且它有效。注意 'outputPort' 是您在尝试将 MIDI 与您的客户端 ref 一起发送之前应该在某处创建的东西(我假设您已经这样做了)
OSStatus s;
MIDIClientRef client;
MIDIPortRef outputPort;
s = MIDIClientCreate((CFStringRef)@"My Test MIDI Client", MyMIDINotifyProc, self, &client);
s = MIDIOutputPortCreate(client, (CFStringRef)@"My Test MIDI Output Port", &outputPort);
一旦你有了这些,你就可以发送 MIDI
- (void) MySendMidi:(const UInt8*)data size:(UInt32)bsize
{
NSLog(@"%s(%u bytes to core MIDI)", __func__, unsigned(bsize));
assert(bsize < 65536);
Byte packetBuffer[bsize+100];
MIDIPacketList *packetList = (MIDIPacketList*)packetBuffer;
MIDIPacket *packet = MIDIPacketListInit(packetList);
packet = MIDIPacketListAdd(packetList, sizeof(packetBuffer), packet, 0, bsize, data);
// Send it to every destination in the system...
for (ItemCount index = 0; index < MIDIGetNumberOfDestinations(); ++index)
{
MIDIEndpointRef outputEndpoint = MIDIGetDestination(index);
if (outputEndpoint)
{
// Send it
OSStatus s = MIDISend(outputPort, outputEndpoint, packetList);
}
}
}