mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 07:59:27 +02:00
Add spectrogram preference migration from old 'Grayscale' checkbox to new 'Color Scheme' choice
This commit is contained in:
parent
e135bcf16f
commit
e9f0590c28
@ -445,7 +445,7 @@ bool SetTrackVisualsCommand::ApplyInner(const CommandContext & context, Track *
|
||||
wt->GetSpectrogramSettings().spectralSelection = bSpectralSelect;
|
||||
}
|
||||
if (wt && bHasSpecColorScheme) {
|
||||
wt->GetSpectrogramSettings().colorScheme = mSpecColorScheme;
|
||||
wt->GetSpectrogramSettings().colorScheme = (SpectrogramSettings::ColorScheme)mSpecColorScheme;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -176,6 +176,26 @@ const EnumValueSymbols &SpectrogramSettings::GetColorSchemeNames()
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void SpectrogramSettings::ColorSchemeEnumSetting::Migrate(wxString &value)
|
||||
{
|
||||
// Migrate old grayscale option to Color scheme choice
|
||||
bool isGrayscale = (gPrefs->Read(wxT("/Spectrum/Grayscale"), 0L) != 0);
|
||||
if (isGrayscale && !gPrefs->Read(wxT("/Spectrum/ColorScheme"), &value)) {
|
||||
value = GetColorSchemeNames().at(csInvGrayscale).Internal();
|
||||
Write(value);
|
||||
gPrefs->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
SpectrogramSettings::ColorSchemeEnumSetting SpectrogramSettings::colorSchemeSetting{
|
||||
wxT("/Spectrum/ColorScheme"),
|
||||
GetColorSchemeNames(),
|
||||
csColorNew, // default to Color(New)
|
||||
{ csColorNew, csColorTheme, csGrayscale, csInvGrayscale },
|
||||
};
|
||||
|
||||
|
||||
//static
|
||||
const TranslatableStrings &SpectrogramSettings::GetAlgorithmNames()
|
||||
{
|
||||
@ -249,7 +269,9 @@ bool SpectrogramSettings::Validate(bool quiet)
|
||||
ScaleType(std::max(0,
|
||||
std::min((int)(SpectrogramSettings::stNumScaleTypes) - 1,
|
||||
(int)(scaleType))));
|
||||
colorScheme = std::max(0, std::min(csNumColorScheme-1, colorScheme));
|
||||
colorScheme = ColorScheme(
|
||||
std::max(0, std::min<int>(csNumColorScheme-1, colorScheme))
|
||||
);
|
||||
algorithm = Algorithm(
|
||||
std::max(0, std::min((int)(algNumAlgorithms) - 1, (int)(algorithm)))
|
||||
);
|
||||
@ -277,7 +299,7 @@ void SpectrogramSettings::LoadPrefs()
|
||||
|
||||
gPrefs->Read(wxT("/Spectrum/WindowType"), &windowType, eWinFuncHann);
|
||||
|
||||
colorScheme = ColorScheme(gPrefs->Read(wxT("/Spectrum/ColorScheme"), 0L));
|
||||
colorScheme = colorSchemeSetting.ReadEnum();
|
||||
|
||||
scaleType = ScaleType(gPrefs->Read(wxT("/Spectrum/ScaleType"), 0L));
|
||||
|
||||
@ -325,7 +347,7 @@ void SpectrogramSettings::SavePrefs()
|
||||
|
||||
gPrefs->Write(wxT("/Spectrum/WindowType"), windowType);
|
||||
|
||||
gPrefs->Write(wxT("/Spectrum/ColorScheme"), (int) colorScheme);
|
||||
colorSchemeSetting.WriteEnum(colorScheme);
|
||||
|
||||
gPrefs->Write(wxT("/Spectrum/ScaleType"), (int) scaleType);
|
||||
|
||||
@ -385,9 +407,7 @@ void SpectrogramSettings::UpdatePrefs()
|
||||
}
|
||||
|
||||
if (colorScheme == defaults().colorScheme) {
|
||||
int temp;
|
||||
gPrefs->Read(wxT("/Spectrum/ColorScheme"), &temp, 0L);
|
||||
colorScheme = ColorScheme(temp);
|
||||
colorScheme = colorSchemeSetting.ReadEnum();
|
||||
}
|
||||
|
||||
if (scaleType == defaults().scaleType) {
|
||||
|
@ -129,8 +129,7 @@ public:
|
||||
size_t GetFFTLength() const; // window size (times zero padding, if STFT)
|
||||
size_t NBins() const;
|
||||
|
||||
typedef int ColorScheme;
|
||||
enum ColorSchemeValues : int {
|
||||
enum ColorScheme : int {
|
||||
// Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
|
||||
csColorNew = 0,
|
||||
csColorTheme,
|
||||
@ -141,6 +140,12 @@ public:
|
||||
};
|
||||
ColorScheme colorScheme;
|
||||
|
||||
class ColorSchemeEnumSetting : public EnumSetting< ColorScheme > {
|
||||
using EnumSetting< ColorScheme >::EnumSetting;
|
||||
void Migrate(wxString &value) override;
|
||||
};
|
||||
static ColorSchemeEnumSetting colorSchemeSetting;
|
||||
|
||||
ScaleType scaleType;
|
||||
|
||||
#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
|
||||
|
@ -225,7 +225,7 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S)
|
||||
8);
|
||||
|
||||
S.Id(ID_COLOR_SCHEME).TieChoice(XXO("Color Sche&me:"),
|
||||
mTempSettings.colorScheme,
|
||||
(int&)mTempSettings.colorScheme,
|
||||
Msgids( SpectrogramSettings::GetColorSchemeNames() ) );
|
||||
}
|
||||
S.EndMultiColumn();
|
||||
|
Loading…
x
Reference in New Issue
Block a user