Audacity 3.2.0
LV2Effect.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LV2Effect.cpp
6
7 Audacity(R) is copyright (c) 1999-2008 Audacity Team.
8 License: GPL v2 or later. See License.txt.
9
10**********************************************************************/
11
12#if defined(USE_LV2)
13
14#if defined(__GNUC__)
15#pragma GCC diagnostic ignored "-Wparentheses"
16#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
17#elif defined(__clang__)
18#pragma clang diagnostic ignored "-Wparentheses"
19#pragma clang diagnostic ignored "-Wdeprecated-declarations"
20#endif
21
22#include "LV2Effect.h"
23#include "LoadLV2.h"
24#include "LV2Instance.h"
25#include "LV2Editor.h"
27#include "LV2Wrapper.h"
28
29#include <cmath>
30#include <exception>
31#include <functional>
32
33
34#ifdef __WXMAC__
35#include <wx/evtloop.h>
36#endif
37
38#include "AudacityMessageBox.h"
39
40#if defined(__WXGTK__)
41#include <gtk/gtk.h>
42#endif
43
44#if defined(__WXMSW__)
45#include <wx/msw/wrapwin.h>
46#endif
47
48LV2Effect::~LV2Effect() = default;
49
50int LV2Effect::ShowClientInterface(const EffectPlugin &, wxWindow &parent,
51 wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const
52{
53 if (pEditor)
54 // Remember the dialog with a weak pointer, but don't control its lifetime
55 static_cast<LV2Editor*>(pEditor)->mDialog = &dialog;
56 // Try to give the window a sensible default/minimum size
57 dialog.Layout();
58 dialog.Fit();
59 dialog.SetMinSize(dialog.GetSize());
61 dialog.SetMaxSize(dialog.GetSize());
62 if ((SupportsRealtime() || GetType() == EffectTypeAnalyze) && !forceModal) {
63 dialog.Show();
64 return 0;
65 }
66 return dialog.ShowModal();
67}
68
69// May come here before destructive processing
70// Or maybe not (if you "Repeat Last Effect")
71std::unique_ptr<EffectEditor> LV2Effect::PopulateUI(const EffectPlugin &,
73 const EffectOutputs *pOutputs) const
74{
75 auto &settings = access.Get();
76 auto parent = S.GetParent();
77
78 auto &myInstance = dynamic_cast<LV2Instance &>(instance);
79 auto pWrapper =
80 // Output port connection isn't needed for fancy UI wrapper. Its
81 // features are needed to make the suil_instance
82 myInstance.MakeWrapper(settings, mProjectRate, nullptr);
83 if (!pWrapper) {
84 AudacityMessageBox( XO("Couldn't instantiate effect") );
85 return nullptr;
86 }
87
88 // Determine if the GUI editor is supposed to be used or not
89 bool useGUI = false;
90 LV2Preferences::GetUseGUI(*this, useGUI);
91
92 // Until I figure out where to put the "Duration" control in the
93 // graphical editor, force usage of plain editor.
95 useGUI = false;
96
97 auto result = std::make_unique<LV2Editor>(*this, GetType(), mPlug,
98 dynamic_cast<LV2Instance&>(instance),
99 access, pOutputs, mProjectRate, mFeatures, mPorts, parent, useGUI);
100
101#ifdef __WXMAC__
102 const auto vendor = GetVendor().Msgid().Translation();
103 const bool doX42Hack = vendor == "Robin Gareus";
104 result->mUI.mJustLeakMemory = doX42Hack;
105#endif
106
107 if (result->mUseGUI)
108 result->mUseGUI = result->BuildFancy(move(pWrapper), settings);
109 if (!result->mUseGUI && !result->BuildPlain(access))
110 return nullptr;
111 result->UpdateUI();
112
113 return result;
114}
115
116std::unique_ptr<EffectEditor> LV2Effect::MakeEditor(
118 const EffectOutputs *) const
119{
121 assert(false);
122 return nullptr;
123}
124
126{
127#ifdef __WXMAC__
128#ifdef __WX_EVTLOOP_BUSY_WAITING__
129 wxEventLoop::SetBusyWaiting(false);
130#endif
131#endif
132
133 return true;
134}
135
137 const EffectPlugin &, const EffectSettings &) const
138{
139}
140
142 const EffectPlugin &, EffectSettings &) const
143{
144 return { nullptr };
145}
146
148{
149 LV2PreferencesDialog{ *this }.ShowModal();
150}
151
152// Inject factory hook to make LV2Effect capable of UI
153static LV2EffectsModule::Factory::SubstituteInUnique<LV2Effect> scope;
154
155#endif
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
@ EffectTypeAnalyze
@ EffectTypeGenerate
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
XO("Cut/Copy/Paste")
static LV2EffectsModule::Factory::SubstituteInUnique< LV2Effect > scope
Definition: LV2Effect.cpp:153
Defines the module to handle the LV2 effect protocol.
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:69
const TranslatableString & Msgid() const
double mProjectRate
Definition: EffectBase.h:112
Performs effect computation.
Hold values to send to effect output meters.
Factory of instances of an effect.
Definition: EffectPlugin.h:36
virtual const EffectSettings & Get()=0
VendorSymbol GetVendor() const override
const LV2Ports mPorts
Definition: LV2EffectBase.h:90
EffectType GetType() const override
Type determines how it behaves.
const LV2FeaturesList mFeatures
Definition: LV2EffectBase.h:88
const LilvPlugin & mPlug
Definition: LV2EffectBase.h:87
void ExportPresets(const EffectPlugin &plugin, const EffectSettings &settings) const override
Definition: LV2Effect.cpp:136
~LV2Effect() override
virtual std::unique_ptr< EffectEditor > MakeEditor(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const final
Will never be called.
Definition: LV2Effect.cpp:116
std::unique_ptr< EffectEditor > PopulateUI(const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
Adds controls to a panel that is given as the parent window of S
Definition: LV2Effect.cpp:71
int ShowClientInterface(const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
Definition: LV2Effect.cpp:50
void ShowOptions(const EffectPlugin &plugin) const override
Definition: LV2Effect.cpp:147
OptionalMessage ImportPresets(const EffectPlugin &plugin, EffectSettings &settings) const override
Definition: LV2Effect.cpp:141
bool CloseUI() const override
Definition: LV2Effect.cpp:125
std::unique_ptr< LV2Wrapper > MakeWrapper(const EffectSettings &settings, double sampleRate, EffectOutputs *pOutputs)
Definition: LV2Instance.cpp:59
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
wxString Translation() const
LV2_API bool GetUseGUI(const EffectDefinitionInterface &effect, bool &useGUI)
Externalized state of a plug-in.