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
16
17
18#if USE_SBSMS
19#include "TimeScale.h"
20#include "LoadEffects.h"
21
22#include <math.h>
23
24#include <wx/slider.h>
25
26#include "MemoryX.h"
27#include "../ShuttleGui.h"
28#include "../widgets/valnum.h"
29
30enum
31{
38};
39
41{
45 > parameters;
46 return parameters;
47}
48
49//
50// EffectTimeScale
51//
52
54{ wxT("Sliding Stretch"), XO("Sliding Stretch") };
55
57
58BEGIN_EVENT_TABLE(EffectTimeScale, wxEvtHandler)
68
70{
71 Parameters().Reset(*this);
72
73 slideTypeRate = SlideLinearOutputRate;
74 slideTypePitch = SlideLinearOutputRate;
75 bPreview = false;
76 previewSelectedDuration = 0.0;
77
78 SetLinearEffectFlag(true);
79}
80
82{
83}
84
85// ComponentInterface implementation
86
88{
89 return Symbol;
90}
91
93{
94 return XO("Allows continuous changes to the tempo and/or pitch");
95}
96
98{
99 return L"Sliding_Stretch";
100}
101
102// EffectDefinitionInterface implementation
103
105{
106 return EffectTypeProcess;
107}
108
109// Effect implementation
110
112 const EffectSettings &settings, double previewLength) const
113{
114 double inputLength = settings.extra.GetDuration();
115 if(inputLength == 0.0) {
116 return 0.0;
117 } else {
120 double tOut = previewLength/inputLength;
121 double t = EffectSBSMS::getInvertedStretchedTime(rateStart1,rateEnd1,slideTypeRate,tOut);
122 return t * inputLength;
123 }
124}
125
127{
129 auto cleanup = valueRestorer( bPreview, true );
130 Effect::Preview(access, dryOnly);
131}
132
135{
140
141 if(bPreview) {
142 double t = (mT1-mT0) / previewSelectedDuration;
143 rateEnd1 = EffectSBSMS::getRate(rateStart1,rateEnd1,slideTypeRate,t);
144 pitchEnd1 = EffectSBSMS::getRate(pitchStart1,pitchEnd1,slideTypePitch,t);
145 }
146
147 EffectSBSMS::setParameters(rateStart1,rateEnd1,pitchStart1,pitchEnd1,slideTypeRate,slideTypePitch,false,false,false);
148 return EffectSBSMS::Process(instance, settings);
149}
150
151std::unique_ptr<EffectUIValidator> EffectTimeScale::PopulateOrExchange(
153 const EffectOutputs *)
154{
155 mUIParent = S.GetParent();
156 S.SetBorder(5);
157 S.AddSpace(0, 5);
158
159 S.StartMultiColumn(2, wxALIGN_CENTER);
160 {
161 // Rate Start
162 S.StartStatic(XO("Initial Tempo Change (%)"));
163 {
164 S.StartMultiColumn(1, wxCENTER);
165 {
167 .Validator<FloatingPointValidator<double>>(
169 NumValidatorStyle::NO_TRAILING_ZEROES,
171 .AddTextBox( {}, L"", 12);
172 }
173 S.EndMultiColumn();
174 S.StartHorizontalLay(wxEXPAND, 0);
175 {
177 .Style(wxSL_HORIZONTAL)
179 }
180 S.EndHorizontalLay();
181 }
182 S.EndStatic();
183
184 S.StartStatic(XO("Final Tempo Change (%)"));
185 {
186 S.StartMultiColumn(1, wxCENTER);
187 {
189 .Validator<FloatingPointValidator<double>>(
191 NumValidatorStyle::NO_TRAILING_ZEROES,
193 .AddTextBox( {}, L"", 12);
194 }
195 S.EndMultiColumn();
196 S.StartHorizontalLay(wxEXPAND, 0);
197 {
199 .Style(wxSL_HORIZONTAL)
201 }
202 S.EndHorizontalLay();
203 }
204 S.EndStatic();
205
206 // Pitch Start
207 S.StartStatic(XO("Initial Pitch Shift"));
208 {
209 S.StartMultiColumn(2, wxCENTER);
210 {
212 .Validator<FloatingPointValidator<double>>(
214 NumValidatorStyle::NO_TRAILING_ZEROES,
216 .AddTextBox(XXO("(&semitones) [-12 to 12]:"), L"", 12);
217
218
220 .Validator<FloatingPointValidator<double>>(
222 NumValidatorStyle::NO_TRAILING_ZEROES,
224 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
225 }
226 S.EndMultiColumn();
227 }
228 S.EndStatic();
229
230 // Pitch End
231 S.StartStatic(XO("Final Pitch Shift"));
232 {
233 S.StartMultiColumn(2, wxCENTER);
234 {
236 .Validator<FloatingPointValidator<double>>(
238 NumValidatorStyle::NO_TRAILING_ZEROES,
240 .AddTextBox(XXO("(s&emitones) [-12 to 12]:"), L"", 12);
241
243 .Validator<FloatingPointValidator<double>>(
245 NumValidatorStyle::NO_TRAILING_ZEROES,
247 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
248 }
249 S.EndMultiColumn();
250 }
251 S.EndStatic();
252 }
253 S.EndMultiColumn();
254
255 return nullptr;
256}
257
259{
260 if (!mUIParent->TransferDataToWindow())
261 {
262 return false;
263 }
264
267
268 return true;
269}
270
272{
273 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
274 {
275 return false;
276 }
277
278 return true;
279}
280
281inline double EffectTimeScale::PercentChangeToRatio(double percentChange)
282{
283 return 1.0 + percentChange / 100.0;
284}
285
286inline double EffectTimeScale::HalfStepsToPercentChange(double halfSteps)
287{
288 return 100.0 * (pow(2.0,halfSteps/12.0) - 1.0);
289}
290
291inline
293{
294 return 12.0 * log2(PercentChangeToRatio(percentChange));
295}
296
298{
299 m_pTextCtrl_RatePercentChangeStart->GetValidator()->TransferToWindow();
300}
301
303{
304 m_pTextCtrl_RatePercentChangeEnd->GetValidator()->TransferToWindow();
305}
306
308{
310}
311
313{
315}
316
318{
319 m_pTextCtrl_PitchHalfStepsStart->GetValidator()->TransferToWindow();
320}
321
323{
324 m_pTextCtrl_PitchHalfStepsEnd->GetValidator()->TransferToWindow();
325}
326
328{
329 m_pTextCtrl_PitchPercentChangeStart->GetValidator()->TransferToWindow();
330}
331
333{
334 m_pTextCtrl_PitchPercentChangeEnd->GetValidator()->TransferToWindow();
335}
336
337void EffectTimeScale::OnText_RatePercentChangeStart(wxCommandEvent & WXUNUSED(evt))
338{
340 mUIParent, mUIParent->TransferDataFromWindow()))
341 {
342 return;
343 }
344
346}
347
348void EffectTimeScale::OnText_RatePercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
349{
351 mUIParent, mUIParent->TransferDataFromWindow()))
352 {
353 return;
354 }
355
357}
358
360{
361 m_RatePercentChangeStart = (double) evt.GetInt();
362
364}
365
367{
368 m_RatePercentChangeEnd = (double) evt.GetInt();
369
371}
372
373void EffectTimeScale::OnText_PitchHalfStepsStart(wxCommandEvent & WXUNUSED(evt))
374{
376 mUIParent, mUIParent->TransferDataFromWindow()))
377 {
378 return;
379 }
380
383}
384
385void EffectTimeScale::OnText_PitchHalfStepsEnd(wxCommandEvent & WXUNUSED(evt))
386{
388 mUIParent, mUIParent->TransferDataFromWindow()))
389 {
390 return;
391 }
392
395}
396
397void EffectTimeScale::OnText_PitchPercentChangeStart(wxCommandEvent & WXUNUSED(evt))
398{
400 mUIParent, mUIParent->TransferDataFromWindow()))
401 {
402 return;
403 }
404
407}
408
409void EffectTimeScale::OnText_PitchPercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
410{
412 mUIParent, mUIParent->TransferDataFromWindow()))
413 {
414 return;
415 }
416
419}
420
421#endif
wxT("CloseDown"))
END_EVENT_TABLE()
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:234
@ ID_RatePercentChangeEnd
Definition: TimeScale.cpp:33
@ ID_PitchHalfStepsEnd
Definition: TimeScale.cpp:35
@ ID_RatePercentChangeStart
Definition: TimeScale.cpp:32
@ ID_PitchPercentChangeEnd
Definition: TimeScale.cpp:37
@ ID_PitchHalfStepsStart
Definition: TimeScale.cpp:34
@ ID_PitchPercentChangeStart
Definition: TimeScale.cpp:36
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:108
void Preview(EffectSettingsAccess &access, bool dryOnly) override
Definition: EffectBase.cpp:333
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)
virtual const EffectSettings & Get()=0
double GetDuration() const
An EffectTimeScale does high quality sliding time scaling/pitch shifting.
Definition: TimeScale.h:26
static double PercentChangeToHalfSteps(double percentChange)
Definition: TimeScale.cpp:292
TranslatableString GetDescription() const override
Definition: TimeScale.cpp:92
SlideType slideTypePitch
Definition: TimeScale.h:88
double m_PitchPercentChangeStart
Definition: TimeScale.h:93
wxTextCtrl * m_pTextCtrl_PitchHalfStepsEnd
Definition: TimeScale.h:101
void Update_Slider_RatePercentChangeEnd()
Definition: TimeScale.cpp:312
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
Default implementation returns previewLength
Definition: TimeScale.cpp:111
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: TimeScale.cpp:133
void OnSlider_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:359
wxSlider * m_pSlider_RatePercentChangeStart
Definition: TimeScale.h:98
static constexpr EffectParameter RatePercentEnd
Definition: TimeScale.h:110
static constexpr EffectParameter RatePercentStart
Definition: TimeScale.h:108
void Update_Text_PitchHalfStepsEnd()
Definition: TimeScale.cpp:322
void Update_Text_PitchHalfStepsStart()
Definition: TimeScale.cpp:317
static double HalfStepsToPercentChange(double halfSteps)
Definition: TimeScale.cpp:286
wxTextCtrl * m_pTextCtrl_RatePercentChangeStart
Definition: TimeScale.h:96
void OnText_PitchPercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:409
wxTextCtrl * m_pTextCtrl_RatePercentChangeEnd
Definition: TimeScale.h:97
void Preview(EffectSettingsAccess &access, bool dryOnly) override
Definition: TimeScale.cpp:126
void OnText_PitchHalfStepsStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:373
static constexpr EffectParameter HalfStepsEnd
Definition: TimeScale.h:114
void OnText_PitchPercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:397
void Update_Slider_RatePercentChangeStart()
Definition: TimeScale.cpp:307
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
Definition: TimeScale.cpp:151
double previewSelectedDuration
Definition: TimeScale.h:86
static constexpr EffectParameter PitchPercentEnd
Definition: TimeScale.h:118
void OnSlider_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:366
EffectType GetType() const override
Type determines how it behaves.
Definition: TimeScale.cpp:104
double m_PitchHalfStepsEnd
Definition: TimeScale.h:92
static const ComponentInterfaceSymbol Symbol
Definition: TimeScale.h:30
double m_PitchHalfStepsStart
Definition: TimeScale.h:91
void OnText_PitchHalfStepsEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:385
static double PercentChangeToRatio(double percentChange)
Definition: TimeScale.cpp:281
void Update_Text_PitchPercentChangeStart()
Definition: TimeScale.cpp:327
wxSlider * m_pSlider_RatePercentChangeEnd
Definition: TimeScale.h:99
void Update_Text_RatePercentChangeEnd()
Definition: TimeScale.cpp:302
SlideType slideTypeRate
Definition: TimeScale.h:87
wxWeakRef< wxWindow > mUIParent
Definition: TimeScale.h:83
wxTextCtrl * m_pTextCtrl_PitchHalfStepsStart
Definition: TimeScale.h:100
double m_PitchPercentChangeEnd
Definition: TimeScale.h:94
void Update_Text_RatePercentChangeStart()
Definition: TimeScale.cpp:297
void OnText_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:337
double m_RatePercentChangeEnd
Definition: TimeScale.h:90
bool TransferDataFromWindow(EffectSettings &settings) override
Update the given settings from controls.
Definition: TimeScale.cpp:271
void Update_Text_PitchPercentChangeEnd()
Definition: TimeScale.cpp:332
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
Definition: TimeScale.cpp:258
const EffectParameterMethods & Parameters() const override
Definition: TimeScale.cpp:40
double m_RatePercentChangeStart
Definition: TimeScale.h:89
static constexpr EffectParameter PitchPercentStart
Definition: TimeScale.h:116
wxTextCtrl * m_pTextCtrl_PitchPercentChangeStart
Definition: TimeScale.h:102
virtual ~EffectTimeScale()
Definition: TimeScale.cpp:81
static constexpr EffectParameter HalfStepsStart
Definition: TimeScale.h:112
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: TimeScale.cpp:97
void OnText_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:348
ComponentInterfaceSymbol GetSymbol() const override
Definition: TimeScale.cpp:87
wxTextCtrl * m_pTextCtrl_PitchPercentChangeEnd
Definition: TimeScale.h:103
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
Holds a msgid for the translation catalog; may also bind format arguments.
BuiltinEffectsModule::Registration< EffectTimeScale > reg
Definition: TimeScale.cpp:56
const Type def
Default value.
Definition: Shuttle.h:29
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
Externalized state of a plug-in.
EffectSettingsExtra extra