I have a Marshall CODE amplifier that can be controlled over MIDI. I can successfully change some of the controls on the amp by sending a simple MIDI message to it:
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);
The Marshall spec indicates that you can retrieve the data for an entire preset by sending a SysEx message, which I'm doing with this:
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");
}
Which appears to work, insofar as there aren't any errors and the comp() callback fires. What I can't figure out is how to get the response from the SysEx call containing the preset data.
I've tried setting up an input port and connecting it to the CODE's source, but the callback never triggers:
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");
}
I'm sure I'm missing something obvious, but it evades me right now.
Okay, I'm not sure exactly what the issue was, but I was originally trying this in a Playground, I tried creating an actual Mac app and the code above now works.