コード例 #1
0
    static String getConnectedEndpointName (MIDIEndpointRef endpoint)
    {
        String result;

        // Does the endpoint have connections?
        CFDataRef connections = nullptr;
        int numConnections = 0;

        MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);

        if (connections != nullptr)
        {
            numConnections = ((int) CFDataGetLength (connections)) / (int) sizeof (MIDIUniqueID);

            if (numConnections > 0)
            {
                const SInt32* pid = reinterpret_cast<const SInt32*> (CFDataGetBytePtr (connections));

                for (int i = 0; i < numConnections; ++i, ++pid)
                {
                    MIDIUniqueID uid = (MIDIUniqueID) ByteOrder::swapIfLittleEndian ((uint32) *pid);
                    MIDIObjectRef connObject;
                    MIDIObjectType connObjectType;
                    OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);

                    if (err == noErr)
                    {
                        String s;

                        if (connObjectType == kMIDIObjectType_ExternalSource
                             || connObjectType == kMIDIObjectType_ExternalDestination)
                        {
                            // Connected to an external device's endpoint (10.3 and later).
                            s = getEndpointName (static_cast<MIDIEndpointRef> (connObject), true);
                        }
                        else
                        {
                            // Connected to an external device (10.2) (or something else, catch-all)
                            s = getMidiObjectName (connObject);
                        }

                        if (s.isNotEmpty())
                        {
                            if (result.isNotEmpty())
                                result += ", ";

                            result += s;
                        }
                    }
                }
            }

            CFRelease (connections);
        }

        if (result.isEmpty())  // Here, either the endpoint had no connections, or we failed to obtain names for them.
            result = getEndpointName (endpoint, false);

        return result;
    }
コード例 #2
0
 void reloadDeviceList(bool advanced)
 {
     int num = MIDIGetNumberOfSources();
     m_clientFilter = !advanced;
     m_inputDevices.clear();
     for (int i = 0; i < num; ++i) {
         bool excluded = false;
         MIDIEndpointRef dest = MIDIGetSource( i );
         if (dest != 0) {
             QString name = getEndpointName(dest);
             if ( m_clientFilter &&
                     name.contains(QLatin1String("IAC"), Qt::CaseSensitive) )
                 continue;
             if ( name.contains(m_publicName))
                 continue;
             foreach( const QString& n, m_excludedNames) {
                 if (name.contains(n)) {
                     excluded = true;
                     break;
                 }
             }
             if (!excluded)
                 m_inputDevices << name;
         }
     }
コード例 #3
0
ファイル: juce_mac_CoreMidi.cpp プロジェクト: Labmind/GUI
    const String getConnectedEndpointName (MIDIEndpointRef endpoint)
    {
        String result;

        // Does the endpoint have connections?
        CFDataRef connections = 0;
        int numConnections = 0;

        MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);

        if (connections != 0)
        {
            numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));

            if (numConnections > 0)
            {
                const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));

                for (int i = 0; i < numConnections; ++i, ++pid)
                {
                    MIDIUniqueID uid = EndianS32_BtoN (*pid);
                    MIDIObjectRef connObject;
                    MIDIObjectType connObjectType;
                    OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);

                    if (err == noErr)
                    {
                        String s;

                        if (connObjectType == kMIDIObjectType_ExternalSource
                             || connObjectType == kMIDIObjectType_ExternalDestination)
                        {
                            // Connected to an external device's endpoint (10.3 and later).
                            s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
                        }
                        else
                        {
                            // Connected to an external device (10.2) (or something else, catch-all)
                            CFStringRef str = 0;
                            MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);

                            if (str != 0)
                            {
                                s = PlatformUtilities::cfStringToJuceString (str);
                                CFRelease (str);
                            }
                        }

                        if (s.isNotEmpty())
                        {
                            if (result.isNotEmpty())
                                result += ", ";

                            result += s;
                        }
                    }
                }
            }

            CFRelease (connections);
        }

        if (result.isNotEmpty())
            return result;

        // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
        return getEndpointName (endpoint, false);
    }