Ejemplo n.º 1
0
QMap<QString,QString> QMidi::outDeviceNames()
{
    QMap<QString,QString> ret;

#if defined(Q_OS_WIN)
    int numDevs = midiOutGetNumDevs();
    if(numDevs == 0) { return ret; }

    for(int i = 0;i<numDevs;i++) {
        MIDIOUTCAPS* devCaps = new MIDIOUTCAPS;
        midiOutGetDevCaps(i,devCaps,sizeof(*devCaps));
        ret.insert(QString::number(i),QString::fromWCharArray(devCaps->szPname));
        delete devCaps;
    }
#elif defined(Q_OS_LINUX)
    snd_seq_client_info_t *cinfo;
    snd_seq_port_info_t *pinfo;
    int client;
    int err;
    snd_seq_t *handle;

    err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
    if(err < 0)
    { /* Could not open sequencer!! use  snd_strerror(errno)  to get error. */ return ret; }

    snd_seq_client_info_alloca(&cinfo);
    snd_seq_client_info_set_client(cinfo, -1);

    while(snd_seq_query_next_client(handle, cinfo) >= 0) {
        client = snd_seq_client_info_get_client(cinfo);
        snd_seq_port_info_alloca(&pinfo);
        snd_seq_port_info_set_client(pinfo, client);

        snd_seq_port_info_set_port(pinfo, -1);
        while(snd_seq_query_next_port(handle, pinfo) >= 0) {
            int cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE);
            if((snd_seq_port_info_get_capability(pinfo) & cap) == cap) {
                QString port = QString::number(snd_seq_port_info_get_client(pinfo));
                port += ":" + QString::number(snd_seq_port_info_get_port(pinfo));
                QString name = snd_seq_client_info_get_name(cinfo);
                ret.insert(port,name);
            }
        }
    }
#elif defined(Q_OS_HAIKU)
	bool OK = true;
	int32 id = 0;
	while(OK) {
		BMidiConsumer* c = BMidiRoster::NextConsumer(&id);
		if(c != NULL) {
			ret.insert(QString::number(id),QString::fromUtf8(c->Name()));
			c->Release();
		} else {
			OK = false;
		}
	}
