mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 16:40:07 +02:00
Redo view mode choice in Tracks preferences
This commit is contained in:
parent
872b4f430c
commit
83a01e255f
@ -96,7 +96,7 @@ WaveTrack::WaveTrack(const std::shared_ptr<DirManager> &projDirManager, sampleFo
|
|||||||
// Force creation always:
|
// Force creation always:
|
||||||
WaveformSettings &settings = GetIndependentWaveformSettings();
|
WaveformSettings &settings = GetIndependentWaveformSettings();
|
||||||
|
|
||||||
mDisplay = FindDefaultViewMode();
|
mDisplay = TracksPrefs::ViewModeChoice();
|
||||||
if (mDisplay == obsoleteWaveformDBDisplay) {
|
if (mDisplay == obsoleteWaveformDBDisplay) {
|
||||||
mDisplay = Waveform;
|
mDisplay = Waveform;
|
||||||
settings.scaleType = WaveformSettings::stLogarithmic;
|
settings.scaleType = WaveformSettings::stLogarithmic;
|
||||||
@ -254,32 +254,6 @@ void WaveTrack::SetPanFromChannelType()
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//static
|
|
||||||
WaveTrack::WaveTrackDisplay WaveTrack::FindDefaultViewMode()
|
|
||||||
{
|
|
||||||
// PRL: Bugs 1043, 1044
|
|
||||||
// 2.1.1 writes a NEW key for this preference, which got NEW values,
|
|
||||||
// to avoid confusing version 2.1.0 if it reads the preference file afterwards.
|
|
||||||
// Prefer the NEW preference key if it is present
|
|
||||||
|
|
||||||
WaveTrack::WaveTrackDisplay viewMode;
|
|
||||||
gPrefs->Read(wxT("/GUI/DefaultViewModeNew"), &viewMode, -1);
|
|
||||||
|
|
||||||
// Default to the old key only if not, default the value if it's not there either
|
|
||||||
wxASSERT(WaveTrack::MinDisplay >= 0);
|
|
||||||
if (viewMode < 0) {
|
|
||||||
int oldMode;
|
|
||||||
gPrefs->Read(wxT("/GUI/DefaultViewMode"), &oldMode,
|
|
||||||
(int)(WaveTrack::Waveform));
|
|
||||||
viewMode = WaveTrack::ConvertLegacyDisplayValue(oldMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now future-proof 2.1.1 against a recurrence of this sort of bug!
|
|
||||||
viewMode = WaveTrack::ValidateWaveTrackDisplay(viewMode);
|
|
||||||
|
|
||||||
return viewMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
WaveTrack::WaveTrackDisplay
|
WaveTrack::WaveTrackDisplay
|
||||||
WaveTrack::ConvertLegacyDisplayValue(int oldValue)
|
WaveTrack::ConvertLegacyDisplayValue(int oldValue)
|
||||||
|
@ -578,9 +578,6 @@ private:
|
|||||||
kMaxZoom,
|
kMaxZoom,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read appropriate value from preferences
|
|
||||||
static WaveTrackDisplay FindDefaultViewMode();
|
|
||||||
|
|
||||||
// Handle remapping of enum values from 2.1.0 and earlier
|
// Handle remapping of enum values from 2.1.0 and earlier
|
||||||
static WaveTrackDisplay ConvertLegacyDisplayValue(int oldValue);
|
static WaveTrackDisplay ConvertLegacyDisplayValue(int oldValue);
|
||||||
|
|
||||||
|
@ -45,17 +45,86 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////
|
||||||
|
static const IdentInterfaceSymbol choicesView[] = {
|
||||||
|
{ XO("Waveform") },
|
||||||
|
{ wxT("WaveformDB"), XO("Waveform (dB)") },
|
||||||
|
{ XO("Spectrogram") }
|
||||||
|
};
|
||||||
|
static const int intChoicesView[] = {
|
||||||
|
(int)(WaveTrack::Waveform),
|
||||||
|
(int)(WaveTrack::obsoleteWaveformDBDisplay),
|
||||||
|
(int)(WaveTrack::Spectrum)
|
||||||
|
};
|
||||||
|
static const size_t nChoicesView = WXSIZEOF(choicesView);
|
||||||
|
static_assert( nChoicesView == WXSIZEOF(intChoicesView), "size mismatch" );
|
||||||
|
|
||||||
|
static const size_t defaultChoiceView = 0;
|
||||||
|
|
||||||
|
class TracksViewModeSetting : public EncodedEnumSetting {
|
||||||
|
public:
|
||||||
|
TracksViewModeSetting(
|
||||||
|
const wxString &key,
|
||||||
|
const IdentInterfaceSymbol symbols[], size_t nSymbols,
|
||||||
|
size_t defaultSymbol,
|
||||||
|
|
||||||
|
const int intValues[],
|
||||||
|
const wxString &oldKey
|
||||||
|
)
|
||||||
|
: EncodedEnumSetting{
|
||||||
|
key, symbols, nSymbols, defaultSymbol, intValues, oldKey }
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Migrate( wxString &value ) override
|
||||||
|
{
|
||||||
|
// Special logic for this preference which was twice migrated!
|
||||||
|
|
||||||
|
// First test for the older but not oldest key:
|
||||||
|
EncodedEnumSetting::Migrate(value);
|
||||||
|
if (!value.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// PRL: Bugs 1043, 1044
|
||||||
|
// 2.1.1 writes a NEW key for this preference, which got NEW values,
|
||||||
|
// to avoid confusing version 2.1.0 if it reads the preference file afterwards.
|
||||||
|
// Prefer the NEW preference key if it is present
|
||||||
|
|
||||||
|
int oldMode;
|
||||||
|
gPrefs->Read(wxT("/GUI/DefaultViewMode"), // The very old key
|
||||||
|
&oldMode,
|
||||||
|
(int)(WaveTrack::Waveform));
|
||||||
|
auto viewMode = WaveTrack::ConvertLegacyDisplayValue(oldMode);
|
||||||
|
|
||||||
|
// Now future-proof 2.1.1 against a recurrence of this sort of bug!
|
||||||
|
viewMode = WaveTrack::ValidateWaveTrackDisplay(viewMode);
|
||||||
|
|
||||||
|
const_cast<TracksViewModeSetting*>(this)->WriteInt( viewMode );
|
||||||
|
gPrefs->Flush();
|
||||||
|
|
||||||
|
value = mSymbols[ FindInt(viewMode) ].Internal();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static TracksViewModeSetting viewModeSetting{
|
||||||
|
wxT("/GUI/DefaultViewModeChoice"),
|
||||||
|
choicesView, nChoicesView, defaultChoiceView,
|
||||||
|
|
||||||
|
intChoicesView,
|
||||||
|
wxT("/GUI/DefaultViewModeNew")
|
||||||
|
};
|
||||||
|
|
||||||
|
WaveTrack::WaveTrackDisplay TracksPrefs::ViewModeChoice()
|
||||||
|
{
|
||||||
|
return (WaveTrack::WaveTrackDisplay) viewModeSetting.ReadInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////
|
||||||
TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
|
TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
|
||||||
/* i18n-hint: "Tracks" include audio recordings but also other collections of
|
/* i18n-hint: "Tracks" include audio recordings but also other collections of
|
||||||
* data associated with a time line, such as sequences of labels, and musical
|
* data associated with a time line, such as sequences of labels, and musical
|
||||||
* notes */
|
* notes */
|
||||||
: PrefsPanel(parent, winid, _("Tracks"))
|
: PrefsPanel(parent, winid, _("Tracks"))
|
||||||
{
|
{
|
||||||
// Bugs 1043, 1044
|
|
||||||
// First rewrite legacy preferences
|
|
||||||
gPrefs->Write(wxT("/GUI/DefaultViewModeNew"),
|
|
||||||
(int) WaveTrack::FindDefaultViewMode());
|
|
||||||
|
|
||||||
Populate();
|
Populate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,15 +137,6 @@ void TracksPrefs::Populate()
|
|||||||
// Keep view choices and codes in proper correspondence --
|
// Keep view choices and codes in proper correspondence --
|
||||||
// we don't display them by increasing integer values.
|
// we don't display them by increasing integer values.
|
||||||
|
|
||||||
mViewChoices.Add(_("Waveform"));
|
|
||||||
mViewCodes.push_back((int)(WaveTrack::Waveform));
|
|
||||||
|
|
||||||
mViewChoices.Add(_("Waveform (dB)"));
|
|
||||||
mViewCodes.push_back((int)(WaveTrack::obsoleteWaveformDBDisplay));
|
|
||||||
|
|
||||||
mViewChoices.Add(_("Spectrogram"));
|
|
||||||
mViewCodes.push_back(WaveTrack::Spectrum);
|
|
||||||
|
|
||||||
|
|
||||||
// How samples are displayed when zoomed in:
|
// How samples are displayed when zoomed in:
|
||||||
|
|
||||||
@ -153,10 +213,7 @@ void TracksPrefs::PopulateOrExchange(ShuttleGui & S)
|
|||||||
S.StartMultiColumn(2);
|
S.StartMultiColumn(2);
|
||||||
{
|
{
|
||||||
S.TieChoice(_("Default &view mode:"),
|
S.TieChoice(_("Default &view mode:"),
|
||||||
wxT("/GUI/DefaultViewModeNew"),
|
viewModeSetting );
|
||||||
0,
|
|
||||||
mViewChoices,
|
|
||||||
mViewCodes);
|
|
||||||
|
|
||||||
S.TieChoice(_("Display &samples:"),
|
S.TieChoice(_("Display &samples:"),
|
||||||
wxT("/GUI/SampleView"),
|
wxT("/GUI/SampleView"),
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "PrefsPanel.h"
|
#include "PrefsPanel.h"
|
||||||
|
#include "../WaveTrack.h"
|
||||||
|
|
||||||
class ShuttleGui;
|
class ShuttleGui;
|
||||||
|
|
||||||
@ -36,14 +37,14 @@ class TracksPrefs final : public PrefsPanel
|
|||||||
|
|
||||||
static wxString GetDefaultAudioTrackNamePreference();
|
static wxString GetDefaultAudioTrackNamePreference();
|
||||||
|
|
||||||
|
static WaveTrack::WaveTrackDisplay ViewModeChoice();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Populate();
|
void Populate();
|
||||||
void PopulateOrExchange(ShuttleGui & S) override;
|
void PopulateOrExchange(ShuttleGui & S) override;
|
||||||
|
|
||||||
static int iPreferencePinned;
|
static int iPreferencePinned;
|
||||||
|
|
||||||
std::vector<int> mViewCodes;
|
|
||||||
wxArrayString mViewChoices;
|
|
||||||
std::vector<int> mSampleDisplayCodes;
|
std::vector<int> mSampleDisplayCodes;
|
||||||
wxArrayString mSampleDisplayChoices;
|
wxArrayString mSampleDisplayChoices;
|
||||||
std::vector<int> mZoomCodes;
|
std::vector<int> mZoomCodes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user