Refactored all filter classes to use awaitProcess() from Tool_Abstract base class.
This commit is contained in:
parent
c47a13a494
commit
475d524124
@ -35,7 +35,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 6
|
||||
#define VER_LAMEXP_TYPE Beta
|
||||
#define VER_LAMEXP_PATCH 1
|
||||
#define VER_LAMEXP_BUILD 2071
|
||||
#define VER_LAMEXP_BUILD 2072
|
||||
#define VER_LAMEXP_CONFG 2002
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,57 +105,28 @@ AbstractFilter::FilterResult DownmixFilter::apply(const QString &sourceFile, con
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
||||
bool bTimeout = false;
|
||||
bool bAborted = false;
|
||||
|
||||
int prevProgress = -1;
|
||||
QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
|
||||
|
||||
while(process.state() != QProcess::NotRunning)
|
||||
const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
|
||||
{
|
||||
if(checkFlag(abortFlag))
|
||||
if (regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
process.kill();
|
||||
bAborted = true;
|
||||
emit messageLogged("\nABORTED BY USER !!!");
|
||||
break;
|
||||
}
|
||||
process.waitForReadyRead(m_processTimeoutInterval);
|
||||
if(!process.bytesAvailable() && process.state() == QProcess::Running)
|
||||
qint32 newProgress;
|
||||
if (MUtils::regexp_parse_int32(regExp, newProgress))
|
||||
{
|
||||
process.kill();
|
||||
qWarning("SoX process timed out <-- killing!");
|
||||
emit messageLogged("\nPROCESS TIMEOUT !!!");
|
||||
bTimeout = true;
|
||||
break;
|
||||
}
|
||||
while(process.bytesAvailable() > 0)
|
||||
if (newProgress > prevProgress)
|
||||
{
|
||||
QByteArray line = process.readLine();
|
||||
QString text = QString::fromUtf8(line.constData()).simplified();
|
||||
if(regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
bool ok = false;
|
||||
int progress = regExp.cap(1).toInt(&ok);
|
||||
if(ok) emit statusUpdated(progress);
|
||||
}
|
||||
else if(!text.isEmpty())
|
||||
{
|
||||
emit messageLogged(text);
|
||||
emit statusUpdated(newProgress);
|
||||
prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
process.waitForFinished();
|
||||
if(process.state() != QProcess::NotRunning)
|
||||
{
|
||||
process.kill();
|
||||
process.waitForFinished(-1);
|
||||
}
|
||||
|
||||
emit statusUpdated(100);
|
||||
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
|
||||
|
||||
if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
|
||||
if (result != RESULT_SUCCESS)
|
||||
{
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
@ -89,57 +89,28 @@ AbstractFilter::FilterResult NormalizeFilter::apply(const QString &sourceFile, c
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
||||
bool bTimeout = false;
|
||||
bool bAborted = false;
|
||||
|
||||
int prevProgress = -1;
|
||||
QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
|
||||
|
||||
while(process.state() != QProcess::NotRunning)
|
||||
const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
|
||||
{
|
||||
if(checkFlag(abortFlag))
|
||||
if (regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
process.kill();
|
||||
bAborted = true;
|
||||
emit messageLogged("\nABORTED BY USER !!!");
|
||||
break;
|
||||
}
|
||||
process.waitForReadyRead(m_processTimeoutInterval);
|
||||
if(!process.bytesAvailable() && process.state() == QProcess::Running)
|
||||
qint32 newProgress;
|
||||
if (MUtils::regexp_parse_int32(regExp, newProgress))
|
||||
{
|
||||
process.kill();
|
||||
qWarning("SoX process timed out <-- killing!");
|
||||
emit messageLogged("\nPROCESS TIMEOUT !!!");
|
||||
bTimeout = true;
|
||||
break;
|
||||
}
|
||||
while(process.bytesAvailable() > 0)
|
||||
if (newProgress > prevProgress)
|
||||
{
|
||||
QByteArray line = process.readLine();
|
||||
QString text = QString::fromUtf8(line.constData()).simplified();
|
||||
if(regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
bool ok = false;
|
||||
int progress = regExp.cap(1).toInt(&ok);
|
||||
if(ok) emit statusUpdated(progress);
|
||||
}
|
||||
else if(!text.isEmpty())
|
||||
{
|
||||
emit messageLogged(text);
|
||||
emit statusUpdated(newProgress);
|
||||
prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
process.waitForFinished();
|
||||
if(process.state() != QProcess::NotRunning)
|
||||
{
|
||||
process.kill();
|
||||
process.waitForFinished(-1);
|
||||
}
|
||||
|
||||
emit statusUpdated(100);
|
||||
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
|
||||
|
||||
if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
|
||||
if (result != RESULT_SUCCESS)
|
||||
{
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
@ -102,65 +102,40 @@ AbstractFilter::FilterResult ResampleFilter::apply(const QString &sourceFile, co
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
||||
bool bTimeout = false;
|
||||
bool bAborted = false;
|
||||
|
||||
int prevProgress = -1;
|
||||
QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
|
||||
|
||||
while(process.state() != QProcess::NotRunning)
|
||||
const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
|
||||
{
|
||||
if(checkFlag(abortFlag))
|
||||
if (regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
process.kill();
|
||||
bAborted = true;
|
||||
emit messageLogged("\nABORTED BY USER !!!");
|
||||
break;
|
||||
}
|
||||
process.waitForReadyRead(m_processTimeoutInterval);
|
||||
if(!process.bytesAvailable() && process.state() == QProcess::Running)
|
||||
qint32 newProgress;
|
||||
if (MUtils::regexp_parse_int32(regExp, newProgress))
|
||||
{
|
||||
process.kill();
|
||||
qWarning("SoX process timed out <-- killing!");
|
||||
emit messageLogged("\nPROCESS TIMEOUT !!!");
|
||||
bTimeout = true;
|
||||
break;
|
||||
}
|
||||
while(process.bytesAvailable() > 0)
|
||||
if (newProgress > prevProgress)
|
||||
{
|
||||
QByteArray line = process.readLine();
|
||||
QString text = QString::fromUtf8(line.constData()).simplified();
|
||||
if(regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
bool ok = false;
|
||||
int progress = regExp.cap(1).toInt(&ok);
|
||||
if(ok) emit statusUpdated(progress);
|
||||
}
|
||||
else if(!text.isEmpty())
|
||||
{
|
||||
emit messageLogged(text);
|
||||
emit statusUpdated(newProgress);
|
||||
prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
process.waitForFinished();
|
||||
if(process.state() != QProcess::NotRunning)
|
||||
{
|
||||
process.kill();
|
||||
process.waitForFinished(-1);
|
||||
}
|
||||
|
||||
emit statusUpdated(100);
|
||||
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
|
||||
|
||||
if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
|
||||
if (result != RESULT_SUCCESS)
|
||||
{
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
||||
if(m_samplingRate)
|
||||
if (m_samplingRate)
|
||||
{
|
||||
formatInfo->setAudioSamplerate(m_samplingRate);
|
||||
if(m_bitDepth)
|
||||
}
|
||||
if (m_bitDepth)
|
||||
{
|
||||
formatInfo->setAudioBitdepth(m_bitDepth);
|
||||
}
|
||||
|
||||
return AbstractFilter::FILTER_SUCCESS;
|
||||
}
|
||||
|
@ -75,57 +75,28 @@ AbstractFilter::FilterResult ToneAdjustFilter::apply(const QString &sourceFile,
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
||||
bool bTimeout = false;
|
||||
bool bAborted = false;
|
||||
|
||||
int prevProgress = -1;
|
||||
QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
|
||||
|
||||
while(process.state() != QProcess::NotRunning)
|
||||
const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
|
||||
{
|
||||
if(checkFlag(abortFlag))
|
||||
if (regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
process.kill();
|
||||
bAborted = true;
|
||||
emit messageLogged("\nABORTED BY USER !!!");
|
||||
break;
|
||||
}
|
||||
process.waitForReadyRead(m_processTimeoutInterval);
|
||||
if(!process.bytesAvailable() && process.state() == QProcess::Running)
|
||||
qint32 newProgress;
|
||||
if (MUtils::regexp_parse_int32(regExp, newProgress))
|
||||
{
|
||||
process.kill();
|
||||
qWarning("SoX process timed out <-- killing!");
|
||||
emit messageLogged("\nPROCESS TIMEOUT !!!");
|
||||
bTimeout = true;
|
||||
break;
|
||||
}
|
||||
while(process.bytesAvailable() > 0)
|
||||
if (newProgress > prevProgress)
|
||||
{
|
||||
QByteArray line = process.readLine();
|
||||
QString text = QString::fromUtf8(line.constData()).simplified();
|
||||
if(regExp.lastIndexIn(text) >= 0)
|
||||
{
|
||||
bool ok = false;
|
||||
int progress = regExp.cap(1).toInt(&ok);
|
||||
if(ok) emit statusUpdated(progress);
|
||||
}
|
||||
else if(!text.isEmpty())
|
||||
{
|
||||
emit messageLogged(text);
|
||||
emit statusUpdated(newProgress);
|
||||
prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
process.waitForFinished();
|
||||
if(process.state() != QProcess::NotRunning)
|
||||
{
|
||||
process.kill();
|
||||
process.waitForFinished(-1);
|
||||
}
|
||||
|
||||
emit statusUpdated(100);
|
||||
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
|
||||
|
||||
if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
|
||||
if (result != RESULT_SUCCESS)
|
||||
{
|
||||
return AbstractFilter::FILTER_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user