1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Filter_ToneAdjust.h"
31 ToneAdjustFilter::ToneAdjustFilter(int bass
, int treble
)
33 m_binary(lamexp_lookup_tool("sox.exe"))
35 if(m_binary
.isEmpty())
37 throw "Error initializing SoX filter. Tool 'sox.exe' is not registred!";
40 m_bass
= qMax(-2000, qMin(2000, bass
));
41 m_treble
= qMax(-2000, qMin(2000, treble
));
44 ToneAdjustFilter::~ToneAdjustFilter(void)
48 bool ToneAdjustFilter::apply(const QString
&sourceFile
, const QString
&outputFile
, AudioFileModel
*formatInfo
, volatile bool *abortFlag
)
53 process
.setWorkingDirectory(QFileInfo(outputFile
).canonicalPath());
55 args
<< "-V3" << "-S";
56 args
<< "--guard" << "--temp" << ".";
57 args
<< QDir::toNativeSeparators(sourceFile
);
58 args
<< QDir::toNativeSeparators(outputFile
);
62 args
<< "bass" << QString().sprintf("%s%.2f", ((m_bass
< 0) ? "-" : "+"), static_cast<double>(abs(m_bass
)) / 100.0);
66 args
<< "treble" << QString().sprintf("%s%.2f", ((m_treble
< 0) ? "-" : "+"), static_cast<double>(abs(m_treble
)) / 100.0);
69 if(!startProcess(process
, m_binary
, args
))
74 bool bTimeout
= false;
75 bool bAborted
= false;
77 QRegExp
regExp("In:(\\d+)(\\.\\d+)*%");
79 while(process
.state() != QProcess::NotRunning
)
85 emit
messageLogged("\nABORTED BY USER !!!");
88 process
.waitForReadyRead(m_processTimeoutInterval
);
89 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
92 qWarning("SoX process timed out <-- killing!");
93 emit
messageLogged("\nPROCESS TIMEOUT !!!");
97 while(process
.bytesAvailable() > 0)
99 QByteArray line
= process
.readLine();
100 QString text
= QString::fromUtf8(line
.constData()).simplified();
101 if(regExp
.lastIndexIn(text
) >= 0)
104 int progress
= regExp
.cap(1).toInt(&ok
);
105 if(ok
) emit
statusUpdated(progress
);
107 else if(!text
.isEmpty())
109 emit
messageLogged(text
);
114 process
.waitForFinished();
115 if(process
.state() != QProcess::NotRunning
)
118 process
.waitForFinished(-1);
121 emit
statusUpdated(100);
122 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
124 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
|| QFileInfo(outputFile
).size() == 0)