예제 #1
0
bool CoreMidiInputDevice::open()
{
    qDebug() << Q_FUNC_INFO;

    // Don't open twice
    if (m_inPort != 0)
        return false;

    OSStatus s = MIDIInputPortCreate(m_client, CFSTR("QLC Input Port"),
                                     MidiInProc, this, &m_inPort);
    if (s != 0)
    {
        qWarning() << Q_FUNC_INFO << "Unable to make an input port for"
                   << name() << ":" << s;
        m_inPort = 0;
    }
    else
    {
        // Connect the input port to the first source
        m_source = MIDIEntityGetSource(m_entity, 0);
        s = MIDIPortConnectSource(m_inPort, m_source, this);
        if (s != 0)
        {
            qWarning() << Q_FUNC_INFO << "Unable to connect input port to source for"
                       << name() << ":" << s;

            s = MIDIPortDispose(m_inPort);
            if (s != 0)
                qWarning() << "Unable to dispose of input port in" << name();
            m_inPort = 0;
        }
    }
    return true;
}
예제 #2
0
//_________________________________________________________
// 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;
}	
예제 #3
0
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;
}
예제 #4
0
파일: MidiApple.cpp 프로젝트: DeRobyJ/lmms
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);
}
JNIEXPORT jint JNICALL Java_com_apple_audio_midi_MIDIEntity_MIDIEntityGetSource
  (JNIEnv *, jclass, jint entity, jint sourceIndex0)
{
	return (jint)MIDIEntityGetSource((MIDIEntityRef)entity, (ItemCount)sourceIndex0);
}
예제 #6
0
MIDIEndpointRef MidiDeviceUtil::GetMidiEndpoint(int deviceIndex, int entityIndex, int sourceIndex)
{
    MIDIEntityRef entity = GetMidiEntity(deviceIndex, entityIndex);
    return MIDIEntityGetSource(entity, sourceIndex);
}