TTKMusicPlayer  4.2.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 - 2025 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
33 public:
34  enum class State
35  {
36  Success,
37  Failed
38  };
39 
40  enum class Format
41  {
42  Type01,
43  Type02,
44  Type03,
45  Type04,
46  Type05,
47  Type06,
48  Type07,
49  Type08,
50  Type09,
51  Type10,
52  Type11,
53  Type12,
54  Type13,
55  Type14
56  };
57 
61  explicit MusicLrcAnalysis(QObject *parent = nullptr);
62 
66  inline void setLineMax(int max) noexcept { m_lineMax = max; }
70  inline int lineMax() const noexcept { return m_lineMax; }
74  inline int lineMiddle() const noexcept { return m_lineMax / 2; }
75 
79  void saveData();
83  State setData(const TTKIntStringMap &data);
84 
88  State loadFromFile(const QString &path);
89 
93  qint64 setSongTimeSpeed(qint64 time);
97  void revertTime(qint64 pos);
98 
102  inline void setCurrentIndex(int index) noexcept { m_currentLrcIndex = index; }
106  inline int currentIndex() const noexcept { return m_currentLrcIndex; }
110  inline void setCurrentFilePath(const QString &name) noexcept { m_currentFilePath = name; }
114  inline QString currentFilePath() const noexcept { return m_currentFilePath; }
115 
119  void clear() noexcept;
123  bool isValid() const noexcept;
127  bool isEmpty() const noexcept;
131  int count() const noexcept;
132 
136  QString text(int index) const;
140  bool findText(qint64 current, qint64 total, QString &pre, QString &last, qint64 &interval) const;
144  qint64 findTime(int index) const;
148  qint64 findTime(const QStringList &ts) const;
149 
153  QString dataString() const;
157  QStringList dataList() const;
158 
159 private:
163  State initialize();
167  void matchLrcLine(const QString &oneLine);
171  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second);
175  void matchLrcLine(const QString &oneLine, QString cap, const QString &splite);
179  void matchLrcLine(const QString &oneLine, const QString &cap, const QString &first, const QString &second, const QString &third);
180 
181  int m_lineMax, m_currentLrcIndex;
182  QString m_currentFilePath;
183  TTKIntStringMap m_lrcContainer;
184  QStringList m_currentShowLrcContainer;
185 
186 };
187 
188 #endif // MUSICLRCANALYSIS_H
#define TTK_MODULE_EXPORT
QString currentFilePath() const noexcept
The input file format support.
Definition: format.h:29
int lineMax() const noexcept
void setLineMax(int max) noexcept
bool isValid(const QString &data)
Definition: qdlna.cpp:76
void setCurrentFilePath(const QString &name) 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
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:164
int lineMiddle() const noexcept
static constexpr int MUSIC_LRC_INTERIOR_MAX_LINE
constexpr const _Tp & max(const _Tp &a, const _Tp &b) noexcept
Definition: ttkcompat.h:33
#define const
Definition: zconf.h:233