Audacity 3.2.0
ChangeTempoBase.cpp
Go to the documentation of this file.
1#include "ChangeTempoBase.h"
2#include "ShuttleAutomation.h"
3#include "TimeWarper.h"
4#ifdef USE_SBSMS
5#include "SBSMSBase.h"
6#endif
7#include <cmath>
8
9// Soundtouch defines these as well, which are also in generated configmac.h
10// and configunix.h, so get rid of them before including,
11// to avoid compiler warnings, and be sure to do this
12// after all other #includes, to avoid any mischief that might result
13// from doing the un-definitions before seeing any wx headers.
14#undef PACKAGE_NAME
15#undef PACKAGE_STRING
16#undef PACKAGE_TARNAME
17#undef PACKAGE_VERSION
18#undef PACKAGE_BUGREPORT
19#undef PACKAGE
20#undef VERSION
21#include "SoundTouch.h"
22
23// Soundtouch is not reasonable below -99% or above 3000%.
24
26{
28 return parameters;
29}
30
32
34{
35 // mUseSBSMS always defaults to false and its value is used only if USE_SBSMS
36 // is defined
37 Parameters().Reset(*this);
38 m_FromBPM = 0.0; // indicates not yet set
39 m_ToBPM = 0.0; // indicates not yet set
40 m_FromLength = 0.0;
41 m_ToLength = 0.0;
42
43 m_bLoopDetect = false;
44
45 SetLinearEffectFlag(true);
46}
47
49{
50}
51
52// ComponentInterface implementation
53
55{
56 return Symbol;
57}
58
60{
61 return XO("Changes the tempo of a selection without changing its pitch");
62}
63
65{
66 return L"Change_Tempo";
67}
68
69// EffectDefinitionInterface implementation
70
72{
73 return EffectTypeProcess;
74}
75
77{
78 return true;
79}
80
81// Effect implementation
82
84 const EffectSettings&, double previewLength) const
85{
86 return previewLength * (100.0 + m_PercentChange) / 100.0;
87}
88
90{
91 return (m_PercentChange == 0.0);
92}
93
95{
96 // The selection might have changed since the last time ChangeTempoBase
97 // was invoked, so recalculate the Length parameters.
98 m_FromLength = mT1 - mT0;
99 m_ToLength = (m_FromLength * 100.0) / (100.0 + m_PercentChange);
100
101 return true;
102}
103
105{
106 bool success = false;
107
108#if USE_SBSMS
109 if (mUseSBSMS)
110 {
111 double tempoRatio = 1.0 + m_PercentChange / 100.0;
112 SBSMSBase proxy;
113 proxy.mProxyEffectName = XO("High Quality Tempo Change");
114 proxy.setParameters(tempoRatio, 1.0);
116 success = Delegate(proxy, settings);
117 }
118 else
119#endif
120 {
121 auto initer = [&](soundtouch::SoundTouch* soundtouch) {
122 soundtouch->setTempoChange(m_PercentChange);
123 };
124 double mT1Dashed = mT0 + (mT1 - mT0) / (m_PercentChange / 100.0 + 1.0);
125 RegionTimeWarper warper {
126 mT0, mT1, std::make_unique<LinearTimeWarper>(mT0, mT0, mT1, mT1Dashed)
127 };
128 success = SoundTouchBase::ProcessWithTimeWarper(initer, warper, false);
129 }
130
131 if (success)
132 mT1 = mT0 + (mT1 - mT0) / (m_PercentChange / 100 + 1.);
133
134 return success;
135}
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
static Settings & settings()
Definition: TrackInfo.cpp:51
Generates EffectParameterMethods overrides from variadic template arguments.
bool Init() override
EffectType GetType() const override
bool CheckWhetherSkipEffect(const EffectSettings &settings) const override
const EffectParameterMethods & Parameters() const override
ManualPageID ManualPage() const override
virtual ~ChangeTempoBase()
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
ComponentInterfaceSymbol GetSymbol() const override
bool Process(EffectInstance &instance, EffectSettings &settings) override
static const ComponentInterfaceSymbol Symbol
bool SupportsAutomation() const override
TranslatableString GetDescription() const override
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Performs effect computation.
Interface for manipulations of an Effect's settings.
virtual void Reset(Effect &effect) const =0
No change before the specified region; during the region, warp according to the given warper; after t...
Definition: TimeWarper.h:192
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
Definition: SBSMSBase.cpp:149
TranslatableString mProxyEffectName
Definition: SBSMSBase.h:41
Holds a msgid for the translation catalog; may also bind format arguments.
Externalized state of a plug-in.