Audacity 3.2.0
TimeScale.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TimeScale.cpp
6
7 Clayton Otey
8
9*******************************************************************//*******************************************************************/
15#if USE_SBSMS
16#include "TimeScale.h"
17#include "EffectEditor.h"
18#include "LoadEffects.h"
19
20#include <math.h>
21
22#include <wx/slider.h>
23
24#include "MemoryX.h"
25#include "ShuttleGui.h"
26#include "../widgets/valnum.h"
27
28enum
29{
36};
37
39{
43 > parameters;
44 return parameters;
45}
46
47//
48// EffectTimeScale
49//
50
52{ wxT("Sliding Stretch"), XO("Sliding Stretch") };
53
55
56BEGIN_EVENT_TABLE(EffectTimeScale, wxEvtHandler)
66
68{
69 Parameters().Reset(*this);
70
71 slideTypeRate = SlideLinearOutputRate;
72 slideTypePitch = SlideLinearOutputRate;
73 bPreview = false;
74 previewSelectedDuration = 0.0;
75
76 SetLinearEffectFlag(true);
77}
78
80{
81}
82
83// ComponentInterface implementation
84
86{
87 return Symbol;
88}
89
91{
92 return XO("Allows continuous changes to the tempo and/or pitch");
93}
94
96{
97 return L"Sliding_Stretch";
98}
99
100// EffectDefinitionInterface implementation
101
103{
104 return EffectTypeProcess;
105}
106
107// Effect implementation
108
110 const EffectSettings &settings, double previewLength) const
111{
112 double inputLength = settings.extra.GetDuration();
113 if(inputLength == 0.0) {
114 return 0.0;
115 } else {
118 double tOut = previewLength/inputLength;
119 double t = EffectSBSMS::getInvertedStretchedTime(rateStart1,rateEnd1,slideTypeRate,tOut);
120 return t * inputLength;
121 }
122}
123
125{
126 previewSelectedDuration = settings.extra.GetDuration();
127 return { CopyableValueRestorer{ bPreview, true } };
128}
129
132{
137
138 if(bPreview) {
139 double t = (mT1-mT0) / previewSelectedDuration;
140 rateEnd1 = EffectSBSMS::getRate(rateStart1,rateEnd1,slideTypeRate,t);
141 pitchEnd1 = EffectSBSMS::getRate(pitchStart1,pitchEnd1,slideTypePitch,t);
142 }
143
144 EffectSBSMS::setParameters(rateStart1,rateEnd1,pitchStart1,pitchEnd1,slideTypeRate,slideTypePitch,false,false,false);
145 return EffectSBSMS::Process(instance, settings);
146}
147
148std::unique_ptr<EffectEditor> EffectTimeScale::PopulateOrExchange(
150 const EffectOutputs *)
151{
152 mUIParent = S.GetParent();
153 S.SetBorder(5);
154 S.AddSpace(0, 5);
155
156 S.StartMultiColumn(2, wxALIGN_CENTER);
157 {
158 // Rate Start
159 S.StartStatic(XO("Initial Tempo Change (%)"));
160 {
161 S.StartMultiColumn(1, wxCENTER);
162 {
164 .Validator<FloatingPointValidator<double>>(
166 NumValidatorStyle::NO_TRAILING_ZEROES,
168 .AddTextBox( {}, L"", 12);
169 }
170 S.EndMultiColumn();
171 S.StartHorizontalLay(wxEXPAND, 0);
172 {
174 .Style(wxSL_HORIZONTAL)
176 }
177 S.EndHorizontalLay();
178 }
179 S.EndStatic();
180
181 S.StartStatic(XO("Final Tempo Change (%)"));
182 {
183 S.StartMultiColumn(1, wxCENTER);
184 {
186 .Validator<FloatingPointValidator<double>>(
188 NumValidatorStyle::NO_TRAILING_ZEROES,
190 .AddTextBox( {}, L"", 12);
191 }
192 S.EndMultiColumn();
193 S.StartHorizontalLay(wxEXPAND, 0);
194 {
196 .Style(wxSL_HORIZONTAL)
198 }
199 S.EndHorizontalLay();
200 }
201 S.EndStatic();
202
203 // Pitch Start
204 S.StartStatic(XO("Initial Pitch Shift"));
205 {
206 S.StartMultiColumn(2, wxCENTER);
207 {
209 .Validator<FloatingPointValidator<double>>(
211 NumValidatorStyle::NO_TRAILING_ZEROES,
213 .AddTextBox(XXO("(&semitones) [-12 to 12]:"), L"", 12);
214
215
217 .Validator<FloatingPointValidator<double>>(
219 NumValidatorStyle::NO_TRAILING_ZEROES,
221 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
222 }
223 S.EndMultiColumn();
224 }
225 S.EndStatic();
226
227 // Pitch End
228 S.StartStatic(XO("Final Pitch Shift"));
229 {
230 S.StartMultiColumn(2, wxCENTER);
231 {
233 .Validator<FloatingPointValidator<double>>(
235 NumValidatorStyle::NO_TRAILING_ZEROES,
237 .AddTextBox(XXO("(s&emitones) [-12 to 12]:"), L"", 12);
238
240 .Validator<FloatingPointValidator<double>>(
242 NumValidatorStyle::NO_TRAILING_ZEROES,
244 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
245 }
246 S.EndMultiColumn();
247 }
248 S.EndStatic();
249 }
250 S.EndMultiColumn();
251
252 return nullptr;
253}
254
256{
257 if (!mUIParent->TransferDataToWindow())
258 {
259 return false;
260 }
261
264
265 return true;
266}
267
269{
270 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
271 {
272 return false;
273 }
274
275 return true;
276}
277
278inline double EffectTimeScale::PercentChangeToRatio(double percentChange)
279{
280 return 1.0 + percentChange / 100.0;
281}
282
283inline double EffectTimeScale::HalfStepsToPercentChange(double halfSteps)
284{
285 return 100.0 * (pow(2.0,halfSteps/12.0) - 1.0);
286}
287
288inline
290{
291 return 12.0 * log2(PercentChangeToRatio(percentChange));
292}
293
295{
296 m_pTextCtrl_RatePercentChangeStart->GetValidator()->TransferToWindow();
297}
298
300{
301 m_pTextCtrl_RatePercentChangeEnd->GetValidator()->TransferToWindow();
302}
303
305{
307}
308
310{
312}
313
315{
316 m_pTextCtrl_PitchHalfStepsStart->GetValidator()->TransferToWindow();
317}
318
320{
321 m_pTextCtrl_PitchHalfStepsEnd->GetValidator()->TransferToWindow();
322}
323
325{
326 m_pTextCtrl_PitchPercentChangeStart->GetValidator()->TransferToWindow();
327}
328
330{
331 m_pTextCtrl_PitchPercentChangeEnd->GetValidator()->TransferToWindow();
332}
333
334void EffectTimeScale::OnText_RatePercentChangeStart(wxCommandEvent & WXUNUSED(evt))
335{
337 mUIParent, mUIParent->TransferDataFromWindow()))
338 {
339 return;
340 }
341
343}
344
345void EffectTimeScale::OnText_RatePercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
346{
348 mUIParent, mUIParent->TransferDataFromWindow()))
349 {
350 return;
351 }
352
354}
355
357{
358 m_RatePercentChangeStart = (double) evt.GetInt();
359
361}
362
364{
365 m_RatePercentChangeEnd = (double) evt.GetInt();
366
368}
369
370void EffectTimeScale::OnText_PitchHalfStepsStart(wxCommandEvent & WXUNUSED(evt))
371{
373 mUIParent, mUIParent->TransferDataFromWindow()))
374 {
375 return;
376 }
377
380}
381
382void EffectTimeScale::OnText_PitchHalfStepsEnd(wxCommandEvent & WXUNUSED(evt))
383{
385 mUIParent, mUIParent->TransferDataFromWindow()))
386 {
387 return;
388 }
389
392}
393
394void EffectTimeScale::OnText_PitchPercentChangeStart(wxCommandEvent & WXUNUSED(evt))
395{
397 mUIParent, mUIParent->TransferDataFromWindow()))
398 {
399 return;
400 }
401
404}
405
406void EffectTimeScale::OnText_PitchPercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
407{
409 mUIParent, mUIParent->TransferDataFromWindow()))
410 {
411 return;
412 }
413
416}
417
418#endif
wxT("CloseDown"))
END_EVENT_TABLE()
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
@ ID_RatePercentChangeEnd
Definition: TimeScale.cpp:31
@ ID_PitchHalfStepsEnd
Definition: TimeScale.cpp:33
@ ID_RatePercentChangeStart
Definition: TimeScale.cpp:30
@ ID_PitchPercentChangeEnd
Definition: TimeScale.cpp:35
@ ID_PitchHalfStepsStart
Definition: TimeScale.cpp:32
@ ID_PitchPercentChangeStart
Definition: TimeScale.cpp:34
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:69
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:115
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.
Interface for manipulations of an Effect's settings.
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
static double getInvertedStretchedTime(double rateStart, double rateEnd, SlideType slideType, double outputTime)
bool Process(EffectInstance &instance, EffectSettings &settings) override
static double getRate(double rateStart, double rateEnd, SlideType slideType, double t)
An EffectTimeScale does high quality sliding time scaling/pitch shifting.
Definition: TimeScale.h:27
static double PercentChangeToHalfSteps(double percentChange)
Definition: TimeScale.cpp:289
TranslatableString GetDescription() const override
Definition: TimeScale.cpp:90
SlideType slideTypePitch
Definition: TimeScale.h:89
double m_PitchPercentChangeStart
Definition: TimeScale.h:94
wxTextCtrl * m_pTextCtrl_PitchHalfStepsEnd
Definition: TimeScale.h:102
void Update_Slider_RatePercentChangeEnd()
Definition: TimeScale.cpp:309
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
Definition: TimeScale.cpp:109
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: TimeScale.cpp:130
void OnSlider_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:356
wxSlider * m_pSlider_RatePercentChangeStart
Definition: TimeScale.h:99
std::any BeginPreview(const EffectSettings &settings) override
Called when Preview() starts, to allow temporary effect state changes.
Definition: TimeScale.cpp:124
static constexpr EffectParameter RatePercentEnd
Definition: TimeScale.h:111
static constexpr EffectParameter RatePercentStart
Definition: TimeScale.h:109
void Update_Text_PitchHalfStepsEnd()
Definition: TimeScale.cpp:319
void Update_Text_PitchHalfStepsStart()
Definition: TimeScale.cpp:314
static double HalfStepsToPercentChange(double halfSteps)
Definition: TimeScale.cpp:283
wxTextCtrl * m_pTextCtrl_RatePercentChangeStart
Definition: TimeScale.h:97
void OnText_PitchPercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:406
wxTextCtrl * m_pTextCtrl_RatePercentChangeEnd
Definition: TimeScale.h:98
void OnText_PitchHalfStepsStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:370
static constexpr EffectParameter HalfStepsEnd
Definition: TimeScale.h:115
void OnText_PitchPercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:394
void Update_Slider_RatePercentChangeStart()
Definition: TimeScale.cpp:304
double previewSelectedDuration
Definition: TimeScale.h:87
static constexpr EffectParameter PitchPercentEnd
Definition: TimeScale.h:119
void OnSlider_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:363
EffectType GetType() const override
Type determines how it behaves.
Definition: TimeScale.cpp:102
double m_PitchHalfStepsEnd
Definition: TimeScale.h:93
static const ComponentInterfaceSymbol Symbol
Definition: TimeScale.h:31
double m_PitchHalfStepsStart
Definition: TimeScale.h:92
void OnText_PitchHalfStepsEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:382
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
Definition: TimeScale.cpp:148
static double PercentChangeToRatio(double percentChange)
Definition: TimeScale.cpp:278
void Update_Text_PitchPercentChangeStart()
Definition: TimeScale.cpp:324
wxSlider * m_pSlider_RatePercentChangeEnd
Definition: TimeScale.h:100
void Update_Text_RatePercentChangeEnd()
Definition: TimeScale.cpp:299
SlideType slideTypeRate
Definition: TimeScale.h:88
wxWeakRef< wxWindow > mUIParent
Definition: TimeScale.h:84
wxTextCtrl * m_pTextCtrl_PitchHalfStepsStart
Definition: TimeScale.h:101
double m_PitchPercentChangeEnd
Definition: TimeScale.h:95
void Update_Text_RatePercentChangeStart()
Definition: TimeScale.cpp:294
void OnText_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:334
double m_RatePercentChangeEnd
Definition: TimeScale.h:91
bool TransferDataFromWindow(EffectSettings &settings) override
Definition: TimeScale.cpp:268
void Update_Text_PitchPercentChangeEnd()
Definition: TimeScale.cpp:329
bool TransferDataToWindow(const EffectSettings &settings) override
Definition: TimeScale.cpp:255
const EffectParameterMethods & Parameters() const override
Definition: TimeScale.cpp:38
double m_RatePercentChangeStart
Definition: TimeScale.h:90
static constexpr EffectParameter PitchPercentStart
Definition: TimeScale.h:117
wxTextCtrl * m_pTextCtrl_PitchPercentChangeStart
Definition: TimeScale.h:103
virtual ~EffectTimeScale()
Definition: TimeScale.cpp:79
static constexpr EffectParameter HalfStepsStart
Definition: TimeScale.h:113
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: TimeScale.cpp:95
void OnText_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:345
ComponentInterfaceSymbol GetSymbol() const override
Definition: TimeScale.cpp:85
wxTextCtrl * m_pTextCtrl_PitchPercentChangeEnd
Definition: TimeScale.h:104
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
Holds a msgid for the translation catalog; may also bind format arguments.
BuiltinEffectsModule::Registration< EffectTimeScale > reg
Definition: TimeScale.cpp:54
const Type def
Default value.
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.