예제 #1
0
 void merge_endpoints(
     EndpointList & to, 
     EndpointList const & from)
 {
     size_t n = to.size();
     for (size_t i = 0; i < from.size(); ++i) {
         EndpointList::iterator end = to.begin() + n;
         if (std::find(to.begin(), end, from[i]) == end) {
             to.push_back(from[i]);
         }
     }
 }
예제 #2
0
void CAMIDIEndpoints::AddEndpoints(MIDIEndpointRef endpoint, EndpointList &eplist) {
    Endpoint *ep, *prev;
    OSStatus err;
    CFStringRef str;
    
    // Add the driver-owned endpoint
    ep = new Endpoint(endpoint, EndpointName(endpoint, false), NULL);
    eplist.push_back(ep);
    prev = ep;
    
    // Does the endpoint have connections?
    CFDataRef connections = NULL;
    int nConnected = 0;
    MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections);
    if (connections != NULL) {
        // It has connections, follow them
        nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID);
        if (nConnected) {
            const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections));
            for (int i = 0; i < nConnected; ++i, ++pid) {
                MIDIUniqueID id = 0;//EndianS32_BtoN(*pid);
                MIDIObjectRef connObject;
                MIDIObjectType connObjectType;
                err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType);
                if (err == noErr) {
                    if (connObjectType == kMIDIObjectType_ExternalSource
                        || connObjectType == kMIDIObjectType_ExternalDestination) {
                        // Connected to an external device's endpoint (10.3 and later).
                        str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true);
                    }
                    else {
                        // Connected to an external device (10.2) (or something else, catch-all)
                        str = NULL;
                        MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str);
                    }
                    if (str != NULL) {
                        ep = new Endpoint(endpoint, str, connObject);
                        eplist.push_back(ep);
                        prev->SetNext(ep);
                        prev = ep;
                    }
                }
            }
        }
    }
}