2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
Amplify.cpp
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
Vaughan Johnson (Preview)
|
|
|
|
|
|
|
|
*******************************************************************//**
|
|
|
|
|
|
|
|
\class EffectAmplify
|
2015-05-09 16:36:54 +00:00
|
|
|
\brief An Effect that makes a sound louder or softer.
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
This rewritten class supports a smart Amplify effect - it calculates
|
|
|
|
the maximum amount of gain that can be applied to all tracks without
|
|
|
|
causing clipping and selects this as the default parameter.
|
|
|
|
|
|
|
|
*//*******************************************************************/
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2015-06-18 14:24:36 +00:00
|
|
|
#include "Amplify.h"
|
2019-01-17 23:31:08 +00:00
|
|
|
#include "LoadEffects.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
2015-04-17 03:53:42 +00:00
|
|
|
#include <float.h>
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/checkbox.h>
|
2015-04-17 03:53:42 +00:00
|
|
|
#include <wx/intl.h>
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/sizer.h>
|
2018-11-11 21:18:23 +00:00
|
|
|
#include <wx/slider.h>
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/valtext.h>
|
2015-05-17 23:17:36 +00:00
|
|
|
#include <wx/log.h>
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-02-06 18:44:52 +00:00
|
|
|
#include "../Shuttle.h"
|
2015-06-18 14:24:36 +00:00
|
|
|
#include "../ShuttleGui.h"
|
2015-04-17 03:53:42 +00:00
|
|
|
#include "../WaveTrack.h"
|
|
|
|
#include "../widgets/valnum.h"
|
|
|
|
|
2015-05-17 23:17:36 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_Amp = 10000,
|
|
|
|
ID_Peak,
|
|
|
|
ID_Clip
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define keys, defaults, minimums, and maximums for the effect parameters
|
|
|
|
//
|
2015-04-27 08:44:10 +00:00
|
|
|
// Name Type Key Def Min Max Scale
|
2017-10-03 22:07:04 +00:00
|
|
|
Param( Ratio, float, wxT("Ratio"), 0.9f, 0.003162f, 316.227766f, 1.0f );
|
2015-04-27 08:44:10 +00:00
|
|
|
Param( Amp, float, wxT(""), -0.91515f, -50.0f, 50.0f, 10.0f );
|
2018-03-25 16:24:53 +00:00
|
|
|
Param( Clipping, bool, wxT("AllowClipping"), false, false, true, 1 );
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// EffectAmplify
|
|
|
|
//
|
|
|
|
|
2019-01-17 22:33:49 +00:00
|
|
|
const ComponentInterfaceSymbol EffectAmplify::Symbol
|
|
|
|
{ XO("Amplify") };
|
|
|
|
|
2019-01-17 23:31:08 +00:00
|
|
|
namespace{ BuiltinEffectsModule::Registration< EffectAmplify > reg; }
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
BEGIN_EVENT_TABLE(EffectAmplify, wxEvtHandler)
|
|
|
|
EVT_SLIDER(ID_Amp, EffectAmplify::OnAmpSlider)
|
|
|
|
EVT_TEXT(ID_Amp, EffectAmplify::OnAmpText)
|
|
|
|
EVT_TEXT(ID_Peak, EffectAmplify::OnPeakText)
|
|
|
|
EVT_CHECKBOX(ID_Clip, EffectAmplify::OnClipCheckBox)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
EffectAmplify::EffectAmplify()
|
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
mAmp = DEF_Amp;
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(mAmp);
|
2015-05-19 14:25:49 +00:00
|
|
|
mRatioClip = 0.0;
|
2015-04-27 08:44:10 +00:00
|
|
|
mCanClip = false;
|
2015-05-17 23:17:36 +00:00
|
|
|
mPeak = 0.0;
|
2015-05-15 11:47:51 +00:00
|
|
|
|
|
|
|
SetLinearEffectFlag(true);
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
EffectAmplify::~EffectAmplify()
|
|
|
|
{
|
2014-06-03 20:30:19 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
// ComponentInterface implementation
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
ComponentInterfaceSymbol EffectAmplify::GetSymbol()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-01-17 22:33:49 +00:00
|
|
|
return Symbol;
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-12-08 18:53:48 +00:00
|
|
|
TranslatableString EffectAmplify::GetDescription()
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
|
|
|
// Note: This is useful only after ratio has been set.
|
2019-12-08 18:53:48 +00:00
|
|
|
return XO("Increases or decreases the volume of the audio you have selected");
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2021-06-06 16:18:35 +00:00
|
|
|
ManualPageID EffectAmplify::ManualPage()
|
2017-05-15 21:00:33 +00:00
|
|
|
{
|
2021-06-06 16:18:35 +00:00
|
|
|
return L"Amplify";
|
2017-05-15 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
// EffectDefinitionInterface implementation
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
EffectType EffectAmplify::GetType()
|
|
|
|
{
|
|
|
|
return EffectTypeProcess;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
// EffectClientInterface implementation
|
|
|
|
|
2016-09-02 19:53:09 +00:00
|
|
|
unsigned EffectAmplify::GetAudioInCount()
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
|
|
|
return 1;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 19:53:09 +00:00
|
|
|
unsigned EffectAmplify::GetAudioOutCount()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
return 1;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t EffectAmplify::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2016-08-24 15:24:26 +00:00
|
|
|
for (decltype(blockLen) i = 0; i < blockLen; i++)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
|
|
|
outBlock[0][i] = inBlock[0][i] * mRatio;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
return blockLen;
|
|
|
|
}
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
bool EffectAmplify::DefineParams( ShuttleParams & S ){
|
|
|
|
S.SHUTTLE_PARAM( mRatio, Ratio );
|
2018-03-25 17:18:53 +00:00
|
|
|
if (!IsBatchProcessing())
|
|
|
|
S.SHUTTLE_PARAM( mCanClip, Clipping );
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-02-21 14:24:25 +00:00
|
|
|
bool EffectAmplify::GetAutomationParameters(CommandParameters & parms)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
|
|
|
parms.WriteFloat(KEY_Ratio, mRatio);
|
2018-03-25 17:18:53 +00:00
|
|
|
if (!IsBatchProcessing())
|
|
|
|
parms.WriteFloat(KEY_Clipping, mCanClip);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-21 14:24:25 +00:00
|
|
|
bool EffectAmplify::SetAutomationParameters(CommandParameters & parms)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-27 08:44:10 +00:00
|
|
|
ReadAndVerifyFloat(Ratio);
|
2015-04-17 03:53:42 +00:00
|
|
|
mRatio = Ratio;
|
2018-03-25 17:18:53 +00:00
|
|
|
|
|
|
|
if (!IsBatchProcessing()){
|
|
|
|
ReadAndVerifyBool(Clipping);
|
|
|
|
mCanClip = Clipping;
|
|
|
|
} else {
|
2018-03-25 16:24:53 +00:00
|
|
|
mCanClip = true;
|
2018-03-25 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 19:10:24 +00:00
|
|
|
bool EffectAmplify::LoadFactoryDefaults()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
mRatioClip = 0.0;
|
|
|
|
if (mPeak > 0.0)
|
|
|
|
{
|
|
|
|
mRatio = 1.0 / mPeak;
|
|
|
|
mRatioClip = mRatio;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mRatio = 1.0;
|
|
|
|
}
|
|
|
|
mCanClip = false;
|
|
|
|
|
|
|
|
return TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
// Effect implementation
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
bool EffectAmplify::Init()
|
|
|
|
{
|
2015-05-17 23:17:36 +00:00
|
|
|
mPeak = 0.0;
|
2015-05-11 19:04:02 +00:00
|
|
|
|
2016-12-31 09:33:35 +00:00
|
|
|
for (auto t : inputTracks()->Selected< const WaveTrack >())
|
2015-05-11 19:04:02 +00:00
|
|
|
{
|
2016-12-31 09:33:35 +00:00
|
|
|
auto pair = t->GetMinMax(mT0, mT1); // may throw
|
2016-12-25 13:40:15 +00:00
|
|
|
const float min = pair.first, max = pair.second;
|
2015-05-11 19:04:02 +00:00
|
|
|
float newpeak = (fabs(min) > fabs(max) ? fabs(min) : fabs(max));
|
2015-05-11 15:51:53 +00:00
|
|
|
|
2015-05-11 19:04:02 +00:00
|
|
|
if (newpeak > mPeak)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
2015-05-11 19:04:02 +00:00
|
|
|
mPeak = newpeak;
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
return true;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 19:04:02 +00:00
|
|
|
void EffectAmplify::Preview(bool dryOnly)
|
|
|
|
{
|
2016-12-15 12:30:14 +00:00
|
|
|
auto cleanup1 = valueRestorer( mRatio );
|
|
|
|
auto cleanup2 = valueRestorer( mPeak );
|
2015-05-11 19:04:02 +00:00
|
|
|
|
|
|
|
Effect::Preview(dryOnly);
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::PopulateOrExchange(ShuttleGui & S)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2018-01-31 01:03:46 +00:00
|
|
|
enum{ precision = 3 }; // allow (a generous) 3 decimal places for Amplification (dB)
|
|
|
|
|
2020-03-02 16:56:43 +00:00
|
|
|
bool batch = IsBatchProcessing();
|
|
|
|
if ( batch )
|
2015-04-27 08:44:10 +00:00
|
|
|
{
|
2020-03-02 16:56:43 +00:00
|
|
|
mCanClip = true;
|
2015-05-17 23:17:36 +00:00
|
|
|
mPeak = 1.0;
|
2015-04-27 08:44:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mPeak > 0.0)
|
|
|
|
{
|
2015-05-17 23:17:36 +00:00
|
|
|
mRatio = 1.0 / mPeak;
|
2015-05-19 14:25:49 +00:00
|
|
|
mRatioClip = mRatio;
|
2015-04-27 08:44:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mRatio = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 22:10:50 +00:00
|
|
|
S.AddSpace(0, 5);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
S.StartVerticalLay(0);
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
// Amplitude
|
|
|
|
S.StartMultiColumn(2, wxCENTER);
|
|
|
|
{
|
2017-10-30 16:23:41 +00:00
|
|
|
mAmpT = S.Id(ID_Amp)
|
|
|
|
.Validator<FloatingPointValidator<double>>(
|
|
|
|
precision, &mAmp, NumValidatorStyle::ONE_TRAILING_ZERO, MIN_Amp, MAX_Amp
|
|
|
|
)
|
2020-05-11 15:28:14 +00:00
|
|
|
.AddTextBox(XXO("&Amplification (dB):"), wxT(""), 12);
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
S.EndMultiColumn();
|
|
|
|
|
|
|
|
// Amplitude
|
|
|
|
S.StartHorizontalLay(wxEXPAND);
|
|
|
|
{
|
2017-10-29 14:27:23 +00:00
|
|
|
mAmpS = S.Id(ID_Amp)
|
2017-10-31 18:52:01 +00:00
|
|
|
.Style(wxSL_HORIZONTAL)
|
2017-10-29 14:27:23 +00:00
|
|
|
.Name(XO("Amplification dB"))
|
|
|
|
.AddSlider( {}, 0, MAX_Amp * SCL_Amp, MIN_Amp * SCL_Amp);
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
S.EndHorizontalLay();
|
|
|
|
|
2015-05-17 23:17:36 +00:00
|
|
|
// Peak
|
2015-04-17 03:53:42 +00:00
|
|
|
S.StartMultiColumn(2, wxCENTER);
|
|
|
|
{
|
2017-10-30 16:23:41 +00:00
|
|
|
mNewPeakT = S.Id(ID_Peak)
|
|
|
|
.Validator<FloatingPointValidator<double>>(
|
|
|
|
// One extra decimal place so that rounding is visible to user
|
|
|
|
// (see: bug 958)
|
|
|
|
precision + 1,
|
|
|
|
&mNewPeak, NumValidatorStyle::ONE_TRAILING_ZERO,
|
|
|
|
// min and max need same precision as what we're validating (bug 963)
|
|
|
|
RoundValue( precision + 1, MIN_Amp + LINEAR_TO_DB(mPeak) ),
|
|
|
|
RoundValue( precision + 1, MAX_Amp + LINEAR_TO_DB(mPeak) )
|
|
|
|
)
|
2020-05-11 15:28:14 +00:00
|
|
|
.AddTextBox(XXO("&New Peak Amplitude (dB):"), wxT(""), 12);
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
S.EndMultiColumn();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
// Clipping
|
|
|
|
S.StartHorizontalLay(wxCENTER);
|
|
|
|
{
|
2020-03-02 16:56:43 +00:00
|
|
|
|
|
|
|
mClip = S.Id(ID_Clip).Disable( batch )
|
2020-05-11 15:28:14 +00:00
|
|
|
.AddCheckBox(XXO("Allo&w clipping"), false);
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
S.EndHorizontalLay();
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
2015-04-17 03:53:42 +00:00
|
|
|
S.EndVerticalLay();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
bool EffectAmplify::TransferDataToWindow()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
// limit range of gain
|
2015-07-24 20:59:34 +00:00
|
|
|
double dBInit = LINEAR_TO_DB(mRatio);
|
2015-05-17 23:17:36 +00:00
|
|
|
double dB = TrapDouble(dBInit, MIN_Amp, MAX_Amp);
|
2015-05-07 09:16:52 +00:00
|
|
|
if (dB != dBInit)
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(dB);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mAmp = LINEAR_TO_DB(mRatio);
|
2015-04-17 03:53:42 +00:00
|
|
|
mAmpT->GetValidator()->TransferToWindow();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-27 08:44:10 +00:00
|
|
|
mAmpS->SetValue((int) (mAmp * SCL_Amp + 0.5f));
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mNewPeak = LINEAR_TO_DB(mRatio * mPeak);
|
2015-04-17 03:53:42 +00:00
|
|
|
mNewPeakT->GetValidator()->TransferToWindow();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-27 08:44:10 +00:00
|
|
|
mClip->SetValue(mCanClip);
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
CheckClip();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
bool EffectAmplify::TransferDataFromWindow()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(TrapDouble(mAmp * SCL_Amp, MIN_Amp * SCL_Amp, MAX_Amp * SCL_Amp) / SCL_Amp);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-04-27 08:44:10 +00:00
|
|
|
mCanClip = mClip->GetValue();
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2015-05-17 23:17:36 +00:00
|
|
|
if (!mCanClip && mRatio * mPeak > 1.0)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
2015-05-17 23:17:36 +00:00
|
|
|
mRatio = 1.0 / mPeak;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
// EffectAmplify implementation
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::CheckClip()
|
|
|
|
{
|
2015-05-19 14:25:49 +00:00
|
|
|
EnableApply(mClip->GetValue() || (mPeak > 0.0 && mRatio <= mRatioClip));
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::OnAmpText(wxCommandEvent & WXUNUSED(evt))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
if (!mAmpT->GetValidator()->TransferFromWindow())
|
|
|
|
{
|
|
|
|
EnableApply(false);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(TrapDouble(mAmp * SCL_Amp, MIN_Amp * SCL_Amp, MAX_Amp * SCL_Amp) / SCL_Amp);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mAmpS->SetValue((int) (LINEAR_TO_DB(mRatio) * SCL_Amp + 0.5));
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mNewPeak = LINEAR_TO_DB(mRatio * mPeak);
|
2015-04-17 03:53:42 +00:00
|
|
|
mNewPeakT->GetValidator()->TransferToWindow();
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
CheckClip();
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::OnPeakText(wxCommandEvent & WXUNUSED(evt))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
if (!mNewPeakT->GetValidator()->TransferFromWindow())
|
|
|
|
{
|
|
|
|
EnableApply(false);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-05-19 14:25:49 +00:00
|
|
|
if (mNewPeak == 0.0)
|
|
|
|
mRatio = mRatioClip;
|
|
|
|
else
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(mNewPeak) / mPeak;
|
2015-05-07 09:16:52 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
double ampInit = LINEAR_TO_DB(mRatio);
|
2015-05-17 23:17:36 +00:00
|
|
|
mAmp = TrapDouble(ampInit, MIN_Amp, MAX_Amp);
|
2015-05-07 09:16:52 +00:00
|
|
|
if (mAmp != ampInit)
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(mAmp);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
mAmpT->GetValidator()->TransferToWindow();
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-04-27 08:44:10 +00:00
|
|
|
mAmpS->SetValue((int) (mAmp * SCL_Amp + 0.5f));
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
CheckClip();
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::OnAmpSlider(wxCommandEvent & evt)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-05-17 23:17:36 +00:00
|
|
|
double dB = evt.GetInt() / SCL_Amp;
|
2015-07-24 20:59:34 +00:00
|
|
|
mRatio = DB_TO_LINEAR(TrapDouble(dB, MIN_Amp, MAX_Amp));
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-05-17 23:17:36 +00:00
|
|
|
double dB2 = (evt.GetInt() - 1) / SCL_Amp;
|
2015-07-24 20:59:34 +00:00
|
|
|
double ratio2 = DB_TO_LINEAR(TrapDouble(dB2, MIN_Amp, MAX_Amp));
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-05-17 23:17:36 +00:00
|
|
|
if (!mClip->GetValue() && mRatio * mPeak > 1.0 && ratio2 * mPeak < 1.0)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
|
|
|
mRatio = 1.0 / mPeak;
|
|
|
|
}
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mAmp = LINEAR_TO_DB(mRatio);
|
2015-04-17 03:53:42 +00:00
|
|
|
mAmpT->GetValidator()->TransferToWindow();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-24 20:59:34 +00:00
|
|
|
mNewPeak = LINEAR_TO_DB(mRatio * mPeak);
|
2015-04-17 03:53:42 +00:00
|
|
|
mNewPeakT->GetValidator()->TransferToWindow();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
CheckClip();
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectAmplify::OnClipCheckBox(wxCommandEvent & WXUNUSED(evt))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
CheckClip();
|
|
|
|
}
|