Permalink
Browse files

Merge pull request #234 from Montellese/volume

Decoupling of mute status and volume level
  • Loading branch information...
2 parents 2d0e9c3 + a6220d2 commit b89e0c826f1eff6332a6f015a8520ca5b1f16e70 @Montellese Montellese committed Jun 29, 2011
Showing with 48 additions and 61 deletions.
  1. +40 −56 xbmc/Application.cpp
  2. +5 −2 xbmc/Application.h
  3. +1 −1 xbmc/interfaces/Builtins.cpp
  4. +1 −1 xbmc/interfaces/http-api/XBMChttp.cpp
  5. +1 −1 xbmc/network/UPnP.cpp
View
@@ -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,42 +2530,28 @@ 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);
if (action.GetRepeat())
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);
@@ -4894,35 +4880,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)
@@ -4931,9 +4922,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)
{
@@ -4946,12 +4936,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
@@ -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);
@@ -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"))
{
@@ -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
@@ -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;
}

0 comments on commit b89e0c8

Please sign in to comment.