24#include <wx/checkbox.h>
26#include <wx/stattext.h>
30#include "../ProjectFileManager.h"
31#include "../ShuttleGui.h"
32#include "../WaveTrack.h"
33#include "../widgets/valnum.h"
34#include "../widgets/ProgressDialog.h"
56 Parameters().Reset(*
this);
57 SetLinearEffectFlag(
false);
73 return XO(
"Sets the peak amplitude of one or more tracks");
92 return ((
mGain ==
false) && (
mDC ==
false));
112 bool bGoodResult =
true;
116 topMsg =
XO(
"Removing DC offset and Normalizing...\n");
118 topMsg =
XO(
"Removing DC offset...\n");
120 topMsg =
XO(
"Normalizing without removing DC offset...\n");
122 topMsg =
XO(
"Not doing anything...\n");
128 double trackStart = track->GetStartTime();
129 double trackEnd = track->GetEndTime();
142 wxString trackName = track->GetName();
146 extent = std::numeric_limits<float>::lowest();
147 std::vector<float> offsets;
149 auto msg = (range.size() == 1)
152 XO(
"Analyzing: %s").Format( trackName )
155 XO(
"Analyzing first track of stereo pair: %s").Format( trackName );
158 for (
auto channel : range) {
162 AnalyseTrack( channel, msg, progress, offset, extent2 );
165 extent = std::max( extent, extent2 );
166 offsets.push_back(offset);
169 XO(
"Analyzing second track of stereo pair: %s").Format( trackName );
173 if( (extent > 0) &&
mGain ) {
174 mMult = ratio / extent;
179 if (range.size() == 1) {
183 XO(
"Processing: %s").Format( trackName );
188 XO(
"Processing stereo channels independently: %s").Format( trackName );
193 XO(
"Processing first track of stereo pair: %s").Format( trackName );
196 auto pOffset = offsets.begin();
197 for (
auto channel : range) {
199 (bGoodResult =
ProcessOne(channel, msg, progress, *pOffset++)) )
203 XO(
"Processing second track of stereo pair: %s").Format( trackName );
219 S.StartVerticalLay(0);
221 S.StartMultiColumn(2, wxALIGN_CENTER);
223 S.StartVerticalLay(
false);
226 .AddCheckBox(
XXO(
"&Remove DC offset (center on 0.0 vertically)"),
229 S.StartHorizontalLay(wxALIGN_LEFT,
false);
233 .Validator<wxGenericValidator>(&
mGain)
234 .AddCheckBox(
XXO(
"&Normalize peak amplitude to "),
238 .Name(
XO(
"Peak amplitude dB"))
239 .
Validator<FloatingPointValidator<double>>(
242 NumValidatorStyle::ONE_TRAILING_ZERO,
245 .AddTextBox( {}, L
"", 10);
247 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
249 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
251 S.EndHorizontalLay();
255 .AddCheckBox(
XXO(
"N&ormalize stereo channels independently"),
276 double &progress,
float &offset,
float &extent)
285 min = pair.first, max = pair.second;
296 min = -1.0, max = 1.0;
303 wxFAIL_MSG(
"Analysing Track when nothing to do!");
304 min = -1.0, max = 1.0;
307 extent = fmax(fabs(
min), fabs(max));
315 double &progress,
float &offset)
326 auto len = (
end - start).as_double();
350 totalSamples += blockSamples;
365 if( totalSamples > 0 )
391 auto len = (
end - start).as_double();
409 track->
GetFloats(buffer.get(), s, block);
436 for(
decltype(len) i = 0; i < len; i++)
437 mSum += (
double)buffer[i];
442 for(
decltype(len) i = 0; i < len; i++) {
443 float adjFrame = (buffer[i] + offset) *
mMult;
444 buffer[i] = adjFrame;
456 if (!
mUIParent->TransferDataFromWindow())
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 EnableApply(bool enable=true)
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
EffectType GetType() const override
Type determines how it behaves.
static constexpr EffectParameter StereoInd
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
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
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
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
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)
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)
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.