1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Encoder_Wave.h"
26 #include "Model_Settings.h"
32 #define WIN32_LEAN_AND_MEAN
36 #define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
42 class WaveEncoderInfo
: public AbstractEncoderInfo
45 virtual bool isModeSupported(int mode
) const
49 case SettingsModel::VBRMode
:
50 case SettingsModel::ABRMode
:
53 case SettingsModel::CBRMode
:
57 MUTILS_THROW("Bad RC mode specified!");
61 virtual int valueCount(int mode
) const
65 case SettingsModel::VBRMode
:
66 case SettingsModel::ABRMode
:
67 case SettingsModel::CBRMode
:
71 MUTILS_THROW("Bad RC mode specified!");
75 virtual int valueAt(int mode
, int index
) const
79 case SettingsModel::VBRMode
:
80 case SettingsModel::ABRMode
:
81 case SettingsModel::CBRMode
:
85 MUTILS_THROW("Bad RC mode specified!");
89 virtual int valueType(int mode
) const
93 case SettingsModel::VBRMode
:
94 case SettingsModel::ABRMode
:
95 case SettingsModel::CBRMode
:
96 return TYPE_UNCOMPRESSED
;
99 MUTILS_THROW("Bad RC mode specified!");
103 virtual const char *description(void) const
105 static const char* s_description
= "Wave Audio (PCM)";
106 return s_description
;
109 virtual const char *extension(void) const
111 static const char* s_extension
= "wav";
115 virtual bool isResamplingSupported(void) const
120 static const g_waveEncoderInfo
;
122 ///////////////////////////////////////////////////////////////////////////////
123 // Encoder implementation
124 ///////////////////////////////////////////////////////////////////////////////
127 WaveEncoder::WaveEncoder(void)
131 WaveEncoder::~WaveEncoder(void)
135 bool WaveEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int duration
, const QString
&outputFile
, volatile bool *abortFlag
)
137 SHFILEOPSTRUCTW fileOperation
;
138 memset(&fileOperation
, 0, sizeof(SHFILEOPSTRUCTW
));
139 fileOperation
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_NOCONFIRMMKDIR
| FOF_NOERRORUI
| FOF_FILESONLY
;
141 emit
messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile
, outputFile
));
142 fileOperation
.wFunc
= FO_COPY
;
145 if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0)
147 //If the source is in the TEMP folder take shortcut and move the file
148 emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
149 fileOperation.wFunc = FO_MOVE;
153 //...otherwise we actually copy the file in order to keep the source
154 emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
155 fileOperation.wFunc = FO_COPY;
159 size_t srcLen
= wcslen(reinterpret_cast<const wchar_t*>(sourceFile
.utf16())) + 3;
160 wchar_t *srcBuffer
= new wchar_t[srcLen
];
161 memset(srcBuffer
, 0, srcLen
* sizeof(wchar_t));
162 wcsncpy_s(srcBuffer
, srcLen
, reinterpret_cast<const wchar_t*>(sourceFile
.utf16()), _TRUNCATE
);
163 FIX_SEPARATORS (srcBuffer
);
164 fileOperation
.pFrom
= srcBuffer
;
166 size_t outLen
= wcslen(reinterpret_cast<const wchar_t*>(outputFile
.utf16())) + 3;
167 wchar_t *outBuffer
= new wchar_t[outLen
];
168 memset(outBuffer
, 0, outLen
* sizeof(wchar_t));
169 wcsncpy_s(outBuffer
, outLen
, reinterpret_cast<const wchar_t*>(outputFile
.utf16()), _TRUNCATE
);
170 FIX_SEPARATORS (outBuffer
);
171 fileOperation
.pTo
= outBuffer
;
173 emit
statusUpdated(0);
174 int result
= SHFileOperation(&fileOperation
);
175 emit
statusUpdated(100);
177 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", result
));
182 return (result
== 0 && fileOperation
.fAnyOperationsAborted
== false);
185 bool WaveEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
187 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
189 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
197 const AbstractEncoderInfo
*WaveEncoder::getEncoderInfo(void)
199 return &g_waveEncoderInfo
;