From: <man...@us...> - 2013-11-23 08:52:48
|
Revision: 3294 http://sourceforge.net/p/modplug/code/3294 Author: manxorist Date: 2013-11-23 08:52:35 +0000 (Sat, 23 Nov 2013) Log Message: ----------- [Ref] sounddev: Let FindDeviceInfo return an invalid sentinal instead of a nullptr in error case. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-23 08:18:31 UTC (rev 3293) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-23 08:52:35 UTC (rev 3294) @@ -242,7 +242,7 @@ OnUpdateFrameTitle(false); // Check for valid sound device - if(!theApp.GetSoundDevicesManager()->FindDeviceInfo(TrackerSettings::Instance().m_nWaveDevice)) + if(!theApp.GetSoundDevicesManager()->FindDeviceInfo(TrackerSettings::Instance().m_nWaveDevice).IsValid()) { // Fall back to default WaveOut device TrackerSettings::Instance().m_nWaveDevice = SoundDeviceID(); Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-23 08:18:31 UTC (rev 3293) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-23 08:52:35 UTC (rev 3294) @@ -116,7 +116,7 @@ void COptionsSoundcard::SetDevice(SoundDeviceID dev) //-------------------------------------------------- { - m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev) ? *(theApp.GetSoundDevicesManager()->FindDeviceInfo(dev)) : SoundDeviceInfo(); + m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev); m_CurrentDeviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true); } Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-23 08:18:31 UTC (rev 3293) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-23 08:52:35 UTC (rev 3294) @@ -852,17 +852,17 @@ } -const SoundDeviceInfo * SoundDevicesManager::FindDeviceInfo(SoundDeviceID id) const -//--------------------------------------------------------------------------------- +SoundDeviceInfo SoundDevicesManager::FindDeviceInfo(SoundDeviceID id) const +//------------------------------------------------------------------------- { for(std::vector<SoundDeviceInfo>::const_iterator it = begin(); it != end(); ++it) { if(it->id == id) { - return &(*it); + return *it; } } - return nullptr; + return SoundDeviceInfo(); } @@ -870,7 +870,7 @@ //-------------------------------------------------------------------------------------------------------------------------------------- { bool result = false; - if(currentSoundDevice && FindDeviceInfo(id) && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id)->internalID)) + if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) { result = currentSoundDevice->OpenDriverSettings(); } else @@ -892,7 +892,7 @@ { if((m_DeviceCaps.find(id) == m_DeviceCaps.end()) || update) { - if(currentSoundDevice && FindDeviceInfo(id) && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id)->internalID)) + if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) { m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(baseSampleRates); } else @@ -913,20 +913,20 @@ ISoundDevice * SoundDevicesManager::CreateSoundDevice(SoundDeviceID id) //--------------------------------------------------------------------- { - const SoundDeviceInfo *info = FindDeviceInfo(id); - if(!info) + const SoundDeviceInfo info = FindDeviceInfo(id); + if(info.IsValid()) { return nullptr; } ISoundDevice *result = nullptr; switch(id.GetType()) { - case SNDDEV_WAVEOUT: result = new CWaveDevice(id, info->internalID); break; + case SNDDEV_WAVEOUT: result = new CWaveDevice(id, info.internalID); break; #ifndef NO_DSOUND - case SNDDEV_DSOUND: result = new CDSoundDevice(id, info->internalID); break; + case SNDDEV_DSOUND: result = new CDSoundDevice(id, info.internalID); break; #endif // NO_DSOUND #ifndef NO_ASIO - case SNDDEV_ASIO: result = new CASIODevice(id, info->internalID); break; + case SNDDEV_ASIO: result = new CASIODevice(id, info.internalID); break; #endif // NO_ASIO #ifndef NO_PORTAUDIO case SNDDEV_PORTAUDIO_WASAPI: @@ -934,7 +934,7 @@ case SNDDEV_PORTAUDIO_WMME: case SNDDEV_PORTAUDIO_DS: case SNDDEV_PORTAUDIO_ASIO: - result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(id, info->internalID) : nullptr; + result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(id, info.internalID) : nullptr; break; #endif // NO_PORTAUDIO } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-23 08:18:31 UTC (rev 3293) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-23 08:52:35 UTC (rev 3294) @@ -121,6 +121,10 @@ { return; } + bool IsValid() const + { + return (type > SNDDEV_INVALID); + } SoundDeviceType GetType() const { return type; } SoundDeviceIndex GetIndex() const { return index; } bool operator == (const SoundDeviceID &cmp) const @@ -436,7 +440,7 @@ std::wstring name; std::wstring apiName; std::wstring internalID; - SoundDeviceInfo() { } + SoundDeviceInfo() : id(SNDDEV_INVALID, 0) { } SoundDeviceInfo(SoundDeviceID id, const std::wstring &name, const std::wstring &apiName, const std::wstring &internalID = std::wstring()) : id(id) , name(name) @@ -445,6 +449,10 @@ { return; } + bool IsValid() const + { + return id.IsValid(); + } }; @@ -468,7 +476,7 @@ std::vector<SoundDeviceInfo>::const_iterator end() const { return m_SoundDevices.end(); } const std::vector<SoundDeviceInfo> & GetDeviceInfos() const { return m_SoundDevices; } - const SoundDeviceInfo * FindDeviceInfo(SoundDeviceID id) const; + SoundDeviceInfo FindDeviceInfo(SoundDeviceID id) const; bool OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |