1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2023 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; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "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_MAC.h"
26 #include "Model_Settings.h"
31 #define APPEND_TAG(NAME, VALUE) do \
33 if (!buffer.isEmpty()) buffer += L1C('|'); \
34 buffer += QString("%1=%2").arg((NAME), (VALUE)); \
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
42 class MACEncoderInfo
: public AbstractEncoderInfo
44 virtual bool isModeSupported(int mode
) const
48 case SettingsModel::VBRMode
:
51 case SettingsModel::ABRMode
:
52 case SettingsModel::CBRMode
:
56 MUTILS_THROW("Bad RC mode specified!");
60 virtual int valueCount(int mode
) const
64 case SettingsModel::VBRMode
:
67 case SettingsModel::ABRMode
:
68 case SettingsModel::CBRMode
:
72 MUTILS_THROW("Bad RC mode specified!");
76 virtual int valueAt(int mode
, int index
) const
80 case SettingsModel::VBRMode
:
81 return qBound(0, index
+ 1, 8);
83 case SettingsModel::ABRMode
:
84 case SettingsModel::CBRMode
:
88 MUTILS_THROW("Bad RC mode specified!");
92 virtual int valueType(int mode
) const
96 case SettingsModel::VBRMode
:
97 return TYPE_COMPRESSION_LEVEL
;
99 case SettingsModel::ABRMode
:
100 case SettingsModel::CBRMode
:
104 MUTILS_THROW("Bad RC mode specified!");
108 virtual const char *description(void) const
110 static const char* s_description
= "Monkey's Audio (MAC)";
111 return s_description
;
114 virtual const char *extension(void) const
116 static const char* s_extension
= "ape";
120 virtual bool isResamplingSupported(void) const
125 static const g_macEncoderInfo
;
127 ///////////////////////////////////////////////////////////////////////////////
128 // Encoder implementation
129 ///////////////////////////////////////////////////////////////////////////////
131 MACEncoder::MACEncoder(void)
133 m_binary(lamexp_tools_lookup(L1S("mac.exe")))
135 if (m_binary
.isEmpty())
137 MUTILS_THROW("Error initializing MAC encoder. Tool 'mac.exe' is not registred!");
141 MACEncoder::~MACEncoder(void)
145 bool MACEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int /*duration*/, const unsigned int /*channels*/, const QString
&outputFile
, QAtomicInt
&abortFlag
)
150 const QString baseName
= QFileInfo(outputFile
).fileName();
152 args
<< QDir::toNativeSeparators(sourceFile
);
153 args
<< QDir::toNativeSeparators(outputFile
);
155 switch(m_configRCMode
)
157 case SettingsModel::VBRMode
:
158 args
<< QString().sprintf("-c%d", (m_configBitrate
+ 1) * 1000);
161 MUTILS_THROW("Bad rate-control mode!");
165 if (!metaInfo
.empty(true))
167 const QString apeTagsData
= createApeTags(metaInfo
);
168 if (!apeTagsData
.isEmpty())
170 args
<< "-t" << apeTagsData
;
174 if(!startProcess(process
, m_binary
, args
))
179 int prevProgress
= -1;
180 QRegExp
regExp(L1S("Progress: (\\d+).(\\d+)%"));
182 const result_t result
= awaitProcess(process
, abortFlag
, [this, &prevProgress
, ®Exp
](const QString
&text
)
184 if (regExp
.lastIndexIn(text
) >= 0)
187 if (MUtils::regexp_parse_int32(regExp
, newProgress
))
189 if (newProgress
> prevProgress
)
191 emit
statusUpdated(newProgress
);
192 prevProgress
= NEXT_PROGRESS(newProgress
);
200 return (result
== RESULT_SUCCESS
);
203 bool MACEncoder::isFormatSupported(const QString
&containerType
, const QString
& /*containerProfile*/, const QString
&formatType
, const QString
& /*formatProfile*/, const QString
& /*formatVersion*/)
205 if(containerType
.compare(L1S("Wave"), Qt::CaseInsensitive
) == 0)
207 if(formatType
.compare(L1S("PCM"), Qt::CaseInsensitive
) == 0)
216 const AbstractEncoderInfo
*MACEncoder::getEncoderInfo(void)
218 return &g_macEncoderInfo
;
221 QString
MACEncoder::createApeTags(const AudioFileModel_MetaInfo
&metaInfo
)
225 if (!metaInfo
.title().isEmpty()) APPEND_TAG(L1S("Title"), cleanTag(metaInfo
.title()));
226 if (!metaInfo
.artist().isEmpty()) APPEND_TAG(L1S("Artist"), cleanTag(metaInfo
.artist()));
227 if (!metaInfo
.album().isEmpty()) APPEND_TAG(L1S("Album"), cleanTag(metaInfo
.album()));
228 if (!metaInfo
.genre().isEmpty()) APPEND_TAG(L1S("Genre"), cleanTag(metaInfo
.genre()));
229 if (!metaInfo
.comment().isEmpty()) APPEND_TAG(L1S("Comment"), cleanTag(metaInfo
.comment()));
230 if (metaInfo
.year()) APPEND_TAG(L1S("Year"), QString::number(metaInfo
.year()));
231 if (metaInfo
.position()) APPEND_TAG(L1S("Track"), QString::number(metaInfo
.position()));