if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
}
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
}
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;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
if (newProgress > prevProgress)
{
emit statusUpdated(newProgress);
- prevProgress = (newProgress < 99) ? (newProgress + 1) : newProgress;
+ prevProgress = NEXT_PROGRESS(newProgress);
}
}
return true;
while (process.state() != QProcess::NotRunning)
{
- if (checkFlag(abortFlag))
+ if (CHECK_FLAG(abortFlag))
{
process.kill();
bAborted = true;
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())
{
}
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());
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<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);
}