OSDN Git Service

Code refactoring.
authorLoRd_MuldeR <mulder2@gmx.de>
Mon, 11 Dec 2017 19:00:50 +0000 (20:00 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Mon, 11 Dec 2017 19:00:50 +0000 (20:00 +0100)
33 files changed:
src/Decoder_AAC.cpp
src/Decoder_AC3.cpp
src/Decoder_ADPCM.cpp
src/Decoder_ALAC.cpp
src/Decoder_Avisynth.cpp
src/Decoder_FLAC.cpp
src/Decoder_MAC.cpp
src/Decoder_MP3.cpp
src/Decoder_Musepack.cpp
src/Decoder_Opus.cpp
src/Decoder_TTA.cpp
src/Decoder_Vorbis.cpp
src/Decoder_WMA.cpp
src/Decoder_WavPack.cpp
src/Encoder_AAC.cpp
src/Encoder_AAC_FDK.cpp
src/Encoder_AAC_FHG.cpp
src/Encoder_AAC_QAAC.cpp
src/Encoder_AC3.cpp
src/Encoder_DCA.cpp
src/Encoder_FLAC.cpp
src/Encoder_MAC.cpp
src/Encoder_MP3.cpp
src/Encoder_Opus.cpp
src/Encoder_Vorbis.cpp
src/Encoder_Wave.cpp
src/Filter_Downmix.cpp
src/Filter_Normalize.cpp
src/Filter_Resample.cpp
src/Filter_ToneAdjust.cpp
src/Tool_Abstract.cpp
src/Tool_Abstract.h
src/Tool_WaveProperties.cpp

index 0daa84d..cf9fbba 100644 (file)
@@ -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;
index 03a17de..b3fac30 100644 (file)
@@ -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;
index fada591..581acbd 100644 (file)
@@ -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;
index 093698f..fa3d47d 100644 (file)
@@ -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;
index 05c7b34..fe1a3da 100644 (file)
@@ -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;
index bae418c..304e7de 100644 (file)
@@ -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;
index 9d81d22..9208f27 100644 (file)
@@ -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;
index 13d0387..003c9eb 100644 (file)
@@ -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);
                                        }
                                }
                        }
index f994ef8..8b6ef42 100644 (file)
@@ -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;
index 4256ae1..5d81778 100644 (file)
@@ -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;
index df6102d..4709c6a 100644 (file)
@@ -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;
index bd2588e..ff686f1 100644 (file)
@@ -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;
index 948c9ed..21534c3 100644 (file)
@@ -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;
index 800d6ec..a7f1c7f 100644 (file)
@@ -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;
index a9386cd..d78fce0 100644 (file)
@@ -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;
index 59d2b85..dd97ab6 100644 (file)
@@ -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;
index de62a09..554a51c 100644 (file)
@@ -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;
index e0e6e57..eed000e 100644 (file)
@@ -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;
index d78cad0..f94f0d5 100644 (file)
@@ -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;
index 0c101f0..eb9a7d5 100644 (file)
@@ -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;
index ba3ceb3..b20ec9f 100644 (file)
@@ -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;
index 3dd0cc1..cc1b6c1 100644 (file)
@@ -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;
index 6f75f87..d7f16b8 100644 (file)
@@ -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;
index a14000f..f0dd544 100644 (file)
@@ -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;
index 96c6ef6..de727ce 100644 (file)
@@ -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;
index 5e87a67..55bf537 100644 (file)
@@ -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;
index 58d2b8e..84d6d6a 100644 (file)
@@ -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;
index f4015c5..5340960 100644 (file)
@@ -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;
index 06a0ffe..304e0c7 100644 (file)
@@ -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;
index 1845544..40c1bcd 100644 (file)
@@ -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;
index 4cb8fd0..872615a 100644 (file)
@@ -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())
                                {
index d8a5da8..610a722 100644 (file)
@@ -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());
index 9a5f46c..abd30cb 100644 (file)
@@ -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, &regExp_prc, &regExp_srt, &regExp_drt, &regExp_chl, &regExp_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<double>(tmp4) / 100.0));
-                               }
+                               info->setDuration((tmp[0] * 3600) + (tmp[1] * 60) + tmp[2] + qRound(static_cast<double>(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);
 }