TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
statehandler.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008-2025 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 STATEHANDLER_H
22 #define STATEHANDLER_H
23 
24 #include <QHash>
25 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
26 # include <QMutex>
27 #else
28 # include <QRecursiveMutex>
29 #endif
30 #include "abstractengine.h"
31 #include "audioparameters.h"
32 
36 class QMMP_EXPORT StateHandler : public QObject
37 {
38  Q_OBJECT
39 public:
44  explicit StateHandler(QObject *parent = nullptr);
48  ~StateHandler();
49 
55  void dispatch(qint64 elapsed, int bitrate);
60  void dispatch(const AudioParameters &p);
65  void dispatch(qint64 duration);
70  bool dispatch(const TrackInfo &info);
74  void dispatch(const QHash<QString, QString> &info);
78  void dispatch(Qmmp::State state);
83  void dispatchBuffer(int percent);
87  qint64 elapsed() const;
91  qint64 duration() const;
95  int bitrate() const;
99  AudioParameters audioParameters() const;
103  Qmmp::State state() const;
107  void sendNextTrackRequest();
111  void sendFinished();
115  static StateHandler* instance();
116 
117 signals:
122  void elapsedChanged(qint64 time);
127  void bitrateChanged(int bitrate);
132  void audioParametersChanged(const AudioParameters &p);
137  void bufferingProgress(int progress);
138 
139 private:
140  qint64 m_elapsed = -1;
141  qint64 m_duration = 0;
142  bool m_sendAboutToFinish = true;
143  int m_bitrate = 0;
146  QHash<QString, QString> m_streamInfo;
149 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
150  mutable QMutex m_mutex;
151 #else
152  mutable QRecursiveMutex m_mutex;
153 #endif
154 };
155 
156 #endif
AudioParameters m_audioParameters
Definition: statehandler.h:148
QRecursiveMutex m_mutex
Definition: statehandler.h:152
The AudioParameters class keeps information about audio settings.
The StateHandler class allows one to track information about playback progress.
Definition: statehandler.h:36
The TrackInfo class stores metadata and other information about track.
Definition: trackinfo.h:32
State
Definition: qmmp.h:89
#define QMMP_EXPORT
Definition: qmmp_export.h:29
TrackInfo m_info
Definition: statehandler.h:145
static StateHandler * m_instance
Definition: statehandler.h:144
state
Definition: http_parser.c:279
QHash< QString, QString > m_streamInfo
Definition: statehandler.h:146