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_TYPE Alpha
#define VER_LAMEXP_PATCH 3
#define VER_LAMEXP_BUILD 2256
#define VER_LAMEXP_BUILD 2258
#define VER_LAMEXP_CONFG 2188
///////////////////////////////////////////////////////////////////////////////

View File

@ -423,18 +423,18 @@ void CueImportDialog::splitFiles(void)
{
QString baseName = QFileInfo(m_cueFileName).completeBaseName().replace(".", " ").simplified();
WorkingBanner *progress = new WorkingBanner(this);
CueSplitter *splitter = new CueSplitter(m_outputDir, baseName, m_model, m_fileInfo);
QScopedPointer<WorkingBanner> progress(new WorkingBanner(this));
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, 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, SIGNAL(progressMaxChanged(unsigned int)), progress, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
connect(progress, SIGNAL(userAbort()), splitter, SLOT(abortProcess()), Qt::DirectConnection);
connect(splitter.data(), SIGNAL(fileSelected(QString)), progress.data(), SLOT(setText(QString)), Qt::QueuedConnection);
connect(splitter.data(), SIGNAL(fileSplit(AudioFileModel)), m_fileList, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
connect(splitter.data(), SIGNAL(progressValChanged(unsigned int)), progress.data(), SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
connect(splitter.data(), SIGNAL(progressMaxChanged(unsigned int)), progress.data(), SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
connect(progress.data(), SIGNAL(userAbort()), splitter.data(), SLOT(abortProcess()), Qt::DirectConnection);
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();
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()));
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;
MUtils::init_process(process, m_outputDir);
qDebug("SoX args: \"%s\"", MUTILS_UTF8(args.join(QLatin1String("\", \""))));
process.start(m_soxBin, args);
if(!process.waitForStarted())
@ -335,12 +336,15 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
while(process.bytesAvailable() > 0)
{
QByteArray line = process.readLine();
if (line.size() > 0)
{
QString text = QString::fromUtf8(line.constData()).simplified();
if (!text.isEmpty())
{
if (rxProgress.lastIndexIn(text) >= 0)
{
bool ok = false;
int progress = rxProgress.cap(1).toInt(&ok);
if(ok)
int progress;
if (MUtils::regexp_parse_int32(rxProgress, progress))
{
const int newProgress = baseProgress + qRound(static_cast<double>(qBound(0, progress, 100)) / 10.0);
if (newProgress > prevProgress)
@ -352,36 +356,42 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
}
else if (rxChannels.lastIndexIn(text) >= 0)
{
bool ok = false;
unsigned int channels = rxChannels.cap(1).toUInt(&ok);
if(ok) outFileInfo.techInfo().setAudioChannels(channels);
unsigned int channels;
if (MUtils::regexp_parse_uint32(rxChannels, channels))
{
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);
unsigned int samplerate;
if (MUtils::regexp_parse_uint32(rxSamplerate, samplerate))
{
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);
unsigned int precision;
if (MUtils::regexp_parse_uint32(rxPrecision, precision))
{
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 int duration[3U];
if (MUtils::regexp_parse_uint32(rxDuration, duration, 3U))
{
unsigned intputLen = (hh * 3600) + (mm * 60) + ss;
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!");
if (duration < 0)
{
qWarning("Track is out of bounds: Track offset exceeds input file duration!");
}
outFileInfo.techInfo().setDuration(qMax(0, duration));
}
else
@ -391,6 +401,12 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
}
}
}
else
{
qDebug("SoX line: %s", MUTILS_UTF8(text));
}
}
}
}
}
@ -401,6 +417,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
process.waitForFinished(-1);
}
qDebug("SoX exit code: %d", process.exitCode());
if(process.exitCode() != EXIT_SUCCESS || QFileInfo(output).size() == 0)
{
qWarning("Splitting has failed !!!");