2

我在我的 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");
}
4

1 回答 1

0

一般来说,代码看起来是正确的,但我怀疑你正在使用的端点有什么问题。

一个简单的测试是简单地将您的数据发送到系统上的每个端点并查看会发生什么,这样您就会知道它是您的数据还是您的端点配置。

用这个替换(临时)你的 sendPacketList 函数中的代码,看看你是否在这些目的地获得数据:

    // Send it everywhere
    for (ItemCount index = 0; index < MIDIGetNumberOfDestinations(); ++index)
    {
        MIDIEndpointRef outputEndpoint = MIDIGetDestination(index);

        if (outputEndpoint)
        {
            OSStatus s = MIDISend(midi.outputPort, outputEndpoint, packetList);
            // check s for errors
        }
    }

我已经使用上面的代码发送到 MIDI 网络目的地以及 MIDI Mobilizer II 设备,并且它有效。

于 2013-03-07T07:50:27.897 回答