Skip to content

Commit

Permalink
Add spectrogram preference migration from old 'Grayscale' checkbox to…
Browse files Browse the repository at this point in the history
… new 'Color Scheme' choice
  • Loading branch information
dofuuz authored and Paul-Licameli committed Jun 15, 2021
1 parent e135bcf commit e9f0590
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/commands/SetTrackInfoCommand.cpp
Expand Up @@ -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;
Expand Down
32 changes: 26 additions & 6 deletions src/prefs/SpectrogramSettings.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)))
);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/prefs/SpectrogramSettings.h
Expand Up @@ -129,8 +129,7 @@ class AUDACITY_DLL_API SpectrogramSettings : public PrefsListener
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,
Expand All @@ -141,6 +140,12 @@ class AUDACITY_DLL_API SpectrogramSettings : public PrefsListener
};
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
Expand Down
2 changes: 1 addition & 1 deletion src/prefs/SpectrumPrefs.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit e9f0590

Please sign in to comment.