Ref T730, function to check range for input/output volume

This commit is contained in:
Klaus Basan
2019-09-29 18:43:24 +02:00
committed by Mat Sutcliffe
parent 905c487451
commit 09b38b4e6d
3 changed files with 25 additions and 11 deletions

View File

@@ -135,11 +135,10 @@ namespace BlackCore
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; }
const bool wasMuted = this->isMuted(); const bool wasMuted = this->isMuted();
if (volume > CSettings::OutMax) { volume = CSettings::OutMax; } volume = CSettings::fixOutVolume(volume);
else if (volume < CSettings::OutMax) { volume = CSettings::OutMax; }
const int currentVolume = m_voiceClient.getNormalizedOutputVolume(); const int currentVolume = m_voiceClient.getNormalizedOutputVolume();
bool changedVoiceOutput = (currentVolume != volume); const bool changedVoiceOutput = (currentVolume != volume);
if (changedVoiceOutput) if (changedVoiceOutput)
{ {
m_voiceClient.setOutputVolumeDb(volume); m_voiceClient.setOutputVolumeDb(volume);

View File

@@ -22,6 +22,20 @@ namespace BlackMisc
{ {
namespace Audio namespace Audio
{ {
int CSettings::fixOutVolume(int v)
{
if (v > OutMax) { return OutMax; }
if (v < OutMin) { return OutMin; }
return v;
}
int CSettings::fixInVolume(int v)
{
if (v > InMax) { return InMax; }
if (v < InMin) { return InMin; }
return v;
}
CSettings::CSettings() CSettings::CSettings()
{ {
this->initDefaultValues(); this->initDefaultValues();
@@ -82,16 +96,12 @@ namespace BlackMisc
void CSettings::setOutVolume(int volume) void CSettings::setOutVolume(int volume)
{ {
if (volume > OutMax) { volume = OutMax; } m_outVolume = fixOutVolume(volume);
else if (volume < OutMin) { volume = OutMin; }
m_outVolume = volume;
} }
void CSettings::setInVolume(int volume) void CSettings::setInVolume(int volume)
{ {
if (volume > InMax) { volume = InMax; } m_inVolume = fixInVolume(volume);
else if (volume < InMin) { volume = InMin; }
m_inVolume = volume;
} }
QString CSettings::convertToQString(bool i18n) const QString CSettings::convertToQString(bool i18n) const

View File

@@ -37,6 +37,11 @@ namespace BlackMisc
static constexpr int OutMin = 0; static constexpr int OutMin = 0;
//! @} //! @}
//! Make sure the volume is within the range @{
static int fixOutVolume(int v);
static int fixInVolume(int v);
//! @}
//! Default constructor. //! Default constructor.
CSettings(); CSettings();
@@ -112,8 +117,8 @@ namespace BlackMisc
QString m_notificationSoundDir; QString m_notificationSoundDir;
int m_notification = static_cast<int>(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) int m_notification = static_cast<int>(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..)
int m_notificationVolume = 90; //!< 0-90 int m_notificationVolume = 90; //!< 0-90
int m_outVolume = 100; //!< 0-300, AFV int m_outVolume = 50; //!< 0-100, AFV
int m_inVolume = 0; //!< AFV range int m_inVolume = 50; //!< AFV range
bool m_audioEffects = true; //!< Audio effects en bool m_audioEffects = true; //!< Audio effects en
void initNotificationFlags(); //!< init flags void initNotificationFlags(); //!< init flags