From e189eb08c291e8b006cc4fb40e305dbc053b2fe7 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 17 Dec 2010 01:12:12 +0100 Subject: [PATCH] Support for Wave (PCM) output. --- LameXP.vcproj | 42 ++++++++++++++++++ src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 18 ++++++-- src/Dialog_Processing.cpp | 9 ++++ src/Encoder_Wave.cpp | 93 +++++++++++++++++++++++++++++++++++++++ src/Encoder_Wave.h | 39 ++++++++++++++++ 6 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 src/Encoder_Wave.cpp create mode 100644 src/Encoder_Wave.h diff --git a/LameXP.vcproj b/LameXP.vcproj index a18e6110..37fe6f69 100644 --- a/LameXP.vcproj +++ b/LameXP.vcproj @@ -366,6 +366,10 @@ RelativePath=".\src\Encoder_Vorbis.cpp" > + + @@ -944,6 +948,40 @@ /> + + + + + + + + + + + @@ -1352,6 +1390,10 @@ RelativePath=".\tmp\MOC_Encoder_Vorbis.cpp" > + + diff --git a/src/Config.h b/src/Config.h index 72c4783b..4b1df0e8 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 157 +#define VER_LAMEXP_BUILD 161 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index df27a484..59c5d824 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -599,9 +599,10 @@ void MainWindow::encodeButtonClicked(void) case SettingsModel::VorbisEncoder: case SettingsModel::AACEncoder: case SettingsModel::FLACEncoder: + case SettingsModel::PCMEncoder: break; default: - QMessageBox::warning(this, "LameXP", "Sorry, only MP3, Vorbis, AAC and FLAC encoding is supported at the moment.
Support for more encoders to be added in later versions!"); + QMessageBox::warning(this, "LameXP", "Sorry, an unsupported encoder has been chosen!"); tabWidget->setCurrentIndex(3); return; } @@ -815,6 +816,10 @@ void MainWindow::styleActionActivated(QAction *action) */ void MainWindow::outputFolderViewClicked(const QModelIndex &index) { + if(outputFolderView->currentIndex() != index) + { + outputFolderView->setCurrentIndex(index); + } QString selectedDir = m_fileSystemModel->filePath(index); if(selectedDir.length() < 3) selectedDir.append(QDir::separator()); outputFolderLabel->setText(selectedDir); @@ -1288,7 +1293,10 @@ void MainWindow::restoreCursor(void) */ void MainWindow::sourceFilesContextMenu(const QPoint &pos) { - m_sourceFilesContextMenu->popup(sourceFileView->mapToGlobal(pos)); + if(pos.x() <= sourceFileView->width() && pos.y() <= sourceFileView->height() && pos.x() >= 0 && pos.y() >= 0) + { + m_sourceFilesContextMenu->popup(sourceFileView->mapToGlobal(pos)); + } } /* @@ -1366,7 +1374,11 @@ void MainWindow::findFileContextActionTriggered(void) */ void MainWindow::outputFolderContextMenu(const QPoint &pos) { - m_outputFolderContextMenu->popup(outputFolderView->mapToGlobal(pos)); + + if(pos.x() <= outputFolderView->width() && pos.y() <= outputFolderView->height() && pos.x() >= 0 && pos.y() >= 0) + { + m_outputFolderContextMenu->popup(outputFolderView->mapToGlobal(pos)); + } } /* diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index e9ce828b..dacfe1aa 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -32,6 +32,7 @@ #include "Encoder_Vorbis.h" #include "Encoder_AAC.h" #include "Encoder_FLAC.h" +#include "Encoder_Wave.h" #include "WinSevenTaskbar.h" #include @@ -455,6 +456,14 @@ void ProcessingDialog::startNextJob(void) encoder = flacEncoder; } break; + case SettingsModel::PCMEncoder: + { + WaveEncoder *waveEncoder = new WaveEncoder(); + waveEncoder->setBitrate(m_settings->compressionBitrate()); + waveEncoder->setRCMode(m_settings->compressionRCMode()); + encoder = waveEncoder; + } + break; default: throw "Unsupported encoder!"; } diff --git a/src/Encoder_Wave.cpp b/src/Encoder_Wave.cpp new file mode 100644 index 00000000..f4d834c9 --- /dev/null +++ b/src/Encoder_Wave.cpp @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#include "Encoder_Wave.h" + +#include "Global.h" +#include "Model_Settings.h" + +#include +#include + +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define IS_UNICODE(STR) (qstricmp(STR.toUtf8().constData(), QString::fromLocal8Bit(STR.toLocal8Bit()).toUtf8().constData())) +#define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; } + +WaveEncoder::WaveEncoder(void) +{ +} + +WaveEncoder::~WaveEncoder(void) +{ +} + +bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) +{ + emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); + + SHFILEOPSTRUCTW fileOperation; + memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW)); + fileOperation.wFunc = FO_MOVE; + fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY; + + size_t srcLen = wcslen(reinterpret_cast(sourceFile.utf16())) + 3; + wchar_t *srcBuffer = new wchar_t[srcLen]; + memset(srcBuffer, 0, srcLen * sizeof(wchar_t)); + wcscpy_s(srcBuffer, srcLen, reinterpret_cast(sourceFile.utf16())); + FIX_SEPARATORS (srcBuffer); + fileOperation.pFrom = srcBuffer; + + size_t outLen = wcslen(reinterpret_cast(outputFile.utf16())) + 3; + wchar_t *outBuffer = new wchar_t[outLen]; + memset(outBuffer, 0, outLen * sizeof(wchar_t)); + wcscpy_s(outBuffer, outLen, reinterpret_cast(outputFile.utf16())); + FIX_SEPARATORS (outBuffer); + fileOperation.pTo = outBuffer; + + emit statusUpdated(0); + int result = SHFileOperation(&fileOperation); + emit statusUpdated(100); + + emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result)); + + delete [] srcBuffer; + delete [] outBuffer; + + return (result == 0 && fileOperation.fAnyOperationsAborted == false); +} + +QString WaveEncoder::extension(void) +{ + return "wav"; +} + +bool WaveEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) +{ + if(containerType.compare("Wave", Qt::CaseInsensitive) == 0) + { + if(formatType.compare("PCM", Qt::CaseInsensitive) == 0) + { + return true; + } + } + return false; +} diff --git a/src/Encoder_Wave.h b/src/Encoder_Wave.h new file mode 100644 index 00000000..5500bc1c --- /dev/null +++ b/src/Encoder_Wave.h @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "Encoder_Abstract.h" + +#include + +class WaveEncoder : public AbstractEncoder +{ + Q_OBJECT + +public: + WaveEncoder(void); + ~WaveEncoder(void); + + virtual bool encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag); + virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion); + virtual QString extension(void); +};