Improved precision of the indexToString() function. The Cue Sheet splitter should be able cut more precise now!

This commit is contained in:
LoRd_MuldeR 2011-05-17 20:06:01 +02:00
parent be4c94932c
commit 352bfd4864
3 changed files with 34 additions and 25 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 2
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 530
#define VER_LAMEXP_BUILD 532
///////////////////////////////////////////////////////////////////////////////
// Tools versions

View File

@ -786,7 +786,7 @@ double CueSheetModel::parseTimeIndex(const QString &index)
if(minOK && secOK && frmOK)
{
return static_cast<double>(60 * min) + static_cast<double>(sec) + ((1.0/75.0) * static_cast<double>(frm));
return static_cast<double>(60 * min) + static_cast<double>(sec) + (static_cast<double>(frm) / 75.0);
}
}
@ -796,21 +796,25 @@ double CueSheetModel::parseTimeIndex(const QString &index)
QString CueSheetModel::indexToString(const double index) const
{
if(index == std::numeric_limits<double>::quiet_NaN())
if(!_finite(index) || (index < 0.0))
{
return QString("<-NaN!->");
return QString("??:??.???");
}
else if(index == std::numeric_limits<double>::infinity() || index < 0.0)
unsigned int temp = static_cast<unsigned int>(floor(0.5 + (index * 1000.0)));
unsigned int msec = temp % 1000;
unsigned int secs = temp / 1000;
unsigned int mins = secs / 60;
secs = secs % 60;
if(mins < 100)
{
return QString("??:??.??");
return QString().sprintf("%02u:%02u.%03u", mins, secs, msec);
}
else
{
int temp = static_cast<int>(floor(0.5 + (index * 100.0)));
int msec = temp % 100;
int secs = temp / 100;
return QString().sprintf("%02d:%02d.%02d", min(99, secs / 60), min(99, secs % 60), min(99, msec));
return QString("99:99.999");
}
}

View File

@ -224,8 +224,8 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
{
qDebug("[Track %02d]", trackNo);
qDebug("File: <%s>", file.toUtf8().constData());
qDebug("Offset: %f", offset);
qDebug("Length: %f", length);
qDebug("Offset: <%f> <%s>", offset, indexToString(offset).toLatin1().constData());
qDebug("Length: <%f> <%s>", length, indexToString(length).toLatin1().constData());
qDebug("Artist: <%s>", metaInfo.fileArtist().toUtf8().constData());
qDebug("Title: <%s>", metaInfo.fileName().toUtf8().constData());
@ -254,11 +254,11 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
args << QDir::toNativeSeparators(output);
//Add trim parameters, if needed
if(_finite(offset) || _finite(length))
if(_finite(offset))
{
args << "trim";
args << indexToString(offset);
if(_finite(length))
{
args << indexToString(length);
@ -384,23 +384,28 @@ QString CueSplitter::indexToString(const double index) const
{
return QString();
}
unsigned int temp = static_cast<unsigned int>(floor(0.5 + (index * 1000.0)));
int temp = static_cast<int>(floor(0.5 + (index * 1000.0)));
unsigned int msec = temp % 1000;
unsigned int secs = temp / 1000;
unsigned int mins = secs / 60;
unsigned int hour = mins / 60;
secs = secs % 60;
mins = mins % 60;
int msec = temp % 1000;
int secs = temp / 1000;
if(secs >= 3600)
if(hour > 0)
{
return QString().sprintf("%d:%02d:%02d.%03d", min(99, secs / 3600), min(59, (secs % 3600) / 60), min(59, (secs % 3600) % 60), min(99, msec));
return QString().sprintf("%u:%02u:%02u.%03u", hour, mins, secs, msec);
}
else if(secs >= 60)
else if(mins > 0)
{
return QString().sprintf("%d:%02d.%03d", min(99, secs / 60), min(59, secs % 60), min(99, msec));
return QString().sprintf("%u:%02u.%03u", mins, secs, msec);
}
else
{
return QString().sprintf("%d.%03d", min(59, secs % 60), min(99, msec));
return QString().sprintf("%u.%03u", secs, msec);
}
}