Audacity 3.2.0
VST3Utils.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file VST3Utils.cpp
6
7 @author Vitaly Sverchinsky
8
9 @brief Part of Audacity VST3 module
10
11**********************************************************************/
12
13
14#include "VST3Utils.h"
15#include "Base64.h"
16
17#include <wx/string.h>
18#include <wx/sizer.h>
19
20#include <pluginterfaces/vst/ivsteditcontroller.h>
21#include <pluginterfaces/vst/ivstparameterchanges.h>
22
23
24wxString VST3Utils::MakePluginPathString(const wxString& modulePath, const std::string& effectUIDString)
25{
26 return wxString::Format("%s;%s", modulePath, effectUIDString);
27}
28
29bool VST3Utils::ParsePluginPath(const wxString& pluginPath, wxString* modulePath,
30 std::string* effectUIDString)
31{
32 const auto sep = pluginPath.Find(';', true);
33 if(sep != wxNOT_FOUND &&
34 //modulePath not empty
35 sep > 0 &&
36 //effectUIDString not empty
37 static_cast<size_t>(sep) < pluginPath.Length() - 1)
38 {
39 if(modulePath != nullptr)
40 *modulePath = pluginPath.Left(sep);
41 if(effectUIDString != nullptr)
42 *effectUIDString = pluginPath.Mid(static_cast<size_t>(sep) + 1);
43 return true;
44 }
45 return false;
46}
47
48wxString VST3Utils::ToWxString(const Steinberg::Vst::TChar* str)
49{
50 static const wxCSConv csConv { wxFONTENCODING_UTF16 };
51 return { reinterpret_cast<const char*>(str), csConv };
52}
53
54wxString VST3Utils::MakeAutomationParameterKey(const Steinberg::Vst::ParameterInfo& parameterInfo)
55{
56 auto suffix = ToWxString(parameterInfo.shortTitle);
57 if(suffix.empty())
58 suffix = ToWxString(parameterInfo.title);
59
60 if(!suffix.empty())
61 return wxString::Format("%lu_", static_cast<unsigned long>(parameterInfo.id)) + suffix;
62
63 return wxString::Format("%lu", static_cast<unsigned long>(parameterInfo.id));
64}
65
66bool VST3Utils::ParseAutomationParameterKey(const wxString& key, Steinberg::Vst::ParamID& paramId)
67{
68 const auto pos = key.Find('_');
69 const auto idStr = pos == wxNOT_FOUND ? key : key.Left(pos);
70 unsigned long value { };
71 if(idStr.ToULong(&value))
72 {
73 paramId = static_cast<Steinberg::Vst::ParamID>(value);
74 return true;
75 }
76 return false;
77
78}
79
80Steinberg::IPtr<PresetsBufferStream> PresetsBufferStream::fromString(const wxString& str)
81{
82 Steinberg::Buffer buffer(str.length() / 4 * 3);
83 const auto numBytes = Base64::Decode(str, buffer);
84 //BufferStream uses fill size as a cursor position and size as a stream end position
85 //To prevent plugins from fetching bytes past the meaningful data we need to truncate
86 //end position
87 buffer.setSize(numBytes);
88
89 auto result = owned(safenew PresetsBufferStream);
90 result->mBuffer.take(buffer);
91 return result;
92}
93
95{
96 auto str = Base64::Encode(mBuffer, mBuffer.getFillSize());
97 return str;
98}
static const AudacityProject::AttachedObjects::RegisteredFactory key
#define str(a)
#define safenew
Definition: MemoryX.h:10
static Steinberg::IPtr< PresetsBufferStream > fromString(const wxString &str)
Definition: VST3Utils.cpp:80
wxString toString() const
Definition: VST3Utils.cpp:94
static wxString MakePluginPathString(const wxString &modulePath, const std::string &effectUIDString)
Definition: VST3Utils.cpp:24
static wxString ToWxString(const Steinberg::Vst::TChar *str)
Definition: VST3Utils.cpp:48
static bool ParseAutomationParameterKey(const wxString &key, Steinberg::Vst::ParamID &paramId)
Definition: VST3Utils.cpp:66
static wxString MakeAutomationParameterKey(const Steinberg::Vst::ParameterInfo &info)
Definition: VST3Utils.cpp:54
static bool ParsePluginPath(const wxString &pluginPath, wxString *modulePath, std::string *effectUIDString)
Definition: VST3Utils.cpp:29
STRINGS_API wxString Encode(const void *in, int len)
Definition: Base64.cpp:27
STRINGS_API int Decode(const wxString &in, void *out)
Definition: Base64.cpp:67