1 Star 0 Fork 2

JIANCAI/MusicPlayer_QT5

forked from fword/MusicPlayer_QT5 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Lyrics.cpp 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
fword 提交于 2021-12-23 15:03 . first commit
#include "lyrics.h"
#include <QFile>
#include <QDebug>
#include <QRegularExpression>
Lyrics::Lyrics(QString lyricsPath)
{
this->lyrics_path = lyricsPath;
max_size = 0;
}
Lyrics::~Lyrics()
{
}
QList<QString> Lyrics::getListLyricsText()
{
return list_lyrics_text;
}
QVector<int> Lyrics::getListLyricsTime()
{
return list_lyrics_time;
}
bool Lyrics::readLyricsFile(QString lyricsPath)
{
if(lyrics_path == lyricsPath)
return true;
lyrics_path = lyricsPath;
size = 0;
QFile file(lyricsPath);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QString line = "";
while((line=file.readLine())>0)
{
//qDebug()<<line;
analysisLyricsFile(line);
}
max_size = max_size < size ? size : max_size;
return true;
}
else
{
return false;
}
}
bool Lyrics::analysisLyricsFile(QString line)
{
if(line == NULL || line.isEmpty())
{
qDebug()<<"This line is empty!";
return false;
}
QRegularExpression regularExpression("\\[(\\d+)?:(\\d+\\.\\d+)?\\](.*)?");
int index = 0;
QRegularExpressionMatch match;
match = regularExpression.match(line, index);
if(match.hasMatch())
{
int totalTime;
//qDebug()<<QString::fromStdString(match.captured(2).toStdString());
totalTime = match.captured(1).toInt() * 60000 + match.captured(2).toFloat() * 1000;
QString currentText =QString::fromStdString(match.captured(3).toStdString());
if(size < list_lyrics_time.size())
{
list_lyrics_text[size] = currentText;
list_lyrics_time[size++] = totalTime;
}
else
{
list_lyrics_text.push_back(currentText);
list_lyrics_time.push_back(totalTime);
size++;
}
return true;
}
return false;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/jiaanCai/Cplusplus.git
git@gitee.com:jiaanCai/Cplusplus.git
jiaanCai
Cplusplus
MusicPlayer_QT5
master

搜索帮助