aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-04-24 19:56:05 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-04-24 19:56:05 +0000
commit766716747a11971e1adfec02c32da0ab785a3815 (patch)
tree182db6829d138a442d2df3c916fc37b78243a597 /src/plugins
parent7253098d8eac878fe614752f89fec226aad74342 (diff)
downloadqmmp-766716747a11971e1adfec02c32da0ab785a3815.tar.gz
qmmp-766716747a11971e1adfec02c32da0ab785a3815.tar.bz2
qmmp-766716747a11971e1adfec02c32da0ab785a3815.zip
cue plugin: using shared CueParser class
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8792 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Input/cue/cue.pro8
-rw-r--r--src/plugins/Input/cue/cuefile.cpp201
-rw-r--r--src/plugins/Input/cue/cuefile.h (renamed from src/plugins/Input/cue/cueparser.h)37
-rw-r--r--src/plugins/Input/cue/cuemetadatamodel.cpp10
-rw-r--r--src/plugins/Input/cue/cuemetadatamodel.h4
-rw-r--r--src/plugins/Input/cue/cueparser.cpp353
-rw-r--r--src/plugins/Input/cue/decoder_cue.cpp38
-rw-r--r--src/plugins/Input/cue/decoder_cue.h4
-rw-r--r--src/plugins/Input/cue/decodercuefactory.cpp6
9 files changed, 248 insertions, 413 deletions
diff --git a/src/plugins/Input/cue/cue.pro b/src/plugins/Input/cue/cue.pro
index e4ddd656b..9e6b9387f 100644
--- a/src/plugins/Input/cue/cue.pro
+++ b/src/plugins/Input/cue/cue.pro
@@ -3,16 +3,16 @@ include(../../plugins.pri)
TARGET = $$PLUGINS_PREFIX/Input/cue
HEADERS += decodercuefactory.h \
- cueparser.h \
decoder_cue.h \
settingsdialog.h \
- cuemetadatamodel.h
+ cuemetadatamodel.h \
+ cuefile.h
SOURCES += decoder_cue.cpp \
decodercuefactory.cpp \
- cueparser.cpp \
settingsdialog.cpp \
- cuemetadatamodel.cpp
+ cuemetadatamodel.cpp \
+ cuefile.cpp
FORMS += settingsdialog.ui
diff --git a/src/plugins/Input/cue/cuefile.cpp b/src/plugins/Input/cue/cuefile.cpp
new file mode 100644
index 000000000..69a4622b9
--- /dev/null
+++ b/src/plugins/Input/cue/cuefile.cpp
@@ -0,0 +1,201 @@
+/***************************************************************************
+ * Copyright (C) 2008-2019 by Ilya Kotov *
+ * forkotov02@ya.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <QFile>
+#include <QDir>
+#include <QDirIterator>
+#include <QSettings>
+#include <QTextStream>
+#include <QTextCodec>
+#include <qmmp/decoder.h>
+#include <qmmp/metadatamanager.h>
+#ifdef WITH_ENCA
+#include <enca.h>
+#endif
+#include "cuefile.h"
+
+CueFile::CueFile(const QString &path) : CueParser()
+{
+ QString fileName = path;
+ if(path.contains("://"))
+ {
+ fileName.remove("cue://");
+ fileName.remove(QRegExp("#\\d+$"));
+ }
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly))
+ {
+ qDebug("CueFile: error: %s", qPrintable(file.errorString()));
+ return;
+ }
+ QByteArray data = file.readAll();
+ file.close();
+
+ QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
+ settings.beginGroup("CUE");
+ m_dirty = settings.value("dirty_cue", false).toBool();
+ QTextCodec *codec = nullptr;
+#ifdef WITH_ENCA
+ EncaAnalyser analyser = nullptr;
+ if(settings.value("use_enca", false).toBool())
+ {
+ analyser = enca_analyser_alloc(settings.value("enca_lang").toByteArray ().constData());
+
+ if(analyser)
+ {
+ enca_set_threshold(analyser, 1.38);
+ EncaEncoding encoding = enca_analyse(analyser, (uchar *)data.constData(), data.size());
+ file.reset();
+ if(encoding.charset != ENCA_CS_UNKNOWN)
+ {
+ codec = QTextCodec::codecForName(enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA));
+ //qDebug("CUEParser: detected charset: %s",
+ // enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA));
+ }
+ enca_analyser_free(analyser);
+ }
+ }
+#endif
+ if(!codec)
+ codec = QTextCodec::codecForName(settings.value("encoding","UTF-8").toByteArray ());
+ if(!codec)
+ codec = QTextCodec::codecForName("UTF-8");
+ settings.endGroup();
+ //qDebug("CUEParser: using %s encoding", codec->name().constData());
+ loadData(data, codec->name());
+ setUrl("cue", path);
+ for(const QString &dataFileName : files())
+ {
+ QString dataFilePath = getDirtyPath(dataFileName, QFileInfo(fileName).dir().filePath(dataFileName));
+ m_dataFiles.insert(dataFileName, dataFilePath);
+ QList<TrackInfo *> pl = MetaDataManager::instance()->createPlayList(dataFilePath, TrackInfo::Properties);
+ if(!pl.isEmpty())
+ {
+ setProperties(dataFileName, pl.first()->properties());
+ setDuration(dataFileName, pl.first()->duration());
+ qDeleteAll(pl);
+ pl.clear();
+ }
+ }
+}
+
+CueFile::~CueFile()
+{}
+
+QString CueFile::dataFilePath(int track) const
+{
+ return m_dataFiles.value(file(track));
+}
+
+QStringList CueFile::dataFilePaths() const
+{
+ return m_dataFiles.values();
+}
+
+QStringList CueFile::splitLine(const QString &line)
+{
+ //qDebug("raw string = %s",qPrintable(line));
+ QStringList list;
+ QString buf = line.trimmed();
+ if (buf.isEmpty())
+ return list;
+ while (!buf.isEmpty())
+ {
+ //qDebug(qPrintable(buf));
+ if (buf.startsWith('"'))
+ {
+ int end = buf.indexOf('"',1);
+ if(end == -1) //ignore invalid line
+ {
+ list.clear();
+ qWarning("CUEParser: unable to parse line: %s",qPrintable(line));
+ return list;
+ }
+ list << buf.mid (1, end - 1);
+ buf.remove (0, end+1);
+ }
+ else
+ {
+ int end = buf.indexOf(' ', 0);
+ if (end < 0)
+ end = buf.size();
+ list << buf.mid (0, end);
+ buf.remove (0, end);
+ }
+ buf = buf.trimmed();
+ }
+ return list;
+}
+
+/*qint64 CueFile::getLength(const QString &str)
+{
+ QStringList list = str.split(":");
+ if (list.size() == 2)
+ return (qint64)list.at(0).toInt()*60000 + list.at(1).toInt()*1000;
+ else if (list.size() == 3)
+ return (qint64)list.at(0).toInt()*60000 + list.at(1).toInt()*1000 + list.at(2).toInt()*1000/75;
+ return 0;
+}*/
+
+QString CueFile::getDirtyPath(const QString &cue_path, const QString &path)
+{
+ if((QFile::exists(path) && Decoder::findByFilePath(path)) || !m_dirty)
+ return path;
+
+ QStringList candidates;
+ QDirIterator it(QFileInfo(path).dir().path(), QDir::Files);
+ while (it.hasNext())
+ {
+ it.next();
+ QString f = it.filePath();
+ if ((f != cue_path) && Decoder::findByFilePath(f))
+ candidates.push_back(f);
+ }
+
+ if (candidates.empty())
+ return path;
+ else if (candidates.count() == 1)
+ return candidates.first();
+
+ int dot = cue_path.lastIndexOf('.');
+ if (dot != -1)
+ {
+ QRegExp r(QRegExp::escape(cue_path.left(dot)) + "\\.[^\\.]+$");
+
+ int index = candidates.indexOf(r);
+ int rindex = candidates.lastIndexOf(r);
+
+ if ((index != -1) && (index == rindex))
+ return candidates[index];
+ }
+ dot = path.lastIndexOf('.');
+ if (dot != -1)
+ {
+ QRegExp r(QRegExp::escape(path.left(dot)) + "\\.[^\\.]+$");
+
+ int index = candidates.indexOf(r);
+ int rindex = candidates.lastIndexOf(r);
+
+ if ((index != -1) && (index == rindex))
+ return candidates[index];
+ }
+
+ return path;
+}
diff --git a/src/plugins/Input/cue/cueparser.h b/src/plugins/Input/cue/cuefile.h
index 8d06fce0b..340f0c24c 100644
--- a/src/plugins/Input/cue/cueparser.h
+++ b/src/plugins/Input/cue/cuefile.h
@@ -17,8 +17,8 @@
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef CUEPARSER_H
-#define CUEPARSER_H
+#ifndef CUEFILE_H
+#define CUEFILE_H
#include <QList>
#include <QMap>
@@ -26,40 +26,27 @@
#include <QStringList>
#include <qmmp/qmmp.h>
#include <qmmp/trackinfo.h>
+#include <qmmp/cueparser.h>
/**
@author Ilya Kotov <forkotov02@ya.ru>
*/
-class CUEParser
+class CueFile : public CueParser
{
public:
- CUEParser(const QString &path);
+ CueFile(const QString &path);
+ ~CueFile();
- ~CUEParser();
-
- QList<TrackInfo*> createPlayList();
- const QString filePath(int track) const;
- const QStringList dataFiles() const;
- qint64 offset(int track) const;
- qint64 duration(int track) const;
- int count() const;
- TrackInfo *info(int track);
- const QString trackURL(int track) const;
- const QMap<Qmmp::ReplayGainKey, double> replayGain(int track) const;
+ QString dataFilePath(int track) const;
+ QStringList dataFilePaths() const;
private:
- struct CUETrack
- {
- TrackInfo info;
- qint64 offset;
- QString file;
- };
- QList <CUETrack *> m_tracks;
- bool m_dirty;
QStringList splitLine(const QString &line);
- qint64 getLength(const QString &str);
QString getDirtyPath(const QString &cue_path, const QString &path);
+ QMap<QString, QString> m_dataFiles; //name, full path
+ bool m_dirty;
+
};
-#endif
+#endif //CUEFILE_H
diff --git a/src/plugins/Input/cue/cuemetadatamodel.cpp b/src/plugins/Input/cue/cuemetadatamodel.cpp
index ee592af53..91beb3639 100644
--- a/src/plugins/Input/cue/cuemetadatamodel.cpp
+++ b/src/plugins/Input/cue/cuemetadatamodel.cpp
@@ -19,24 +19,24 @@
***************************************************************************/
#include <qmmp/metadatamanager.h>
-#include "cueparser.h"
+#include "cuefile.h"
#include "cuemetadatamodel.h"
CUEMetaDataModel::CUEMetaDataModel(const QString &url) : MetaDataModel(true)
{
- m_parser = new CUEParser(url);
- if (m_parser->count() == 0)
+ m_cueFile = new CueFile(url);
+ if (m_cueFile->count() == 0)
{
qWarning("CUEMetaDataModel: invalid cue file");
return;
}
int track = url.section("#", -1).toInt();
- m_path = m_parser->filePath(track);
+ m_path = m_cueFile->dataFilePath(track);
}
CUEMetaDataModel::~CUEMetaDataModel()
{
- delete m_parser;
+ delete m_cueFile;
}
QList<MetaDataItem> CUEMetaDataModel::extraProperties() const
diff --git a/src/plugins/Input/cue/cuemetadatamodel.h b/src/plugins/Input/cue/cuemetadatamodel.h
index 78ef36307..26a15f017 100644
--- a/src/plugins/Input/cue/cuemetadatamodel.h
+++ b/src/plugins/Input/cue/cuemetadatamodel.h
@@ -23,7 +23,7 @@
#include <qmmp/metadatamodel.h>
-class CUEParser;
+class CueFile;
class CUEMetaDataModel : public MetaDataModel
{
@@ -34,7 +34,7 @@ public:
QString coverPath() const override;
private:
- CUEParser *m_parser;
+ CueFile *m_cueFile;
QString m_path;
};
diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp
deleted file mode 100644
index 08b0f804c..000000000
--- a/src/plugins/Input/cue/cueparser.cpp
+++ /dev/null
@@ -1,353 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2008-2019 by Ilya Kotov *
- * forkotov02@ya.ru *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-
-#include <QFile>
-#include <QDir>
-#include <QDirIterator>
-#include <QSettings>
-#include <QTextStream>
-#include <QTextCodec>
-#include <qmmp/decoder.h>
-#include <qmmp/metadatamanager.h>
-#ifdef WITH_ENCA
-#include <enca.h>
-#endif
-#include "cueparser.h"
-
-CUEParser::CUEParser(const QString &path)
-{
- QString fileName = path;
- if(path.contains("://"))
- {
- fileName.remove("cue://");
- fileName.remove(QRegExp("#\\d+$"));
- }
- QFile file(fileName);
- if (!file.open(QIODevice::ReadOnly))
- {
- qDebug("CUEParser: error: %s", qPrintable(file.errorString()));
- return;
- }
- QTextStream textStream (&file);
- QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
- settings.beginGroup("CUE");
- m_dirty = settings.value("dirty_cue", false).toBool();
- QTextCodec *codec = nullptr;
-#ifdef WITH_ENCA
- EncaAnalyser analyser = nullptr;
- if(settings.value("use_enca", false).toBool())
- {
- analyser = enca_analyser_alloc(settings.value("enca_lang").toByteArray ().constData());
-
- if(analyser)
- {
- enca_set_threshold(analyser, 1.38);
- EncaEncoding encoding = enca_analyse(analyser,
- (uchar *)file.readAll().constData(),
- file.size());
- file.reset();
- if(encoding.charset != ENCA_CS_UNKNOWN)
- {
- codec = QTextCodec::codecForName(enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA));
- //qDebug("CUEParser: detected charset: %s",
- // enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA));
- }
- }
- }
-#endif
- if(!codec)
- codec = QTextCodec::codecForName(settings.value("encoding","UTF-8").toByteArray ());
- if(!codec)
- codec = QTextCodec::codecForName("UTF-8");
- settings.endGroup();
- //qDebug("CUEParser: using %s encoding", codec->name().constData());
- textStream.setCodec(codec);
- QString album, genre, date, comment, artist, file_path;
- double album_gain = 0.0, album_peak = 0.0;
-
- while (!textStream.atEnd())
- {
- QString line = textStream.readLine().trimmed();
- QStringList words = splitLine(line);
- if (words.size() < 2)
- continue;
-
- if (words[0] == "FILE")
- {
- file_path = getDirtyPath(fileName, QFileInfo(fileName).dir().filePath(words[1]));
- }
- else if (words[0] == "PERFORMER")
- {
- if(m_tracks.isEmpty())
- artist = words[1];
- else
- m_tracks.last()->info.setValue(Qmmp::ARTIST, words[1]);
- }
- else if (words[0] == "TITLE")
- {
- if(m_tracks.isEmpty())
- album = words[1];
- else
- m_tracks.last()->info.setValue(Qmmp::TITLE, words[1]);
- }
- else if (words[0] == "TRACK")
- {
- QString path = fileName;
- TrackInfo info("cue://" + path + QString("#%1").arg(words[1].toInt()));
- info.setValue(Qmmp::TRACK, words[1].toInt());
- info.setValue(Qmmp::ALBUM, album);
- info.setValue(Qmmp::GENRE, genre);
- info.setValue(Qmmp::YEAR, date);
- info.setValue(Qmmp::COMMENT, comment);
- info.setValue(Qmmp::ARTIST, artist);
- info.setValue(Qmmp::ALBUMARTIST, artist);
- info.setValue(Qmmp::REPLAYGAIN_ALBUM_GAIN, album_gain);
- info.setValue(Qmmp::REPLAYGAIN_ALBUM_PEAK, album_peak);
-
- m_tracks << new CUETrack;
- m_tracks.last()->info = info;
- m_tracks.last()->offset = 0;
- }
- else if (words[0] == "INDEX" && words[1] == "01")
- {
- if (m_tracks.isEmpty())
- continue;
- m_tracks.last()->offset = getLength(words[2]);
- m_tracks.last()->file = file_path;
- }
- else if (words[0] == "REM")
- {
- if (words.size() < 3)
- continue;
- if (words[1] == "GENRE")
- genre = words[2];
- else if (words[1] == "DATE")
- date = words[2];
- else if (words[1] == "COMMENT")
- comment = words[2];
- else if (words[1] == "REPLAYGAIN_ALBUM_GAIN")
- album_gain = words[2].toDouble();
- else if (words[1] == "REPLAYGAIN_ALBUM_PEAK")
- album_peak = words[2].toDouble();
- else if (words[1] == "REPLAYGAIN_TRACK_GAIN" && !m_tracks.isEmpty())
- m_tracks.last()->info.setValue(Qmmp::REPLAYGAIN_TRACK_GAIN, words[2].toDouble());
- else if (words[1] == "REPLAYGAIN_TRACK_PEAK" && !m_tracks.isEmpty())
- m_tracks.last()->info.setValue(Qmmp::REPLAYGAIN_TRACK_PEAK, words[2].toDouble());
- }
- }
- file.close();
-#ifdef WITH_ENCA
- if(analyser)
- enca_analyser_free(analyser);
-#endif
- if(m_tracks.isEmpty())
- {
- qWarning("CUEParser: invalid cue file");
- return;
- }
- //skip invalid cue sheet
- foreach(CUETrack *track, m_tracks)
- {
- if(!QFile::exists(track->file))
- {
- qDeleteAll(m_tracks);
- m_tracks.clear();
- break;
- }
- }
- //calculate lengths
- QList<TrackInfo *> f_list;
- for(int i = 0; i < m_tracks.count(); ++i)
- {
- if(i == 0 || m_tracks[i - 1]->file != m_tracks[i]->file)
- {
- qDeleteAll(f_list);
- f_list = MetaDataManager::instance()->createPlayList(m_tracks[i]->file, TrackInfo::Properties);
- }
- if(!f_list.isEmpty())
- m_tracks[i]->info.setValues(f_list.first()->properties());
-
- if((i < m_tracks.count() - 1) && (m_tracks[i]->file == m_tracks[i+1]->file))
- m_tracks[i]->info.setDuration(m_tracks[i+1]->offset - m_tracks[i]->offset);
- else if(!f_list.isEmpty())
- m_tracks[i]->info.setDuration(qMax(0LL, f_list.first()->duration() - m_tracks[i]->offset));
- }
- qDeleteAll(f_list);
- f_list.clear();
-}
-
-CUEParser::~CUEParser()
-{
- qDeleteAll(m_tracks);
- m_tracks.clear();
-}
-
-QList<TrackInfo *> CUEParser::createPlayList()
-{
- QList<TrackInfo*> list;
- foreach(CUETrack *track, m_tracks)
- {
- list << new TrackInfo(track->info);
- }
- return list;
-}
-
-const QString CUEParser::filePath(int track) const
-{
- return (track <= m_tracks.count()) ? m_tracks[track - 1]->file : QString();
-}
-
-const QStringList CUEParser::dataFiles() const
-{
- QStringList files;
- for(int i = 0; i < m_tracks.count(); ++i)
- {
- if(i == 0)
- {
- files << m_tracks[i]->file;
- continue;
- }
-
- if(files.last() != m_tracks[i]->file)
- files.append(m_tracks[i]->file);
- }
- return files;
-}
-
-qint64 CUEParser::offset(int track) const
-{
- return m_tracks.at(track - 1)->offset;
-}
-
-qint64 CUEParser::duration(int track) const
-{
- return m_tracks.at(track - 1)->info.duration();
-}
-
-int CUEParser::count() const
-{
- return m_tracks.count();
-}
-
-TrackInfo *CUEParser::info(int track)
-{
- return &m_tracks.at(track - 1)->info;
-}
-
-const QString CUEParser::trackURL(int track) const
-{
- return m_tracks.at(track - 1)->info.path();
-}
-
-const QMap<Qmmp::ReplayGainKey, double> CUEParser::replayGain(int track) const
-{
- return m_tracks.at(track - 1)->info.replayGainInfo();
-}
-
-QStringList CUEParser::splitLine(const QString &line)
-{
- //qDebug("raw string = %s",qPrintable(line));
- QStringList list;
- QString buf = line.trimmed();
- if (buf.isEmpty())
- return list;
- while (!buf.isEmpty())
- {
- //qDebug(qPrintable(buf));
- if (buf.startsWith('"'))
- {
- int end = buf.indexOf('"',1);
- if(end == -1) //ignore invalid line
- {
- list.clear();
- qWarning("CUEParser: unable to parse line: %s",qPrintable(line));
- return list;
- }
- list << buf.mid (1, end - 1);
- buf.remove (0, end+1);
- }
- else
- {
- int end = buf.indexOf(' ', 0);
- if (end < 0)
- end = buf.size();
- list << buf.mid (0, end);
- buf.remove (0, end);
- }
- buf = buf.trimmed();
- }
- return list;
-}
-
-qint64 CUEParser::getLength(const QString &str)
-{
- QStringList list = str.split(":");
- if (list.size() == 2)
- return (qint64)list.at(0).toInt()*60000 + list.at(1).toInt()*1000;
- else if (list.size() == 3)
- return (qint64)list.at(0).toInt()*60000 + list.at(1).toInt()*1000 + list.at(2).toInt()*1000/75;
- return 0;
-}
-
-QString CUEParser::getDirtyPath(const QString &cue_path, const QString &path)
-{
- if((QFile::exists(path) && Decoder::findByFilePath(path)) || !m_dirty)
- return path;
-
- QStringList candidates;
- QDirIterator it(QFileInfo(path).dir().path(), QDir::Files);
- while (it.hasNext())
- {
- it.next();
- QString f = it.filePath();
- if ((f != cue_path) && Decoder::findByFilePath(f))
- candidates.push_back(f);
- }
-
- if (candidates.empty())
- return path;
- else if (candidates.count() == 1)
- return candidates.first();
-
- int dot = cue_path.lastIndexOf('.');
- if (dot != -1)
- {
- QRegExp r(QRegExp::escape(cue_path.left(dot)) + "\\.[^\\.]+$");
-
- int index = candidates.indexOf(r);
- int rindex = candidates.lastIndexOf(r);
-
- if ((index != -1) && (index == rindex))
- return candidates[index];
- }
- dot = path.lastIndexOf('.');
- if (dot != -1)
- {
- QRegExp r(QRegExp::escape(path.left(dot)) + "\\.[^\\.]+$");
-
- int index = candidates.indexOf(r);
- int rindex = candidates.lastIndexOf(r);
-
- if ((index != -1) && (index == rindex))
- return candidates[index];
- }
-
- return path;
-}
diff --git a/src/plugins/Input/cue/decoder_cue.cpp b/src/plugins/Input/cue/decoder_cue.cpp
index e56b34683..91057fb86 100644
--- a/src/plugins/Input/cue/decoder_cue.cpp
+++ b/src/plugins/Input/cue/decoder_cue.cpp
@@ -25,7 +25,7 @@
#include <qmmp/trackinfo.h>
#include <qmmp/decoderfactory.h>
#include <qmmp/soundcore.h>
-#include "cueparser.h"
+#include "cuefile.h"
#include "decoder_cue.h"
@@ -34,7 +34,7 @@ DecoderCUE::DecoderCUE(const QString &url)
{
m_path = url;
m_decoder = nullptr;
- m_parser = nullptr;
+ m_cueFile = nullptr;
m_track = 0;
m_buf = nullptr;
m_input = nullptr;
@@ -45,9 +45,9 @@ DecoderCUE::~DecoderCUE()
if(m_decoder)
delete m_decoder;
m_decoder = nullptr;
- if(m_parser)
- delete m_parser;
- m_parser = nullptr;
+ if(m_cueFile)
+ delete m_cueFile;
+ m_cueFile = nullptr;
if(m_buf)
delete [] m_buf;
m_buf = nullptr;
@@ -58,14 +58,14 @@ DecoderCUE::~DecoderCUE()
bool DecoderCUE::initialize()
{
- m_parser = new CUEParser(m_path);
- if (m_parser->count() == 0)
+ m_cueFile = new CueFile(m_path);
+ if (m_cueFile->count() == 0)
{
qWarning("DecoderCUE: invalid cue file");
return false;
}
m_track = m_path.section("#", -1).toInt();
- m_path = m_parser->filePath(m_track);
+ m_path = m_cueFile->dataFilePath(m_track);
if (!QFile::exists(m_path))
{
qWarning("DecoderCUE: file \"%s\" doesn't exist", qPrintable(m_path));
@@ -77,8 +77,8 @@ bool DecoderCUE::initialize()
qWarning("DecoderCUE: unsupported file format");
return false;
}
- m_length = m_parser->duration(m_track);
- m_offset = m_parser->offset(m_track);
+ m_length = m_cueFile->duration(m_track);
+ m_offset = m_cueFile->offset(m_track);
if(!df->properties().noInput)
{
m_input = new QFile(m_path);
@@ -97,14 +97,14 @@ bool DecoderCUE::initialize()
m_decoder->seek(m_offset);
configure(m_decoder->audioParameters());
- setReplayGainInfo(m_parser->replayGain(m_track));
+ setReplayGainInfo(m_cueFile->info(m_track)->replayGainInfo());
length_in_bytes = audioParameters().sampleRate() *
audioParameters().frameSize() * m_length/1000;
m_totalBytes = 0;
m_sz = audioParameters().frameSize();
- addMetaData(m_parser->info(m_track)->metaData());
+ addMetaData(m_cueFile->info(m_track)->metaData());
return true;
}
@@ -171,23 +171,23 @@ int DecoderCUE::bitrate() const
const QString DecoderCUE::nextURL() const
{
- if(m_track +1 <= m_parser->count() && m_parser->filePath(m_track) == m_parser->filePath(m_track + 1))
- return m_parser->trackURL(m_track + 1);
+ if(m_track +1 <= m_cueFile->count() && m_cueFile->dataFilePath(m_track) == m_cueFile->dataFilePath(m_track + 1))
+ return m_cueFile->url(m_track + 1);
else
return QString();
}
void DecoderCUE::next()
{
- if(m_track +1 <= m_parser->count())
+ if(m_track +1 <= m_cueFile->count())
{
m_track++;
- m_length = m_parser->duration(m_track);
- m_offset = m_parser->offset(m_track);
+ m_length = m_cueFile->duration(m_track);
+ m_offset = m_cueFile->offset(m_track);
length_in_bytes = audioParameters().sampleRate() *
audioParameters().frameSize() * m_length/1000;
- addMetaData(m_parser->info(m_track)->metaData());
- setReplayGainInfo(m_parser->replayGain(m_track));
+ addMetaData(m_cueFile->info(m_track)->metaData());
+ setReplayGainInfo(m_cueFile->info(m_track)->replayGainInfo());
m_totalBytes = 0;
}
}
diff --git a/src/plugins/Input/cue/decoder_cue.h b/src/plugins/Input/cue/decoder_cue.h
index 3518ea039..f0aa7b906 100644
--- a/src/plugins/Input/cue/decoder_cue.h
+++ b/src/plugins/Input/cue/decoder_cue.h
@@ -26,7 +26,7 @@
class Output;
class QIDevice;
-class CUEParser;
+class CueFile;
class DecoderCUE : public Decoder
{
@@ -50,7 +50,7 @@ private:
qint64 length_in_bytes;
qint64 m_totalBytes;
QString m_path;
- CUEParser *m_parser;
+ CueFile *m_cueFile;
int m_track;
char *m_buf; //buffer for remainig data
qint64 m_buf_size;
diff --git a/src/plugins/Input/cue/decodercuefactory.cpp b/src/plugins/Input/cue/decodercuefactory.cpp
index c6b3c4499..43bbb7354 100644
--- a/src/plugins/Input/cue/decodercuefactory.cpp
+++ b/src/plugins/Input/cue/decodercuefactory.cpp
@@ -21,7 +21,7 @@
#include <QMessageBox>
#include "decoder_cue.h"
#include "cuemetadatamodel.h"
-#include "cueparser.h"
+#include "cuefile.h"
#include "settingsdialog.h"
#include "decodercuefactory.h"
@@ -55,7 +55,7 @@ Decoder *DecoderCUEFactory::create(const QString &path, QIODevice *input)
QList<TrackInfo *> DecoderCUEFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *ignoredPaths)
{
Q_UNUSED(parts);
- CUEParser parser(path);
+ CueFile parser(path);
if(path.contains("://"))
{
QList<TrackInfo *> list;
@@ -69,7 +69,7 @@ QList<TrackInfo *> DecoderCUEFactory::createPlayList(const QString &path, TrackI
}
else
{
- ignoredPaths->append(parser.dataFiles());
+ ignoredPaths->append(parser.dataFilePaths());
return parser.createPlayList();
}
}