From a979a3a5d449e7a416de8769c2899b6b7438028a Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 21 Feb 2021 21:43:59 +0100 Subject: [PATCH] Use the built-in tagging capability of Monkey's Audio encoder (available since v5.43) + drop the 'tag.exe' tool. --- LameXP_VS2017.vcxproj | 20 ---------- LameXP_VS2017.vcxproj.filters | 6 --- res/Tools.tag.qrc | 2 - res/_ALL.qrc | 1 - src/Config.h | 2 +- src/Encoder_Abstract.cpp | 3 +- src/Encoder_MAC.cpp | 72 +++++++++++++++++------------------ src/Encoder_MAC.h | 5 ++- src/Encoder_MP3.cpp | 2 +- src/Global.h | 1 + src/Tools.h | 1 - 11 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 res/Tools.tag.qrc diff --git a/LameXP_VS2017.vcxproj b/LameXP_VS2017.vcxproj index 174bc2b0..c3c2cf69 100644 --- a/LameXP_VS2017.vcxproj +++ b/LameXP_VS2017.vcxproj @@ -680,11 +680,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Shared\plugins\i true false - - true - true - false - true true @@ -1970,21 +1965,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Shared\plugins\i true false - - Document - "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -no-compress -name "%(Filename)" "%(FullPath)" - RCC "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" - $(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp;%(Outputs) - "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -no-compress -name "%(Filename)" "%(FullPath)" - RCC "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" - $(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp;%(Outputs) - "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -no-compress -name "%(Filename)" "%(FullPath)" - RCC "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" - $(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp;%(Outputs) - true - true - false - Document "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -no-compress -name "%(Filename)" "%(FullPath)" diff --git a/LameXP_VS2017.vcxproj.filters b/LameXP_VS2017.vcxproj.filters index d7207de5..21d5e126 100644 --- a/LameXP_VS2017.vcxproj.filters +++ b/LameXP_VS2017.vcxproj.filters @@ -493,9 +493,6 @@ Generated Files\QRC - - Generated Files\QRC - Generated Files\QRC @@ -998,9 +995,6 @@ Resources - - Resources - Resources diff --git a/res/Tools.tag.qrc b/res/Tools.tag.qrc deleted file mode 100644 index aa1b7769..00000000 --- a/res/Tools.tag.qrc +++ /dev/null @@ -1,2 +0,0 @@ - -tools/tag.exe diff --git a/res/_ALL.qrc b/res/_ALL.qrc index abf80f55..2eefb198 100644 --- a/res/_ALL.qrc +++ b/res/_ALL.qrc @@ -267,7 +267,6 @@ tools/sox.i686.exe tools/sox.sse2.exe tools/speexdec.exe - tools/tag.exe tools/tta.exe tools/valdec.exe tools/vorbiscomment.exe diff --git a/src/Config.h b/src/Config.h index 0fadff30..9b096d10 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_TYPE RC #define VER_LAMEXP_PATCH 3 -#define VER_LAMEXP_BUILD 2297 +#define VER_LAMEXP_BUILD 2299 #define VER_LAMEXP_CONFG 2188 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Encoder_Abstract.cpp b/src/Encoder_Abstract.cpp index a05561ea..6b2e8961 100644 --- a/src/Encoder_Abstract.cpp +++ b/src/Encoder_Abstract.cpp @@ -128,7 +128,8 @@ bool AbstractEncoder::isUnicode(const QString &original) QString AbstractEncoder::cleanTag(const QString &text) { QString result(text); - result.replace(QChar('"'), "'"); + result.replace(QChar('"'), "'"); result.replace(QChar('\\'), "/"); + result.replace(QChar('|'), "/"); return result; } diff --git a/src/Encoder_MAC.cpp b/src/Encoder_MAC.cpp index 75d6aa39..92d2bdd3 100644 --- a/src/Encoder_MAC.cpp +++ b/src/Encoder_MAC.cpp @@ -28,6 +28,13 @@ #include #include +#define APPEND_TAG(NAME, VALUE) do \ +{ \ + if (!buffer.isEmpty()) buffer += L1C('|'); \ + buffer += QString("%1=%2").arg((NAME), (VALUE)); \ +} \ +while(0) + /////////////////////////////////////////////////////////////////////////////// // Encoder Info /////////////////////////////////////////////////////////////////////////////// @@ -123,12 +130,11 @@ static const g_macEncoderInfo; MACEncoder::MACEncoder(void) : - m_binary_enc(lamexp_tools_lookup(L1S("mac.exe"))), - m_binary_tag(lamexp_tools_lookup(L1S("tag.exe"))) + m_binary(lamexp_tools_lookup(L1S("mac.exe"))) { - if(m_binary_enc.isEmpty() || m_binary_tag.isEmpty()) + if (m_binary.isEmpty()) { - MUTILS_THROW("Error initializing MAC encoder. Tool 'mac.exe' or 'tag.exe' is not registred!"); + MUTILS_THROW("Error initializing MAC encoder. Tool 'mac.exe' is not registred!"); } } @@ -156,7 +162,16 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo break; } - if(!startProcess(process, m_binary_enc, args)) + if (!metaInfo.empty(true)) + { + const QString apeTagsData = createApeTags(metaInfo); + if (!apeTagsData.isEmpty()) + { + args << "-t" << apeTagsData; + } + } + + if(!startProcess(process, m_binary, args)) { return false; } @@ -182,37 +197,7 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo return false; }); - if(result != RESULT_SUCCESS) - { - return false; - } - - if(metaInfo.empty(true)) - { - return true; - } - - emit messageLogged(L1S("\n-------------------------------\n")); - - args.clear(); - args << L1S("APE2") << QDir::toNativeSeparators(outputFile); - - if(!metaInfo.title().isEmpty()) args << QString("Title=%1").arg(cleanTag(metaInfo.title())); - if(!metaInfo.artist().isEmpty()) args << QString("Artist=%1").arg(cleanTag(metaInfo.artist())); - if(!metaInfo.album().isEmpty()) args << QString("Album=%1").arg(cleanTag(metaInfo.album())); - if(!metaInfo.genre().isEmpty()) args << QString("Genre=%1").arg(cleanTag(metaInfo.genre())); - if(!metaInfo.comment().isEmpty()) args << QString("Comment=%1").arg(cleanTag(metaInfo.comment())); - if(metaInfo.year()) args << QString("Year=%1").arg(QString::number(metaInfo.year())); - if(metaInfo.position()) args << QString("Track=%1").arg(QString::number(metaInfo.position())); - - //if(!metaInfo.cover().isEmpty()) args << QString("-add-cover:%1:%2").arg("front", metaInfo.cover()); - - if(!startProcess(process, m_binary_tag, args)) - { - return false; - } - - return (awaitProcess(process, abortFlag) == RESULT_SUCCESS); + return (result == RESULT_SUCCESS); } bool MACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) @@ -232,3 +217,18 @@ const AbstractEncoderInfo *MACEncoder::getEncoderInfo(void) { return &g_macEncoderInfo; } + +QString MACEncoder::createApeTags(const AudioFileModel_MetaInfo &metaInfo) +{ + QString buffer; + + if (!metaInfo.title().isEmpty()) APPEND_TAG(L1S("Title"), cleanTag(metaInfo.title())); + if (!metaInfo.artist().isEmpty()) APPEND_TAG(L1S("Artist"), cleanTag(metaInfo.artist())); + if (!metaInfo.album().isEmpty()) APPEND_TAG(L1S("Album"), cleanTag(metaInfo.album())); + if (!metaInfo.genre().isEmpty()) APPEND_TAG(L1S("Genre"), cleanTag(metaInfo.genre())); + if (!metaInfo.comment().isEmpty()) APPEND_TAG(L1S("Comment"), cleanTag(metaInfo.comment())); + if (metaInfo.year()) APPEND_TAG(L1S("Year"), QString::number(metaInfo.year())); + if (metaInfo.position()) APPEND_TAG(L1S("Track"), QString::number(metaInfo.position())); + + return buffer; +} diff --git a/src/Encoder_MAC.h b/src/Encoder_MAC.h index 45d86f5c..c2795844 100644 --- a/src/Encoder_MAC.h +++ b/src/Encoder_MAC.h @@ -42,6 +42,7 @@ public: static const AbstractEncoderInfo *getEncoderInfo(void); private: - const QString m_binary_enc; - const QString m_binary_tag; + const QString m_binary; + + QString createApeTags(const AudioFileModel_MetaInfo &metaInfo); }; diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index ce60e908..09ea804b 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -227,7 +227,7 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo if(!metaInfo.title().isEmpty()) args << L1S("--tt") << cleanTag(metaInfo.title()); if(!metaInfo.artist().isEmpty()) args << L1S("--ta") << cleanTag(metaInfo.artist()); - if(!metaInfo.album().isEmpty()) args << L1S("--tl") << cleanTag( metaInfo.album()); + if(!metaInfo.album().isEmpty()) args << L1S("--tl") << cleanTag(metaInfo.album()); if(!metaInfo.genre().isEmpty()) args << L1S("--tg") << cleanTag(metaInfo.genre()); if(!metaInfo.comment().isEmpty()) args << L1S("--tc") << cleanTag(metaInfo.comment()); if(metaInfo.year()) args << L1S("--ty") << QString::number(metaInfo.year()); diff --git a/src/Global.h b/src/Global.h index 5697ee23..df55b4ba 100644 --- a/src/Global.h +++ b/src/Global.h @@ -88,4 +88,5 @@ const QString lamexp_version2string(const QString &pattern, unsigned int version /////////////////////////////////////////////////////////////////////////////// #define L1S(STR) (QLatin1String((STR))) +#define L1C(CHR) (QLatin1Char((CHR))) #define NOBREAK(STR) (QString("
%1
").arg((STR))) diff --git a/src/Tools.h b/src/Tools.h index 311eff62..66c9c7c0 100644 --- a/src/Tools.h +++ b/src/Tools.h @@ -115,7 +115,6 @@ g_lamexp_tools[] = {"16a71940aa5e9b393e83cdfb2a4dda4291ea01858f8ba338510013f25f4d7c53b9b5cffb86404ea49ef28e6795182fd5", CPU_TYPE_ALL_SSE, "sox.sse2.exe", 1442, "" }, {"25585ca9e2e025d82d93341a9db8527eb0b4ce451dade607f9784a79ed30e050ced0824835d5467aa0bf0c6b8fe08612", CPU_TYPE_ALL_AVX, "sox.avx.exe", 1442, "" }, {"5a4261e1b41a59d1a5bc92e1d2766422a67454d77e06ea29af392811b7b4704e0f3e494ab9cb6375ce9e39257867c5ed", CPU_TYPE_ALL_ALL, "speexdec.exe", 12, ""}, - {"75d4c18dbb74e2dbf7342698428248d45cc4070d5f95da8831ef755e63dcd7ff9c3a760f289e8ef8b5c06b82548edbd8", CPU_TYPE_ALL_ALL, "tag.exe", 100, ""}, {"a83628880da0b7519ec368a74a92da5a5099d8d46aa0583131f92d7321f47c9e16a1841b2a3fb8ffcca7205ef4b1bb0a", CPU_TYPE_ALL_ALL, "tta.exe", 21, ""}, {"9e1ade2137ea5cee0ad4657971c314a372df3068594fbe4f77d45b9eb65fa7c69e55027b0df81b6fe072a220e9a8ba8a", CPU_TYPE_ALL_ALL, "valdec.exe", 100, "a"}, {"572b9448bf4a338ecb9727951fdfcc5a219cc69896695cc96b9f6b083690e339910e41558968264a38992e45f2be152c", CPU_TYPE_ALL_ALL, "wma2wav.exe", 20111001, ""},