diff options
| -rw-r--r-- | src/qmmp/soundcore.cpp | 28 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 36 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.cpp | 51 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol_p.h | 33 |
4 files changed, 130 insertions, 18 deletions
diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 072542755..8bd2601f3 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -57,6 +57,8 @@ SoundCore::SoundCore(QObject *parent) connect(QmmpSettings::instance(), SIGNAL(eqSettingsChanged()), SIGNAL(eqSettingsChanged())); connect(QmmpSettings::instance(), SIGNAL(audioSettingsChanged()), m_volumeControl, SLOT(reload())); connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); + connect(m_volumeControl, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); + connect(m_volumeControl, SIGNAL(balanceChanged(int)), SIGNAL(balanceChanged(int))); } SoundCore::~SoundCore() @@ -172,16 +174,38 @@ void SoundCore::changeVolume(int delta) m_volumeControl->changeVolume(delta); } -int SoundCore::leftVolume() +void SoundCore::setVolume(int volume) +{ + setMuted(false); + m_volumeControl->setVolume(volume); +} + +void SoundCore::setBalance(int balance) +{ + setMuted(false); + m_volumeControl->setBalance(balance); +} + +int SoundCore::leftVolume() const { return m_volumeControl->left(); } -int SoundCore::rightVolume() +int SoundCore::rightVolume() const { return m_volumeControl->right(); } +int SoundCore::volume() const +{ + return m_volumeControl->volume(); +} + +int SoundCore::balance() const +{ + return m_volumeControl->left(); +} + bool SoundCore::isMuted() const { return m_muted; diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index 8bd41062b..245fd9518 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -67,11 +67,19 @@ public: /*! * Returns left volume level. */ - int leftVolume(); + int leftVolume() const; /*! * Returns left volume level. */ - int rightVolume(); + int rightVolume() const; + /*! + * Returns the highest volume of the left and right channels. + */ + int volume() const; + /*! + * Returns the balance between left and right channels. + */ + int balance() const; /*! * Returns \b true if volume is unmuted, otherwise returns \b false */ @@ -139,6 +147,16 @@ public slots: */ void changeVolume(int delta); /*! + * Sets the volume of the left and right channels with keeping of the balance. + * @param volume volume of the left and right channels \b[0..100]. + */ + void setVolume(int volume); + /*! + * Sets the balance between left and right channels. + * @param balance balance between left and right channels \b [-100..100]. + */ + void setBalance(int balance); + /*! * This function plays file or stream with the given path \p source. * Returns \b true if playback has been started successful or source is not a local file, * otherwise returns \b false. Useful for invalid files skipping. @@ -216,11 +234,21 @@ signals: void volumeChanged(int left, int right); /*! * Emitted when volume has muted or restored - * @param muted - new state of volume (\b true - muted, \b false - unmuted) + * @param muted new state of the volume (\b true - muted, \b false - unmuted) */ void mutedChanged(bool muted); /*! - * Emitted when equalizer settings have changed. + * Emitted when the highest volume of the left and right channels has changed. + * @param volume new value of the highest volume of the left and right channels. + */ + void volumeChanged(int volume); + /*! + * Emitted when the balance between left and right channels has changed. + * @param volume new balance value. + */ + void balanceChanged(int balance); + /*! + * Emitted when equalizer settings has changed. */ void eqSettingsChanged(); /*! diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp index 98c2a3da7..469665038 100644 --- a/src/qmmp/volumecontrol.cpp +++ b/src/qmmp/volumecontrol.cpp @@ -43,11 +43,6 @@ VolumeControl::~VolumeControl() delete m_volume; } -int VolumeControl::left() -{ - return m_left; -} - void VolumeControl::setVolume(int left, int right) { VolumeSettings v; @@ -59,17 +54,47 @@ void VolumeControl::setVolume(int left, int right) void VolumeControl::changeVolume(int delta) { - int volume = qMax(m_left, m_right); - int balance = volume > 0 ? (m_right - m_left)*100/volume : 0; - volume = delta > 0 ? qMin(100, volume + 5) : qMax(0, volume - 5); - setVolume(volume-qMax(balance,0)*volume/100, volume+qMin(balance,0)*volume/100); + int v = qMax(m_left, m_right); + int balance = v > 0 ? (m_right - m_left)*100/v : 0; + v = delta > 0 ? qMin(100, v + 5) : qMax(0, v - 5); + setVolume(v-qMax(balance,0)*v/100, v+qMin(balance,0)*v/100); +} + +void VolumeControl::setVolume(int volume) +{ + volume = qBound(0, volume, 100); + setVolume(volume-qMax(balance(),0)*volume/100, + volume+qMin(balance(),0)*volume/100); +} + +void VolumeControl::setBalance(int balance) +{ + balance = qBound(-100, balance, 100); + setVolume(volume()-qMax(balance,0)*volume()/100, + volume()+qMin(balance,0)*volume()/100); +} + +int VolumeControl::left() const +{ + return m_left; } -int VolumeControl::right() +int VolumeControl::right() const { return m_right; } +int VolumeControl::volume() const +{ + return qMax(m_right, m_left); +} + +int VolumeControl::balance() const +{ + int v = volume(); + return v > 0 ? (m_right - m_left)*100/v : 0; +} + void VolumeControl::checkVolume() { VolumeSettings v = m_volume->volume(); @@ -85,9 +110,15 @@ void VolumeControl::checkVolume() m_left = l; m_right = r; emit volumeChanged(m_left, m_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(volume()); + emit balanceChanged(balance()); + } m_prev_block = signalsBlocked (); } diff --git a/src/qmmp/volumecontrol_p.h b/src/qmmp/volumecontrol_p.h index 0c33f70d8..12b8c8493 100644 --- a/src/qmmp/volumecontrol_p.h +++ b/src/qmmp/volumecontrol_p.h @@ -57,13 +57,32 @@ public: */ void changeVolume(int delta); /*! + * Sets the volume of the left and right channels with keeping of the balance. + * @param volume volume of the left and right channels \b[0..100]. + */ + void setVolume(int volume); + /*! + * Sets the balance between left and right channels. + * @param balance balance between left and right channels \b [-100..100]. + */ + void setBalance(int balance); + /*! * Returns left channel volume. */ - int left(); + int left() const; /*! * Returns right channel volume. */ - int right(); + int right() const; + /*! + * Returns the maximum volume of the left and right channels. + */ + int volume() const; + /*! + * Returns the balance between left and right channels. + */ + int balance() const; + signals: /*! @@ -72,6 +91,16 @@ signals: * @param right Right channel volume level. It should be \b 0..100 */ void volumeChanged(int left, int right); + /*! + * Emitted when the highest volume of the left and right channels has changed. + * @param volume new value of the highest volume of the left and right channels. + */ + void volumeChanged(int volume); + /*! + * Emitted when the balance between left and right channels has changed. + * @param volume new balance value. + */ + void balanceChanged(int balance); public slots: /*! |
