1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 07:13:49 +01:00

dB range is now in Waveforms preferences and view settings, and ...

... the preference is independent of those in Interface and Recording
preferences, which affect meters, sound activated recordings, time track,
and Plot Spectrum
This commit is contained in:
Paul Licameli
2015-08-15 18:07:29 -04:00
parent 0a03f222ff
commit cf45a58fdc
14 changed files with 232 additions and 121 deletions

View File

@@ -39,6 +39,35 @@ GUIPrefs::~GUIPrefs()
{
}
void GUIPrefs::GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes)
{
if (pCodes) {
wxArrayString &codes = *pCodes;
codes.Clear();
codes.Add(wxT("36"));
codes.Add(wxT("48"));
codes.Add(wxT("60"));
codes.Add(wxT("72"));
codes.Add(wxT("84"));
codes.Add(wxT("96"));
codes.Add(wxT("120"));
codes.Add(wxT("145"));
}
if (pChoices) {
wxArrayString &choices = *pChoices;
choices.Clear();
choices.Add(_("-36 dB (shallow range for high-amplitude editing)"));
choices.Add(_("-48 dB (PCM range of 8 bit samples)"));
choices.Add(_("-60 dB (PCM range of 10 bit samples)"));
choices.Add(_("-72 dB (PCM range of 12 bit samples)"));
choices.Add(_("-84 dB (PCM range of 14 bit samples)"));
choices.Add(_("-96 dB (PCM range of 16 bit samples)"));
choices.Add(_("-120 dB (approximate limit of human hearing)"));
choices.Add(_("-145 dB (PCM range of 24 bit samples)"));
}
}
void GUIPrefs::Populate()
{
// First any pre-processing for constructing the GUI.
@@ -50,23 +79,7 @@ void GUIPrefs::Populate()
mHtmlHelpChoices.Add(_("Local"));
mHtmlHelpChoices.Add(_("From Internet"));
mRangeCodes.Add(wxT("36"));
mRangeCodes.Add(wxT("48"));
mRangeCodes.Add(wxT("60"));
mRangeCodes.Add(wxT("72"));
mRangeCodes.Add(wxT("84"));
mRangeCodes.Add(wxT("96"));
mRangeCodes.Add(wxT("120"));
mRangeCodes.Add(wxT("145"));
mRangeChoices.Add(_("-36 dB (shallow range for high-amplitude editing)"));
mRangeChoices.Add(_("-48 dB (PCM range of 8 bit samples)"));
mRangeChoices.Add(_("-60 dB (PCM range of 10 bit samples)"));
mRangeChoices.Add(_("-72 dB (PCM range of 12 bit samples)"));
mRangeChoices.Add(_("-84 dB (PCM range of 14 bit samples)"));
mRangeChoices.Add(_("-96 dB (PCM range of 16 bit samples)"));
mRangeChoices.Add(_("-120 dB (approximate limit of human hearing)"));
mRangeChoices.Add(_("-145 dB (PCM range of 24 bit samples)"));
GetRangeChoices(&mRangeChoices, &mRangeCodes);
#if 0
// only for testing...
@@ -101,7 +114,7 @@ void GUIPrefs::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2);
{
const wxString defaultRange = wxString::Format(wxT("%d"), ENV_DB_RANGE);
S.TieChoice(_("Meter/Waveform dB &range:"),
S.TieChoice(_("Meter dB &range:"),
ENV_DB_KEY,
defaultRange,
mRangeChoices,

View File

@@ -29,6 +29,8 @@ class GUIPrefs :public PrefsPanel
~GUIPrefs();
virtual bool Apply();
static void GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes);
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);

View File

@@ -376,6 +376,8 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
gAudacityProjects[i]->UpdatePrefs();
}
WaveformSettings::defaults().LoadPrefs();
gPrefs->Flush();
EndModal(true);
}

View File

