Audacity 3.2.0
TimeScaleBase.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TimeScaleBase.cpp
6
7 Clayton Otey
8
9*******************************************************************//*******************************************************************/
15
16#if USE_SBSMS
17
18#include "TimeScaleBase.h"
19#include "MemoryX.h"
20#include <cmath>
21
23{
24 static CapturedParameters<
27 parameters;
28 return parameters;
29}
30
31//
32// TimeScaleBase
33//
34
35const ComponentInterfaceSymbol TimeScaleBase::Symbol { wxT("Sliding Stretch"),
36 XO("Sliding Stretch") };
37
39{
40 Parameters().Reset(*this);
41
42 slideTypeRate = SlideLinearOutputRate;
43 slideTypePitch = SlideLinearOutputRate;
44 bPreview = false;
46
48}
49
51{
52}
53
54// ComponentInterface implementation
55
57{
58 return Symbol;
59}
60
62{
63 return XO("Allows continuous changes to the tempo and/or pitch");
64}
65
67{
68 return L"Sliding_Stretch";
69}
70
71// EffectDefinitionInterface implementation
72
74{
75 return EffectTypeProcess;
76}
77
78// Effect implementation
79
81 const EffectSettings& settings, double previewLength) const
82{
83 double inputLength = settings.extra.GetDuration();
84 if (inputLength == 0.0)
85 {
86 return 0.0;
87 }
88 else
89 {
92 double tOut = previewLength / inputLength;
94 rateStart1, rateEnd1, slideTypeRate, tOut);
95 return t * inputLength;
96 }
97}
98
100{
101 previewSelectedDuration = settings.extra.GetDuration();
102 return { CopyableValueRestorer { bPreview, true } };
103}
104
106{
111
112 if (bPreview)
113 {
114 double t = (mT1 - mT0) / previewSelectedDuration;
115 rateEnd1 = SBSMSBase::getRate(rateStart1, rateEnd1, slideTypeRate, t);
116 pitchEnd1 = SBSMSBase::getRate(pitchStart1, pitchEnd1, slideTypePitch, t);
117 }
118
120 rateStart1, rateEnd1, pitchStart1, pitchEnd1, slideTypeRate,
121 slideTypePitch, false, false, false);
122 return SBSMSBase::Process(instance, settings);
123}
124
125double TimeScaleBase::PercentChangeToRatio(double percentChange)
126{
127 return 1.0 + percentChange / 100.0;
128}
129
131{
132 return 100.0 * (pow(2.0, halfSteps / 12.0) - 1.0);
133}
134
135double TimeScaleBase::PercentChangeToHalfSteps(double percentChange)
136{
137 return 12.0 * log2(PercentChangeToRatio(percentChange));
138}
139
140#endif // USE_SBSMS
wxT("CloseDown"))
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
static Settings & settings()
Definition: TrackInfo.cpp:51
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:123
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
double mT0
Definition: EffectBase.h:122
Performs effect computation.
Interface for manipulations of an Effect's settings.
virtual void Reset(Effect &effect) const =0
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
Definition: SBSMSBase.cpp:149
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: SBSMSBase.cpp:226
static double getInvertedStretchedTime(double rateStart, double rateEnd, SlideType slideType, double outputTime)
Definition: SBSMSBase.cpp:214
static double getRate(double rateStart, double rateEnd, SlideType slideType, double t)
Definition: SBSMSBase.cpp:220
static constexpr EffectParameter PitchPercentEnd
double m_RatePercentChangeStart
Definition: TimeScaleBase.h:58
static double HalfStepsToPercentChange(double halfSteps)
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
static double PercentChangeToRatio(double percentChange)
double m_PitchPercentChangeStart
Definition: TimeScaleBase.h:62
double m_RatePercentChangeEnd
Definition: TimeScaleBase.h:59
static constexpr EffectParameter HalfStepsEnd
Definition: TimeScaleBase.h:91
SlideType slideTypePitch
Definition: TimeScaleBase.h:57
double m_PitchPercentChangeEnd
Definition: TimeScaleBase.h:63
ComponentInterfaceSymbol GetSymbol() const override
bool Process(EffectInstance &instance, EffectSettings &settings) override
virtual ~TimeScaleBase()
static const ComponentInterfaceSymbol Symbol
Definition: TimeScaleBase.h:25
double previewSelectedDuration
Definition: TimeScaleBase.h:55
EffectType GetType() const override
Type determines how it behaves.
static constexpr EffectParameter RatePercentStart
Definition: TimeScaleBase.h:67
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
static constexpr EffectParameter RatePercentEnd
Definition: TimeScaleBase.h:75
const EffectParameterMethods & Parameters() const override
static constexpr EffectParameter PitchPercentStart
Definition: TimeScaleBase.h:99
static constexpr EffectParameter HalfStepsStart
Definition: TimeScaleBase.h:83
SlideType slideTypeRate
Definition: TimeScaleBase.h:56
static double PercentChangeToHalfSteps(double percentChange)
std::any BeginPreview(const EffectSettings &settings) override
Called when Preview() starts, to allow temporary effect state changes.
TranslatableString GetDescription() const override
Holds a msgid for the translation catalog; may also bind format arguments.
Externalized state of a plug-in.