示例#1
0
/**************************************************************************
 * 				MIDIMAP_drvOpen			[internal]
 */
static	DWORD	MIDIMAP_drvOpen(LPSTR str)
{
    MIDIOUTCAPSA	moc;
    unsigned		dev, i;

    if (midiOutPorts)
	return 0;

    numMidiOutPorts = midiOutGetNumDevs();
    midiOutPorts = HeapAlloc(GetProcessHeap(), 0,
			     numMidiOutPorts * sizeof(MIDIOUTPORT));
    for (dev = 0; dev < numMidiOutPorts; dev++)
    {
	if (midiOutGetDevCapsA(dev, &moc, sizeof(moc)) == 0L)
	{
	    strcpy(midiOutPorts[dev].name, moc.szPname);
	    midiOutPorts[dev].loaded = 0;
	    midiOutPorts[dev].hMidi = 0;
	    midiOutPorts[dev].uDevID = 0;
	    midiOutPorts[dev].lpbPatch = NULL;
	    for (i = 0; i < 16; i++)
		midiOutPorts[dev].aChn[i] = i;
	}
	else
	{
	    midiOutPorts[dev].loaded = -1;
	}
    }

    return 1;
}
示例#2
0
文件: e6y.c 项目: TheMatthew/DoomUst
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();
}
示例#3
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;
	}
}
示例#4
0
void MidiOutPort_visual::initialize(void) {
   // get the number of ports
   numDevices = midiOutGetNumDevs();
   if  (getNumPorts() <= 0) {
      cerr << "Error: no MIDI output devices" << endl;
      exit(1);
   }

   // allocate space for Windoze MIDI output structures
   if (device != NULL) {
      cerr << "Error: device array should be NULL when calling "
           << "initialize() in MidiOutPort." << endl;
      exit(1);
   }
   device = new HMIDIOUT[numDevices];

   // allocate space for openQ, the port open/close status
   if (openQ != NULL) delete [] openQ;
   openQ = new int[numDevices];

   // allocate space for object count on each port:
   if (portObjectCount != NULL) delete [] portObjectCount;
   portObjectCount = new int[numDevices];


   // initialize the static arrays
   for (int i=0; i<getNumPorts(); i++) {
      device[i] = NULL;
      openQ[i] = 0;
      portObjectCount[i] = 0;
   }
}
示例#5
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;
}
示例#6
0
void RtMidiOut :: openPort( unsigned int portNumber, const std::string /*portName*/ )
{
  if ( connected_ ) {
    errorString_ = "RtMidiOut::openPort: a valid connection already exists!";
    error( RtError::WARNING );
    return;
  }

  unsigned int nDevices = midiOutGetNumDevs();
  if (nDevices < 1) {
    errorString_ = "RtMidiOut::openPort: no MIDI output destinations found!";
    error( RtError::NO_DEVICES_FOUND );
  }

  std::ostringstream ost;
  if ( portNumber >= nDevices ) {
    ost << "RtMidiOut::openPort: the 'portNumber' argument (" << portNumber << ") is invalid.";
    errorString_ = ost.str();
    error( RtError::INVALID_PARAMETER );
  }

  WinMidiData *data = static_cast<WinMidiData *> (apiData_);
  MMRESULT result = midiOutOpen( &data->outHandle,
                                 portNumber,
                                 (DWORD)NULL,
                                 (DWORD)NULL,
                                 CALLBACK_NULL );
  if ( result != MMSYSERR_NOERROR ) {
    errorString_ = "RtMidiOut::openPort: error creating Windows MM MIDI output port.";
    error( RtError::DRIVER_ERROR );
  }

  connected_ = true;
}
示例#7
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;
}
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);
			}
		}
	}
}
示例#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 );
		}
	}
}
示例#10
0
文件: midiports.cpp 项目: 0xtob/dsmi
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;
}
示例#11
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;
}
示例#12
0
文件: midi.c 项目: thomcom/wine
static void test_midi_outfns(HWND hwnd)
{
    HMIDIOUT hm;
    MMRESULT rc;
    UINT udev, ndevs = midiOutGetNumDevs();

    rc = midiOutOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
    ok(rc==MMSYSERR_BADDEVICEID, "midiOutOpen udev>max rc=%s\n", mmsys_error(rc));
    if (!rc) {
        rc = midiOutClose(hm);
        ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
    }
    if (!ndevs) {
        MIDIOUTCAPSA capsA;
        skip("Found no MIDI out device\n");

        rc = midiOutGetDevCapsA(MIDIMAPPER, &capsA, sizeof(capsA));
        /* GetDevCaps and Open must return compatible results */
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiOutGetDevCaps MAPPER with no MIDI rc=%s\n", mmsys_error(rc));

        rc = midiOutOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
        if (rc==MIDIERR_INVALIDSETUP) todo_wine /* Wine without snd-seq */
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k*/), "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
        else
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k sound disabled*/),
           "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
        if (!rc) {
            rc = midiOutClose(hm);
            ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
        }
        return;
    }
    trace("Found %d MIDI OUT devices\n", ndevs);

    test_midi_mci(hwnd);

    for (udev=0; udev < ndevs; udev++) {
        MIDIOUTCAPSA capsA;
        rc = midiOutGetDevCapsA(udev, &capsA, sizeof(capsA));
        if (rc || strcmp(capsA.szPname, "Creative Sound Blaster MPU-401") != 0 || ! on_vmware()) {
            trace("** Testing device %d\n", udev);
            test_midiOut_device(udev, hwnd);
            Sleep(800); /* Let the synth rest */
            test_midiStream(udev, hwnd);
            Sleep(800);
        }
        else
            win_skip("Skipping this device on VMware, driver problem\n");
    }
    trace("** Testing MIDI mapper\n");
    test_midiOut_device(MIDIMAPPER, hwnd);
    Sleep(800);
    test_midiStream(MIDIMAPPER, hwnd);
}
示例#13
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;
}
示例#14
0
MidiDevice *
openMidiDevice (int errorLevel, const char *device) {
  MidiDevice *midi;
  MMRESULT error;
  int id = 0;
  static const char *const defaultDevice = "default";

  if (!*device) device = defaultDevice;

  if (strcmp(device, defaultDevice) == 0) {
    id = -1;
  } else if (!isInteger(&id, device) || (id < 0) || (id >= midiOutGetNumDevs())) {
    int count = midiOutGetNumDevs();
    for (id=0; id<count; ++id) {
      MIDIOUTCAPS cap;
      if (midiOutGetDevCaps(id, &cap, sizeof(cap)) == MMSYSERR_NOERROR)
        if (strncasecmp(device, cap.szPname, strlen(device)) == 0)
          break;
    }

    if (id == count) {
      logMessage(errorLevel, "invalid MIDI device number: %s", device);
      return NULL;
    }
  }

  if ((midi = malloc(sizeof(*midi)))) {
    if ((error = midiOutOpen(&midi->handle, id, 0, 0, CALLBACK_NULL)) == MMSYSERR_NOERROR) {
      midi->note = 0;
      midi->count = 0;
      return midi;
    } else {
      logMidiOutError(error, errorLevel, "MIDI device open");
    }

    free(midi);
  } else {
    logSystemError("MIDI device allocation");
  }
  return NULL;
}
示例#15
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);
    }
  }  
}
示例#16
0
void MIDIOut::rescanDevices()
{
	UINT deviceCount;

	/* Destroy existing devices in case something has changed */
	while (m_devices.isEmpty() == false)
		removeDevice(m_devices.takeFirst());

	/* Create devices for each valid midi input */
	deviceCount = midiOutGetNumDevs();
	for (UINT id = 0; id < deviceCount; id++)
		addDevice(new MIDIDevice(this, id));
}
示例#17
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;
}
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;
}
示例#19
0
void RtMidiOut :: initialize( const std::string& /*clientName*/ )
{
  // We'll issue a warning here if no devices are available but not
  // throw an error since the user can plug something in later.
  unsigned int nDevices = midiOutGetNumDevs();
  if ( nDevices == 0 ) {
    errorString_ = "RtMidiOut::initialize: no MIDI output devices currently available.";
    error( RtError::WARNING );
  }

  // Save our api-specific connection information.
  WinMidiData *data = (WinMidiData *) new WinMidiData;
  apiData_ = (void *) data;
}
示例#20
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;
}
示例#21
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;
}
示例#22
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;
}
示例#23
0
void midiInitialize()
{
    MIDIINCAPSA  inCap;
    MIDIOUTCAPSA outCap;
    int num;

    memset(&midi, 0, sizeof(midi));
    midi.enabled = 1;

    num = midiOutGetNumDevs();
    if (num > 0 && midiOutGetDevCapsA(MIDI_MAPPER, &outCap, sizeof(outCap)) == MMSYSERR_NOERROR) {
        int i;

        midi.out.dev = (DevInfo*)calloc(1, (num + 1) * sizeof(DevInfo));

        strcpy(midi.out.dev[0].name, outCap.szPname);
        midi.out.dev[0].id = MIDI_MAPPER;
        strcpy(midi.out.dev[0].idString, "midi-out");
        midi.out.count++;

        for (i = 0; i < num; i++) {
            if (midiOutGetDevCapsA(i, &outCap, sizeof(outCap)) == MMSYSERR_NOERROR) {
                strcpy(midi.out.dev[midi.out.count].name, outCap.szPname);
                midi.out.dev[midi.out.count].id = i;
                sprintf(midi.out.dev[midi.out.count].idString, "midi-out-%u", i);
                midi.out.count++;
            }
        }
    }

    num = midiInGetNumDevs();
    if (num > 0) {
        int i;

        midi.in.dev = (DevInfo*)calloc(1, num * sizeof(DevInfo));

        for (i = 0; i < num; ++i) {
            if (midiInGetDevCapsA(i, &inCap, sizeof(inCap)) == MMSYSERR_NOERROR) {
                strcpy(midi.in.dev[midi.in.count].name, inCap.szPname);
                midi.in.dev[midi.in.count].id = i;
                sprintf(midi.in.dev[midi.in.count].idString, "midi-in-%u", i);
                midi.in.count++;
            }
        }
    }
}
示例#24
0
static PyObject *Winmidi_New(PyObject *self, PyObject *args) {
	WinmidiObject *obj;
	UINT		retVal;
	UINT		numDevs;
	UINT		devNum;

	UNUSED(self);

	if(!PyArg_ParseTuple(args, "i:Winmidi", &devNum)) {
	return NULL;
	}

	/* Initialize the new object. */
	obj = PyObject_NEW(WinmidiObject, &s_winmidiObjectType);
	if(!obj) {
	return NULL;
	}
	obj->m_midiOut = 0;
	obj->m_initialized = 0;
	obj->m_playNode = 0;
	obj->m_list = 0;
	obj->m_listEnd = 0;

	/* Get the number of MIDI devices on the system. */
	numDevs = midiOutGetNumDevs();
	if(numDevs == 0) {
	PyErr_SetString(PyExc_RuntimeError, 
		"No MIDI output devices found.");
	Py_DECREF(obj);
	return NULL;
	}

	/* Open the MIDI output device. */
	obj->m_midiOut = 0;
	retVal = midiStreamOpen(&(obj->m_midiOut), &devNum, 1,
		(DWORD) s_MidiCallback, (DWORD) obj, CALLBACK_FUNCTION); //lint !e620
	if(retVal != MMSYSERR_NOERROR) {
	s_SetMidiError("opening a MIDI stream", retVal);
	Py_DECREF(obj);
	return NULL;
	}
	assert(obj->m_midiOut);

	/* printf("Winmidi object created.\n"); */
	return (PyObject *) obj;
}
示例#25
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_));
        }
      }
    }

  }

}
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;
}
示例#27
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;
}
示例#28
0
UINT AppState::GetMidiDeviceId()
{
    UINT deviceId = 0;
    UINT cDevices = midiOutGetNumDevs();
    for (UINT i = 0; i < cDevices; i++)
    {
        MIDIOUTCAPS outcaps = { 0 };
        MMRESULT result = midiOutGetDevCaps(i, &outcaps, sizeof(outcaps));
        if (result == MMSYSERR_NOERROR)
        {
            if (0 == lstrcmpi(outcaps.szPname, _midiDeviceName.c_str()))
            {
                deviceId = i;
                break;
            }
        }
    }
    return deviceId;
}
示例#29
0
void MManagerWin32::GetDriverNames()
{
	// get the names of all devices
	int numIns = midiInGetNumDevs();
	int numOuts = midiOutGetNumDevs();
	MIDIINCAPS inCaps;
	MIDIOUTCAPS outCaps;
	std::wstring name;
	for(int n = 0; n < numIns; n++) {
		midiInGetDevCaps(n,&inCaps,sizeof(MIDIINCAPS));
		name = inCaps.szPname;
		inputDeviceNames.push_back(name);
	}
	for(int n = 0; n < numOuts; n++) {
		midiOutGetDevCaps(n,&outCaps,sizeof(MIDIOUTCAPS));
		name = outCaps.szPname;
		outputDeviceNames.push_back(name);
	}
}
      /* print to stdout the midi output devices on your win32 system.. */
      virtual void printOutDevices()
      {
         MIDIOUTCAPS     moc;
         unsigned long   iNumDevs, i;

         /* Get the number of MIDI Out devices in this computer */
         iNumDevs = midiOutGetNumDevs();

         /* Go through all of those devices, displaying their names */
         for (i = 0; i < iNumDevs; i++)
         {
             /* Get info about the next device */
             if (!midiOutGetDevCaps(i, &moc, sizeof(MIDIOUTCAPS)))
             {
                 /* Display its Device ID and name */
                 printf("Device ID #%u: %s\r\n", i, moc.szPname);
             }
         }
      }