From: <man...@us...> - 2014-09-29 07:14:14
|
Revision: 4321 http://sourceforge.net/p/modplug/code/4321 Author: manxorist Date: 2014-09-29 07:13:52 +0000 (Mon, 29 Sep 2014) Log Message: ----------- [Mod] Soundcard settings: No longer display a modal dialog when chaging to the soundcard tab in case of a unavailable sound device being selected. Instead, just select the best matching device immediately. In case of changing to a unavailable device, retain the modal dialog box as silently modifying the underlying combo box would be evenmore annoying. [Mod] Soundcard settings: Add a hidden setting [Sound Settings]PreferSameTypeIfDeviceUnavailable=0 which optionally changes the algorithm for selecting the fallback device if the device selected by the user (or read from the configuration) is currently unavailable. When this setting is set, a device of the same type as the currently selected is preferred instead of just defaulting to wave mapper. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.h trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-29 07:13:52 UTC (rev 4321) @@ -1887,7 +1887,7 @@ CPropertySheet dlg("OpenMPT Setup", this, m_nLastOptionsPage); COptionsGeneral general; - COptionsSoundcard sounddlg(TrackerSettings::Instance().GetSoundDeviceID()); + COptionsSoundcard sounddlg(TrackerSettings::Instance().m_SoundDeviceIdentifier); COptionsSampleEditor smpeditor; COptionsKeyboard keyboard; COptionsColors colors; Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-09-29 07:13:52 UTC (rev 4321) @@ -149,15 +149,42 @@ } -COptionsSoundcard::COptionsSoundcard(SoundDevice::ID dev) -//------------------------------------------------------- +COptionsSoundcard::COptionsSoundcard(std::wstring deviceIdentifier) +//----------------------------------------------------------------- : CPropertyPage(IDD_OPTIONS_SOUNDCARD) - , m_InitialDevice(dev) + , m_InitialDeviceIdentifier(deviceIdentifier) { return; } +void COptionsSoundcard::SetInitialDevice() +//---------------------------------------- +{ + bool ok = false; + std::set<SoundDevice::ID> triedSet; + while(!ok) + { + m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_InitialDeviceIdentifier, TrackerSettings::Instance().m_SoundDevicePreferSameTypeIfDeviceUnavailable); + SoundDevice::ID dev = m_CurrentDeviceInfo.id; + if(triedSet.find(dev) != triedSet.end()) + { + Reporting::Error("No sound device available."); + break; + } + m_CurrentDeviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, CMainFrame::GetMainFrame()->gpSoundDevice); + m_CurrentDeviceDynamicCaps = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true); + if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(dev)) + { + triedSet.insert(dev); + m_InitialDeviceIdentifier = m_CurrentDeviceInfo.GetIdentifier(); + continue; // makes progress because FindDeviceInfoBestMatch will not return devices again that were found out to be unavailable + } + ok = true; + } +} + + void COptionsSoundcard::SetDevice(SoundDevice::ID dev, bool forceReload) //---------------------------------------------------------------------- { @@ -171,16 +198,22 @@ } if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(dev)) { - // if the device is unavailable, use the default device - SoundDevice::ID newdev = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(std::wstring()).id; + SoundDevice::ID newdev; + if(TrackerSettings::Instance().m_SoundDevicePreferSameTypeIfDeviceUnavailable) + { // try finding a device of the same type + newdev = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_CurrentDeviceInfo.GetIdentifier(), true).id; + } else + { // if the device is unavailable, use the default device + newdev = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(std::wstring()).id; + } if(newdev != dev) { - Reporting::Information("Device not availble. Reverting to default device."); + Reporting::Information("Device not available. Reverting to default device."); SetDevice(newdev); UpdateEverything(); } else { - Reporting::Warning("Device not availble."); + Reporting::Warning("Device not available."); } } } @@ -204,7 +237,7 @@ //------------------------------------ { CPropertyPage::OnInitDialog(); - SetDevice(m_InitialDevice, true); + SetInitialDevice(); UpdateEverything(); return TRUE; } Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2014-09-29 07:13:52 UTC (rev 4321) @@ -32,7 +32,8 @@ CStatic m_StaticChannelMapping[NUM_CHANNELCOMBOBOXES]; CComboBox m_CbnChannelMapping[NUM_CHANNELCOMBOBOXES]; - SoundDevice::ID m_InitialDevice; + std::wstring m_InitialDeviceIdentifier; + void SetInitialDevice(); void SetDevice(SoundDevice::ID dev, bool forceReload=false); SoundDevice::Info m_CurrentDeviceInfo; @@ -41,7 +42,7 @@ SoundDevice::Settings m_Settings; public: - COptionsSoundcard(SoundDevice::ID sd); + COptionsSoundcard(std::wstring deviceIdentifier); void UpdateStatistics(); Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2014-09-29 07:13:52 UTC (rev 4321) @@ -173,6 +173,7 @@ , m_SoundDeviceSettingsUseOldDefaults(false) , m_SoundDeviceID_DEPRECATED(SoundDevice::ID()) , m_SoundDeviceIdentifier(conf, "Sound Settings", "Device", std::wstring()) + , m_SoundDevicePreferSameTypeIfDeviceUnavailable(conf, "Sound Settings", "PreferSameTypeIfDeviceUnavailable", false) , MixerMaxChannels(conf, "Sound Settings", "MixChannels", MixerSettings().m_nMaxMixChannels) , MixerDSPMask(conf, "Sound Settings", "Quality", MixerSettings().DSPMask) , MixerFlags(conf, "Sound Settings", "SoundSetup", MixerSettings().MixerFlags) Modified: trunk/OpenMPT/mptrack/TrackerSettings.h =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/mptrack/TrackerSettings.h 2014-09-29 07:13:52 UTC (rev 4321) @@ -379,6 +379,7 @@ SoundDevice::Settings GetSoundDeviceSettingsDefaults() const; Setting<std::wstring> m_SoundDeviceIdentifier; + Setting<bool> m_SoundDevicePreferSameTypeIfDeviceUnavailable; SoundDevice::ID GetSoundDeviceID() const; void SetSoundDeviceID(const SoundDevice::ID &id); SoundDevice::Settings GetSoundDeviceSettings(const SoundDevice::ID &device) const; Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-29 07:13:52 UTC (rev 4321) @@ -562,8 +562,8 @@ } -SoundDevice::Info Manager::FindDeviceInfoBestMatch(const std::wstring &identifier) const -//-------------------------------------------------------------------------------------- +SoundDevice::Info Manager::FindDeviceInfoBestMatch(const std::wstring &identifier, bool preferSameType) +//----------------------------------------------------------------------------------------------------- { if(m_SoundDevices.empty()) { @@ -575,7 +575,7 @@ } for(std::vector<SoundDevice::Info>::const_iterator it = begin(); it != end(); ++it) { - if(it->GetIdentifier() == identifier) + if((it->GetIdentifier() == identifier) && !IsDeviceUnavailable(it->id)) { // exact match return *it; } @@ -589,7 +589,7 @@ // just find the first WASAPI device. for(std::vector<SoundDevice::Info>::const_iterator it = begin(); it != end(); ++it) { - if(it->id.GetType() == TypePORTAUDIO_WASAPI) + if((it->id.GetType() == TypePORTAUDIO_WASAPI) && !IsDeviceUnavailable(it->id)) { return *it; } @@ -604,8 +604,20 @@ case TypeASIO: case TypePORTAUDIO_WDMKS: case TypePORTAUDIO_ASIO: - // default to first device - return *begin(); + if(preferSameType) + { + for(std::vector<SoundDevice::Info>::const_iterator it = begin(); it != end(); ++it) + { + if((it->id.GetType() == type) && !IsDeviceUnavailable(it->id)) + { + return *it; + } + } + } else + { + // default to first device + return *begin(); + } break; } // invalid Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-29 06:38:49 UTC (rev 4320) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-29 07:13:52 UTC (rev 4321) @@ -669,7 +669,7 @@ SoundDevice::Info FindDeviceInfo(SoundDevice::ID id) const; SoundDevice::Info FindDeviceInfo(const std::wstring &identifier) const; - SoundDevice::Info FindDeviceInfoBestMatch(const std::wstring &identifier) const; + SoundDevice::Info FindDeviceInfoBestMatch(const std::wstring &identifier, bool preferSameType = false); bool OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |