Audacity 3.2.0
AudacityVst3HostApplication.cpp
Go to the documentation of this file.
2
3#include <pluginterfaces/vst/ivstaudioprocessor.h>
4#include <pluginterfaces/vst/ivstcomponent.h>
5#include <pluginterfaces/vst/ivsteditcontroller.h>
6#include <public.sdk/source/vst/hosting/hostclasses.h>
7#include <public.sdk/source/vst/utility/stringconvert.h>
8
9#include <algorithm>
10#include <memory>
11#include <string>
12#include <pluginterfaces/vst/ivstunits.h>
13
14using namespace Steinberg;
15using namespace Steinberg::Vst;
16
17// This class was copied from VST3 SDK 3.7.3 hostclasses.h
19{
20public:
21 enum Type
22 {
27 };
28
29 explicit AudacityHostAttribute(int64 value)
30 : size(0)
31 , type(kInteger)
32 {
33 v.intValue = value;
34 }
35
36 explicit AudacityHostAttribute(double value)
37 : size(0)
38 , type(kFloat)
39 {
40 v.floatValue = value;
41 }
43 explicit AudacityHostAttribute(const TChar* value, uint32 sizeInCodeUnit)
44 : size(sizeInCodeUnit)
45 , type(kString)
46 {
47 v.stringValue = new TChar[sizeInCodeUnit];
48 memcpy(v.stringValue, value, sizeInCodeUnit * sizeof(TChar));
49 }
50
51 explicit AudacityHostAttribute(const void* value, uint32 sizeInBytes)
52 : size(sizeInBytes)
53 , type(kBinary)
54 {
55 v.binaryValue = new char[sizeInBytes];
56 memcpy(v.binaryValue, value, sizeInBytes);
57 }
58
60 {
61 if (size)
62 delete[] v.binaryValue;
63 }
64
65 int64 intValue() const
66 {
67 return v.intValue;
68 }
69
70 double floatValue() const
71 {
72 return v.floatValue;
73 }
75 const TChar* stringValue(uint32& sizeInCodeUnit)
76 {
77 sizeInCodeUnit = size;
78 return v.stringValue;
79 }
80 const void* binaryValue(uint32& sizeInBytes)
81 {
82 sizeInBytes = size;
83 return v.binaryValue;
84 }
85
86 Type getType() const
87 {
88 return type;
89 }
90
91protected:
92 union v
93 {
94 int64 intValue;
95 double floatValue;
98 } v;
99 uint32 size;
101};
102// This class was copied from VST3 SDK 3.7.3 hostclasses.h
103class AudacityHostAttributeList : public IAttributeList
104{
105public:
107 {
108 FUNKNOWN_CTOR
109 }
110
111 virtual ~AudacityHostAttributeList() { FUNKNOWN_DTOR }
112
113 tresult PLUGIN_API setInt(AttrID aid, int64 value) SMTG_OVERRIDE
114 {
115 if (!aid)
116 return kInvalidArgument;
117 removeAttrID(aid);
118 list[aid] = std::make_unique<AudacityHostAttribute>(value);
119 return kResultTrue;
120 }
121
122 tresult PLUGIN_API getInt(AttrID aid, int64& value) SMTG_OVERRIDE
123 {
124 if (!aid)
125 return kInvalidArgument;
126 auto it = list.find(aid);
127 if (it != list.end() && it->second)
128 {
129 value = it->second->intValue();
130 return kResultTrue;
131 }
132 return kResultFalse;
133 }
134
135 tresult PLUGIN_API setFloat(AttrID aid, double value) SMTG_OVERRIDE
136 {
137 if (!aid)
138 return kInvalidArgument;
139 removeAttrID(aid);
140 list[aid] = std::make_unique<AudacityHostAttribute>(value);
141 return kResultTrue;
142 }
143
144 tresult PLUGIN_API getFloat(AttrID aid, double& value) SMTG_OVERRIDE
145 {
146 if (!aid)
147 return kInvalidArgument;
148 auto it = list.find(aid);
149 if (it != list.end() && it->second)
150 {
151 value = it->second->floatValue();
152 return kResultTrue;
153 }
154 return kResultFalse;
155 }
156
157 tresult PLUGIN_API setString(AttrID aid, const TChar* string) SMTG_OVERRIDE
158 {
159 if (!aid)
160 return kInvalidArgument;
161 removeAttrID(aid);
162 // + 1 for the null-terminate
163 auto length = tstrlen(string);
164 list[aid] = std::make_unique<AudacityHostAttribute>(string, length + 1);
165 return kResultTrue;
166 }
167
168 tresult PLUGIN_API getString(AttrID aid, TChar* string, uint32 sizeInBytes)
169 SMTG_OVERRIDE
170 {
171 if (!aid)
172 return kInvalidArgument;
173
174 auto it = list.find(aid);
175 if (it != list.end() && it->second)
176 {
177 uint32 sizeInCodeUnit = 0;
178 const TChar* _string = it->second->stringValue(sizeInCodeUnit);
179 memcpy(
180 string, _string,
181 std::min<uint32>(sizeInCodeUnit * sizeof(TChar), sizeInBytes));
182 return kResultTrue;
183 }
184
185 return kResultFalse;
186 }
187
188 tresult PLUGIN_API
189 setBinary(AttrID aid, const void* data, uint32 sizeInBytes) SMTG_OVERRIDE
190 {
191 if (!aid)
192 return kInvalidArgument;
193 removeAttrID(aid);
194 list[aid] = std::make_unique<AudacityHostAttribute>(data, sizeInBytes);
195 return kResultTrue;
196 }
197
198 tresult PLUGIN_API
199 getBinary(AttrID aid, const void*& data, uint32& sizeInBytes) SMTG_OVERRIDE
200 {
201 if (!aid)
202 return kInvalidArgument;
203 auto it = list.find(aid);
204 if (it != list.end() && it->second)
205 {
206 data = it->second->binaryValue(sizeInBytes);
207 return kResultTrue;
208 }
209 sizeInBytes = 0;
210 return kResultFalse;
211 }
212
213 DECLARE_FUNKNOWN_METHODS
214protected:
216 {
217 if (!aid)
218 return;
219
220 auto it = list.find(aid);
221 if (it != list.end())
222 list.erase(it);
223 }
224
225 std::map<std::string, std::unique_ptr<AudacityHostAttribute>> list;
226};
227
229 AudacityHostAttributeList, IAttributeList, IAttributeList::iid)
230
231class AudacityHostMessage : public IMessage
232{
233public:
234 AudacityHostMessage()
235 {
236 FUNKNOWN_CTOR
237 }
238
239 virtual ~AudacityHostMessage()
240 {
241 FUNKNOWN_DTOR
242 }
243
244 const char* PLUGIN_API getMessageID() SMTG_OVERRIDE
245 {
246 return mMessageId.c_str();
247 }
248
249 void PLUGIN_API setMessageID(const char* messageID) SMTG_OVERRIDE
250 {
251 if (messageID != nullptr)
252 mMessageId = messageID;
253 else
254 mMessageId.clear();
255 }
256
257 IAttributeList* PLUGIN_API getAttributes() SMTG_OVERRIDE
258 {
259 if (!mAattributeList)
260 mAattributeList = safenew AudacityHostAttributeList;
261
262 return mAattributeList.get();
263 }
264
265 DECLARE_FUNKNOWN_METHODS
266protected:
267 std::string mMessageId;
268 IPtr<AudacityHostAttributeList> mAattributeList;
269};
270
271IMPLEMENT_FUNKNOWN_METHODS(AudacityHostMessage, IMessage, IMessage::iid)
272
274
276
277Steinberg::Vst::IHostApplication& AudacityVst3HostApplication::Get()
278{
279 static AudacityVst3HostApplication instance;
280 return instance;
281}
282
283Steinberg::tresult PLUGIN_API
284AudacityVst3HostApplication::queryInterface(const char* _iid, void** obj)
285{
286 QUERY_INTERFACE(_iid, obj, FUnknown::iid, IHostApplication)
287 QUERY_INTERFACE(_iid, obj, IHostApplication::iid, IHostApplication)
288 QUERY_INTERFACE(_iid, obj, IPlugInterfaceSupport::iid, IPlugInterfaceSupport)
289
290 *obj = nullptr;
291 return Steinberg::kResultFalse;
292}
293
294Steinberg::uint32 PLUGIN_API AudacityVst3HostApplication::addRef()
295{
296 return 1;
297}
298
299Steinberg::uint32 PLUGIN_API AudacityVst3HostApplication::release()
300{
301 return 1;
302}
303
304Steinberg::tresult PLUGIN_API
306{
307 return VST3::StringConvert::convert("Audacity VST3 host application", name) ?
308 Steinberg::kResultTrue :
309 Steinberg::kInternalError;
310}
311
313 Steinberg::TUID cid, Steinberg::TUID _iid, void** obj)
314{
315 using namespace Steinberg;
316
317 FUID classID(FUID::fromTUID(cid));
318 FUID interfaceID(FUID::fromTUID(_iid));
319 if (classID == Vst::IMessage::iid && interfaceID == Vst::IMessage::iid)
320 {
321 *obj = safenew AudacityHostMessage;
322 return kResultTrue;
323 }
324 else if (
325 classID == Vst::IAttributeList::iid &&
326 interfaceID == Vst::IAttributeList::iid)
327 {
329 return kResultTrue;
330 }
331 *obj = nullptr;
332 return kResultFalse;
333}
334
336 const Steinberg::TUID _iid)
337{
338 static auto supportedInterfaces = {
339 Steinberg::Vst::IComponent::iid,
340 Steinberg::Vst::IAudioProcessor::iid,
341 Steinberg::Vst::IEditController::iid,
342 Steinberg::Vst::IConnectionPoint::iid,
343 Steinberg::Vst::IUnitInfo::iid
344 };
345
346 auto uid = Steinberg::FUID::fromTUID(_iid);
347 if (
348 std::find(supportedInterfaces.begin(), supportedInterfaces.end(), uid) !=
349 supportedInterfaces.end())
350 return Steinberg::kResultTrue;
351 return Steinberg::kResultFalse;
352}
#define safenew
Definition: MemoryX.h:10
IMPLEMENT_FUNKNOWN_METHODS(RunLoop, Steinberg::Linux::IRunLoop, Steinberg::Linux::IRunLoop::iid)
wxString name
Definition: TagsEditor.cpp:166
union AudacityHostAttribute::v v
AudacityHostAttribute(const void *value, uint32 sizeInBytes)
const void * binaryValue(uint32 &sizeInBytes)
const TChar * stringValue(uint32 &sizeInCodeUnit)
AudacityHostAttribute(const TChar *value, uint32 sizeInCodeUnit)
std::map< std::string, std::unique_ptr< AudacityHostAttribute > > list
tresult PLUGIN_API getBinary(AttrID aid, const void *&data, uint32 &sizeInBytes) SMTG_OVERRIDE
tresult PLUGIN_API getInt(AttrID aid, int64 &value) SMTG_OVERRIDE
tresult PLUGIN_API getString(AttrID aid, TChar *string, uint32 sizeInBytes) SMTG_OVERRIDE
tresult PLUGIN_API setInt(AttrID aid, int64 value) SMTG_OVERRIDE
tresult PLUGIN_API getFloat(AttrID aid, double &value) SMTG_OVERRIDE
tresult PLUGIN_API setBinary(AttrID aid, const void *data, uint32 sizeInBytes) SMTG_OVERRIDE
tresult PLUGIN_API setString(AttrID aid, const TChar *string) SMTG_OVERRIDE
tresult PLUGIN_API setFloat(AttrID aid, double value) SMTG_OVERRIDE
Steinberg::tresult PLUGIN_API isPlugInterfaceSupported(const Steinberg::TUID _iid) override
DECLARE_FUNKNOWN_METHODS AudacityVst3HostApplication()
Steinberg::tresult PLUGIN_API getName(Steinberg::Vst::String128 name) override
Steinberg::tresult PLUGIN_API createInstance(Steinberg::TUID cid, Steinberg::TUID _iid, void **obj) override