Audacity  2.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 <wx/choice.h>
17 #include <wx/event.h>
18 #include <wx/slider.h>
19 #include <wx/string.h>
20 #include <wx/textctrl.h>
21 
22 #include "../widgets/NumericTextCtrl.h"
23 
24 #include "Effect.h"
25 
26 class ShuttleGui;
27 
28 #define CHANGESPEED_PLUGIN_SYMBOL XO("Change Speed")
29 
30 class EffectChangeSpeed final : public Effect
31 {
32 public:
34  virtual ~EffectChangeSpeed();
35 
36  // IdentInterface implementation
37 
38  wxString GetSymbol() override;
39  wxString GetDescription() override;
40  wxString ManualPage() override;
41 
42  // EffectIdentInterface implementation
43 
44  EffectType GetType() override;
45 
46  // EffectClientInterface implementation
47 
48  bool GetAutomationParameters(EffectAutomationParameters & parms) override;
49  bool SetAutomationParameters(EffectAutomationParameters & parms) override;
50  bool LoadFactoryDefaults() override;
51 
52  // Effect implementation
53 
54  bool CheckWhetherSkipEffect() override;
55  double CalcPreviewInputLength(double previewLength) override;
56  bool Startup() override;
57  bool Init() override;
58  bool Process() override;
59  void PopulateOrExchange(ShuttleGui & S) override;
60  bool TransferDataFromWindow() override;
61  bool TransferDataToWindow() override;
62 
63 private:
64  // EffectChangeSpeed implementation
65 
66  bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end);
68 
69  // handlers
70  void OnText_PercentChange(wxCommandEvent & evt);
71  void OnText_Multiplier(wxCommandEvent & evt);
72  void OnSlider_PercentChange(wxCommandEvent & evt);
73  void OnChoice_Vinyl(wxCommandEvent & evt);
74  void OnTimeCtrl_ToLength(wxCommandEvent & evt);
75  void OnTimeCtrlUpdate(wxCommandEvent & evt);
76 
77  // helper functions
78  void Update_Text_PercentChange(); // Update control per current m_PercentChange.
79  void Update_Text_Multiplier(); // Update control per current m_PercentChange.
80  void Update_Slider_PercentChange(); // Update control per current m_PercentChange.
81  void Update_Vinyl(); // Update Vinyl controls for NEW percent change.
82  void Update_TimeCtrl_ToLength(); // Update target length controls for NEW percent change.
83  void UpdateUI(); // Enable / disable OK / preview.
84 
85 private:
86  // track related
88  double mMaxNewLength;
89  double mCurT0;
90  double mCurT1;
91 
92  // control values
93  double m_PercentChange; // percent change to apply to tempo
94  // -100% is meaningless, but sky's the upper limit.
95  // Slider is (-100, 200], but textCtrls can set higher.
96  int mFromVinyl; // from standard vinyl speed (RPM) enum
97  double mFactor; // scale factor calculated from percent change
98  double mFromLength; // current selection length
99  int mTimeCtrlFormat; // time control format index number
100  double mMultiplier;
101 
103 
104  // controls
106  wxTextCtrl * mpTextCtrl_Multiplier;
108  wxChoice * mpChoice_FromVinyl;
109  wxChoice * mpChoice_ToVinyl;
112  double mRate;
113 
114  // private effect parameters
115  int mToVinyl; // to standard vinyl speed (rpm)
116  double mToLength; // target length of selection
117  wxString mFormat; // time control format
118 
119  DECLARE_EVENT_TABLE()
120 };
121 
122 #endif // __AUDACITY_EFFECT_CHANGESPEED__
wxString ManualPage() override
Definition: ChangeSpeed.cpp:118
void Update_Slider_PercentChange()
Definition: ChangeSpeed.cpp:698
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
double mToLength
Definition: ChangeSpeed.h:116
EffectChangeSpeed()
Definition: ChangeSpeed.cpp:87
bool TransferDataToWindow() override
Definition: ChangeSpeed.cpp:406
void OnTimeCtrlUpdate(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:673
double mCurT0
Definition: ChangeSpeed.h:89
wxTextCtrl * mpTextCtrl_Multiplier
Definition: ChangeSpeed.h:106
void UpdateUI()
Definition: ChangeSpeed.cpp:780
wxSlider * mpSlider_PercentChange
Definition: ChangeSpeed.h:107
int mTimeCtrlFormat
Definition: ChangeSpeed.h:99
void Update_TimeCtrl_ToLength()
Definition: ChangeSpeed.cpp:766
Base class for many of the effects in Audacity.
Definition: Effect.h:62
double m_PercentChange
Definition: ChangeSpeed.h:93
bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end)
Definition: ChangeSpeed.cpp:473
An Effect that affects both pitch & speed.
Definition: ChangeSpeed.h:30
wxChoice * mpChoice_FromVinyl
Definition: ChangeSpeed.h:108
wxString GetSymbol() override
Definition: ChangeSpeed.cpp:108
wxTextCtrl * mpTextCtrl_PercentChange
Definition: ChangeSpeed.h:105
bool TransferDataFromWindow() override
Definition: ChangeSpeed.cpp:442
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:114
double mCurT1
Definition: ChangeSpeed.h:90
void PopulateOrExchange(ShuttleGui &S) override
Definition: ChangeSpeed.cpp:291
void Update_Text_PercentChange()
Definition: ChangeSpeed.cpp:685
wxString mFormat
Definition: ChangeSpeed.h:117
double mRate
Definition: ChangeSpeed.h:112
NumericTextCtrl * mpFromLengthCtrl
Definition: ChangeSpeed.h:110
int mCurTrackNum
Definition: ChangeSpeed.h:87
bool Init() override
Definition: ChangeSpeed.cpp:209
virtual ~EffectChangeSpeed()
Definition: ChangeSpeed.cpp:102
void Update_Vinyl()
Definition: ChangeSpeed.cpp:713
double mFromLength
Definition: ChangeSpeed.h:98
void OnChoice_Vinyl(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:612
double mFactor
Definition: ChangeSpeed.h:97
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
void OnTimeCtrl_ToLength(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:652
Definition: NumericTextCtrl.h:141
wxChoice * mpChoice_ToVinyl
Definition: ChangeSpeed.h:109
void OnText_Multiplier(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:576
double CalcPreviewInputLength(double previewLength) override
Definition: ChangeSpeed.cpp:164
EffectType GetType() override
Definition: ChangeSpeed.cpp:126
double mMaxNewLength
Definition: ChangeSpeed.h:88
bool CheckWhetherSkipEffect() override
Definition: ChangeSpeed.cpp:159
bool GetAutomationParameters(EffectAutomationParameters &parms) override
Definition: ChangeSpeed.cpp:133
bool Startup() override
Definition: ChangeSpeed.cpp:169
void OnSlider_PercentChange(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:593
bool ProcessLabelTrack(LabelTrack *t)
Definition: ChangeSpeed.cpp:462
int mToVinyl
Definition: ChangeSpeed.h:115
int mFromVinyl
Definition: ChangeSpeed.h:96
void OnText_PercentChange(wxCommandEvent &evt)
Definition: ChangeSpeed.cpp:560
bool LoadFactoryDefaults() override
Definition: ChangeSpeed.cpp:149
wxString GetDescription() override
Definition: ChangeSpeed.cpp:113
bool mbLoopDetect
Definition: ChangeSpeed.h:102
void Update_Text_Multiplier()
Definition: ChangeSpeed.cpp:691
double mMultiplier
Definition: ChangeSpeed.h:100
bool Process() override
Definition: ChangeSpeed.cpp:217
NumericTextCtrl * mpToLengthCtrl
Definition: ChangeSpeed.h:111
bool SetAutomationParameters(EffectAutomationParameters &parms) override
Definition: ChangeSpeed.cpp:140