From: <man...@us...> - 2014-03-18 18:53:47
|
Revision: 3901 http://sourceforge.net/p/modplug/code/3901 Author: manxorist Date: 2014-03-18 18:53:38 +0000 (Tue, 18 Mar 2014) Log Message: ----------- [Ref] sounddev: Split SoundDeviceCaps structure into the static part (which does not depend on a particular device but only on the device type) and the dynamic part. [Ref] sounddev: Kill duplicated information via ISoundDevice::CanStopMode(), this can now be implemented using ISoundDevice::GetDeviceCaps().CanKeepDeviceRunning . Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.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 Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -252,7 +252,7 @@ // If no mixing rate is specified and we're using ASIO, get a mixing rate supported by the device. if(TrackerSettings::Instance().GetSoundDeviceID().GetType() == SNDDEV_ASIO) { - TrackerSettings::Instance().MixerSamplerate = theApp.GetSoundDevicesManager()->GetDeviceCaps(TrackerSettings::Instance().GetSoundDeviceID(), TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).currentSampleRate; + TrackerSettings::Instance().MixerSamplerate = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(TrackerSettings::Instance().GetSoundDeviceID(), TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).currentSampleRate; } #endif // NO_ASIO } @@ -1215,7 +1215,7 @@ m_NotifyTimer = 0; } ResetNotificationBuffer(); - if(!gpSoundDevice->CanStopMode() || TrackerSettings::Instance().m_SoundSettingsStopMode == SoundDeviceStopModeClosed) + if(!gpSoundDevice->GetDeviceCaps().CanKeepDeviceRunning || TrackerSettings::Instance().m_SoundSettingsStopMode == SoundDeviceStopModeClosed) { audioCloseDevice(); } Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -123,7 +123,8 @@ //----------------------------------------------------- : CPropertyPage(IDD_OPTIONS_SOUNDCARD) , m_CurrentDeviceInfo(theApp.GetSoundDevicesManager()->FindDeviceInfo(dev)) - , m_CurrentDeviceCaps(theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true)) + , m_CurrentDeviceCaps(theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, CMainFrame::GetMainFrame()->gpSoundDevice)) + , m_CurrentDeviceDynamicCaps(theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true)) , m_Settings(TrackerSettings::Instance().GetSoundDeviceSettings(dev)) { return; @@ -135,7 +136,8 @@ { bool deviceChanged = (dev != m_CurrentDeviceInfo.id); m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev); - m_CurrentDeviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true); + 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(deviceChanged || forceReload) { m_Settings = TrackerSettings::Instance().GetSoundDeviceSettings(dev); @@ -349,9 +351,9 @@ { m_CbnChannels.ResetContent(); UINT maxChannels = 0; - if(m_CurrentDeviceCaps.channelNames.size() > 0) + if(m_CurrentDeviceDynamicCaps.channelNames.size() > 0) { - maxChannels = std::min<std::size_t>(4, m_CurrentDeviceCaps.channelNames.size()); + maxChannels = std::min<std::size_t>(4, m_CurrentDeviceDynamicCaps.channelNames.size()); } else { maxChannels = 4; @@ -458,9 +460,9 @@ combo->SetCurSel(0); if(mch < usedChannels) { - for(size_t dch = 0; dch < m_CurrentDeviceCaps.channelNames.size(); dch++) // Device channels + for(size_t dch = 0; dch < m_CurrentDeviceDynamicCaps.channelNames.size(); dch++) // Device channels { - const int pos = (int)::SendMessageW(combo->m_hWnd, CB_ADDSTRING, 0, (LPARAM)m_CurrentDeviceCaps.channelNames[dch].c_str()); + const int pos = (int)::SendMessageW(combo->m_hWnd, CB_ADDSTRING, 0, (LPARAM)m_CurrentDeviceDynamicCaps.channelNames[dch].c_str()); combo->SetItemData(pos, (DWORD_PTR)dch); if(dch == m_Settings.ChannelMapping.ToDevice(mch)) { @@ -521,7 +523,7 @@ // find an unused channel bool found = false; std::size_t deviceChannel = 0; - for(; deviceChannel < m_CurrentDeviceCaps.channelNames.size(); ++deviceChannel) + for(; deviceChannel < m_CurrentDeviceDynamicCaps.channelNames.size(); ++deviceChannel) { bool used = false; for(int hostChannel = 0; hostChannel < NUM_CHANNELCOMBOBOXES; ++hostChannel) @@ -559,7 +561,7 @@ { m_CbnMixingFreq.ResetContent(); - std::vector<uint32> samplerates = m_CurrentDeviceCaps.supportedSampleRates; + std::vector<uint32> samplerates = m_CurrentDeviceDynamicCaps.supportedSampleRates; if(samplerates.empty()) { Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2014-03-18 18:53:38 UTC (rev 3901) @@ -33,6 +33,7 @@ void SetDevice(SoundDeviceID dev, bool forceReload=false); SoundDeviceInfo m_CurrentDeviceInfo; SoundDeviceCaps m_CurrentDeviceCaps; + SoundDeviceDynamicCaps m_CurrentDeviceDynamicCaps; SoundDeviceSettings m_Settings; public: Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -147,10 +147,18 @@ } -SoundDeviceCaps ISoundDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) -//------------------------------------------------------------------------------------- +SoundDeviceCaps ISoundDevice::GetDeviceCaps() +//------------------------------------------- { SoundDeviceCaps result; + return result; +} + + +SoundDeviceDynamicCaps ISoundDevice::GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) +//--------------------------------------------------------------------------------------------------- +{ + SoundDeviceDynamicCaps result; result.supportedSampleRates = baseSampleRates; return result; } @@ -585,21 +593,20 @@ } -SoundDeviceCaps SoundDevicesManager::GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice, bool update) -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +SoundDeviceCaps SoundDevicesManager::GetDeviceCaps(SoundDeviceID id, ISoundDevice *currentSoundDevice) +//---------------------------------------------------------------------------------------------------- { - if((m_DeviceCaps.find(id) == m_DeviceCaps.end()) || update) + if(m_DeviceCaps.find(id) == m_DeviceCaps.end()) { if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) { - m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(baseSampleRates); + m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(); } else { ISoundDevice *dummy = CreateSoundDevice(id); if(dummy) { - dummy->SetMessageReceiver(messageReceiver); - m_DeviceCaps[id] = dummy->GetDeviceCaps(baseSampleRates); + m_DeviceCaps[id] = dummy->GetDeviceCaps(); } delete dummy; } @@ -608,6 +615,29 @@ } +SoundDeviceDynamicCaps SoundDevicesManager::GetDeviceDynamicCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice, bool update) +//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +{ + if((m_DeviceDynamicCaps.find(id) == m_DeviceDynamicCaps.end()) || update) + { + if(currentSoundDevice && FindDeviceInfo(id).IsValid() && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id).internalID)) + { + m_DeviceDynamicCaps[id] = currentSoundDevice->GetDeviceDynamicCaps(baseSampleRates); + } else + { + ISoundDevice *dummy = CreateSoundDevice(id); + if(dummy) + { + dummy->SetMessageReceiver(messageReceiver); + m_DeviceDynamicCaps[id] = dummy->GetDeviceDynamicCaps(baseSampleRates); + } + delete dummy; + } + } + return m_DeviceDynamicCaps[id]; +} + + ISoundDevice * SoundDevicesManager::CreateSoundDevice(SoundDeviceID id) //--------------------------------------------------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2014-03-18 18:53:38 UTC (rev 3901) @@ -322,9 +322,6 @@ struct SoundDeviceCaps { - uint32 currentSampleRate; - std::vector<uint32> supportedSampleRates; // Which samplerates are actually supported by the device. Currently only implemented properly for ASIO, DirectSound and PortAudio. - std::vector<std::wstring> channelNames; bool CanUpdateInterval; bool CanSampleFormat; bool CanExclusiveMode; @@ -336,8 +333,7 @@ bool HasInternalDither; std::wstring ExclusiveModeDescription; SoundDeviceCaps() - : currentSampleRate(0) - , CanUpdateInterval(true) + : CanUpdateInterval(true) , CanSampleFormat(true) , CanExclusiveMode(false) , CanBoostThreadPriority(true) @@ -353,6 +349,19 @@ }; +struct SoundDeviceDynamicCaps +{ + uint32 currentSampleRate; + std::vector<uint32> supportedSampleRates; // Which samplerates are actually supported by the device. Currently only implemented properly for ASIO, DirectSound and PortAudio. + std::vector<std::wstring> channelNames; + SoundDeviceDynamicCaps() + : currentSampleRate(0) + { + return; + } +}; + + class SoundDevicesManager; @@ -465,8 +474,8 @@ SoundDeviceIndex GetDeviceIndex() const { return m_ID.GetIndex(); } std::wstring GetDeviceInternalID() const { return m_InternalID; } - virtual SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); - virtual bool CanStopMode() const { return false; } + virtual SoundDeviceCaps GetDeviceCaps(); + virtual SoundDeviceDynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates); bool Open(const SoundDeviceSettings &settings); bool Close(); @@ -555,6 +564,7 @@ private: std::vector<SoundDeviceInfo> m_SoundDevices; std::map<SoundDeviceID, SoundDeviceCaps> m_DeviceCaps; + std::map<SoundDeviceID, SoundDeviceDynamicCaps> m_DeviceDynamicCaps; public: SoundDevicesManager(); @@ -574,7 +584,8 @@ bool OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); - SoundDeviceCaps GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr, bool update = false); + SoundDeviceCaps GetDeviceCaps(SoundDeviceID id, ISoundDevice *currentSoundDevice = nullptr); + SoundDeviceDynamicCaps GetDeviceDynamicCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr, bool update = false); ISoundDevice * CreateSoundDevice(SoundDeviceID id); Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -1311,8 +1311,8 @@ } -SoundDeviceCaps CASIODevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) -//------------------------------------------------------------------------------------ +SoundDeviceCaps CASIODevice::GetDeviceCaps() +//------------------------------------------ { SoundDeviceCaps caps; @@ -1325,6 +1325,15 @@ caps.CanChannelMapping = true; caps.CanDriverPanel = true; + return caps; +} + + +SoundDeviceDynamicCaps CASIODevice::GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) +//-------------------------------------------------------------------------------------------------- +{ + SoundDeviceDynamicCaps caps; + TemporaryASIODriverOpener opener(*this); if(!IsDriverOpen()) { Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2014-03-18 18:53:38 UTC (rev 3901) @@ -108,8 +108,8 @@ bool OnIdle() { return HandleRequests(); } - SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); - bool CanStopMode() const { return true; } + SoundDeviceCaps GetDeviceCaps(); + SoundDeviceDynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates); bool OpenDriverSettings(); Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -110,8 +110,8 @@ } -SoundDeviceCaps CDSoundDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) -//-------------------------------------------------------------------------------------- +SoundDeviceCaps CDSoundDevice::GetDeviceCaps() +//-------------------------------------------- { SoundDeviceCaps caps; caps.CanUpdateInterval = true; @@ -122,6 +122,14 @@ caps.CanChannelMapping = false; caps.CanDriverPanel = false; caps.ExclusiveModeDescription = L"Use primary buffer"; + return caps; +} + + +SoundDeviceDynamicCaps CDSoundDevice::GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) +//---------------------------------------------------------------------------------------------------- +{ + SoundDeviceDynamicCaps caps; IDirectSound *dummy = nullptr; IDirectSound *ds = nullptr; if(m_piDS) Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2014-03-18 18:53:38 UTC (rev 3901) @@ -48,7 +48,8 @@ void StopFromSoundThread(); bool InternalIsOpen() const { return (m_pMixBuffer != NULL); } double GetCurrentLatency() const { return 1.0 * m_dwLatency / m_Settings.GetBytesPerSecond(); } - SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); + SoundDeviceCaps GetDeviceCaps(); + SoundDeviceDynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates); protected: DWORD LockBuffer(DWORD dwBytes, LPVOID *lpBuf1, LPDWORD lpSize1, LPVOID *lpBuf2, LPDWORD lpSize2); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-03-18 18:53:38 UTC (rev 3901) @@ -194,8 +194,8 @@ } -SoundDeviceCaps CPortaudioDevice::GetDeviceCaps(const std::vector<uint32> &baseSampleRates) -//----------------------------------------------------------------------------------------- +SoundDeviceCaps CPortaudioDevice::GetDeviceCaps() +//----------------------------------------------- { SoundDeviceCaps caps; caps.CanUpdateInterval = true; @@ -214,6 +214,14 @@ { caps.CanUpdateInterval = false; } + return caps; +} + + +SoundDeviceDynamicCaps CPortaudioDevice::GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) +//------------------------------------------------------------------------------------------------------- +{ + SoundDeviceDynamicCaps caps; PaDeviceIndex device = HostApiOutputIndexToGlobalDeviceIndex(GetDeviceIndex(), m_HostApi); if(device == -1) { Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2014-03-18 10:17:40 UTC (rev 3900) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2014-03-18 18:53:38 UTC (rev 3901) @@ -53,7 +53,8 @@ double GetCurrentLatency() const; bool InternalHasGetStreamPosition() const { return false; } int64 InternalGetStreamPositionFrames() const; - SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); + SoundDeviceCaps GetDeviceCaps(); + SoundDeviceDynamicCaps GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates); bool OpenDriverSettings(); int StreamCallback( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |