OSDN Git Service

Refactored all encoder classes to use awaitProcess() from Tool_Abstract base class.
authorLoRd_MuldeR <mulder2@gmx.de>
Sun, 10 Dec 2017 20:46:56 +0000 (21:46 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sun, 10 Dec 2017 20:46:56 +0000 (21:46 +0100)
16 files changed:
src/Config.h
src/Decoder_WMA.cpp
src/Dialog_MainWindow.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/Tool_Abstract.cpp
src/Tool_Abstract.h

index f9a42a2..3c82590 100644 (file)
@@ -35,7 +35,7 @@
 #define VER_LAMEXP_MINOR_LO                                    6
 #define VER_LAMEXP_TYPE                                                Beta
 #define VER_LAMEXP_PATCH                                       1
-#define VER_LAMEXP_BUILD                                       2068
+#define VER_LAMEXP_BUILD                                       2071
 #define VER_LAMEXP_CONFG                                       2002
 
 ///////////////////////////////////////////////////////////////////////////////
index 87177fe..aae6ef8 100644 (file)
@@ -70,7 +70,7 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, QA
                if (regExp.lastIndexIn(text) >= 0)
                {
                        qint32 newProgress;
-                       if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
                                if (newProgress > prevProgress)
                                {
index 6291081..1e8e3ee 100644 (file)
@@ -1594,7 +1594,7 @@ void MainWindow::windowShown(void)
                                messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
                                messageText += NOBR(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac(), tr("n/a")), lamexp_version2string("?.?.?.?", lamexp_tools_version("neroAacEnc.exe"), tr("n/a")))).append("<br><br>");
                                messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
-                               messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br><br>";
+                               messageText += QString("<nobr><tt>").append(LINK(AboutDialog::neroAacUrl)).append("</tt></nobr><br><br>");
                                messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
                                QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
                        }
@@ -1609,10 +1609,10 @@ void MainWindow::windowShown(void)
                        QString messageText;
                        messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
                        messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
-                       messageText += NOBR(tr("Your LameXP directory is located here:")).append("<br>");
+                       messageText += QString("<b>").append(NOBR(tr("Your LameXP install directory is located here:"))).append("</b><br>");
                        messageText += QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath)));
-                       messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
-                       messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
+                       messageText += QString("<b>").append(NOBR(tr("You can download the Nero AAC encoder for free from this website:"))).append("</b><br>");
+                       messageText += QString("<nobr><tt>").append(LINK(AboutDialog::neroAacUrl)).append("</tt></nobr><br>");
                        if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
                        {
                                m_settings->neroAacNotificationsEnabled(false);
index 91919f5..37ed646 100644 (file)
@@ -208,97 +208,45 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        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(L1S("Processed\\s+(\\d+)\\s+seconds"));
-       QRegExp regExp_pass1(L1S("First\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"));
-       QRegExp regExp_pass2(L1S("Second\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"));
-
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &duration, &regExp_sp, &regExp_mp](const QString &text)
        {
-               if(checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("NeroAacEnc process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
+               if (regExp_mp.lastIndexIn(text) >= 0)
                {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp_pass1.lastIndexIn(text) >= 0)
-                       {
-                               bool ok = false;
-                               int progress = regExp_pass1.cap(1).toInt(&ok);
-                               if(ok && (duration > 0))
-                               {
-                                       int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 50.0);
-                                       if(newProgress > prevProgress)
-                                       {
-                                               emit statusUpdated(newProgress);
-                                               prevProgress = qMin(newProgress + 2, 99);
-                                       }
-                               }
-                       }
-                       else if(regExp_pass2.lastIndexIn(text) >= 0)
+                       int timeElapsed;
+                       if ((duration > 0) && MUtils::regexp_parse_int32(regExp_mp, timeElapsed, 2))
                        {
-                               bool ok = false;
-                               int progress = regExp_pass2.cap(1).toInt(&ok);
-                               if(ok && (duration > 0))
+                               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<double>(timeElapsed) / static_cast<double>(duration)) * 50.0));
+                               if (newProgress > prevProgress)
                                {
-                                       int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 50.0) + 50;
-                                       if(newProgress > prevProgress)
-                                       {
-                                               emit statusUpdated(newProgress);
-                                               prevProgress = qMin(newProgress + 2, 99);
-                                       }
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else if(regExp.lastIndexIn(text) >= 0)
+                       return true;
+               }
+               if (regExp_sp.lastIndexIn(text) >= 0)
+               {
+                       int timeElapsed;
+                       if ((duration > 0) && MUtils::regexp_parse_int32(regExp_sp, timeElapsed))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (duration > 0))
+                               int newProgress = qRound((static_cast<double>(timeElapsed) / static_cast<double>(duration)) * 100.0);
+                               if (newProgress > prevProgress)
                                {
-                                       int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 100.0);
-                                       if(newProgress > prevProgress)
-                                       {
-                                               emit statusUpdated(newProgress);
-                                               prevProgress = qMin(newProgress + 2, 99);
-                                       }
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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()));
+               return false;
+       });
 
-       if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
+       if(result != RESULT_SUCCESS)
        {
                return false;
        }
