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