TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musiclrcanalysis.h
Go to the documentation of this file.
1 #ifndef MUSICLRCANALYSIS_H
2 #define MUSICLRCANALYSIS_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2026 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include "musicglobaldefine.h"
23 
24 static constexpr int MUSIC_LRC_INTERIOR_MAX_LINE = 11;
25 
29 class TTK_MODULE_EXPORT MusicLrcAnalysis : public QObject
30 {
31  Q_OBJECT
32 public:
33  enum class State
34  {
35  Success,
36  Failed
37  };
38 
39  enum class Format
40  {
41  Type01,
42  Type02,
43  Type03,
44  Type04,
45  Type05,
46  Type06,
47  Type07,
48  Type08,
49  Type09,
50  Type10,
51  Type11,
52  Type12,
53  Type13,
54  Type14
55  };
56 
60  explicit MusicLrcAnalysis(QObject *parent = nullptr);
61 
65  inline void setMaximum(int max) noexcept { m_maximum = max; }
69  inline int maximum() const noexcept { return m_maximum; }
73  inline int middle() const noexcept { return m_maximum / 2; }
74 
78  State loadFromFile(const QString &path);
82  State loadFromBuffer(const TTKIntStringMap &data);
86  void save();
87 
91  void setTimePosition(qint64 pos);
95  qint64 findTimePosition(qint64 time);
96 
100  inline void setCurrentIndex(int index) noexcept { m_currentIndex = index; }
104  inline int currentIndex() const noexcept { return m_currentIndex; }
108  inline void setFilePath(const QString &name) noexcept { m_filePath = name; }
112  inline QString filePath() const noexcept { return m_filePath; }
113 
117  void clear() noexcept;
121  bool isValid() const noexcept;
125  bool isEmpty() const noexcept;
129  int count() const noexcept;
130 
134  QString text(int index) const;
138  bool findText(qint64 current, qint64 total, QString &pre, QString &last, qint64 &interval) const;
142  qint64 findTime(int index) const;
146  qint64 findTime(const QStringList &ts) const;
147 
151  QString dataString() const;
155  QStringList dataList() const;
156 
157 private:
161  State initialize();
165  void matchLrcLine(const QString &oneLine);
169  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second);
173  void matchLrcLine(const QString &oneLine, QString cap, const QString &splite);
177  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second, const QString &third);
178 
179  int m_maximum, m_currentIndex;
180  QString m_filePath;
181  TTKIntStringMap m_lrcContainer;
182  QStringList m_currentShowLrcContainer;
183 
184 };
185 
186 #endif // MUSICLRCANALYSIS_H
#define TTK_MODULE_EXPORT
The input file format support.
Definition: format.h:29
bool isValid(const QString &data)
Definition: qdlna.cpp:76
int maximum() const noexcept
void setCurrentIndex(int index) noexcept
int currentIndex() const noexcept
const char * name
Definition: http_parser.c:458
The class of the core lrc analysis.
QMap< qint64, QString > TTKIntStringMap
Definition: ttkqtglobal.h:204
void setMaximum(int max) noexcept
void setFilePath(const QString &name) noexcept
TTK_MODULE_EXPORT void initialize(TTK::Attribute attr)
static constexpr int MUSIC_LRC_INTERIOR_MAX_LINE
QString filePath() const noexcept
constexpr const _Tp & max(const _Tp &a, const _Tp &b) noexcept
Definition: ttkcompat.h:33
#define const
Definition: zconf.h:233
int middle() const noexcept