Audacity 3.2.0
EffectUI.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EffectUI.h
6
7 Leland Lucius
8
9 Audacity(R) is copyright (c) 1999-2008 Audacity Team.
10 License: GPL v2 or later. See License.txt.
11
12**********************************************************************/
13
14#ifndef __AUDACITY_EFFECTUI_H__
15#define __AUDACITY_EFFECTUI_H__
16
17#include <wx/bitmap.h> // member variables
18
19#include <optional>
20
21#include "Identifier.h"
22#include "EffectPlugin.h"
23#include "Observer.h"
24#include "PluginInterface.h"
27
28struct AudioIOEvent;
29
30#include "EffectInterface.h"
31#include "widgets/wxPanelWrapper.h" // to inherit
32
33#include "SelectedRegion.h"
34
35class AudacityCommand;
36class AudacityProject;
38
39class wxCheckBox;
40
41//
42class EffectUIHost final
43 : public wxDialogWrapper
45{
46public:
47 // constructors and destructors
48 /*
49 @param[out] pInstance may construct
50 (and then must call Init() with success), or leave null for failure
51 */
52 EffectUIHost(wxWindow *parent, AudacityProject &project,
54 std::shared_ptr<EffectInstance> &pInstance,
56 const std::shared_ptr<RealtimeEffectState> &pPriorState = {});
57 virtual ~EffectUIHost();
58
59 bool TransferDataToWindow() override;
60 bool TransferDataFromWindow() override;
61
62 int ShowModal() override;
63
64 bool Initialize();
65 EffectUIValidator *GetValidator() const { return mpValidator.get(); }
66
67 bool HandleCommandKeystrokes() override;
68
69 void SetClosed() {
70#if wxDEBUG_LEVEL
71 mClosed = true;
72#endif
73 }
74
75private:
76 std::shared_ptr<EffectInstance> InitializeInstance();
77
78 wxPanel *BuildButtonBar(wxWindow *parent, bool graphicalUI);
79 void BuildButtonBar(ShuttleGui &S, bool graphicalUI);
80
81 void OnInitDialog(wxInitDialogEvent & evt);
82 void OnErase(wxEraseEvent & evt);
83 void OnPaint(wxPaintEvent & evt);
84 void OnClose(wxCloseEvent & evt);
85 void OnApply(wxCommandEvent & evt);
86 void DoCancel();
87 void OnCancel(wxCommandEvent & evt);
88 void OnDebug(wxCommandEvent & evt);
89 void OnMenu(wxCommandEvent & evt);
90 void OnEnable(wxCommandEvent & evt);
91 void OnPlay(wxCommandEvent & evt);
94 void OnUserPreset(wxCommandEvent & evt);
95 void OnFactoryPreset(wxCommandEvent & evt);
96 void OnDeletePreset(wxCommandEvent & evt);
97 void OnSaveAs(wxCommandEvent & evt);
98 void OnImport(wxCommandEvent & evt);
99 void OnExport(wxCommandEvent & evt);
100 void OnOptions(wxCommandEvent & evt);
101 void OnDefaults(wxCommandEvent & evt);
102 void OnIdle(wxIdleEvent &evt);
103 void OnCharHook(wxKeyEvent& evt);
104
105 bool IsOpenedFromEffectPanel() const;
106
107 void UpdateControls();
108 wxBitmap CreateBitmap(const char * const xpm[], bool up, bool pusher);
109 void LoadUserPresets();
110
111 void CleanupRealtime();
112
113 void StopPlayback();
114
115private:
117
119 wxWindow *const mParent;
126 std::weak_ptr<RealtimeEffectState> mwState{};
127 // Temporary state used for destructive processing
128 std::shared_ptr<RealtimeEffectState> mpTempProjectState {};
129
131 bool mInitialized{ false };
133 bool mIsGUI{};
134 bool mIsBatch{};
135
136 wxButton *mApplyBtn{};
137 wxButton *mMenuBtn{};
138 wxButton *mEnableBtn{};
139 wxButton *mDebugBtn{};
140 wxButton *mPlayToggleBtn{};
141
144
145 bool mEnabled{ true };
146
147 bool mDisableTransport{ true };
148 bool mPlaying{};
150
152 double mPlayPos{ 0.0 };
153
155 const bool mHadPriorState;
156
157#if wxDEBUG_LEVEL
158 // Used only in an assertion
159 bool mClosed{ false };
160#endif
161
162 const std::shared_ptr<EffectInstance> mpInstance;
164
165 std::unique_ptr<EffectUIValidator> mpValidator;
166
167 DECLARE_EVENT_TABLE()
168};
169
170class CommandContext;
171
172namespace EffectUI {
173
174 AUDACITY_DLL_API
175 DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host,
177
179 // Returns true on success. Will only operate on tracks that
180 // have the "selected" flag set to true, which is consistent with
181 // Audacity's standard UI.
182 AUDACITY_DLL_API bool DoEffect(
183 const PluginID & ID, const CommandContext &context, unsigned flags );
184
185}
186
187class ShuttleGui;
188
189// Obsolescent dialog still used only in Noise Reduction/Removal
190class AUDACITY_DLL_API EffectDialog /* not final */ : public wxDialogWrapper
191{
192public:
193 // constructors and destructors
194 EffectDialog(wxWindow * parent,
196 int type = 0,
197 int flags = wxDEFAULT_DIALOG_STYLE,
198 int additionalButtons = 0);
199
200 void Init();
201
202 bool TransferDataToWindow() override;
203 bool TransferDataFromWindow() override;
204 bool Validate() override;
205
206 // NEW virtuals:
207 virtual void PopulateOrExchange(ShuttleGui & S);
208 virtual void OnPreview(wxCommandEvent & evt);
209 virtual void OnOk(wxCommandEvent & evt);
210
211private:
212 int mType;
214
215 DECLARE_EVENT_TABLE()
216 wxDECLARE_NO_COPY_CLASS(EffectDialog);
217};
218
219#endif // __AUDACITY_EFFECTUI_H__
wxString PluginID
Definition: EffectManager.h:30
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
static const auto title
#define S(N)
Definition: ToChars.cpp:64
Base class for command in Audacity.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
int mAdditionalButtons
Definition: EffectUI.h:213
Hold values to send to effect output meters.
Factory of instances of an effect and of dialogs to control them.
Definition: EffectPlugin.h:55
std::shared_ptr< EffectSettingsAccess > EffectSettingsAccessPtr
Definition: EffectPlugin.h:57
EffectUIClientInterface is an abstract base class to populate a UI and validate UI values....
Definition: EffectPlugin.h:170
EffectPlugin & mEffectUIHost
Definition: EffectUI.h:120
void OnEnable(wxCommandEvent &evt)
Definition: EffectUI.cpp:740
void OnFactoryPreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:845
RegistryPaths mUserPresets
Definition: EffectUI.h:130
void OnDefaults(wxCommandEvent &evt)
Definition: EffectUI.cpp:984
Observer::Subscription mAudioIOSubscription
Definition: EffectUI.h:116
bool HandleCommandKeystrokes() override
Definition: EffectUI.cpp:480
void UpdateControls()
Definition: EffectUI.cpp:1058
const EffectPlugin::EffectSettingsAccessPtr mpGivenAccess
Definition: EffectUI.h:123
wxButton * mEnableBtn
Definition: EffectUI.h:138
wxPanel * BuildButtonBar(wxWindow *parent, bool graphicalUI)
bool mIsBatch
Definition: EffectUI.h:134
bool mCapturing
Definition: EffectUI.h:149
EffectUIValidator * GetValidator() const
Definition: EffectUI.h:65
wxButton * mMenuBtn
Definition: EffectUI.h:137
virtual ~EffectUIHost()
Definition: EffectUI.cpp:263
std::unique_ptr< EffectUIValidator > mpValidator
Definition: EffectUI.h:165
void OnErase(wxEraseEvent &evt)
Definition: EffectUI.cpp:509
void OnPlayback(AudioIOEvent)
Definition: EffectUI.cpp:797
void CleanupRealtime()
Definition: EffectUI.cpp:1170
AudacityProject & mProject
Definition: EffectUI.h:118
std::shared_ptr< RealtimeEffectState > mpTempProjectState
Definition: EffectUI.h:128
bool mIsGUI
Definition: EffectUI.h:133
bool TransferDataToWindow() override
Definition: EffectUI.cpp:275
EffectPlugin::EffectSettingsAccessPtr mpAccess
Definition: EffectUI.h:124
const EffectOutputs *const mpOutputs
Definition: EffectUI.h:163
void OnUserPreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:832
void OnDeletePreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:856
bool mPlaying
Definition: EffectUI.h:148
void OnIdle(wxIdleEvent &evt)
Definition: EffectUI.cpp:995
wxButton * mPlayToggleBtn
Definition: EffectUI.h:140
void StopPlayback()
Definition: EffectUI.cpp:1191
int ShowModal() override
Definition: EffectUI.cpp:324
bool mDisableTransport
Definition: EffectUI.h:147
Observer::Subscription mEffectStateSubscription
Definition: EffectUI.h:116
EffectUIClientInterface & mClient
Definition: EffectUI.h:121
SelectedRegion mRegion
Definition: EffectUI.h:151
void DoCancel()
Definition: EffectUI.cpp:605
void OnCapture(AudioIOEvent)
Definition: EffectUI.cpp:817
double mPlayPos
Definition: EffectUI.h:152
void OnClose(wxCloseEvent &evt)
Definition: EffectUI.cpp:521
void OnExport(wxCommandEvent &evt)
Definition: EffectUI.cpp:967
void OnSaveAs(wxCommandEvent &evt)
Definition: EffectUI.cpp:875
void SetClosed()
Definition: EffectUI.h:69
wxButton * mApplyBtn
Definition: EffectUI.h:136
const bool mHadPriorState
Definition: EffectUI.h:155
void OnOptions(wxCommandEvent &evt)
Definition: EffectUI.cpp:977
void LoadUserPresets()
Definition: EffectUI.cpp:1094
void OnInitDialog(wxInitDialogEvent &evt)
Definition: EffectUI.cpp:486
EffectUIHost(wxWindow *parent, AudacityProject &project, EffectPlugin &effect, EffectUIClientInterface &client, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, const std::shared_ptr< RealtimeEffectState > &pPriorState={})
Definition: EffectUI.cpp:227
void OnMenu(wxCommandEvent &evt)
Definition: EffectUI.cpp:648
void OnDebug(wxCommandEvent &evt)
Definition: EffectUI.cpp:632
void OnCharHook(wxKeyEvent &evt)
Definition: EffectUI.cpp:1002
bool mEnabled
Definition: EffectUI.h:145
EffectPlugin::EffectSettingsAccessPtr mpAccess2
Definition: EffectUI.h:125
void OnImport(wxCommandEvent &evt)
Definition: EffectUI.cpp:955
std::shared_ptr< EffectInstance > InitializeInstance()
Definition: EffectUI.cpp:1106
void OnApply(wxCommandEvent &evt)
Definition: EffectUI.cpp:540
const bool mSupportsRealtime
Definition: EffectUI.h:132
bool Initialize()
Definition: EffectUI.cpp:420
void OnPlay(wxCommandEvent &evt)
Definition: EffectUI.cpp:751
const std::shared_ptr< EffectInstance > mpInstance
Definition: EffectUI.h:162
void OnCancel(wxCommandEvent &evt)
Definition: EffectUI.cpp:626
bool mInitialized
Definition: EffectUI.h:131
std::weak_ptr< RealtimeEffectState > mwState
Definition: EffectUI.h:126
wxWindow *const mParent
Definition: EffectUI.h:119
wxButton * mDebugBtn
Definition: EffectUI.h:139
wxBitmap CreateBitmap(const char *const xpm[], bool up, bool pusher)
Definition: EffectUI.cpp:1025
bool IsOpenedFromEffectPanel() const
Definition: EffectUI.cpp:1020
bool TransferDataFromWindow() override
Definition: EffectUI.cpp:285
wxBitmap mRealtimeDisabledBM
Definition: EffectUI.h:143
void OnPaint(wxPaintEvent &evt)
Definition: EffectUI.cpp:514
bool mDismissed
Definition: EffectUI.h:154
wxBitmap mRealtimeEnabledBM
Definition: EffectUI.h:142
Interface for transferring values from a panel of effect controls.
Definition: EffectPlugin.h:239
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Defines a selected portion of a project.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
Holds a msgid for the translation catalog; may also bind format arguments.
AUDACITY_DLL_API bool DoEffect(const PluginID &ID, const CommandContext &context, unsigned flags)
'Repeat Last Effect'.
Definition: EffectUI.cpp:1241
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1202