char *mus_midi_describe(void) { int i, n; MIDIDeviceRef dev; CFStringRef cs1, cs2, cs3; char name[64], mfg[64], model[64], all[192]; char *buf; n = MIDIGetNumberOfDevices(); if (n <= 0) buf = (char *)CALLOC(192, sizeof(char)); else buf = (char *)CALLOC(n * 192, sizeof(char)); if (n <= 0) sprintf(buf, "no midi"); else { for (i = 0; i < n; i++) { dev = MIDIGetDevice(i); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &cs1); MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &cs2); MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &cs3); CFStringGetCString(cs1, name, sizeof(name), 0); CFStringGetCString(cs2, mfg, sizeof(mfg), 0); CFStringGetCString(cs3, model, sizeof(model), 0); CFRelease(cs1); CFRelease(cs2); CFRelease(cs3); sprintf(all, "%s (%s): %s\n", name, mfg, model); strcat(buf, all); } } return(buf); }
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(); }
//_________________________________________________________ // Find the device model associated to a MIDIEndpointRef Boolean GetModel (MIDIEndpointRef device, char* gmodel, int strlen) { int i,j,k, n,m,o,p; MIDIDeviceRef dev; MIDIEntityRef ref; CFStringRef pmodel; OSStatus err; n = MIDIGetNumberOfDevices(); for (i = 0; i < n; i++) { dev = MIDIGetDevice(i); err = MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel); if (err == noErr) { if (!CFStringGetCString(pmodel, gmodel, strlen, 0)) { fprintf(stderr, "GetModel error : string too long\n"); return false; } CFRelease(pmodel); m = MIDIDeviceGetNumberOfEntities(dev); for (j = 0; j < m; j++) { ref = MIDIDeviceGetEntity(dev,j); o = MIDIEntityGetNumberOfSources(ref); p = MIDIEntityGetNumberOfDestinations(ref); for (k = 0; k < o; k++) { if (MIDIEntityGetSource(ref,k) == device) return true; } for (k = 0; k < p; k++) { if (MIDIEntityGetDestination(ref,k) == device) return true; } } } } return false; }
void MidiUtil::printDevices() { #if defined(ARK2D_MACINTOSH) ItemCount numOfDevices = MIDIGetNumberOfDevices(); for (int i = 0; i < numOfDevices; i++) { MIDIDeviceRef midiDevice = MIDIGetDevice(i); NSDictionary* midiProperties; CFDictionaryRef midiPropertiesCF = (__bridge CFDictionaryRef )midiProperties; MIDIObjectGetProperties(midiDevice, (CFPropertyListRef* )&midiPropertiesCF, YES); midiProperties = CFBridgingRelease(midiPropertiesCF); NSLog(@"Midi properties: %d \n %@", i, midiProperties); } #else ARK2D::getLog()->w("MidiUtil::printDevices not available on this platform."); #endif }
lp_device_t lp_get_device() { _lp_ctx_create(); for(int i=0;i<MIDIGetNumberOfDevices();++i) { MIDIDeviceRef d = MIDIGetDevice(i); if(!_lp_is_launchpad(d) || !_lp_is_device_online(d)) continue; MIDIEntityRef entity = MIDIDeviceGetEntity(d, 0); MIDIEndpointRef source = MIDIEntityGetSource(entity, 0); MIDIEndpointRef dest = MIDIEntityGetDestination(entity, 0); lp_device_t device = _lp_create_device(d, dest, 0); MIDIPortConnectSource(_lp_ctx.inport, source, device); _lp_set_is_s(device); lp_send_reset(device); return device; } return NULL; }
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 main(int argc, char *argv[]) { if (argc >= 2) { // first argument, if present, is the MIDI channel number to echo to (1-16) sscanf(argv[1], "%d", &gChannel); if (gChannel < 1) gChannel = 1; else if (gChannel > 16) gChannel = 16; --gChannel; // convert to 0-15 } // create client and ports MIDIClientRef client = NULL; MIDIClientCreate(CFSTR("MIDI Echo"), NULL, NULL, &client); MIDIPortRef inPort = NULL; MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL, &inPort); MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort); // enumerate devices (not really related to purpose of the echo program // but shows how to get information about devices) int i, n; CFStringRef pname, pmanuf, pmodel; char name[64], manuf[64], model[64]; n = MIDIGetNumberOfDevices(); for (i = 0; i < n; ++i) { MIDIDeviceRef dev = MIDIGetDevice(i); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &pname); MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &pmanuf); MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel); CFStringGetCString(pname, name, sizeof(name), 0); CFStringGetCString(pmanuf, manuf, sizeof(manuf), 0); CFStringGetCString(pmodel, model, sizeof(model), 0); CFRelease(pname); CFRelease(pmanuf); CFRelease(pmodel); printf("name=%s, manuf=%s, model=%s\n", name, manuf, model); } // open connections from all sources n = MIDIGetNumberOfSources(); printf("%d sources\n", n); for (i = 0; i < n; ++i) { MIDIEndpointRef src = MIDIGetSource(i); MIDIPortConnectSource(inPort, src, NULL); } // find the first destination n = MIDIGetNumberOfDestinations(); if (n > 0) gDest = MIDIGetDestination(0); if (gDest != NULL) { MIDIObjectGetStringProperty(gDest, kMIDIPropertyName, &pname); CFStringGetCString(pname, name, sizeof(name), 0); CFRelease(pname); printf("Echoing to channel %d of %s\n", gChannel + 1, name); } else { printf("No MIDI destinations present\n"); } CFRunLoopRun(); // run until aborted with control-C return 0; }
void MidiEnumeratorPrivate::rescan() { qDebug() << Q_FUNC_INFO; bool changed = false; QList <MidiOutputDevice*> destroyOutputs(m_outputDevices); QList <MidiInputDevice*> destroyInputs(m_inputDevices); /* Find out which devices are still present */ ItemCount numDevices = MIDIGetNumberOfDevices(); for (ItemCount devIndex = 0; devIndex < numDevices; devIndex++) { MIDIDeviceRef dev = MIDIGetDevice(devIndex); ItemCount numEntities = MIDIDeviceGetNumberOfEntities(dev); for (ItemCount entIndex = 0; entIndex < numEntities; entIndex++) { MIDIEntityRef entity = MIDIDeviceGetEntity(dev, entIndex); /* Get the entity's UID */ QVariant uid = extractUID(entity); if (uid.isValid() == false) continue; QString name = extractName(entity); qDebug() << Q_FUNC_INFO << "Found device:" << name << "UID:" << uid.toString(); ItemCount destCount = MIDIEntityGetNumberOfDestinations(entity); if (destCount > 0) { MidiOutputDevice* dev = outputDevice(uid); if (dev == NULL) { CoreMidiOutputDevice* dev = new CoreMidiOutputDevice( uid, name, entity, m_client, this); m_outputDevices << dev; changed = true; } else { destroyOutputs.removeAll(dev); } } ItemCount srcCount = MIDIEntityGetNumberOfSources(entity); if (srcCount > 0) { MidiInputDevice* dev = inputDevice(uid); if (dev == NULL) { CoreMidiInputDevice* dev = new CoreMidiInputDevice( uid, name, entity, m_client, this); m_inputDevices << dev; changed = true; } else { destroyInputs.removeAll(dev); } } } } foreach (MidiOutputDevice* dev, destroyOutputs) { m_outputDevices.removeAll(dev); delete dev; changed = true; }
unsigned long MidiDeviceUtil::GetDeviceCount() { return MIDIGetNumberOfDevices(); }