aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/qmmp/volume.h10
-rw-r--r--src/qmmp/volumehandler.cpp23
-rw-r--r--src/qmmp/volumehandler.h2
3 files changed, 21 insertions, 14 deletions
diff --git a/src/qmmp/volume.h b/src/qmmp/volume.h
index 69d2c02bf..fd82cca87 100644
--- a/src/qmmp/volume.h
+++ b/src/qmmp/volume.h
@@ -32,8 +32,18 @@ struct VolumeSettings
{
int left = 0; /*!< Volume of the left channel. It should be \b 0..100. */
int right = 0; /*!< Volume of the left channel It should be \b 0..100. */
+
};
+inline bool operator==(const VolumeSettings &v1, const VolumeSettings &v2)
+{
+ return v1.left == v2.left && v1.right == v2.right;
+}
+
+inline bool operator!=(const VolumeSettings &v1, const VolumeSettings &v2)
+{
+ return v1.left != v2.left || v1.right != v2.right;
+}
/*! @brief The Volume class provides asbtract volume interface
* @author Ilya Kotov <forkotov02@ya.ru>
diff --git a/src/qmmp/volumehandler.cpp b/src/qmmp/volumehandler.cpp
index 8bed61ce4..49abeb064 100644
--- a/src/qmmp/volumehandler.cpp
+++ b/src/qmmp/volumehandler.cpp
@@ -78,23 +78,23 @@ void VolumeHandler::setMuted(bool muted)
int VolumeHandler::left() const
{
- return m_left;
+ return m_settings.left;
}
int VolumeHandler::right() const
{
- return m_right;
+ return m_settings.right;
}
int VolumeHandler::volume() const
{
- return qMax(m_right, m_left);
+ return qMax(m_settings.right, m_settings.left);
}
int VolumeHandler::balance() const
{
int v = volume();
- return v > 0 ? (m_right - m_left)*100/v : 0;
+ return v > 0 ? (m_settings.right - m_settings.left) * 100 / v : 0;
}
bool VolumeHandler::isMuted() const
@@ -105,29 +105,26 @@ bool VolumeHandler::isMuted() const
void VolumeHandler::checkVolume()
{
VolumeSettings v = m_volume->volume();
- int l = v.left;
- int r = v.right;
bool muted = m_volume->isMuted();
- l = qBound(0, l, 100);
- r = qBound(0, r, 100);
+ v.left = qBound(0, v.left, 100);
+ v.right = qBound(0, v.right, 100);
if(m_muted != muted || (m_prev_block && !signalsBlocked ()))
{
m_muted = muted;
emit mutedChanged(m_muted);
}
- if (m_left != l || m_right != r) //volume has been changed
+ if (m_settings != v) //volume has been changed
{
- m_left = l;
- m_right = r;
- emit volumeChanged(m_left, m_right);
+ m_settings = v;
+ emit volumeChanged(v.left, v.right);
emit volumeChanged(volume());
emit balanceChanged(balance());
}
else if(m_prev_block && !signalsBlocked ()) //signals have been unblocked
{
- emit volumeChanged(m_left, m_right);
+ emit volumeChanged(v.left, v.right);
emit volumeChanged(volume());
emit balanceChanged(balance());
}
diff --git a/src/qmmp/volumehandler.h b/src/qmmp/volumehandler.h
index 73def472a..0bf3bd99e 100644
--- a/src/qmmp/volumehandler.h
+++ b/src/qmmp/volumehandler.h
@@ -116,7 +116,7 @@ public slots:
void reload();
private:
- int m_left = 0, m_right = 0;
+ VolumeSettings m_settings;
bool m_prev_block = false;
bool m_muted = false;
Volume *m_volume = nullptr;