Refactor the MP3 encoder into a separate class.

This commit is contained in:
LoRd_MuldeR 2010-11-17 00:49:38 +01:00
parent 6a8ebd873b
commit b996bfdece
4 changed files with 63 additions and 78 deletions

View File

@ -310,6 +310,14 @@
RelativePath=".\src\Dialog_WorkingBanner.cpp" RelativePath=".\src\Dialog_WorkingBanner.cpp"
> >
</File> </File>
<File
RelativePath=".\src\Encoder_Abstract.cpp"
>
</File>
<File
RelativePath=".\src\Encoder_MP3.cpp"
>
</File>
<File <File
RelativePath=".\src\Genres.cpp" RelativePath=".\src\Genres.cpp"
> >
@ -538,6 +546,44 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\src\Encoder_Abstract.h"
>
</File>
<File
RelativePath=".\src\Encoder_MP3.h"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Static|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
</File>
<File <File
RelativePath=".\src\Genres.h" RelativePath=".\src\Genres.h"
> >
@ -796,6 +842,10 @@
RelativePath=".\tmp\MOC_Dialog_WorkingBanner.cpp" RelativePath=".\tmp\MOC_Dialog_WorkingBanner.cpp"
> >
</File> </File>
<File
RelativePath=".\tmp\MOC_Encoder_MP3.cpp"
>
</File>
<File <File
RelativePath=".\tmp\MOC_Model_FileList.cpp" RelativePath=".\tmp\MOC_Model_FileList.cpp"
> >

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0 #define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 27 #define VER_LAMEXP_BUILD 30
#define VER_LAMEXP_SUFFIX TechPreview #define VER_LAMEXP_SUFFIX TechPreview
/* /*

View File

@ -31,6 +31,7 @@
#include "Thread_MessageHandler.h" #include "Thread_MessageHandler.h"
#include "Model_MetaInfo.h" #include "Model_MetaInfo.h"
#include "Model_Settings.h" #include "Model_Settings.h"
#include "Encoder_MP3.h"
//Qt includes //Qt includes
#include <QMessageBox> #include <QMessageBox>
@ -457,11 +458,11 @@ void MainWindow::encodeButtonClicked(void)
return; return;
} }
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
m_banner->show("Encoding files, please wait..."); m_banner->show("Encoding files, please wait...");
QApplication::processEvents();
MP3Encoder *mp3Encoder = new MP3Encoder();
connect(mp3Encoder, SIGNAL(statusUpdated(QString)), m_banner, SLOT(setText(QString)));
for(int i = 0; i < m_fileListModel->rowCount(); i++) for(int i = 0; i < m_fileListModel->rowCount(); i++)
{ {
@ -472,22 +473,6 @@ void MainWindow::encodeButtonClicked(void)
int pos = baseName.lastIndexOf("."); int pos = baseName.lastIndexOf(".");
if(pos >= 1) baseName = baseName.left(pos); if(pos >= 1) baseName = baseName.left(pos);
QStringList args = QStringList() << "--nohist" << "-h";
switch(m_settings->compressionRCMode())
{
case SettingsModel::VBRMode:
args << "-V" << QString::number(9 - m_settings->compressionBitrate());
break;
case SettingsModel::ABRMode:
args << "--abr" << QString::number(SettingsModel::mp3Bitrates[m_settings->compressionBitrate()]);
break;
case SettingsModel::CBRMode:
args << "--cbr";
args << "-b" << QString::number(SettingsModel::mp3Bitrates[m_settings->compressionBitrate()]);
break;
}
int n = 1; int n = 1;
QString outFileName = QString(outFolder).append("/").append(baseName).append(".mp3"); QString outFileName = QString(outFolder).append("/").append(baseName).append(".mp3");
@ -496,66 +481,12 @@ void MainWindow::encodeButtonClicked(void)
outFileName = QString(outFolder).append("/").append(baseName).append(" (").append(QString::number(++n)).append(").mp3"); outFileName = QString(outFolder).append("/").append(baseName).append(" (").append(QString::number(++n)).append(").mp3");
} }
IF_UNICODE(file.fileName()) mp3Encoder->encode(file, outFileName);
{
args << "--uTitle" << file.fileName();
}
else
{
args << "--lTitle" << file.fileName();
} }
args << QDir::toNativeSeparators(file.filePath()); LAMEXP_DELETE(mp3Encoder);
args << QDir::toNativeSeparators(outFileName);
m_banner->setText(QString("Encoding: %1").arg(QFileInfo(file.filePath()).fileName()));
process.start(lamexp_lookup_tool("lame.exe"), args);
if(!process.waitForStarted())
{
QMessageBox::warning(this, "LAME", "Failed to create process!");
m_banner->close(); m_banner->close();
return;
}
QRegExp regExp("\\(.*(\\d+)%\\)\\|");
while(process.state() != QProcess::NotRunning)
{
process.waitForReadyRead();
QByteArray line = process.readLine();
if(line.isEmpty())
{
break;
}
while(line.size() > 0)
{
qDebug("%s", line.constData());
QString text = QString::fromLocal8Bit(line.constData()).simplified();
if(regExp.lastIndexIn(line) >= 0)
{
m_banner->setText(QString("Encoding: %1 (%2%)").arg(QFileInfo(file.filePath()).fileName(),regExp.cap(1)));
}
line = process.readLine();
QApplication::processEvents();
}
}
process.waitForFinished();
if(process.state() != QProcess::NotRunning)
{
process.kill();
process.waitForFinished(-1);
}
if(process.exitStatus() != QProcess::NormalExit)
{
QMessageBox::critical(this, "Error", QString("Ahrg, encoding has failed with error code %1.").arg(QString::number(process.exitCode())));
}
}
m_banner->close();
QMessageBox::information(this, "Done", "Encoding process completed."); QMessageBox::information(this, "Done", "Encoding process completed.");
} }

View File

@ -142,4 +142,8 @@ void WorkingBanner::setText(const QString &text)
} }
labelStatus->setText(choppedText); labelStatus->setText(choppedText);
} }
if(this->isVisible())
{
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
} }