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/intl.h>
25#include <wx/slider.h>
26
27#include "MemoryX.h"
28#include "../ShuttleGui.h"
29#include "../widgets/valnum.h"
30
31enum
32{
39};
40
42{
46 > parameters;
47 return parameters;
48}
49
50//
51// EffectTimeScale
52//
53
55{ wxT("Sliding Stretch"), XO("Sliding Stretch") };
56
58
59BEGIN_EVENT_TABLE(EffectTimeScale, wxEvtHandler)
69
71{
72 Parameters().Reset(*this);
73
74 slideTypeRate = SlideLinearOutputRate;
75 slideTypePitch = SlideLinearOutputRate;
76 bPreview = false;
77 previewSelectedDuration = 0.0;
78
79 SetLinearEffectFlag(true);
80}
81
83{
84}
85
86// ComponentInterface implementation
87
89{
90 return Symbol;
91}
92
94{
95 return XO("Allows continuous changes to the tempo and/or pitch");
96}
97
99{
100 return L"Sliding_Stretch";
101}
102
103// EffectDefinitionInterface implementation
104
106{
107 return EffectTypeProcess;
108}
109
110// Effect implementation
111
113 const EffectSettings &settings, double previewLength) const
114{
115 double inputLength = settings.extra.GetDuration();
116 if(inputLength == 0.0) {
117 return 0.0;
118 } else {
121 double tOut = previewLength/inputLength;
122 double t = EffectSBSMS::getInvertedStretchedTime(rateStart1,rateEnd1,slideTypeRate,tOut);
123 return t * inputLength;
124 }
125}
126
128{
130 auto cleanup = valueRestorer( bPreview, true );
131 Effect::Preview(access, dryOnly);
132}
133
136{
141
142 if(bPreview) {
143 double t = (mT1-mT0) / previewSelectedDuration;
144 rateEnd1 = EffectSBSMS::getRate(rateStart1,rateEnd1,slideTypeRate,t);
145 pitchEnd1 = EffectSBSMS::getRate(pitchStart1,pitchEnd1,slideTypePitch,t);
146 }
147
148 EffectSBSMS::setParameters(rateStart1,rateEnd1,pitchStart1,pitchEnd1,slideTypeRate,slideTypePitch,false,false,false);
149 return EffectSBSMS::Process(instance, settings);
150}
151
152std::unique_ptr<EffectUIValidator> EffectTimeScale::PopulateOrExchange(
154{
155 S.SetBorder(5);
156 S.AddSpace(0, 5);
157
158 S.StartMultiColumn(2, wxALIGN_CENTER);
159 {
160 // Rate Start
161 S.StartStatic(XO("Initial Tempo Change (%)"));
162 {
163 S.StartMultiColumn(1, wxCENTER);
164 {
166 .Validator<FloatingPointValidator<double>>(
168 NumValidatorStyle::NO_TRAILING_ZEROES,
170 .AddTextBox( {}, L"", 12);
171 }
172 S.EndMultiColumn();
173 S.StartHorizontalLay(wxEXPAND, 0);
174 {
176 .Style(wxSL_HORIZONTAL)
178 }
179 S.EndHorizontalLay();
180 }
181 S.EndStatic();
182
183 S.StartStatic(XO("Final Tempo Change (%)"));
184 {
185 S.StartMultiColumn(1, wxCENTER);
186 {
188 .Validator<FloatingPointValidator<double>>(
190 NumValidatorStyle::NO_TRAILING_ZEROES,
192 .AddTextBox( {}, L"", 12);
193 }
194 S.EndMultiColumn();
195 S.StartHorizontalLay(wxEXPAND, 0);
196 {
198 .Style(wxSL_HORIZONTAL)
200 }
201 S.EndHorizontalLay();
202 }
203 S.EndStatic();
204
205 // Pitch Start
206 S.StartStatic(XO("Initial Pitch Shift"));
207 {
208 S.StartMultiColumn(2, wxCENTER);
209 {
211 .Validator<FloatingPointValidator<double>>(
213 NumValidatorStyle::NO_TRAILING_ZEROES,
215 .AddTextBox(XXO("(&semitones) [-12 to 12]:"), L"", 12);
216
217
219 .Validator<FloatingPointValidator<double>>(
221 NumValidatorStyle::NO_TRAILING_ZEROES,
223 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
224 }
225 S.EndMultiColumn();
226 }
227 S.EndStatic();
228
229 // Pitch End
230 S.StartStatic(XO("Final Pitch Shift"));
231 {
232 S.StartMultiColumn(2, wxCENTER);
233 {
235 .Validator<FloatingPointValidator<double>>(
237 NumValidatorStyle::NO_TRAILING_ZEROES,
239 .AddTextBox(XXO("(s&emitones) [-12 to 12]:"), L"", 12);
240
242 .Validator<FloatingPointValidator<double>>(
244 NumValidatorStyle::NO_TRAILING_ZEROES,
246 .AddTextBox(XXO("(%) [-50 to 100]:"), L"", 12);
247 }
248 S.EndMultiColumn();
249 }
250 S.EndStatic();
251 }
252 S.EndMultiColumn();
253
254 return nullptr;
255}
256
258{
261
262 return true;
263}
264
265inline double EffectTimeScale::PercentChangeToRatio(double percentChange)
266{
267 return 1.0 + percentChange / 100.0;
268}
269
270inline double EffectTimeScale::HalfStepsToPercentChange(double halfSteps)
271{
272 return 100.0 * (pow(2.0,halfSteps/12.0) - 1.0);
273}
274
275inline
277{
278 return 12.0 * log2(PercentChangeToRatio(percentChange));
279}
280
282{
283 m_pTextCtrl_RatePercentChangeStart->GetValidator()->TransferToWindow();
284}
285
287{
288 m_pTextCtrl_RatePercentChangeEnd->GetValidator()->TransferToWindow();
289}
290
292{
294}
295
297{
299}
300
302{
303 m_pTextCtrl_PitchHalfStepsStart->GetValidator()->TransferToWindow();
304}
305
307{
308 m_pTextCtrl_PitchHalfStepsEnd->GetValidator()->TransferToWindow();
309}
310
312{
313 m_pTextCtrl_PitchPercentChangeStart->GetValidator()->TransferToWindow();
314}
315
317{
318 m_pTextCtrl_PitchPercentChangeEnd->GetValidator()->TransferToWindow();
319}
320
321void EffectTimeScale::OnText_RatePercentChangeStart(wxCommandEvent & WXUNUSED(evt))
322{
323 if (!EnableApply(mUIParent->TransferDataFromWindow()))
324 {
325 return;
326 }
327
329}
330
331void EffectTimeScale::OnText_RatePercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
332{
333 if (!EnableApply(mUIParent->TransferDataFromWindow()))
334 {
335 return;
336 }
337
339}
340
342{
343 m_RatePercentChangeStart = (double) evt.GetInt();
344
346}
347
349{
350 m_RatePercentChangeEnd = (double) evt.GetInt();
351
353}
354
355void EffectTimeScale::OnText_PitchHalfStepsStart(wxCommandEvent & WXUNUSED(evt))
356{
357 if (!EnableApply(mUIParent->TransferDataFromWindow()))
358 {
359 return;
360 }
361
364}
365
366void EffectTimeScale::OnText_PitchHalfStepsEnd(wxCommandEvent & WXUNUSED(evt))
367{
368 if (!EnableApply(mUIParent->TransferDataFromWindow()))
369 {
370 return;
371 }
372
375}
376
377void EffectTimeScale::OnText_PitchPercentChangeStart(wxCommandEvent & WXUNUSED(evt))
378{
379 if (!EnableApply(mUIParent->TransferDataFromWindow()))
380 {
381 return;
382 }
383
386}
387
388void EffectTimeScale::OnText_PitchPercentChangeEnd(wxCommandEvent & WXUNUSED(evt))
389{
390 if (!EnableApply(mUIParent->TransferDataFromWindow()))
391 {
392 return;
393 }
394
397}
398
399#endif
END_EVENT_TABLE()
EffectType
@ EffectTypeProcess
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:226
@ ID_RatePercentChangeEnd
Definition: TimeScale.cpp:34
@ ID_PitchHalfStepsEnd
Definition: TimeScale.cpp:36
@ ID_RatePercentChangeStart
Definition: TimeScale.cpp:33
@ ID_PitchPercentChangeEnd
Definition: TimeScale.cpp:38
@ ID_PitchHalfStepsStart
Definition: TimeScale.cpp:35
@ ID_PitchPercentChangeStart
Definition: TimeScale.cpp:37
#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:107
double mT0
Definition: EffectBase.h:106
void Preview(EffectSettingsAccess &access, bool dryOnly) override
Definition: EffectBase.cpp:328
bool EnableApply(bool enable=true)
Definition: Effect.cpp:613
wxWindow * mUIParent
Definition: Effect.h:270
Performs effect computation.
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
Actually do the effect here.
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:276
TranslatableString GetDescription() const override
Definition: TimeScale.cpp:93
SlideType slideTypePitch
Definition: TimeScale.h:85
double m_PitchPercentChangeStart
Definition: TimeScale.h:90
wxTextCtrl * m_pTextCtrl_PitchHalfStepsEnd
Definition: TimeScale.h:98
void Update_Slider_RatePercentChangeEnd()
Definition: TimeScale.cpp:296
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
Default implementation returns previewLength
Definition: TimeScale.cpp:112
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
Definition: TimeScale.cpp:152
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
Definition: TimeScale.cpp:134
void OnSlider_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:341
wxSlider * m_pSlider_RatePercentChangeStart
Definition: TimeScale.h:95
static constexpr EffectParameter RatePercentEnd
Definition: TimeScale.h:107
static constexpr EffectParameter RatePercentStart
Definition: TimeScale.h:105
void Update_Text_PitchHalfStepsEnd()
Definition: TimeScale.cpp:306
void Update_Text_PitchHalfStepsStart()
Definition: TimeScale.cpp:301
static double HalfStepsToPercentChange(double halfSteps)
Definition: TimeScale.cpp:270
wxTextCtrl * m_pTextCtrl_RatePercentChangeStart
Definition: TimeScale.h:93
void OnText_PitchPercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:388
wxTextCtrl * m_pTextCtrl_RatePercentChangeEnd
Definition: TimeScale.h:94
void Preview(EffectSettingsAccess &access, bool dryOnly) override
Definition: TimeScale.cpp:127
void OnText_PitchHalfStepsStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:355
static constexpr EffectParameter HalfStepsEnd
Definition: TimeScale.h:111
void OnText_PitchPercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:377
void Update_Slider_RatePercentChangeStart()
Definition: TimeScale.cpp:291
double previewSelectedDuration
Definition: TimeScale.h:83
static constexpr EffectParameter PitchPercentEnd
Definition: TimeScale.h:115
void OnSlider_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:348
EffectType GetType() const override
Type determines how it behaves.
Definition: TimeScale.cpp:105
double m_PitchHalfStepsEnd
Definition: TimeScale.h:89
static const ComponentInterfaceSymbol Symbol
Definition: TimeScale.h:30
double m_PitchHalfStepsStart
Definition: TimeScale.h:88
void OnText_PitchHalfStepsEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:366
static double PercentChangeToRatio(double percentChange)
Definition: TimeScale.cpp:265
void Update_Text_PitchPercentChangeStart()
Definition: TimeScale.cpp:311
wxSlider * m_pSlider_RatePercentChangeEnd
Definition: TimeScale.h:96
void Update_Text_RatePercentChangeEnd()
Definition: TimeScale.cpp:286
SlideType slideTypeRate
Definition: TimeScale.h:84
wxTextCtrl * m_pTextCtrl_PitchHalfStepsStart
Definition: TimeScale.h:97
double m_PitchPercentChangeEnd
Definition: TimeScale.h:91
void Update_Text_RatePercentChangeStart()
Definition: TimeScale.cpp:281
void OnText_RatePercentChangeStart(wxCommandEvent &evt)
Definition: TimeScale.cpp:321
double m_RatePercentChangeEnd
Definition: TimeScale.h:87
void Update_Text_PitchPercentChangeEnd()
Definition: TimeScale.cpp:316
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
Definition: TimeScale.cpp:257
const EffectParameterMethods & Parameters() const override
Definition: TimeScale.cpp:41
double m_RatePercentChangeStart
Definition: TimeScale.h:86
static constexpr EffectParameter PitchPercentStart
Definition: TimeScale.h:113
wxTextCtrl * m_pTextCtrl_PitchPercentChangeStart
Definition: TimeScale.h:99
virtual ~EffectTimeScale()
Definition: TimeScale.cpp:82
static constexpr EffectParameter HalfStepsStart
Definition: TimeScale.h:109
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: TimeScale.cpp:98
void OnText_RatePercentChangeEnd(wxCommandEvent &evt)
Definition: TimeScale.cpp:331
ComponentInterfaceSymbol GetSymbol() const override
Definition: TimeScale.cpp:88
wxTextCtrl * m_pTextCtrl_PitchPercentChangeEnd
Definition: TimeScale.h:100
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:57
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