From: <man...@us...> - 2013-11-29 22:33:37
|
Revision: 3336 http://sourceforge.net/p/modplug/code/3336 Author: manxorist Date: 2013-11-29 22:33:28 +0000 (Fri, 29 Nov 2013) Log Message: ----------- [Mod] sounddev: WASAPI devices might change names if a different connector jack is used. In order to avoid defaulting to wave mapper in that case, just find the first WASAPI device. Modified Paths: -------------- trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -572,7 +572,7 @@ SoundDeviceID TrackerSettings::GetSoundDeviceID() const //----------------------------------------------------- { - return theApp.GetSoundDevicesManager()->FindDeviceInfo(m_SoundDeviceIdentifier).id; + return theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_SoundDeviceIdentifier).id; } void TrackerSettings::SetSoundDeviceID(const SoundDeviceID &id) Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -26,7 +26,24 @@ #include <iterator> +std::wstring SoundDeviceTypeToString(SoundDeviceType type) +//-------------------------------------------------------- +{ + switch(type) + { + case SNDDEV_WAVEOUT: return L"WaveOut"; break; + case SNDDEV_DSOUND: return L"DirectSound"; break; + case SNDDEV_ASIO: return L"ASIO"; break; + case SNDDEV_PORTAUDIO_WASAPI: return L"WASAPI"; break; + case SNDDEV_PORTAUDIO_WDMKS: return L"WDM-KS"; break; + case SNDDEV_PORTAUDIO_WMME: return L"MME"; break; + case SNDDEV_PORTAUDIO_DS: return L"DS"; break; + case SNDDEV_PORTAUDIO_ASIO: return L"ASIO"; break; + } + return std::wstring(); +} + SoundChannelMapping::SoundChannelMapping() //---------------------------------------- { @@ -900,6 +917,72 @@ } +static SoundDeviceType ParseType(const std::wstring &identifier) +//-------------------------------------------------------------- +{ + for(int i = 0; i < SNDDEV_NUM_DEVTYPES; ++i) + { + const std::wstring api = SoundDeviceTypeToString(static_cast<SoundDeviceType>(i)); + if(identifier.find(api) == 0) + { + return static_cast<SoundDeviceType>(i); + } + } + return SNDDEV_INVALID; +} + + +SoundDeviceInfo SoundDevicesManager::FindDeviceInfoBestMatch(const std::wstring &identifier) const +//------------------------------------------------------------------------------------------------ +{ + if(m_SoundDevices.empty()) + { + return SoundDeviceInfo(); + } + if(identifier.empty()) + { + return m_SoundDevices[0]; + } + for(std::vector<SoundDeviceInfo>::const_iterator it = begin(); it != end(); ++it) + { + if(it->GetIdentifier() == identifier) + { // exact match + return *it; + } + } + const SoundDeviceType type = ParseType(identifier); + switch(type) + { + case SNDDEV_PORTAUDIO_WASAPI: + // WASAPI devices might change names if a different connector jack is used. + // In order to avoid defaulting to wave mapper in that case, + // just find the first WASAPI device. + for(std::vector<SoundDeviceInfo>::const_iterator it = begin(); it != end(); ++it) + { + if(it->id.GetType() == SNDDEV_PORTAUDIO_WASAPI) + { + return *it; + } + } + // default to first device + return *begin(); + break; + case SNDDEV_WAVEOUT: + case SNDDEV_DSOUND: + case SNDDEV_PORTAUDIO_WMME: + case SNDDEV_PORTAUDIO_DS: + case SNDDEV_ASIO: + case SNDDEV_PORTAUDIO_WDMKS: + case SNDDEV_PORTAUDIO_ASIO: + // default to first device + return *begin(); + break; + } + // invalid + return SoundDeviceInfo(); +} + + bool SoundDevicesManager::OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice) //-------------------------------------------------------------------------------------------------------------------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-29 22:33:28 UTC (rev 3336) @@ -98,6 +98,8 @@ SNDDEV_NUM_DEVTYPES }; +std::wstring SoundDeviceTypeToString(SoundDeviceType type); + typedef uint8 SoundDeviceIndex; template<typename T> @@ -518,6 +520,7 @@ SoundDeviceInfo FindDeviceInfo(SoundDeviceID id) const; SoundDeviceInfo FindDeviceInfo(const std::wstring &identifier) const; + SoundDeviceInfo FindDeviceInfoBestMatch(const std::wstring &identifier) const; bool OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -152,7 +152,7 @@ if(SoundDeviceIndexIsValid(devices.size())) { // everything ok - devices.push_back(SoundDeviceInfo(SoundDeviceID(SNDDEV_ASIO, static_cast<SoundDeviceIndex>(devices.size())), description, L"ASIO", internalID)); + devices.push_back(SoundDeviceInfo(SoundDeviceID(SNDDEV_ASIO, static_cast<SoundDeviceIndex>(devices.size())), description, SoundDeviceTypeToString(SNDDEV_ASIO), internalID)); } } } Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -73,7 +73,7 @@ SoundDeviceInfo info; info.id = SoundDeviceID(SNDDEV_DSOUND, static_cast<SoundDeviceIndex>(devices.size())); info.name = lpstrDescription; - info.apiName = L"DirectSound"; + info.apiName = SoundDeviceTypeToString(SNDDEV_DSOUND); if(lpGuid) { info.internalID = GuidToString(*lpGuid); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -353,15 +353,15 @@ } -std::string CPortaudioDevice::HostApiToString(PaHostApiIndex hostapi) -//------------------------------------------------------------------- +std::wstring CPortaudioDevice::HostApiToString(PaHostApiIndex hostapi) +//-------------------------------------------------------------------- { - if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWASAPI)) return "WASAPI"; - if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) return "WDM-KS"; - if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paMME)) return "MME"; - if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paDirectSound)) return "DS"; - if(hostapi == Pa_HostApiTypeIdToHostApiIndex(paASIO)) return "ASIO"; - return "PortAudio"; + SoundDeviceType type = HostApiToSndDevType(hostapi); + if(type == SNDDEV_INVALID) + { + return L"PortAudio"; + } + return SoundDeviceTypeToString(type); } @@ -376,7 +376,7 @@ return false; result.id = SoundDeviceID(HostApiToSndDevType(hostapi), index); result.name = mpt::ToWide(mpt::CharsetUTF8, Pa_GetDeviceInfo(dev)->name); - result.apiName = mpt::ToWide(mpt::CharsetUTF8, HostApiToString(Pa_GetDeviceInfo(dev)->hostApi)); + result.apiName = HostApiToString(Pa_GetDeviceInfo(dev)->hostApi); result.isDefault = (Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == (PaDeviceIndex)dev); return true; } Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-29 22:33:28 UTC (rev 3336) @@ -72,7 +72,7 @@ void *userData ); - static std::string HostApiToString(PaHostApiIndex hostapi); + static std::wstring HostApiToString(PaHostApiIndex hostapi); static PaDeviceIndex HostApiOutputIndexToGlobalDeviceIndex(int hostapioutputdeviceindex, PaHostApiIndex hostapi); static SoundDeviceType HostApiToSndDevType(PaHostApiIndex hostapi); Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-29 21:39:12 UTC (rev 3335) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-29 22:33:28 UTC (rev 3336) @@ -243,7 +243,7 @@ } SoundDeviceInfo info; info.id = SoundDeviceID(SNDDEV_WAVEOUT, static_cast<SoundDeviceIndex>(index)); - info.apiName = L"WaveOut"; + info.apiName = SoundDeviceTypeToString(SNDDEV_WAVEOUT); WAVEOUTCAPSW woc; MemsetZero(woc); if(index == 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |