24#include <wx/checkbox.h>
25#include <wx/stattext.h>
29#include "../ProjectFileManager.h"
30#include "../ShuttleGui.h"
31#include "../WaveTrack.h"
32#include "../widgets/valnum.h"
33#include "../widgets/ProgressDialog.h"
55 Parameters().Reset(*
this);
56 SetLinearEffectFlag(
false);
72 return XO(
"Sets the peak amplitude of one or more tracks");
91 return ((
mGain ==
false) && (
mDC ==
false));
111 bool bGoodResult =
true;
115 topMsg =
XO(
"Removing DC offset and Normalizing...\n");
117 topMsg =
XO(
"Removing DC offset...\n");
119 topMsg =
XO(
"Normalizing without removing DC offset...\n");
121 topMsg =
XO(
"Not doing anything...\n");
127 double trackStart = track->GetStartTime();
128 double trackEnd = track->GetEndTime();
141 wxString trackName = track->GetName();
145 extent = std::numeric_limits<float>::lowest();
146 std::vector<float> offsets;
148 auto msg = (range.size() == 1)
151 XO(
"Analyzing: %s").Format( trackName )
154 XO(
"Analyzing first track of stereo pair: %s").Format( trackName );
157 for (
auto channel : range) {
161 AnalyseTrack( channel, msg, progress, offset, extent2 );
164 extent = std::max( extent, extent2 );
165 offsets.push_back(offset);
168 XO(
"Analyzing second track of stereo pair: %s").Format( trackName );
172 if( (extent > 0) &&
mGain ) {
173 mMult = ratio / extent;
178 if (range.size() == 1) {
182 XO(
"Processing: %s").Format( trackName );
187 XO(
"Processing stereo channels independently: %s").Format( trackName );
192 XO(
"Processing first track of stereo pair: %s").Format( trackName );
195 auto pOffset = offsets.begin();
196 for (
auto channel : range) {
198 (bGoodResult =
ProcessOne(channel, msg, progress, *pOffset++)) )
202 XO(
"Processing second track of stereo pair: %s").Format( trackName );
220 S.StartVerticalLay(0);
222 S.StartMultiColumn(2, wxALIGN_CENTER);
224 S.StartVerticalLay(
false);
227 .AddCheckBox(
XXO(
"&Remove DC offset (center on 0.0 vertically)"),
230 S.StartHorizontalLay(wxALIGN_LEFT,
false);
234 .Validator<wxGenericValidator>(&
mGain)
235 .AddCheckBox(
XXO(
"&Normalize peak amplitude to "),
239 .Name(
XO(
"Peak amplitude dB"))
240 .
Validator<FloatingPointValidator<double>>(
243 NumValidatorStyle::ONE_TRAILING_ZERO,
246 .AddTextBox( {}, L
"", 10);
248 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
250 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
252 S.EndHorizontalLay();
256 .AddCheckBox(
XXO(
"N&ormalize stereo channels independently"),
293 double &progress,
float &offset,
float &extent)
302 min = pair.first, max = pair.second;
313 min = -1.0, max = 1.0;
320 wxFAIL_MSG(
"Analysing Track when nothing to do!");
321 min = -1.0, max = 1.0;
324 extent = fmax(fabs(
min), fabs(max));
332 double &progress,
float &offset)
343 auto len = (
end - start).as_double();
367 totalSamples += blockSamples;
382 if( totalSamples > 0 )
408 auto len = (
end - start).as_double();
426 track->
GetFloats(buffer.get(), s, block);
453 for(
decltype(len) i = 0; i < len; i++)
454 mSum += (
double)buffer[i];
459 for(
decltype(len) i = 0; i < len; i++) {
460 float adjFrame = (buffer[i] + offset) *
mMult;
461 buffer[i] = adjFrame;
473 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)
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
Update the given settings from controls.
EffectType GetType() const override
Type determines how it behaves.
static constexpr EffectParameter StereoInd
bool Process(EffectInstance &instance, EffectSettings &settings) override
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
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()
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
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
Default implementation returns false.
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.
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
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.