Audacity 3.2.0
LV2Editor.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file LV2Editor.h
6 @brief Event handling object for user interfaces of LV2 effects
7
8 Paul Licameli split from LV2Effect.h
9
10 Audacity(R) is copyright (c) 1999-2013 Audacity Team.
11 License: GPL v2 or later. See License.txt.
12
13*********************************************************************/
14
15#ifndef __AUDACITY_LV2_EDITOR__
16#define __AUDACITY_LV2_EDITOR__
17
18#if USE_LV2
19
20#include "../EffectEditor.h"
21
22#include <optional>
23#include <vector>
24
25#include <wx/timer.h>
26#include <wx/weakref.h>
27#include <wx/window.h>
28#include <wx/windowptr.h>
29
30#include "LV2UIFeaturesList.h"
31#include "LV2Ports.h"
32#include "NativeWindow.h"
33
35
36// We use deprecated LV2 interfaces to remain compatible with older
37// plug-ins, so disable warnings
38LV2_DISABLE_DEPRECATION_WARNINGS
39
40class wxButton;
41class wxCheckBox;
42class wxChoice;
43class wxSlider;
44class wxTextCtrl;
45class NumericTextCtrl;
46
47class LV2EffectMeter;
48class LV2Instance;
49class LV2Wrapper;
51
52class LV2Editor final : public EffectEditor
53 , public wxEvtHandler
55{
56public:
58 const LilvPlugin &plug, LV2Instance &instance,
59 EffectSettingsAccess &access, const EffectOutputs *pOutputs,
60 double sampleRate,
61 const LV2FeaturesList &features,
62 const LV2Ports &ports, wxWindow *parent, bool useGUI);
63 ~LV2Editor() override;
64
65 bool ValidateUI() override;
66 bool UpdateUI() override;
67 bool IsGraphicalUI() override;
68 void Disconnect() override;
69
70 int ui_resize(int width, int height) override;
71 void ui_closed() override;
72
73#if defined(__WXGTK__)
74 static void size_request(GtkWidget *widget, GtkRequisition *requisition,
75 LV2Editor *pEditor);
76 void SizeRequest(GtkWidget *widget, GtkRequisition *requisition);
77#endif
78
82 bool BuildFancy(std::unique_ptr<LV2Wrapper> pWrapper,
84 bool BuildPlain(EffectSettingsAccess &access);
85
86 void suil_port_write(uint32_t port_index,
87 uint32_t buffer_size, uint32_t protocol, const void *buffer) override;
88 uint32_t suil_port_index(const char *port_symbol) override;
89
90 void UpdateControlPortValue(LV2EffectSettings& settings, size_t controlPortIndex, float value);
91
92 void OnTrigger(wxCommandEvent & evt);
93 void OnToggle(wxCommandEvent & evt);
94 void OnChoice(wxCommandEvent & evt);
95 void OnText(wxCommandEvent & evt);
96 void OnSlider(wxCommandEvent & evt);
97
98 void OnIdle(wxIdleEvent & evt);
99 void OnSize(wxSizeEvent & evt);
100
101 static std::shared_ptr<SuilHost> GetSuilHost();
102
103 const LilvPlugin &mPlug;
107 const double mSampleRate;
109 std::unique_ptr<LV2Wrapper> mpWrapper;
110 std::optional<const LV2UIFeaturesList> mUIFeatures;
112
113 std::shared_ptr<SuilHost> mSuilHost;
114 wxWindow *mParent;
115 bool mUseGUI{};
116
117 // UI
119 wxTextCtrl *mText{};
121 union {
122 wxButton *button;
123 wxCheckBox *checkbox;
124 wxChoice *choice;
126 wxSlider *slider;
127 };
128 };
130 std::vector<PlainUIControl> mPlainUIControls;
131 void SetSlider(const LV2ControlPortState &state, const PlainUIControl &ctrl);
132
133 // Two smart pointers are grouped because their destruction needs caution
134 struct UI {
135 void Destroy();
136 ~UI() { Destroy(); }
138 wxWindowPtr<NativeWindow> mNativeWin{};
139#ifdef __WXMAC__
140 bool mJustLeakMemory{ false };
141#endif
143
144 wxSize mNativeWinInitialSize{ wxDefaultSize };
145 wxSize mNativeWinLastSize{ wxDefaultSize };
146 bool mResizing{ false };
147#if defined(__WXGTK__)
148 bool mResized{ false };
149#endif
150
151 wxWeakRef<wxDialog> mDialog;
152 bool mExternalUIClosed{ false };
153
155 struct Timer : wxTimer {
157 void Notify() override;
159
160 const LV2UI_Idle_Interface *mUIIdleInterface{};
161 const LV2UI_Show_Interface *mUIShowInterface{};
163
164 DECLARE_EVENT_TABLE()
165};
166
167#endif
168#endif
EffectType
Lilv_ptr< SuilInstance, suil_instance_free > SuilInstancePtr
Definition: LV2Editor.h:34
std::unique_ptr< Type, Lilv_deleter< Type, f > > Lilv_ptr
Generate classes of smart pointers to lv2 resources.
Definition: LV2Utils.h:26
static Settings & settings()
Definition: TrackInfo.cpp:47
Hold values to send to effect output meters.
bool IsGraphicalUI() override
Definition: LV2Editor.cpp:144
wxWeakRef< wxDialog > mDialog
Definition: LV2Editor.h:151
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: LV2Editor.cpp:149
bool mResizing
Definition: LV2Editor.h:146
const LV2Ports & mPorts
Definition: LV2Editor.h:108
void OnIdle(wxIdleEvent &evt)
Definition: LV2Editor.cpp:819
const LilvPlugin & mPlug
Definition: LV2Editor.h:103
LV2PortUIStates mPortUIStates
Definition: LV2Editor.h:111
wxSize mNativeWinLastSize
Definition: LV2Editor.h:145
std::shared_ptr< SuilHost > mSuilHost
Definition: LV2Editor.h:113
const double mSampleRate
Definition: LV2Editor.h:107
void OnChoice(wxCommandEvent &evt)
Definition: LV2Editor.cpp:762
std::vector< PlainUIControl > mPlainUIControls
Array in correspondence with the control ports.
Definition: LV2Editor.h:130
std::unique_ptr< LV2Wrapper > mpWrapper
Definition: LV2Editor.h:109
LV2Instance & mInstance
Definition: LV2Editor.h:105
LV2Editor(const StatelessEffectUIServices &effect, EffectType type, const LilvPlugin &plug, LV2Instance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs, double sampleRate, const LV2FeaturesList &features, const LV2Ports &ports, wxWindow *parent, bool useGUI)
Definition: LV2Editor.cpp:103
static void size_request(GtkWidget *widget, GtkRequisition *requisition, LV2Editor *pEditor)
Definition: LV2Editor.cpp:1015
void OnSlider(wxCommandEvent &evt)
Definition: LV2Editor.cpp:790
~LV2Editor() override
Definition: LV2Editor.cpp:182
LV2Editor::Timer mTimer
wxWindow * mParent
Definition: LV2Editor.h:114
void OnTrigger(wxCommandEvent &evt)
Definition: LV2Editor.cpp:742
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: LV2Editor.cpp:641
bool BuildFancy(std::unique_ptr< LV2Wrapper > pWrapper, const EffectSettings &settings)
Definition: LV2Editor.cpp:203
struct LV2Editor::UI mUI
void OnSize(wxSizeEvent &evt)
Definition: LV2Editor.cpp:889
void OnToggle(wxCommandEvent &evt)
Definition: LV2Editor.cpp:752
void suil_port_write(uint32_t port_index, uint32_t buffer_size, uint32_t protocol, const void *buffer) override
Definition: LV2Editor.cpp:969
void ui_closed() override
Definition: LV2Editor.cpp:963
void UpdateControlPortValue(LV2EffectSettings &settings, size_t controlPortIndex, float value)
Definition: LV2Editor.cpp:722
const EffectOutputs * mpOutputs
Definition: LV2Editor.h:106
void SizeRequest(GtkWidget *widget, GtkRequisition *requisition)
Definition: LV2Editor.cpp:1021
uint32_t suil_port_index(const char *port_symbol) override
Definition: LV2Editor.cpp:998
bool mUseGUI
Definition: LV2Editor.h:115
const EffectType mType
Definition: LV2Editor.h:104
std::optional< const LV2UIFeaturesList > mUIFeatures
Definition: LV2Editor.h:110
bool mExternalUIClosed
Definition: LV2Editor.h:152
void OnText(wxCommandEvent &evt)
Definition: LV2Editor.cpp:773
int ui_resize(int width, int height) override
Definition: LV2Editor.cpp:949
NumericTextCtrl * mDuration
Definition: LV2Editor.h:162
static std::shared_ptr< SuilHost > GetSuilHost()
Definition: LV2Editor.cpp:187
const LV2UI_Show_Interface * mUIShowInterface
Definition: LV2Editor.h:161
const LV2UI_Idle_Interface * mUIIdleInterface
Definition: LV2Editor.h:160
wxSize mNativeWinInitialSize
Definition: LV2Editor.h:144
void SetSlider(const LV2ControlPortState &state, const PlainUIControl &ctrl)
Definition: LV2Editor.cpp:708
bool BuildPlain(EffectSettingsAccess &access)
Definition: LV2Editor.cpp:389
void Disconnect() override
On the first call only, may disconnect from further event handling.
Definition: LV2Editor.cpp:159
bool mResized
Definition: LV2Editor.h:148
UI widget that watches a floating point location and then updates a bar.
Manager of a handle to an LV2 plug-in instantiation.
Definition: LV2Wrapper.h:45
Externalized state of a plug-in.
Other UI related state of an instance of an LV2 Control port.
Definition: LV2Ports.h:237
LV2EffectMeter * meter
Definition: LV2Editor.h:125
This must be destroyed before mSuilInstance.
Definition: LV2Editor.h:155
void Notify() override
Definition: LV2Editor.cpp:813
LV2_External_UI_Widget * mExternalWidget
Definition: LV2Editor.h:156
wxWindowPtr< NativeWindow > mNativeWin
Definition: LV2Editor.h:138
SuilInstancePtr mSuilInstance
Definition: LV2Editor.h:137
bool mJustLeakMemory
Definition: LV2Editor.h:140
void Destroy()
Definition: LV2Editor.cpp:52
Storage locations to be connected to LV2 control ports.
Definition: LV2Ports.h:206
Abstraction of host services that a plug-ins native UI needs.