From 7c64096fc4c36912a0aabeba1ea141e23e7e1668 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 10 Mar 2019 16:32:21 +0000 Subject: refactoring git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8752 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmp/output.cpp | 2 +- src/qmmp/outputwriter.cpp | 2 +- src/qmmp/qmmp.pro | 10 +- src/qmmp/softwarevolume.cpp | 75 +++++++++++++++ src/qmmp/softwarevolume_p.h | 46 +++++++++ src/qmmp/soundcore.cpp | 4 +- src/qmmp/soundcore.h | 4 +- src/qmmp/volumecontrol.cpp | 227 -------------------------------------------- src/qmmp/volumecontrol_p.h | 145 ---------------------------- src/qmmp/volumehandler.cpp | 177 ++++++++++++++++++++++++++++++++++ src/qmmp/volumehandler.h | 127 +++++++++++++++++++++++++ 11 files changed, 437 insertions(+), 382 deletions(-) create mode 100644 src/qmmp/softwarevolume.cpp create mode 100644 src/qmmp/softwarevolume_p.h delete mode 100644 src/qmmp/volumecontrol.cpp delete mode 100644 src/qmmp/volumecontrol_p.h create mode 100644 src/qmmp/volumehandler.cpp create mode 100644 src/qmmp/volumehandler.h (limited to 'src') diff --git a/src/qmmp/output.cpp b/src/qmmp/output.cpp index ff5bd0495..e81f68a1e 100644 --- a/src/qmmp/output.cpp +++ b/src/qmmp/output.cpp @@ -9,7 +9,7 @@ #include "audioparameters.h" #include "qmmpsettings.h" #include "buffer.h" -#include "volumecontrol_p.h" +#include "volumehandler.h" #include "qmmp.h" #include "qmmpplugincache_p.h" #include "output.h" diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp index 47806cd95..28d91a325 100644 --- a/src/qmmp/outputwriter.cpp +++ b/src/qmmp/outputwriter.cpp @@ -25,7 +25,7 @@ #include "output.h" #include "audioconverter.h" #include "channelconverter_p.h" -#include "volumecontrol_p.h" +#include "volumehandler.h" #include "outputwriter_p.h" extern "C" { diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index 1a3c55f15..466e0a6ce 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -31,7 +31,6 @@ HEADERS += \ eqsettings.h \ qmmpevents_p.h \ volume.h \ - volumecontrol_p.h \ outputwriter_p.h \ recycler_p.h \ qmmpplugincache_p.h \ @@ -41,7 +40,9 @@ HEADERS += \ dithering_p.h \ visualbuffer_p.h \ qmmp_export.h \ - trackinfo.h + trackinfo.h \ + volumehandler.h \ + softwarevolume_p.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -53,7 +54,6 @@ SOURCES += recycler.cpp \ effect.cpp \ statehandler.cpp \ qmmp.cpp \ - volumecontrol.cpp \ metadatamodel.cpp \ tagmodel.cpp \ abstractengine.cpp \ @@ -75,7 +75,9 @@ SOURCES += recycler.cpp \ volume.cpp \ dithering.cpp \ visualbuffer.cpp \ - trackinfo.cpp + trackinfo.cpp \ + volumehandler.cpp \ + softwarevolume.cpp unix:TARGET = ../../lib/qmmp$$APP_NAME_SUFFIX win32:TARGET = ../../../bin/qmmp diff --git a/src/qmmp/softwarevolume.cpp b/src/qmmp/softwarevolume.cpp new file mode 100644 index 000000000..ed4343fb4 --- /dev/null +++ b/src/qmmp/softwarevolume.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (C) 2008-2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include "buffer.h" +#include "qmmp.h" +#include "softwarevolume_p.h" + +SoftwareVolume::SoftwareVolume() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_left = settings.value("Volume/left", 80).toInt(); + m_right = settings.value("Volume/right", 80).toInt(); + m_scaleLeft = (double)m_left/100.0; + m_scaleRight = (double)m_right/100.0; +} + +SoftwareVolume::~SoftwareVolume() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.setValue("Volume/left", m_left); + settings.setValue("Volume/right", m_right); +} + +void SoftwareVolume::setVolume(const VolumeSettings &v) +{ + m_left = v.left; + m_right = v.right; + m_scaleLeft = (double)m_left/100.0; + m_scaleRight = (double)m_right/100.0; +} + +VolumeSettings SoftwareVolume::volume() const +{ + VolumeSettings v; + v.left = m_left; + v.right = m_right; + return v; +} + +void SoftwareVolume::changeVolume(Buffer *b, int chan) +{ + if(chan == 1) + { + for(size_t i = 0; i < b->samples; ++i) + { + b->data[i] *= qMax(m_scaleLeft, m_scaleRight); + } + } + else + { + for(size_t i = 0; i < b->samples; i+=2) + { + b->data[i] *= m_scaleLeft; + b->data[i+1] *= m_scaleRight; + } + } +} diff --git a/src/qmmp/softwarevolume_p.h b/src/qmmp/softwarevolume_p.h new file mode 100644 index 000000000..e82f4317b --- /dev/null +++ b/src/qmmp/softwarevolume_p.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2008-2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef SOFTWAREVOLUME_P_H +#define SOFTWAREVOLUME_P_H + +#include "volume.h" +#include "buffer.h" + +/*! @internal + * @brief The SoftwareVolume class provides access to the software volume control. + * @author Ilya Kotov + */ +class SoftwareVolume : public Volume +{ +public: + SoftwareVolume(); + ~SoftwareVolume(); + + void setVolume(const VolumeSettings &v) override; + VolumeSettings volume() const override; + void changeVolume(Buffer *b, int chan); + +private: + int m_left, m_right; + double m_scaleLeft, m_scaleRight; +}; + +#endif // SOFTWAREVOLUME_P_H diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 2f21941e7..39d2a5db7 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -29,7 +29,7 @@ #include "effect.h" #include "statehandler.h" #include "inputsource.h" -#include "volumecontrol_p.h" +#include "volumehandler.h" #include "enginefactory.h" #include "metadatamanager.h" #include "qmmpsettings.h" @@ -47,7 +47,7 @@ SoundCore::SoundCore(QObject *parent) m_engine = nullptr; m_nextState = NO_ENGINE; m_handler = new StateHandler(this); - m_volumeControl = new VolumeControl(this); + m_volumeControl = new VolumeHandler(this); connect(m_handler, SIGNAL(elapsedChanged(qint64)), SIGNAL(elapsedChanged(qint64))); connect(m_handler, SIGNAL(bitrateChanged(int)), SIGNAL(bitrateChanged(int))); connect(m_handler, SIGNAL(audioParametersChanged(AudioParameters)), SIGNAL(audioParametersChanged(AudioParameters))); diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index b28c2124f..241f4a15d 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -33,7 +33,7 @@ #include "eqsettings.h" #include "trackinfo.h" -class VolumeControl; +class VolumeHandler; class AbstractEngine; class InputSource; class StateHandler; @@ -270,7 +270,7 @@ private: QString m_path; static SoundCore* m_instance; StateHandler *m_handler; - VolumeControl *m_volumeControl; + VolumeHandler *m_volumeControl; AbstractEngine *m_engine; QQueue m_sources; int m_nextState; diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp deleted file mode 100644 index b172ed23b..000000000 --- a/src/qmmp/volumecontrol.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2016 by Ilya Kotov * - * forkotov02@ya.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "qmmpsettings.h" -#include "output.h" -#include "volumecontrol_p.h" - -VolumeControl::VolumeControl(QObject *parent) : QObject(parent) -{ - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), SLOT(checkVolume())); - reload(); -} - -VolumeControl::~VolumeControl() -{ - if(m_volume) - delete m_volume; -} - -void VolumeControl::setVolume(int left, int right) -{ - VolumeSettings v; - v.left = qBound(0,left,100); - v.right = qBound(0,right,100); - m_volume->setVolume(v); - checkVolume(); -} - -void VolumeControl::changeVolume(int delta) -{ - setVolume(qBound(0, volume() + delta, 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); -} - -void VolumeControl::setMuted(bool muted) -{ - if(m_muted != muted) - { - m_volume->setMuted(muted); - checkVolume(); - } -} - -int VolumeControl::left() const -{ - return m_left; -} - -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; -} - -bool VolumeControl::isMuted() const -{ - return m_muted; -} - -void VolumeControl::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); - 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 - { - 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 (); -} - -void VolumeControl::reload() -{ - m_timer->stop(); - bool restore = false; - if(m_volume) - { - restore = true; - delete m_volume; - m_volume = nullptr; - } - - if(!QmmpSettings::instance()->useSoftVolume() && Output::currentFactory()) - m_volume = Output::currentFactory()->createVolume(); - - if(m_volume) - { - if(restore) - m_volume->setMuted(m_muted); - - if(m_volume->flags() & Volume::HasNotifySignal) - { - checkVolume(); - connect(m_volume, SIGNAL(changed()), SLOT(checkVolume())); - } - else - { - m_timer->start(150); // fallback to polling if change notification is not available. - } - } - else - { - if(restore) - m_volume->setMuted(m_muted); - - m_volume = new SoftwareVolume; - blockSignals(true); - checkVolume(); - blockSignals(false); - QTimer::singleShot(125, this, SLOT(checkVolume())); - } -} - -SoftwareVolume::SoftwareVolume() -{ - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - m_left = settings.value("Volume/left", 80).toInt(); - m_right = settings.value("Volume/right", 80).toInt(); - m_scaleLeft = (double)m_left/100.0; - m_scaleRight = (double)m_right/100.0; -} - -SoftwareVolume::~SoftwareVolume() -{ - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.setValue("Volume/left", m_left); - settings.setValue("Volume/right", m_right); -} - -void SoftwareVolume::setVolume(const VolumeSettings &v) -{ - m_left = v.left; - m_right = v.right; - m_scaleLeft = (double)m_left/100.0; - m_scaleRight = (double)m_right/100.0; -} - -VolumeSettings SoftwareVolume::volume() const -{ - VolumeSettings v; - v.left = m_left; - v.right = m_right; - return v; -} - -void SoftwareVolume::changeVolume(Buffer *b, int chan) -{ - if(chan == 1) - { - for(size_t i = 0; i < b->samples; ++i) - { - b->data[i] *= qMax(m_scaleLeft, m_scaleRight); - } - } - else - { - for(size_t i = 0; i < b->samples; i+=2) - { - b->data[i] *= m_scaleLeft; - b->data[i+1] *= m_scaleRight; - } - } -} diff --git a/src/qmmp/volumecontrol_p.h b/src/qmmp/volumecontrol_p.h deleted file mode 100644 index 5b652821c..000000000 --- a/src/qmmp/volumecontrol_p.h +++ /dev/null @@ -1,145 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2019 by Ilya Kotov * - * forkotov02@ya.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef VOLUMECONTROL_P_H -#define VOLUMECONTROL_P_H - -#include -#include "qmmp.h" -#include "volume.h" -#include "buffer.h" - -class QTimer; -class SoftwareVolume; - -/*! @internal - * @brief The VolumeControl class provides volume control access - * @author Ilya Kotov - */ -class QMMP_EXPORT VolumeControl : public QObject -{ - Q_OBJECT -public: - /*! - * Object constructor. - * @param parent Parent object. - */ - VolumeControl(QObject *parent = nullptr); - /*! - * Destructor. - */ - ~VolumeControl(); - /*! - * Setups volume level. - * Subclass should reimplement this fucntion. - * @param left Left channel volume level. It should be \b 0..100 - * @param right Right channel volume level. It should be \b 0..100 - */ - void setVolume(int left, int right); - /*! - * Changes volume by \b delta percent - */ - 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); - void setMuted(bool muted); - /*! - * Returns left channel volume. - */ - int left() const; - /*! - * Returns right channel volume. - */ - 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; - - bool isMuted() const; - -signals: - /*! - * Emitted when volume is changed. - * @param left Left channel volume level. It should be \b 0..100 - * @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); - void mutedChanged(bool muted); - -public slots: - /*! - * Forces the volumeChanged signal to emit. - */ - void checkVolume(); - /*! - * Updates volume configuration - */ - void reload(); - -private: - int m_left = 0, m_right = 0; - bool m_prev_block = false; - bool m_muted = false; - Volume *m_volume = nullptr; - QTimer *m_timer; - -}; -/*! @internal - * @brief The SoftwareVolume class provides access to the software volume control. - * @author Ilya Kotov - */ -class SoftwareVolume : public Volume -{ -public: - SoftwareVolume(); - ~SoftwareVolume(); - - void setVolume(const VolumeSettings &v) override; - VolumeSettings volume() const override; - void changeVolume(Buffer *b, int chan); - -private: - int m_left, m_right; - double m_scaleLeft, m_scaleRight; -}; - -#endif diff --git a/src/qmmp/volumehandler.cpp b/src/qmmp/volumehandler.cpp new file mode 100644 index 000000000..8bed61ce4 --- /dev/null +++ b/src/qmmp/volumehandler.cpp @@ -0,0 +1,177 @@ +/*************************************************************************** + * Copyright (C) 2008-2016 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include "qmmpsettings.h" +#include "output.h" +#include "softwarevolume_p.h" +#include "volumehandler.h" + +VolumeHandler::VolumeHandler(QObject *parent) : QObject(parent) +{ + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), SLOT(checkVolume())); + reload(); +} + +VolumeHandler::~VolumeHandler() +{ + if(m_volume) + delete m_volume; +} + +void VolumeHandler::setVolume(int left, int right) +{ + VolumeSettings v; + v.left = qBound(0,left,100); + v.right = qBound(0,right,100); + m_volume->setVolume(v); + checkVolume(); +} + +void VolumeHandler::changeVolume(int delta) +{ + setVolume(qBound(0, volume() + delta, 100)); +} + +void VolumeHandler::setVolume(int volume) +{ + volume = qBound(0, volume, 100); + setVolume(volume-qMax(balance(),0)*volume/100, + volume+qMin(balance(),0)*volume/100); +} + +void VolumeHandler::setBalance(int balance) +{ + balance = qBound(-100, balance, 100); + setVolume(volume()-qMax(balance,0)*volume()/100, + volume()+qMin(balance,0)*volume()/100); +} + +void VolumeHandler::setMuted(bool muted) +{ + if(m_muted != muted) + { + m_volume->setMuted(muted); + checkVolume(); + } +} + +int VolumeHandler::left() const +{ + return m_left; +} + +int VolumeHandler::right() const +{ + return m_right; +} + +int VolumeHandler::volume() const +{ + return qMax(m_right, m_left); +} + +int VolumeHandler::balance() const +{ + int v = volume(); + return v > 0 ? (m_right - m_left)*100/v : 0; +} + +bool VolumeHandler::isMuted() const +{ + return m_muted; +} + +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); + 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 + { + 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 (); +} + +void VolumeHandler::reload() +{ + m_timer->stop(); + bool restore = false; + if(m_volume) + { + restore = true; + delete m_volume; + m_volume = nullptr; + } + + if(!QmmpSettings::instance()->useSoftVolume() && Output::currentFactory()) + m_volume = Output::currentFactory()->createVolume(); + + if(m_volume) + { + if(restore) + m_volume->setMuted(m_muted); + + if(m_volume->flags() & Volume::HasNotifySignal) + { + checkVolume(); + connect(m_volume, SIGNAL(changed()), SLOT(checkVolume())); + } + else + { + m_timer->start(150); // fallback to polling if change notification is not available. + } + } + else + { + if(restore) + m_volume->setMuted(m_muted); + + m_volume = new SoftwareVolume; + blockSignals(true); + checkVolume(); + blockSignals(false); + QTimer::singleShot(125, this, SLOT(checkVolume())); + } +} diff --git a/src/qmmp/volumehandler.h b/src/qmmp/volumehandler.h new file mode 100644 index 000000000..73def472a --- /dev/null +++ b/src/qmmp/volumehandler.h @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2008-2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef VOLUMEHANDLER_H +#define VOLUMEHANDLER_H + +#include +#include "qmmp.h" +#include "volume.h" +#include "buffer.h" + +class QTimer; +class SoftwareVolume; + +/*! + * @brief The VolumeHandler class provides volume control access + * @author Ilya Kotov + */ +class QMMP_EXPORT VolumeHandler : public QObject +{ + Q_OBJECT +public: + /*! + * Object constructor. + * @param parent Parent object. + */ + VolumeHandler(QObject *parent = nullptr); + /*! + * Destructor. + */ + ~VolumeHandler(); + /*! + * Setups volume level. + * Subclass should reimplement this fucntion. + * @param left Left channel volume level. It should be \b 0..100 + * @param right Right channel volume level. It should be \b 0..100 + */ + void setVolume(int left, int right); + /*! + * Changes volume by \b delta percent + */ + 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); + void setMuted(bool muted); + /*! + * Returns left channel volume. + */ + int left() const; + /*! + * Returns right channel volume. + */ + 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; + + bool isMuted() const; + +signals: + /*! + * Emitted when volume is changed. + * @param left Left channel volume level. It should be \b 0..100 + * @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); + void mutedChanged(bool muted); + +public slots: + /*! + * Forces the volumeChanged signal to emit. + */ + void checkVolume(); + /*! + * Updates volume configuration + */ + void reload(); + +private: + int m_left = 0, m_right = 0; + bool m_prev_block = false; + bool m_muted = false; + Volume *m_volume = nullptr; + QTimer *m_timer; + +}; + +#endif -- cgit v1.2.3-13-gbd6f