Refactored EncoderRegistry::createInstance() method to handle all common encoder parameters at a single place. Also added function to load/store the custom parameters.

This commit is contained in:
LoRd_MuldeR 2013-10-03 17:01:37 +02:00
parent 4faf3a2e40
commit d1cdbd77cd
9 changed files with 98 additions and 70 deletions

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 1346
#define VER_LAMEXP_CONFG 1338
#define VER_LAMEXP_BUILD 1348
#define VER_LAMEXP_CONFG 1348
///////////////////////////////////////////////////////////////////////////////
// LameXP Build Options

View File

@ -413,14 +413,14 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
SET_CHECKBOX_STATE(ui->checkBoxOpusDisableResample, m_settings->opusDisableResample());
ui->checkBoxNeroAAC2PassMode->setEnabled(aacEncoder == SettingsModel::AAC_ENCODER_NERO);
ui->lineEditCustomParamLAME->setText(m_settings->customParametersLAME());
ui->lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEnc());
ui->lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEnc());
ui->lineEditCustomParamFLAC->setText(m_settings->customParametersFLAC());
ui->lineEditCustomParamAften->setText(m_settings->customParametersAften());
ui->lineEditCustomParamOpus->setText(m_settings->customParametersOpus());
ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPath()));
ui->lineEditRenamePattern->setText(m_settings->renameOutputFilesPattern());
ui->lineEditCustomParamLAME ->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::MP3Encoder));
ui->lineEditCustomParamOggEnc ->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::VorbisEncoder));
ui->lineEditCustomParamNeroAAC->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::AACEncoder));
ui->lineEditCustomParamFLAC ->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::FLACEncoder));
ui->lineEditCustomParamAften ->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::AC3Encoder));
ui->lineEditCustomParamOpus ->setText(EncoderRegistry::loadEncoderCustomParams(m_settings, SettingsModel::OpusEncoder));
ui->lineEditCustomTempFolder ->setText(QDir::toNativeSeparators(m_settings->customTempPath()));
ui->lineEditRenamePattern ->setText(m_settings->renameOutputFilesPattern());
m_evenFilterCustumParamsHelp = new CustomEventFilter();
ui->helpCustomParamLAME->installEventFilter(m_evenFilterCustumParamsHelp);
@ -3686,12 +3686,12 @@ void MainWindow::customParamsChanged(void)
ui->labelCustomParamsText->setVisible(customParamsUsed);
ui->labelCustomParamsSpacer->setVisible(customParamsUsed);
m_settings->customParametersLAME(ui->lineEditCustomParamLAME->text());
m_settings->customParametersOggEnc(ui->lineEditCustomParamOggEnc->text());
m_settings->customParametersAacEnc(ui->lineEditCustomParamNeroAAC->text());
m_settings->customParametersFLAC(ui->lineEditCustomParamFLAC->text());
m_settings->customParametersAften(ui->lineEditCustomParamAften->text());
m_settings->customParametersOpus(ui->lineEditCustomParamOpus->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::MP3Encoder, ui->lineEditCustomParamLAME->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::VorbisEncoder, ui->lineEditCustomParamOggEnc->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::AACEncoder, ui->lineEditCustomParamNeroAAC->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::FLACEncoder, ui->lineEditCustomParamFLAC->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::AC3Encoder, ui->lineEditCustomParamAften->text());
EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::OpusEncoder, ui->lineEditCustomParamOpus->text());
}
/*
@ -4001,13 +4001,13 @@ void MainWindow::resetAdvancedOptionsButtonClicked(void)
SET_CHECKBOX_STATE(ui->checkBoxForceStereoDownmix, m_settings->forceStereoDownmixDefault());
SET_CHECKBOX_STATE(ui->checkBoxOpusDisableResample, m_settings->opusDisableResampleDefault());
ui->lineEditCustomParamLAME->setText(m_settings->customParametersLAMEDefault());
ui->lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEncDefault());
ui->lineEditCustomParamLAME ->setText(m_settings->customParametersLAMEDefault());
ui->lineEditCustomParamOggEnc ->setText(m_settings->customParametersOggEncDefault());
ui->lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEncDefault());
ui->lineEditCustomParamFLAC->setText(m_settings->customParametersFLACDefault());
ui->lineEditCustomParamOpus->setText(m_settings->customParametersFLACDefault());
ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
ui->lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
ui->lineEditCustomParamFLAC ->setText(m_settings->customParametersFLACDefault());
ui->lineEditCustomParamOpus ->setText(m_settings->customParametersOpusEncDefault());
ui->lineEditCustomTempFolder ->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
ui->lineEditRenamePattern ->setText(m_settings->renameOutputFilesPatternDefault());
if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth) ui->radioButtonOverwriteModeKeepBoth->click();
if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile) ui->radioButtonOverwriteModeSkipFile->click();

View File

@ -40,7 +40,7 @@ AbstractEncoder::~AbstractEncoder(void)
void AbstractEncoder::setBitrate(int bitrate) { m_configBitrate = qMax(0, bitrate); }
void AbstractEncoder::setRCMode(int mode) { m_configRCMode = qMax(0, mode); }
void AbstractEncoder::setCustomParams(const QString &customParams) { m_configCustomParams = customParams; }
void AbstractEncoder::setCustomParams(const QString &customParams) { m_configCustomParams = customParams.trimmed(); }
/*
* Default implementation

View File

@ -243,11 +243,6 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &meta
return true;
}
void VorbisEncoder::setBitrate(int bitrate)
{
m_configBitrate = qMax(-2, bitrate);
}
QString VorbisEncoder::extension(void)
{
return "ogg";

View File

@ -38,7 +38,6 @@ public:
virtual QString extension(void);
virtual void setBitrateLimits(int minimumBitrate, int maximumBitrate);
virtual void setSamplingRate(int value);
virtual void setBitrate(int bitrate);
//Encoder info
static const AbstractEncoderInfo *getEncoderInfo(void);

View File

@ -216,10 +216,12 @@ LAMEXP_MAKE_ID(currentLanguage, "Localization/Language");
LAMEXP_MAKE_ID(currentLanguageFile, "Localization/UseQMFile");
LAMEXP_MAKE_ID(customParametersAacEnc, "AdvancedOptions/CustomParameters/AacEnc");
LAMEXP_MAKE_ID(customParametersAften, "AdvancedOptions/CustomParameters/Aften");
LAMEXP_MAKE_ID(customParametersDcaEnc, "AdvancedOptions/CustomParameters/DcaEnc");
LAMEXP_MAKE_ID(customParametersFLAC, "AdvancedOptions/CustomParameters/FLAC");
LAMEXP_MAKE_ID(customParametersLAME, "AdvancedOptions/CustomParameters/LAME");
LAMEXP_MAKE_ID(customParametersOggEnc, "AdvancedOptions/CustomParameters/OggEnc");
LAMEXP_MAKE_ID(customParametersOpus, "AdvancedOptions/CustomParameters/OpusEnc");
LAMEXP_MAKE_ID(customParametersOpusEnc, "AdvancedOptions/CustomParameters/OpusEnc");
LAMEXP_MAKE_ID(customParametersWave, "AdvancedOptions/CustomParameters/Wave");
LAMEXP_MAKE_ID(customTempPath, "AdvancedOptions/TempDirectory/CustomPath");
LAMEXP_MAKE_ID(customTempPathEnabled, "AdvancedOptions/TempDirectory/UseCustomPath");
LAMEXP_MAKE_ID(dropBoxWidgetEnabled, "Flags/EnableDropBoxWidget");
@ -599,10 +601,12 @@ LAMEXP_MAKE_OPTION_S(currentLanguage, defaultLanguage())
LAMEXP_MAKE_OPTION_S(currentLanguageFile, QString())
LAMEXP_MAKE_OPTION_S(customParametersAacEnc, QString())
LAMEXP_MAKE_OPTION_S(customParametersAften, QString())
LAMEXP_MAKE_OPTION_S(customParametersDcaEnc, QString())
LAMEXP_MAKE_OPTION_S(customParametersFLAC, QString())
LAMEXP_MAKE_OPTION_S(customParametersLAME, QString())
LAMEXP_MAKE_OPTION_S(customParametersOggEnc, QString())
LAMEXP_MAKE_OPTION_S(customParametersOpus, QString())
LAMEXP_MAKE_OPTION_S(customParametersOpusEnc, QString())
LAMEXP_MAKE_OPTION_S(customParametersWave, QString())
LAMEXP_MAKE_OPTION_S(customTempPath, QDesktopServices::storageLocation(QDesktopServices::TempLocation))
LAMEXP_MAKE_OPTION_B(customTempPathEnabled, false)
LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled, true)

View File

@ -145,10 +145,12 @@ public:
LAMEXP_MAKE_OPTION_S(currentLanguageFile)
LAMEXP_MAKE_OPTION_S(customParametersAacEnc)
LAMEXP_MAKE_OPTION_S(customParametersAften)
LAMEXP_MAKE_OPTION_S(customParametersDcaEnc)
LAMEXP_MAKE_OPTION_S(customParametersFLAC)
LAMEXP_MAKE_OPTION_S(customParametersLAME)
LAMEXP_MAKE_OPTION_S(customParametersOggEnc)
LAMEXP_MAKE_OPTION_S(customParametersOpus)
LAMEXP_MAKE_OPTION_S(customParametersOpusEnc)
LAMEXP_MAKE_OPTION_S(customParametersWave)
LAMEXP_MAKE_OPTION_S(customTempPath)
LAMEXP_MAKE_OPTION_B(customTempPathEnabled)
LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled)

View File

@ -48,21 +48,13 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
AbstractEncoder *encoder = NULL;
*nativeResampling = false;
//Sanity checking
if((rcMode < SettingsModel::VBRMode) || (rcMode > SettingsModel::CBRMode))
{
throw "Unknown rate-control mode!";
}
//Create new encoder instance
//Create new encoder instance and apply encoder-specific settings
switch(encoderId)
{
/*-------- MP3Encoder /*--------*/
case SettingsModel::MP3Encoder:
{
MP3Encoder *mp3Encoder = new MP3Encoder();
mp3Encoder->setRCMode(rcMode = settings->compressionRCModeLAME());
mp3Encoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityLAME() : settings->compressionAbrBitrateLAME());
mp3Encoder->setAlgoQuality(settings->lameAlgoQuality());
if(settings->bitrateManagementEnabled())
{
@ -74,7 +66,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
*nativeResampling = true;
}
mp3Encoder->setChannelMode(settings->lameChannelMode());
mp3Encoder->setCustomParams(settings->customParametersLAME());
encoder = mp3Encoder;
}
break;
@ -82,8 +73,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::VorbisEncoder:
{
VorbisEncoder *vorbisEncoder = new VorbisEncoder();
vorbisEncoder->setRCMode(rcMode = settings->compressionRCModeOggEnc());
vorbisEncoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityOggEnc() : settings->compressionAbrBitrateOggEnc());
if(settings->bitrateManagementEnabled())
{
vorbisEncoder->setBitrateLimits(settings->bitrateManagementMinRate(), settings->bitrateManagementMaxRate());
@ -93,7 +82,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
vorbisEncoder->setSamplingRate(SettingsModel::samplingRates[settings->samplingRate()]);
*nativeResampling = true;
}
vorbisEncoder->setCustomParams(settings->customParametersOggEnc());
encoder = vorbisEncoder;
}
break;
@ -105,31 +93,22 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::AAC_ENCODER_QAAC:
{
QAACEncoder *aacEncoder = new QAACEncoder();
aacEncoder->setRCMode(rcMode = settings->compressionRCModeAacEnc());
aacEncoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityAacEnc() : settings->compressionAbrBitrateAacEnc());
aacEncoder->setProfile(settings->aacEncProfile());
aacEncoder->setCustomParams(settings->customParametersAacEnc());
encoder = aacEncoder;
}
break;
case SettingsModel::AAC_ENCODER_FHG:
{
FHGAACEncoder *aacEncoder = new FHGAACEncoder();
aacEncoder->setRCMode(rcMode = settings->compressionRCModeAacEnc());
aacEncoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityAacEnc() : settings->compressionAbrBitrateAacEnc());
aacEncoder->setProfile(settings->aacEncProfile());
aacEncoder->setCustomParams(settings->customParametersAacEnc());
encoder = aacEncoder;
}
break;
case SettingsModel::AAC_ENCODER_NERO:
{
AACEncoder *aacEncoder = new AACEncoder();
aacEncoder->setRCMode(rcMode = settings->compressionRCModeAacEnc());
aacEncoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityAacEnc() : settings->compressionAbrBitrateAacEnc());
aacEncoder->setEnable2Pass(settings->neroAACEnable2Pass());
aacEncoder->setProfile(settings->aacEncProfile());
aacEncoder->setCustomParams(settings->customParametersAacEnc());
encoder = aacEncoder;
}
break;
@ -143,9 +122,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::AC3Encoder:
{
AC3Encoder *ac3Encoder = new AC3Encoder();
ac3Encoder->setRCMode(rcMode = settings->compressionRCModeAften());
ac3Encoder->setBitrate(IS_VBR(rcMode) ? settings->compressionVbrQualityAften() : settings->compressionAbrBitrateAften());
ac3Encoder->setCustomParams(settings->customParametersAften());
ac3Encoder->setAudioCodingMode(settings->aftenAudioCodingMode());
ac3Encoder->setDynamicRangeCompression(settings->aftenDynamicRangeCompression());
ac3Encoder->setExponentSearchSize(settings->aftenExponentSearchSize());
@ -157,9 +133,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::FLACEncoder:
{
FLACEncoder *flacEncoder = new FLACEncoder();
flacEncoder->setBitrate(settings->compressionVbrQualityFLAC());
flacEncoder->setRCMode(SettingsModel::VBRMode);
flacEncoder->setCustomParams(settings->customParametersFLAC());
encoder = flacEncoder;
}
break;
@ -167,12 +140,9 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::OpusEncoder:
{
OpusEncoder *opusEncoder = new OpusEncoder();
opusEncoder->setRCMode(rcMode = settings->compressionRCModeOpusEnc());
opusEncoder->setBitrate(settings->compressionAbrBitrateOpusEnc()); /*Opus always uses bitrate*/
opusEncoder->setOptimizeFor(settings->opusOptimizeFor());
opusEncoder->setEncodeComplexity(settings->opusComplexity());
opusEncoder->setFrameSize(settings->opusFramesize());
opusEncoder->setCustomParams(settings->customParametersOpus());
encoder = opusEncoder;
}
break;
@ -180,8 +150,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::DCAEncoder:
{
DCAEncoder *dcaEncoder = new DCAEncoder();
dcaEncoder->setRCMode(SettingsModel::CBRMode);
dcaEncoder->setBitrate(IS_VBR(rcMode) ? 0 : settings->compressionAbrBitrateDcaEnc());
encoder = dcaEncoder;
}
break;
@ -189,8 +157,6 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
case SettingsModel::PCMEncoder:
{
WaveEncoder *waveEncoder = new WaveEncoder();
waveEncoder->setBitrate(0); /*does NOT apply to PCM output*/
waveEncoder->setRCMode(0); /*does NOT apply to PCM output*/
encoder = waveEncoder;
}
break;
@ -205,6 +171,11 @@ AbstractEncoder *EncoderRegistry::createInstance(const int encoderId, const Sett
throw "No encoder instance has been assigend!";
}
//Apply common settings
encoder->setRCMode(rcMode = loadEncoderMode(settings, encoderId));
encoder->setCustomParams(loadEncoderCustomParams(settings, encoderId));
encoder->setBitrate(loadEncoderValue(settings, encoderId, rcMode));
return encoder;
}
@ -285,7 +256,7 @@ void EncoderRegistry::saveEncoderMode(SettingsModel *settings, const int encoder
}
}
int EncoderRegistry::loadEncoderMode(SettingsModel *settings, const int encoderId)
int EncoderRegistry::loadEncoderMode(const SettingsModel *settings, const int encoderId)
{
int rcMode = -1;
@ -376,6 +347,60 @@ int EncoderRegistry::loadEncoderValue(const SettingsModel *settings, const int e
return value;
}
////////////////////////////////////////////////////////////
// Load/store encoder custom parameters
////////////////////////////////////////////////////////////
#define STORE_PARAMS(ENCODER_ID, PARAMS) do \
{ \
settings->customParameters##ENCODER_ID(PARAMS); \
} \
while(0)
#define LOAD_PARAMS(PARAMS, ENCODER_ID) do \
{ \
(PARAMS) = settings->customParameters##ENCODER_ID(); \
} \
while(0)
void EncoderRegistry::saveEncoderCustomParams(SettingsModel *settings, const int encoderId, const QString params)
{
//Store the encoder bitrate/quality value
switch(encoderId)
{
case SettingsModel::MP3Encoder: STORE_PARAMS(LAME, params.trimmed()); break;
case SettingsModel::VorbisEncoder: STORE_PARAMS(OggEnc, params.trimmed()); break;
case SettingsModel::AACEncoder: STORE_PARAMS(AacEnc, params.trimmed()); break;
case SettingsModel::AC3Encoder: STORE_PARAMS(Aften, params.trimmed()); break;
case SettingsModel::FLACEncoder: STORE_PARAMS(FLAC, params.trimmed()); break;
case SettingsModel::OpusEncoder: STORE_PARAMS(OpusEnc, params.trimmed()); break;
case SettingsModel::DCAEncoder: STORE_PARAMS(DcaEnc, params.trimmed()); break;
case SettingsModel::PCMEncoder: STORE_PARAMS(Wave, params.trimmed()); break;
default: throw "Unsupported encoder!";
}
}
QString EncoderRegistry::loadEncoderCustomParams(const SettingsModel *settings, const int encoderId)
{
QString params;
//Load the encoder bitrate/quality value
switch(encoderId)
{
case SettingsModel::MP3Encoder: LOAD_PARAMS(params, LAME); break;
case SettingsModel::VorbisEncoder: LOAD_PARAMS(params, OggEnc); break;
case SettingsModel::AACEncoder: LOAD_PARAMS(params, AacEnc); break;
case SettingsModel::AC3Encoder: LOAD_PARAMS(params, Aften); break;
case SettingsModel::FLACEncoder: LOAD_PARAMS(params, FLAC); break;
case SettingsModel::OpusEncoder: LOAD_PARAMS(params, OpusEnc); break;
case SettingsModel::DCAEncoder: LOAD_PARAMS(params, DcaEnc); break;
case SettingsModel::PCMEncoder: LOAD_PARAMS(params, Wave); break;
default: throw "Unsupported encoder!";
}
return params;
}
////////////////////////////////////////////////////////////
// Reset encoder settings
////////////////////////////////////////////////////////////

View File

@ -36,11 +36,14 @@ public:
static const AbstractEncoderInfo *getEncoderInfo(const int encoderId);
static void saveEncoderMode(SettingsModel *settings, const int encoderId, const int rcMode);
static int loadEncoderMode(SettingsModel *settings, const int encoderId);
static int loadEncoderMode(const SettingsModel *settings, const int encoderId);
static void saveEncoderValue(SettingsModel *settings, const int encoderId, const int rcMode, const int value);
static int loadEncoderValue(const SettingsModel *settings, const int encoderId, const int rcMode);
static void saveEncoderCustomParams(SettingsModel *settings, const int encoderId, const QString params);
static QString loadEncoderCustomParams(const SettingsModel *settings, const int encoderId);
static void resetAllEncoders(SettingsModel *settings);
static int getAacEncoder(void);
};