Audacity 3.2.0
Reverb.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4 Audacity(R) is copyright (c) 1999-2013 Audacity Team.
5 License: GPL v2 or later. See License.txt.
6
7 Reverb.cpp
8 Rob Sykes, Vaughan Johnson
9
10******************************************************************//*******************************************************************/
16#include "Reverb.h"
17#include "EffectEditor.h"
18#include "LoadEffects.h"
19
20#include <wx/arrstr.h>
21#include <wx/checkbox.h>
22#include <wx/slider.h>
23#include <wx/spinctrl.h>
24
25#include "Prefs.h"
26#include "ShuttleGui.h"
27#include "../widgets/valnum.h"
28
30
31
34{
35 Editor(const EffectUIServices& services,
37 ) : EffectEditor{ services, access }
39 {}
40 virtual ~Editor() = default;
41
42 bool ValidateUI() override;
43 bool UpdateUI() override;
44
46
48
49 bool mProcessingEvent = false;
50
51#define SpinSlider(n) \
52 wxSpinCtrl *m ## n ## T; \
53 wxSlider *m ## n ## S;
54
64
65#undef SpinSlider
66
67 wxCheckBox* mWetOnlyC;
68
69
70#define SpinSliderHandlers(n) \
71 void On ## n ## Slider(wxCommandEvent & evt); \
72 void On ## n ## Text(wxCommandEvent & evt);
73
83
84#undef SpinSliderHandlers
85
86 void OnCheckbox(wxCommandEvent &evt);
87
88};
89
90
92{
93 auto& rs = mSettings;
94
95 rs.mRoomSize = mRoomSizeS->GetValue();
96 rs.mPreDelay = mPreDelayS->GetValue();
97 rs.mReverberance = mReverberanceS->GetValue();
98 rs.mHfDamping = mHfDampingS->GetValue();
99 rs.mToneLow = mToneLowS->GetValue();
100 rs.mToneHigh = mToneHighS->GetValue();
101 rs.mWetGain = mWetGainS->GetValue();
102 rs.mDryGain = mDryGainS->GetValue();
103 rs.mStereoWidth = mStereoWidthS->GetValue();
104 rs.mWetOnly = mWetOnlyC->GetValue();
105
107 (
108 [this](EffectSettings& settings)
109 {
110 // pass back the modified settings to the MessageBuffer
111
113 return nullptr;
114 }
115 );
116
117 return true;
118}
119
120std::shared_ptr<EffectInstance>
122{
123 return std::make_shared<Instance>(*this);
124}
125
126// Effect implementation
127std::unique_ptr<EffectEditor> EffectReverb::MakeEditor(
129 const EffectOutputs *) const
130{
131 auto& settings = access.Get();
132 auto& myEffSettings = GetSettings(settings);
133
134 auto result = std::make_unique<Editor>(*this, access, myEffSettings);
135 result->PopulateOrExchange(S);
136 return result;
137}
138
139
141{
142 S.AddSpace(0, 5);
143
144 S.StartMultiColumn(3, wxEXPAND);
145 {
146 S.SetStretchyCol(2);
147
148#define SpinSlider(n, p) \
149 m ## n ## T = S.AddSpinCtrl( p, n.def, n.max, n.min); \
150 BindTo(*m ## n ## T, wxEVT_SPINCTRL, &Editor::On ## n ## Text);\
151 \
152 m ## n ## S = S.Style(wxSL_HORIZONTAL).AddSlider( {}, n.def, n.max, n.min); \
153 BindTo(*m ## n ## S, wxEVT_SLIDER, &Editor::On ## n ## Slider);
154
155 SpinSlider(RoomSize, XXO("&Room Size (%):"))
156 SpinSlider(PreDelay, XXO("&Pre-delay (ms):"))
157 SpinSlider(Reverberance, XXO("Rever&berance (%):"))
158 SpinSlider(HfDamping, XXO("Da&mping (%):"))
159 SpinSlider(ToneLow, XXO("Tone &Low (%):"))
160 SpinSlider(ToneHigh, XXO("Tone &High (%):"))
161 SpinSlider(WetGain, XXO("Wet &Gain (dB):"))
162 SpinSlider(DryGain, XXO("Dr&y Gain (dB):"))
163 SpinSlider(StereoWidth, XXO("Stereo Wid&th (%):"))
164
165#undef SpinSlider
166
167 }
168 S.EndMultiColumn();
169
170 S.StartHorizontalLay(wxCENTER, false);
171 {
172 mWetOnlyC =
173 S.AddCheckBox(XXO("Wet O&nly"), WetOnly.def);
174 BindTo(*mWetOnlyC, wxEVT_CHECKBOX, &Editor::OnCheckbox);
175 }
176 S.EndHorizontalLay();
177
178}
179
181{
182 // get the settings from the MessageBuffer and write them to our local copy
183 mSettings = GetSettings(mAccess.Get());
184
185 auto& rs = mSettings;
186
187#define SetSpinSlider(n) \
188 m ## n ## S->SetValue((int) rs.m ## n); \
189 m ## n ## T->SetValue(wxString::Format(wxT("%d"), (int) rs.m ## n));
190
200
201#undef SetSpinSlider
202
203 mWetOnlyC->SetValue((int) rs.mWetOnly);
204
205 return true;
206}
207
208
209#define SpinSliderHandlers(n) \
210 void EffectReverb::Editor::On ## n ## Slider(wxCommandEvent & evt) \
211 { \
212 if (mProcessingEvent) return; \
213 mProcessingEvent = true; \
214 m ## n ## T->SetValue(wxString::Format(wxT("%d"), evt.GetInt())); \
215 mProcessingEvent = false; \
216 ValidateUI(); \
217 Publish(EffectSettingChanged{}); \
218 } \
219 void EffectReverb::Editor::On ## n ## Text(wxCommandEvent & evt) \
220 { \
221 if (mProcessingEvent) return; \
222 mProcessingEvent = true; \
223 m ## n ## S->SetValue(std::clamp<long>(evt.GetInt(), n.min, n.max)); \
224 mProcessingEvent = false; \
225 ValidateUI(); \
226 Publish(EffectSettingChanged{}); \
227 }
228
238
239void EffectReverb::Editor::OnCheckbox(wxCommandEvent &evt)
240{
241 ValidateUI();
242 Publish(EffectSettingChanged{});
243}
244
245#undef SpinSliderHandlers
XXO("&Cut/Copy/Paste Toolbar")
#define SetSpinSlider(n)
#define SpinSliderHandlers(n)
Definition: Reverb.cpp:209
#define SpinSlider(n)
Definition: Reverb.cpp:51
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:51
bool ValidateUI(const EffectPlugin &context, EffectSettings &) const override
EffectSettingsAccess & mAccess
Definition: EffectEditor.h:92
Performs effect computation.
Hold values to send to effect output meters.
std::unique_ptr< EffectEditor > MakeEditor(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
Called only from PopulateUI, to add controls to effect panel.
Definition: Reverb.cpp:127
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Definition: Reverb.cpp:121
void ModifySettings(Function &&function)
Do a correct read-modify-write of settings.
virtual const EffectSettings & Get()=0
static ReverbSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166
static constexpr EffectParameter WetOnly
Definition: ReverbBase.h:212
static constexpr EffectParameter StereoWidth
Definition: ReverbBase.h:203
static constexpr EffectParameter RoomSize
Definition: ReverbBase.h:143
static constexpr EffectParameter HfDamping
Definition: ReverbBase.h:166
static constexpr EffectParameter PreDelay
Definition: ReverbBase.h:150
static constexpr EffectParameter Reverberance
Definition: ReverbBase.h:157
static constexpr EffectParameter WetGain
Definition: ReverbBase.h:189
static constexpr EffectParameter DryGain
Definition: ReverbBase.h:196
static constexpr EffectParameter ToneHigh
Definition: ReverbBase.h:182
static constexpr EffectParameter ToneLow
Definition: ReverbBase.h:175
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
BuiltinEffectsModule::Registration< EffectReverb > reg
Definition: Reverb.cpp:29
const Type def
Default value.
SpinSlider(RoomSize) SpinSlider(PreDelay) SpinSlider(Reverberance) SpinSlider(HfDamping) SpinSlider(ToneLow) SpinSlider(ToneHigh) SpinSlider(WetGain) SpinSlider(DryGain) SpinSlider(StereoWidth) wxCheckBox *mWetOnlyC
ReverbSettings mSettings
Definition: Reverb.cpp:47
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: Reverb.cpp:180
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: Reverb.cpp:91
Editor(const EffectUIServices &services, EffectSettingsAccess &access, const ReverbSettings &settings)
Definition: Reverb.cpp:35
SpinSliderHandlers(RoomSize) SpinSliderHandlers(PreDelay) SpinSliderHandlers(Reverberance) SpinSliderHandlers(HfDamping) SpinSliderHandlers(ToneLow) SpinSliderHandlers(ToneHigh) SpinSliderHandlers(WetGain) SpinSliderHandlers(DryGain) SpinSliderHandlers(StereoWidth) void OnCheckbox(wxCommandEvent &evt)
void PopulateOrExchange(ShuttleGui &S)
Definition: Reverb.cpp:140
virtual ~Editor()=default
Message sent by EffectEditor when a setting is changed by the user.
Definition: EffectEditor.h:26
Externalized state of a plug-in.
double mRoomSize
Definition: ReverbBase.h:20