Audacity 3.2.0
VST3UIValidator.cpp
Go to the documentation of this file.
1#include "VST3UIValidator.h"
2
3#include <pluginterfaces/gui/iplugview.h>
4
6#include "VST3Utils.h"
7#include "VST3Wrapper.h"
11
12#ifdef __WXGTK__
14#endif
15
16VST3UIValidator::VST3UIValidator(wxWindow* parent, VST3Wrapper& wrapper, EffectBase& effect, EffectSettingsAccess& access, bool useNativeUI)
17 : EffectUIValidator(effect, access), mWrapper(wrapper), mParent(parent)
18{
19 if(effect.GetType() == EffectTypeGenerate)
20 {
21 auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
22 auto controlsRoot = safenew wxWindow(parent, wxID_ANY);
23 if(!useNativeUI || !TryLoadNativeUI(controlsRoot))
25 vSizer->Add(controlsRoot);
26
27 auto &extra = access.Get().extra;
29 parent, wxID_ANY,
31 extra.GetDurationFormat(),
32 extra.GetDuration(),
33 mWrapper.mSetup.sampleRate,
35 .AutoPos(true)
36 );
37 mDuration->SetName( XO("Duration") );
38
39 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
40 hSizer->Add(safenew wxStaticText(parent, wxID_ANY, _("Duration:")));
41 hSizer->AddSpacer(5);
42 hSizer->Add(mDuration);
43 vSizer->AddSpacer(10);
44 vSizer->Add(hSizer.release());
45
46 parent->SetMinSize(vSizer->CalcMin());
47 parent->SetSizer(vSizer.release());
48 }
49 else if(!useNativeUI || !TryLoadNativeUI(parent))
50 {
52 *parent,
55 );
56 }
57
59 [this](Steinberg::Vst::ParamID id, Steinberg::Vst::ParamValue value) {
60 Publish({ static_cast<size_t>(id), static_cast<float>(value) });
61 };
62
64
65 Bind(wxEVT_IDLE, &VST3UIValidator::OnIdle, this);
66
67 mParent->PushEventHandler(this);
68}
69
71{
73}
74
75void VST3UIValidator::OnIdle(wxIdleEvent& evt)
76{
77 evt.Skip();
78 if(!mWrapper.IsActive())
79 {
81 {
82 bool hasChanges{false};
83 mWrapper.FlushParameters(settings, &hasChanges);
84 if(hasChanges)
86 return nullptr;
87 });
88 }
89}
90
91
93{
94 using namespace Steinberg;
95
96 if(const auto view = owned (mWrapper.mEditController->createView (Vst::ViewType::kEditor)))
97 {
98 //Workaround: override default min size set by EffectUIHost::Initialize()
99 parent->SetMinSize(wxDefaultSize);
100 //IPlugFrame::resizeView is supposed to call IPlugView::setSize
101 //in the same call stack, assign before frame is attached
102 mPlugView = view;
103
104#if __WXGTK__
105 safenew internal::x11::SocketWindow(parent, wxID_ANY, view);
106#else
107
108 static const auto platformType =
109# if __WXMAC__
110 kPlatformTypeNSView;
111# elif __WXMSW__
112 kPlatformTypeHWND;
113# else
114# error "Platform not supported"
115# endif
116 auto plugFrame = owned(safenew internal::PlugFrame { parent });
117 view->setFrame(plugFrame);
118 if(view->attached(parent->GetHandle(), platformType) != kResultOk)
119 return false;
120 mPlugFrame = plugFrame;
121
122 ViewRect initialSize;
123 if(view->getSize(&initialSize) == kResultOk)
124 plugFrame->init(view.get(), &initialSize);
125#endif
126 return true;
127 }
128 return false;
129}
130
132{
133 return mPlugView != nullptr;
134}
135
137{
139 if (mDuration != nullptr)
140 settings.extra.SetDuration(mDuration->GetValue());
143 return nullptr;
144 });
145
146 return true;
147}
148
150{
151 using namespace Steinberg;
152
153 mParent->PopEventHandler();
154
155 mPlainUI = nullptr;
156 mParent = nullptr;
157 if(mPlugView)
158 {
159 mPlugView->setFrame(nullptr);
160 mPlugView->removed();
161 mPlugView = nullptr;
162 mPlugFrame = nullptr;
163 }
164
166
168 if (mDuration != nullptr)
169 settings.extra.SetDuration(mDuration->GetValue());
170 //Flush changes if there is no processing performed at the moment
173 return nullptr;
174 });
175 //Make sure that new state has been written to the caches...
176 mAccess.Flush();
177
179
181}
182
184{
187 return nullptr;
188 });
189
190 if (mPlainUI != nullptr)
192
193 //Write to main...
194 mAccess.Flush();
195
196 return true;
197}
@ EffectTypeGenerate
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
#define safenew
Definition: MemoryX.h:10
static Settings & settings()
Definition: TrackInfo.cpp:87
int id
Base class for many of the effects in Audacity.
Definition: EffectBase.h:33
virtual EffectType GetType() const =0
Type determines how it behaves.
void ModifySettings(Function &&function)
Do a correct read-modify-write of settings.
virtual const EffectSettings & Get()=0
virtual void Flush()=0
Make the last Set changes "persistent" in underlying storage.
Interface for transferring values from a panel of effect controls.
EffectSettingsAccess & mAccess
virtual void OnClose()
void SetName(const TranslatableString &name)
CallbackReturn Publish(const EffectSettingChanged &message)
Send a message to connected callbacks.
Definition: Observer.h:207
static VST3ParametersWindow * Setup(wxWindow &parent, Steinberg::Vst::IEditController &editController, Steinberg::Vst::IComponentHandler &componentHandler)
Creates VST3ParametersWindow inside parent.
bool UpdateUI() override
Update appearance of the panel for changes in settings.
VST3UIValidator(wxWindow *parent, VST3Wrapper &wrapper, EffectBase &effect, EffectSettingsAccess &access, bool useNativeUI)
void OnClose() override
bool IsGraphicalUI() override
~VST3UIValidator() override
VST3Wrapper & mWrapper
Steinberg::IPtr< Steinberg::IPlugFrame > mPlugFrame
Steinberg::IPtr< Steinberg::IPlugView > mPlugView
NumericTextCtrl * mDuration
wxWindow * mParent
VST3ParametersWindow * mPlainUI
void OnIdle(wxIdleEvent &)
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
bool TryLoadNativeUI(wxWindow *parent)
void BeginParameterEdit(EffectSettingsAccess &access)
Steinberg::IPtr< Steinberg::Vst::IEditController > mEditController
Definition: VST3Wrapper.h:61
Steinberg::IPtr< Steinberg::Vst::IComponentHandler > mComponentHandler
Definition: VST3Wrapper.h:64
void FetchSettings(EffectSettings &)
Fetch state from settings object, may change internal runtime data.
std::function< void(Steinberg::Vst::ParamID, Steinberg::Vst::ParamValue)> ParamChangedHandler
Definition: VST3Wrapper.h:126
bool IsActive() const noexcept
void StoreSettings(EffectSettings &) const
Saves current state inside settings object, clears all runtime data.
void EndParameterEdit()
Steinberg::Vst::ProcessSetup mSetup
Definition: VST3Wrapper.h:59
void FlushParameters(EffectSettings &settings, bool *hasChanges=nullptr)
Dispatches window resize events from VST PlugView to the wxWindow.
Definition: PlugFrame.h:23
Wrapper for GtkSocket object, which provides X window mapping via XEmbed protocol.
Definition: SocketWindow.h:34
Externalized state of a plug-in.
EffectSettingsExtra extra
Options & AutoPos(bool enable)