-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add native MIDI support for Mac OSX via Core MIDI API #395
base: master
Are you sure you want to change the base?
Conversation
File change notes: - CMakeLists.txt: - link required Core API libraries on OSX - src/MusicSrc/MusicDevice.c: - include relevant headers for native MIDI support on OSX - add Core MIDI handles to native MIDI device struct on OSX - change Windows NativeMidiSendMessage() to take a pointer for outHandle so that calling code can stay common between that and OSX - add device name lookup utilities from rtmidi library - implement Core MIDI based NativeMidiSendMessage() function - implement Core MIDI device init/destroy and device query logic - update NativeMidiSendMessage() callers to pass outHandle as pointer for Windows and OSX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some CoreFoundation memory changes that I'm not sure about (CFRelease
on functions that are "Get" and not "Copy" or "Create") and some places where the usage of the CFSTR()
macro might make more sense.
src/MusicSrc/MusicDevice.c
Outdated
} | ||
|
||
// some MIDI devices have a leading space in endpoint name. trim | ||
CFStringRef space = CFStringCreateWithCString(NULL, " ", kCFStringEncodingUTF8); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/MusicSrc/MusicDevice.c
Outdated
if (str) | ||
{ | ||
CFStringAppend(result, str); | ||
CFRelease(str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see anything in MIDIObjectGetStringProperty
that suggests that the property should be released, so I'm assuming it follows the "Get" rule.
In other words, it shouldn't be released.
if (CFStringGetLength(result) == 0 ) | ||
{ | ||
CFRelease(result); | ||
return str; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/MusicSrc/MusicDevice.c
Outdated
#elif defined(__APPLE__) | ||
// create Core MIDI client | ||
if (ndev->midiClient) WARN("NativeMidiInit(): midiClient != 0"); | ||
const CFStringRef clientNameRef = CFStringCreateWithCString(NULL, "systemshockClient", kCFStringEncodingASCII); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another use of CFSTR()
const CFStringRef clientNameRef = CFSTR("systemshockClient");
const OSStatus clientResult = MIDIClientCreate(clientNameRef, NULL, NULL, &(ndev->midiClient));
//CFRelease(clientNameRef); // Has no effect on CFStrings created with CFSTR
src/MusicSrc/MusicDevice.c
Outdated
} | ||
// create output port | ||
if (ndev->outHandle.outputPort) WARN("NativeMidiInit(): outputPort != 0"); | ||
const CFStringRef portNameRef = CFStringCreateWithCString(NULL, "systemshockPort", kCFStringEncodingASCII); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same CFSTR()
comment.
Fix possible memory management errors. Rename some functions to better match CoreFoundation naming conventions (this is not needed, just makes me feel better). Replace unneeded calls to CFStringCreateWithCString with just the CFSTR macro.
Fix typo.
You can see what I meant with my own pull request to your pull request: HunterZ#2 |
Update MusicDevice.c
Thanks. I don't know much about coremidi and was just going off of what examples I could find, so I'm happy to merge in your suggestions. |
A couple of years ago I contributed native MIDI support for Windows and Linux, but was not able to do so for Mac OSX because I lacked a workable development environment. This has been remedied, and I was able to implement and test Core MIDI support in an OSX Mojave VM talking to a real Roland SC-88 via a USB-MIDI interface.
As with Windows, support for this is automatically enabled in OSX builds because it's an OS-provided functionality.
File change notes: