CoreMIDI:接收来自MIDISendSysex的响应

时间:2018-06-21 07:44:47

标签: swift coremidi

我有一个可以通过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");
}

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

1 个答案:

答案 0 :(得分:0)

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