Audacity  2.2.0
LV2Effect.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LV2Effect.h
6 
7  Audacity(R) is copyright (c) 1999-2013 Audacity Team.
8  License: GPL v2. See License.txt.
9 
10 *********************************************************************/
11 
12 #include "../../Audacity.h"
13 
14 #if USE_LV2
15 
16 #include "../../MemoryX.h"
17 #include <vector>
18 #include <wx/checkbox.h>
19 #include <wx/dialog.h>
20 #include <wx/dynarray.h>
21 #include <wx/event.h>
22 #include <wx/slider.h>
23 #include <wx/stattext.h>
24 #include <wx/string.h>
25 #include <wx/textctrl.h>
26 
27 #include "lv2/lv2plug.in/ns/ext/atom/forge.h"
28 #include "lv2/lv2plug.in/ns/ext/data-access/data-access.h"
29 #include "lv2/lv2plug.in/ns/ext/options/options.h"
30 #include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h"
31 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
32 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
33 
34 #include <lilv/lilv.h>
35 #include <suil/suil.h>
36 
37 #include "../../SampleFormat.h"
38 #include "../../widgets/NumericTextCtrl.h"
39 
40 #include "LoadLV2.h"
41 
42 #define LV2EFFECTS_VERSION wxT("1.0.0.0")
43 #define LV2EFFECTS_FAMILY wxT("LV2")
44 
46 class LV2Port
47 {
48 public:
49  LV2Port()
50  {
51  mInput = false;
52  mToggle = false;
53  mTrigger = false;
54  mInteger = false;
55  mSampleRate = false;
56  mEnumeration = false;
57  mLogarithmic = false;
58  mHasLo = false;
59  mHasHi = false;
60  }
61 
62  uint32_t mIndex;
63  wxString mSymbol;
64  wxString mName;
65  wxString mGroup;
66  wxString mUnits;
67  float mMin;
68  float mMax;
69  float mDef;
70  float mVal;
71  float mTmp;
72  float mLo;
73  float mHi;
74  bool mHasLo;
75  bool mHasHi;
76  bool mInput;
77  bool mToggle;
78  bool mTrigger;
79  bool mInteger;
80  bool mSampleRate;
81  bool mEnumeration;
82  bool mLogarithmic;
83 
84  LilvPort *mPort;
85 
86  // ScalePoints
87  wxArrayDouble mScaleValues;
88  wxArrayString mScaleLabels;
89 };
90 
91 WX_DECLARE_OBJARRAY(LV2Port, LV2PortArray);
92 WX_DECLARE_STRING_HASH_MAP(wxArrayInt, LV2GroupMap);
93 WX_DEFINE_ARRAY_PTR(LilvInstance *, LV2SlaveArray);
94 
95 class LV2EffectSettingsDialog;
96 
97 class LV2Effect final : public wxEvtHandler,
98  public EffectClientInterface,
99  public EffectUIClientInterface
100 {
101 public:
102  LV2Effect(const LilvPlugin *plug);
103  virtual ~LV2Effect();
104 
105  // IdentInterface implementation
106 
107  wxString GetPath() override;
108  wxString GetSymbol() override;
109  wxString GetName() override;
110  wxString GetVendor() override;
111  wxString GetVersion() override;
112  wxString GetDescription() override;
113 
114  // EffectIdentInterface implementation
115 
116  EffectType GetType() override;
117  wxString GetFamily() override;
118  bool IsInteractive() override;
119  bool IsDefault() override;
120  bool IsLegacy() override;
121  bool SupportsRealtime() override;
122  bool SupportsAutomation() override;
123 
124  // EffectClientInterface implementation
125 
126  bool SetHost(EffectHostInterface *host) override;
127 
128  unsigned GetAudioInCount() override;
129  unsigned GetAudioOutCount() override;
130 
131  int GetMidiInCount() override;
132  int GetMidiOutCount() override;
133 
134  void SetSampleRate(double rate) override;
135  size_t SetBlockSize(size_t maxBlockSize) override;
136 
137  sampleCount GetLatency() override;
138  size_t GetTailSize() override;
139 
140  bool IsReady() override;
141  bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap = NULL) override;
142  bool ProcessFinalize() override;
143  size_t ProcessBlock(float **inbuf, float **outbuf, size_t size) override;
144 
145  bool RealtimeInitialize() override;
146  bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override;
147  bool RealtimeFinalize() override;
148  bool RealtimeSuspend() override;
149  bool RealtimeResume() override;
150  bool RealtimeProcessStart() override;
151  size_t RealtimeProcess(int group,
152  float **inbuf,
153  float **outbuf,
154  size_t numSamples) override;
155  bool RealtimeProcessEnd() override;
156 
157  bool ShowInterface(wxWindow *parent, bool forceModal = false) override;
158 
159  bool GetAutomationParameters(EffectAutomationParameters & parms) override;
160  bool SetAutomationParameters(EffectAutomationParameters & parms) override;
161 
162  // EffectUIClientInterface implementation
163 
164  void SetHostUI(EffectUIHostInterface *host) override;
165  bool PopulateUI(wxWindow *parent) override;
166  bool IsGraphicalUI() override;
167  bool ValidateUI() override;
168  bool HideUI() override;
169  bool CloseUI() override;
170 
171  bool LoadUserPreset(const wxString & name) override;
172  bool SaveUserPreset(const wxString & name) override;
173 
174  wxArrayString GetFactoryPresets() override;
175  bool LoadFactoryPreset(int id) override;
176  bool LoadFactoryDefaults() override;
177 
178  bool CanExportPresets() override;
179  void ExportPresets() override;
180  void ImportPresets() override;
181 
182  bool HasOptions() override;
183  void ShowOptions() override;
184 
185  // LV2Effect implementation
186 
187 private:
188  bool Load();
189  void Unload();
190 
191  bool LoadParameters(const wxString & group);
192  bool SaveParameters(const wxString & group);
193 
194  LilvInstance *InitInstance(float sampleRate);
195  void FreeInstance(LilvInstance *handle);
196 
197  static uint32_t uri_to_id(LV2_URI_Map_Callback_Data callback_data,
198  const char *map,
199  const char *uri);
200 
201  static LV2_URID urid_map(LV2_URID_Map_Handle handle, const char *uri);
202  LV2_URID URID_Map(const char *uri);
203 
204  static const char *urid_unmap(LV2_URID_Unmap_Handle handle, LV2_URID urid);
205  const char *URID_Unmap(LV2_URID urid);
206 
207  static int ui_resize(LV2UI_Feature_Handle handle, int width, int height);
208  int UIResize(int width, int height);
209 
210  size_t AddOption(const char *key, uint32_t size, const char *type, void *value);
211  LV2_Feature *AddFeature(const char *uri, void *data);
212 
213  bool BuildFancy();
214  bool BuildPlain();
215 
216  bool TransferDataToWindow();
217  bool TransferDataFromWindow();
218  void SetSlider(wxSlider *slider, const LV2Port & ctrl);
219 
220  void OnTrigger(wxCommandEvent & evt);
221  void OnToggle(wxCommandEvent & evt);
222  void OnChoice(wxCommandEvent & evt);
223  void OnText(wxCommandEvent & evt);
224  void OnSlider(wxCommandEvent & evt);
225 
226  void OnIdle(wxIdleEvent & evt);
227 
228  static void suil_write_func(SuilController controller,
229  uint32_t port_index,
230  uint32_t buffer_size,
231  uint32_t protocol,
232  const void *buffer);
233 
234  void UIWrite(uint32_t port_index,
235  uint32_t buffer_size,
236  uint32_t protocol,
237  const void *buffer);
238 
239  static void set_value_func(const char *port_symbol,
240  void *user_data,
241  const void *value,
242  uint32_t size,
243  uint32_t type);
244 
245  void SetPortValue(const char *port_symbol,
246  const void *value,
247  uint32_t size,
248  uint32_t type);
249 
250 private:
251  // Declare the static URI nodes
252  #undef URI
253  #define URI(n, u) static LilvNode *n;
254  URILIST
255 
256  const LilvPlugin *mPlug;
257 
258  EffectHostInterface *mHost;
259 
260  size_t mBlockSize;
261  double mSampleRate;
262 
263  wxLongToLongHashMap mControlsMap;
264  LV2PortArray mControls;
265  wxArrayInt mAudioInputs;
266  wxArrayInt mAudioOutputs;
267 
268  LV2GroupMap mGroupMap;
269  wxArrayString mGroups;
270 
271  bool mUseLatency;
272  int mLatencyPort;
273  bool mLatencyDone;
274  float mLatency;
275 
276  LilvInstance *mMaster;
277  LilvInstance *mProcess;
278  LV2SlaveArray mSlaves;
279 
280  FloatBuffers mMasterIn, mMasterOut;
281  size_t mNumSamples;
282 
283  double mLength;
284 
285  wxDialog *mDialog;
286  wxWindow *mParent;
287  EffectUIHostInterface *mUIHost;
288 
289  bool mUseGUI;
290 
291  std::vector< movable_ptr_with_deleter<char, freer> > mURIMap;
292 
293  LV2_URI_Map_Feature mUriMapFeature;
294  LV2_URID_Map mURIDMapFeature;
295  LV2_URID_Unmap mURIDUnmapFeature;
296  LV2UI_Resize mUIResizeFeature;
297  LV2_Extension_Data_Feature mExtDataFeature;
298 
299  size_t mBlockSizeOption;
300  size_t mSampleRateOption;
301 
302  LV2_Options_Interface *mOptionsInterface;
303  std::vector<LV2_Options_Option> mOptions;
304 
305  std::vector<movable_ptr<LV2_Feature>> mFeatures;
306 
307  LV2_Feature *mInstanceAccessFeature;
308  LV2_Feature *mParentFeature;
309 
310  const LV2UI_Idle_Interface *mIdleFeature;
311 
312  SuilHost *mSuilHost;
313  SuilInstance *mSuilInstance;
314 
315  NumericTextCtrl *mDuration;
316  ArrayOf<wxSlider*> mSliders;
317  ArrayOf<wxTextCtrl*> mFields;
318 
319  bool mFactoryPresetsLoaded;
320  wxArrayString mFactoryPresetNames;
321  wxArrayString mFactoryPresetUris;
322 
323  DECLARE_EVENT_TABLE()
324 
325  friend class LV2EffectSettingsDialog;
326  friend class LV2EffectsModule;
327 };
328 
329 inline wxString LilvString(const LilvNode *node)
330 {
331  return wxString::FromUTF8(lilv_node_as_string(node));
332 };
333 
334 inline wxString LilvString(LilvNode *node, bool free)
335 {
336  wxString str = LilvString(node);
337  if (free)
338  {
339  lilv_node_free(node);
340  }
341 
342  return str;
343 };
344 
345 
346 #endif
#define URILIST
Definition: LoadLV2.h:38
void OnToggle()
WX_DECLARE_OBJARRAY(AutoDuckRegion, AutoDuckRegionArray)
Definition: NumericTextCtrl.h:141
const wxChar * name
Definition: Distortion.cpp:94
WX_DECLARE_STRING_HASH_MAP(wxString, LangHash)
Definition: LoadLV2.h:71
WX_DEFINE_ARRAY_PTR(LADSPA_Handle, LadspaSlaveArray)