2011-05-12 22:57:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2017-03-12 12:12:49 +01:00
|
|
|
// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
|
2011-05-12 22:57:08 +02:00
|
|
|
//
|
|
|
|
// 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
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2011-05-12 22:57:08 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//Internal
|
2011-05-13 02:44:20 +02:00
|
|
|
#include "Global.h"
|
2011-05-12 22:57:08 +02:00
|
|
|
#include "Model_CueSheet.h"
|
2013-10-13 20:50:12 +02:00
|
|
|
#include "Model_AudioFile.h"
|
2011-05-12 22:57:08 +02:00
|
|
|
#include "Genres.h"
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
2014-11-30 21:32:23 +01:00
|
|
|
#include <MUtils/OSSupport.h>
|
2014-11-25 02:14:42 +01:00
|
|
|
|
|
|
|
//Qt
|
2011-05-13 13:17:21 +02:00
|
|
|
#include <QApplication>
|
2011-05-14 15:54:04 +02:00
|
|
|
#include <QDir>
|
2011-05-12 22:57:08 +02:00
|
|
|
#include <QFileInfo>
|
2011-05-14 15:54:04 +02:00
|
|
|
#include <QFont>
|
2011-05-18 00:36:51 +02:00
|
|
|
#include <QTime>
|
2011-12-10 01:59:45 +01:00
|
|
|
#include <QTextCodec>
|
2011-12-13 23:33:21 +01:00
|
|
|
#include <QTextStream>
|
2013-10-12 20:36:45 +02:00
|
|
|
#include <QMutexLocker>
|
2011-05-12 22:57:08 +02:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//CRT
|
2011-05-12 22:57:08 +02:00
|
|
|
#include <float.h>
|
|
|
|
#include <limits>
|
|
|
|
|
2011-09-24 00:15:50 +02:00
|
|
|
#define UNQUOTE(STR) STR.split("\"", QString::SkipEmptyParts).first().trimmed()
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Helper Classes
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class CueSheetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const char* type(void) = 0;
|
2011-05-14 15:54:04 +02:00
|
|
|
virtual bool isValid(void) { return false; }
|
2011-05-12 22:57:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CueSheetTrack : public CueSheetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CueSheetTrack(CueSheetFile *parent, int trackNo)
|
|
|
|
:
|
2013-10-13 20:50:12 +02:00
|
|
|
m_parent(parent)
|
2011-05-12 22:57:08 +02:00
|
|
|
{
|
|
|
|
m_startIndex = std::numeric_limits<double>::quiet_NaN();
|
2011-05-14 15:54:04 +02:00
|
|
|
m_duration = std::numeric_limits<double>::infinity();
|
2013-10-13 20:50:12 +02:00
|
|
|
m_metaInfo.setPosition(trackNo);
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
2013-10-13 20:50:12 +02:00
|
|
|
|
|
|
|
//Getter
|
|
|
|
CueSheetFile *parent(void) { return m_parent; }
|
2011-05-12 22:57:08 +02:00
|
|
|
double startIndex(void) { return m_startIndex; }
|
2011-05-14 15:54:04 +02:00
|
|
|
double duration(void) { return m_duration; }
|
2013-10-13 20:50:12 +02:00
|
|
|
AudioFileModel_MetaInfo &metaInfo(void) { return m_metaInfo; }
|
|
|
|
|
|
|
|
//Setter
|
2011-05-12 22:57:08 +02:00
|
|
|
void setStartIndex(double startIndex) { m_startIndex = startIndex; }
|
2011-05-14 15:54:04 +02:00
|
|
|
void setDuration(double duration) { m_duration = duration; }
|
2013-10-13 20:50:12 +02:00
|
|
|
|
|
|
|
//Misc
|
|
|
|
virtual bool isValid(void) { return !(_isnan(m_startIndex) || (m_metaInfo.position() == 0)); }
|
2011-05-12 22:57:08 +02:00
|
|
|
virtual const char* type(void) { return "CueSheetTrack"; }
|
2013-10-13 20:50:12 +02:00
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
private:
|
|
|
|
double m_startIndex;
|
2011-05-14 15:54:04 +02:00
|
|
|
double m_duration;
|
2013-10-13 20:50:12 +02:00
|
|
|
AudioFileModel_MetaInfo m_metaInfo;
|
|
|
|
CueSheetFile *const m_parent;
|
2011-05-12 22:57:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CueSheetFile : public CueSheetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CueSheetFile(const QString &fileName) : m_fileName(fileName) {}
|
|
|
|
~CueSheetFile(void) { while(!m_tracks.isEmpty()) delete m_tracks.takeLast(); }
|
2013-10-13 20:50:12 +02:00
|
|
|
|
|
|
|
//Getter
|
2011-05-12 22:57:08 +02:00
|
|
|
QString fileName(void) { return m_fileName; }
|
|
|
|
CueSheetTrack *track(int index) { return m_tracks.at(index); }
|
|
|
|
int trackCount(void) { return m_tracks.count(); }
|
2013-10-13 20:50:12 +02:00
|
|
|
|
|
|
|
//Modifier
|
|
|
|
void addTrack(CueSheetTrack *track) { m_tracks.append(track); }
|
|
|
|
void clearTracks(void) { while(!m_tracks.isEmpty()) delete m_tracks.takeLast(); }
|
|
|
|
|
|
|
|
//Misc
|
2011-05-14 15:54:04 +02:00
|
|
|
virtual bool isValid(void) { return m_tracks.count() > 0; }
|
2011-05-12 22:57:08 +02:00
|
|
|
virtual const char* type(void) { return "CueSheetFile"; }
|
2013-10-13 20:50:12 +02:00
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
private:
|
|
|
|
const QString m_fileName;
|
|
|
|
QList<CueSheetTrack*> m_tracks;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor & Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutex CueSheetModel::m_mutex(QMutex::Recursive);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
CueSheetModel::CueSheetModel()
|
2011-05-15 15:14:33 +02:00
|
|
|
:
|
|
|
|
m_fileIcon(":/icons/music.png"),
|
|
|
|
m_trackIcon(":/icons/control_play_blue.png")
|
2011-05-12 22:57:08 +02:00
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
/*nothing to do*/
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CueSheetModel::~CueSheetModel(void)
|
|
|
|
{
|
|
|
|
while(!m_files.isEmpty()) delete m_files.takeLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Model Functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QModelIndex CueSheetModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
if(!parent.isValid())
|
|
|
|
{
|
2011-05-15 18:53:44 +02:00
|
|
|
return (row < m_files.count()) ? createIndex(row, column, m_files.at(row)) : QModelIndex();
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CueSheetItem *parentItem = static_cast<CueSheetItem*>(parent.internalPointer());
|
|
|
|
if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(parentItem))
|
|
|
|
{
|
2011-05-15 18:53:44 +02:00
|
|
|
return (row < filePtr->trackCount()) ? createIndex(row, column, filePtr->track(row)) : QModelIndex();
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CueSheetModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
2011-05-14 15:54:04 +02:00
|
|
|
return 4;
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CueSheetModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
if(!parent.isValid())
|
|
|
|
{
|
|
|
|
return m_files.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
CueSheetItem *parentItem = static_cast<CueSheetItem*>(parent.internalPointer());
|
|
|
|
if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(parentItem))
|
|
|
|
{
|
|
|
|
return filePtr->trackCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex CueSheetModel::parent(const QModelIndex &child) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
if(child.isValid())
|
|
|
|
{
|
|
|
|
CueSheetItem *childItem = static_cast<CueSheetItem*>(child.internalPointer());
|
|
|
|
if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(childItem))
|
|
|
|
{
|
|
|
|
return createIndex(m_files.indexOf(trackPtr->parent()), 0, trackPtr->parent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CueSheetModel::headerData (int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr("No.");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return tr("File / Track");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return tr("Index");
|
|
|
|
break;
|
2011-05-14 15:54:04 +02:00
|
|
|
case 3:
|
|
|
|
return tr("Duration");
|
|
|
|
break;
|
2011-05-12 22:57:08 +02:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CueSheetModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
|
|
|
|
if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item))
|
|
|
|
{
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return tr("File %1").arg(QString().sprintf("%02d", index.row() + 1)).append(" ");
|
|
|
|
break;
|
|
|
|
case 1:
|
2011-05-14 15:54:04 +02:00
|
|
|
return QFileInfo(filePtr->fileName()).fileName();
|
2011-05-12 22:57:08 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item))
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
const AudioFileModel_MetaInfo &trackInfo = trackPtr->metaInfo();
|
2011-05-12 22:57:08 +02:00
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case 0:
|
2013-10-13 20:50:12 +02:00
|
|
|
return tr("Track %1").arg(QString().sprintf("%02d", trackInfo.position())).append(" ");
|
2011-05-12 22:57:08 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-10-13 20:50:12 +02:00
|
|
|
if(!trackInfo.title().isEmpty() && !trackInfo.artist().isEmpty())
|
2011-05-12 22:57:08 +02:00
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
return QString("%1 - %2").arg(trackInfo.artist(), trackInfo.title());
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
2013-10-13 20:50:12 +02:00
|
|
|
else if(!trackInfo.title().isEmpty())
|
2011-05-12 22:57:08 +02:00
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
return QString("%1 - %2").arg(tr("Unknown Artist"), trackInfo.title());
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
2013-10-13 20:50:12 +02:00
|
|
|
else if(!trackInfo.artist().isEmpty())
|
2011-05-12 22:57:08 +02:00
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
return QString("%1 - %2").arg(trackInfo.artist(), tr("Unknown Title"));
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString("%1 - %2").arg(tr("Unknown Artist"), tr("Unknown Title"));
|
2011-05-12 22:57:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2011-05-13 02:44:20 +02:00
|
|
|
return indexToString(trackPtr->startIndex());
|
2011-05-12 22:57:08 +02:00
|
|
|
break;
|
2011-05-14 15:54:04 +02:00
|
|
|
case 3:
|
|
|
|
return indexToString(trackPtr->duration());
|
|
|
|
break;
|
2011-05-12 22:57:08 +02:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-14 18:34:34 +02:00
|
|
|
else if(role == Qt::ToolTipRole)
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
|
|
|
|
if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item))
|
|
|
|
{
|
|
|
|
return QDir::toNativeSeparators(filePtr->fileName());
|
|
|
|
}
|
|
|
|
else if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item))
|
|
|
|
{
|
|
|
|
return QDir::toNativeSeparators(trackPtr->parent()->fileName());
|
|
|
|
}
|
|
|
|
}
|
2011-05-15 15:14:33 +02:00
|
|
|
else if(role == Qt::DecorationRole)
|
|
|
|
{
|
|
|
|
if(index.column() == 0)
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
|
|
|
|
if(dynamic_cast<CueSheetFile*>(item))
|
|
|
|
{
|
|
|
|
return m_fileIcon;
|
|
|
|
}
|
|
|
|
else if(dynamic_cast<CueSheetTrack*>(item))
|
|
|
|
{
|
|
|
|
return m_trackIcon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-14 15:54:04 +02:00
|
|
|
else if(role == Qt::FontRole)
|
|
|
|
{
|
|
|
|
QFont font("Monospace");
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
if((index.column() == 1))
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
font.setBold(dynamic_cast<CueSheetFile*>(item) != NULL);
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
else if(role == Qt::ForegroundRole)
|
|
|
|
{
|
|
|
|
if((index.column() == 1))
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item))
|
|
|
|
{
|
2011-05-14 18:34:34 +02:00
|
|
|
return (QFileInfo(filePtr->fileName()).size() > 4) ? QColor("mediumblue") : QColor("darkred");
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((index.column() == 3))
|
|
|
|
{
|
|
|
|
CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer());
|
|
|
|
if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item))
|
|
|
|
{
|
|
|
|
if(trackPtr->duration() == std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
return QColor("dimgrey");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 22:57:08 +02:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CueSheetModel::clearData(void)
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-12 22:57:08 +02:00
|
|
|
beginResetModel();
|
|
|
|
while(!m_files.isEmpty()) delete m_files.takeLast();
|
|
|
|
endResetModel();
|
|
|
|
}
|
2011-05-13 02:44:20 +02:00
|
|
|
|
2011-05-14 18:34:34 +02:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// External API
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int CueSheetModel::getFileCount(void)
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
2011-05-14 18:34:34 +02:00
|
|
|
return m_files.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CueSheetModel::getFileName(int fileIndex)
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-14 18:34:34 +02:00
|
|
|
if(fileIndex < 0 || fileIndex >= m_files.count())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_files.at(fileIndex)->fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CueSheetModel::getTrackCount(int fileIndex)
|
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-14 18:34:34 +02:00
|
|
|
if(fileIndex < 0 || fileIndex >= m_files.count())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_files.at(fileIndex)->trackCount();
|
|
|
|
}
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
const AudioFileModel_MetaInfo *CueSheetModel::getTrackInfo(int fileIndex, int trackIndex)
|
2011-05-15 01:45:27 +02:00
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-15 01:45:27 +02:00
|
|
|
if(fileIndex >= 0 && fileIndex < m_files.count())
|
|
|
|
{
|
|
|
|
CueSheetFile *currentFile = m_files.at(fileIndex);
|
|
|
|
if(trackIndex >= 0 && trackIndex < currentFile->trackCount())
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
return ¤tFile->track(trackIndex)->metaInfo();
|
2011-05-15 01:45:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
return NULL;
|
2011-05-15 01:45:27 +02:00
|
|
|
}
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
bool CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration)
|
2011-05-14 18:34:34 +02:00
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
2011-05-14 18:34:34 +02:00
|
|
|
*startIndex = std::numeric_limits<double>::quiet_NaN();
|
|
|
|
*duration = std::numeric_limits<double>::quiet_NaN();
|
|
|
|
|
|
|
|
if(fileIndex >= 0 && fileIndex < m_files.count())
|
|
|
|
{
|
|
|
|
CueSheetFile *currentFile = m_files.at(fileIndex);
|
|
|
|
if(trackIndex >= 0 && trackIndex < currentFile->trackCount())
|
|
|
|
{
|
|
|
|
CueSheetTrack *currentTrack = currentFile->track(trackIndex);
|
|
|
|
*startIndex = currentTrack->startIndex();
|
|
|
|
*duration = currentTrack->duration();
|
2013-10-13 20:50:12 +02:00
|
|
|
return true;
|
2011-05-14 18:34:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
return false;
|
2011-05-15 01:45:27 +02:00
|
|
|
}
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
const AudioFileModel_MetaInfo *CueSheetModel::getAlbumInfo(void)
|
2011-05-15 01:45:27 +02:00
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
2013-10-13 20:50:12 +02:00
|
|
|
return &m_albumInfo;
|
2011-05-15 01:45:27 +02:00
|
|
|
}
|
|
|
|
|
2011-05-13 02:44:20 +02:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Cue Sheet Parser
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2011-12-10 17:06:31 +01:00
|
|
|
int CueSheetModel::loadCueSheet(const QString &cueFileName, QCoreApplication *application, QTextCodec *forceCodec)
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
2011-05-16 18:05:50 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
2011-12-10 23:12:47 +01:00
|
|
|
const QTextCodec *codec = (forceCodec != NULL) ? forceCodec : QTextCodec::codecForName("System");
|
2011-05-16 18:05:50 +02:00
|
|
|
|
2011-05-13 02:44:20 +02:00
|
|
|
QFile cueFile(cueFileName);
|
|
|
|
if(!cueFile.open(QIODevice::ReadOnly))
|
|
|
|
{
|
2011-05-14 15:54:04 +02:00
|
|
|
return ErrorIOFailure;
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clearData();
|
|
|
|
|
|
|
|
beginResetModel();
|
2011-12-10 17:06:31 +01:00
|
|
|
int iResult = parseCueFile(cueFile, QDir(QFileInfo(cueFile).canonicalPath()), application, codec);
|
2011-05-13 02:44:20 +02:00
|
|
|
endResetModel();
|
|
|
|
|
|
|
|
return iResult;
|
|
|
|
}
|
|
|
|
|
2011-12-10 17:06:31 +01:00
|
|
|
int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplication *application, const QTextCodec *codec)
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
2011-12-13 23:33:21 +01:00
|
|
|
cueFile.reset();
|
2011-05-13 13:17:21 +02:00
|
|
|
qDebug("\n[Cue Sheet Import]");
|
2011-12-10 17:06:31 +01:00
|
|
|
bool bForceLatin1 = false;
|
2011-05-13 02:44:20 +02:00
|
|
|
|
2011-05-13 13:17:21 +02:00
|
|
|
//Reject very large files, as parsing might take until forever
|
|
|
|
if(cueFile.size() >= 10485760i64)
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
2011-05-13 13:17:21 +02:00
|
|
|
qWarning("File is very big. Probably not a Cue Sheet. Rejecting...");
|
|
|
|
return 2;
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
|
2011-12-08 14:46:11 +01:00
|
|
|
//Test selected Codepage for decoding errors
|
2011-12-10 17:06:31 +01:00
|
|
|
qDebug("Character encoding is: %s.", codec->name().constData());
|
|
|
|
const QString replacementSymbol = QString(QChar(QChar::ReplacementCharacter));
|
|
|
|
QByteArray testData = cueFile.peek(1048576);
|
|
|
|
if((!testData.isEmpty()) && codec->toUnicode(testData.constData(), testData.size()).contains(replacementSymbol))
|
2011-12-08 14:46:11 +01:00
|
|
|
{
|
2011-12-13 23:33:21 +01:00
|
|
|
qWarning("Decoding error using selected codepage (%s). Enforcing Latin-1.", codec->name().constData());
|
2011-12-10 17:06:31 +01:00
|
|
|
bForceLatin1 = true;
|
2011-12-08 14:46:11 +01:00
|
|
|
}
|
2011-12-10 17:06:31 +01:00
|
|
|
testData.clear();
|
2011-12-08 14:46:11 +01:00
|
|
|
|
2011-12-13 23:33:21 +01:00
|
|
|
//Init text stream
|
|
|
|
QTextStream cueStream(&cueFile);
|
|
|
|
cueStream.setAutoDetectUnicode(false);
|
|
|
|
cueStream.setCodec(bForceLatin1 ? "latin1" : codec->name());
|
|
|
|
cueStream.seek(0i64);
|
|
|
|
|
2011-12-10 17:06:31 +01:00
|
|
|
//Create regular expressions
|
2011-09-24 00:15:50 +02:00
|
|
|
QRegExp rxFile("^FILE\\s+(\"[^\"]+\"|\\S+)\\s+(\\w+)$", Qt::CaseInsensitive);
|
2011-05-13 02:44:20 +02:00
|
|
|
QRegExp rxTrack("^TRACK\\s+(\\d+)\\s(\\w+)$", Qt::CaseInsensitive);
|
|
|
|
QRegExp rxIndex("^INDEX\\s+(\\d+)\\s+([0-9:]+)$", Qt::CaseInsensitive);
|
2011-09-24 00:15:50 +02:00
|
|
|
QRegExp rxTitle("^TITLE\\s+(\"[^\"]+\"|\\S+)$", Qt::CaseInsensitive);
|
|
|
|
QRegExp rxPerformer("^PERFORMER\\s+(\"[^\"]+\"|\\S+)$", Qt::CaseInsensitive);
|
|
|
|
QRegExp rxGenre("^REM\\s+GENRE\\s+(\"[^\"]+\"|\\S+)$", Qt::CaseInsensitive);
|
2011-09-23 21:30:55 +02:00
|
|
|
QRegExp rxYear("^REM\\s+DATE\\s+(\\d+)$", Qt::CaseInsensitive);
|
2011-05-13 02:44:20 +02:00
|
|
|
|
|
|
|
bool bPreamble = true;
|
|
|
|
bool bUnsupportedTrack = false;
|
|
|
|
|
2011-05-13 13:17:21 +02:00
|
|
|
CueSheetFile *currentFile = NULL;
|
|
|
|
CueSheetTrack *currentTrack = NULL;
|
|
|
|
|
2013-10-13 20:50:12 +02:00
|
|
|
m_albumInfo.reset();
|
2011-05-13 02:44:20 +02:00
|
|
|
|
|
|
|
//Loop over the Cue Sheet until all lines were processed
|
2011-05-14 18:34:34 +02:00
|
|
|
for(int lines = 0; lines < INT_MAX; lines++)
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
2011-05-13 13:17:21 +02:00
|
|
|
if(application)
|
|
|
|
{
|
|
|
|
application->processEvents();
|
2014-11-30 21:32:23 +01:00
|
|
|
if(lines < 128) MUtils::OS::sleep_ms(10);
|
2011-05-13 13:17:21 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:21 +01:00
|
|
|
if(cueStream.atEnd())
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
|
|
|
qDebug("End of Cue Sheet file.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:21 +01:00
|
|
|
QString line = cueStream.readLine().trimmed();
|
2011-05-13 02:44:20 +02:00
|
|
|
|
|
|
|
/* --- FILE --- */
|
|
|
|
if(rxFile.indexIn(line) >= 0)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d File: <%s> <%s>", lines, MUTILS_UTF8(rxFile.cap(1)), MUTILS_UTF8(rxFile.cap(2)));
|
2011-05-13 02:44:20 +02:00
|
|
|
if(currentFile)
|
|
|
|
{
|
|
|
|
if(currentTrack)
|
|
|
|
{
|
|
|
|
if(currentTrack->isValid())
|
|
|
|
{
|
|
|
|
currentFile->addTrack(currentTrack);
|
|
|
|
currentTrack = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentTrack);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 15:54:04 +02:00
|
|
|
if(currentFile->isValid())
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
|
|
|
m_files.append(currentFile);
|
|
|
|
currentFile = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentFile);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-13 13:17:21 +02:00
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentTrack);
|
2011-05-13 13:17:21 +02:00
|
|
|
}
|
2011-05-13 02:44:20 +02:00
|
|
|
if(!rxFile.cap(2).compare("WAVE", Qt::CaseInsensitive) || !rxFile.cap(2).compare("MP3", Qt::CaseInsensitive) || !rxFile.cap(2).compare("AIFF", Qt::CaseInsensitive))
|
|
|
|
{
|
2011-09-24 00:15:50 +02:00
|
|
|
currentFile = new CueSheetFile(baseDir.absoluteFilePath(UNQUOTE(rxFile.cap(1))));
|
2011-05-14 18:34:34 +02:00
|
|
|
qDebug("%03d File path: <%s>", lines, currentFile->fileName().toUtf8().constData());
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bUnsupportedTrack = true;
|
2014-11-25 02:14:42 +01:00
|
|
|
qWarning("%03d Skipping unsupported file of type '%s'.", lines, MUTILS_UTF8(rxFile.cap(2)));
|
2011-05-13 02:44:20 +02:00
|
|
|
currentFile = NULL;
|
|
|
|
}
|
|
|
|
bPreamble = false;
|
|
|
|
currentTrack = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- TRACK --- */
|
|
|
|
if(rxTrack.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(currentFile)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Track: <%s> <%s>", lines, MUTILS_UTF8(rxTrack.cap(1)), MUTILS_UTF8(rxTrack.cap(2)));
|
2011-05-13 02:44:20 +02:00
|
|
|
if(currentTrack)
|
|
|
|
{
|
|
|
|
if(currentTrack->isValid())
|
|
|
|
{
|
|
|
|
currentFile->addTrack(currentTrack);
|
|
|
|
currentTrack = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentTrack);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!rxTrack.cap(2).compare("AUDIO", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
currentTrack = new CueSheetTrack(currentFile, rxTrack.cap(1).toInt());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bUnsupportedTrack = true;
|
2014-11-25 02:14:42 +01:00
|
|
|
qWarning("%03d Skipping unsupported track of type '%s'.", lines, MUTILS_UTF8(rxTrack.cap(2)));
|
2011-05-13 02:44:20 +02:00
|
|
|
currentTrack = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentTrack);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
bPreamble = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- INDEX --- */
|
|
|
|
if(rxIndex.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(currentFile && currentTrack)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Index: <%s> <%s>", lines, MUTILS_UTF8(rxIndex.cap(1)), MUTILS_UTF8(rxIndex.cap(2)));
|
2011-05-13 02:44:20 +02:00
|
|
|
if(rxIndex.cap(1).toInt() == 1)
|
|
|
|
{
|
|
|
|
currentTrack->setStartIndex(parseTimeIndex(rxIndex.cap(2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- TITLE --- */
|
|
|
|
if(rxTitle.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(bPreamble)
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
m_albumInfo.setAlbum(UNQUOTE(rxTitle.cap(1)).simplified());
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
else if(currentFile && currentTrack)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Title: <%s>", lines, MUTILS_UTF8(rxTitle.cap(1)));
|
2013-10-13 20:50:12 +02:00
|
|
|
currentTrack->metaInfo().setTitle(UNQUOTE(rxTitle.cap(1)).simplified());
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- PERFORMER --- */
|
|
|
|
if(rxPerformer.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(bPreamble)
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
m_albumInfo.setArtist(UNQUOTE(rxPerformer.cap(1)).simplified());
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
else if(currentFile && currentTrack)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Title: <%s>", lines, MUTILS_UTF8(rxPerformer.cap(1)));
|
2013-10-13 20:50:12 +02:00
|
|
|
currentTrack->metaInfo().setArtist(UNQUOTE(rxPerformer.cap(1)).simplified());
|
2011-09-23 21:30:55 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- GENRE --- */
|
|
|
|
if(rxGenre.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(bPreamble)
|
|
|
|
{
|
2011-09-24 00:15:50 +02:00
|
|
|
QString temp = UNQUOTE(rxGenre.cap(1)).simplified();
|
2011-09-23 21:30:55 +02:00
|
|
|
for(int i = 0; g_lamexp_generes[i]; i++)
|
|
|
|
{
|
|
|
|
if(temp.compare(g_lamexp_generes[i], Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
m_albumInfo.setGenre(QString(g_lamexp_generes[i]));
|
2011-09-23 21:30:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(currentFile && currentTrack)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Genre: <%s>", lines, MUTILS_UTF8(rxGenre.cap(1)));
|
2011-09-24 00:15:50 +02:00
|
|
|
QString temp = UNQUOTE(rxGenre.cap(1).simplified());
|
2011-09-23 21:30:55 +02:00
|
|
|
for(int i = 0; g_lamexp_generes[i]; i++)
|
|
|
|
{
|
|
|
|
if(temp.compare(g_lamexp_generes[i], Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
currentTrack->metaInfo().setGenre(QString(g_lamexp_generes[i]));
|
2011-09-23 21:30:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- YEAR --- */
|
|
|
|
if(rxYear.indexIn(line) >= 0)
|
|
|
|
{
|
|
|
|
if(bPreamble)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
unsigned int temp = rxYear.cap(1).toUInt(&ok);
|
2013-10-13 20:50:12 +02:00
|
|
|
if(ok) m_albumInfo.setYear(temp);
|
2011-09-23 21:30:55 +02:00
|
|
|
}
|
|
|
|
else if(currentFile && currentTrack)
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
qDebug("%03d Year: <%s>", lines, MUTILS_UTF8(rxPerformer.cap(1)));
|
2011-09-23 21:30:55 +02:00
|
|
|
bool ok = false;
|
|
|
|
unsigned int temp = rxYear.cap(1).toUInt(&ok);
|
2013-10-13 20:50:12 +02:00
|
|
|
if(ok) currentTrack->metaInfo().setYear(temp);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:54:04 +02:00
|
|
|
//Append the very last track/file that is still pending
|
2011-05-13 02:44:20 +02:00
|
|
|
if(currentFile)
|
|
|
|
{
|
|
|
|
if(currentTrack)
|
|
|
|
{
|
|
|
|
if(currentTrack->isValid())
|
|
|
|
{
|
|
|
|
currentFile->addTrack(currentTrack);
|
|
|
|
currentTrack = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentTrack);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 15:54:04 +02:00
|
|
|
if(currentFile->isValid())
|
2011-05-13 02:44:20 +02:00
|
|
|
{
|
|
|
|
m_files.append(currentFile);
|
|
|
|
currentFile = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(currentFile);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:54:04 +02:00
|
|
|
//Finally calculate duration of each track
|
|
|
|
int nFiles = m_files.count();
|
|
|
|
for(int i = 0; i < nFiles; i++)
|
|
|
|
{
|
|
|
|
if(application)
|
|
|
|
{
|
|
|
|
application->processEvents();
|
2014-11-30 21:32:23 +01:00
|
|
|
MUtils::OS::sleep_ms(10);
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CueSheetFile *currentFile = m_files.at(i);
|
|
|
|
int nTracks = currentFile->trackCount();
|
|
|
|
if(nTracks > 1)
|
|
|
|
{
|
|
|
|
for(int j = 1; j < nTracks; j++)
|
|
|
|
{
|
|
|
|
CueSheetTrack *currentTrack = currentFile->track(j);
|
|
|
|
CueSheetTrack *previousTrack = currentFile->track(j-1);
|
|
|
|
double duration = currentTrack->startIndex() - previousTrack->startIndex();
|
2011-11-08 15:12:31 +01:00
|
|
|
previousTrack->setDuration(qMax(0.0, duration));
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Sanity check of track numbers
|
|
|
|
if(nFiles > 0)
|
|
|
|
{
|
2011-09-24 00:15:50 +02:00
|
|
|
bool hasTracks = false;
|
2011-05-15 01:45:27 +02:00
|
|
|
int previousTrackNo = -1;
|
2011-05-14 15:54:04 +02:00
|
|
|
bool trackNo[100];
|
|
|
|
for(int i = 0; i < 100; i++)
|
|
|
|
{
|
|
|
|
trackNo[i] = false;
|
|
|
|
}
|
2011-09-24 00:15:50 +02:00
|
|
|
|
2011-05-14 15:54:04 +02:00
|
|
|
for(int i = 0; i < nFiles; i++)
|
|
|
|
{
|
|
|
|
if(application)
|
|
|
|
{
|
|
|
|
application->processEvents();
|
2014-11-30 21:32:23 +01:00
|
|
|
MUtils::OS::sleep_ms(10);
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
CueSheetFile *currentFile = m_files.at(i);
|
|
|
|
int nTracks = currentFile->trackCount();
|
|
|
|
if(nTracks > 1)
|
|
|
|
{
|
2011-05-15 01:45:27 +02:00
|
|
|
for(int j = 0; j < nTracks; j++)
|
2011-05-14 15:54:04 +02:00
|
|
|
{
|
2013-10-13 20:50:12 +02:00
|
|
|
int currentTrackNo = currentFile->track(j)->metaInfo().position();
|
2011-05-14 15:54:04 +02:00
|
|
|
if(currentTrackNo > 99)
|
|
|
|
{
|
|
|
|
qWarning("Track #%02d is invalid (maximum is 99), Cue Sheet is inconsistent!", currentTrackNo);
|
|
|
|
return ErrorInconsistent;
|
|
|
|
}
|
2011-05-15 01:45:27 +02:00
|
|
|
if(currentTrackNo <= previousTrackNo)
|
|
|
|
{
|
2011-09-24 00:15:50 +02:00
|
|
|
qWarning("Non-increasing track numbers (%02d -> %02d), Cue Sheet is inconsistent!", previousTrackNo, currentTrackNo);
|
2011-05-15 01:45:27 +02:00
|
|
|
return ErrorInconsistent;
|
|
|
|
}
|
2011-05-14 15:54:04 +02:00
|
|
|
if(trackNo[currentTrackNo])
|
|
|
|
{
|
|
|
|
qWarning("Track #%02d exists multiple times, Cue Sheet is inconsistent!", currentTrackNo);
|
|
|
|
return ErrorInconsistent;
|
|
|
|
}
|
|
|
|
trackNo[currentTrackNo] = true;
|
2011-05-15 01:45:27 +02:00
|
|
|
previousTrackNo = currentTrackNo;
|
2011-09-24 00:15:50 +02:00
|
|
|
hasTracks = true;
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 00:15:50 +02:00
|
|
|
|
|
|
|
if(!hasTracks)
|
|
|
|
{
|
|
|
|
qWarning("Could not find at least one valid track in the Cue Sheet!");
|
|
|
|
return ErrorInconsistent;
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:54:04 +02:00
|
|
|
return ErrorSuccess;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 00:15:50 +02:00
|
|
|
qWarning("Could not find at least one valid input file in the Cue Sheet!");
|
2011-05-14 15:54:04 +02:00
|
|
|
return bUnsupportedTrack ? ErrorUnsupported : ErrorBadFile;
|
|
|
|
}
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double CueSheetModel::parseTimeIndex(const QString &index)
|
|
|
|
{
|
|
|
|
QRegExp rxTimeIndex("\\s*(\\d+)\\s*:\\s*(\\d+)\\s*:\\s*(\\d+)\\s*");
|
|
|
|
|
|
|
|
if(rxTimeIndex.indexIn(index) >= 0)
|
|
|
|
{
|
|
|
|
int min, sec, frm;
|
|
|
|
bool minOK, secOK, frmOK;
|
|
|
|
|
|
|
|
min = rxTimeIndex.cap(1).toInt(&minOK);
|
|
|
|
sec = rxTimeIndex.cap(2).toInt(&secOK);
|
|
|
|
frm = rxTimeIndex.cap(3).toInt(&frmOK);
|
|
|
|
|
|
|
|
if(minOK && secOK && frmOK)
|
|
|
|
{
|
2011-05-17 20:06:01 +02:00
|
|
|
return static_cast<double>(60 * min) + static_cast<double>(sec) + (static_cast<double>(frm) / 75.0);
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
qWarning(" Bad time index: '%s'", MUTILS_UTF8(index));
|
2011-05-13 02:44:20 +02:00
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CueSheetModel::indexToString(const double index) const
|
|
|
|
{
|
2011-05-18 00:36:51 +02:00
|
|
|
if(!_finite(index) || (index < 0.0) || (index > 86400.0))
|
2011-05-14 15:54:04 +02:00
|
|
|
{
|
2011-05-17 20:06:01 +02:00
|
|
|
return QString("??:??.???");
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
2011-05-17 20:06:01 +02:00
|
|
|
|
2011-05-18 00:36:51 +02:00
|
|
|
QTime time = QTime().addMSecs(static_cast<int>(floor(0.5 + (index * 1000.0))));
|
2011-05-17 20:06:01 +02:00
|
|
|
|
2011-05-18 00:36:51 +02:00
|
|
|
if(time.minute() < 100)
|
2011-05-14 15:54:04 +02:00
|
|
|
{
|
2011-05-18 00:36:51 +02:00
|
|
|
return time.toString("mm:ss.zzz");
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-17 20:06:01 +02:00
|
|
|
return QString("99:99.999");
|
2011-05-14 15:54:04 +02:00
|
|
|
}
|
2011-05-13 02:44:20 +02:00
|
|
|
}
|