From c47a13a494e9ca9069c97dcfe9f530ff014aa7ad Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 10 Dec 2017 22:21:42 +0100 Subject: [PATCH] Small tweak to progress updates. --- src/Decoder_AAC.cpp | 2 +- src/Decoder_AC3.cpp | 4 +--- src/Decoder_ADPCM.cpp | 2 +- src/Decoder_ALAC.cpp | 2 +- src/Decoder_Avisynth.cpp | 2 +- src/Decoder_FLAC.cpp | 2 +- src/Decoder_MAC.cpp | 2 +- src/Decoder_MP3.cpp | 2 +- src/Decoder_Musepack.cpp | 2 +- src/Decoder_Opus.cpp | 2 +- src/Decoder_Shorten.cpp | 49 +--------------------------------------- src/Decoder_TTA.cpp | 2 +- src/Decoder_Vorbis.cpp | 2 +- src/Decoder_WMA.cpp | 2 +- src/Decoder_WavPack.cpp | 2 +- src/Encoder_AAC.cpp | 10 ++++---- src/Encoder_AAC_FDK.cpp | 2 +- src/Encoder_AAC_FHG.cpp | 2 +- src/Encoder_AAC_QAAC.cpp | 2 +- src/Encoder_AC3.cpp | 2 +- src/Encoder_DCA.cpp | 2 +- src/Encoder_FLAC.cpp | 2 +- src/Encoder_MAC.cpp | 2 +- src/Encoder_MP3.cpp | 2 +- src/Encoder_Opus.cpp | 2 +- src/Encoder_Vorbis.cpp | 2 +- 26 files changed, 30 insertions(+), 79 deletions(-) diff --git a/src/Decoder_AAC.cpp b/src/Decoder_AAC.cpp index 6a653952..0daa84d0 100644 --- a/src/Decoder_AAC.cpp +++ b/src/Decoder_AAC.cpp @@ -73,7 +73,7 @@ bool AACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_AC3.cpp b/src/Decoder_AC3.cpp index 51bffa5d..03a17def 100644 --- a/src/Decoder_AC3.cpp +++ b/src/Decoder_AC3.cpp @@ -67,15 +67,13 @@ bool AC3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA { if (regExp.lastIndexIn(text) >= 0) { - qWarning("Found! [\"%s\"]", MUTILS_UTF8(regExp.cap(1))); qint32 newProgress; if (MUtils::regexp_parse_int32(regExp, newProgress)) { - qWarning("newProgress: %d", newProgress); if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_ADPCM.cpp b/src/Decoder_ADPCM.cpp index a1487fc1..fada5915 100644 --- a/src/Decoder_ADPCM.cpp +++ b/src/Decoder_ADPCM.cpp @@ -75,7 +75,7 @@ bool ADPCMDecoder::decode(const QString &sourceFile, const QString &outputFile, if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_ALAC.cpp b/src/Decoder_ALAC.cpp index 19523d28..093698f4 100644 --- a/src/Decoder_ALAC.cpp +++ b/src/Decoder_ALAC.cpp @@ -76,7 +76,7 @@ bool ALACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_Avisynth.cpp b/src/Decoder_Avisynth.cpp index ee119ccd..05c7b347 100644 --- a/src/Decoder_Avisynth.cpp +++ b/src/Decoder_Avisynth.cpp @@ -74,7 +74,7 @@ bool AvisynthDecoder::decode(const QString &sourceFile, const QString &outputFil if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_FLAC.cpp b/src/Decoder_FLAC.cpp index a426a20f..bae418c0 100644 --- a/src/Decoder_FLAC.cpp +++ b/src/Decoder_FLAC.cpp @@ -74,7 +74,7 @@ bool FLACDecoder::decode(const QString &sourceFile, const QString &outputFile, Q if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_MAC.cpp b/src/Decoder_MAC.cpp index 02135ecf..9d81d22c 100644 --- a/src/Decoder_MAC.cpp +++ b/src/Decoder_MAC.cpp @@ -74,7 +74,7 @@ bool MACDecoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_MP3.cpp b/src/Decoder_MP3.cpp index 220a1cde..13d03876 100644 --- a/src/Decoder_MP3.cpp +++ b/src/Decoder_MP3.cpp @@ -83,7 +83,7 @@ bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } } diff --git a/src/Decoder_Musepack.cpp b/src/Decoder_Musepack.cpp index c11ee975..f994ef8e 100644 --- a/src/Decoder_Musepack.cpp +++ b/src/Decoder_Musepack.cpp @@ -75,7 +75,7 @@ bool MusepackDecoder::decode(const QString &sourceFile, const QString &outputFil if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_Opus.cpp b/src/Decoder_Opus.cpp index 73a9e9ef..4256ae12 100644 --- a/src/Decoder_Opus.cpp +++ b/src/Decoder_Opus.cpp @@ -81,7 +81,7 @@ bool OpusDecoder::decode(const QString &sourceFile, const QString &outputFile, Q if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_Shorten.cpp b/src/Decoder_Shorten.cpp index c7f616e4..65cc7471 100644 --- a/src/Decoder_Shorten.cpp +++ b/src/Decoder_Shorten.cpp @@ -62,57 +62,10 @@ bool ShortenDecoder::decode(const QString &sourceFile, const QString &outputFile return false; } - bool bTimeout = false; - bool bAborted = false; - //The Shorten Decoder doesn't actually send any status updates :-[ emit statusUpdated(20 + (QUuid::createUuid().data1 % 80)); - while(process.state() != QProcess::NotRunning) - { - if(checkFlag(abortFlag)) - { - process.kill(); - bAborted = true; - emit messageLogged("\nABORTED BY USER !!!"); - break; - } - process.waitForReadyRead(m_processTimeoutInterval); - if(!process.bytesAvailable() && process.state() == QProcess::Running) - { - process.kill(); - qWarning("Shorten process timed out <-- killing!"); - emit messageLogged("\nPROCESS TIMEOUT !!!"); - bTimeout = true; - break; - } - while(process.bytesAvailable() > 0) - { - QByteArray line = process.readLine(); - QString text = QString::fromUtf8(line.constData()).simplified(); - if(!text.isEmpty()) - { - emit messageLogged(text); - } - } - } - - process.waitForFinished(); - if(process.state() != QProcess::NotRunning) - { - process.kill(); - process.waitForFinished(-1); - } - - emit statusUpdated(100); - emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); - - if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) - { - return false; - } - - return true; + return (awaitProcess(process, abortFlag) == RESULT_SUCCESS); } bool ShortenDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) diff --git a/src/Decoder_TTA.cpp b/src/Decoder_TTA.cpp index 8e4d3183..df6102df 100644 --- a/src/Decoder_TTA.cpp +++ b/src/Decoder_TTA.cpp @@ -75,7 +75,7 @@ bool TTADecoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_Vorbis.cpp b/src/Decoder_Vorbis.cpp index 78ea56d6..bd2588e8 100644 --- a/src/Decoder_Vorbis.cpp +++ b/src/Decoder_Vorbis.cpp @@ -73,7 +73,7 @@ bool VorbisDecoder::decode(const QString &sourceFile, const QString &outputFile, if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_WMA.cpp b/src/Decoder_WMA.cpp index aae6ef82..948c9ed7 100644 --- a/src/Decoder_WMA.cpp +++ b/src/Decoder_WMA.cpp @@ -75,7 +75,7 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Decoder_WavPack.cpp b/src/Decoder_WavPack.cpp index 81173a83..e07f75bd 100644 --- a/src/Decoder_WavPack.cpp +++ b/src/Decoder_WavPack.cpp @@ -74,7 +74,7 @@ bool WavPackDecoder::decode(const QString &sourceFile, const QString &outputFile if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_AAC.cpp b/src/Encoder_AAC.cpp index 37ed646d..a9386cde 100644 --- a/src/Encoder_AAC.cpp +++ b/src/Encoder_AAC.cpp @@ -210,7 +210,7 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo int prevProgress = -1; QRegExp regExp_sp(L1S("\\bprocessed\\s+(\\d+)\\s+seconds"), Qt::CaseInsensitive); - QRegExp regExp_mp(L1S("(\\w+)\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"), Qt::CaseInsensitive); + QRegExp regExp_mp(L1S("\\b(\\w+)\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"), Qt::CaseInsensitive); const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &duration, ®Exp_sp, ®Exp_mp](const QString &text) { @@ -220,11 +220,11 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if ((duration > 0) && MUtils::regexp_parse_int32(regExp_mp, timeElapsed, 2)) { const bool second_pass = (regExp_mp.cap(1).compare(L1S("second"), Qt::CaseInsensitive) == 0); - int newProgress = qRound((second_pass ? 50.0 : 0.0) + ((static_cast(timeElapsed) / static_cast(duration)) * 50.0)); + const int newProgress = qRound((second_pass ? 50.0 : 0.0) + ((static_cast(timeElapsed) / static_cast(duration)) * 50.0)); if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; @@ -234,11 +234,11 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo int timeElapsed; if ((duration > 0) && MUtils::regexp_parse_int32(regExp_sp, timeElapsed)) { - int newProgress = qRound((static_cast(timeElapsed) / static_cast(duration)) * 100.0); + const int newProgress = qRound((static_cast(timeElapsed) / static_cast(duration)) * 100.0); if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_AAC_FDK.cpp b/src/Encoder_AAC_FDK.cpp index 21408743..59d2b852 100644 --- a/src/Encoder_AAC_FDK.cpp +++ b/src/Encoder_AAC_FDK.cpp @@ -214,7 +214,7 @@ bool FDKAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_AAC_FHG.cpp b/src/Encoder_AAC_FHG.cpp index 7f80ea7c..de62a09b 100644 --- a/src/Encoder_AAC_FHG.cpp +++ b/src/Encoder_AAC_FHG.cpp @@ -209,7 +209,7 @@ bool FHGAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_AAC_QAAC.cpp b/src/Encoder_AAC_QAAC.cpp index 4e291b92..e0e6e576 100644 --- a/src/Encoder_AAC_QAAC.cpp +++ b/src/Encoder_AAC_QAAC.cpp @@ -235,7 +235,7 @@ bool QAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_AC3.cpp b/src/Encoder_AC3.cpp index 1703aa59..d78cad05 100644 --- a/src/Encoder_AC3.cpp +++ b/src/Encoder_AC3.cpp @@ -202,7 +202,7 @@ bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_DCA.cpp b/src/Encoder_DCA.cpp index 08c5a222..0c101f0b 100644 --- a/src/Encoder_DCA.cpp +++ b/src/Encoder_DCA.cpp @@ -168,7 +168,7 @@ bool DCAEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_FLAC.cpp b/src/Encoder_FLAC.cpp index eeb034e3..ba3ceb39 100644 --- a/src/Encoder_FLAC.cpp +++ b/src/Encoder_FLAC.cpp @@ -177,7 +177,7 @@ bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_MAC.cpp b/src/Encoder_MAC.cpp index 33bd88cc..3dd0cc16 100644 --- a/src/Encoder_MAC.cpp +++ b/src/Encoder_MAC.cpp @@ -174,7 +174,7 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 68e120c5..6f75f87a 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -250,7 +250,7 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_Opus.cpp b/src/Encoder_Opus.cpp index 3f3d1436..a14000f4 100644 --- a/src/Encoder_Opus.cpp +++ b/src/Encoder_Opus.cpp @@ -219,7 +219,7 @@ bool OpusEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true; diff --git a/src/Encoder_Vorbis.cpp b/src/Encoder_Vorbis.cpp index 5170ae2b..96c6ef68 100644 --- a/src/Encoder_Vorbis.cpp +++ b/src/Encoder_Vorbis.cpp @@ -209,7 +209,7 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = qMin(newProgress + 2, 99); + prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; } } return true;