From 66961fc32f85aab9dced82b85a91abec21787603 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 19 Apr 2020 20:00:43 +0200 Subject: [PATCH] Some improvements and code-refactoring in the CueSplitter class. --- src/Config.h | 2 +- src/Dialog_CueImport.cpp | 19 +++---- src/Thread_CueSplitter.cpp | 107 +++++++++++++++++++++---------------- 3 files changed, 71 insertions(+), 57 deletions(-) diff --git a/src/Config.h b/src/Config.h index 6711fe51..72b0cb74 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index 3ed06413..195fe960 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -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 progress(new WorkingBanner(this)); + QScopedPointer 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("%1 %2").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); } diff --git a/src/Thread_CueSplitter.cpp b/src/Thread_CueSplitter.cpp index b4c972cf..fe7d81c7 100644 --- a/src/Thread_CueSplitter.cpp +++ b/src/Thread_CueSplitter.cpp @@ -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,59 +336,74 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); - QString text = QString::fromUtf8(line.constData()).simplified(); - if(rxProgress.lastIndexIn(text) >= 0) + if (line.size() > 0) { - bool ok = false; - int progress = rxProgress.cap(1).toInt(&ok); - if(ok) + QString text = QString::fromUtf8(line.constData()).simplified(); + if (!text.isEmpty()) { - const int newProgress = baseProgress + qRound(static_cast(qBound(0, progress, 100)) / 10.0); - if(newProgress > prevProgress) + if (rxProgress.lastIndexIn(text) >= 0) { - emit progressValChanged(newProgress); - prevProgress = newProgress; + int progress; + if (MUtils::regexp_parse_int32(rxProgress, progress)) + { + const int newProgress = baseProgress + qRound(static_cast(qBound(0, progress, 100)) / 10.0); + if (newProgress > prevProgress) + { + emit progressValChanged(newProgress); + prevProgress = newProgress; + } + } } - } - } - 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::infinity()) + else if (rxChannels.lastIndexIn(text) >= 0) { - qDebug("Duration updated from SoX info!"); - int duration = intputLen - static_cast(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)); + unsigned int channels; + if (MUtils::regexp_parse_uint32(rxChannels, channels)) + { + 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::infinity()) + { + qDebug("Duration updated from SoX info!"); + int duration = intputLen - static_cast(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(floor(offset + 0.5)) + static_cast(floor(length + 0.5)); + if (trackEnd > intputLen) qWarning("Track is out of bounds: End of track exceeds input file duration!"); + } + } } else { - unsigned int trackEnd = static_cast(floor(offset + 0.5)) + static_cast(floor(length + 0.5)); - if(trackEnd > intputLen) qWarning("Track is out of bounds: End of track exceeds input file duration!"); + 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 !!!");