Correctly forward meta info to MP3 encoder and apply.

This commit is contained in:
LoRd_MuldeR 2010-11-20 19:16:04 +01:00
parent bfa197b020
commit cffa6a2454
11 changed files with 101 additions and 39 deletions

View File

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

View File

@ -153,8 +153,10 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
metaDataView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
metaDataView->verticalHeader()->hide();
metaDataView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
while(writeMetaDataCheckBox->isChecked() != m_settings->writeMetaTags()) writeMetaDataCheckBox->click();
connect(buttonEditMeta, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
connect(buttonClearMeta, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
connect(writeMetaDataCheckBox, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
//Setup "Compression" tab
m_encoderButtonGroup = new QButtonGroup(this);
@ -1066,3 +1068,11 @@ void MainWindow::modelReset(void)
{
m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
}
/*
* Meta tags enabled changed
*/
void MainWindow::metaTagsEnabledChanged(void)
{
m_settings->writeMetaTags(writeMetaDataCheckBox->isChecked());
}

View File

@ -78,6 +78,7 @@ private slots:
void updateBitrate(int value);
void rowsChanged(const QModelIndex &parent, int start, int end);
void modelReset(void);
void metaTagsEnabledChanged(void);
protected:
void showEvent(QShowEvent *event);

View File

@ -43,9 +43,11 @@
// Constructor
////////////////////////////////////////////////////////////
ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, SettingsModel *settings)
ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent)
:
m_settings(settings)
QDialog(parent),
m_settings(settings),
m_metaInfo(metaInfo)
{
//Init the dialog, from the .ui file
setupUi(this);
@ -91,6 +93,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, SettingsModel *
//Init other vars
m_runningThreads = 0;
m_currentFile = 0;
m_userAborted = false;
}
@ -168,6 +171,7 @@ bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
void ProcessingDialog::initEncoding(void)
{
m_runningThreads = 0;
m_currentFile = 0;
m_userAborted = false;
label_progress->setText("Encoding files, please wait...");
@ -177,7 +181,7 @@ void ProcessingDialog::initEncoding(void)
button_AbortProcess->setEnabled(true);
progressBar->setRange(0, m_pendingJobs.count());
startNextJob();
startNextJob(); //TODO: Start as many jobs in parallel as processors available
startNextJob();
}
@ -240,7 +244,9 @@ void ProcessingDialog::startNextJob(void)
{
return;
}
m_currentFile++;
AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst());
AbstractEncoder *encoder = NULL;
switch(m_settings->compressionEncoder())
@ -257,7 +263,7 @@ void ProcessingDialog::startNextJob(void)
throw "Unsupported encoder!";
}
ProcessThread *thread = new ProcessThread(m_pendingJobs.takeFirst(), m_settings->outputDir(), encoder);
ProcessThread *thread = new ProcessThread(currentFile, m_settings->outputDir(), encoder);
m_threadList.append(thread);
connect(thread, SIGNAL(finished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel, SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
@ -266,6 +272,25 @@ void ProcessingDialog::startNextJob(void)
thread->start();
}
AudioFileModel ProcessingDialog::updateMetaInfo(const AudioFileModel &audioFile)
{
if(!m_settings->writeMetaTags())
{
return AudioFileModel(audioFile.filePath());
}
AudioFileModel result = audioFile;
if(!m_metaInfo->fileArtist().isEmpty()) result.setFileArtist(m_metaInfo->fileArtist());
if(!m_metaInfo->fileAlbum().isEmpty()) result.setFileAlbum(m_metaInfo->fileAlbum());
if(!m_metaInfo->fileGenre().isEmpty()) result.setFileGenre(m_metaInfo->fileGenre());
if(m_metaInfo->fileYear()) result.setFileYear(m_metaInfo->fileYear());
if(m_metaInfo->filePosition()) result.setFileYear(m_metaInfo->filePosition() != UINT_MAX ? m_metaInfo->filePosition() : m_currentFile);
if(!m_metaInfo->fileComment().isEmpty()) result.setFileComment(m_metaInfo->fileComment());
return result;
}
void ProcessingDialog::setCloseButtonEnabled(bool enabled)
{
HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);

View File

@ -35,7 +35,7 @@ class ProcessingDialog : public QDialog, private Ui::ProcessingDialog
Q_OBJECT
public:
ProcessingDialog(FileListModel *fileListModel, SettingsModel *settings);
ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent = 0);
~ProcessingDialog(void);
private slots:
@ -50,13 +50,17 @@ protected:
private:
void setCloseButtonEnabled(bool enabled);
void ProcessingDialog::startNextJob(void);
void startNextJob(void);
AudioFileModel updateMetaInfo(const AudioFileModel &audioFile);
QList<AudioFileModel> m_pendingJobs;
SettingsModel *m_settings;
AudioFileModel *m_metaInfo;
QList<ProcessThread*> m_threadList;
QMovie *m_progressIndicator;
ProgressModel *m_progressModel;
unsigned int m_runningThreads;
unsigned int m_currentFile;
bool m_userAborted;
};

