Audacity 3.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 or later. See License.txt.
6
7 ChangePitch.h
8 Vaughan Johnson, Dominic Mazzoni, Steve Daulton
9
10******************************************************************//*******************************************************************/
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#include "ShuttleAutomation.h"
30#include <wx/weakref.h>
31
32class wxSlider;
33class wxChoice;
34class wxCheckBox;
35class wxTextCtrl;
36class wxSpinCtrl;
37class ShuttleGui;
38
39class EffectChangePitch final : public EffectSoundTouch
40{
41public:
42 static inline EffectChangePitch *
43 FetchParameters(EffectChangePitch &e, EffectSettings &) { return &e; }
44 static const ComponentInterfaceSymbol Symbol;
45
46 EffectChangePitch();
47 virtual ~EffectChangePitch();
48
49 // ComponentInterface implementation
50
51 ComponentInterfaceSymbol GetSymbol() const override;
52 TranslatableString GetDescription() const override;
53 ManualPageID ManualPage() const override;
54
55 // EffectDefinitionInterface implementation
56
57 EffectType GetType() const override;
58 OptionalMessage LoadFactoryDefaults(EffectSettings &settings)
59 const override;
60 OptionalMessage DoLoadFactoryDefaults(EffectSettings &settings);
61
62 bool Process(EffectInstance &instance, EffectSettings &settings) override;
63 bool CheckWhetherSkipEffect(const EffectSettings &settings) const override;
64 std::unique_ptr<EffectEditor> PopulateOrExchange(
65 ShuttleGui & S, EffectInstance &instance,
66 EffectSettingsAccess &access, const EffectOutputs *pOutputs) override;
67 bool TransferDataToWindow(const EffectSettings &settings) override;
68 bool TransferDataFromWindow(EffectSettings &settings) override;
69
70private:
71 // EffectChangePitch implementation
72
73 // Deduce m_FromFrequency from the samples at the beginning of
74 // the selection. Then set some other params accordingly.
75 void DeduceFrequencies();
76
77 // calculations
78 void Calc_ToPitch(); // Update m_nToPitch from NEW m_dSemitonesChange.
79 void Calc_ToOctave();
80 void Calc_SemitonesChange_fromPitches();
81 void Calc_SemitonesChange_fromOctaveChange();
82 void Calc_SemitonesChange_fromPercentChange();
83 void Calc_ToFrequency(); // Update m_ToFrequency from m_FromFrequency & m_dPercentChange.
84 void Calc_PercentChange(); // Update m_dPercentChange based on NEW m_dSemitonesChange.
85
86 // handlers
87 void OnChoice_FromPitch(wxCommandEvent & evt);
88 void OnSpin_FromOctave(wxCommandEvent & evt);
89 void OnChoice_ToPitch(wxCommandEvent & evt);
90 void OnSpin_ToOctave(wxCommandEvent & evt);
91
92 void OnText_SemitonesChange(wxCommandEvent & evt);
93
94 void OnText_FromFrequency(wxCommandEvent & evt);
95 void OnText_ToFrequency(wxCommandEvent & evt);
96
97 void OnText_PercentChange(wxCommandEvent & evt);
98 void OnSlider_PercentChange(wxCommandEvent & evt);
99
100 // helper fns for controls
101 void Update_Choice_FromPitch();
102 void Update_Spin_FromOctave();
103 void Update_Choice_ToPitch();
104 void Update_Spin_ToOctave();
105
106 void Update_Text_SemitonesChange();
107
108 void Update_Text_FromFrequency();
109 void Update_Text_ToFrequency();
110
111 void Update_Text_PercentChange(); // Update control per current m_dPercentChange.
112 void Update_Slider_PercentChange(); // Update control per current m_dPercentChange.
113
114private:
115 wxWeakRef<wxWindow> mUIParent{};
116
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 const EffectParameterMethods& Parameters() const override;
151 DECLARE_EVENT_TABLE()
152
153static constexpr EffectParameter Percentage{ &EffectChangePitch::m_dPercentChange,
154 L"Percentage", 0.0, -99.0, 3000.0, 1 };
155static constexpr EffectParameter UseSBSMS{ &EffectChangePitch::mUseSBSMS,
156 L"SBSMS", false, false, true, 1 };
157};
158
159#endif // __AUDACITY_EFFECT_CHANGEPITCH__
160
161#endif // USE_SOUNDTOUCH
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,...
Performs effect computation.
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
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.
Externalized state of a plug-in.