如何使用CoreMidi在iO上发送多个同时的NoteOn消息?

时间:2018-07-12 21:31:34

标签: ios objective-c midi simultaneous coremidi

由于某种原因,当我尝试使用CORE-MIDI通过USB发送3条关于Midi消息时,输出设备仅播放一个音符,这是我的代码Objectivc-C

    const UInt8 noteOn[]  = { 0x90, 60, 127 };
    const UInt8 noteOn2[] = { 0x90, 64, 127 };
    const UInt8 noteOn3[] = { 0x90, 68, 127 };
    UInt32 size0 = sizeof(noteOn);

    NSLog(@"%s(%u bytes to core MIDI)", __func__, unsigned(size0));
    assert(size0 < 65536);
    Byte packetBuffer[size0*3+100];
    MIDIPacketList *packetList = (MIDIPacketList*)packetBuffer;
    MIDIPacket     *packet     = MIDIPacketListInit(packetList);

    packet = MIDIPacketListAdd(packetList, sizeof(packetBuffer), packet, 0, size0, noteOn);
    packet = MIDIPacketListAdd(packetList, sizeof(packetBuffer), packet, 0, size0, noteOn2);
    packet = MIDIPacketListAdd(packetList, sizeof(packetBuffer), packet, 0, size0, noteOn3);

    for (ItemCount index = 0; index < MIDIGetNumberOfDestinations(); ++index)
{
    MIDIEndpointRef outputEndpoint = MIDIGetDestination(index);
    if (outputEndpoint)
    {
        // Send it
        OSStatus s = MIDISend(outputPort, outputEndpoint, packetList);
        NSLogError(s, @"Sending MIDI");
    }
}

如何同时发送这3条NOTE Midi消息?

关于ObjetiveC或Swift的任何示例都会有所帮助。

0 个答案:

没有答案