CoreMIDI:接收来自 MIDISendSysex 的响应

CoreMIDI: Receiving a response from MIDISendSysex

我有一个可以通过 MIDI 控制的 Marshall CODE 放大器。我可以通过向它发送一个简单的 MIDI 消息来成功地更改放大器上的一些控件:

var midiClient: MIDIClientRef = 0;
var outPort:MIDIPortRef = 0;
MIDIClientCreate("MidiTestClient" as CFString, nil, nil, &midiClient);
MIDIOutputPortCreate(midiClient, "MidiTest_OutPort" as CFString, &outPort);

var packet1:MIDIPacket = MIDIPacket();
packet1.timeStamp = 0;
packet1.length = 3;
packet1.data.0 = 0xB0;
packet1.data.1 = 0x46;
packet1.data.2 = 0x64;    
var packetList:MIDIPacketList = MIDIPacketList(numPackets: 1, packet: packet1);

let dest:MIDIEndpointRef = MIDIGetDestination(0);
MIDISend(outPort, dest, &packetList);

Marshall spec 表示您可以通过发送 SysEx 消息来检索整个预设的数据,我正在这样做:

var method:MIDICompletionProc = comp
let buffer:UnsafePointer<UInt8> = UnsafePointer([0xF0,0x00,0x21,0x15,0x7F,0x7F,0x7F,0x72,0x01,0x00,0xF7])    
var sendRequest = MIDISysexSendRequest(destination: dest,
                                       data: buffer,
                                       bytesToSend: 11,
                                       complete: false,
                                       reserved: (0, 0, 0),
                                       completionProc: method,
                                       completionRefCon: UnsafeMutableRawPointer(&method))
MIDISendSysex(&sendRequest);
CFRunLoopRun();

func comp(req: UnsafeMutablePointer<MIDISysexSendRequest>) -> Void {
    print("Complete");
}

这似乎有效,因为没有任何错误并且 comp() 回调触发。我想不通的是如何从包含预设数据的 SysEx 调用中获取响应。

我尝试设置一个输入端口并将其连接到 CODE 的源,但回调从未触发:

var inPort:MIDIPortRef = 0;
MIDIInputPortCreate(midiClient, "MidiTest_InPort" as CFString, midiInputCallback, nil, &inPort);
let endpoint:MIDIEndpointRef = MIDIGetSource(0);
MIDIPortConnectSource(inPort, endpoint, nil);

func midiInputCallback (pktList: UnsafePointer<MIDIPacketList>,
                    readProcRefCon: UnsafeMutableRawPointer?, srcConnRefCon: UnsafeMutableRawPointer?) -> Void
{
    print("midiInputCallback was called");
}

我确定我遗漏了一些明显的东西,但它现在让我回避了。

好吧,我不确定到底是什么问题,但我最初是在 Playground 中尝试这个,我尝试创建一个实际的 Mac 应用程序,上面的代码现在可以工作了。