Audacity 3.2.0
VST3Editor.cpp
Go to the documentation of this file.
1#include "VST3Editor.h"
2
3#include <pluginterfaces/gui/iplugview.h>
4
6#include "VST3Utils.h"
7#include "VST3Wrapper.h"
11
12#ifdef __WXGTK__
14#endif
15
16VST3Editor::VST3Editor(wxWindow* parent, VST3Wrapper& wrapper,
17 const EffectUIServices& effect, EffectType type,
19 bool useNativeUI)
20 : EffectEditor(effect, access), mWrapper(wrapper), mParent(parent)
21{
22 if (type == EffectTypeGenerate)
23 {
24 auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
25 auto controlsRoot = safenew wxWindow(parent, wxID_ANY);
26 if(!useNativeUI || !TryLoadNativeUI(controlsRoot))
28 vSizer->Add(controlsRoot);
29
30 auto &extra = access.Get().extra;
33 parent, wxID_ANY,
35 extra.GetDurationFormat(),
36 extra.GetDuration(),
38 .AutoPos(true)
39 );
40 mDuration->SetName( XO("Duration") );
41
42 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
43 hSizer->Add(safenew wxStaticText(parent, wxID_ANY, _("Duration:")));
44 hSizer->AddSpacer(5);
45 hSizer->Add(mDuration);
46 vSizer->AddSpacer(10);
47 vSizer->Add(hSizer.release());
48
49 parent->SetMinSize(vSizer->CalcMin());
50 parent->SetSizer(vSizer.release());
51 }
52 else if(!useNativeUI || !TryLoadNativeUI(parent))
53 {
55 *parent,
58 );
59 }
60
62 [this](Steinberg::Vst::ParamID id, Steinberg::Vst::ParamValue value) {
63 Publish({ static_cast<size_t>(id), static_cast<float>(value) });
64 };
65
67
68 Bind(wxEVT_IDLE, &VST3Editor::OnIdle, this);
69
70 mParent->PushEventHandler(this);
71}
72
74{
76}
77
78void VST3Editor::OnIdle(wxIdleEvent& evt)
79{
80 evt.Skip();
81 if(!mWrapper.IsActive())
82 {
84 {
85 bool hasChanges{false};
86 mWrapper.FlushParameters(settings, &hasChanges);
87 if(hasChanges)
89 return nullptr;
90 });
91 }
92}
93
94
95bool VST3Editor::TryLoadNativeUI(wxWindow* parent)
96{
97 using namespace Steinberg;
98
99 if(const auto view = owned (mWrapper.mEditController->createView (Vst::ViewType::kEditor)))
100 {
101 //Workaround: override default min size set by EffectUIHost::Initialize()
102 parent->SetMinSize(wxDefaultSize);
103 //IPlugFrame::resizeView is supposed to call IPlugView::setSize
104 //in the same call stack, assign before frame is attached
105 mPlugView = view;
106
107#if __WXGTK__
108 safenew internal::x11::SocketWindow(parent, wxID_ANY, view);
109#else
110
111 static const auto platformType =
112# if __WXMAC__
113 kPlatformTypeNSView;
114# elif __WXMSW__
115 kPlatformTypeHWND;
116# else
117# error "Platform not supported"
118# endif
119 auto plugFrame = owned(safenew internal::PlugFrame { parent });
120 view->setFrame(plugFrame);
121 if(view->attached(parent->GetHandle(), platformType) != kResultOk)
122 return false;
123 mPlugFrame = plugFrame;
124
125 ViewRect initialSize;
126 if(view->getSize(&initialSize) == kResultOk)
127 plugFrame->init(view.get(), &initialSize);
128#endif
129 return true;
130 }
131 return false;
132}
133
135{
136 return mPlugView != nullptr;
137}
138
140{
142 if (mDuration != nullptr)
143 settings.extra.SetDuration(mDuration->GetValue());
146 return nullptr;
147 });
148
149 return true;
150}
151
153{
154 using namespace Steinberg;
155
156 mParent->PopEventHandler();
157
158 mPlainUI = nullptr;
159 mParent = nullptr;
160 if(mPlugView)
161 {
162 mPlugView->setFrame(nullptr);
163 mPlugView->removed();
164 mPlugView = nullptr;
165 mPlugFrame = nullptr;
166 }
167
169
171 if (mDuration != nullptr)
172 settings.extra.SetDuration(mDuration->GetValue());
173 //Flush changes if there is no processing performed at the moment
176 return nullptr;
177 });
178 //Make sure that new state has been written to the caches...
179 mAccess.Flush();
180
182
184}
185
187{
190 return nullptr;
191 });
192
193 if (mPlainUI != nullptr)
195
196 //Write to main...
197 mAccess.Flush();
198
199 return true;
200}
EffectType
@ EffectTypeGenerate
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
#define safenew
Definition: MemoryX.h:10
const NumericConverterType & NumericConverterType_TIME()
static Settings & settings()
Definition: TrackInfo.cpp:51
int id
virtual void OnClose()
EffectSettingsAccess & mAccess
Definition: EffectEditor.h:92
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.
static FormatterContext SampleRateContext(double sampleRate)
void SetName(const TranslatableString &name)
CallbackReturn Publish(const EffectSettingChanged &message)
Send a message to connected callbacks.
Definition: Observer.h:207
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: VST3Editor.cpp:139
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: VST3Editor.cpp:186
bool TryLoadNativeUI(wxWindow *parent)
Definition: VST3Editor.cpp:95
VST3ParametersWindow * mPlainUI
Definition: VST3Editor.h:31
void OnClose() override
Definition: VST3Editor.cpp:152
VST3Wrapper & mWrapper
Definition: VST3Editor.h:24
Steinberg::IPtr< Steinberg::IPlugFrame > mPlugFrame
Definition: VST3Editor.h:27
void OnIdle(wxIdleEvent &)
Definition: VST3Editor.cpp:78
Steinberg::IPtr< Steinberg::IPlugView > mPlugView
Definition: VST3Editor.h:26
~VST3Editor() override
Definition: VST3Editor.cpp:73
bool IsGraphicalUI() override
Definition: VST3Editor.cpp:134
NumericTextCtrl * mDuration
Definition: VST3Editor.h:29
wxWindow * mParent
Definition: VST3Editor.h:28
VST3Editor(wxWindow *parent, VST3Wrapper &wrapper, const EffectUIServices &effect, EffectType type, EffectSettingsAccess &access, bool useNativeUI)
Definition: VST3Editor.cpp:16
static VST3ParametersWindow * Setup(wxWindow &parent, Steinberg::Vst::IEditController &editController, Steinberg::Vst::IComponentHandler &componentHandler)
Creates VST3ParametersWindow inside parent.
void BeginParameterEdit(EffectSettingsAccess &access)
Steinberg::IPtr< Steinberg::Vst::IEditController > mEditController
Definition: VST3Wrapper.h:70
Steinberg::IPtr< Steinberg::Vst::IComponentHandler > mComponentHandler
Definition: VST3Wrapper.h:73
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:143
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:68
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)