1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-10 16:43:33 +02:00

A means to specify legacy values of effect choice controls...

... For Truncate Silence only now, perhaps it will find more future use
This commit is contained in:
Paul Licameli
2018-03-26 10:44:34 -04:00
parent cb8e35574d
commit 170f92c181
3 changed files with 50 additions and 12 deletions

View File

@@ -155,7 +155,14 @@ public:
return Write(key, f);
}
bool ReadEnum(const wxString & key, int *pi, const wxArrayString & choices) const
// For reading old config files with enumeration names that have been
// changed in later versions. Pair a string with an index into the other
// list of non-obsolete names.
using ObsoleteMap = std::pair< wxString, size_t >;
bool ReadEnum(const wxString & key, int *pi, const wxArrayString & choices,
const ObsoleteMap obsoletes[] = nullptr,
size_t nObsoletes = 0) const
{
wxString s;
if (!wxFileConfig::Read(key, &s))
@@ -163,10 +170,21 @@ public:
return false;
}
*pi = choices.Index(s);
if (*pi < 0 && obsoletes) {
auto index = std::find_if(obsoletes, obsoletes + nObsoletes,
[&](const ObsoleteMap &entry){
return entry.first == s; })
- obsoletes;
if (index < nObsoletes)
*pi = (int)obsoletes[index].second;
}
return true;
}
bool ReadEnum(const wxString & key, int *pi, int defVal, const wxArrayString & choices) const
bool ReadEnum(const wxString & key, int *pi, int defVal,
const wxArrayString & choices,
const ObsoleteMap obsoletes[] = nullptr,
size_t nObsoletes = 0) const
{
if (!ReadEnum(key, pi, choices))
{
@@ -175,7 +193,10 @@ public:
return true;
}
bool ReadEnum(const wxString & key, int *pi, const wxString & defVal, const wxArrayString & choices) const
bool ReadEnum(const wxString & key, int *pi, const wxString & defVal,
const wxArrayString & choices,
const ObsoleteMap obsoletes[] = nullptr,
size_t nObsoletes = 0) const
{
if (!ReadEnum(key, pi, choices))
{
@@ -230,15 +251,21 @@ public:
return true;
}
bool ReadAndVerify(const wxString & key, int *val, int defVal, const wxArrayString & choices) const
bool ReadAndVerify(const wxString & key, int *val, int defVal,
const wxArrayString & choices,
const ObsoleteMap obsoletes[] = nullptr,
size_t nObsoletes = 0) const
{
ReadEnum(key, val, defVal, choices);
ReadEnum(key, val, defVal, choices, obsoletes, nObsoletes);
return (*val != wxNOT_FOUND);
}
bool ReadAndVerify(const wxString & key, int *val, const wxString & defVal, const wxArrayString & choices) const
bool ReadAndVerify(const wxString & key, int *val, const wxString & defVal,
const wxArrayString & choices,
const ObsoleteMap obsoletes[] = nullptr,
size_t nObsoletes = 0) const
{
ReadEnum(key, val, defVal, choices);
ReadEnum(key, val, defVal, choices, obsoletes, nObsoletes);
return (*val != wxNOT_FOUND);
}

View File

@@ -792,6 +792,12 @@ inline long TrapLong(long x, long min, long max)
if (!parms.ReadAndVerify(KEY_ ## name, &name, DEF_ ## name, list)) \
return false;
#define ReadAndVerifyEnumWithObsoletes(name, list, obsoleteList, nObsolete) \
int name; \
if (!parms.ReadAndVerify(KEY_ ## name, &name, DEF_ ## name, \
list, obsoleteList, nObsolete)) \
return false;
#define ReadAndVerifyInt(name) ReadParam(int, name)
#define ReadAndVerifyDouble(name) ReadParam(double, name)
#define ReadAndVerifyFloat(name) ReadParam(float, name)

View File

@@ -50,6 +50,14 @@ static const wxChar *kActionStrings[nActions] =
XO("Compress Excess Silence")
};
static CommandParameters::ObsoleteMap kObsoleteActions[] = {
// Compatible with 2.1.0 and before
{ wxT("0"), 0 }, // Remap to Truncate Detected Silence
{ wxT("1"), 1 }, // Remap to Compress Excess Silence
};
static const size_t nObsoleteActions = WXSIZEOF( kObsoleteActions );
// Define defaults, minimums, and maximums for each parameter
#define DefaultAndLimits(name, def, min, max) \
static const double DEF_ ## name = (def); \
@@ -136,8 +144,6 @@ EffectType EffectTruncSilence::GetType()
bool EffectTruncSilence::DefineParams( ShuttleParams & S ){
wxArrayString actions(nActions, kActionStrings);
//actions.Insert(wxT("0"), 0); // Compatible with 2.1.0 and before
//actions.Insert(wxT("1"), 1); // Compatible with 2.1.0 and before
S.SHUTTLE_ENUM_PARAM( mTruncDbChoiceIndex, DbIndex, mDbChoices );
S.SHUTTLE_ENUM_PARAM( mActionIndex, ActIndex, actions );
@@ -163,14 +169,13 @@ bool EffectTruncSilence::GetAutomationParameters(CommandParameters & parms)
bool EffectTruncSilence::SetAutomationParameters(CommandParameters & parms)
{
wxArrayString actions(nActions, kActionStrings);
actions.Insert(wxT("0"), 0); // Compatible with 2.1.0 and before
actions.Insert(wxT("1"), 1); // Compatible with 2.1.0 and before
ReadAndVerifyDouble(Minimum);
ReadAndVerifyDouble(Truncate);
ReadAndVerifyDouble(Compress);
ReadAndVerifyEnum(DbIndex, mDbChoices);
ReadAndVerifyEnum(ActIndex, actions);
ReadAndVerifyEnumWithObsoletes(ActIndex, actions,
kObsoleteActions, nObsoleteActions);
ReadAndVerifyBool(Independent);
mInitialAllowedSilence = Minimum;