#endif

    return ret;
}
Ejemplo n.º 2
0
const char *MusicDriver_Win32::Start(const char * const *parm)
{
	MIDIOUTCAPS midicaps;
	UINT nbdev;
	UINT_PTR dev;
	char buf[16];

	mciSendStringA("capability sequencer has audio", buf, lengthof(buf), 0);
	if (strcmp(buf, "true") != 0) return "MCI sequencer can't play audio";

	memset(&_midi, 0, sizeof(_midi));
	_midi.new_vol = -1;

	/* Get midi device */
	_midi.devid = MIDI_MAPPER;
	for (dev = 0, nbdev = midiOutGetNumDevs(); dev < nbdev; dev++) {
		if (midiOutGetDevCaps(dev, &midicaps, sizeof(midicaps)) == 0 && (midicaps.dwSupport & MIDICAPS_VOLUME)) {
			_midi.devid = dev;
			break;
		}
	}

	if (NULL == (_midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL))) return "Failed to create event";

	/* The lpThreadId parameter of CreateThread (the last parameter)
	 * may NOT be NULL on Windows 95, 98 and ME. */
	DWORD threadId;
	if (NULL == (_midi.thread = CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId))) return "Failed to create thread";

	return NULL;
}
Ejemplo n.º 3
0
void MIDIDevice::extractName()
{
	MMRESULT res;
	MIDIOUTCAPS caps;

	res = midiOutGetDevCaps(m_id, &caps, sizeof(MIDIOUTCAPS));
	if (res == MMSYSERR_BADDEVICEID)
	{
		m_name = QString("Bad device ID");
		qDebug() << "MIDI OUT" << m_id + 1 << "has bad device ID";
	}
	else if (res == MMSYSERR_INVALPARAM)
	{
		m_name = QString("Invalid parameters");
		qDebug() << "Invalid params for MIDI OUT device" << m_id + 1;
	}
	else if (res == MMSYSERR_NODRIVER)
	{
		m_name = QString("No driver installed");
		qDebug() << "MIDI OUT device" << m_id + 1 << "has no driver";
	}
	else if (res == MMSYSERR_NOMEM)
	{
		m_name = QString("Out of memory");
		qDebug() << "Out of memory while opening MIDI OUT" << m_id + 1;
	}
	else
	{
		m_name = QString::fromWCharArray(caps.szPname);
		m_isOK = true;
	}
}
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_findPorts(JNIEnv* env, jobject obj, jlong ptr)
{
	midi_handle_t *handle = NULL;
	memcpy(&handle, &ptr, sizeof(handle));
	if(handle != NULL){
		MIDIOUTCAPS moc;
		UINT count, i;
		count = midiOutGetNumDevs();
		for (i = 0; i < count; i++){
			if (midiOutGetDevCaps(i, &moc, sizeof(MIDIOUTCAPS)) == MMSYSERR_NOERROR){
				int srcLen = strlen( moc.szPname );
				int dstLen = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)moc.szPname, srcLen, NULL, 0 );
				wchar_t* dstBuffer = malloc( (dstLen * 2) + 1 );
				MultiByteToWideChar( CP_ACP, 0, (LPCSTR)moc.szPname, srcLen,(LPWSTR)dstBuffer, dstLen );
				
				//Add a new MidiDevice to the java class
				jint device  = i;
				jstring name =  (*env)->NewString( env, (jchar*)dstBuffer, dstLen );
				jclass cl = (*env)->GetObjectClass(env, obj);
				jmethodID mid = (*env)->GetMethodID(env, cl, "addPort", "(Ljava/lang/String;I)V");
				if (mid != 0){
					(*env)->CallVoidMethod(env, obj, mid, name, device);
				}
				free (dstBuffer);
			}
		}
	}
}
Ejemplo n.º 5
0
const char* MidiOutPort_visual::getName(int i) {
   static MIDIOUTCAPS outputCapabilities;

   midiOutGetDevCaps(i, &outputCapabilities, sizeof(MIDIOUTCAPS));
  
   return outputCapabilities.szPname;
}
Ejemplo n.º 6
0
std::vector<std::string> getOutputPorts()
{
	std::vector< std:: string > res;
	
	MIDIOUTCAPS caps;
	
	int n_devices = midiOutGetNumDevs();
	
	for(int i=0; i < n_devices; ++i)
	{
		midiOutGetDevCaps(i, &caps, sizeof(MIDIOUTCAPS));
		WCHAR *wname = caps.szPname;
		
		char name[256];
		int j;
		for(j=0; j<255 && wname[j]!=0; ++j) {
			name[j] = (char)wname[j];
		}
		name[j] = 0;
		
		res.push_back(std::string(name));
	}
	
	return res;
}
static void msw_open_midiout(int nmidiout, int *midioutvec)
{
    UINT result, wRtn;
    int i;
    int dev;
    MIDIOUTCAPS midioutcaps;
    if (nmidiout > MAXMIDIOUTDEV)
        nmidiout = MAXMIDIOUTDEV;

    dev = 0;

    for (i = 0; i < nmidiout; i++)
    {
        MIDIOUTCAPS mocap;
        int devno =  midioutvec[i];
        result = midiOutOpen(&hMidiOut[dev], devno, 0, 0, 
            CALLBACK_NULL);
        wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
            sizeof(mocap));
        if (result != MMSYSERR_NOERROR)
        {
            fprintf(stderr,"midiOutOpen: %s\n",midioutcaps.szPname);
            msw_midiouterror("midiOutOpen: %s\n", result);
        }
        else
        {
            if (sys_verbose)
                fprintf(stderr,"midiOutOpen: Open %s as Port %d\n",
                    midioutcaps.szPname, dev);
            dev++;
        }
    }
    msw_nmidiout = dev;
}
Ejemplo n.º 8
0
void I_midiOutSetVolumes(int volume)
{
  // NSM changed to work on the 0-15 volume scale,
  // and to check mus_extend_volume itself.
  
  MMRESULT result;
  int calcVolume;
  MIDIOUTCAPS capabilities;
  unsigned int i;

  if (volume > 15)
    volume = 15;
  if (volume < 0)
    volume = 0;
  calcVolume = (65535 * volume / 15);

  //SDL_LockAudio(); // this function doesn't touch anything the audio callback touches

  //Device loop
  for (i = 0; i < midiOutGetNumDevs(); i++)
  {
    //Get device capabilities
    result = midiOutGetDevCaps(i, &capabilities, sizeof(capabilities));
    if (result == MMSYSERR_NOERROR)
    {
      //Adjust volume on this candidate
      if ((capabilities.dwSupport & MIDICAPS_VOLUME))
      {
        midiOutSetVolume((HMIDIOUT)i, MAKELONG(calcVolume, calcVolume));
      }
    }
  }

  //SDL_UnlockAudio();
}
Ejemplo n.º 9
0
void MidiWinMM::openDevices()
{
	m_inputDevices.clear();
	for( unsigned int i = 0; i < midiInGetNumDevs(); ++i )
	{
		MIDIINCAPS c;
		midiInGetDevCaps( i, &c, sizeof( c ) );
		HMIDIIN hm = 0;
		MMRESULT res = midiInOpen( &hm, i, (DWORD_PTR) &inputCallback,
						(DWORD_PTR) this,
							CALLBACK_FUNCTION );
		if( res == MMSYSERR_NOERROR )
		{
			m_inputDevices[hm] = qstrdup( c.szPname );
			midiInStart( hm );
		}
	}

	m_outputDevices.clear();
	for( unsigned int i = 0; i < midiOutGetNumDevs(); ++i )
	{
		MIDIOUTCAPS c;
		midiOutGetDevCaps( i, &c, sizeof( c ) );
		HMIDIOUT hm = 0;
		MMRESULT res = midiOutOpen( &hm, i, 0, 0, CALLBACK_NULL );
		if( res == MMSYSERR_NOERROR )
		{
			m_outputDevices[hm] = qstrdup( c.szPname );
		}
	}
}
Ejemplo n.º 10
0
void CMidiDevice::EnumMidiDev()
{
	int i = 0; 
	MIDIINCAPS midiInDevCaps;
	MIDIOUTCAPS midiOutDevCaps;

	// get the number of midi device in and out
	m_nTotalNumOfDevIn = midiInGetNumDevs();
	m_nTotalNumOfDevOut = midiOutGetNumDevs();

	// init the device name and device id
	for(i = 0; i < MAX_MIDI_DEV; i++)
	{
		m_midiDevIn[i].nDevID = -1;
		m_midiDevOut[i].nDevID = -1;
		memset(m_midiDevIn[i].szPnameIn, 0, MAXPNAMELEN);
		memset(m_midiDevOut[i].szPnameOut, 0, MAXPNAMELEN);
	}

	// get the device name and device id of midi device in
	for(i = 0; i < m_nTotalNumOfDevIn; i++)
	{
		midiInGetDevCaps(i, &midiInDevCaps, sizeof(MIDIINCAPS));
		memcpy(m_midiDevIn[i].szPnameIn, midiInDevCaps.szPname, MAXPNAMELEN);
		m_midiDevIn[i].nDevID = i;
	}

	// get the device name and device id of midi device out
	for(i = 0; i < m_nTotalNumOfDevOut; i++)
	{
		midiOutGetDevCaps(i, &midiOutDevCaps, sizeof(MIDIOUTCAPS));
		memcpy(m_midiDevOut[i].szPnameOut, midiOutDevCaps.szPname, MAXPNAMELEN);
		m_midiDevOut[i].nDevID = i;
	}
}
Ejemplo n.º 11
0
const char* MidiOutPort_visual::getName(void) {
   static MIDIOUTCAPS outputCapabilities;

   if (getPort() == -1) {
      return "Null MIDI Output";
   }

   if (openQ[getPort()]) {  // port already open
      midiOutGetDevCaps(getPort(), &outputCapabilities, sizeof(MIDIOUTCAPS));
   } else {  // port is currently closed
      if(open()) {;
         midiOutGetDevCaps(getPort(), &outputCapabilities, sizeof(MIDIOUTCAPS));
         close();
      } else {
         return "";
      }
   }
   return outputCapabilities.szPname;
}
Ejemplo n.º 12
0
void
TPlayWindow::GetDeviceInfo()
{
  MIDIOUTCAPS MidiOutCaps;

  if (!midiOutGetDevCaps(DeviceId, &MidiOutCaps, sizeof(MidiOutCaps))) {
	 MessageBox("GetDevCaps Error", "Play Midi", MB_OK);
	 return;
  }
}
Ejemplo n.º 13
0
BOOL CMidiDevice::GetDevOutCaps(UINT uDeviceOutId, MIDIOUTCAPS &Caps)
{
	MMRESULT Result = midiOutGetDevCaps(uDeviceOutId, &Caps, sizeof Caps);
    if(Result != MMSYSERR_NOERROR)
    {
        return FALSE;
    }

	return TRUE;
}
Ejemplo n.º 14
0
int WinMIDIDevice::GetTechnology() const
{
	MIDIOUTCAPS caps;

	if (MMSYSERR_NOERROR == midiOutGetDevCaps(DeviceID, &caps, sizeof(caps)))
	{
		return caps.wTechnology;
	}
	return -1;
}
Ejemplo n.º 15
0
static PyObject *s_output_devices(PyObject *self, PyObject *args) {
	MIDIOUTCAPS caps;
	UINT		numDevs, i;
	PyObject    *result;
	
	result = PyList_New(0);
	numDevs = midiOutGetNumDevs();
	if (midiOutGetDevCaps(MIDI_MAPPER, &caps, sizeof(caps)) == 0)
		PyList_Append(result, PyString_FromString(caps.szPname));
	else
		PyList_Append(result, Py_None);		
	for(i = 0; i < numDevs; i++) {
		if (midiOutGetDevCaps(i, &caps, sizeof(caps)) == 0)
			PyList_Append(result, PyString_FromString(caps.szPname));
		else
			PyList_Append(result, Py_None);		
	}
	return result;
}
Ejemplo n.º 16
0
MF_API bool MFMidi_OpenOutput(MFDevice *pDevice)
{
	MFDebug_Assert(pDevice->type == MFDT_MidiOutput, "Not a MIDI device!");

	if (pDevice->state == MFDevState_Ready)
	{
		MFDebug_Warn(1, "Midi output device already opened!");
		return false;
	}
	if (pDevice->state != MFDevState_Available)
	{
		MFDebug_Warn(1, "Unable to open midi output device!");
		return false;
	}

	MFMidiPC_MidiOutputDevice *pMidi = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;

	// find and open the device
	// TODO: FIXME! this won't work if there are 2 instances of the same device attached to the PC!!!
	UINT numOutputDevices = midiOutGetNumDevs();
	UINT i = 0;
	for (; i < numOutputDevices; ++i)
	{
		MIDIOUTCAPS caps;
		MMRESULT r = midiOutGetDevCaps(i, &caps, sizeof(caps));
		if (r != MMSYSERR_NOERROR)
			continue;

		if (caps.wMid == pMidi->mid && caps.wPid == pMidi->pid)
			break;
	}
	if (i == numOutputDevices)
	{
		MFDebug_Log(0, MFStr("Midi output device '%s' not found!", pDevice->strings[MFDS_ID]));
		pDevice->state = MFDevState_Unknown; // set this flag?
		return false;
	}

	MMRESULT r = midiOutOpen(&pMidi->hMidiOut, i, (DWORD_PTR)MidiOutProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION);
	if (r != MMSYSERR_NOERROR)
	{
		pMidi->hMidiOut = NULL;
		pDevice->state = MFDevState_Unknown;

		wchar_t errorBuffer[256];
		midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
		MFDebug_Warn(1, MFStr("Failed to open MIDI output device: %s", MFString_WCharAsUTF8(errorBuffer)));

		return false;
	}

	pDevice->state = MFDevState_Ready;

	return true;
}
Ejemplo n.º 17
0
static int getOutputDeviceName(int id, char *buf, int len) {
  MIDIOUTCAPS moc;

  if (!midiOutGetDevCaps(id, &moc, sizeof(MIDIOUTCAPS))) {
    strncpy(buf, moc.szPname, len);
    return 0;
  } else {
    buf[0] = '\0';
    return -1;
  }
}
Ejemplo n.º 18
0
BOOL Midi_LookupPortIndexes(MIDI *midi)
{
    BOOL setupValid = TRUE;
    int midiInDevCnt = midiInGetNumDevs();
    int midiOutDevCnt = midiOutGetNumDevs();
    int i;
    
    if (StrEq(midi->inPortName, _T("Disabled"))) {
        midi->inPort = -1;
        goto InPortFound;
    }
    for (i = 0; i < midiInDevCnt; i++) {
        MIDIINCAPS midiDevInfo;

        midiInGetDevCaps(i, &midiDevInfo, sizeof midiDevInfo);
        if (StrEq(midi->inPortName, midiDevInfo.szPname)) {
            midi->inPort = i;
            goto InPortFound;
        }
    }
    setupValid = FALSE;
InPortFound:
    if (StrEq(midi->outPortName, _T("Disabled"))) {
        midi->outPort = -1;
        goto OutPortFound;
    }
    for (i = 0; i < midiOutDevCnt; i++) {
        MIDIOUTCAPS midiDevInfo;

        midiOutGetDevCaps(i, &midiDevInfo, sizeof midiDevInfo);
        if (StrEq(midi->outPortName, midiDevInfo.szPname)) {
            midi->outPort = i;
            goto OutPortFound;
        }
    }
    setupValid = FALSE;
OutPortFound:
    if (StrEq(midi->masterInPortName, _T("Disabled"))) {
        midi->masterInPort = -1;
        goto MasterInPortFound;
    }
    for (i = 0; i < midiInDevCnt; i++) {
        MIDIINCAPS midiDevInfo;

        midiInGetDevCaps(i, &midiDevInfo, sizeof midiDevInfo);
        if (StrEq(midi->masterInPortName, midiDevInfo.szPname)) {
            midi->masterInPort = i;
            goto MasterInPortFound;
        }
    }
MasterInPortFound:

    return setupValid;
}
Ejemplo n.º 19
0
MOutputDeviceWin32::MOutputDeviceWin32(int deviceId)
{
	hMidiOut = 0;
	// get the devs caps
	midiOutGetDevCaps(deviceId,&midiOutCaps,sizeof(MIDIOUTCAPS));

	// open the device
	HRESULT err = midiOutOpen(&hMidiOut,deviceId,0,0,CALLBACK_NULL);
	if(err != MMSYSERR_NOERROR)
		throw Resound::Exception();
}
Ejemplo n.º 20
0
int JackWinMMEDriver::Attach()
{
    JackPort* port;
    jack_port_id_t port_index;
    char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
    char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
    MMRESULT res;
    int i;

    jack_log("JackMidiDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate);

    for (i = 0; i < fCaptureChannels; i++) {
        MIDIINCAPS caps;
		res = midiInGetDevCaps(fMidiDestination[i].fIndex, &caps, sizeof(caps));
		if (res == MMSYSERR_NOERROR) {
            snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, caps.szPname, i + 1);
		} else {
		    snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, i + 1);
		}
        snprintf(name, sizeof(name) - 1, "%s:capture_%d", fClientControl.fName, i + 1);

        if ((port_index = fGraphManager->AllocatePort(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE, CaptureDriverFlags, fEngineControl->fBufferSize)) == NO_PORT) {
            jack_error("driver: cannot register port for %s", name);
            return -1;
        }
        port = fGraphManager->GetPort(port_index);
        port->SetAlias(alias);
        fCapturePortList[i] = port_index;
        jack_log("JackMidiDriver::Attach fCapturePortList[i] port_index = %ld", port_index);
    }

    for (i = 0; i < fPlaybackChannels; i++) {
        MIDIOUTCAPS caps;
		res = midiOutGetDevCaps(fMidiSource[i].fIndex, &caps, sizeof(caps));
        if (res == MMSYSERR_NOERROR) {
            snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, caps.szPname, i + 1);
		} else {
		    snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fPlaybackDriverName, i + 1);
		}
        snprintf(name, sizeof(name) - 1, "%s:playback_%d", fClientControl.fName, i + 1);

        if ((port_index = fGraphManager->AllocatePort(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE, PlaybackDriverFlags, fEngineControl->fBufferSize)) == NO_PORT) {
            jack_error("driver: cannot register port for %s", name);
            return -1;
        }
        port = fGraphManager->GetPort(port_index);
        port->SetAlias(alias);
        fPlaybackPortList[i] = port_index;
        jack_log("JackMidiDriver::Attach fPlaybackPortList[i] port_index = %ld", port_index);
    }

    return 0;
}
Ejemplo n.º 21
0
void MidiUartWinClass::listOutputMidiDevices() {
  MIDIOUTCAPS     moc;
  unsigned long   iNumDevs, i;
  
  iNumDevs = midiOutGetNumDevs();

  for (i = 0; i < iNumDevs; i++) {
    if (!midiOutGetDevCaps(i, &moc, sizeof(MIDIOUTCAPS))){
      printf("%lu) %s\r\n", i, moc.szPname);
    }
  }  
}
int main(int argc, char **argv)
{
	int i, max;

	for (i = 0, max = midiOutGetNumDevs(); i < max; i++)
	{
		MIDIOUTCAPS midi_out_caps;
		midiOutGetDevCaps(i, &midi_out_caps, sizeof(midi_out_caps));
		printf("%3d %s\n", i, midi_out_caps.szPname);
	}

	return 0;
}
Ejemplo n.º 23
0
static void pm_winmm_mapper_output()
{
    WORD wRtn;
    /* Note: if MIDIMAPPER opened as output (pseudo MIDI device
        maps device independent messages into device dependant ones,
        via NT midimapper program) you still should get some setup info */
    wRtn = midiOutGetDevCaps((UINT) MIDIMAPPER,(LPMIDIOUTCAPS) 
                              &midi_out_mapper_caps,sizeof(MIDIOUTCAPS));
    if (wRtn == MMSYSERR_NOERROR) {
        pm_add_device("MMSystem", midi_out_mapper_caps.szPname, FALSE,
                  (void *) MIDIMAPPER, &pm_winmm_out_dictionary);
    }
}
Ejemplo n.º 24
0
//________________________________________________________________
static Boolean IsInternalSynth (char *name)
{
	UINT i, n = midiOutGetNumDevs ();
	for (i=0; i<n; i++) {
		MIDIOUTCAPS caps; 
		MMRESULT res = midiOutGetDevCaps (i, &caps, sizeof(caps));
		if (res == MMSYSERR_NOERROR) {
			if (caps.wTechnology != MOD_MIDIPORT)
				return strcmp (name, caps.szPname) == 0;
		}
	}
	return FALSE;
}
Ejemplo n.º 25
0
MusicDevices WindowsMusicPlugin::getDevices() const {
	MusicDevices devices;
	int numDevs = midiOutGetNumDevs();
	MIDIOUTCAPS tmp;

	for (int i = 0; i < numDevs; i++) {
		if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR)
			break;
		// There is no way to detect the "MusicType" so I just set it to MT_GM
		// The user will have to manually select his MT32 type device and his GM type device.
		devices.push_back(MusicDevice(this, tmp.szPname, MT_GM));
	}
	return devices;
}
Ejemplo n.º 26
0
MusicDevices WindowsMusicPlugin::getDevices() const {
	MusicDevices devices;
	int numDevs = midiOutGetNumDevs();
	MIDIOUTCAPS tmp;

	Common::StringArray deviceNames;
	for (int i = 0; i < numDevs; i++) {
		if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR)
			break;
		deviceNames.push_back(tmp.szPname);
	}

	// Check for non-unique device names. This may happen if someone has devices with identical
	// names (e. g. more than one USB device of the exact same hardware type). It seems that this
	// does happen in reality sometimes. We generate index numbers for these devices.
	// This is not an ideal solution, since this index could change whenever another USB
	// device gets plugged in or removed, switched off or just plugged into a different port.
	// Unfortunately midiOutGetDevCaps() does not generate any other unique information
	// that could be used. Our index numbers which match the device order should at least be
	// a little more stable than just using the midiOutGetDevCaps() device ID, since a missing
	// device (e.g. switched off) should actually not be harmful to our indices (as it would be
	// when using the device IDs). The cases where users have devices with identical names should
	// be rare enough anyway.
	Common::Array<int> nonUniqueIndex;
	for (int i = 0; i < numDevs; i++) {
		int match = -1;
		for (int ii = 0; ii < i; ii++) {
			if (deviceNames[i] == deviceNames[ii]) {
				if (nonUniqueIndex[ii] == -1)
					nonUniqueIndex[ii] = 0;
				if (++match == 0)
					++match;
			}
		}
		nonUniqueIndex.push_back(match);
	}

	// We now add the index number to the non-unique device names to make them unique.
	for (int i = 0; i < numDevs; i++) {
		if (nonUniqueIndex[i] != -1)
			deviceNames[i] = Common::String::format("%s - #%.02d", deviceNames[i].c_str(), nonUniqueIndex[i]);
	}

	for (Common::StringArray::iterator i = deviceNames.begin(); i != deviceNames.end(); ++i)
		// There is no way to detect the "MusicType" so I just set it to MT_GM
		// The user will have to manually select his MT32 type device and his GM type device.
		devices.push_back(MusicDevice(this, *i, MT_GM));

	return devices;
}
INT32 getMidiOutCaps(INT32 deviceID, MIDIOUTCAPS* caps) {
    INT32 result;

    if (deviceID == 0) {
	deviceID = MIDI_MAPPER;
    } else {
	deviceID--;
    }
    result = (midiOutGetDevCaps(deviceID, caps, sizeof(MIDIOUTCAPS)) == MMSYSERR_NOERROR);
    if (!result) {
	ERROR1("ERROR: MIDI_OUT_GetDeviceName: failed to get MIDIOUTCAPS for deviceID %d\n", deviceID);
    }
    return result;
}
Ejemplo n.º 28
0
//==============================================================================
StringArray MidiOutput::getDevices()
{
    StringArray s;
    const int num = midiOutGetNumDevs();

    for (int i = 0; i < num; ++i)
    {
        MIDIOUTCAPS mc = { 0 };

        if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
            s.add (String (mc.szPname, sizeof (mc.szPname)));
    }

    return s;
}
Ejemplo n.º 29
0
void midi_device_manager::enum_device_infos()
{
  // MIDI IN デバイスの列挙
  {
    const uint32_t num_devs_ = midiInGetNumDevs();
    if(num_devs_ > 0)
    {
      midi_input_device_infos_.clear();
      for( uint32_t dev_id_ = 0;dev_id_ < num_devs_;++dev_id_)
      {
        MIDIINCAPS2 caps2_;
        uint32_t result = midiInGetDevCaps(dev_id_,reinterpret_cast<LPMIDIINCAPS>(&caps2_),sizeof(MIDIINCAPS2));
        if(result != MMSYSERR_NOERROR)
        {
           throw midi_input_error(result);
        } else {
          midi_input_device_infos_.push_back(new midi_input_device_t(caps2_,dev_id_));
        }
      }
    }
  }

  // MIDI OUT デバイスの列挙
  {
    const uint32_t num_devs_ = midiOutGetNumDevs();
    if(num_devs_ > 0)
    {
      midi_output_device_infos_.clear();
      for( uint32_t dev_id_ = 0;dev_id_ < num_devs_;++dev_id_)
      {
        MIDIOUTCAPS2 device_infos_2_;
        uint32_t result = midiOutGetDevCaps(dev_id_,reinterpret_cast<LPMIDIOUTCAPS>(&device_infos_2_),sizeof(MIDIOUTCAPS2));
        if(result != MMSYSERR_NOERROR)
        {
           throw midi_output_error(result);
        } else {
          midi_output_device_infos_
            .push_back(new midi_output_device_t(device_infos_2_,dev_id_));
        }
      }
    }

  }

}
Ejemplo n.º 30
0
QMap<QString, QString> QMidiOut::devices()
{
	QMap<QString, QString> ret;

    int numDevs = midiOutGetNumDevs();
	if (numDevs == 0) {
		return ret;
	}

	for (int i = 0; i < numDevs; i++) {
		MIDIOUTCAPS* devCaps = new MIDIOUTCAPS;
		midiOutGetDevCaps(i, devCaps, sizeof(*devCaps));
		ret.insert(QString::number(i), QString::fromWCharArray(devCaps->szPname));
		delete devCaps;
	}

	return ret;
}