Audacity 3.2.0
TruncSilence.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TruncSilence.cpp
6
7 Lynn Allan (from DM's Normalize)
8 Philip Van Baren (more options and boundary fixes)
9
10**********************************************************************/
11#include "TruncSilence.h"
12#include "BasicUI.h"
13#include "EffectEditor.h"
14#include "LoadEffects.h"
15
16#include <wx/checkbox.h>
17#include <wx/choice.h>
18#include <wx/valgen.h>
19
20#include "ShuttleGui.h"
21#include "../widgets/valnum.h"
22#include "AudacityMessageBox.h"
23
25
26BEGIN_EVENT_TABLE(EffectTruncSilence, wxEvtHandler)
27 EVT_CHOICE(wxID_ANY, EffectTruncSilence::OnControlChange)
28 EVT_TEXT(wxID_ANY, EffectTruncSilence::OnControlChange)
30
31std::unique_ptr<EffectEditor> EffectTruncSilence::PopulateOrExchange(
33 const EffectOutputs *)
34{
35 mUIParent = S.GetParent();
36 wxASSERT(nActions == WXSIZEOF(kActionStrings));
37
38 S.AddSpace(0, 5);
39
40 S.StartStatic(XO("Detect Silence"));
41 {
42 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
43 {
44 // Threshold
45 mThresholdText = S
46 .Validator<FloatingPointValidator<double>>(
47 3, &mThresholdDB, NumValidatorStyle::NO_TRAILING_ZEROES,
48 Threshold.min, Threshold.max )
49 .NameSuffix(XO("db"))
50 .AddTextBox(XXO("&Threshold:"), wxT(""), 0);
51 S.AddUnits(XO("dB"));
52
53 // Ignored silence
54 mInitialAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
55 3, &mInitialAllowedSilence,
56 NumValidatorStyle::NO_TRAILING_ZEROES,
57 Minimum.min, Minimum.max)
58 .NameSuffix(XO("seconds"))
59 .AddTextBox(XXO("&Duration:"), wxT(""), 12);
60 S.AddUnits(XO("seconds"));
61 }
62 S.EndMultiColumn();
63 }
64 S.EndStatic();
65
66 S.StartStatic(XO("Action"));
67 {
68 S.StartHorizontalLay();
69 {
70 // Action choices
71 auto actionChoices = Msgids( kActionStrings, nActions );
72 mActionChoice = S
73 .Validator<wxGenericValidator>(&mActionIndex)
74 .MinSize( { -1, -1 } )
75 .AddChoice( {}, actionChoices );
76 }
77 S.EndHorizontalLay();
78 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
79 {
80 // Truncation / Compression factor
81
82 mTruncLongestAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
83 3, &mTruncLongestAllowedSilence,
84 NumValidatorStyle::NO_TRAILING_ZEROES,
85 Truncate.min, Truncate.max )
86 .NameSuffix(XO("seconds"))
87 .AddTextBox(XXO("Tr&uncate to:"), wxT(""), 12);
88 S.AddUnits(XO("seconds"));
89
90 mSilenceCompressPercentT = S.Validator<FloatingPointValidator<double>>(
91 3, &mSilenceCompressPercent,
92 NumValidatorStyle::NO_TRAILING_ZEROES,
93 Compress.min, Compress.max )
94 .NameSuffix(XO("%"))
95 .AddTextBox(XXO("C&ompress to:"), wxT(""), 12);
96 S.AddUnits(XO("%"));
97 }
98 S.EndMultiColumn();
99
100 S.StartMultiColumn(2, wxALIGN_CENTER_HORIZONTAL);
101 {
102 mIndependent = S.AddCheckBox(XXO("Trunc&ate tracks independently"),
103 mbIndependent);
104 }
105 S.EndMultiColumn();
106 }
107 S.EndStatic();
108
109 UpdateUI();
110 return nullptr;
111}
112
114{
115 if (!mUIParent->TransferDataToWindow())
116 {
117 return false;
118 }
119
120 return true;
121}
122
124{
125 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
126 {
127 return false;
128 }
129
130 mbIndependent = mIndependent->IsChecked();
131
132 return true;
133}
134
136{
137 switch (mActionIndex)
138 {
139 case kTruncate:
140 mTruncLongestAllowedSilenceT->Enable(true);
141 mSilenceCompressPercentT->Enable(false);
142 break;
143 case kCompress:
144 mTruncLongestAllowedSilenceT->Enable(false);
145 mSilenceCompressPercentT->Enable(true);
146 }
147}
148
149void EffectTruncSilence::OnControlChange(wxCommandEvent & WXUNUSED(evt))
150{
151 mActionChoice->GetValidator()->TransferFromWindow();
152
153 UpdateUI();
154
156 mUIParent, mUIParent->TransferDataFromWindow()))
157 {
158 return;
159 }
160}
wxT("CloseDown"))
Toolkit-neutral facade for basic user interface services.
END_EVENT_TABLE()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
Performs effect computation.
Hold values to send to effect output meters.
wxChoice * mActionChoice
Definition: TruncSilence.h:49
bool TransferDataToWindow(const EffectSettings &settings) override
wxWeakRef< wxWindow > mUIParent
Definition: TruncSilence.h:46
void OnControlChange(wxCommandEvent &evt)
wxCheckBox * mIndependent
Definition: TruncSilence.h:53
bool TransferDataFromWindow(EffectSettings &settings) override
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:51
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:52
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
BuiltinEffectsModule::Registration< EffectTruncSilence > reg
STL namespace.
Externalized state of a plug-in.