首页 > 解决方案 > 在 C/C++ 中使用 MIDISendEventList() 发送 MIDI

问题描述

我一直在努力迁移较旧的 Core MIDI 发送实现,以使用 Apple 较新的 UMP 感知 MIDI 事件列表 API 方法发送 MIDI 1.0 消息。

我已经找到了可以运行并且应该输出 MIDI 时钟消息的代码,但是当我发送它时,MIDISendEventList(...)我看不到 MIDI 接口没有输出任何内容;该方法也没有返回错误来指示问题所在。

这是我正在使用的代码:

const ByteCount clockMessageSize = 1;
const UInt32 clockMessage[clockMessageSize] = { (UInt32)0xF8 };    // MIDI clock tick 
const MIDITimeStamp timeStamp = mach_absolute_time();
MIDIEventList clockMessageEventList = {};
MIDIEventPacket* clockMessageEventListEndPacket = nullptr;

clockMessageEventListEndPacket = MIDIEventListInit(&clockMessageEventList, kMIDIProtocol_1_0);
clockMessageEventListEndPacket = MIDIEventListAdd(&clockMessageEventList, sizeof(MIDIEventList::packet), clockMessageEventListEndPacket, timeStamp, clockMessageSize, clockMessage);
                
for (NSUInteger endpointRefIndex = 0; endpointRefIndex < endPointRefsCount; ++endpointRefIndex) {
    MIDIObjectRef destinationEndpoint = endPointRefs[endpointRefIndex];
    OSStatus midiSendError = MIDISendEventList(outputPortRef, destinationEndpoint, &clockMessageEventList);
                    
    if (midiSendError != noErr) {
        printf("MIDISendEventList error: %i", (int)midiSendError);
    }
 }

clockMessageEventList.packet在配置之后但在发送之前检查显示:

(248, 0, 0, [... all zeros to index 63]) 

有谁知道我要去哪里错了?

标签: ioscmidicoremidiump

解决方案


推荐阅读