Updated Simplified Chinese translation, thanks to <kidneybean@sohu.com>.
[LameXP.git] / src / Encoder_Wave.cpp
blob0a9c85dae4c924cc565b3bb8ed386383843652a5
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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 "Encoder_Wave.h"
24 #include "Global.h"
25 #include "Model_Settings.h"
27 #include <QDir>
29 //Windows includes
30 #define NOMINMAX
31 #define WIN32_LEAN_AND_MEAN
32 #include <Windows.h>
33 #include <Shellapi.h>
35 #define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
37 ///////////////////////////////////////////////////////////////////////////////
38 // Encoder Info
39 ///////////////////////////////////////////////////////////////////////////////
41 class WaveEncoderInfo : public AbstractEncoderInfo
43 public:
44 virtual bool isModeSupported(int mode) const
46 switch(mode)
48 case SettingsModel::VBRMode:
49 case SettingsModel::ABRMode:
50 return false;
51 break;
52 case SettingsModel::CBRMode:
53 return true;
54 break;
55 default:
56 throw "Bad RC mode specified!";
60 virtual int valueCount(int mode) const
62 switch(mode)
64 case SettingsModel::VBRMode:
65 case SettingsModel::ABRMode:
66 case SettingsModel::CBRMode:
67 return 0;
68 break;
69 default:
70 throw "Bad RC mode specified!";
74 virtual int valueAt(int mode, int index) const
76 switch(mode)
78 case SettingsModel::VBRMode:
79 case SettingsModel::ABRMode:
80 case SettingsModel::CBRMode:
81 return -1;
82 break;
83 default:
84 throw "Bad RC mode specified!";
88 virtual int valueType(int mode) const
90 switch(mode)
92 case SettingsModel::VBRMode:
93 case SettingsModel::ABRMode:
94 case SettingsModel::CBRMode:
95 return TYPE_UNCOMPRESSED;
96 break;
97 default:
98 throw "Bad RC mode specified!";
102 virtual const char *description(void) const
104 static const char* s_description = "Wave Audio (PCM)";
105 return s_description;
108 static const g_waveEncoderInfo;
110 ///////////////////////////////////////////////////////////////////////////////
111 // Encoder implementation
112 ///////////////////////////////////////////////////////////////////////////////
115 WaveEncoder::WaveEncoder(void)
119 WaveEncoder::~WaveEncoder(void)
123 bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag)
125 SHFILEOPSTRUCTW fileOperation;
126 memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));
127 fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
129 emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
130 fileOperation.wFunc = FO_COPY;
133 if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0)
135 //If the source is in the TEMP folder take shortcut and move the file
136 emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
137 fileOperation.wFunc = FO_MOVE;
139 else
141 //...otherwise we actually copy the file in order to keep the source
142 emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
143 fileOperation.wFunc = FO_COPY;
147 size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3;
148 wchar_t *srcBuffer = new wchar_t[srcLen];
149 memset(srcBuffer, 0, srcLen * sizeof(wchar_t));
150 wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE);
151 FIX_SEPARATORS (srcBuffer);
152 fileOperation.pFrom = srcBuffer;
154 size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3;
155 wchar_t *outBuffer = new wchar_t[outLen];
156 memset(outBuffer, 0, outLen * sizeof(wchar_t));
157 wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE);
158 FIX_SEPARATORS (outBuffer);
159 fileOperation.pTo = outBuffer;
161 emit statusUpdated(0);
162 int result = SHFileOperation(&fileOperation);
163 emit statusUpdated(100);
165 emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result));
167 delete [] srcBuffer;
168 delete [] outBuffer;
170 return (result == 0 && fileOperation.fAnyOperationsAborted == false);
173 QString WaveEncoder::extension(void)
175 return "wav";
178 bool WaveEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
180 if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
182 if(formatType.compare("PCM", Qt::CaseInsensitive) == 0)
184 return true;
187 return false;
190 const AbstractEncoderInfo *WaveEncoder::getEncoderInfo(void)
192 return &g_waveEncoderInfo;