Audacity 3.2.0
LV2Wrapper.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file LV2Wrapper.h
6 @brief manager for a handle to an lv2 plug-in instance and request and
7 response queues for inter-thread work scheduling
8
9 Paul Licameli split from LV2Effect.h
10
11 Audacity(R) is copyright (c) 1999-2013 Audacity Team.
12 License: GPL v2 or later. See License.txt.
13
14*********************************************************************/
15
16#ifndef __AUDACITY_LV2_WRAPPER__
17#define __AUDACITY_LV2_WRAPPER__
18
19#if USE_LV2
20
21#include "LV2Utils.h"
23
24#include "lilv/lilv.h"
25#include "lv2/core/attributes.h"
26#include "lv2/options/options.h"
27#include "lv2/state/state.h"
28#include "lv2/worker/worker.h"
29
30#include <thread>
31#include <wx/msgqueue.h>
32
33struct EffectOutputs;
35class LV2Ports;
36class LV2PortStates;
38
39// We use deprecated LV2 interfaces to remain compatible with older
40// plug-ins, so disable warnings
41LV2_DISABLE_DEPRECATION_WARNINGS
42
44class LV2_API LV2Wrapper final
45{
47 struct CreateToken{};
48public:
49 struct LV2Work {
50 uint32_t size{};
51 const void *data{};
52 };
53
54public:
56 static std::unique_ptr<LV2Wrapper> Create(
57 LV2InstanceFeaturesList &baseFeatures,
58 const LV2Ports &ports, LV2PortStates &portStates,
60 EffectOutputs *pOutputs);
61
63 LV2Wrapper(CreateToken&&,
64 LV2InstanceFeaturesList &baseFeatures,
65 const LilvPlugin &plugin, float sampleRate);
66
69
70 void ConnectControlPorts(const LV2Ports &ports,
71 const LV2EffectSettings &settings, EffectOutputs *pOutputs);
72 void ConnectPorts(const LV2Ports &ports,
73 LV2PortStates &portStates, const LV2EffectSettings &settings,
74 EffectOutputs *pOutputs);
75 void Activate();
76 void Deactivate();
77 LilvInstance &GetInstance() const;
78 LV2_Handle GetHandle() const;
79 float GetLatency() const;
80 void SetFreeWheeling(bool enable);
81 void SendBlockSize();
82 void ConsumeResponses();
83 static LV2_Worker_Status schedule_work(LV2_Worker_Schedule_Handle handle,
84 uint32_t size,
85 const void *data);
86 LV2_Worker_Status ScheduleWork(uint32_t size, const void *data);
87 static LV2_Worker_Status respond(LV2_Worker_Respond_Handle handle,
88 uint32_t size,
89 const void *data);
90 LV2_Worker_Status Respond(uint32_t size, const void *data);
91
92 LV2WrapperFeaturesList &GetFeatures() { return mFeaturesList; }
93 const LV2WrapperFeaturesList &GetFeatures() const { return mFeaturesList; }
94
95private:
96 void ThreadFunction();
97
98 // Another object with an explicit virtual function table
99 LV2_Worker_Schedule mWorkerSchedule{ this, LV2Wrapper::schedule_work };
100
102
105 const LV2_Handle mHandle;
106
107 // Pointers to extension interfaces that the foreign plug-in instance
108 // may expose:
109 // Options extension
110 const LV2_Options_Interface *const mOptionsInterface;
111 // State extension
112 const LV2_State_Interface *const mStateInterface;
113 // Worker extension
114 const LV2_Worker_Interface *const mWorkerInterface;
115
116 std::thread mThread;
117 wxMessageQueue<LV2Work> mRequests;
118 wxMessageQueue<LV2Work> mResponses;
119 float mLatency{ 0.0 };
120
122 bool mFreeWheeling{ false };
123
126 bool mStopWorker{ false };
127 bool mActivated{ false };
128};
129
130#endif
131#endif
RAII for lv2 resources.
std::unique_ptr< Type, Lilv_deleter< Type, f > > Lilv_ptr
Generate classes of smart pointers to lv2 resources.
Definition: LV2Utils.h:26
Lilv_ptr< LilvInstance, lilv_instance_free > LilvInstancePtr
Definition: LV2Wrapper.h:37
static Settings & settings()
Definition: TrackInfo.cpp:69
Hold values to send to effect output meters.
Manager of a handle to an LV2 plug-in instantiation.
Definition: LV2Wrapper.h:45
std::thread mThread
Definition: LV2Wrapper.h:116
const LV2_Handle mHandle
Definition: LV2Wrapper.h:105
const LV2_State_Interface *const mStateInterface
Definition: LV2Wrapper.h:112
const LilvInstancePtr mInstance
Definition: LV2Wrapper.h:104
const LV2WrapperFeaturesList & GetFeatures() const
Definition: LV2Wrapper.h:93
wxMessageQueue< LV2Work > mRequests
Definition: LV2Wrapper.h:117
const LV2_Options_Interface *const mOptionsInterface
Definition: LV2Wrapper.h:110
LV2WrapperFeaturesList & GetFeatures()
Definition: LV2Wrapper.h:92
static LV2_Worker_Status schedule_work(LV2_Worker_Schedule_Handle handle, uint32_t size, const void *data)
Definition: LV2Wrapper.cpp:238
LV2WrapperFeaturesList mFeaturesList
Definition: LV2Wrapper.h:101
const LV2_Worker_Interface *const mWorkerInterface
Definition: LV2Wrapper.h:114
wxMessageQueue< LV2Work > mResponses
Definition: LV2Wrapper.h:118
FrameStatistics & GetInstance() noexcept
Storage locations to be connected to LV2 control ports.
Definition: LV2Ports.h:206
To compel use of the factory.
Definition: LV2Wrapper.h:47