Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit a6220d22d9c4f5d11efe6aba74936a5713172bdd 1 parent a401db7
@Montellese Montellese authored
View
96 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)
{
View
7 xbmc/Application.h
@@ -160,8 +160,8 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
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 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
XbmcThreads::ConditionVariable m_frameCond;
#endif
+ void Mute();
+ void UnMute();
+
void SetHardwareVolume(long hardwareVolume);
void UpdateLCD();
void FatalErrorHandler(bool WindowSystemInitialized, bool MapDrives, bool InitNetwork);
View
2  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"))
{
View
2  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");
}
View
2  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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.