1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-23 23:03:55 +02:00

Restore non-preset values when Factory Preset -> Defaults is selected

This commit is contained in:
Leland Lucius
2015-04-27 10:52:42 -05:00
parent 7407243e25
commit 27657ddea7
6 changed files with 101 additions and 66 deletions

View File

@@ -139,6 +139,13 @@ bool EffectChangePitch::SetAutomationParameters(EffectAutomationParameters & par
return true; return true;
} }
bool EffectChangePitch::LoadFactoryDefaults()
{
DeduceFrequencies();
return Effect::LoadFactoryDefaults();
}
// Effect implementation // Effect implementation
bool EffectChangePitch::Init() bool EffectChangePitch::Init()
@@ -174,20 +181,6 @@ void EffectChangePitch::PopulateOrExchange(ShuttleGui & S)
{ {
DeduceFrequencies(); // Set frequency-related control values based on sample. DeduceFrequencies(); // Set frequency-related control values based on sample.
// effect parameters
double dFromMIDInote = FreqToMIDInote(m_dStartFrequency);
double dToMIDInote = dFromMIDInote + m_dSemitonesChange;
m_nFromPitch = PitchIndex(dFromMIDInote);
m_nFromOctave = PitchOctave(dFromMIDInote);
m_nToPitch = PitchIndex(dToMIDInote);
m_nToOctave = PitchOctave(dToMIDInote);
m_dSemitonesChange = m_dSemitonesChange;
m_FromFrequency = m_dStartFrequency;
Calc_PercentChange();
Calc_ToFrequency();
wxArrayString pitch; wxArrayString pitch;
pitch.Add(wxT("C")); pitch.Add(wxT("C"));
pitch.Add(wxT("C#/Db")); pitch.Add(wxT("C#/Db"));
@@ -315,6 +308,7 @@ bool EffectChangePitch::TransferDataToWindow()
Update_Spin_FromOctave(); Update_Spin_FromOctave();
Update_Spin_ToOctave(); Update_Spin_ToOctave();
Update_Text_SemitonesChange(); Update_Text_SemitonesChange();
Update_Text_FromFrequency();
Update_Text_ToFrequency(); Update_Text_ToFrequency();
Update_Text_PercentChange(); Update_Text_PercentChange();
Update_Slider_PercentChange(); Update_Slider_PercentChange();
@@ -408,6 +402,17 @@ void EffectChangePitch::DeduceFrequencies()
lag = (windowSize/2 - 1) - argmax; lag = (windowSize/2 - 1) - argmax;
m_dStartFrequency = rate / lag; m_dStartFrequency = rate / lag;
} }
double dFromMIDInote = FreqToMIDInote(m_dStartFrequency);
double dToMIDInote = dFromMIDInote + m_dSemitonesChange;
m_nFromPitch = PitchIndex(dFromMIDInote);
m_nFromOctave = PitchOctave(dFromMIDInote);
m_nToPitch = PitchIndex(dToMIDInote);
m_nToOctave = PitchOctave(dToMIDInote);
m_FromFrequency = m_dStartFrequency;
Calc_PercentChange();
Calc_ToFrequency();
} }
// calculations // calculations

View File

@@ -52,6 +52,7 @@ public:
virtual bool GetAutomationParameters(EffectAutomationParameters & parms); virtual bool GetAutomationParameters(EffectAutomationParameters & parms);
virtual bool SetAutomationParameters(EffectAutomationParameters & parms); virtual bool SetAutomationParameters(EffectAutomationParameters & parms);
virtual bool LoadFactoryDefaults();
// Effect implementation // Effect implementation

View File

