///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include <QDir>
#include <QProcess>
#include <QRegExp>
+#include <QFileInfo>
ToneAdjustFilter::ToneAdjustFilter(int bass, int treble)
:
throw "Error initializing SoX filter. Tool 'sox.exe' is not registred!";
}
- m_bass = max(-2000, min(2000, bass));
- m_treble = max(-2000, min(2000, treble));
+ m_bass = qMax(-2000, qMin(2000, bass));
+ m_treble = qMax(-2000, qMin(2000, treble));
}
ToneAdjustFilter::~ToneAdjustFilter(void)
{
}
-bool ToneAdjustFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag)
+bool ToneAdjustFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag)
{
QProcess process;
QStringList args;
- process.setWorkingDirectory(lamexp_temp_folder());
+ process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath());
- args << "-V3";
+ args << "-V3" << "-S";
args << "--guard" << "--temp" << ".";
args << QDir::toNativeSeparators(sourceFile);
args << QDir::toNativeSeparators(outputFile);
bool bTimeout = false;
bool bAborted = false;
+ QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
+
while(process.state() != QProcess::NotRunning)
{
if(*abortFlag)
emit messageLogged("\nABORTED BY USER !!!");
break;
}
- process.waitForReadyRead();
+ process.waitForReadyRead(m_processTimeoutInterval);
if(!process.bytesAvailable() && process.state() == QProcess::Running)
{
process.kill();
qWarning("SoX process timed out <-- killing!");
+ emit messageLogged("\nPROCESS TIMEOUT !!!");
bTimeout = true;
break;
}
{
QByteArray line = process.readLine();
QString text = QString::fromUtf8(line.constData()).simplified();
- if(!text.isEmpty())
+ 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(100);
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
- if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit || QFileInfo(outputFile).size() == 0)
+ if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
{
return false;
}