@@ -327,52 +275,7 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bTimeout = false;
-
-       while(process.state() != QProcess::NotRunning)
-       {
-               if(checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("NeroAacTag process timed out <-- killing!");
-                       emit messageLogged(L1S("\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 messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
-       if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
-       {
-               return false;
-       }
-
-       return true;
+       return (awaitProcess(process, abortFlag) == RESULT_SUCCESS);
 }
 
 bool AACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 07b29b9..2140874 100644 (file)
@@ -201,67 +201,28 @@ bool FDKAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\[(\\d+)%\\]\\s+(\\d+):(\\d+)"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if(checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("FDKAAC process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool FDKAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 1c0e252..7f80ea7 100644 (file)
@@ -196,67 +196,28 @@ bool FHGAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("Progress:\\s*(\\d+)%"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("FhgAacEnc process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool FHGAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index ef7a70d..4e291b9 100644 (file)
@@ -222,67 +222,28 @@ bool QAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\[(\\d+)\\.(\\d)%\\]"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("QAAC process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool QAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index b9348a4..1703aa5 100644 (file)
@@ -189,67 +189,28 @@ bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
+       QRegExp regExp(L1S("progress:\\s+(\\d+)%"));
 
-       QRegExp regExp(L1S("progress:(\\s+)(\\d+)%(\\s+)\\|"));
-
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("Aften process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(2).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 void AC3Encoder::setAudioCodingMode(int value)
index 218d955..08c5a22 100644 (file)
@@ -155,67 +155,28 @@ bool DCAEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\[(\\d+)\\.(\\d+)%\\]"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("DCAENC process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool DCAEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 94f2b9c..eeb034e 100644 (file)
@@ -164,67 +164,28 @@ bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\b(\\d+)% complete"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if(checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("FLAC process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine().replace('\b', char(0x20));
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool FLACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 2df1485..33bd88c 100644 (file)
@@ -161,62 +161,28 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("Progress: (\\d+).(\\d+)%"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("MAC process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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()));
+               return false;
+       });
 
-       if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
+       if(result != RESULT_SUCCESS)
        {
                return false;
        }
@@ -246,52 +212,7 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bTimeout = false;
-
-       while(process.state() != QProcess::NotRunning)
-       {
-               if(checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("Tag process timed out <-- killing!");
-                       emit messageLogged(L1S("\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 messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
-       if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
-       {
-               return false;
-       }
-
-       return true;
+       return (awaitProcess(process, abortFlag) == RESULT_SUCCESS);
 }
 
 bool MACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index f37fae8..68e120c 100644 (file)
@@ -237,67 +237,28 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\(.*(\\d+)%\\)\\|"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("LAME process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool MP3Encoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 9b6ac92..3f3d143 100644 (file)
@@ -206,67 +206,28 @@ bool OpusEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\((\\d+)%\\)"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if (checkFlag(abortFlag))
-               {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("Opus process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 QString OpusEncoder::detectMimeType(const QString &coverFile)
index 058f33a..5170ae2 100644 (file)
@@ -196,67 +196,28 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
                return false;
        }
 
-       bool bTimeout = false;
-       bool bAborted = false;
        int prevProgress = -1;
-
        QRegExp regExp(L1S("\\[.*(\\d+)[.,](\\d+)%\\]"));
 
-       while(process.state() != QProcess::NotRunning)
+       const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &regExp](const QString &text)
        {
-               if(checkFlag(abortFlag))
+               if (regExp.lastIndexIn(text) >= 0)
                {
-                       process.kill();
-                       bAborted = true;
-                       emit messageLogged(L1S("\nABORTED BY USER !!!"));
-                       break;
-               }
-               process.waitForReadyRead(m_processTimeoutInterval);
-               if(!process.bytesAvailable() && process.state() == QProcess::Running)
-               {
-                       process.kill();
-                       qWarning("OggEnc process timed out <-- killing!");
-                       emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
-                       bTimeout = true;
-                       break;
-               }
-               while(process.bytesAvailable() > 0)
-               {
-                       QByteArray line = process.readLine();
-                       QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(regExp.lastIndexIn(text) >= 0)
+                       qint32 newProgress;
+                       if (MUtils::regexp_parse_int32(regExp, newProgress))
                        {
-                               bool ok = false;
-                               int progress = regExp.cap(1).toInt(&ok);
-                               if(ok && (progress > prevProgress))
+                               if (newProgress > prevProgress)
                                {
-                                       emit statusUpdated(progress);
-                                       prevProgress = qMin(progress + 2, 99);
+                                       emit statusUpdated(newProgress);
+                                       prevProgress = qMin(newProgress + 2, 99);
                                }
                        }
-                       else 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);
 }
 
 bool VorbisEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
index 66989fc..4cb8fd0 100644 (file)
@@ -159,6 +159,14 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
 /*
 * Wait for process to terminate while processing its output
 */
+AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt &abortFlag, int *const exitCode)
+{
+       return awaitProcess(process, abortFlag, [](const QString &text) { return false; }, exitCode);
+}
+
+/*
+* Wait for process to terminate while processing its output
+*/
 AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function<bool(const QString &text)> &&handler, int *const exitCode)
 {
        bool bTimeout = false;
@@ -223,8 +231,8 @@ AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt
                *exitCode = process.exitCode();
        }
 
-       emit statusUpdated(100);
        emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
+       if (!(bAborted || bTimeout)) emit statusUpdated(100);
 
        if (bAborted || bTimeout || (process.exitCode() != EXIT_SUCCESS))
        {
index 0d93af3..d8a5da8 100644 (file)
@@ -67,6 +67,7 @@ protected:
        static QString commandline2string(const QString &program, const QStringList &arguments);
 
        bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString());
+       result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, int *const exitCode = NULL);
        result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function<bool(const QString &text)> &&handler, int *const exitCode = NULL);
 
 private: