Audacity 3.2.0
EffectPlugin.h
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file EffectPlugin.h
6
7 Paul Licameli
8 split from EffectInterface.h
9
10**********************************************************************/
11
12#ifndef __AUDACITY_EFFECTPLUGIN_H__
13#define __AUDACITY_EFFECTPLUGIN_H__
14
15#include "EffectInterface.h"
16
17#include <functional>
18#include <memory>
19
21
22class wxDialog;
23class wxWindow;
25class EffectInstance;
26class EffectSettings;
28class EffectPlugin;
30
32 wxDialog *pDialog{};
34 std::shared_ptr<EffectInstance> pInstance{};
36};
37
39
41 wxWindow &parent, EffectPlugin &, EffectUIClientInterface &,
43
44class TrackList;
47class EffectInstance;
48
49/***************************************************************************/
53class AUDACITY_DLL_API EffectPlugin
55{
56public:
57 using EffectSettingsAccessPtr = std::shared_ptr<EffectSettingsAccess>;
58
59 const static wxString kUserPresetIdent;
60 const static wxString kFactoryPresetIdent;
61 const static wxString kCurrentSettingsIdent;
62 const static wxString kFactoryDefaultsIdent;
63
65 virtual ~EffectPlugin();
66
67 virtual const EffectSettingsManager& GetDefinition() const = 0;
68
70
83 virtual int ShowHostInterface(
84 wxWindow &parent, const EffectDialogFactory &factory,
85 std::shared_ptr<EffectInstance> &pInstance, EffectSettingsAccess &access,
86 bool forceModal = false) = 0;
87
89
95
96 virtual void Preview(EffectSettingsAccess &access, bool dryOnly) = 0;
98 const EffectSettings &settings, wxString & parms) const = 0;
99 // @return nullptr for failure
101 const wxString & parms, EffectSettings &settings) const = 0;
102 virtual bool IsBatchProcessing() const = 0;
103 virtual void SetBatchProcessing() = 0;
104 virtual void UnsetBatchProcessing() = 0;
105
107
120 virtual bool DoEffect(
122 double projectRate, TrackList *list,
124 unsigned flags,
125 // Prompt the user for input only if the next arguments are not all null.
126 wxWindow *pParent = nullptr,
127 const EffectDialogFactory &dialogFactory = {},
128 const EffectSettingsAccessPtr &pAccess = nullptr
130 ) = 0;
131
134
137};
138
139/***************************************************************************/
143class AUDACITY_DLL_API EffectInstanceEx : public virtual EffectInstance {
144public:
146
150 virtual bool Init();
151
153
156 virtual bool Process(EffectSettings &settings) = 0;
157
159};
160
161/*************************************************************************************/
169class AUDACITY_DLL_API EffectUIClientInterface /* not final */
170{
171public:
173
178 virtual int ShowClientInterface(wxWindow &parent, wxDialog &dialog,
179 EffectUIValidator *pValidator, bool forceModal = false) = 0;
180
184 virtual bool IsGraphicalUI() = 0;
185
187
200 virtual std::unique_ptr<EffectUIValidator> PopulateUI(ShuttleGui &S,
201 EffectInstance &instance, EffectSettingsAccess &access,
202 const EffectOutputs *pOutputs) = 0;
203
204 virtual bool CanExportPresets() = 0;
205 virtual void ExportPresets(const EffectSettings &settings) const = 0;
207 [[nodiscard]] virtual OptionalMessage
209
210 virtual bool HasOptions() = 0;
211 virtual void ShowOptions() = 0;
212
214 virtual bool CloseUI() = 0;
215};
216
217/*************************************************************************************/
225{
226 size_t index { size_t(-1) };
227 float newValue {};
228};
229
230/*************************************************************************************/
237class AUDACITY_DLL_API EffectUIValidator /* not final */
238 : public Observer::Publisher<EffectSettingChanged>
239{
240public:
243
245
247
250 virtual bool ValidateUI() = 0;
251
253
258 virtual bool UpdateUI();
259
264 virtual bool IsGraphicalUI();
265
267
270 virtual void Disconnect();
271
275 virtual void OnClose();
276
278 static bool EnableApply(wxWindow *parent, bool enable = true);
279
280 // id that should be used by preview play button of effect dialog
281 static constexpr int kPlayID = 20102;
282
285 static bool EnablePreview(wxWindow *parent, bool enable = true);
286
287 protected:
288 // Convenience function template for binding event handler functions
289 template<typename EventTag, typename Class, typename Event>
290 void BindTo(
291 wxEvtHandler &src, const EventTag& eventType, void (Class::*pmf)(Event &))
292 {
293 src.Bind(eventType, pmf, static_cast<Class *>(this));
294 }
295
298
299 bool mUIClosed { false };
300};
301#endif
static const int kPlayID
Definition: Effect.cpp:43
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
std::function< DialogFactoryResults(wxWindow &parent, EffectPlugin &, EffectUIClientInterface &, EffectSettingsAccess &) > EffectDialogFactory
Type of function that creates a dialog for an effect.
Definition: EffectPlugin.h:42
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
Performs effect computation.
Definition: EffectPlugin.h:143
~EffectInstanceEx() override
virtual bool Process(EffectSettings &settings)=0
Actually do the effect here.
Performs effect computation.
Hold values to send to effect output meters.
Factory of instances of an effect and of dialogs to control them.
Definition: EffectPlugin.h:55
static const wxString kUserPresetIdent
Definition: EffectPlugin.h:59
virtual void SetBatchProcessing()=0
virtual bool TransferDataToWindow(const EffectSettings &settings)=0
Update controls for the settings.
virtual ~EffectPlugin()
std::shared_ptr< EffectSettingsAccess > EffectSettingsAccessPtr
Definition: EffectPlugin.h:57
virtual bool DoEffect(EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
Unfortunately complicated dual-use function.
static const wxString kFactoryPresetIdent
Definition: EffectPlugin.h:60
virtual bool TransferDataFromWindow(EffectSettings &settings)=0
Update the given settings from controls.
virtual void UnsetBatchProcessing()=0
virtual int ShowHostInterface(wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
Usually applies factory to self and given access.
virtual EffectUIClientInterface * GetEffectUIClientInterface()=0
Returns the EffectUIClientInterface instance for this effect.
virtual bool SaveSettingsAsString(const EffectSettings &settings, wxString &parms) const =0
virtual const EffectSettingsManager & GetDefinition() const =0
virtual bool IsBatchProcessing() const =0
virtual OptionalMessage LoadSettingsFromString(const wxString &parms, EffectSettings &settings) const =0
static const wxString kCurrentSettingsIdent
Definition: EffectPlugin.h:61
static const wxString kFactoryDefaultsIdent
Definition: EffectPlugin.h:62
virtual void Preview(EffectSettingsAccess &access, bool dryOnly)=0
EffectPlugin & operator=(EffectPlugin &)=delete
EffectSettingsManager is an EffectDefinitionInterface that adds a factory function for EffectSettings...
EffectUIClientInterface is an abstract base class to populate a UI and validate UI values....
Definition: EffectPlugin.h:170
virtual std::unique_ptr< EffectUIValidator > PopulateUI(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=0
Adds controls to a panel that is given as the parent window of S
virtual OptionalMessage ImportPresets(EffectSettings &settings)=0
virtual bool CloseUI()=0
virtual void ShowOptions()=0
virtual int ShowClientInterface(wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
virtual bool ValidateUI(EffectSettings &settings)=0
virtual ~EffectUIClientInterface()
virtual bool IsGraphicalUI()=0
virtual void ExportPresets(const EffectSettings &settings) const =0
virtual bool CanExportPresets()=0
virtual bool HasOptions()=0
Interface for transferring values from a panel of effect controls.
Definition: EffectPlugin.h:239
EffectSettingsAccess & mAccess
Definition: EffectPlugin.h:297
virtual bool ValidateUI()=0
Get settings data from the panel; may make error dialogs and return false.
virtual ~EffectUIValidator()
void BindTo(wxEvtHandler &src, const EventTag &eventType, void(Class::*pmf)(Event &))
Definition: EffectPlugin.h:290
EffectUIClientInterface & mEffect
Definition: EffectPlugin.h:296
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1338
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:620
void OnClose(wxCommandEvent &e)
static RegisteredToolbarFactory factory
std::shared_ptr< EffectInstance > pInstance
constructed and successfully Init()-ed; or null for failure
Definition: EffectPlugin.h:34
EffectUIValidator * pValidator
Definition: EffectPlugin.h:35
Message sent by validator when a setting is changed by a user.
Definition: EffectPlugin.h:225
Externalized state of a plug-in.