22#include <wx/checkbox.h>
23#include <wx/stattext.h>
27#include "../ProjectFileManager.h"
30#include "../widgets/valnum.h"
53 Parameters().Reset(*
this);
54 SetLinearEffectFlag(
false);
70 return XO(
"Sets the peak amplitude of one or more tracks");
89 return ((
mGain ==
false) && (
mDC ==
false));
109 bool bGoodResult =
true;
113 topMsg =
XO(
"Removing DC offset and Normalizing...\n");
115 topMsg =
XO(
"Removing DC offset...\n");
117 topMsg =
XO(
"Normalizing without removing DC offset...\n");
119 topMsg =
XO(
"Not doing anything...\n");
125 double trackStart = track->GetStartTime();
126 double trackEnd = track->GetEndTime();
139 wxString trackName = track->GetName();
143 extent = std::numeric_limits<float>::lowest();
144 std::vector<float> offsets;
146 auto msg = (range.size() == 1)
149 XO(
"Analyzing: %s").Format( trackName )
152 XO(
"Analyzing first track of stereo pair: %s").Format( trackName );
155 for (
auto channel : range) {
159 AnalyseTrack( channel, msg, progress, offset, extent2 );
162 extent = std::max( extent, extent2 );
163 offsets.push_back(offset);
166 XO(
"Analyzing second track of stereo pair: %s").Format( trackName );
170 if( (extent > 0) &&
mGain ) {
171 mMult = ratio / extent;
176 if (range.size() == 1) {
180 XO(
"Processing: %s").Format( trackName );
185 XO(
"Processing stereo channels independently: %s").Format( trackName );
190 XO(
"Processing first track of stereo pair: %s").Format( trackName );
193 auto pOffset = offsets.begin();
194 for (
auto channel : range) {
196 (bGoodResult =
ProcessOne(channel, msg, progress, *pOffset++)) )
200 XO(
"Processing second track of stereo pair: %s").Format( trackName );
218 S.StartVerticalLay(0);
220 S.StartMultiColumn(2, wxALIGN_CENTER);
222 S.StartVerticalLay(
false);
225 .AddCheckBox(
XXO(
"&Remove DC offset (center on 0.0 vertically)"),
228 S.StartHorizontalLay(wxALIGN_LEFT,
false);
232 .Validator<wxGenericValidator>(&
mGain)
233 .AddCheckBox(
XXO(
"&Normalize peak amplitude to "),
237 .Name(
XO(
"Peak amplitude dB"))
238 .
Validator<FloatingPointValidator<double>>(
241 NumValidatorStyle::ONE_TRAILING_ZERO,
244 .AddTextBox( {}, L
"", 10);
246 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
248 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
250 S.EndHorizontalLay();
254 .AddCheckBox(
XXO(
"N&ormalize stereo channels independently"),
291 double &progress,
float &offset,
float &extent)
300 min = pair.first, max = pair.second;
311 min = -1.0, max = 1.0;
318 wxFAIL_MSG(
"Analysing Track when nothing to do!");
319 min = -1.0, max = 1.0;
322 extent = fmax(fabs(
min), fabs(max));
330 double &progress,
float &offset)
341 auto len = (
end - start).as_double();
365 totalSamples += blockSamples;
380 if( totalSamples > 0 )
406 auto len = (
end - start).as_double();
424 track->
GetFloats(buffer.get(), s, block);
451 for(
decltype(len) i = 0; i < len; i++)
452 mSum += (
double)buffer[i];
457 for(
decltype(len) i = 0; i < len; i++) {
458 float adjFrame = (buffer[i] + offset) *
mMult;
459 buffer[i] = adjFrame;
471 if (!
mUIParent->TransferDataFromWindow())
XXO("&Cut/Copy/Paste Toolbar")
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
std::shared_ptr< TrackList > mOutputTracks
void ReplaceProcessedTracks(const bool bGoodResult)
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
void CopyInputTracks(bool allSyncLockSelected=false)
bool TotalProgress(double frac, const TranslatableString &={}) const
int GetNumWaveTracks() const
Performs effect computation.
An Effect to bring the peak level up to a chosen level.
static constexpr EffectParameter RemoveDC
bool TransferDataFromWindow(EffectSettings &settings) override
EffectType GetType() const override
Type determines how it behaves.
static constexpr EffectParameter StereoInd
bool Process(EffectInstance &instance, EffectSettings &settings) override
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
bool TransferDataToWindow(const EffectSettings &settings) override
const EffectParameterMethods & Parameters() const override
bool AnalyseTrack(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset, float &extent)
bool AnalyseTrackData(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset)
static constexpr EffectParameter PeakLevel
wxWeakRef< wxWindow > mUIParent
wxCheckBox * mGainCheckBox
ComponentInterfaceSymbol GetSymbol() const override
bool ProcessOne(WaveTrack *t, const TranslatableString &msg, double &progress, float offset)
virtual ~EffectNormalize()
static const ComponentInterfaceSymbol Symbol
void OnUpdateUI(wxCommandEvent &evt)
static constexpr EffectParameter ApplyGain
TranslatableString GetDescription() const override
wxTextCtrl * mLevelTextCtrl
wxCheckBox * mStereoIndCheckBox
void ProcessData(float *buffer, size_t len, float offset)
bool CheckWhetherSkipEffect(const EffectSettings &settings) const override
After Init(), tell whether Process() should be skipped.
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
void AnalyseDataDC(float *buffer, size_t len)
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Holds a msgid for the translation catalog; may also bind format arguments.
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
A Track that contains audio waveform data.
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Positions or offsets within audio files need a wide type.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
BuiltinEffectsModule::Registration< EffectNormalize > reg
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.