Audacity  2.2.0
ChangePitch.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4  Audacity(R) is copyright (c) 1999-2012 Audacity Team.
5  License: GPL v2. See License.txt.
6 
7  ChangePitch.h
8  Vaughan Johnson, Dominic Mazzoni, Steve Daulton
9 
10 ******************************************************************//*******************************************************************/
17 
18 #if USE_SOUNDTOUCH
19 
20 #ifndef __AUDACITY_EFFECT_CHANGEPITCH__
21 #define __AUDACITY_EFFECT_CHANGEPITCH__
22 
23 #if USE_SBSMS
24 #include "SBSMSEffect.h"
25 #include <wx/checkbox.h>
26 #endif
27 
28 #include <wx/choice.h>
29 #include <wx/event.h>
30 #include <wx/slider.h>
31 #include <wx/spinctrl.h>
32 #include <wx/string.h>
33 #include <wx/textctrl.h>
34 
35 #include "SoundTouchEffect.h"
36 
37 class ShuttleGui;
38 
39 #define CHANGEPITCH_PLUGIN_SYMBOL XO("Change Pitch")
40 
41 class EffectChangePitch final : public EffectSoundTouch
42 {
43 public:
44  EffectChangePitch();
45  virtual ~EffectChangePitch();
46 
47  // IdentInterface implementation
48 
49  wxString GetSymbol() override;
50  wxString GetDescription() override;
51  wxString ManualPage() override;
52 
53  // EffectIdentInterface implementation
54 
55  EffectType GetType() override;
56 
57  // EffectClientInterface implementation
58 
59  bool GetAutomationParameters(EffectAutomationParameters & parms) override;
60  bool SetAutomationParameters(EffectAutomationParameters & parms) override;
61  bool LoadFactoryDefaults() override;
62 
63  // Effect implementation
64 
65  bool Init() override;
66  bool Process() override;
67  bool CheckWhetherSkipEffect() override;
68  void PopulateOrExchange(ShuttleGui & S) override;
69  bool TransferDataToWindow() override;
70  bool TransferDataFromWindow() override;
71 
72 private:
73  // EffectChangePitch implementation
74 
75  // Deduce m_FromFrequency from the samples at the beginning of
76  // the selection. Then set some other params accordingly.
77  void DeduceFrequencies();
78 
79  // calculations
80  void Calc_ToPitch(); // Update m_nToPitch from NEW m_dSemitonesChange.
81  void Calc_ToOctave();
82  void Calc_SemitonesChange_fromPitches();
83  void Calc_SemitonesChange_fromOctaveChange();
84  void Calc_SemitonesChange_fromPercentChange();
85  void Calc_ToFrequency(); // Update m_ToFrequency from m_FromFrequency & m_dPercentChange.
86  void Calc_PercentChange(); // Update m_dPercentChange based on NEW m_dSemitonesChange.
87 
88  // handlers
89  void OnChoice_FromPitch(wxCommandEvent & evt);
90  void OnSpin_FromOctave(wxCommandEvent & evt);
91  void OnChoice_ToPitch(wxCommandEvent & evt);
92  void OnSpin_ToOctave(wxCommandEvent & evt);
93 
94  void OnText_SemitonesChange(wxCommandEvent & evt);
95 
96  void OnText_FromFrequency(wxCommandEvent & evt);
97  void OnText_ToFrequency(wxCommandEvent & evt);
98 
99  void OnText_PercentChange(wxCommandEvent & evt);
100  void OnSlider_PercentChange(wxCommandEvent & evt);
101 
102  // helper fns for controls
103  void Update_Choice_FromPitch();
104  void Update_Spin_FromOctave();
105  void Update_Choice_ToPitch();
106  void Update_Spin_ToOctave();
107 
108  void Update_Text_SemitonesChange();
109 
110  void Update_Text_FromFrequency();
111  void Update_Text_ToFrequency();
112 
113  void Update_Text_PercentChange(); // Update control per current m_dPercentChange.
114  void Update_Slider_PercentChange(); // Update control per current m_dPercentChange.
115 
116 private:
117  bool mUseSBSMS;
118  // effect parameters
119  int m_nFromPitch; // per PitchIndex()
120  int m_nFromOctave; // per PitchOctave()
121  int m_nToPitch; // per PitchIndex()
122  int m_nToOctave; // per PitchOctave()
123 
124  double m_FromFrequency; // starting frequency of selection
125  double m_ToFrequency; // target frequency of selection
126 
127  double m_dSemitonesChange; // how many semitones to change pitch
128  double m_dStartFrequency; // starting frequency of first 0.2s of selection
129  double m_dPercentChange; // percent change to apply to pitch
130  // Slider is (-100, 200], but textCtrls can set higher.
131 
132  bool m_bLoopDetect; // Used to avoid loops in initialization and in event handling.
133 
134  // controls
135  wxChoice * m_pChoice_FromPitch;
136  wxSpinCtrl * m_pSpin_FromOctave;
137  wxChoice * m_pChoice_ToPitch;
138  wxSpinCtrl * m_pSpin_ToOctave;
139  wxTextCtrl * m_pTextCtrl_SemitonesChange;
140 
141  wxTextCtrl * m_pTextCtrl_FromFrequency;
142  wxTextCtrl * m_pTextCtrl_ToFrequency;
143  wxTextCtrl * m_pTextCtrl_PercentChange;
144  wxSlider * m_pSlider_PercentChange;
145 
146 #if USE_SBSMS
147  wxCheckBox * mUseSBSMSCheckBox;
148 #endif
149 
150  DECLARE_EVENT_TABLE()
151 };
152 
153 #endif // __AUDACITY_EFFECT_CHANGEPITCH__
154 
155 #endif // USE_SOUNDTOUCH
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366