@@ -15,6 +15,8 @@ Paul Licameli
#include "../Audacity.h"
#include "WaveformPrefs.h"
#include "GUIPrefs.h"
#include "GUISettings.h"
#include <wx/checkbox.h>
@@ -38,6 +40,7 @@ WaveformPrefs::WaveformPrefs(wxWindow * parent, WaveTrack *wt)
mDefaulted = false;
}
mTempSettings.ConvertToEnumeratedDBRange();
Populate();
}
@@ -50,12 +53,16 @@ enum {
ID_APPLY,
ID_SCALE,
ID_RANGE,
};
void WaveformPrefs::Populate()
{
mScaleChoices = WaveformSettings::GetScaleNames();
// Reuse the same choices and codes as for Interface prefs
GUIPrefs::GetRangeChoices(&mRangeChoices, &mRangeCodes);
//------------------------- Main section --------------------
// Now construct the GUI itself.
ShuttleGui S(this, eIsCreating);
@@ -81,9 +88,16 @@ void WaveformPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.StartTwoColumn();
{
S.Id(ID_SCALE).TieChoice(_("S&cale") + wxString(wxT(":")),
*(int*)&mTempSettings.scaleType,
&mScaleChoices);
mScaleChoice =
S.Id(ID_SCALE).TieChoice(_("S&cale") + wxString(wxT(":")),
*(int*)&mTempSettings.scaleType,
&mScaleChoices);
mRangeChoice =
S.Id(ID_RANGE).TieChoice(_("Waveform dB &range") + wxString(wxT(":")),
*(int*)&mTempSettings.dBRange,
&mRangeChoices);
S.SetSizeHints(mRangeChoices);
}
S.EndTwoColumn();
}
@@ -104,6 +118,8 @@ void WaveformPrefs::PopulateOrExchange(ShuttleGui & S)
}
S.EndMultiColumn();
EnableDisableRange();
mPopulating = false;
}
@@ -117,7 +133,9 @@ bool WaveformPrefs::Validate()
PopulateOrExchange(S);
// Delegate range checking to WaveformSettings class
mTempSettings.ConvertToActualDBRange();
const bool result = mTempSettings.Validate(false);
mTempSettings.ConvertToEnumeratedDBRange();
return result;
}
@@ -131,6 +149,7 @@ bool WaveformPrefs::Apply()
ShuttleGui S(this, eIsGettingFromDialog);
PopulateOrExchange(S);
mTempSettings.ConvertToActualDBRange();
WaveformSettings::Globals::Get().SavePrefs();
if (mWt) {
@@ -157,6 +176,8 @@ bool WaveformPrefs::Apply()
pSettings->SavePrefs();
}
mTempSettings.ConvertToEnumeratedDBRange();
if (mWt && isOpenPage) {
mWt->SetDisplay(WaveTrack::Waveform);
if (partner)
@@ -179,10 +200,19 @@ void WaveformPrefs::OnControl(wxCommandEvent&)
}
}
void WaveformPrefs::OnScale(wxCommandEvent &e)
{
EnableDisableRange();
// do the common part
OnControl(e);
}
void WaveformPrefs::OnDefaults(wxCommandEvent &)
{
if (mDefaultsCheckbox->IsChecked()) {
mTempSettings = WaveformSettings::defaults();
mTempSettings.ConvertToEnumeratedDBRange();
mDefaulted = true;
ShuttleGui S(this, eIsSettingToDialog);
PopulateOrExchange(S);
@@ -197,9 +227,15 @@ void WaveformPrefs::OnApply(wxCommandEvent &)
}
}
void WaveformPrefs::EnableDisableRange()
{
mRangeChoice->Enable(mScaleChoice->GetSelection() == 1);
}
BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
EVT_CHOICE(ID_SCALE, WaveformPrefs::OnControl)
EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale)
EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl)
EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults)
EVT_BUTTON(ID_APPLY, WaveformPrefs::OnApply)

View File

@@ -18,6 +18,7 @@ Paul Licameli
class ShuttleGui;
class WaveTrack;
class wxCheckBox;
class wxChoice;
class WaveformPrefs :public PrefsPanel
{
@@ -32,16 +33,23 @@ private:
void PopulateOrExchange(ShuttleGui & S);
void OnControl(wxCommandEvent&);
void OnScale(wxCommandEvent&);
void OnDefaults(wxCommandEvent&);
void OnApply(wxCommandEvent &);
DECLARE_EVENT_TABLE()
void EnableDisableRange();
WaveTrack *const mWt;
bool mDefaulted;
wxCheckBox *mDefaultsCheckbox;
wxChoice *mScaleChoice;
wxChoice *mRangeChoice;
wxArrayString mScaleChoices;
wxArrayString mRangeCodes;
wxArrayString mRangeChoices;
WaveformSettings mTempSettings;

View File

@@ -15,6 +15,8 @@ Paul Licameli
#include "../Audacity.h"
#include "WaveformSettings.h"
#include "GUISettings.h"
#include "GUIPrefs.h"
#include <algorithm>
#include <wx/intl.h>
@@ -48,6 +50,7 @@ WaveformSettings::WaveformSettings()
WaveformSettings::WaveformSettings(const WaveformSettings &other)
: scaleType(other.scaleType)
, dBRange(other.dBRange)
{
}
@@ -55,6 +58,7 @@ WaveformSettings &WaveformSettings::operator= (const WaveformSettings &other)
{
if (this != &other) {
scaleType = other.scaleType;
dBRange = other.dBRange;
}
return *this;
}
@@ -73,12 +77,18 @@ bool WaveformSettings::Validate(bool quiet)
std::max(0, std::min(int(stNumScaleTypes) - 1, int(scaleType)))
);
ConvertToEnumeratedDBRange();
ConvertToActualDBRange();
return true;
}
void WaveformSettings::LoadPrefs()
{
scaleType = ScaleType(gPrefs->Read(wxT("/Waveform/ScaleType"), 0L));
bool newPrefFound = gPrefs->Read(wxT("/Waveform/dBRange"), &dBRange);
if (!newPrefFound)
dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
// Enforce legal values
Validate(true);
@@ -89,12 +99,37 @@ void WaveformSettings::LoadPrefs()
void WaveformSettings::SavePrefs()
{
gPrefs->Write(wxT("/Waveform/ScaleType"), long(scaleType));
gPrefs->Write(wxT("/Waveform/dBRange"), long(dBRange));
}
void WaveformSettings::Update()
{
}
void WaveformSettings::ConvertToEnumeratedDBRange()
{
// Assumes the codes are in ascending sequence.
wxArrayString codes;
GUIPrefs::GetRangeChoices(NULL, &codes);
int ii = 0;
for (int nn = codes.size(); ii < nn; ++ii) {
long value = 0;
codes[ii].ToLong(&value);
if (dBRange < value)
break;
}
dBRange = std::max(0, ii - 1);
}
void WaveformSettings::ConvertToActualDBRange()
{
wxArrayString codes;
GUIPrefs::GetRangeChoices(NULL, &codes);
long value = 0;
codes[dBRange].ToLong(&value);
dBRange = int(value);
}
namespace
{
wxArrayString &scaleNamesArray()

View File

@@ -45,6 +45,9 @@ public:
void SavePrefs();
void Update();
void ConvertToEnumeratedDBRange();
void ConvertToActualDBRange();
enum ScaleType {
stLinear,
stLogarithmic,
@@ -56,6 +59,7 @@ public:
static const wxArrayString &GetScaleNames();
ScaleType scaleType;
int dBRange;
// Convenience
bool isLinear() const { return stLinear == scaleType; }