View File

@ -75,13 +75,18 @@ bool MP3Encoder::encode(const AudioFileModel &sourceFile, const QString &outputF
if(!sourceFile.fileName().isEmpty()) args << (IS_UNICODE(sourceFile.fileName()) ? "--uTitle" : "--lTitle") << sourceFile.fileName();
if(!sourceFile.fileArtist().isEmpty()) args << (IS_UNICODE(sourceFile.fileArtist()) ? "--uArtist" : "--lArtist") << sourceFile.fileArtist();
if(!sourceFile.fileAlbum().isEmpty()) args << (IS_UNICODE(sourceFile.fileAlbum()) ? "--uAlbum" : "--lAlbum") << sourceFile.fileAlbum();
if(!sourceFile.fileGenre().isEmpty()) args << (IS_UNICODE(sourceFile.fileGenre()) ? "--uGenre" : "--lGenre") << sourceFile.fileGenre();
if(!sourceFile.fileComment().isEmpty()) args << (IS_UNICODE(sourceFile.fileComment()) ? "--uComment" : "--lComment") << sourceFile.fileComment();
if(sourceFile.fileYear()) args << "--ty" << QString::number(sourceFile.fileYear());
if(sourceFile.filePosition()) args << "--tn" << QString::number(sourceFile.filePosition());
//args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release());
args << QDir::toNativeSeparators(sourceFile.filePath());
args << QDir::toNativeSeparators(outputFile);
process.start(lamexp_lookup_tool("lame.exe"), args);
process.start(m_binary, args);
if(!process.waitForStarted())
{
return false;

View File

@ -140,7 +140,7 @@ int lamexp_main(int argc, char* argv[])
//Show processing dialog
if(bAccepted && fileListModel->rowCount() > 0)
{
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, settingsModel);
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
processingDialog->exec();
LAMEXP_DELETE(processingDialog);
}

View File

@ -24,6 +24,7 @@
#include <QMessageBox>
#include <QInputDialog>
#include <QFileInfo>
#define MODEL_ROW_COUNT 12
@ -251,6 +252,13 @@ void MetaInfoModel::editItem(const QModelIndex &index, QWidget *parent)
temp = QInputDialog::getText(parent, "Edit Title", "Please enter the title for this file:", QLineEdit::Normal, m_audioFile->fileName(), &ok).simplified();
if(ok)
{
if(temp.isEmpty())
{
QMessageBox::warning(parent, "Edit Title", "The title must not be empty. Generating title from file name!");
temp = QFileInfo(m_audioFile->filePath()).completeBaseName().replace("_", " ").simplified();
int index = temp.lastIndexOf(" - ");
if(index >= 0) temp = temp.mid(index + 3).trimmed();
}
beginResetModel();
m_audioFile->setFileName(temp.isEmpty() ? QString() : temp);
endResetModel();

View File

@ -36,11 +36,14 @@ static const char *g_settingsId_compressionEncoder = "Compression/Encoder";
static const char *g_settingsId_compressionRCMode = "Compression/RCMode";
static const char *g_settingsId_compressionBitrate = "Compression/Bitrate";
static const char *g_settingsId_outputDir = "OutputDirectory";
static const char *g_settingsId_writeMetaTags = "WriteMetaTags";
#define MAKE_GETTER(OPT,DEF) int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toInt(); }
#define MAKE_SETTER(OPT) void SettingsModel::OPT(int value) { m_settings->setValue(g_settingsId_##OPT, value); }
#define MAKE_GETTER1(OPT,DEF) int SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toInt(); }
#define MAKE_SETTER1(OPT) void SettingsModel::OPT(int value) { m_settings->setValue(g_settingsId_##OPT, value); }
#define MAKE_GETTER2(OPT,DEF) QString SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toString().trimmed(); }
#define MAKE_SETTER2(OPT) void SettingsModel::OPT(const QString &value) { m_settings->setValue(g_settingsId_##OPT, value); }
#define MAKE_GETTER3(OPT,DEF) bool SettingsModel::OPT(void) { return m_settings->value(g_settingsId_##OPT, DEF).toBool(); }
#define MAKE_SETTER3(OPT) void SettingsModel::OPT(bool value) { m_settings->setValue(g_settingsId_##OPT, value); }
const int SettingsModel::mp3Bitrates[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1};
@ -94,21 +97,23 @@ void SettingsModel::validate(void)
// Getter and Setter
////////////////////////////////////////////////////////////
MAKE_GETTER(licenseAccepted, 0)
MAKE_SETTER(licenseAccepted)
MAKE_GETTER1(licenseAccepted, 0)
MAKE_SETTER1(licenseAccepted)
MAKE_GETTER(interfaceStyle, 0)
MAKE_SETTER(interfaceStyle)
MAKE_GETTER1(interfaceStyle, 0)
MAKE_SETTER1(interfaceStyle)
MAKE_GETTER(compressionEncoder, 0)
MAKE_SETTER(compressionEncoder)
MAKE_GETTER1(compressionEncoder, 0)
MAKE_SETTER1(compressionEncoder)
MAKE_GETTER(compressionRCMode, 0)
MAKE_SETTER(compressionRCMode)
MAKE_GETTER1(compressionRCMode, 0)
MAKE_SETTER1(compressionRCMode)
MAKE_GETTER(compressionBitrate, 0)
MAKE_SETTER(compressionBitrate)
MAKE_GETTER1(compressionBitrate, 0)
MAKE_SETTER1(compressionBitrate)
MAKE_GETTER2(outputDir, QString())
MAKE_SETTER2(outputDir)
MAKE_GETTER3(writeMetaTags, true)
MAKE_SETTER3(writeMetaTags)

View File

@ -24,10 +24,12 @@
class QSettings;
class QString;
#define MAKE_GETTER_DEC(OPT) int OPT(void)
#define MAKE_SETTER_DEC(OPT) void OPT(int value)
#define MAKE_GETTER_DEC1(OPT) int OPT(void)
#define MAKE_SETTER_DEC1(OPT) void OPT(int value)
#define MAKE_GETTER_DEC2(OPT) QString OPT(void)
#define MAKE_SETTER_DEC2(OPT) void OPT(const QString &value)
#define MAKE_GETTER_DEC3(OPT) bool OPT(void)
#define MAKE_SETTER_DEC3(OPT) void OPT(bool value)
class SettingsModel
{
@ -55,21 +57,22 @@ public:
static const int mp3Bitrates[15];
//Getters
MAKE_GETTER_DEC(licenseAccepted);
MAKE_GETTER_DEC(interfaceStyle);
MAKE_GETTER_DEC(compressionEncoder);
MAKE_GETTER_DEC(compressionRCMode);
MAKE_GETTER_DEC(compressionBitrate);
MAKE_GETTER_DEC1(licenseAccepted);
MAKE_GETTER_DEC1(interfaceStyle);
MAKE_GETTER_DEC1(compressionEncoder);
MAKE_GETTER_DEC1(compressionRCMode);
MAKE_GETTER_DEC1(compressionBitrate);
MAKE_GETTER_DEC2(outputDir);
MAKE_GETTER_DEC3(writeMetaTags);
//Setters
MAKE_SETTER_DEC(licenseAccepted);
MAKE_SETTER_DEC(interfaceStyle);
MAKE_SETTER_DEC(compressionBitrate);
MAKE_SETTER_DEC(compressionRCMode);
MAKE_SETTER_DEC(compressionEncoder);
MAKE_SETTER_DEC1(licenseAccepted);
MAKE_SETTER_DEC1(interfaceStyle);
MAKE_SETTER_DEC1(compressionBitrate);
MAKE_SETTER_DEC1(compressionRCMode);
MAKE_SETTER_DEC1(compressionEncoder);
MAKE_SETTER_DEC2(outputDir);
MAKE_SETTER_DEC3(writeMetaTags);
void validate(void);
@ -77,7 +80,9 @@ private:
QSettings *m_settings;
};
#undef MAKE_GETTER_DEC
#undef MAKE_SETTER_DEC
#undef MAKE_GETTER_DEC1
#undef MAKE_SETTER_DEC1
#undef MAKE_GETTER_DEC2
#undef MAKE_SETTER_DEC2
#undef MAKE_GETTER_DEC3
#undef MAKE_SETTER_DEC3

View File

@ -165,7 +165,7 @@ void InitializationThread::initNeroAac(void)
catch(...)
{
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
qWarning("Failed to lock Nero encoder binary -> AAC encoding support will be disabled!");
qWarning("Failed to get excluive lock to Nero encoder binary -> AAC encoding support will be disabled!");
return;
}
@ -178,7 +178,6 @@ void InitializationThread::initNeroAac(void)
{
qWarning("Nero process failed to create!");
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
qDebug("File '%s' does exist?\n%s!\n", neroFileInfo[0].canonicalFilePath().toUtf8().constData(), (neroFileInfo[0].exists() ? "Yes, it still exists" : "Nope, it disappeared"));
process.kill();
process.waitForFinished(-1);
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);