1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +02:00

Rewrite threshold control of Truncate Silence as text box, not a choice

This commit is contained in:
Paul Licameli 2018-05-09 23:09:01 -04:00
parent a22be24ae3
commit b3bf321893
2 changed files with 42 additions and 29 deletions

View File

@ -37,13 +37,13 @@
class Enums { class Enums {
public: public:
static const size_t NumDbChoices; static const size_t NumDbChoices;
static const double Db2Signal[];
static const IdentInterfaceSymbol DbChoices[]; static const IdentInterfaceSymbol DbChoices[];
}; };
const IdentInterfaceSymbol Enums::DbChoices[] = { const IdentInterfaceSymbol Enums::DbChoices[] = {
// Yuck, why is this a choice control and not a slider? I'm leaving this // Table of text values, only for reading what was stored in legacy config
// table of names alone for now -- PRL // files.
// It was inappropriate to make this a discrete choice control.
{ wxT("-20 dB") }, { wxT("-20 dB") },
{ wxT("-25 dB") }, { wxT("-25 dB") },
{ wxT("-30 dB") }, { wxT("-30 dB") },
@ -59,16 +59,11 @@ const IdentInterfaceSymbol Enums::DbChoices[] = {
{ wxT("-80 dB") } { wxT("-80 dB") }
}; };
const double Enums::Db2Signal[] = // Map from position in table above to numerical value.
// -20dB -25dB -30dB -35dB -40dB -45dB -50dB -55dB -60dB -65dB -70dB -75dB -80dB static inline double enumToDB( int val ) { return -( 5.0 * val + 20.0 ); }
{ 0.10000, 0.05620, 0.03160, 0.01780, 0.01000, 0.00562, 0.00316, 0.00178, 0.00100, 0.000562, 0.000316, 0.000178, 0.0001000 };
const size_t Enums::NumDbChoices = WXSIZEOF(Enums::DbChoices); const size_t Enums::NumDbChoices = WXSIZEOF(Enums::DbChoices);
static_assert( Enums::NumDbChoices == WXSIZEOF( Enums::Db2Signal ),
"size mismatch" );
// Declaration of RegionList // Declaration of RegionList
class RegionList : public std::list < Region > {}; class RegionList : public std::list < Region > {};
@ -102,7 +97,11 @@ static const size_t nObsoleteActions = WXSIZEOF( kObsoleteActions );
// Define keys, defaults, minimums, and maximums for the effect parameters // Define keys, defaults, minimums, and maximums for the effect parameters
// //
// Name Type Key Def Min Max Scale // Name Type Key Def Min Max Scale
// This one is legacy and is intentionally not reported by DefineParams:
Param( DbIndex, int, wxT("Db"), 0, 0, Enums::NumDbChoices - 1, 1 ); Param( DbIndex, int, wxT("Db"), 0, 0, Enums::NumDbChoices - 1, 1 );
Param( Threshold, double, wxT("Threshold"), -20.0, -80.0, -20.0, 1 );
Param( ActIndex, int, wxT("Action"), kTruncate, 0, nActions - 1, 1 ); Param( ActIndex, int, wxT("Action"), kTruncate, 0, nActions - 1, 1 );
Param( Minimum, double, wxT("Minimum"), 0.5, 0.001, 10000.0, 1 ); Param( Minimum, double, wxT("Minimum"), 0.5, 0.001, 10000.0, 1 );
Param( Truncate, double, wxT("Truncate"), 0.5, 0.0, 10000.0, 1 ); Param( Truncate, double, wxT("Truncate"), 0.5, 0.0, 10000.0, 1 );
@ -128,7 +127,7 @@ EffectTruncSilence::EffectTruncSilence()
mInitialAllowedSilence = DEF_Minimum; mInitialAllowedSilence = DEF_Minimum;
mTruncLongestAllowedSilence = DEF_Truncate; mTruncLongestAllowedSilence = DEF_Truncate;
mSilenceCompressPercent = DEF_Compress; mSilenceCompressPercent = DEF_Compress;
mTruncDbChoiceIndex = DEF_DbIndex; mThresholdDB = DEF_Threshold;
mActionIndex = DEF_ActIndex; mActionIndex = DEF_ActIndex;
mbIndependent = DEF_Independent; mbIndependent = DEF_Independent;
@ -176,8 +175,7 @@ EffectType EffectTruncSilence::GetType()
// EffectClientInterface implementation // EffectClientInterface implementation
bool EffectTruncSilence::DefineParams( ShuttleParams & S ){ bool EffectTruncSilence::DefineParams( ShuttleParams & S ){
S.SHUTTLE_ENUM_PARAM( mTruncDbChoiceIndex, DbIndex, S.SHUTTLE_PARAM( mThresholdDB, Threshold );
Enums::DbChoices, Enums::NumDbChoices );
S.SHUTTLE_ENUM_PARAM( mActionIndex, ActIndex, kActionStrings, nActions ); S.SHUTTLE_ENUM_PARAM( mActionIndex, ActIndex, kActionStrings, nActions );
S.SHUTTLE_PARAM( mInitialAllowedSilence, Minimum ); S.SHUTTLE_PARAM( mInitialAllowedSilence, Minimum );
S.SHUTTLE_PARAM( mTruncLongestAllowedSilence, Truncate ); S.SHUTTLE_PARAM( mTruncLongestAllowedSilence, Truncate );
@ -188,7 +186,7 @@ bool EffectTruncSilence::DefineParams( ShuttleParams & S ){
bool EffectTruncSilence::GetAutomationParameters(CommandParameters & parms) bool EffectTruncSilence::GetAutomationParameters(CommandParameters & parms)
{ {
parms.Write(KEY_DbIndex, Enums::DbChoices[mTruncDbChoiceIndex].Internal()); parms.Write(KEY_Threshold, mThresholdDB);
parms.Write(KEY_ActIndex, kActionStrings[mActionIndex].Internal()); parms.Write(KEY_ActIndex, kActionStrings[mActionIndex].Internal());
parms.Write(KEY_Minimum, mInitialAllowedSilence); parms.Write(KEY_Minimum, mInitialAllowedSilence);
parms.Write(KEY_Truncate, mTruncLongestAllowedSilence); parms.Write(KEY_Truncate, mTruncLongestAllowedSilence);
@ -203,7 +201,21 @@ bool EffectTruncSilence::SetAutomationParameters(CommandParameters & parms)
ReadAndVerifyDouble(Minimum); ReadAndVerifyDouble(Minimum);
ReadAndVerifyDouble(Truncate); ReadAndVerifyDouble(Truncate);
ReadAndVerifyDouble(Compress); ReadAndVerifyDouble(Compress);
ReadAndVerifyEnum(DbIndex, Enums::DbChoices, Enums::NumDbChoices);
// This control migrated from a choice to a text box in version 2.3.0
double myThreshold {};
bool newParams = [&] {
ReadAndVerifyDouble(Threshold); // macro may return false
myThreshold = Threshold;
return true;
} ();
if ( !newParams ) {
// Use legacy param:
ReadAndVerifyEnum(DbIndex, Enums::DbChoices, Enums::NumDbChoices);
myThreshold = enumToDB( DbIndex );
}
ReadAndVerifyEnumWithObsoletes(ActIndex, kActionStrings, nActions, ReadAndVerifyEnumWithObsoletes(ActIndex, kActionStrings, nActions,
kObsoleteActions, nObsoleteActions); kObsoleteActions, nObsoleteActions);
ReadAndVerifyBool(Independent); ReadAndVerifyBool(Independent);
@ -211,7 +223,7 @@ bool EffectTruncSilence::SetAutomationParameters(CommandParameters & parms)
mInitialAllowedSilence = Minimum; mInitialAllowedSilence = Minimum;
mTruncLongestAllowedSilence = Truncate; mTruncLongestAllowedSilence = Truncate;
mSilenceCompressPercent = Compress; mSilenceCompressPercent = Compress;
mTruncDbChoiceIndex = DbIndex; mThresholdDB = myThreshold;
mActionIndex = ActIndex; mActionIndex = ActIndex;
mbIndependent = Independent; mbIndependent = Independent;
@ -265,11 +277,12 @@ bool EffectTruncSilence::Startup()
// Load the old "current" settings // Load the old "current" settings
if (gPrefs->Exists(base)) if (gPrefs->Exists(base))
{ {
mTruncDbChoiceIndex = gPrefs->Read(base + wxT("DbChoiceIndex"), 4L); int truncDbChoiceIndex = gPrefs->Read(base + wxT("DbChoiceIndex"), 4L);
if ((mTruncDbChoiceIndex < 0) || (mTruncDbChoiceIndex >= Enums::NumDbChoices)) if ((truncDbChoiceIndex < 0) || (truncDbChoiceIndex >= Enums::NumDbChoices))
{ // corrupted Prefs? { // corrupted Prefs?
mTruncDbChoiceIndex = 4L; truncDbChoiceIndex = 4L;
} }
mThresholdDB = enumToDB( truncDbChoiceIndex );
mActionIndex = gPrefs->Read(base + wxT("ProcessChoice"), 0L); mActionIndex = gPrefs->Read(base + wxT("ProcessChoice"), 0L);
if ((mActionIndex < 0) || (mActionIndex > 1)) if ((mActionIndex < 0) || (mActionIndex > 1))
{ // corrupted Prefs? { // corrupted Prefs?
@ -595,7 +608,7 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
// Smallest silent region to detect in frames // Smallest silent region to detect in frames
auto minSilenceFrames = sampleCount(std::max( mInitialAllowedSilence, DEF_MinTruncMs) * wt->GetRate()); auto minSilenceFrames = sampleCount(std::max( mInitialAllowedSilence, DEF_MinTruncMs) * wt->GetRate());
double truncDbSilenceThreshold = Enums::Db2Signal[mTruncDbChoiceIndex]; double truncDbSilenceThreshold = DB_TO_LINEAR( mThresholdDB );
auto blockLen = wt->GetMaxBlockSize(); auto blockLen = wt->GetMaxBlockSize();
auto start = wt->TimeToLongSamples(mT0); auto start = wt->TimeToLongSamples(mT0);
auto end = wt->TimeToLongSamples(mT1); auto end = wt->TimeToLongSamples(mT1);
@ -751,12 +764,12 @@ void EffectTruncSilence::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL); S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
{ {
// Threshold // Threshold
auto dbChoices = FloatingPointValidator<double> vldThreshold(3, &mThresholdDB,
LocalizedStrings( Enums::DbChoices, Enums::NumDbChoices ); NumValidatorStyle::NO_TRAILING_ZEROES);
mTruncDbChoice = S.AddChoice(_("Level:"), wxT(""), &dbChoices); vldThreshold.SetRange(MIN_Threshold, MAX_Threshold);
mTruncDbChoice->SetValidator(wxGenericValidator(&mTruncDbChoiceIndex)); mThresholdText = S.AddTextBox(_("Threshold:"), wxT(""), 0);
S.SetSizeHints(-1, -1); mThresholdText->SetValidator(vldThreshold);
S.AddSpace(0); // 'choices' already includes units. S.AddUnits(_("dB"));
// Ignored silence // Ignored silence
FloatingPointValidator<double> vldDur(3, &mInitialAllowedSilence, NumValidatorStyle::NO_TRAILING_ZEROES); FloatingPointValidator<double> vldDur(3, &mInitialAllowedSilence, NumValidatorStyle::NO_TRAILING_ZEROES);

View File

@ -97,7 +97,7 @@ private:
private: private:
int mTruncDbChoiceIndex; double mThresholdDB {} ;
int mActionIndex; int mActionIndex;
double mInitialAllowedSilence; double mInitialAllowedSilence;
double mTruncLongestAllowedSilence; double mTruncLongestAllowedSilence;
@ -106,7 +106,7 @@ private:
size_t mBlendFrameCount; size_t mBlendFrameCount;
wxChoice *mTruncDbChoice; wxTextCtrl *mThresholdText;
wxChoice *mActionChoice; wxChoice *mActionChoice;
wxTextCtrl *mInitialAllowedSilenceT; wxTextCtrl *mInitialAllowedSilenceT;
wxTextCtrl *mTruncLongestAllowedSilenceT; wxTextCtrl *mTruncLongestAllowedSilenceT;