@@ -139,6 +139,14 @@ bool EffectChangeSpeed::SetAutomationParameters(EffectAutomationParameters & par
return true; return true;
} }
bool EffectChangeSpeed::LoadFactoryDefaults()
{
mFromVinyl = kVinyl_33AndAThird;
mFormat = _("hh:mm:ss + milliseconds");
return Effect::LoadFactoryDefaults();
}
// Effect implementation // Effect implementation
bool EffectChangeSpeed::CheckWhetherSkipEffect() bool EffectChangeSpeed::CheckWhetherSkipEffect()
@@ -275,6 +283,9 @@ bool EffectChangeSpeed::Process()
void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S) void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S)
{ {
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat, mFormat);
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl, mFromVinyl);
S.SetBorder(5); S.SetBorder(5);
S.StartVerticalLay(0); S.StartVerticalLay(0);
@@ -394,9 +405,6 @@ bool EffectChangeSpeed::TransferDataToWindow()
return false; return false;
} }
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat, mFormat);
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl, mFromVinyl);
if (mFromVinyl == kVinyl_NA) if (mFromVinyl == kVinyl_NA)
{ {
mFromVinyl = kVinyl_33AndAThird; mFromVinyl = kVinyl_33AndAThird;

View File

@@ -47,6 +47,7 @@ public:
virtual bool GetAutomationParameters(EffectAutomationParameters & parms); virtual bool GetAutomationParameters(EffectAutomationParameters & parms);
virtual bool SetAutomationParameters(EffectAutomationParameters & parms); virtual bool SetAutomationParameters(EffectAutomationParameters & parms);
virtual bool LoadFactoryDefaults();
// Effect implementation // Effect implementation

View File

@@ -376,6 +376,16 @@ bool EffectEqualization::SetAutomationParameters(EffectAutomationParameters & pa
return true; return true;
} }
bool EffectEqualization::LoadFactoryDefaults()
{
mdBMin = DEF_dBMin;
mdBMax = DEF_dBMax;
mDrawMode = DEF_DrawMode;
mDrawGrid = DEF_DrawGrid;
return Effect::LoadFactoryDefaults();
}
// EffectUIClientInterface implementation // EffectUIClientInterface implementation
bool EffectEqualization::ValidateUI() bool EffectEqualization::ValidateUI()
@@ -895,6 +905,7 @@ bool EffectEqualization::TransferDataToWindow()
if (mDrawMode) if (mDrawMode)
{ {
mDraw->SetValue(true); mDraw->SetValue(true);
UpdateDraw();
} }
else else
{ {
@@ -1841,6 +1852,60 @@ void EffectEqualization::LayoutEQSliders()
mUIParent->RefreshRect(wxRect(szrG->GetPosition(), szrGSize)); mUIParent->RefreshRect(wxRect(szrG->GetPosition(), szrGSize));
} }
void EffectEqualization::UpdateDraw()
{
int numPoints = mLogEnvelope->GetNumberOfPoints();
double *when = new double[ numPoints ];
double *value = new double[ numPoints ];
double deltadB = 0.1;
double dx, dy, dx1, dy1, err;
mLogEnvelope->GetPoints( when, value, numPoints );
// set 'unnamed' as the selected curve
EnvelopeUpdated();
bool flag = true;
while (flag)
{
flag = false;
int numDeleted = 0;
mLogEnvelope->GetPoints( when, value, numPoints );
for(int j=0;j<numPoints-2;j++)
{
dx = when[j+2+numDeleted] - when[j+numDeleted];
dy = value[j+2+numDeleted] - value[j+numDeleted];
dx1 = when[j+numDeleted+1] - when[j+numDeleted];
dy1 = dy * dx1 / dx;
err = fabs(value[j+numDeleted+1] - (value[j+numDeleted] + dy1));
if( err < deltadB )
{ // within < deltadB dB?
mLogEnvelope->Delete(j+1);
numPoints--;
numDeleted++;
flag = true;
}
}
}
delete [] when;
delete [] value;
if(mLin)
{
EnvLogToLin();
mEnvelope = mLinEnvelope;
mFreqRuler->ruler.SetLog(false);
mFreqRuler->ruler.SetRange(0, mHiFreq);
}
szrV->Show(szrG,false);
szrH->Show(szrI,false);
szrH->Show(szrL,true);
mUIParent->Layout();
wxGetTopLevelParent(mUIParent)->Layout();
mPanel->ForceRecalc(); // it may have changed slightly due to the deletion of points
}
void EffectEqualization::UpdateGraphic() void EffectEqualization::UpdateGraphic()
{ {
double loLog = log10(mLoFreq); double loLog = log10(mLoFreq);
@@ -2323,56 +2388,8 @@ void EffectEqualization::OnInterp(wxCommandEvent & WXUNUSED(event))
void EffectEqualization::OnDrawMode(wxCommandEvent & WXUNUSED(event)) void EffectEqualization::OnDrawMode(wxCommandEvent & WXUNUSED(event))
{ {
int numPoints = mLogEnvelope->GetNumberOfPoints(); UpdateDraw();
double *when = new double[ numPoints ];
double *value = new double[ numPoints ];
double deltadB = 0.1;
double dx, dy, dx1, dy1, err;
mLogEnvelope->GetPoints( when, value, numPoints );
// set 'unnamed' as the selected curve
EnvelopeUpdated();
bool flag = true;
while (flag)
{
flag = false;
int numDeleted = 0;
mLogEnvelope->GetPoints( when, value, numPoints );
for(int j=0;j<numPoints-2;j++)
{
dx = when[j+2+numDeleted] - when[j+numDeleted];
dy = value[j+2+numDeleted] - value[j+numDeleted];
dx1 = when[j+numDeleted+1] - when[j+numDeleted];
dy1 = dy * dx1 / dx;
err = fabs(value[j+numDeleted+1] - (value[j+numDeleted] + dy1));
if( err < deltadB )
{ // within < deltadB dB?
mLogEnvelope->Delete(j+1);
numPoints--;
numDeleted++;
flag = true;
}
}
}
delete [] when;
delete [] value;
if(mLin)
{
EnvLogToLin();
mEnvelope = mLinEnvelope;
mFreqRuler->ruler.SetLog(false);
mFreqRuler->ruler.SetRange(0, mHiFreq);
}
szrV->Show(szrG,false);
szrH->Show(szrI,false);
szrH->Show(szrL,true);
mUIParent->Layout();
wxGetTopLevelParent(mUIParent)->Layout();
mPanel->ForceRecalc(); // it may have changed slightly due to the deletion of points
mDrawMode = true; mDrawMode = true;
} }

View File

@@ -101,6 +101,7 @@ public:
virtual bool GetAutomationParameters(EffectAutomationParameters & parms); virtual bool GetAutomationParameters(EffectAutomationParameters & parms);
virtual bool SetAutomationParameters(EffectAutomationParameters & parms); virtual bool SetAutomationParameters(EffectAutomationParameters & parms);
virtual bool LoadFactoryDefaults();
// EffectUIClientInterface implementation // EffectUIClientInterface implementation
@@ -149,6 +150,8 @@ private:
XMLTagHandler *HandleXMLChild(const wxChar *tag); XMLTagHandler *HandleXMLChild(const wxChar *tag);
void WriteXML(XMLWriter &xmlFile); void WriteXML(XMLWriter &xmlFile);
void UpdateDraw();
void LayoutEQSliders(); void LayoutEQSliders();
void UpdateGraphic(void); void UpdateGraphic(void);
void EnvLogToLin(void); void EnvLogToLin(void);