Browse Source

CoreMidi: Added unique id property when creating virtual midi ports on macOS and iOS

tags/2021-05-28
hogliux 8 years ago
parent
commit
ac60ce57ce
1 changed files with 35 additions and 0 deletions
  1. +35
    -0
      modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp

+ 35
- 0
modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp View File

@@ -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…
Cancel
Save