mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
CoreMidi: Added unique id property when creating virtual midi ports on macOS and iOS
This commit is contained in:
parent
829e64468f
commit
ac60ce57ce
1 changed files with 35 additions and 0 deletions
|
|
@ -186,6 +186,37 @@ namespace CoreMidiHelpers
|
|||
return result;
|
||||
}
|
||||
|
||||
static void setUniqueIdForMidiPort (MIDIObjectRef device, const String& portName, bool isInput)
|
||||
{
|
||||
String portUniqueId;
|
||||
#if defined (JucePlugin_CFBundleIdentifier)
|
||||
portUniqueId = JUCE_STRINGIFY (JucePlugin_CFBundleIdentifier);
|
||||
#else
|
||||
File appBundle (File::getSpecialLocation (File::currentApplicationFile));
|
||||
CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, appBundle.getFullPathName().toCFString(), kCFURLPOSIXPathStyle, true);
|
||||
if (bundleURL != nullptr)
|
||||
{
|
||||
CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, bundleURL);
|
||||
CFRelease (bundleURL);
|
||||
|
||||
if (bundleRef != nullptr)
|
||||
{
|
||||
if (auto bundleId = CFBundleGetIdentifier (bundleRef))
|
||||
portUniqueId = String::fromCFString (bundleId);
|
||||
|
||||
CFRelease (bundleRef);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (portUniqueId.isNotEmpty())
|
||||
{
|
||||
portUniqueId += (String ("." + portName + String (isInput ? ".input" : ".output")));
|
||||
|
||||
CHECK_ERROR (MIDIObjectSetStringProperty (device, kMIDIPropertyUniqueID, portUniqueId.toCFString()));
|
||||
}
|
||||
}
|
||||
|
||||
static StringArray findDevices (const bool forInput)
|
||||
{
|
||||
// It seems that OSX can be a bit picky about the thread that's first used to
|
||||
|
|
@ -380,6 +411,8 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
|
|||
|
||||
if (client != 0 && CHECK_ERROR (MIDISourceCreate (client, name.cfString, &endPoint)))
|
||||
{
|
||||
CoreMidiHelpers::setUniqueIdForMidiPort (endPoint, deviceName, false);
|
||||
|
||||
MidiOutput* mo = new MidiOutput (deviceName);
|
||||
mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (0, endPoint);
|
||||
return mo;
|
||||
|
|
@ -522,6 +555,8 @@ MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallba
|
|||
|
||||
if (CHECK_ERROR (MIDIDestinationCreate (client, name.cfString, midiInputProc, mpc, &endPoint)))
|
||||
{
|
||||
CoreMidiHelpers::setUniqueIdForMidiPort (endPoint, deviceName, true);
|
||||
|
||||
mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
|
||||
|
||||
mi = new MidiInput (deviceName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue