Audacity 3.2.0
ChangeSpeed.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ChangeSpeed.h
6
7 Vaughan Johnson, Dominic Mazzoni
8
9 Change Speed effect, that affects both pitch & tempo.
10
11**********************************************************************/
12
13#ifndef __AUDACITY_EFFECT_CHANGESPEED__
14#define __AUDACITY_EFFECT_CHANGESPEED__
15
16#include "StatefulEffect.h"
17#include "ShuttleAutomation.h"
18#include <wx/weakref.h>
19
20class wxSlider;
21class wxChoice;
22class wxTextCtrl;
23class LabelTrack;
24class NumericTextCtrl;
25class ShuttleGui;
26class WaveChannel;
27
29{
30public:
31 static inline EffectChangeSpeed *
34
36 virtual ~EffectChangeSpeed();
37
38 // ComponentInterface implementation
39
40 ComponentInterfaceSymbol GetSymbol() const override;
41 TranslatableString GetDescription() const override;
42 ManualPageID ManualPage() const override;
43
44 // EffectDefinitionInterface implementation
45
46 EffectType GetType() const override;
48 const override;
50
51 bool CheckWhetherSkipEffect(const EffectSettings &settings) const override;
53 const EffectSettings &settings, double previewLength) const override;
54 bool Init() override;
55 bool Process(EffectInstance &instance, EffectSettings &settings) override;
56 std::unique_ptr<EffectEditor> PopulateOrExchange(
57 ShuttleGui & S, EffectInstance &instance,
58 EffectSettingsAccess &access, const EffectOutputs *pOutputs) override;
59 bool TransferDataToWindow(const EffectSettings &settings) override;
61
62private:
63 // EffectChangeSpeed implementation
64
65 using Gap = std::pair<double, double>;
66 using Gaps = std::vector<Gap>;
68 const WaveTrack &track, const double curT0, const double curT1);
69
70 bool ProcessOne(const WaveChannel &track, WaveChannel &outputTrack,
73
74 // handlers
75 void OnText_PercentChange(wxCommandEvent & evt);
76 void OnText_Multiplier(wxCommandEvent & evt);
77 void OnSlider_PercentChange(wxCommandEvent & evt);
78 void OnChoice_Vinyl(wxCommandEvent & evt);
79 void OnTimeCtrl_ToLength(wxCommandEvent & evt);
80 void OnTimeCtrlUpdate(wxCommandEvent & evt);
81
82 // helper functions
83 void Update_Text_PercentChange(); // Update control per current m_PercentChange.
84 void Update_Text_Multiplier(); // Update control per current m_PercentChange.
85 void Update_Slider_PercentChange(); // Update control per current m_PercentChange.
86 void Update_Vinyl(); // Update Vinyl controls for NEW percent change.
87 void Update_TimeCtrl_ToLength(); // Update target length controls for NEW percent change.
88 void UpdateUI(); // Enable / disable OK / preview.
89
90private:
91 wxWeakRef<wxWindow> mUIParent{};
92
93 // track related
95 double mCurT0;
96 double mCurT1;
97
98 // control values
99 double m_PercentChange; // percent change to apply to tempo
100 // -100% is meaningless, but sky's the upper limit.
101 // Slider is (-100, 200], but textCtrls can set higher.
102 int mFromVinyl; // from standard vinyl speed (RPM) enum
103 double mFactor; // scale factor calculated from percent change
104 double mFromLength; // current selection length
105 int mTimeCtrlFormat; // time control format index number
107
109
110 // controls
118 double mRate;
119
120 // private effect parameters
121 int mToVinyl; // to standard vinyl speed (rpm)
122 double mToLength; // target length of selection
123 NumericFormatID mFormat; // time control format
124
125 const EffectParameterMethods& Parameters() const override;
126 DECLARE_EVENT_TABLE()
127
129 L"Percentage", 0.0, -99.0, 4900.0, 1 };
130};
131
132#endif // __AUDACITY_EFFECT_CHANGESPEED__
EffectType
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:69
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An Effect that affects both pitch & speed.
Definition: ChangeSpeed.h:29
void OnText_PercentChange(wxCommandEvent &evt)
NumericFormatID mFormat
Definition: ChangeSpeed.h:123
NumericTextCtrl * mpToLengthCtrl
Definition: ChangeSpeed.h:117
EffectType GetType() const override
Type determines how it behaves.
bool CheckWhetherSkipEffect(const EffectSettings &settings) const override
After Init(), tell whether Process() should be skipped.
virtual ~EffectChangeSpeed()
static const ComponentInterfaceSymbol Symbol
Definition: ChangeSpeed.h:33
OptionalMessage LoadFactoryDefaults(EffectSettings &settings) const override
void OnChoice_Vinyl(wxCommandEvent &evt)
void OnText_Multiplier(wxCommandEvent &evt)
bool TransferDataToWindow(const EffectSettings &settings) override
static EffectChangeSpeed * FetchParameters(EffectChangeSpeed &e, EffectSettings &)
Definition: ChangeSpeed.h:32
void Update_Slider_PercentChange()
OptionalMessage DoLoadFactoryDefaults(EffectSettings &settings)
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
wxTextCtrl * mpTextCtrl_Multiplier
Definition: ChangeSpeed.h:112
void Update_TimeCtrl_ToLength()
std::vector< Gap > Gaps
Definition: ChangeSpeed.h:66
wxChoice * mpChoice_ToVinyl
Definition: ChangeSpeed.h:115
wxTextCtrl * mpTextCtrl_PercentChange
Definition: ChangeSpeed.h:111
const EffectParameterMethods & Parameters() const override
Definition: ChangeSpeed.cpp:71
std::pair< double, double > Gap
Definition: ChangeSpeed.h:65
Gaps FindGaps(const WaveTrack &track, const double curT0, const double curT1)
bool ProcessOne(const WaveChannel &track, WaveChannel &outputTrack, sampleCount start, sampleCount end)
wxWeakRef< wxWindow > mUIParent
Definition: ChangeSpeed.h:91
void Update_Text_PercentChange()
bool Process(EffectInstance &instance, EffectSettings &settings) override
wxChoice * mpChoice_FromVinyl
Definition: ChangeSpeed.h:114
void OnTimeCtrl_ToLength(wxCommandEvent &evt)
void Update_Text_Multiplier()
void OnSlider_PercentChange(wxCommandEvent &evt)
ComponentInterfaceSymbol GetSymbol() const override
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
bool TransferDataFromWindow(EffectSettings &settings) override
void OnTimeCtrlUpdate(wxCommandEvent &evt)
static constexpr EffectParameter Percentage
Definition: ChangeSpeed.h:128
bool ProcessLabelTrack(LabelTrack *t)
wxSlider * mpSlider_PercentChange
Definition: ChangeSpeed.h:113
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
double m_PercentChange
Definition: ChangeSpeed.h:99
TranslatableString GetDescription() const override
bool Init() override
NumericTextCtrl * mpFromLengthCtrl
Definition: ChangeSpeed.h:116
Performs effect computation.
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
Externalized state of a plug-in.