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 ******************************************************************//** 11 12 \file ChangePitch.h 13 \brief Change Pitch effect provides raising or lowering 14 the pitch without changing the tempo. 15 16 *//*******************************************************************/ 17 18 19 #if USE_SOUNDTOUCH 20 21 #ifndef __AUDACITY_EFFECT_CHANGEPITCH__ 22 #define __AUDACITY_EFFECT_CHANGEPITCH__ 23 24 #if USE_SBSMS 25 #include "SBSMSEffect.h" 26 #endif 27 28 #include "SoundTouchEffect.h" 29 30 class wxSlider; 31 class wxChoice; 32 class wxCheckBox; 33 class wxTextCtrl; 34 class wxSpinCtrl; 35 class ShuttleGui; 36 37 class EffectChangePitch final : public EffectSoundTouch 38 { 39 public: 40 static const ComponentInterfaceSymbol Symbol; 41 42 EffectChangePitch(); 43 virtual ~EffectChangePitch(); 44 45 // ComponentInterface implementation 46 47 ComponentInterfaceSymbol GetSymbol() override; 48 TranslatableString GetDescription() override; 49 ManualPageID ManualPage() override; 50 51 // EffectDefinitionInterface implementation 52 53 EffectType GetType() override; 54 55 // EffectClientInterface implementation 56 57 bool DefineParams( ShuttleParams & S ) override; 58 bool GetAutomationParameters(CommandParameters & parms) override; 59 bool SetAutomationParameters(CommandParameters & parms) override; 60 bool LoadFactoryDefaults() override; 61 62 // Effect implementation 63 64 bool Init() override; 65 bool Process() override; 66 bool CheckWhetherSkipEffect() override; 67 void PopulateOrExchange(ShuttleGui & S) override; 68 bool TransferDataToWindow() override; 69 bool TransferDataFromWindow() override; 70 71 private: 72 // EffectChangePitch implementation 73 74 // Deduce m_FromFrequency from the samples at the beginning of 75 // the selection. Then set some other params accordingly. 76 void DeduceFrequencies(); 77 78 // calculations 79 void Calc_ToPitch(); // Update m_nToPitch from NEW m_dSemitonesChange. 80 void Calc_ToOctave(); 81 void Calc_SemitonesChange_fromPitches(); 82 void Calc_SemitonesChange_fromOctaveChange(); 83 void Calc_SemitonesChange_fromPercentChange(); 84 void Calc_ToFrequency(); // Update m_ToFrequency from m_FromFrequency & m_dPercentChange. 85 void Calc_PercentChange(); // Update m_dPercentChange based on NEW m_dSemitonesChange. 86 87 // handlers 88 void OnChoice_FromPitch(wxCommandEvent & evt); 89 void OnSpin_FromOctave(wxCommandEvent & evt); 90 void OnChoice_ToPitch(wxCommandEvent & evt); 91 void OnSpin_ToOctave(wxCommandEvent & evt); 92 93 void OnText_SemitonesChange(wxCommandEvent & evt); 94 95 void OnText_FromFrequency(wxCommandEvent & evt); 96 void OnText_ToFrequency(wxCommandEvent & evt); 97 98 void OnText_PercentChange(wxCommandEvent & evt); 99 void OnSlider_PercentChange(wxCommandEvent & evt); 100 101 // helper fns for controls 102 void Update_Choice_FromPitch(); 103 void Update_Spin_FromOctave(); 104 void Update_Choice_ToPitch(); 105 void Update_Spin_ToOctave(); 106 107 void Update_Text_SemitonesChange(); 108 109 void Update_Text_FromFrequency(); 110 void Update_Text_ToFrequency(); 111 112 void Update_Text_PercentChange(); // Update control per current m_dPercentChange. 113 void Update_Slider_PercentChange(); // Update control per current m_dPercentChange. 114 115 private: 116 bool mUseSBSMS; 117 // effect parameters 118 int m_nFromPitch; // per PitchIndex() 119 int m_nFromOctave; // per PitchOctave() 120 int m_nToPitch; // per PitchIndex() 121 int m_nToOctave; // per PitchOctave() 122 123 double m_FromFrequency; // starting frequency of selection 124 double m_ToFrequency; // target frequency of selection 125 126 double m_dSemitonesChange; // how many semitones to change pitch 127 double m_dStartFrequency; // starting frequency of first 0.2s of selection 128 double m_dPercentChange; // percent change to apply to pitch 129 // Slider is (-100, 200], but textCtrls can set higher. 130 131 bool m_bLoopDetect; // Used to avoid loops in initialization and in event handling. 132 133 // controls 134 wxChoice * m_pChoice_FromPitch; 135 wxSpinCtrl * m_pSpin_FromOctave; 136 wxChoice * m_pChoice_ToPitch; 137 wxSpinCtrl * m_pSpin_ToOctave; 138 wxTextCtrl * m_pTextCtrl_SemitonesChange; 139 140 wxTextCtrl * m_pTextCtrl_FromFrequency; 141 wxTextCtrl * m_pTextCtrl_ToFrequency; 142 wxTextCtrl * m_pTextCtrl_PercentChange; 143 wxSlider * m_pSlider_PercentChange; 144 145 #if USE_SBSMS 146 wxCheckBox * mUseSBSMSCheckBox; 147 #endif 148 149 DECLARE_EVENT_TABLE() 150 }; 151 152 #endif // __AUDACITY_EFFECT_CHANGEPITCH__ 153 154 #endif // USE_SOUNDTOUCH 155