int _lp_is_device_online(MIDIDeviceRef d) { SInt32 offline; MIDIObjectGetIntegerProperty(d, kMIDIPropertyOffline, &offline); return !offline; }
void MIDIOut::rescanDevices() { /* Treat all devices nonexistent and doomed for destruction */ QList <MIDIDevice*> destroyList(m_devices); /* Find out which devices are still present */ for (ItemCount i = 0; i < MIDIGetNumberOfDevices(); i++) { MIDIDeviceRef dev = MIDIGetDevice(i); for (ItemCount j = 0; j < MIDIDeviceGetNumberOfEntities(dev); j++) { MIDIEntityRef entity = MIDIDeviceGetEntity(dev, j); OSStatus s = 0; SInt32 uid = 0; /* Check if the entity is able to send data */ if (MIDIEntityGetNumberOfDestinations(entity) == 0) continue; /* Extract UID from the entity */ s = MIDIObjectGetIntegerProperty(entity, kMIDIPropertyUniqueID, &uid); if (s != 0) { qWarning() << "Unable to get entity UID"; continue; } MIDIDevice* dev(deviceByUID(uid)); if (dev != NULL) { /* Device still exists */ destroyList.removeAll(dev); } else { /* New device */ dev = new MIDIDevice(this, entity); Q_ASSERT(dev != NULL); if (dev->extractUID() == true && dev->extractName() == true) { addDevice(dev); } else { delete dev; dev = NULL; } } } } /* Destroy all devices that were no longer present */ while (destroyList.isEmpty() == false) delete destroyList.takeFirst(); }
QVariant MidiEnumeratorPrivate::extractUID(MIDIEntityRef entity) { qDebug() << Q_FUNC_INFO; SInt32 uid = 0; if (MIDIObjectGetIntegerProperty(entity, kMIDIPropertyUniqueID, &uid) != 0) { qWarning() << Q_FUNC_INFO << "Unable to get UID from MIDI entity" << entity; return QVariant(); } else { return QVariant(uid); } }
CAMIDIEndpoints::Endpoint::Endpoint(MIDIEndpointRef endpoint, CFStringRef name, MIDIObjectRef connectedObj) : mUniqueID(kMIDIInvalidUniqueID), mIOEndpoint(endpoint), mName(name), mEntity(NULL), mEmbeddedOrVirtual(false), mConnectedObj(connectedObj), mNext(NULL), mPairMate(NULL) { MIDIObjectGetIntegerProperty(connectedObj ? connectedObj : endpoint, kMIDIPropertyUniqueID, &mUniqueID); // Is the endpoint that of an embedded entity? or virtual? MIDIEndpointGetEntity(endpoint, &mEntity); if (mEntity == NULL) { mEmbeddedOrVirtual = true; // presumably virtual } else { SInt32 embedded = 0; MIDIObjectGetIntegerProperty(mEntity, kMIDIPropertyIsEmbeddedEntity, &embedded); if (embedded) { mEmbeddedOrVirtual = true; } } }
SInt32 MidiDeviceUtil::IsEndpointOffline(int deviceIndex, int entityIndex, int sourceIndex) { MIDIEndpointRef endpoint = GetMidiEndpoint(deviceIndex, entityIndex, sourceIndex); SInt32 isOffline; OSStatus err = MIDIObjectGetIntegerProperty(endpoint, kMIDIPropertyOffline, &isOffline); if (err == 0) { //TODO:Error } return isOffline; }
bool MIDIDevice::extractUID() { OSStatus s; SInt32 uid; /* Get the UID property */ s = MIDIObjectGetIntegerProperty(m_entity, kMIDIPropertyUniqueID, &uid); if (s == 0) { m_uid = uid; return true; } else { m_uid = -1; qWarning() << "Unable to get UID for MIDI entity:" << s; return false; } }
// // @see com.sun.media.sound.AbstractMidiDeviceProvider.getDeviceInfo(). static int getEndpointProperty(int direction, INT32 deviceID, char *buffer, int bufferLength, CFStringRef propertyID) { if (deviceID < 0) { return MIDI_INVALID_DEVICEID; } MIDIEndpointRef endpoint; if (direction == MIDI_IN) { endpoint = MIDIGetSource(deviceID); } else if (direction == MIDI_OUT) { endpoint = MIDIGetDestination(deviceID); } else { return MIDI_INVALID_ARGUMENT; } if (!endpoint) { return MIDI_INVALID_DEVICEID; } int status = MIDI_SUCCESS; if (propertyID == kMIDIPropertyDriverVersion) { SInt32 driverVersion; status = MIDIObjectGetIntegerProperty(endpoint, kMIDIPropertyDriverVersion, &driverVersion); if (status != MIDI_SUCCESS) return status; snprintf(buffer, bufferLength, "%d", (int) driverVersion); } else { CFStringRef pname; status = MIDIObjectGetStringProperty(endpoint, propertyID, &pname); if (status != MIDI_SUCCESS) return status; CFStringExtractCString(pname, buffer, bufferLength, 0); } return MIDI_ERROR_NONE; }
void MidiApple::openDevices() { qDebug("openDevices"); m_inputDevices.clear(); // How many MIDI devices do we have? ItemCount deviceCount = MIDIGetNumberOfDevices(); // Iterate through all MIDI devices for (ItemCount i = 0 ; i < deviceCount ; ++i) { // Grab a reference to current device MIDIDeviceRef device = MIDIGetDevice(i); char * deviceName = getName(device); QString qsDeviceName = QString::fromUtf8((char*)(deviceName)); qDebug("Device name:%s",deviceName); // Is this device online? (Currently connected?) SInt32 isOffline = 0; MIDIObjectGetIntegerProperty(device, kMIDIPropertyOffline, &isOffline); qDebug(" is online: %s", (isOffline ? "No" : "Yes")); // How many entities do we have? ItemCount entityCount = MIDIDeviceGetNumberOfEntities(device); // Iterate through this device's entities for (ItemCount j = 0 ; j < entityCount ; ++j) { // Grab a reference to an entity MIDIEntityRef entity = MIDIDeviceGetEntity(device, j); qDebug(" Entity: %s", getName(entity)); // Iterate through this device's source endpoints (MIDI In) ItemCount sourceCount = MIDIEntityGetNumberOfSources(entity); for ( ItemCount k = 0 ; k < sourceCount ; ++k ) { // Grab a reference to a source endpoint MIDIEndpointRef source = MIDIEntityGetSource(entity, k); char * name = getName(source); qDebug(" Source: '%s'", name); QString sourceName = qsDeviceName + ":" + QString::fromUtf8((char*)(name)); qDebug(" Source name: '%s'", sourceName.toLatin1().constData() ); m_inputDevices.insert(sourceName, source); openMidiReference(source,sourceName,true); } // Iterate through this device's destination endpoints (MIDI Out) ItemCount destCount = MIDIEntityGetNumberOfDestinations(entity); for ( ItemCount k = 0 ; k < destCount ; ++k ) { // Grab a reference to a destination endpoint MIDIEndpointRef dest = MIDIEntityGetDestination(entity, k); char * name = getName(dest); qDebug(" Destination: '%s'", name); QString destinationName = qsDeviceName + ":" + QString::fromUtf8((char*)(name)); qDebug(" Destination name: '%s'", destinationName.toLatin1().constData() ); m_outputDevices.insert(destinationName, dest); openMidiReference(dest,destinationName,false); } } qDebug("------"); } printQStringKeys("m_inputDevices:",m_inputDevices); printQStringKeys("m_outputDevices:",m_outputDevices); }
int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed) { OSStatus error; PyrSlot *a = g->sp; int numSrc = (int)MIDIGetNumberOfSources(); int numDst = (int)MIDIGetNumberOfDestinations(); PyrObject* idarray = newPyrArray(g->gc, 6 * sizeof(PyrObject), 0 , true); SetObject(a, idarray); PyrObject* idarraySo = newPyrArray(g->gc, numSrc * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarraySo); g->gc->GCWrite(idarray, idarraySo); PyrObject* devarraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarraySo); g->gc->GCWrite(idarray, devarraySo); PyrObject* namearraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearraySo); g->gc->GCWrite(idarray, namearraySo); PyrObject* idarrayDe = newPyrArray(g->gc, numDst * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarrayDe); g->gc->GCWrite(idarray, idarrayDe); PyrObject* namearrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearrayDe); g->gc->GCWrite(idarray, namearrayDe); PyrObject* devarrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarrayDe); g->gc->GCWrite(idarray, devarrayDe); for (int i=0; i<numSrc; ++i) { MIDIEndpointRef src = MIDIGetSource(i); SInt32 id; MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(src, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual sources don't have entities if(error) { MIDIObjectGetStringProperty(src, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearraySo->slots+i, string); namearraySo->size++; g->gc->GCWrite(namearraySo, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarraySo->slots+i, devstring); devarraySo->size++; g->gc->GCWrite(devarraySo, (PyrObject*)devstring); SetInt(idarraySo->slots+i, id); idarraySo->size++; CFRelease(devname); CFRelease(endname); } // post("numDst %d\n", numDst); for (int i=0; i<numDst; ++i) { MIDIEndpointRef dst = MIDIGetDestination(i); SInt32 id; MIDIObjectGetIntegerProperty(dst, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(dst, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual destinations don't have entities either if(error) { MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearrayDe->slots+namearrayDe->size++, string); g->gc->GCWrite(namearrayDe, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarrayDe->slots+devarrayDe->size++, devstring); g->gc->GCWrite(devarrayDe, (PyrObject*)devstring); SetInt(idarrayDe->slots+idarrayDe->size++, id); CFRelease(devname); CFRelease(endname); } return errNone; }
OSStatus USBMIDIDeviceManager::UseDeviceAndInterface(USBDevice * usbDevice, USBInterface * usbInterface) { // Match the device that was just located with what is in the current state MIDIDeviceRef midiDevice = NULL; IOUSBDeviceInterface **devIntf = usbDevice->GetPluginInterface(); const IOUSBDeviceDescriptor *devDesc = usbDevice->GetDeviceDescriptor(); bool deviceInSetup = false; UInt32 vendorProduct = ((UInt32)USBToHostWord(devDesc->idVendor) << 16) | USBToHostWord(devDesc->idProduct); CFStringRef serialNumber = usbDevice->GetString(devDesc->iSerialNumber); OSStatus err; UInt32 locationID; require_noerr(err = (*devIntf)->GetLocationID(devIntf, &locationID), errexit); { // See if it's already in the setup MIDIDeviceListRef curDevices = MIDIGetDriverDeviceList(mDriver->Self()); int nDevices = MIDIDeviceListGetNumberOfDevices(curDevices), firstPass, lastPass; if (serialNumber == NULL) { firstPass = 2; lastPass = 3; } else { firstPass = 1; lastPass = 1; } for (int pass = firstPass; pass <= lastPass && !deviceInSetup; ++pass) { // pass 1: match by serial number if present (skipped if not) // pass 2: match by locationID // pass 3: match by order found for (int iDevice = 0; iDevice < nDevices; ++iDevice) { SInt32 prevLocation, prevVendorProduct, isOffline; midiDevice = MIDIDeviceListGetDevice(curDevices, iDevice); err = MIDIObjectGetIntegerProperty(midiDevice, kUSBVendorProductProperty, &prevVendorProduct); if (!err && UInt32(prevVendorProduct) == vendorProduct) { switch (pass) { case 1: { CFStringRef prevSerial; err = MIDIObjectGetStringProperty(midiDevice, kSerialNumberProperty, &prevSerial); if (!err) { if (CFEqual(prevSerial, serialNumber)) deviceInSetup = true; CFRelease(prevSerial); } } break; case 2: err = MIDIObjectGetIntegerProperty(midiDevice, kUSBLocationProperty, &prevLocation); if (!err && UInt32(prevLocation) == locationID) deviceInSetup = true; break; case 3: err = MIDIObjectGetIntegerProperty(midiDevice, kMIDIPropertyOffline, &isOffline); if (!err && isOffline) deviceInSetup = true; break; } } if (deviceInSetup) break; } } MIDIDeviceListDispose(curDevices); } if (!deviceInSetup) { #if VERBOSE printf("creating new device\n"); #endif midiDevice = mDriver->CreateDevice(usbDevice, usbInterface); require_noerr(err = MIDISetupAddDevice(midiDevice), errexit); } else { #if VERBOSE printf("old device found\n"); #endif mDriver->PreExistingDeviceFound(midiDevice, usbDevice, usbInterface); } // set device properties unconditionally MIDIObjectSetIntegerProperty(midiDevice, kUSBVendorProductProperty, vendorProduct); MIDIObjectSetIntegerProperty(midiDevice, kUSBLocationProperty, locationID); if (serialNumber != NULL) MIDIObjectSetStringProperty(midiDevice, kSerialNumberProperty, serialNumber); // Create a USBMIDIDevice (or subclass), starting it for I/O { USBMIDIDevice *ioDev = mDriver->CreateUSBMIDIDevice(usbDevice, usbInterface, midiDevice); if (ioDev == NULL) goto errexit; if (!ioDev->Initialize()) delete ioDev; else { if (mUSBMIDIDeviceList.size() == 0) mUSBMIDIDeviceList.reserve(4); mUSBMIDIDeviceList.push_back(ioDev); MIDIObjectSetIntegerProperty(midiDevice, kMIDIPropertyOffline, false); } } errexit: if (serialNumber != NULL) CFRelease(serialNumber); return err; }