Audacity 3.2.0
StatefulEffectUIServices.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 StatefulEffectUIServices.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10 Paul Licameli split from Effect.cpp
11
12**********************************************************************/
14#include "EffectEditor.h"
15#include "ShuttleGui.h"
16#include <wx/sizer.h>
17#include <wx/window.h>
18
19namespace {
22/*
23 Also pops the even handler stack of a window, if given to the contructor
24
25 This is a transitional class; it should be eliminated when all effect classes
26 define their own associated subclasses of EffectEditor, which can hold
27 state only for the lifetime of a dialog, so the effect object need not hold it
28*/
30 : public EffectEditor
31 // Inherit wxEvtHandler so that Un-Bind()-ing is automatic in the destructor
32 , protected wxEvtHandler
33{
34public:
40 EffectUIServices &services, EffectSettingsAccess &access,
41 wxWindow *pParent = nullptr);
43 ~DefaultEffectEditor() override;
45 bool ValidateUI() override;
46 void Disconnect() override;
47protected:
49 wxWindow *mpParent{};
50};
51
52DefaultEffectEditor::DefaultEffectEditor(const EffectPlugin &plugin,
53 EffectUIServices &services, EffectSettingsAccess &access,
54 wxWindow *pParent
55) : EffectEditor{ services, access }
56 , mPlugin{ plugin }
57 , mpParent{ pParent }
58{
59}
60
62{
63 Disconnect();
64}
65
67{
68 bool result {};
71 return nullptr;
72 });
73 return result;
74}
75
77{
78 if (mpParent) {
79 mpParent->PopEventHandler();
80 mpParent = nullptr;
81 }
82}
83}
84
86
87std::unique_ptr<EffectEditor>
89 EffectInstance &instance, EffectSettingsAccess &access,
90 const EffectOutputs *pOutputs) const
91{
92 auto parent = S.GetParent();
93
94 // As in MakeInstance, we still cheat const for stateful effects!
95 auto pThis = const_cast<StatefulEffectUIServices*>(this);
96
97 // Let the effect subclass provide its own editor if it wants
98 auto result = pThis->PopulateOrExchange(S, instance, access, pOutputs);
99
100 parent->SetMinSize(parent->GetSizer()->GetMinSize());
101
102 if (!result) {
103 // No custom editor object? Then use the default
104 result = std::make_unique<DefaultEffectEditor>(plugin,
105 *pThis, access, S.GetParent());
106 parent->PushEventHandler(pThis);
107 }
108 return result;
109}
110
113 const EffectOutputs *)
114{
115 return nullptr;
116}
117
119{
120 return true;
121}
122
124{
125 return true;
126}
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:51
const EffectUIServices & mUIServices
Definition: EffectEditor.h:91
EffectSettingsAccess & mAccess
Definition: EffectEditor.h:92
Performs effect computation.
Hold values to send to effect output meters.
Factory of instances of an effect.
Definition: EffectPlugin.h:36
void ModifySettings(Function &&function)
Do a correct read-modify-write of settings.
virtual bool ValidateUI(const EffectPlugin &context, EffectSettings &settings) const =0
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
virtual bool TransferDataToWindow(const EffectSettings &settings)
virtual std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
Add controls to effect panel; always succeeds.
~StatefulEffectUIServices() override
virtual bool TransferDataFromWindow(EffectSettings &settings)
std::unique_ptr< EffectEditor > PopulateUI(const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
Allows PopulateOrExchange to return null.
void Disconnect() override
On the first call only, may disconnect from further event handling.
Externalized state of a plug-in.