我在我的 iOS 应用程序中使用 PGMidi 实现 MIDI。它工作得很好。但是,我收到了两份报告,称在某些情况下消息无法通过。第一个是在 PC 上使用 Ableton Live 进行无线传输。我知道它可以在带有 Ableton 的 Mac 上通过无线方式正常工作。另一种情况是使用 Line6 Mobilizer II。该设备显示在 MIDI 端口中,但没有注册任何 MIDI 消息。
我假设我对数据做错了什么,导致 PC 无法识别它?任何想法这可能是什么?
这是基本的 MIDI 发送内容(大部分直接来自 PGMidi)
-(void)noteOn:(NSUInteger)voice note:(NSUInteger)note{
if(voice == 1){
UInt8 status = 144 + (UInt8)chordMIDIChannel;
const UInt8 noteOn[] = { status, (UInt8)note, chordMIDIVelocity };
if(chordMIDIDest)[chordMIDIDest sendBytes:noteOn size:sizeof(noteOn)];
else [midi virtualPortSend:noteOn size:sizeof(noteOn)];
}else{
UInt8 status = 144 + (UInt8)leadMIDIChannel;
const UInt8 noteOn[] = { status, (UInt8)note, leadMIDIVelocity };
if(leadMIDIDest)[leadMIDIDest sendBytes:noteOn size:sizeof(noteOn)];
else[midi virtualPortSend:noteOn size:sizeof(noteOn)];
}
}
和 PGMidiDestination 发送字节:
- (void) sendBytes:(const UInt8*)bytes size:(UInt32)size
{
assert(size < 65536);
Byte packetBuffer[size+100];
MIDIPacketList *packetList = (MIDIPacketList*)packetBuffer;
MIDIPacket *packet = MIDIPacketListInit(packetList);
packet = MIDIPacketListAdd(packetList, sizeof(packetBuffer), packet, 0, size, bytes);
[self sendPacketList:packetList];
}
- (void) sendPacketList:(const MIDIPacketList *)packetList
{
// Send it
OSStatus s = MIDISend(midi.outputPort, endpoint, packetList);
NSLogError(s, @"Sending MIDI");
}