1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00

Rename EnumSetting -> ChoiceSetting, EncodedEnumSetting -> EnumSetting

This commit is contained in:
Paul Licameli 2019-04-07 16:42:11 -04:00
parent d6c8352c9b
commit 1649e3669e
8 changed files with 35 additions and 35 deletions

View File

@ -368,13 +368,13 @@ void FinishPreferences()
}
//////////
wxString EnumSetting::Read() const
wxString ChoiceSetting::Read() const
{
const auto &defaultValue = Default().Internal();
wxString value;
if ( !gPrefs->Read(mKey, &value, defaultValue) )
if (!mMigrated) {
const_cast<EnumSetting*>(this)->Migrate( value );
const_cast<ChoiceSetting*>(this)->Migrate( value );
mMigrated = true;
}
@ -386,19 +386,19 @@ wxString EnumSetting::Read() const
return value;
}
size_t EnumSetting::Find( const wxString &value ) const
size_t ChoiceSetting::Find( const wxString &value ) const
{
return size_t(
std::find( begin(), end(), EnumValueSymbol{ value, {} } )
- mSymbols );
}
void EnumSetting::Migrate( wxString &value )
void ChoiceSetting::Migrate( wxString &value )
{
(void)value;// Compiler food
}
bool EnumSetting::Write( const wxString &value )
bool ChoiceSetting::Write( const wxString &value )
{
auto index = Find( value );
if (index >= mnSymbols)
@ -409,7 +409,7 @@ bool EnumSetting::Write( const wxString &value )
return result;
}
int EncodedEnumSetting::ReadInt() const
int EnumSetting::ReadInt() const
{
if (!mIntValues)
return 0;
@ -419,7 +419,7 @@ int EncodedEnumSetting::ReadInt() const
return mIntValues[ index ];
}
size_t EncodedEnumSetting::FindInt( int code ) const
size_t EnumSetting::FindInt( int code ) const
{
if (!mIntValues)
return mnSymbols;
@ -429,7 +429,7 @@ size_t EncodedEnumSetting::FindInt( int code ) const
- mIntValues );
}
void EncodedEnumSetting::Migrate( wxString &value )
void EnumSetting::Migrate( wxString &value )
{
int intValue = 0;
if ( !mOldKey.empty() &&
@ -447,7 +447,7 @@ void EncodedEnumSetting::Migrate( wxString &value )
}
}
bool EncodedEnumSetting::WriteInt( int code ) // you flush gPrefs afterward
bool EnumSetting::WriteInt( int code ) // you flush gPrefs afterward
{
auto index = FindInt( code );
if ( index >= mnSymbols )

View File

@ -62,10 +62,10 @@ public:
/// Packages a table of user-visible choices each with an internal code string,
/// a preference key path, and a default choice
class EnumSetting
class ChoiceSetting
{
public:
EnumSetting(
ChoiceSetting(
const wxString &key,
const EnumValueSymbol symbols[], size_t nSymbols,
size_t defaultSymbol
@ -104,14 +104,14 @@ protected:
const size_t mDefaultSymbol;
};
/// Extends EnumSetting with a corresponding table of integer codes
/// Extends ChoiceSetting with a corresponding table of integer codes
/// (generally not equal to their table positions),
/// and optionally an old preference key path that stored integer codes, to be
/// migrated into one that stores internal string values instead
class EncodedEnumSetting : public EnumSetting
class EnumSetting : public ChoiceSetting
{
public:
EncodedEnumSetting(
EnumSetting(
const wxString &key,
const EnumValueSymbol symbols[], size_t nSymbols,
size_t defaultSymbol,
@ -119,7 +119,7 @@ public:
const int intValues[] = nullptr, // must have same size as symbols
const wxString &oldKey = wxString("")
)
: EnumSetting{ key, symbols, nSymbols, defaultSymbol }
: ChoiceSetting{ key, symbols, nSymbols, defaultSymbol }
, mIntValues{ intValues }
, mOldKey{ oldKey }
{

View File

@ -82,7 +82,7 @@ static const int intChoicesMethod[] = {
static_assert( WXSIZEOF(intChoicesMethod) == numMethods, "size mismatch" );
EncodedEnumSetting Resample::FastMethodSetting{
EnumSetting Resample::FastMethodSetting{
fastMethodKey,
methodNames, numMethods,
fastMethodDefault,
@ -91,7 +91,7 @@ EncodedEnumSetting Resample::FastMethodSetting{
oldFastMethodKey
};
EncodedEnumSetting Resample::BestMethodSetting
EnumSetting Resample::BestMethodSetting
{
bestMethodKey,
methodNames, numMethods,

View File

@ -18,7 +18,7 @@
#include "SampleFormat.h"
class EncodedEnumSetting;
class EnumSetting;
struct soxr;
extern "C" void soxr_delete(soxr*);
@ -43,8 +43,8 @@ class Resample final
Resample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor);
~Resample();
static EncodedEnumSetting FastMethodSetting;
static EncodedEnumSetting BestMethodSetting;
static EnumSetting FastMethodSetting;
static EnumSetting BestMethodSetting;
/** @brief Main processing function. Resamples from the input buffer to the
* output buffer.

View File

@ -1843,18 +1843,18 @@ wxTextCtrl * ShuttleGuiBase::TieNumericTextBox(
/// those as default.
wxChoice *ShuttleGuiBase::TieChoice(
const wxString &Prompt,
EnumSetting &enumSetting )
ChoiceSetting &choiceSetting )
{
// Do this to force any needed migrations first
enumSetting.Read();
choiceSetting.Read();
wxArrayStringEx visibleChoices, internalChoices;
for (const auto &ident : enumSetting) {
for (const auto &ident : choiceSetting) {
visibleChoices.push_back( ident.Translation() );
internalChoices.push_back( ident.Internal() );
}
return TieChoice(
Prompt, enumSetting.Key(), enumSetting.Default().Internal(),
Prompt, choiceSetting.Key(), choiceSetting.Default().Internal(),
visibleChoices, internalChoices );
}

View File

@ -24,7 +24,7 @@
// For ShuttleGuiGetDefinitions.
#include "commands/CommandTargets.h"
class EnumSetting;
class ChoiceSetting;
class wxArrayStringEx;
@ -213,7 +213,7 @@ public:
// This one is defined in terms of the next and not virtual
virtual wxChoice *TieChoice(
const wxString &Prompt,
EnumSetting &enumSetting );
ChoiceSetting &choiceSetting );
virtual wxChoice * TieChoice(
const wxString &Prompt,

View File

@ -49,7 +49,7 @@ static_assert( nChoicesFormat == WXSIZEOF(intChoicesFormat), "size mismatch" );
static const size_t defaultChoiceFormat = 2; // floatSample
static EncodedEnumSetting formatSetting{
static EnumSetting formatSetting{
wxT("/SamplingRate/DefaultProjectSampleFormatChoice"),
choicesFormat, nChoicesFormat, defaultChoiceFormat,
@ -78,7 +78,7 @@ static_assert(
static const size_t defaultFastDither = 0; // none
static EncodedEnumSetting fastDitherSetting{
static EnumSetting fastDitherSetting{
wxT("Quality/DitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultFastDither,
intChoicesDither,
@ -87,7 +87,7 @@ static EncodedEnumSetting fastDitherSetting{
static const size_t defaultBestDither = 3; // shaped
static EncodedEnumSetting bestDitherSetting{
static EnumSetting bestDitherSetting{
wxT("Quality/HQDitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultBestDither,

View File

@ -72,7 +72,7 @@ static_assert( nChoicesView == WXSIZEOF(intChoicesView), "size mismatch" );
static const size_t defaultChoiceView = 0;
class TracksViewModeSetting : public EncodedEnumSetting {
class TracksViewModeSetting : public EnumSetting {
public:
TracksViewModeSetting(
const wxString &key,
@ -82,7 +82,7 @@ public:
const int intValues[],
const wxString &oldKey
)
: EncodedEnumSetting{
: EnumSetting{
key, symbols, nSymbols, defaultSymbol, intValues, oldKey }
{}
@ -91,7 +91,7 @@ public:
// Special logic for this preference which was twice migrated!
// First test for the older but not oldest key:
EncodedEnumSetting::Migrate(value);
EnumSetting::Migrate(value);
if (!value.empty())
return;
@ -144,7 +144,7 @@ static_assert(
static const size_t defaultChoiceSampleDisplay = 1;
static EncodedEnumSetting sampleDisplaySetting{
static EnumSetting sampleDisplaySetting{
wxT("/GUI/SampleViewChoice"),
choicesSampleDisplay, nChoicesSampleDisplay, defaultChoiceSampleDisplay,
@ -197,7 +197,7 @@ static_assert( nChoicesZoom == WXSIZEOF(intChoicesZoom), "size mismatch" );
static const size_t defaultChoiceZoom1 = 2; // kZoomDefault
static EncodedEnumSetting zoom1Setting{
static EnumSetting zoom1Setting{
wxT("/GUI/ZoomPreset1Choice"),
choicesZoom, nChoicesZoom, defaultChoiceZoom1,
@ -207,7 +207,7 @@ static EncodedEnumSetting zoom1Setting{
static const size_t defaultChoiceZoom2 = 13; // kZoom4To1
static EncodedEnumSetting zoom2Setting{
static EnumSetting zoom2Setting{
wxT("/GUI/ZoomPreset2Choice"),
choicesZoom, nChoicesZoom, defaultChoiceZoom2,