Skip to content

Commit

Permalink
Make ExportMP3 configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Jan 23, 2024
1 parent 753d766 commit 6cb34ce
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions modules/mod-mp3/ExportMP3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#include <wx/textctrl.h>
#include <wx/choice.h>

#include <rapidjson/document.h>

#include "FileNames.h"
#include "float_cast.h"
#include "Mix.h"
Expand Down Expand Up @@ -1644,6 +1646,12 @@ class ExportMP3 final : public ExportPlugin
CreateOptionsEditor(int, ExportOptionsEditor::Listener* listener) const override;

std::unique_ptr<ExportProcessor> CreateProcessor(int format) const override;

std::vector<std::string> GetMimeTypes(int) const override;

bool ParseConfig(
int formatIndex, const rapidjson::Value& document,
ExportProcessor::Parameters& parameters) const override;
};

ExportMP3::ExportMP3() = default;
Expand Down Expand Up @@ -1671,6 +1679,81 @@ std::unique_ptr<ExportProcessor> ExportMP3::CreateProcessor(int format) const
return std::make_unique<MP3ExportProcessor>();
}

std::vector<std::string> 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
Expand Down

0 comments on commit 6cb34ce

Please sign in to comment.