Sending a system exclusive message using CoreMIDI
I am working on a macOS application where I am using MIDI. What I would like to do is send a SysEx message to the MIDI device. Now I have done this once in Java, but have never been to Swift.
And since the library coremidi
is almost completely new to me, I have no idea how it will work. So far, I've figured out what I have to compose 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)
There are several things about this that confuse me:
- How should I compose a variable
data
? I know what bytes I want to send, just not how to format this for Swift - It is assumed that
reserved
?
I couldn't find any examples or links to them that I could use. Can someone help me /
Thanks in advance.
source to share
Reserved means you cannot 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 appear in the header.
A quick google shows many swift projects that use MIDI. Check out some of them to see working examples.
The first one I looked at seemed perfect for understanding how things are done. It even has quite a few .java files in it, so it might be easier for you to see how this relates to swift (or how to include them).
Take a look here: MIDI in Swift
Within the CoreMIDI structure, there is a file called "MIDIServices.h" (the search engine will find it for you). It contains a lot of information about MIDI.
Good luck! 🍀
source to share