From 6cb34ce0473ba031a9d46822acf79697c1638309 Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Thu, 18 Jan 2024 14:09:14 +0300 Subject: [PATCH] Make ExportMP3 configurable --- modules/mod-mp3/ExportMP3.cpp | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/modules/mod-mp3/ExportMP3.cpp b/modules/mod-mp3/ExportMP3.cpp index 66ab8a25bbe2..afef8f38a3eb 100644 --- a/modules/mod-mp3/ExportMP3.cpp +++ b/modules/mod-mp3/ExportMP3.cpp @@ -73,6 +73,8 @@ #include #include +#include + #include "FileNames.h" #include "float_cast.h" #include "Mix.h" @@ -1644,6 +1646,12 @@ class ExportMP3 final : public ExportPlugin CreateOptionsEditor(int, ExportOptionsEditor::Listener* listener) const override; std::unique_ptr CreateProcessor(int format) const override; + + std::vector GetMimeTypes(int) const override; + + bool ParseConfig( + int formatIndex, const rapidjson::Value& document, + ExportProcessor::Parameters& parameters) const override; }; ExportMP3::ExportMP3() = default; @@ -1671,6 +1679,81 @@ std::unique_ptr ExportMP3::CreateProcessor(int format) const return std::make_unique(); } +std::vector ExportMP3::GetMimeTypes(int) const +{ + return { "audio/mpeg" }; +} + +bool ExportMP3::ParseConfig( + int formatIndex, const rapidjson::Value& document, + ExportProcessor::Parameters& parameters) const +{ + if (!document.IsObject()) + return false; + + MP3OptionID qualityMode; + + if (document.HasMember("mode")) + { + auto& mode = document["mode"]; + if (!mode.IsString()) + return false; + + auto value = mode.GetString(); + + if (value == std::string_view { "SET" }) + qualityMode = MP3OptionIDQualitySET; + else if (value == std::string_view { "VBR" }) + qualityMode = MP3OptionIDQualityVBR; + else if (value == std::string_view { "ABR" }) + qualityMode = MP3OptionIDQualityABR; + else if (value == std::string_view { "CBR" }) + qualityMode = MP3OptionIDQualityCBR; + else + return false; + + parameters.push_back(std::make_tuple(MP3OptionIDMode, value)); + } + else + return false; + + if (document.HasMember("quality")) + { + auto& qualityMember = document["quality"]; + + if (!qualityMember.IsInt()) + return false; + + const auto quality = qualityMember.GetInt(); + + if (qualityMode == MP3OptionIDQualitySET && (quality < 0 || quality > 3)) + return false; + else if ( + qualityMode == MP3OptionIDQualityVBR && (quality < 0 || quality > 9)) + return false; + else if ( + qualityMode == MP3OptionIDQualityABR && + std::find( + fixRateValues.begin(), fixRateValues.end(), + ExportValue { quality }) == + fixRateValues.end()) + return false; + else if ( + qualityMode == MP3OptionIDQualityCBR && + std::find( + fixRateValues.begin(), fixRateValues.end(), + ExportValue { quality }) == + fixRateValues.end()) + return false; + + parameters.push_back(std::make_tuple(qualityMode, quality)); + } + else + return false; + + return true; +} + bool ExportMP3::CheckFileName(wxFileName & WXUNUSED(filename), int WXUNUSED(format)) const { #ifndef DISABLE_DYNAMIC_LOADING_LAME