TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
volumehandler.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008-2024 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 
21 #ifndef VOLUMEHANDLER_H
22 #define VOLUMEHANDLER_H
23 
24 #include <QMutex>
25 #include <atomic>
26 #include "volume.h"
27 #include "buffer.h"
28 
29 class QTimer;
30 class SoftwareVolume;
31 
36 class QMMP_EXPORT VolumeHandler : public QObject
37 {
38  Q_OBJECT
39 public:
44  explicit VolumeHandler(QObject *parent = nullptr);
48  ~VolumeHandler();
49 
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:
111  void volumeChanged(int volume);
116  void balanceChanged(int balance);
121  void mutedChanged(bool muted);
122 
123 public slots:
127  void checkVolume();
131  void reload();
132 
133 private:
135  bool m_prev_block = false;
136  std::atomic_bool m_muted = ATOMIC_VAR_INIT(false);
137  std::atomic_bool m_apply = ATOMIC_VAR_INIT(false);
138  QMutex m_mutex;
139  double m_scaleLeft = 0, m_scaleRight = 0;
140  Volume *m_volume = nullptr;
141  QTimer *m_timer = nullptr;
143 
144 };
145 
146 #endif
static VolumeHandler * m_instance
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:36
#define QMMP_EXPORT
Definition: qmmp_export.h:29
Audio buffer class.
Definition: buffer.h:33
VolumeSettings m_settings