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 std::unique_ptr<EffectUIValidator> mpValidator;
130
132 bool mInitialized{ false };
134 bool mIsGUI{};
135 bool mIsBatch{};
136
137 wxButton *mApplyBtn{};
138 wxButton *mMenuBtn{};
139 wxButton *mEnableBtn{};
140 wxButton *mDebugBtn{};
141 wxButton *mPlayToggleBtn{};
142
145
146 bool mEnabled{ true };
147
148 bool mDisableTransport{ true };
149 bool mPlaying{};
151
153 double mPlayPos{ 0.0 };
154
156 const bool mHadPriorState;
157
158#if wxDEBUG_LEVEL
159 // Used only in an assertion
160 bool mClosed{ false };
161#endif
162
163 const std::shared_ptr<EffectInstance> mpInstance;
164
165 DECLARE_EVENT_TABLE()
166};
167
168class CommandContext;
169
170namespace EffectUI {
171
172 AUDACITY_DLL_API
173 DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host,
175
177 // Returns true on success. Will only operate on tracks that
178 // have the "selected" flag set to true, which is consistent with
179 // Audacity's standard UI.
180 AUDACITY_DLL_API bool DoEffect(
181 const PluginID & ID, const CommandContext &context, unsigned flags );
182
183}
184
185class ShuttleGui;
186
187// Obsolescent dialog still used only in Noise Reduction/Removal
188class AUDACITY_DLL_API EffectDialog /* not final */ : public wxDialogWrapper
189{
190public:
191 // constructors and destructors
192 EffectDialog(wxWindow * parent,
194 int type = 0,
195 int flags = wxDEFAULT_DIALOG_STYLE,
196 int additionalButtons = 0);
197
198 void Init();
199
200 bool TransferDataToWindow() override;
201 bool TransferDataFromWindow() override;
202 bool Validate() override;
203
204 // NEW virtuals:
205 virtual void PopulateOrExchange(ShuttleGui & S);
206 virtual void OnPreview(wxCommandEvent & evt);
207 virtual void OnOk(wxCommandEvent & evt);
208
209private:
210 int mType;
212
213 DECLARE_EVENT_TABLE()
214 wxDECLARE_NO_COPY_CLASS(EffectDialog);
215};
216
217#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:89
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
int mAdditionalButtons
Definition: EffectUI.h:211
Factory of instances of an effect and of dialogs to control them.
Definition: EffectPlugin.h:54
std::shared_ptr< EffectSettingsAccess > EffectSettingsAccessPtr
Definition: EffectPlugin.h:56
EffectUIClientInterface is an abstract base class to populate a UI and validate UI values....
EffectPlugin & mEffectUIHost
Definition: EffectUI.h:120
void OnEnable(wxCommandEvent &evt)
Definition: EffectUI.cpp:721
void OnFactoryPreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:825
RegistryPaths mUserPresets
Definition: EffectUI.h:131
void OnDefaults(wxCommandEvent &evt)
Definition: EffectUI.cpp:962
Observer::Subscription mAudioIOSubscription
Definition: EffectUI.h:116
bool HandleCommandKeystrokes() override
Definition: EffectUI.cpp:462
void UpdateControls()
Definition: EffectUI.cpp:1034
const EffectPlugin::EffectSettingsAccessPtr mpGivenAccess
Definition: EffectUI.h:123
wxButton * mEnableBtn
Definition: EffectUI.h:139
wxPanel * BuildButtonBar(wxWindow *parent, bool graphicalUI)
bool mIsBatch
Definition: EffectUI.h:135
bool mCapturing
Definition: EffectUI.h:150
EffectUIValidator * GetValidator() const
Definition: EffectUI.h:65
wxButton * mMenuBtn
Definition: EffectUI.h:138
virtual ~EffectUIHost()
Definition: EffectUI.cpp:246
std::unique_ptr< EffectUIValidator > mpValidator
Definition: EffectUI.h:129
void OnErase(wxEraseEvent &evt)
Definition: EffectUI.cpp:491
void OnPlayback(AudioIOEvent)
Definition: EffectUI.cpp:778
void CleanupRealtime()
Definition: EffectUI.cpp:1147
AudacityProject & mProject
Definition: EffectUI.h:118
std::shared_ptr< RealtimeEffectState > mpTempProjectState
Definition: EffectUI.h:128
bool mIsGUI
Definition: EffectUI.h:134
bool TransferDataToWindow() override
Definition: EffectUI.cpp:258
EffectPlugin::EffectSettingsAccessPtr mpAccess
Definition: EffectUI.h:124
void OnUserPreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:813
void OnDeletePreset(wxCommandEvent &evt)
Definition: EffectUI.cpp:835
bool mPlaying
Definition: EffectUI.h:149
void OnIdle(wxIdleEvent &evt)
Definition: EffectUI.cpp:971
wxButton * mPlayToggleBtn
Definition: EffectUI.h:141
void StopPlayback()
Definition: EffectUI.cpp:1168
int ShowModal() override
Definition: EffectUI.cpp:306
bool mDisableTransport
Definition: EffectUI.h:148
Observer::Subscription mEffectStateSubscription
Definition: EffectUI.h:116
EffectUIClientInterface & mClient
Definition: EffectUI.h:121
SelectedRegion mRegion
Definition: EffectUI.h:152
void DoCancel()
Definition: EffectUI.cpp:587
void OnCapture(AudioIOEvent)
Definition: EffectUI.cpp:798
double mPlayPos
Definition: EffectUI.h:153
void OnClose(wxCloseEvent &evt)
Definition: EffectUI.cpp:503
void OnExport(wxCommandEvent &evt)
Definition: EffectUI.cpp:945
void OnSaveAs(wxCommandEvent &evt)
Definition: EffectUI.cpp:854
void SetClosed()
Definition: EffectUI.h:69
wxButton * mApplyBtn
Definition: EffectUI.h:137
const bool mHadPriorState
Definition: EffectUI.h:156
void OnOptions(wxCommandEvent &evt)
Definition: EffectUI.cpp:955
void LoadUserPresets()
Definition: EffectUI.cpp:1070
void OnInitDialog(wxInitDialogEvent &evt)
Definition: EffectUI.cpp:468
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:211
void OnMenu(wxCommandEvent &evt)
Definition: EffectUI.cpp:629
void OnDebug(wxCommandEvent &evt)
Definition: EffectUI.cpp:613
void OnCharHook(wxKeyEvent &evt)
Definition: EffectUI.cpp:978
bool mEnabled
Definition: EffectUI.h:146
EffectPlugin::EffectSettingsAccessPtr mpAccess2
Definition: EffectUI.h:125
void OnImport(wxCommandEvent &evt)
Definition: EffectUI.cpp:934
std::shared_ptr< EffectInstance > InitializeInstance()
Definition: EffectUI.cpp:1082
void OnApply(wxCommandEvent &evt)
Definition: EffectUI.cpp:522
const bool mSupportsRealtime
Definition: EffectUI.h:133
bool Initialize()
Definition: EffectUI.cpp:402
void OnPlay(wxCommandEvent &evt)
Definition: EffectUI.cpp:732
const std::shared_ptr< EffectInstance > mpInstance
Definition: EffectUI.h:163
void OnCancel(wxCommandEvent &evt)
Definition: EffectUI.cpp:607
bool mInitialized
Definition: EffectUI.h:132
std::weak_ptr< RealtimeEffectState > mwState
Definition: EffectUI.h:126
wxWindow *const mParent
Definition: EffectUI.h:119
wxButton * mDebugBtn
Definition: EffectUI.h:140
wxBitmap CreateBitmap(const char *const xpm[], bool up, bool pusher)
Definition: EffectUI.cpp:1001
bool IsOpenedFromEffectPanel() const
Definition: EffectUI.cpp:996
bool TransferDataFromWindow() override
Definition: EffectUI.cpp:268
wxBitmap mRealtimeDisabledBM
Definition: EffectUI.h:144
void OnPaint(wxPaintEvent &evt)
Definition: EffectUI.cpp:496
bool mDismissed
Definition: EffectUI.h:155
wxBitmap mRealtimeEnabledBM
Definition: EffectUI.h:143
Interface for transferring values from a panel of effect controls.
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:1218
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1179