I'm working on a MacOS app where I'm utilizing MIDI. What I'd like to do is send s SysEx message to a MIDI device. Now, I've done this once in Java, but never in Swift.
And since the coremidi
library is almost totally new to me, i have no idea how this would work. What I've figured out so far is that I have to compose a MIDISysexSendRequest
, and I've come this far:
let SysEx = MIDISysexSendRequest(destination: self.endpointRef, data: UnsafePointer<UInt8>, bytesToSend: 8, complete: complete, reserved: (UInt8, UInt8, UInt8), completionProc: completionProc, completionRefCon: nil)
In this, there are a few things that confuse me:
data
variable? I know what bytes i want to send, just not how to format this for Swiftreserved
supposed to be?I couldn't find any examples or reference on these that i could use. Could someone help me/
Thanks in advance.
Reserved means you can't use it, as in: "reserved for internal use"
struct MIDISysexSendRequest
{
MIDIEndpointRef destination;
const Byte * data;
UInt32 bytesToSend;
Boolean complete;
Byte reserved[3];
MIDICompletionProc completionProc;
void * __nullable completionRefCon;
};
/*!
@struct MIDISysexSendRequest
@abstract A request to transmit a system-exclusive event.
@field destination
The endpoint to which the event is to be sent.
@field data
Initially, a pointer to the sys-ex event to be sent.
MIDISendSysex will advance this pointer as bytes are
sent.
@field bytesToSend
Initially, the number of bytes to be sent. MIDISendSysex
will decrement this counter as bytes are sent.
@field complete
The client may set this to true at any time to abort
transmission. The implementation sets this to true when
all bytes have been sent.
@field completionProc
Called when all bytes have been sent, or after the client
has set complete to true.
@field completionRefCon
Passed as a refCon to completionProc.
@discussion
This represents a request to send a single system-exclusive MIDI event to
a MIDI destination asynchronously.
*/
Notice how the reserved variable doesn't even show up in the header.
A quick google shows many projects written in swift that use MIDI. Browse through some of these to see working examples.
The first one I looked at seemed perfect for seeing how things are done. It even has quite a few .java files, so it might be easier for you to see how it relates to swift (or how to connect them).
Take a look here: MIDI in Swift
In the CoreMIDI framework there is a file called "MIDIServices.h" (finder will find it for you). It has a LOT of information regarding MIDI.
Best of luck!! 🍀