Audacity 3.2.0
ToneGen.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ToneGen.cpp
6
7 Steve Jolly
8 James Crook (Adapted for 'Chirps')
9
10 This class implements a tone generator effect.
11
12*******************************************************************//*******************************************************************/
20#include "ToneGen.h"
21#include "EffectEditor.h"
22#include "LoadEffects.h"
23
24#include <math.h>
25
26#include <wx/choice.h>
27#include <wx/valgen.h>
28
29#include "Project.h"
30#include "ProjectRate.h"
31#include "ShuttleGui.h"
32#include "../widgets/valnum.h"
33#include "../widgets/NumericTextCtrl.h"
34
35
37{ XO("Chirp") };
38
40
42{ XO("Tone") };
43
45
46BEGIN_EVENT_TABLE(EffectToneGen, wxEvtHandler)
47 EVT_TEXT(wxID_ANY, EffectToneGen::OnControlUpdate)
49
50// ComponentInterface implementation
51
53{
55}
56
58{
59 return mChirp ?
60 XO("Generates an ascending or descending tone of one of four types") :
61 XO("Generates a constant frequency tone of one of four types");
62}
63
65{
66 return mChirp ? L"Chirp" : L"Tone";
67}
68
69// Effect implementation
70
71std::unique_ptr<EffectEditor> EffectToneGen::PopulateOrExchange(
73 const EffectOutputs *)
74{
75 mUIParent = S.GetParent();
76 wxTextCtrl *t;
77
78 S.StartMultiColumn(2, wxCENTER);
79 {
80 S.Validator<wxGenericValidator>(&mWaveform)
81 .AddChoice(XXO("&Waveform:"),
83
84 if (mChirp)
85 {
86 S.AddFixedText( {} );
87 S.StartHorizontalLay(wxEXPAND);
88 {
89 S.StartHorizontalLay(wxLEFT, 50);
90 {
91 S.AddTitle(XO("Start"));
92 }
93 S.EndHorizontalLay();
94
95 S.StartHorizontalLay(wxLEFT, 50);
96 {
97 S.AddTitle(XO("End"));
98 }
99 S.EndHorizontalLay();
100 }
101 S.EndHorizontalLay();
102
103 S.AddPrompt(XXO("&Frequency (Hz):"));
104 S.StartHorizontalLay(wxEXPAND);
105 {
106 S.StartHorizontalLay(wxLEFT, 50);
107 {
108 t = S.Name(XO("Frequency Hertz Start"))
109 .Validator<FloatingPointValidator<double>>(
110 6, &mFrequency0,
111 NumValidatorStyle::NO_TRAILING_ZEROES,
113 mProjectRate / 2.0 )
114 .AddTextBox( {}, L"", 12);
115 }
116 S.EndHorizontalLay();
117
118 S.StartHorizontalLay(wxLEFT, 50);
119 {
120 t = S.Name(XO("Frequency Hertz End"))
121 .Validator<FloatingPointValidator<double>>(
122 6, &mFrequency1,
123 NumValidatorStyle::NO_TRAILING_ZEROES,
124 EndFreq.min,
125 mProjectRate / 2.0 )
126 .AddTextBox( {}, L"", 12);
127 }
128 S.EndHorizontalLay();
129 }
130 S.EndHorizontalLay();
131
132 S.AddPrompt(XXO("&Amplitude (0-1):"));
133 S.StartHorizontalLay(wxEXPAND);
134 {
135 S.StartHorizontalLay(wxLEFT, 50);
136 {
137 t = S.Name(XO("Amplitude Start"))
138 .Validator<FloatingPointValidator<double>>(
139 6, &mAmplitude0, NumValidatorStyle::NO_TRAILING_ZEROES,
141 .AddTextBox( {}, L"", 12);
142 }
143 S.EndHorizontalLay();
144
145 S.StartHorizontalLay(wxLEFT, 50);
146 {
147 t = S.Name(XO("Amplitude End"))
148 .Validator<FloatingPointValidator<double>>(
149 6, &mAmplitude1, NumValidatorStyle::NO_TRAILING_ZEROES,
151 .AddTextBox( {}, L"", 12);
152 }
153 S.EndHorizontalLay();
154 }
155 S.EndHorizontalLay();
156
157 S.Validator<wxGenericValidator>(&mInterpolation)
158 .AddChoice(XXO("I&nterpolation:"),
160 }
161 else
162 {
163 t = S.Validator<FloatingPointValidator<double>>(
164 6, &mFrequency0, NumValidatorStyle::NO_TRAILING_ZEROES,
166 mProjectRate / 2.0 )
167 .AddTextBox(XXO("&Frequency (Hz):"), L"", 12);
168
169 t = S.Validator<FloatingPointValidator<double>>(
170 6, &mAmplitude0, NumValidatorStyle::NO_TRAILING_ZEROES,
172 .AddTextBox(XXO("&Amplitude (0-1):"), L"", 12);
173 }
174
175 S.AddPrompt(XXO("&Duration:"));
176 auto &extra = access.Get().extra;
179 S.GetParent(), wxID_ANY,
181 extra.GetDurationFormat(),
182 extra.GetDuration(),
184 .AutoPos(true));
185 S.Name(XO("Duration"))
186 .Position(wxALIGN_LEFT | wxALL)
187 .AddWindow(mToneDurationT);
188 }
189 S.EndMultiColumn();
190
191 return nullptr;
192}
193
195{
196 if (!mUIParent->TransferDataToWindow())
197 {
198 return false;
199 }
200
201 mToneDurationT->SetValue(settings.extra.GetDuration());
202 return true;
203}
204
206{
207 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
208 {
209 return false;
210 }
211
212 if (!mChirp)
213 {
216 }
217
218 settings.extra.SetDuration(mToneDurationT->GetValue());
219
220 return true;
221}
222
223// ToneGenBase implementation
224
225void EffectToneGen::OnControlUpdate(wxCommandEvent & WXUNUSED(evt))
226{
228 mUIParent, mUIParent->TransferDataFromWindow()))
229 {
230 return;
231 }
232}
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
const NumericConverterType & NumericConverterType_TIME()
an object holding per-project preferred sample rate
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
END_EVENT_TABLE()
static Settings & settings()
Definition: TrackInfo.cpp:51
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mProjectRate
Definition: EffectBase.h:119
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:63
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.
virtual const EffectSettings & Get()=0
An Effect that can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen suppor...
Definition: ToneGen.h:27
TranslatableString GetDescription() const override
Definition: ToneGen.cpp:57
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
Definition: ToneGen.cpp:71
void OnControlUpdate(wxCommandEvent &evt)
Definition: ToneGen.cpp:225
wxWeakRef< wxWindow > mUIParent
Definition: ToneGen.h:56
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: ToneGen.cpp:64
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:57
bool TransferDataToWindow(const EffectSettings &settings) override
Definition: ToneGen.cpp:194
bool TransferDataFromWindow(EffectSettings &settings) override
Definition: ToneGen.cpp:205
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:73
static FormatterContext SampleRateContext(double sampleRate)
void SetValue(double newValue)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
double mAmplitude1
Definition: ToneGenBase.h:61
static const EnumValueSymbol kInterStrings[nInterpolations]
Definition: ToneGenBase.h:90
static constexpr EffectParameter StartAmp
Definition: ToneGenBase.h:99
const bool mChirp
Definition: ToneGenBase.h:45
static constexpr EffectParameter StartFreq
Definition: ToneGenBase.h:93
double mFrequency0
Definition: ToneGenBase.h:58
double mFrequency1
Definition: ToneGenBase.h:59
static constexpr EffectParameter Frequency
Definition: ToneGenBase.h:105
static constexpr EffectParameter EndAmp
Definition: ToneGenBase.h:102
int mInterpolation
Definition: ToneGenBase.h:57
double mAmplitude0
Definition: ToneGenBase.h:60
static constexpr EffectParameter Amplitude
Definition: ToneGenBase.h:108
static const EnumValueSymbol kWaveStrings[nWaveforms]
Definition: ToneGenBase.h:81
static constexpr EffectParameter EndFreq
Definition: ToneGenBase.h:96
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....
Definition: Validators.h:54
BuiltinEffectsModule::Registration< EffectTone > reg2
Definition: ToneGen.cpp:44
BuiltinEffectsModule::Registration< EffectChirp > reg
Definition: ToneGen.cpp:39
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.
EffectSettingsExtra extra
Options & AutoPos(bool enable)