diff options
author | montellese <montellese@xbmc.org> | 2011-06-23 18:18:39 +0200 |
---|---|---|
committer | montellese <montellese@xbmc.org> | 2011-06-29 09:05:15 +0200 |
commit | a6220d22d9c4f5d11efe6aba74936a5713172bdd (patch) | |
tree | 261c261c8305e34ad7f176a1a9f2b4de5327a3be | |
parent | a401db7b84f06027532e6c67a0bef2b251bb590b (diff) |
change volume control behaviour
Mute status and volume level are now independant. If audio is muted at 0% volume and then unmuted, volume will be set back to 0% (and not 100% as it was until now).
Furthermore when "Volume Up" or "Volume Down" is executed during muted audio, it will me unmuted and the action will be applied to the restored volume level.
-rw-r--r-- | xbmc/Application.cpp | 96 | ||||
-rw-r--r-- | xbmc/Application.h | 7 | ||||
-rw-r--r-- | xbmc/interfaces/Builtins.cpp | 2 | ||||
-rw-r--r-- | xbmc/interfaces/http-api/XBMChttp.cpp | 2 | ||||
-rw-r--r-- | xbmc/network/UPnP.cpp | 2 |
5 files changed, 48 insertions, 61 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 485dde998b..2b8be407c3 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -1165,7 +1165,7 @@ bool CApplication::Initialize() CUtil::RemoveTempFiles(); // Show mute symbol - if (g_settings.m_nVolumeLevel == VOLUME_MINIMUM) + if (g_settings.m_bMute) Mute(); // if the user shutoff the xbox during music scan @@ -2502,7 +2502,7 @@ bool CApplication::OnAction(const CAction &action) } if (action.GetID() == ACTION_MUTE) { - Mute(); + ToggleMute(); return true; } @@ -2530,7 +2530,14 @@ bool CApplication::OnAction(const CAction &action) if (!m_pPlayer || !m_pPlayer->IsPassthrough()) { // increase or decrease the volume - int volume = g_settings.m_nVolumeLevel + g_settings.m_dynamicRangeCompressionLevel; + int volume; + if (g_settings.m_bMute) + { + volume = (int)((float)g_settings.m_iPreMuteVolumeLevel * 0.01f * (VOLUME_MAXIMUM - VOLUME_MINIMUM) + VOLUME_MINIMUM); + UnMute(); + } + else + volume = g_settings.m_nVolumeLevel + g_settings.m_dynamicRangeCompressionLevel; // calculate speed so that a full press will equal 1 second from min to max float speed = float(VOLUME_MAXIMUM - VOLUME_MINIMUM); @@ -2538,34 +2545,13 @@ bool CApplication::OnAction(const CAction &action) speed *= action.GetRepeat(); else speed /= 50; //50 fps - if (g_settings.m_bMute) - { - // only unmute if volume is to be increased, otherwise leave muted - if (action.GetID() == ACTION_VOLUME_DOWN) - return true; - - if (g_settings.m_iPreMuteVolumeLevel == 0) - SetVolume(1); - else - // In muted, unmute - Mute(); - return true; - } + if (action.GetID() == ACTION_VOLUME_UP) - { volume += (int)((float)fabs(action.GetAmount()) * action.GetAmount() * speed); - } else - { volume -= (int)((float)fabs(action.GetAmount()) * action.GetAmount() * speed); - } - SetHardwareVolume(volume); - #ifndef HAS_SDL_AUDIO - g_audioManager.SetVolume(g_settings.m_nVolumeLevel); - #else - g_audioManager.SetVolume((int)(128.f * (g_settings.m_nVolumeLevel - VOLUME_MINIMUM) / (float)(VOLUME_MAXIMUM - VOLUME_MINIMUM))); - #endif + SetVolume(volume, false); } // show visual feedback of volume change... ShowVolumeBar(&action); @@ -4895,35 +4881,40 @@ void CApplication::ShowVolumeBar(const CAction *action) } } -void CApplication::Mute(void) +void CApplication::ToggleMute(void) { if (g_settings.m_bMute) - { // muted - unmute. - // In case our premutevolume is 0, return to 100% volume - if( g_settings.m_iPreMuteVolumeLevel == 0 ) - { - SetVolume(100); - } - else - { - SetVolume(g_settings.m_iPreMuteVolumeLevel); - g_settings.m_iPreMuteVolumeLevel = 0; - } - ShowVolumeBar(); - } + UnMute(); else - { // mute - g_settings.m_iPreMuteVolumeLevel = GetVolume(); - SetVolume(0); - } + Mute(); } -void CApplication::SetVolume(int iPercent) +void CApplication::Mute() +{ + g_settings.m_iPreMuteVolumeLevel = GetVolume(); + SetVolume(0); + g_settings.m_bMute = true; +} + +void CApplication::UnMute() +{ + SetVolume(g_settings.m_iPreMuteVolumeLevel); + g_settings.m_iPreMuteVolumeLevel = 0; + g_settings.m_bMute = false; +} + +void CApplication::SetVolume(long iValue, bool isPercentage /* = true */) { // convert the percentage to a mB (milliBell) value (*100 for dB) - long hardwareVolume = (long)((float)iPercent * 0.01f * (VOLUME_MAXIMUM - VOLUME_MINIMUM) + VOLUME_MINIMUM); - SetHardwareVolume(hardwareVolume); - g_audioManager.SetVolume(iPercent); + if (isPercentage) + iValue = (long)((float)iValue * 0.01f * (VOLUME_MAXIMUM - VOLUME_MINIMUM) + VOLUME_MINIMUM); + + SetHardwareVolume(iValue); +#ifndef HAS_SDL_AUDIO + g_audioManager.SetVolume(g_settings.m_nVolumeLevel); +#else + g_audioManager.SetVolume((int)(128.f * (g_settings.m_nVolumeLevel - VOLUME_MINIMUM) / (float)(VOLUME_MAXIMUM - VOLUME_MINIMUM))); +#endif } void CApplication::SetHardwareVolume(long hardwareVolume) @@ -4932,9 +4923,8 @@ void CApplication::SetHardwareVolume(long hardwareVolume) if (hardwareVolume >= VOLUME_MAXIMUM) // + VOLUME_DRC_MAXIMUM hardwareVolume = VOLUME_MAXIMUM;// + VOLUME_DRC_MAXIMUM; if (hardwareVolume <= VOLUME_MINIMUM) - { hardwareVolume = VOLUME_MINIMUM; - } + // update our settings if (hardwareVolume > VOLUME_MAXIMUM) { @@ -4947,12 +4937,6 @@ void CApplication::SetHardwareVolume(long hardwareVolume) g_settings.m_nVolumeLevel = hardwareVolume; } - // update mute state - if(!g_settings.m_bMute && hardwareVolume <= VOLUME_MINIMUM) - g_settings.m_bMute = true; - else if(g_settings.m_bMute && hardwareVolume > VOLUME_MINIMUM) - g_settings.m_bMute = false; - // and tell our player to update the volume if (m_pPlayer) { diff --git a/xbmc/Application.h b/xbmc/Application.h index b16124f085..28e26f5f2d 100644 --- a/xbmc/Application.h +++ b/xbmc/Application.h @@ -160,8 +160,8 @@ public: void ProcessSlow(); void ResetScreenSaver(); int GetVolume() const; - void SetVolume(int iPercent); - void Mute(void); + void SetVolume(long iValue, bool isPercentage = true); + void ToggleMute(void); void ShowVolumeBar(const CAction *action = NULL); int GetPlaySpeed() const; int GetSubtitleDelay() const; @@ -345,6 +345,9 @@ protected: XbmcThreads::ConditionVariable m_frameCond; #endif + void Mute(); + void UnMute(); + void SetHardwareVolume(long hardwareVolume); void UpdateLCD(); void FatalErrorHandler(bool WindowSystemInitialized, bool MapDrives, bool InitNetwork); diff --git a/xbmc/interfaces/Builtins.cpp b/xbmc/interfaces/Builtins.cpp index 08290323a5..f4fc51f548 100644 --- a/xbmc/interfaces/Builtins.cpp +++ b/xbmc/interfaces/Builtins.cpp @@ -789,7 +789,7 @@ int CBuiltins::Execute(const CStdString& execString) } else if (execute.Equals("mute")) { - g_application.Mute(); + g_application.ToggleMute(); } else if (execute.Equals("setvolume")) { diff --git a/xbmc/interfaces/http-api/XBMChttp.cpp b/xbmc/interfaces/http-api/XBMChttp.cpp index 998c6a2532..99a68d22e4 100644 --- a/xbmc/interfaces/http-api/XBMChttp.cpp +++ b/xbmc/interfaces/http-api/XBMChttp.cpp @@ -1586,7 +1586,7 @@ int CXbmcHttp::xbmcSeekPercentage(int numParas, CStdString paras[], bool relativ int CXbmcHttp::xbmcMute() { - g_application.Mute(); + g_application.ToggleMute(); return SetResponse(openTag+"OK"); } diff --git a/xbmc/network/UPnP.cpp b/xbmc/network/UPnP.cpp index 9645323c0f..bd99396cd4 100644 --- a/xbmc/network/UPnP.cpp +++ b/xbmc/network/UPnP.cpp @@ -1992,7 +1992,7 @@ CUPnPRenderer::OnSetMute(PLT_ActionReference& action) NPT_String mute; NPT_CHECK_SEVERE(action->GetArgumentValue("DesiredMute",mute)); if((mute == "1") ^ g_settings.m_bMute) - g_application.Mute(); + g_application.ToggleMute(); return NPT_SUCCESS; } |