TTKMusicPlayer  3.7.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 - 2024 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 static constexpr const char *MUSIC_TTKLRCF = "[TTKLRCF]";
26 
30 class TTK_MODULE_EXPORT MusicLrcAnalysis : public QObject
31 {
32  Q_OBJECT
34 public:
35  enum class State
36  {
37  Success,
38  Failed
39  };
40 
41  enum class Format
42  {
43  Type01,
44  Type02,
45  Type03,
46  Type04,
47  Type05,
48  Type06,
49  Type07,
50  Type08,
51  Type09,
52  Type10,
53  Type11,
54  Type12,
55  Type13,
56  Type14
57  };
58 
62  explicit MusicLrcAnalysis(QObject *parent = nullptr);
67 
71  inline void setLineMax(int max) { m_lineMax = max; }
75  inline int lineMax() const { return m_lineMax; }
79  inline int lineMiddle() const { return m_lineMax / 2; }
80 
84  State setData(const QByteArray &data);
88  State setData(const TTKIntStringMap &data);
92  void saveData();
93 
97  State loadFromLrcFile(const QString &path);
101  State loadFromKrcFile(const QString &path);
102 
106  qint64 setSongTimeSpeed(qint64 time);
110  void revertTime(qint64 pos);
111 
115  inline void setCurrentIndex(int index) { m_currentLrcIndex = index; }
119  inline int currentIndex() const { return m_currentLrcIndex; }
123  inline void setCurrentFilePath(const QString &name) { m_currentFilePath = name; }
127  inline QString currentFilePath() const { return m_currentFilePath; }
128 
132  void clear();
136  bool isValid() const;
140  bool isEmpty() const;
144  int count() const;
145 
149  QString text(int index) const;
153  bool findText(qint64 current, qint64 total, QString &pre, QString &last, qint64 &interval) const;
157  qint64 findTime(int index) const;
161  qint64 findTime(const QStringList &ts) const;
162 
166  QString dataString() const;
170  QStringList dataList() const;
171 
172 private:
176  void matchLrcLine(const QString &oneLine);
180  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second);
184  void matchLrcLine(const QString &oneLine, QString cap, const QString &splite);
188  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second, const QString &third);
189 
190  int m_lineMax, m_currentLrcIndex;
194 
195 };
196 
197 #endif // MUSICLRCANALYSIS_H
#define TTK_MODULE_EXPORT
void setLineMax(int max)
The input file format support.
Definition: format.h:29
void setCurrentIndex(int index)
int lineMax() const
constexpr const _Tp & max(const _Tp &a, const _Tp &b)
Definition: ttkcompat.h:33
int lineMiddle() const
const char * name
Definition: http_parser.c:458
The class of the core lrc analysis.
QMap< qint64, QString > TTKIntStringMap
Definition: ttkqtglobal.h:192
int currentIndex() const
void setCurrentFilePath(const QString &name)
QString currentFilePath() const
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152
static constexpr int MUSIC_LRC_INTERIOR_MAX_LINE
TTKIntStringMap m_lrcContainer
static constexpr const char * MUSIC_TTKLRCF
QStringList m_currentShowLrcContainer