Audacity  2.2.2
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 IdentInterfaceSymbol{ XO("Change Pitch") }
40 
41 class EffectChangePitch final : public EffectSoundTouch
42 {
43 public:
44  EffectChangePitch();
45  virtual ~EffectChangePitch();
46 
47  // IdentInterface implementation
48 
49  IdentInterfaceSymbol GetSymbol() override;
50  wxString GetDescription() override;
51  wxString ManualPage() override;
52 
53  // EffectDefinitionInterface implementation
54 
55  EffectType GetType() override;
56 
57  // EffectClientInterface implementation
58 
59  bool DefineParams( ShuttleParams & S ) override;
60  bool GetAutomationParameters(CommandParameters & parms) override;
61  bool SetAutomationParameters(CommandParameters & parms) override;
62  bool LoadFactoryDefaults() override;
63 
64  // Effect implementation
65 
66  bool Init() override;
67  bool Process() override;
68  bool CheckWhetherSkipEffect() override;
69  void PopulateOrExchange(ShuttleGui & S) override;
70  bool TransferDataToWindow() override;
71  bool TransferDataFromWindow() override;
72 
73 private:
74  // EffectChangePitch implementation
75 
76  // Deduce m_FromFrequency from the samples at the beginning of
77  // the selection. Then set some other params accordingly.
78  void DeduceFrequencies();
79 
80  // calculations
81  void Calc_ToPitch(); // Update m_nToPitch from NEW m_dSemitonesChange.
82  void Calc_ToOctave();
83  void Calc_SemitonesChange_fromPitches();
84  void Calc_SemitonesChange_fromOctaveChange();
85  void Calc_SemitonesChange_fromPercentChange();
86  void Calc_ToFrequency(); // Update m_ToFrequency from m_FromFrequency & m_dPercentChange.
87  void Calc_PercentChange(); // Update m_dPercentChange based on NEW m_dSemitonesChange.
88 
89  // handlers
90  void OnChoice_FromPitch(wxCommandEvent & evt);
91  void OnSpin_FromOctave(wxCommandEvent & evt);
92  void OnChoice_ToPitch(wxCommandEvent & evt);
93  void OnSpin_ToOctave(wxCommandEvent & evt);
94 
95  void OnText_SemitonesChange(wxCommandEvent & evt);
96 
97  void OnText_FromFrequency(wxCommandEvent & evt);
98  void OnText_ToFrequency(wxCommandEvent & evt);
99 
100  void OnText_PercentChange(wxCommandEvent & evt);
101  void OnSlider_PercentChange(wxCommandEvent & evt);
102 
103  // helper fns for controls
104  void Update_Choice_FromPitch();
105  void Update_Spin_FromOctave();
106  void Update_Choice_ToPitch();
107  void Update_Spin_ToOctave();
108 
109  void Update_Text_SemitonesChange();
110 
111  void Update_Text_FromFrequency();
112  void Update_Text_ToFrequency();
113 
114  void Update_Text_PercentChange(); // Update control per current m_dPercentChange.
115  void Update_Slider_PercentChange(); // Update control per current m_dPercentChange.
116 
117 private:
118  bool mUseSBSMS;
119  // effect parameters
120  int m_nFromPitch; // per PitchIndex()
121  int m_nFromOctave; // per PitchOctave()
122  int m_nToPitch; // per PitchIndex()
123  int m_nToOctave; // per PitchOctave()
124 
125  double m_FromFrequency; // starting frequency of selection
126  double m_ToFrequency; // target frequency of selection
127 
128  double m_dSemitonesChange; // how many semitones to change pitch
129  double m_dStartFrequency; // starting frequency of first 0.2s of selection
130  double m_dPercentChange; // percent change to apply to pitch
131  // Slider is (-100, 200], but textCtrls can set higher.
132 
133  bool m_bLoopDetect; // Used to avoid loops in initialization and in event handling.
134 
135  // controls
136  wxChoice * m_pChoice_FromPitch;
137  wxSpinCtrl * m_pSpin_FromOctave;
138  wxChoice * m_pChoice_ToPitch;
139  wxSpinCtrl * m_pSpin_ToOctave;
140  wxTextCtrl * m_pTextCtrl_SemitonesChange;
141 
142  wxTextCtrl * m_pTextCtrl_FromFrequency;
143  wxTextCtrl * m_pTextCtrl_ToFrequency;
144  wxTextCtrl * m_pTextCtrl_PercentChange;
145  wxSlider * m_pSlider_PercentChange;
146 
147 #if USE_SBSMS
148  wxCheckBox * mUseSBSMSCheckBox;
149 #endif
150 
151  DECLARE_EVENT_TABLE()
152 };
153 
154 #endif // __AUDACITY_EFFECT_CHANGEPITCH__
155 
156 #endif // USE_SOUNDTOUCH
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
EffectType