From fcdb087e20b78d18bbe8874a6d1090a40767bf13 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Mon, 11 Dec 2017 20:00:50 +0100 Subject: [PATCH] Code refactoring. --- src/Decoder_AAC.cpp | 2 +- src/Decoder_AC3.cpp | 2 +- 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_TTA.cpp | 2 +- src/Decoder_Vorbis.cpp | 2 +- src/Decoder_WMA.cpp | 2 +- src/Decoder_WavPack.cpp | 2 +- src/Encoder_AAC.cpp | 4 +- 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 +- src/Encoder_Wave.cpp | 2 +- src/Filter_Downmix.cpp | 2 +- src/Filter_Normalize.cpp | 2 +- src/Filter_Resample.cpp | 2 +- src/Filter_ToneAdjust.cpp | 2 +- src/Tool_Abstract.cpp | 8 +-- src/Tool_Abstract.h | 7 ++- src/Tool_WaveProperties.cpp | 115 ++++++++++++++++---------------------------- 33 files changed, 80 insertions(+), 112 deletions(-) diff --git a/src/Decoder_AAC.cpp b/src/Decoder_AAC.cpp index 0daa84d0..cf9fbbab 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_AC3.cpp b/src/Decoder_AC3.cpp index 03a17def..b3fac30c 100644 --- a/src/Decoder_AC3.cpp +++ b/src/Decoder_AC3.cpp @@ -73,7 +73,7 @@ bool AC3Decoder::decode(const QString &sourceFile, const QString &outputFile, QA if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_ADPCM.cpp b/src/Decoder_ADPCM.cpp index fada5915..581acbdb 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_ALAC.cpp b/src/Decoder_ALAC.cpp index 093698f4..fa3d47d1 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_Avisynth.cpp b/src/Decoder_Avisynth.cpp index 05c7b347..fe1a3da5 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_FLAC.cpp b/src/Decoder_FLAC.cpp index bae418c0..304e7de6 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_MAC.cpp b/src/Decoder_MAC.cpp index 9d81d22c..9208f279 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_MP3.cpp b/src/Decoder_MP3.cpp index 13d03876..003c9ebd 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } } diff --git a/src/Decoder_Musepack.cpp b/src/Decoder_Musepack.cpp index f994ef8e..8b6ef429 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_Opus.cpp b/src/Decoder_Opus.cpp index 4256ae12..5d817786 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_TTA.cpp b/src/Decoder_TTA.cpp index df6102df..4709c6a1 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_Vorbis.cpp b/src/Decoder_Vorbis.cpp index bd2588e8..ff686f1b 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_WMA.cpp b/src/Decoder_WMA.cpp index 948c9ed7..21534c36 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Decoder_WavPack.cpp b/src/Decoder_WavPack.cpp index 800d6ec1..a7f1c7f8 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_AAC.cpp b/src/Encoder_AAC.cpp index a9386cde..d78fce0a 100644 --- a/src/Encoder_AAC.cpp +++ b/src/Encoder_AAC.cpp @@ -224,7 +224,7 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; @@ -238,7 +238,7 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_AAC_FDK.cpp b/src/Encoder_AAC_FDK.cpp index 59d2b852..dd97ab67 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_AAC_FHG.cpp b/src/Encoder_AAC_FHG.cpp index de62a09b..554a51c4 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_AAC_QAAC.cpp b/src/Encoder_AAC_QAAC.cpp index e0e6e576..eed000e6 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_AC3.cpp b/src/Encoder_AC3.cpp index d78cad05..f94f0d57 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_DCA.cpp b/src/Encoder_DCA.cpp index 0c101f0b..eb9a7d56 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_FLAC.cpp b/src/Encoder_FLAC.cpp index ba3ceb39..b20ec9f0 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_MAC.cpp b/src/Encoder_MAC.cpp index 3dd0cc16..cc1b6c1d 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 6f75f87a..d7f16b82 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_Opus.cpp b/src/Encoder_Opus.cpp index a14000f4..f0dd5444 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_Vorbis.cpp b/src/Encoder_Vorbis.cpp index 96c6ef68..de727ceb 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 = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Encoder_Wave.cpp b/src/Encoder_Wave.cpp index 5e87a677..55bf537a 100644 --- a/src/Encoder_Wave.cpp +++ b/src/Encoder_Wave.cpp @@ -148,7 +148,7 @@ bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf } else { - emit messageLogged(checkFlag(abortFlag) ? L1S("Operation cancelled by user!") : L1S("Error: Failed to copy file!")); + emit messageLogged(CHECK_FLAG(abortFlag) ? L1S("Operation cancelled by user!") : L1S("Error: Failed to copy file!")); } return success; diff --git a/src/Filter_Downmix.cpp b/src/Filter_Downmix.cpp index 58d2b8e4..84d6d6a7 100644 --- a/src/Filter_Downmix.cpp +++ b/src/Filter_Downmix.cpp @@ -118,7 +118,7 @@ AbstractFilter::FilterResult DownmixFilter::apply(const QString &sourceFile, con if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Filter_Normalize.cpp b/src/Filter_Normalize.cpp index f4015c5e..53409605 100644 --- a/src/Filter_Normalize.cpp +++ b/src/Filter_Normalize.cpp @@ -102,7 +102,7 @@ AbstractFilter::FilterResult NormalizeFilter::apply(const QString &sourceFile, c if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Filter_Resample.cpp b/src/Filter_Resample.cpp index 06a0ffed..304e0c70 100644 --- a/src/Filter_Resample.cpp +++ b/src/Filter_Resample.cpp @@ -115,7 +115,7 @@ AbstractFilter::FilterResult ResampleFilter::apply(const QString &sourceFile, co if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Filter_ToneAdjust.cpp b/src/Filter_ToneAdjust.cpp index 1845544d..40c1bcdc 100644 --- a/src/Filter_ToneAdjust.cpp +++ b/src/Filter_ToneAdjust.cpp @@ -88,7 +88,7 @@ AbstractFilter::FilterResult ToneAdjustFilter::apply(const QString &sourceFile, if (newProgress > prevProgress) { emit statusUpdated(newProgress); - prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress; + prevProgress = NEXT_PROGRESS(newProgress); } } return true; diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index 4cb8fd00..872615ac 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -176,7 +176,7 @@ AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt while (process.state() != QProcess::NotRunning) { - if (checkFlag(abortFlag)) + if (CHECK_FLAG(abortFlag)) { process.kill(); bAborted = true; @@ -199,11 +199,7 @@ AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt QByteArray line = process.readLine(); if (line.size() > 0) { - static const char REPALCE_CHARS[3] = { '\r', '\b', '\t' }; - for (size_t i = 0; i < MUTILS_ARR2LEN(REPALCE_CHARS); ++i) - { - line.replace(REPALCE_CHARS[i], char(0x20)); - } + line.replace('\r', char(0x20)).replace('\b', char(0x20)).replace('\t', char(0x20)); const QString text = QString::fromUtf8(line.constData()).simplified(); if (!text.isEmpty()) { diff --git a/src/Tool_Abstract.h b/src/Tool_Abstract.h index d8a5da89..610a722b 100644 --- a/src/Tool_Abstract.h +++ b/src/Tool_Abstract.h @@ -59,11 +59,16 @@ protected: } result_t; - static __forceinline bool checkFlag(QAtomicInt &flag) + static __forceinline bool CHECK_FLAG(QAtomicInt &flag) { return MUTILS_BOOLIFY(flag); } + static __forceinline int NEXT_PROGRESS(const int &progress) + { + return (progress < 99) ? qMax(0, progress + 1) : qMin(100, progress); + } + static QString commandline2string(const QString &program, const QStringList &arguments); bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString()); diff --git a/src/Tool_WaveProperties.cpp b/src/Tool_WaveProperties.cpp index 9a5f46c5..abd30cb9 100644 --- a/src/Tool_WaveProperties.cpp +++ b/src/Tool_WaveProperties.cpp @@ -59,101 +59,68 @@ bool WaveProperties::detect(const QString &sourceFile, AudioFileModel_TechInfo * return false; } - bool bTimeout = false; - bool bAborted = false; - int progress = 0; - QRegExp regExp_precision("Precision\\s*:\\s*(\\d+)-bit", Qt::CaseInsensitive); - QRegExp regExp_samplerate("Sample Rate\\s*:\\s*(\\d+)", Qt::CaseInsensitive); - QRegExp regExp_duration("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d\\d)", Qt::CaseInsensitive); - QRegExp regExp_channels("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive); - QRegExp regExp_encoding("Sample Encoding\\s*:\\s*(\\d+)-bit\\s*Float", Qt::CaseInsensitive); //SoX returns a precision of 24-Bit for 32-Bit Float data, so we detect it this way! + QRegExp regExp_prc("Precision\\s*:\\s*(\\d+)-bit", Qt::CaseInsensitive); + QRegExp regExp_srt("Sample Rate\\s*:\\s*(\\d+)", Qt::CaseInsensitive); + QRegExp regExp_drt("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d\\d)", Qt::CaseInsensitive); + QRegExp regExp_chl("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive); + QRegExp regExp_enc("Sample Encoding\\s*:\\s*(\\d+)-bit\\s*Float", Qt::CaseInsensitive); //SoX returns a precision of 24-Bit for 32-Bit Float data, so we detect it this way! - while(process.state() != QProcess::NotRunning) + const result_t result = awaitProcess(process, abortFlag, [this, &info, &progress, ®Exp_prc, ®Exp_srt, ®Exp_drt, ®Exp_chl, ®Exp_enc](const QString &text) { - if(checkFlag(abortFlag)) - { - process.kill(); - bAborted = true; - emit messageLogged("\nABORTED BY USER !!!"); - break; - } - process.waitForReadyRead(m_processTimeoutInterval); - if(!process.bytesAvailable() && process.state() == QProcess::Running) + if (regExp_prc.lastIndexIn(text) >= 0) { - process.kill(); - qWarning("SoX 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(regExp_precision.lastIndexIn(text) >= 0) + quint32 tmp; + if (MUtils::regexp_parse_uint32(regExp_prc, tmp)) { - bool ok = false; - unsigned int tmp = regExp_precision.cap(1).toUInt(&ok); - if(ok) info->setAudioBitdepth(tmp); + info->setAudioBitdepth(tmp); emit statusUpdated(qMin(progress += 25, 100)); } - if(regExp_encoding.lastIndexIn(text) >= 0) + return true; + } + if (regExp_enc.lastIndexIn(text) >= 0) + { + quint32 tmp; + if (MUtils::regexp_parse_uint32(regExp_enc, tmp)) { - bool ok = false; - unsigned int tmp = regExp_encoding.cap(1).toUInt(&ok); - if(ok) info->setAudioBitdepth((tmp == 32) ? AudioFileModel::BITDEPTH_IEEE_FLOAT32 : tmp); + info->setAudioBitdepth((tmp == 32) ? AudioFileModel::BITDEPTH_IEEE_FLOAT32 : tmp); emit statusUpdated(qMin(progress += 25, 100)); } - if(regExp_samplerate.lastIndexIn(text) >= 0) + return true; + } + if (regExp_srt.lastIndexIn(text) >= 0) + { + quint32 tmp; + if (MUtils::regexp_parse_uint32(regExp_srt, tmp)) { - bool ok = false; - unsigned int tmp = regExp_samplerate.cap(1).toUInt(&ok); - if(ok) info->setAudioSamplerate(tmp); + info->setAudioSamplerate(tmp); emit statusUpdated(qMin(progress += 25, 100)); } - if(regExp_duration.lastIndexIn(text) >= 0) + return true; + } + if (regExp_drt.lastIndexIn(text) >= 0) + { + quint32 tmp[4]; + if (MUtils::regexp_parse_uint32(regExp_drt, tmp, 4)) { - bool ok[4] = {false, false, false, false}; - unsigned int tmp1 = regExp_duration.cap(1).toUInt(&ok[0]); - unsigned int tmp2 = regExp_duration.cap(2).toUInt(&ok[1]); - unsigned int tmp3 = regExp_duration.cap(3).toUInt(&ok[2]); - unsigned int tmp4 = regExp_duration.cap(4).toUInt(&ok[3]); - if(ok[0] && ok[1] && ok[2] && ok[3]) - { - info->setDuration((tmp1 * 3600) + (tmp2 * 60) + tmp3 + qRound(static_cast(tmp4) / 100.0)); - } + info->setDuration((tmp[0] * 3600) + (tmp[1] * 60) + tmp[2] + qRound(static_cast(tmp[3]) / 100.0)); emit statusUpdated(qMin(progress += 25, 100)); } - if(regExp_channels.lastIndexIn(text) >= 0) + return true; + } + if (regExp_chl.lastIndexIn(text) >= 0) + { + quint32 tmp; + if (MUtils::regexp_parse_uint32(regExp_chl, tmp)) { - bool ok = false; - unsigned int tmp = regExp_channels.cap(1).toUInt(&ok); - if(ok) info->setAudioChannels(tmp); + info->setAudioChannels(tmp); emit statusUpdated(qMin(progress += 25, 100)); } - if(!text.isEmpty()) - { - emit messageLogged(text); - } + return true; } - } - - 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) - { return false; - } + }); - return true; + return (result == RESULT_SUCCESS); } -- 2.11.4.GIT