Some improvements and code-refactoring in the CueSplitter class.

This commit is contained in:
LoRd_MuldeR 2020-04-19 20:00:43 +02:00
parent 3124ed4f7b
commit 66961fc32f
3 changed files with 71 additions and 57 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 3 #define VER_LAMEXP_PATCH 3
#define VER_LAMEXP_BUILD 2256 #define VER_LAMEXP_BUILD 2258
#define VER_LAMEXP_CONFG 2188 #define VER_LAMEXP_CONFG 2188
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -423,18 +423,18 @@ void CueImportDialog::splitFiles(void)
{ {
QString baseName = QFileInfo(m_cueFileName).completeBaseName().replace(".", " ").simplified(); QString baseName = QFileInfo(m_cueFileName).completeBaseName().replace(".", " ").simplified();
WorkingBanner *progress = new WorkingBanner(this); QScopedPointer<WorkingBanner> progress(new WorkingBanner(this));
CueSplitter *splitter = new CueSplitter(m_outputDir, baseName, m_model, m_fileInfo); QScopedPointer<CueSplitter> splitter(new CueSplitter(m_outputDir, baseName, m_model, m_fileInfo));
connect(splitter, SIGNAL(fileSelected(QString)), progress, SLOT(setText(QString)), Qt::QueuedConnection); connect(splitter.data(), SIGNAL(fileSelected(QString)), progress.data(), SLOT(setText(QString)), Qt::QueuedConnection);
connect(splitter, SIGNAL(fileSplit(AudioFileModel)), m_fileList, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection); connect(splitter.data(), SIGNAL(fileSplit(AudioFileModel)), m_fileList, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
connect(splitter, SIGNAL(progressValChanged(unsigned int)), progress, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection); connect(splitter.data(), SIGNAL(progressValChanged(unsigned int)), progress.data(), SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
connect(splitter, SIGNAL(progressMaxChanged(unsigned int)), progress, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection); connect(splitter.data(), SIGNAL(progressMaxChanged(unsigned int)), progress.data(), SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
connect(progress, SIGNAL(userAbort()), splitter, SLOT(abortProcess()), Qt::DirectConnection); connect(progress.data(), SIGNAL(userAbort()), splitter.data(), SLOT(abortProcess()), Qt::DirectConnection);
DecoderRegistry::configureDecoders(m_settings); DecoderRegistry::configureDecoders(m_settings);
progress->show(tr("Splitting file(s), please wait..."), splitter); progress->show(tr("Splitting file(s), please wait..."), splitter.data());
progress->close(); progress->close();
if(splitter->getAborted()) if(splitter->getAborted())
@ -450,7 +450,4 @@ void CueImportDialog::splitFiles(void)
QString text = QString("<nobr>%1 %2</nobr>").arg(tr("Imported %n track(s) from the Cue Sheet.", "", splitter->getTracksSuccess()), tr("Skipped %n track(s).", "", splitter->getTracksSkipped())); QString text = QString("<nobr>%1 %2</nobr>").arg(tr("Imported %n track(s) from the Cue Sheet.", "", splitter->getTracksSuccess()), tr("Skipped %n track(s).", "", splitter->getTracksSkipped()));
QMessageBox::information(this, tr("Cue Sheet Completed"), text); QMessageBox::information(this, tr("Cue Sheet Completed"), text);
} }
MUTILS_DELETE(splitter);
MUTILS_DELETE(progress);
} }

View File

@ -305,6 +305,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
QProcess process; QProcess process;
MUtils::init_process(process, m_outputDir); MUtils::init_process(process, m_outputDir);
qDebug("SoX args: \"%s\"", MUTILS_UTF8(args.join(QLatin1String("\", \""))));
process.start(m_soxBin, args); process.start(m_soxBin, args);
if(!process.waitForStarted()) if(!process.waitForStarted())
@ -335,59 +336,74 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
while(process.bytesAvailable() > 0) while(process.bytesAvailable() > 0)
{ {
QByteArray line = process.readLine(); QByteArray line = process.readLine();
QString text = QString::fromUtf8(line.constData()).simplified(); if (line.size() > 0)
if(rxProgress.lastIndexIn(text) >= 0)
{ {
bool ok = false; QString text = QString::fromUtf8(line.constData()).simplified();
int progress = rxProgress.cap(1).toInt(&ok); if (!text.isEmpty())
if(ok)
{ {
const int newProgress = baseProgress + qRound(static_cast<double>(qBound(0, progress, 100)) / 10.0); if (rxProgress.lastIndexIn(text) >= 0)
if(newProgress > prevProgress)
{ {
emit progressValChanged(newProgress); int progress;
prevProgress = newProgress; if (MUtils::regexp_parse_int32(rxProgress, progress))
{
const int newProgress = baseProgress + qRound(static_cast<double>(qBound(0, progress, 100)) / 10.0);
if (newProgress > prevProgress)
{
emit progressValChanged(newProgress);
prevProgress = newProgress;
}
}
} }
} else if (rxChannels.lastIndexIn(text) >= 0)
}
else if(rxChannels.lastIndexIn(text) >= 0)
{
bool ok = false;
unsigned int channels = rxChannels.cap(1).toUInt(&ok);
if(ok) outFileInfo.techInfo().setAudioChannels(channels);
}
else if(rxSamplerate.lastIndexIn(text) >= 0)
{
bool ok = false;
unsigned int samplerate = rxSamplerate.cap(1).toUInt(&ok);
if(ok) outFileInfo.techInfo().setAudioSamplerate(samplerate);
}
else if(rxPrecision.lastIndexIn(text) >= 0)
{
bool ok = false;
unsigned int precision = rxPrecision.cap(1).toUInt(&ok);
if(ok) outFileInfo.techInfo().setAudioBitdepth(precision);
}
else if(rxDuration.lastIndexIn(text) >= 0)
{
bool ok1 = false, ok2 = false, ok3 = false;
unsigned int hh = rxDuration.cap(1).toUInt(&ok1);
unsigned int mm = rxDuration.cap(2).toUInt(&ok2);
unsigned int ss = rxDuration.cap(3).toUInt(&ok3);
if(ok1 && ok2 && ok3)
{
unsigned intputLen = (hh * 3600) + (mm * 60) + ss;
if(length == std::numeric_limits<double>::infinity())
{ {
qDebug("Duration updated from SoX info!"); unsigned int channels;
int duration = intputLen - static_cast<int>(floor(offset + 0.5)); if (MUtils::regexp_parse_uint32(rxChannels, channels))
if(duration < 0) qWarning("Track is out of bounds: Track offset exceeds input file duration!"); {
outFileInfo.techInfo().setDuration(qMax(0, duration)); outFileInfo.techInfo().setAudioChannels(channels);
}
}
else if (rxSamplerate.lastIndexIn(text) >= 0)
{
unsigned int samplerate;
if (MUtils::regexp_parse_uint32(rxSamplerate, samplerate))
{
outFileInfo.techInfo().setAudioSamplerate(samplerate);
}
}
else if (rxPrecision.lastIndexIn(text) >= 0)
{
unsigned int precision;
if (MUtils::regexp_parse_uint32(rxPrecision, precision))
{
outFileInfo.techInfo().setAudioBitdepth(precision);
}
}
else if (rxDuration.lastIndexIn(text) >= 0)
{
unsigned int duration[3U];
if (MUtils::regexp_parse_uint32(rxDuration, duration, 3U))
{
unsigned intputLen = (duration[0U] * 3600) + (duration[1U] * 60) + duration[2U];
if (length == std::numeric_limits<double>::infinity())
{
qDebug("Duration updated from SoX info!");
int duration = intputLen - static_cast<int>(floor(offset + 0.5));
if (duration < 0)
{
qWarning("Track is out of bounds: Track offset exceeds input file duration!");
}
outFileInfo.techInfo().setDuration(qMax(0, duration));
}
else
{
unsigned int trackEnd = static_cast<unsigned int>(floor(offset + 0.5)) + static_cast<unsigned int>(floor(length + 0.5));
if (trackEnd > intputLen) qWarning("Track is out of bounds: End of track exceeds input file duration!");
}
}
} }
else else
{ {
unsigned int trackEnd = static_cast<unsigned int>(floor(offset + 0.5)) + static_cast<unsigned int>(floor(length + 0.5)); qDebug("SoX line: %s", MUTILS_UTF8(text));
if(trackEnd > intputLen) qWarning("Track is out of bounds: End of track exceeds input file duration!");
} }
} }
} }
@ -401,6 +417,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
process.waitForFinished(-1); process.waitForFinished(-1);
} }
qDebug("SoX exit code: %d", process.exitCode());
if(process.exitCode() != EXIT_SUCCESS || QFileInfo(output).size() == 0) if(process.exitCode() != EXIT_SUCCESS || QFileInfo(output).size() == 0)
{ {
qWarning("Splitting has failed !!!"); qWarning("Splitting has failed !!!");