Qmmp
volumehandler.h
1 /***************************************************************************
2  * Copyright (C) 2008-2020 by Ilya Kotov *
3  * forkotov02@ya.ru *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef VOLUMEHANDLER_H
21 #define VOLUMEHANDLER_H
22 
23 #include <QObject>
24 #include <QMutex>
25 #include <atomic>
26 #include "qmmp.h"
27 #include "volume.h"
28 #include "buffer.h"
29 
30 class QTimer;
31 class SoftwareVolume;
32 
37 class QMMP_EXPORT VolumeHandler : public QObject
38 {
39  Q_OBJECT
40 public:
45  VolumeHandler(QObject *parent = nullptr);
49  ~VolumeHandler();
56  void setVolume(int left, int right);
60  void changeVolume(int delta);
65  void setVolume(int volume);
70  void setBalance(int balance);
74  void setMuted(bool muted);
78  int left() const;
82  int right() const;
86  int volume() const;
90  int balance() const;
94  bool isMuted() const;
100  void apply(Buffer *b, int chan);
104  static VolumeHandler *instance();
105 
106 signals:
112  void volumeChanged(int left, int right);
117  void volumeChanged(int volume);
122  void balanceChanged(int balance);
127  void mutedChanged(bool muted);
128 
129 public slots:
133  void checkVolume();
137  void reload();
138 
139 private:
140  VolumeSettings m_settings;
141  bool m_prev_block = false;
142  std::atomic_bool m_muted = ATOMIC_VAR_INIT(false);
143  std::atomic_bool m_apply = ATOMIC_VAR_INIT(false);
144  QMutex m_mutex;
145  double m_scaleLeft = 0, m_scaleRight = 0;
146  Volume *m_volume = nullptr;
147  QTimer *m_timer;
148  static VolumeHandler *m_instance;
149 
150 };
151 
152 #endif
The VolumeSettings structure stores volume levels.
Definition: volume.h:31
The Volume class provides asbtract volume interface.
Definition: volume.h:51
The VolumeHandler class provides volume control access.
Definition: volumehandler.h:37
Audio buffer class.
Definition: buffer.h:20