26#include "../widgets/valnum.h"
28#if defined(__WXMSW__) && !defined(__CYGWIN__)
30#define finite(x) _finite(x)
35#include <wx/radiobut.h>
37#include <wx/valtext.h>
38#include <wx/textctrl.h>
57 wxWindow *parent,
bool bHasProfile,
58 bool bAllowTwiddleSettings);
70#ifdef ADVANCED_SETTINGS
71 void EnableDisableSensitivityControls();
77#ifdef ADVANCED_SETTINGS
78 void OnMethodChoice(wxCommandEvent &);
80 void OnPreview(wxCommandEvent &event)
override;
82 void OnCancel( wxCommandEvent &event );
83 void OnHelp( wxCommandEvent &event );
85 void OnText(wxCommandEvent &event);
86 void OnSlider(wxCommandEvent &event);
102 wxRadioButton *mKeepNoise;
105 wxRadioButton *mResidue;
109 DECLARE_EVENT_TABLE()
119 bool bAllowTwiddleSettings)
122 effect, access, &
settings, &parent, bHasProfile, bAllowTwiddleSettings);
124 dlog.CentreOnParent();
127 const auto returnCode = dlog.GetReturnCode();
132 settings.mDoProfile = (returnCode == 1);
172 ID_RADIOBUTTON_KEEPNOISE,
175 ID_RADIOBUTTON_RESIDUE,
178#ifdef ADVANCED_SETTINGS
189#ifdef ATTACK_AND_RELEASE
190 ID_ATTACK_TIME_SLIDER,
193 ID_RELEASE_TIME_SLIDER,
194 ID_RELEASE_TIME_TEXT,
202#ifdef ADVANCED_SETTINGS
204 ID_OLD_SENSITIVITY_TEXT,
206 END_OF_ADVANCED_SLIDERS,
220 double Value(
long sliderSetting)
const
224 (double(sliderSetting) / sliderMax) * (valueMax - valueMin);
229 return std::clamp<long>(
230 0.5 + sliderMax * (value - valueMin) / (valueMax - valueMin),
234 wxString
Text(
double value)
const
237 return wxString::Format(
format, (
int)(value));
239 return wxString::Format(
format, value);
244 wxTextCtrl *
const text =
S.Id(
id + 1)
245 .Validator<FloatingPointValidator<double>>(
248 NumValidatorStyle::DEFAULT,
251 .AddTextBox(textBoxCaption,
wxT(
""), 0);
253 wxSlider *
const slider =
256 .Style(wxSL_HORIZONTAL)
257 .MinSize( { 150, -1 } )
258 .AddSlider( {}, 0, sliderMax);
273 :
field(f), valueMin(vMin), valueMax(vMax), sliderMax(sMax),
format(fmt), formatAsInt(fAsInt)
274 , textBoxCaption(caption), sliderName(
name)
282 0.0, 48.0, 48,
wxT(
"%d"),
true,
283 XXO(
"&Noise reduction (dB):"),
XO(
"Noise reduction")),
285 0.01, 24.0, 48,
wxT(
"%.2f"),
false,
286 XXO(
"&Sensitivity:"),
XO(
"Sensitivity")),
287#ifdef ATTACK_AND_RELEASE
289 0, 1.0, 100,
wxT(
"%.2f"),
false,
290 XXO(
"Attac&k time (secs):"),
XO(
"Attack time")),
292 0, 1.0, 100,
wxT(
"%.2f"),
false,
293 XXO(
"R&elease time (secs):"),
XO(
"Release time")),
296 0, 12, 12,
wxT(
"%d"),
true,
297 XXO(
"&Frequency smoothing (bands):"),
XO(
"Frequency smoothing")),
299#ifdef ADVANCED_SETTINGS
301 -20.0, 20.0, 4000,
wxT(
"%.2f"),
false,
302 XXO(
"Sensiti&vity (dB):"),
XO(
"Old Sensitivity")),
328#ifdef ADVANCED_SETTINGS
329 EVT_CHOICE(ID_CHOICE_METHOD, EffectNoiseReduction::Dialog::OnMethodChoice)
341#ifdef ATTACK_AND_RELEASE
350#ifdef ADVANCED_SETTINGS
359 wxWindow *parent,
bool bHasProfile,
bool bAllowTwiddleSettings)
365 , mbHasProfile(bHasProfile)
366 , mbAllowTwiddleSettings(bAllowTwiddleSettings)
378 wxButton *
const pButtonPreview =
380 wxButton *
const pButtonReduceNoise =
381 (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
383 if (mbHasProfile || mbAllowTwiddleSettings) {
384 pButtonPreview->Enable(!mbAllowTwiddleSettings);
385 pButtonReduceNoise->SetFocus();
388 pButtonPreview->Enable(
false);
389 pButtonReduceNoise->Enable(
false);
404 static const int toDisable[] = {
411#ifdef ATTACK_AND_RELEASE
412 ID_ATTACK_TIME_SLIDER,
415 ID_RELEASE_TIME_SLIDER,
416 ID_RELEASE_TIME_TEXT,
419 static const auto nToDisable =
sizeof(toDisable) /
sizeof(toDisable[0]);
423 mKeepNoise->GetValue();
427 for (
auto ii = nToDisable; ii--;)
428 wxWindow::FindWindowById(toDisable[ii],
this)->Enable(!bIsolating);
431#ifdef ADVANCED_SETTINGS
432void EffectNoiseReduction::Dialog::EnableDisableSensitivityControls()
434 wxChoice *
const pChoice =
435 static_cast<wxChoice*
>(wxWindow::FindWindowById(ID_CHOICE_METHOD,
this));
436 const bool bOldMethod =
438 wxWindow::FindWindowById(ID_OLD_SENSITIVITY_SLIDER,
this)->Enable(bOldMethod);
439 wxWindow::FindWindowById(ID_OLD_SENSITIVITY_TEXT,
this)->Enable(bOldMethod);
460 if (mKeepSignal->GetValue())
463 else if (mKeepNoise->GetValue())
470 DisableControlsIfIsolating();
473#ifdef ADVANCED_SETTINGS
474void EffectNoiseReduction::Dialog::OnMethodChoice(wxCommandEvent &)
476 EnableDisableSensitivityControls();
487 *m_pSettings = mTempSettings;
488 m_pSettings->mDoProfile =
false;
516 S.StartStatic(
XO(
"Step 1"));
518 S.AddVariableText(
XO(
519"Select a few seconds of just noise so Audacity knows what to filter out,\nthen click Get Noise Profile:"));
525 S.StartStatic(
XO(
"Step 2"));
527 S.AddVariableText(
XO(
528"Select all of the audio you want filtered, choose how much noise you want\nfiltered out, and then click 'OK' to reduce noise.\n"));
530 S.StartMultiColumn(3, wxEXPAND);
549 wxALIGN_CENTER_HORIZONTAL);
551 S.AddPrompt(
XXO(
"Noise:"));
554 .AddRadioButton(
XXO(
"Re&duce"));
556 mKeepNoise =
S.Id(ID_RADIOBUTTON_KEEPNOISE)
557 .AddRadioButtonToGroup(
XXO(
"&Isolate"));
560 mResidue =
S.Id(ID_RADIOBUTTON_RESIDUE)
562 .AddRadioButtonToGroup(
XXO(
"Resid&ue"));
570#ifdef ADVANCED_SETTINGS
571 S.StartStatic(
XO(
"Advanced Settings"));
573 S.StartMultiColumn(2);
575 S.TieChoice(
XXO(
"&Window types:"),
576 mTempSettings.mWindowTypes,
581 return windowTypeChoices;
585 S.TieChoice(
XXO(
"Window si&ze:"),
586 mTempSettings.mWindowSizeChoice,
596 XO(
"2048 (default)") ,
603 S.TieChoice(
XXO(
"S&teps per window:"),
604 mTempSettings.mStepsPerWindowChoice,
615 S.Id(ID_CHOICE_METHOD)
616 .TieChoice(
XXO(
"Discrimination &method:"),
617 mTempSettings.mMethod,
621#ifndef OLD_METHOD_AVAILABLE
624 for (
auto ii = 0; ii < nn; ++ii)
626 return methodChoices;
631 S.StartMultiColumn(3, wxEXPAND);
653 static_cast<wxSlider*
>(wxWindow::FindWindowById(
id,
this));
655 static_cast<wxTextCtrl*
>(wxWindow::FindWindowById(
id + 1,
this));
657 const double field = mTempSettings.*(info.field);
658 text->SetValue(info.Text(
field));
659 slider->SetValue(info.SliderSetting(
field));
662 mKeepSignal->SetValue(mTempSettings.mNoiseReductionChoice ==
NRC_REDUCE_NOISE);
671 DisableControlsIfIsolating();
672#ifdef ADVANCED_SETTINGS
673 EnableDisableSensitivityControls();
681 if( !wxWindow::Validate() )
687 wxCommandEvent dummy;
688 OnNoiseReductionChoice(dummy);
690 return mTempSettings.Validate(m_pEffect);
695 int id =
event.GetId();
699 static_cast<wxTextCtrl*
>(wxWindow::FindWindowById(
id,
this));
701 static_cast<wxSlider*
>(wxWindow::FindWindowById(
id - 1,
this));
702 double &
field = mTempSettings.*(info.field);
704 text->GetValue().ToDouble(&
field);
705 slider->SetValue(info.SliderSetting(
field));
710 int id =
event.GetId();
714 static_cast<wxSlider*
>(wxWindow::FindWindowById(
id,
this));
716 static_cast<wxTextCtrl*
>(wxWindow::FindWindowById(
id + 1,
this));
717 double &
field = mTempSettings.*(info.field);
719 field = info.Value(slider->GetValue());
720 text->SetValue(info.Text(
field));
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
#define ID_EFFECT_PREVIEW
void EffectPreview(EffectBase &effect, EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly)
Calculate temporary tracks of limited length with effect applied and play.
std::function< DialogFactoryResults(wxWindow &parent, EffectBase &, EffectUIServices &, EffectSettingsAccess &) > EffectDialogFactory
Type of function that creates a dialog for an effect.
XXO("&Cut/Copy/Paste Toolbar")
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
@ ID_NEW_SENSITIVITY_SLIDER
@ ID_NEW_SENSITIVITY_TEXT
@ ID_RADIOBUTTON_KEEPSIGNAL
static Settings & settings()
std::vector< TranslatableString > TranslatableStrings
Base class for many of the effects in Audacity.
bool TransferDataToWindow() override
bool TransferDataFromWindow() override
bool IsBatchProcessing() const override
void SetSkipStateFlag(bool flag)
static EffectManager & Get()
Dialog used with EffectNoiseReduction.
const Settings & GetTempSettings() const
void OnNoiseReductionChoice(wxCommandEvent &event)
void DisableControlsIfIsolating()
void OnSlider(wxCommandEvent &event)
void OnHelp(wxCommandEvent &event)
bool TransferDataToWindow() override
EffectNoiseReduction::Settings mTempSettings
EffectSettingsAccess & mAccess
This dialog is modal, so mAccess will live long enough for it.
void PopulateOrExchange(ShuttleGui &S) override
void OnText(wxCommandEvent &event)
Dialog(EffectNoiseReduction *effect, EffectSettingsAccess &access, Settings *settings, wxWindow *parent, bool bHasProfile, bool bAllowTwiddleSettings)
wxRadioButton * mKeepSignal
void OnReduceNoise(wxCommandEvent &event)
void OnPreview(wxCommandEvent &event) override
EffectNoiseReduction * m_pEffect
bool mbAllowTwiddleSettings
void OnGetProfile(wxCommandEvent &event)
void OnCancel(wxCommandEvent &event)
EffectNoiseReduction::Settings * m_pSettings
bool TransferDataFromWindow() override
int ShowHostInterface(EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
double mFreqSmoothingBands
std::unique_ptr< Settings > mSettings
std::unique_ptr< Statistics > mStatistics
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
virtual bool TransferDataFromWindow(EffectSettings &settings)
Holds a msgid for the translation catalog; may also bind format arguments.
const ControlInfo * controlInfo()
BuiltinEffectsModule::Registration< EffectNoiseReduction > reg
int PromptUser(EffectNoiseReduction::Settings &settings, EffectNoiseReduction *effect, EffectSettingsAccess &access, wxWindow &parent, bool bHasProfile, bool bAllowTwiddleSettings)
const struct anonymous_namespace{NoiseReductionBase.cpp}::WindowTypesInfo windowTypesInfo[WT_N_WINDOW_TYPES]
const struct anonymous_namespace{NoiseReductionBase.cpp}::DiscriminationMethodInfo discriminationMethodInfo[DM_N_METHODS]
long SliderSetting(double value) const
wxString Text(double value) const
void CreateControls(int id, ShuttleGui &S) const
const TranslatableString textBoxCaption
doubleEffectNoiseReduction::Settings::* MemberPointer
ControlInfo(MemberPointer f, double vMin, double vMax, long sMax, const wxChar *fmt, bool fAsInt, const TranslatableString &caption, const TranslatableString &name)
double Value(long sliderSetting) const
const TranslatableString sliderName