From: <man...@us...> - 2014-09-29 09:01:26
|
Revision: 4323 http://sourceforge.net/p/modplug/code/4323 Author: manxorist Date: 2014-09-29 09:01:08 +0000 (Mon, 29 Sep 2014) Log Message: ----------- [Ref] sounddev: Having both, a (type,index) tuple (SoundDevice::ID) and a string based identifier (SoundDevice::Identifier) to identify sound device got way too confusing. Rework the SoundDevice::Manager interface to always expect the string based identifier. The old SoundDevice::ID is still used internally and exposed for the purpose of importing old ini files. All other cases now use SoundDevice::Identifier. [Ref] sounddev: Related cleanups. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceThread.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -243,19 +243,21 @@ OnUpdateFrameTitle(false); // Check for valid sound device - if(!theApp.GetSoundDevicesManager()->FindDeviceInfo(TrackerSettings::Instance().GetSoundDeviceID()).IsValid()) + SoundDevice::Identifier dev = TrackerSettings::Instance().GetSoundDeviceIdentifier(); + if(!theApp.GetSoundDevicesManager()->FindDeviceInfo(dev).IsValid()) { // Fall back to default WaveOut device - TrackerSettings::Instance().SetSoundDeviceID(SoundDevice::ID()); + dev = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(dev, TrackerSettings::Instance().m_SoundDevicePreferSameTypeIfDeviceUnavailable).GetIdentifier(); + TrackerSettings::Instance().SetSoundDeviceIdentifier(dev); } if(TrackerSettings::Instance().MixerSamplerate == 0) { TrackerSettings::Instance().MixerSamplerate = MixerSettings().gdwMixingFreq; #ifndef NO_ASIO // If no mixing rate is specified and we're using ASIO, get a mixing rate supported by the device. - if(TrackerSettings::Instance().GetSoundDeviceID().GetType() == SoundDevice::TypeASIO) + if(SoundDevice::ParseType(dev) == SoundDevice::TypeASIO) { - TrackerSettings::Instance().MixerSamplerate = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(TrackerSettings::Instance().GetSoundDeviceID(), TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).currentSampleRate; + TrackerSettings::Instance().MixerSamplerate = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).currentSampleRate; } #endif // NO_ASIO } @@ -810,8 +812,8 @@ Reporting::Error("Unable to open sound device: Invalid mixer settings."); return false; } - const SoundDevice::ID deviceID = TrackerSettings::Instance().GetSoundDeviceID(); - if(gpSoundDevice && (gpSoundDevice->GetDeviceID() != deviceID)) + const SoundDevice::Identifier deviceIdentifier = TrackerSettings::Instance().GetSoundDeviceIdentifier(); + if(gpSoundDevice && (gpSoundDevice->GetDeviceIdentifier() != deviceIdentifier)) { gpSoundDevice->Stop(); gpSoundDevice->Close(); @@ -824,7 +826,7 @@ } if(!gpSoundDevice) { - gpSoundDevice = theApp.GetSoundDevicesManager()->CreateSoundDevice(deviceID); + gpSoundDevice = theApp.GetSoundDevicesManager()->CreateSoundDevice(deviceIdentifier); } if(!gpSoundDevice) { @@ -833,12 +835,12 @@ } gpSoundDevice->SetMessageReceiver(this); gpSoundDevice->SetSource(this); - SoundDevice::Settings deviceSettings = TrackerSettings::Instance().GetSoundDeviceSettings(deviceID); + SoundDevice::Settings deviceSettings = TrackerSettings::Instance().GetSoundDeviceSettings(deviceIdentifier); if(!gpSoundDevice->Open(deviceSettings)) { if(!gpSoundDevice->IsAvailable()) { - theApp.GetSoundDevicesManager()->SetDeviceUnavailable(deviceID); + theApp.GetSoundDevicesManager()->SetDeviceUnavailable(deviceIdentifier); Reporting::Error("Unable to open sound device: Device not available."); } else { @@ -854,7 +856,7 @@ } deviceSettings.sampleFormat = actualSampleFormat; TrackerSettings::Instance().MixerSamplerate = gpSoundDevice->GetSettings().Samplerate; - TrackerSettings::Instance().SetSoundDeviceSettings(deviceID, deviceSettings); + TrackerSettings::Instance().SetSoundDeviceSettings(deviceIdentifier, deviceSettings); return true; } @@ -1680,16 +1682,16 @@ BOOL CMainFrame::ResetSoundCard() //------------------------------- { - return CMainFrame::SetupSoundCard(TrackerSettings::Instance().GetSoundDeviceSettings(TrackerSettings::Instance().GetSoundDeviceID()), TrackerSettings::Instance().GetSoundDeviceID(), TrackerSettings::Instance().m_SoundSettingsStopMode, true); + return CMainFrame::SetupSoundCard(TrackerSettings::Instance().GetSoundDeviceSettings(TrackerSettings::Instance().GetSoundDeviceIdentifier()), TrackerSettings::Instance().GetSoundDeviceIdentifier(), TrackerSettings::Instance().m_SoundSettingsStopMode, true); } -BOOL CMainFrame::SetupSoundCard(SoundDevice::Settings deviceSettings, SoundDevice::ID deviceID, SoundDevice::StopMode stoppedMode, bool forceReset) -//------------------------------------------------------------------------------------------------------------------------------------------------- +BOOL CMainFrame::SetupSoundCard(SoundDevice::Settings deviceSettings, SoundDevice::Identifier deviceIdentifier, SoundDevice::StopMode stoppedMode, bool forceReset) +//----------------------------------------------------------------------------------------------------------------------------------------------------------------- { if(forceReset - || (TrackerSettings::Instance().GetSoundDeviceID() != deviceID) - || (TrackerSettings::Instance().GetSoundDeviceSettings(deviceID) != deviceSettings) + || (TrackerSettings::Instance().GetSoundDeviceIdentifier() != deviceIdentifier) + || (TrackerSettings::Instance().GetSoundDeviceSettings(deviceIdentifier) != deviceSettings) || (TrackerSettings::Instance().m_SoundSettingsStopMode != stoppedMode) ) { @@ -1716,8 +1718,8 @@ deviceSettings.KeepDeviceRunning = true; break; } - TrackerSettings::Instance().SetSoundDeviceID(deviceID); - TrackerSettings::Instance().SetSoundDeviceSettings(deviceID, deviceSettings); + TrackerSettings::Instance().SetSoundDeviceIdentifier(deviceIdentifier); + TrackerSettings::Instance().SetSoundDeviceSettings(deviceIdentifier, deviceSettings); TrackerSettings::Instance().MixerOutputChannels = deviceSettings.Channels; TrackerSettings::Instance().MixerSamplerate = deviceSettings.Samplerate; if(pActiveMod) Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -494,7 +494,7 @@ void IdleHandlerSounddevice(); BOOL ResetSoundCard(); - BOOL SetupSoundCard(SoundDevice::Settings deviceSettings, SoundDevice::ID deviceID, SoundDevice::StopMode stoppedMode, bool forceReset = false); + BOOL SetupSoundCard(SoundDevice::Settings deviceSettings, SoundDevice::Identifier deviceIdentifier, SoundDevice::StopMode stoppedMode, bool forceReset = false); BOOL SetupMiscOptions(); BOOL SetupPlayer(); Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -162,11 +162,11 @@ //---------------------------------------- { bool ok = false; - std::set<SoundDevice::ID> triedSet; + std::set<SoundDevice::Identifier> triedSet; while(!ok) { m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_InitialDeviceIdentifier, TrackerSettings::Instance().m_SoundDevicePreferSameTypeIfDeviceUnavailable); - SoundDevice::ID dev = m_CurrentDeviceInfo.id; + SoundDevice::Identifier dev = m_CurrentDeviceInfo.GetIdentifier(); if(triedSet.find(dev) != triedSet.end()) { Reporting::Error("No sound device available."); @@ -186,10 +186,10 @@ } -void COptionsSoundcard::SetDevice(SoundDevice::ID dev, bool forceReload) -//---------------------------------------------------------------------- +void COptionsSoundcard::SetDevice(SoundDevice::Identifier dev, bool forceReload) +//------------------------------------------------------------------------------ { - bool deviceChanged = (dev != m_CurrentDeviceInfo.id); + bool deviceChanged = (dev != m_CurrentDeviceInfo.GetIdentifier()); m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev); m_CurrentDeviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, CMainFrame::GetMainFrame()->gpSoundDevice); m_CurrentDeviceDynamicCaps = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true); @@ -199,14 +199,7 @@ } if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(dev)) { - 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; - } + SoundDevice::Identifier newdev = theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_CurrentDeviceInfo.GetIdentifier(), TrackerSettings::Instance().m_SoundDevicePreferSameTypeIfDeviceUnavailable).GetIdentifier(); if(newdev != dev) { Reporting::Information("Device not available. Reverting to default device."); @@ -360,7 +353,7 @@ } } - if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(it->id)) + if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(it->GetIdentifier())) { continue; } @@ -582,7 +575,7 @@ int n = m_CbnDevice.GetCurSel(); if(n >= 0) { - SetDevice(SoundDevice::ID::FromIdRaw(m_CbnDevice.GetItemData(n))); + SetDevice(theApp.GetSoundDevicesManager()->FindDeviceInfo(SoundDevice::ID::FromIdRaw(m_CbnDevice.GetItemData(n))).GetIdentifier()); UpdateDevice(); OnSettingsChanged(); } @@ -608,7 +601,11 @@ void COptionsSoundcard::OnSoundCardDriverPanel() //---------------------------------------------- { - theApp.GetSoundDevicesManager()->OpenDriverSettings(SoundDevice::ID::FromIdRaw(m_CbnDevice.GetItemData(m_CbnDevice.GetCurSel())), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice); + theApp.GetSoundDevicesManager()->OpenDriverSettings( + theApp.GetSoundDevicesManager()->FindDeviceInfo(SoundDevice::ID::FromIdRaw(m_CbnDevice.GetItemData(m_CbnDevice.GetCurSel()))).GetIdentifier(), + CMainFrame::GetMainFrame(), + CMainFrame::GetMainFrame()->gpSoundDevice + ); } @@ -763,7 +760,6 @@ UINT n = m_CbnDither.GetCurSel(); m_Settings.DitherType = (DitherMode)(n); } - const SoundDevice::ID dev = m_CurrentDeviceInfo.id; // Latency { CString s; @@ -801,8 +797,8 @@ m_Settings.ChannelMapping = SoundDevice::ChannelMapping(); } } - CMainFrame::GetMainFrame()->SetupSoundCard(m_Settings, m_CurrentDeviceInfo.id, (SoundDevice::StopMode)m_CbnStoppedMode.GetCurSel()); - SetDevice(m_CurrentDeviceInfo.id, true); // Poll changed ASIO sample format and channel names + CMainFrame::GetMainFrame()->SetupSoundCard(m_Settings, m_CurrentDeviceInfo.GetIdentifier(), (SoundDevice::StopMode)m_CbnStoppedMode.GetCurSel()); + SetDevice(m_CurrentDeviceInfo.GetIdentifier(), true); // Poll changed ASIO sample format and channel names UpdateDevice(); UpdateStatistics(); CPropertyPage::OnOK(); Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -32,10 +32,10 @@ CStatic m_StaticChannelMapping[NUM_CHANNELCOMBOBOXES]; CComboBox m_CbnChannelMapping[NUM_CHANNELCOMBOBOXES]; - std::wstring m_InitialDeviceIdentifier; + SoundDevice::Identifier m_InitialDeviceIdentifier; void SetInitialDevice(); - void SetDevice(SoundDevice::ID dev, bool forceReload=false); + void SetDevice(SoundDevice::Identifier dev, bool forceReload=false); SoundDevice::Info m_CurrentDeviceInfo; SoundDevice::Caps m_CurrentDeviceCaps; SoundDevice::DynamicCaps m_CurrentDeviceDynamicCaps; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -914,11 +914,11 @@ if(TrackerSettings::Instance().m_SoundDeviceSettingsUseOldDefaults) { // get the old default device - TrackerSettings::Instance().m_SoundDeviceIdentifier = m_pSoundDevicesManager->FindDeviceInfo(TrackerSettings::Instance().m_SoundDeviceID_DEPRECATED).GetIdentifier(); + TrackerSettings::Instance().SetSoundDeviceIdentifier(m_pSoundDevicesManager->FindDeviceInfo(TrackerSettings::Instance().m_SoundDeviceID_DEPRECATED).GetIdentifier()); // apply old global sound device settings to each found device for(std::vector<SoundDevice::Info>::const_iterator it = m_pSoundDevicesManager->begin(); it != m_pSoundDevicesManager->end(); ++it) { - TrackerSettings::Instance().SetSoundDeviceSettings(it->id, TrackerSettings::Instance().GetSoundDeviceSettingsDefaults()); + TrackerSettings::Instance().SetSoundDeviceSettings(it->GetIdentifier(), TrackerSettings::Instance().GetSoundDeviceSettingsDefaults()); } } Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -658,20 +658,20 @@ return m_SoundDeviceSettingsDefaults; } -SoundDevice::ID TrackerSettings::GetSoundDeviceID() const -//------------------------------------------------------- +SoundDevice::Identifier TrackerSettings::GetSoundDeviceIdentifier() const +//----------------------------------------------------------------------- { - return theApp.GetSoundDevicesManager()->FindDeviceInfoBestMatch(m_SoundDeviceIdentifier).id; + return m_SoundDeviceIdentifier; } -void TrackerSettings::SetSoundDeviceID(const SoundDevice::ID &id) -//--------------------------------------------------------------- +void TrackerSettings::SetSoundDeviceIdentifier(const SoundDevice::Identifier &identifier) +//--------------------------------------------------------------------------------------- { - m_SoundDeviceIdentifier = theApp.GetSoundDevicesManager()->FindDeviceInfo(id).GetIdentifier(); + m_SoundDeviceIdentifier = identifier; } -SoundDevice::Settings TrackerSettings::GetSoundDeviceSettings(const SoundDevice::ID &device) const -//------------------------------------------------------------------------------------------------ +SoundDevice::Settings TrackerSettings::GetSoundDeviceSettings(const SoundDevice::Identifier &device) const +//-------------------------------------------------------------------------------------------------------- { const SoundDevice::Info deviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(device); if(!deviceInfo.IsValid()) @@ -684,8 +684,8 @@ return settings; } -void TrackerSettings::SetSoundDeviceSettings(const SoundDevice::ID &device, const SoundDevice::Settings &settings) -//---------------------------------------------------------------------------------------------------------------- +void TrackerSettings::SetSoundDeviceSettings(const SoundDevice::Identifier &device, const SoundDevice::Settings &settings) +//------------------------------------------------------------------------------------------------------------------------ { const SoundDevice::Info deviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(device); if(!deviceInfo.IsValid()) Modified: trunk/OpenMPT/mptrack/TrackerSettings.h =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/mptrack/TrackerSettings.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -380,10 +380,10 @@ 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; - void SetSoundDeviceSettings(const SoundDevice::ID &device, const SoundDevice::Settings &settings); + SoundDevice::Identifier GetSoundDeviceIdentifier() const; + void SetSoundDeviceIdentifier(const SoundDevice::Identifier &identifier); + SoundDevice::Settings GetSoundDeviceSettings(const SoundDevice::Identifier &device) const; + void SetSoundDeviceSettings(const SoundDevice::Identifier &device, const SoundDevice::Settings &settings); Setting<uint32> MixerMaxChannels; Setting<uint32> MixerDSPMask; Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -140,12 +140,11 @@ // SoundDevice::Base base class // -Base::Base(SoundDevice::ID id, const std::wstring &internalID) -//------------------------------------------------------------ +Base::Base(SoundDevice::Info info) +//-------------------------------- : m_Source(nullptr) , m_MessageReceiver(nullptr) - , m_ID(id) - , m_InternalID(internalID) + , m_Info(info) { m_DeviceUnavailableOnOpen = false; @@ -525,8 +524,8 @@ } -SoundDevice::Info Manager::FindDeviceInfo(const std::wstring &identifier) const -//----------------------------------------------------------------------------- +SoundDevice::Info Manager::FindDeviceInfo(SoundDevice::Identifier identifier) const +//--------------------------------------------------------------------------------- { if(m_SoundDevices.empty()) { @@ -547,8 +546,8 @@ } -static SoundDevice::Type ParseType(const std::wstring &identifier) -//---------------------------------------------------------------- +SoundDevice::Type ParseType(const SoundDevice::Identifier &identifier) +//-------------------------------------------------------------------- { for(int i = 0; i < TypeNUM_DEVTYPES; ++i) { @@ -562,8 +561,8 @@ } -SoundDevice::Info Manager::FindDeviceInfoBestMatch(const std::wstring &identifier, bool preferSameType) -//----------------------------------------------------------------------------------------------------- +SoundDevice::Info Manager::FindDeviceInfoBestMatch(SoundDevice::Identifier identifier, bool preferSameType) +//--------------------------------------------------------------------------------------------------------- { if(m_SoundDevices.empty()) { @@ -575,7 +574,7 @@ } for(std::vector<SoundDevice::Info>::const_iterator it = begin(); it != end(); ++it) { - if((it->GetIdentifier() == identifier) && !IsDeviceUnavailable(it->id)) + if((it->GetIdentifier() == identifier) && !IsDeviceUnavailable(it->GetIdentifier())) { // exact match return *it; } @@ -589,7 +588,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) && !IsDeviceUnavailable(it->id)) + if((it->id.GetType() == TypePORTAUDIO_WASAPI) && !IsDeviceUnavailable(it->GetIdentifier())) { return *it; } @@ -608,7 +607,7 @@ { for(std::vector<SoundDevice::Info>::const_iterator it = begin(); it != end(); ++it) { - if((it->id.GetType() == type) && !IsDeviceUnavailable(it->id)) + if((it->id.GetType() == type) && !IsDeviceUnavailable(it->GetIdentifier())) { return *it; } @@ -625,16 +624,16 @@ } -bool Manager::OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice) -//------------------------------------------------------------------------------------------------------------------------------------------ +bool Manager::OpenDriverSettings(SoundDevice::Identifier identifier, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice) +//---------------------------------------------------------------------------------------------------------------------------------------------------------- { bool result = false; - if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) + if(currentSoundDevice && FindDeviceInfo(identifier).IsValid() && (currentSoundDevice->GetDeviceIdentifier() == identifier)) { result = currentSoundDevice->OpenDriverSettings(); } else { - SoundDevice::IBase *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(identifier); if(dummy) { dummy->SetMessageReceiver(messageReceiver); @@ -646,82 +645,82 @@ } -SoundDevice::Caps Manager::GetDeviceCaps(SoundDevice::ID id, SoundDevice::IBase *currentSoundDevice) -//-------------------------------------------------------------------------------------------------- +SoundDevice::Caps Manager::GetDeviceCaps(SoundDevice::Identifier identifier, SoundDevice::IBase *currentSoundDevice) +//------------------------------------------------------------------------------------------------------------------ { - if(m_DeviceCaps.find(id) == m_DeviceCaps.end()) + if(m_DeviceCaps.find(identifier) == m_DeviceCaps.end()) { - if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) + if(currentSoundDevice && FindDeviceInfo(identifier).IsValid() && (currentSoundDevice->GetDeviceIdentifier() == identifier)) { - m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(); + m_DeviceCaps[identifier] = currentSoundDevice->GetDeviceCaps(); } else { - SoundDevice::IBase *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(identifier); if(dummy) { - m_DeviceCaps[id] = dummy->GetDeviceCaps(); + m_DeviceCaps[identifier] = dummy->GetDeviceCaps(); } else { - SetDeviceUnavailable(id); + SetDeviceUnavailable(identifier); } delete dummy; } } - return m_DeviceCaps[id]; + return m_DeviceCaps[identifier]; } -SoundDevice::DynamicCaps Manager::GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice, bool update) -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +SoundDevice::DynamicCaps Manager::GetDeviceDynamicCaps(SoundDevice::Identifier identifier, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver, SoundDevice::IBase *currentSoundDevice, bool update) +//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { - if((m_DeviceDynamicCaps.find(id) == m_DeviceDynamicCaps.end()) || update) + if((m_DeviceDynamicCaps.find(identifier) == m_DeviceDynamicCaps.end()) || update) { - if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) + if(currentSoundDevice && FindDeviceInfo(identifier).IsValid() && (currentSoundDevice->GetDeviceIdentifier() == identifier)) { - m_DeviceDynamicCaps[id] = currentSoundDevice->GetDeviceDynamicCaps(baseSampleRates); + m_DeviceDynamicCaps[identifier] = currentSoundDevice->GetDeviceDynamicCaps(baseSampleRates); if(!currentSoundDevice->IsAvailable()) { - SetDeviceUnavailable(id); + SetDeviceUnavailable(identifier); } } else { - SoundDevice::IBase *dummy = CreateSoundDevice(id); + SoundDevice::IBase *dummy = CreateSoundDevice(identifier); if(dummy) { dummy->SetMessageReceiver(messageReceiver); - m_DeviceDynamicCaps[id] = dummy->GetDeviceDynamicCaps(baseSampleRates); + m_DeviceDynamicCaps[identifier] = dummy->GetDeviceDynamicCaps(baseSampleRates); if(!dummy->IsAvailable()) { - SetDeviceUnavailable(id); + SetDeviceUnavailable(identifier); } } else { - SetDeviceUnavailable(id); + SetDeviceUnavailable(identifier); } delete dummy; } } - return m_DeviceDynamicCaps[id]; + return m_DeviceDynamicCaps[identifier]; } -SoundDevice::IBase * Manager::CreateSoundDevice(SoundDevice::ID id) -//----------------------------------------------------------------- +SoundDevice::IBase * Manager::CreateSoundDevice(SoundDevice::Identifier identifier) +//--------------------------------------------------------------------------------- { - const SoundDevice::Info info = FindDeviceInfo(id); + const SoundDevice::Info info = FindDeviceInfo(identifier); if(!info.IsValid()) { return nullptr; } SoundDevice::IBase *result = nullptr; - switch(id.GetType()) + switch(info.id.GetType()) { - case TypeWAVEOUT: result = new CWaveDevice(id, info.internalID); break; + case TypeWAVEOUT: result = new CWaveDevice(info); break; #ifndef NO_DSOUND - case TypeDSOUND: result = new CDSoundDevice(id, info.internalID); break; + case TypeDSOUND: result = new CDSoundDevice(info); break; #endif // NO_DSOUND #ifndef NO_ASIO - case TypeASIO: result = new CASIODevice(id, info.internalID); break; + case TypeASIO: result = new CASIODevice(info); break; #endif // NO_ASIO #ifndef NO_PORTAUDIO case TypePORTAUDIO_WASAPI: @@ -729,7 +728,7 @@ case TypePORTAUDIO_WMME: case TypePORTAUDIO_DS: case TypePORTAUDIO_ASIO: - result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(id, info.internalID) : nullptr; + result = SndDevPortaudioIsInitialized() ? new CPortaudioDevice(info) : nullptr; break; #endif // NO_PORTAUDIO } @@ -743,7 +742,7 @@ result = nullptr; return nullptr; } - m_DeviceCaps[id] = result->GetDeviceCaps(); // update cached caps + m_DeviceCaps[identifier] = result->GetDeviceCaps(); // update cached caps return result; } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -154,6 +154,59 @@ }; +typedef std::wstring Identifier; + +SoundDevice::Type ParseType(const SoundDevice::Identifier &identifier); + + +struct Info +{ + SoundDevice::ID id; + std::wstring name; + std::wstring apiName; + std::wstring internalID; + bool isDefault; + Info() : id(TypeINVALID, 0), isDefault(false) { } + Info(SoundDevice::ID id, const std::wstring &name, const std::wstring &apiName, const std::wstring &internalID = std::wstring()) + : id(id) + , name(name) + , apiName(apiName) + , internalID(internalID) + , isDefault(false) + { + return; + } + bool IsValid() const + { + return id.IsValid(); + } + SoundDevice::Identifier GetIdentifier() const + { + if(!IsValid()) + { + return std::wstring(); + } + std::wstring result = apiName; + result += L"_"; + if(!internalID.empty()) + { + result += internalID; // safe to not contain special characters + } else if(!name.empty()) + { + // UTF8-encode the name and convert the utf8 to hex. + // This ensures that no special characters are contained in the configuration key. + std::string utf8String = mpt::To(mpt::CharsetUTF8, name); + std::wstring hexString = Util::BinToHex(std::vector<char>(utf8String.begin(), utf8String.end())); + result += hexString; + } else + { + result += mpt::ToWString(id.GetIndex()); + } + return result; + } +}; + + struct ChannelMapping { @@ -420,10 +473,12 @@ virtual void SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) = 0; virtual SoundDevice::IMessageReceiver *GetMessageReceiver() const = 0; + virtual SoundDevice::Info GetDeviceInfo() const = 0; virtual SoundDevice::ID GetDeviceID() const = 0; virtual SoundDevice::Type GetDeviceType() const = 0; virtual SoundDevice::Index GetDeviceIndex() const = 0; virtual std::wstring GetDeviceInternalID() const = 0; + virtual SoundDevice::Identifier GetDeviceIdentifier() const = 0; virtual SoundDevice::Caps GetDeviceCaps() const = 0; virtual SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) = 0; @@ -474,10 +529,8 @@ SoundDevice::ISource *m_Source; SoundDevice::IMessageReceiver *m_MessageReceiver; - const SoundDevice::ID m_ID; + const SoundDevice::Info m_Info; - std::wstring m_InternalID; - private: SoundDevice::Caps m_Caps; @@ -545,7 +598,7 @@ protected: - Base(SoundDevice::ID id, const std::wstring &internalID); + Base(SoundDevice::Info info); public: @@ -556,10 +609,12 @@ void SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) { m_MessageReceiver = receiver; } SoundDevice::IMessageReceiver *GetMessageReceiver() const { return m_MessageReceiver; } - SoundDevice::ID GetDeviceID() const { return m_ID; } - SoundDevice::Type GetDeviceType() const { return m_ID.GetType(); } - SoundDevice::Index GetDeviceIndex() const { return m_ID.GetIndex(); } - std::wstring GetDeviceInternalID() const { return m_InternalID; } + SoundDevice::Info GetDeviceInfo() const { return m_Info; } + SoundDevice::ID GetDeviceID() const { return m_Info.id; } + SoundDevice::Type GetDeviceType() const { return m_Info.id.GetType(); } + SoundDevice::Index GetDeviceIndex() const { return m_Info.id.GetIndex(); } + std::wstring GetDeviceInternalID() const { return m_Info.internalID; } + SoundDevice::Identifier GetDeviceIdentifier() const { return m_Info.GetIdentifier(); } SoundDevice::Caps GetDeviceCaps() const { return m_Caps; } virtual SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates); @@ -597,63 +652,15 @@ }; -struct Info -{ - SoundDevice::ID id; - std::wstring name; - std::wstring apiName; - std::wstring internalID; - bool isDefault; - Info() : id(TypeINVALID, 0), isDefault(false) { } - Info(SoundDevice::ID id, const std::wstring &name, const std::wstring &apiName, const std::wstring &internalID = std::wstring()) - : id(id) - , name(name) - , apiName(apiName) - , internalID(internalID) - , isDefault(false) - { - return; - } - bool IsValid() const - { - return id.IsValid(); - } - std::wstring GetIdentifier() const - { - if(!IsValid()) - { - return std::wstring(); - } - std::wstring result = apiName; - result += L"_"; - if(!internalID.empty()) - { - result += internalID; // safe to not contain special characters - } else if(!name.empty()) - { - // UTF8-encode the name and convert the utf8 to hex. - // This ensures that no special characters are contained in the configuration key. - std::string utf8String = mpt::To(mpt::CharsetUTF8, name); - std::wstring hexString = Util::BinToHex(std::vector<char>(utf8String.begin(), utf8String.end())); - result += hexString; - } else - { - result += mpt::ToWString(id.GetIndex()); - } - return result; - } -}; - - //=========== class Manager //=========== { private: std::vector<SoundDevice::Info> m_SoundDevices; - std::map<SoundDevice::ID, bool> m_DeviceUnavailable; - std::map<SoundDevice::ID, SoundDevice::Caps> m_DeviceCaps; - std::map<SoundDevice::ID, SoundDevice::DynamicCaps> m_DeviceDynamicCaps; + std::map<SoundDevice::Identifier, bool> m_DeviceUnavailable; + std::map<SoundDevice::Identifier, SoundDevice::Caps> m_DeviceCaps; + std::map<SoundDevice::Identifier, SoundDevice::DynamicCaps> m_DeviceDynamicCaps; public: Manager(); @@ -668,18 +675,18 @@ const std::vector<SoundDevice::Info> & GetDeviceInfos() const { return m_SoundDevices; } SoundDevice::Info FindDeviceInfo(SoundDevice::ID id) const; - SoundDevice::Info FindDeviceInfo(const std::wstring &identifier) const; - SoundDevice::Info FindDeviceInfoBestMatch(const std::wstring &identifier, bool preferSameType = false); + SoundDevice::Info FindDeviceInfo(SoundDevice::Identifier identifier) const; + SoundDevice::Info FindDeviceInfoBestMatch(SoundDevice::Identifier identifier, bool preferSameType); - bool OpenDriverSettings(SoundDevice::ID id, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr); + bool OpenDriverSettings(SoundDevice::Identifier identifier, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr); - void SetDeviceUnavailable(SoundDevice::ID id) { m_DeviceUnavailable[id] = true; } - bool IsDeviceUnavailable(SoundDevice::ID id) { return m_DeviceUnavailable[id]; } + void SetDeviceUnavailable(SoundDevice::Identifier identifier) { m_DeviceUnavailable[identifier] = true; } + bool IsDeviceUnavailable(SoundDevice::Identifier identifier) { return m_DeviceUnavailable[identifier]; } - SoundDevice::Caps GetDeviceCaps(SoundDevice::ID id, SoundDevice::IBase *currentSoundDevice = nullptr); - SoundDevice::DynamicCaps GetDeviceDynamicCaps(SoundDevice::ID id, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr, bool update = false); + SoundDevice::Caps GetDeviceCaps(SoundDevice::Identifier identifier, SoundDevice::IBase *currentSoundDevice = nullptr); + SoundDevice::DynamicCaps GetDeviceDynamicCaps(SoundDevice::Identifier identifier, const std::vector<uint32> &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr, bool update = false); - SoundDevice::IBase * CreateSoundDevice(SoundDevice::ID id); + SoundDevice::IBase * CreateSoundDevice(SoundDevice::Identifier identifier); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -180,9 +180,9 @@ } -CASIODevice::CASIODevice(SoundDevice::ID id, const std::wstring &internalID) -//------------------------------------------------------------------------ - : SoundDevice::Base(id, internalID) +CASIODevice::CASIODevice(SoundDevice::Info info) +//---------------------------------------------- + : SoundDevice::Base(info) { InitMembers(); m_QueriedFeatures.reset(); Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -91,7 +91,7 @@ void SetRenderSilence(bool silence, bool wait=false); public: - CASIODevice(SoundDevice::ID id, const std::wstring &internalID); + CASIODevice(SoundDevice::Info info); ~CASIODevice(); private: Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -73,9 +73,9 @@ } -CDSoundDevice::CDSoundDevice(SoundDevice::ID id, const std::wstring &internalID) -//---------------------------------------------------------------------------- - : CSoundDeviceWithThread(id, internalID) +CDSoundDevice::CDSoundDevice(SoundDevice::Info info) +//-------------------------------------------------- + : CSoundDeviceWithThread(info) , m_piDS(NULL) , m_pPrimary(NULL) , m_pMixBuffer(NULL) Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -43,7 +43,7 @@ DWORD m_dwLatency; public: - CDSoundDevice(SoundDevice::ID id, const std::wstring &internalID); + CDSoundDevice(SoundDevice::Info info); ~CDSoundDevice(); public: Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -37,11 +37,11 @@ #include "../include/portaudio/src/common/pa_debugprint.h" -CPortaudioDevice::CPortaudioDevice(SoundDevice::ID id, const std::wstring &internalID) -//---------------------------------------------------------------------------------- - : SoundDevice::Base(id, internalID) +CPortaudioDevice::CPortaudioDevice(SoundDevice::Info info) +//-------------------------------------------------------- + : SoundDevice::Base(info) { - m_HostApi = SndDevTypeToHostApi(id.GetType()); + m_HostApi = SndDevTypeToHostApi(info.id.GetType()); MemsetZero(m_StreamParameters); m_Stream = 0; m_StreamInfo = 0; Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -44,7 +44,7 @@ double m_CurrentRealLatency; // seconds public: - CPortaudioDevice(SoundDevice::ID id, const std::wstring &internalID); + CPortaudioDevice(SoundDevice::Info info); ~CPortaudioDevice(); public: Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -82,7 +82,7 @@ void SetWakeupEvent(HANDLE ev); void SetWakeupInterval(double seconds); public: - CSoundDeviceWithThread(SoundDevice::ID id, const std::wstring &internalID) : SoundDevice::Base(id, internalID), m_AudioThread(*this) {} + CSoundDeviceWithThread(SoundDevice::Info info) : SoundDevice::Base(info), m_AudioThread(*this) {} virtual ~CSoundDeviceWithThread() {} bool InternalStart(); void InternalStop(); Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2014-09-29 09:01:08 UTC (rev 4323) @@ -42,9 +42,9 @@ static const std::size_t WAVEOUT_MAXBUFFERSIZE = 65536; -CWaveDevice::CWaveDevice(SoundDevice::ID id, const std::wstring &internalID) -//------------------------------------------------------------------------ - : CSoundDeviceWithThread(id, internalID) +CWaveDevice::CWaveDevice(SoundDevice::Info info) +//---------------------------------------------- + : CSoundDeviceWithThread(info) { m_ThreadWakeupEvent; m_hWaveOut = NULL; Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2014-09-29 08:25:21 UTC (rev 4322) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2014-09-29 09:01:08 UTC (rev 4323) @@ -44,7 +44,7 @@ std::vector<std::vector<char> > m_WaveBuffersData; public: - CWaveDevice(SoundDevice::ID id, const std::wstring &internalID); + CWaveDevice(SoundDevice::Info info); ~CWaveDevice(); public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |