Loading...
Searching...
No Matches
score-plugin-vst3/Vst3/ApplicationPlugin.hpp
1#pragma once
2#include <Vst3/Plugin.hpp>
3
4#include <score/plugins/application/GUIApplicationPlugin.hpp>
5
6#include <ossia/detail/fmt.hpp>
7#include <ossia/detail/string_map.hpp>
8
9#include <QElapsedTimer>
10#include <QProcess>
11#include <QWebSocketServer>
12
13#include <base/source/fstring.h>
14#include <pluginterfaces/vst/ivstmessage.h>
15
16#include <memory>
17#include <stdexcept>
18
19namespace vst3
20{
22{
23 QString path;
24 QString name;
25 QString url;
26 std::vector<VST3::Hosting::ClassInfo> classInfo;
27
28 bool isValid{};
29};
30
31struct HostApp final : public Steinberg::Vst::IHostApplication
32{
33 Steinberg::Vst::PlugInterfaceSupport m_support;
34 HostApp() { }
35 virtual ~HostApp() { }
36 Steinberg::tresult getName(Steinberg::Vst::String128 name) override
37 {
38 Steinberg::String str("ossia score");
39 str.copyTo16(name, 0, 127);
40 return Steinberg::kResultTrue;
41 }
42
43 Steinberg::tresult
44 createInstance(Steinberg::TUID cid, Steinberg::TUID _iid, void** obj) override
45 {
46 using namespace Steinberg;
47 using namespace Steinberg::Vst;
48 FUID classID(FUID::fromTUID(cid));
49 FUID interfaceID(FUID::fromTUID(_iid));
50 if(classID == Vst::IMessage::iid && interfaceID == Vst::IMessage::iid)
51 {
52 *obj = new HostMessage;
53 return kResultTrue;
54 }
55 else if(
56 classID == Vst::IAttributeList::iid && interfaceID == Vst::IAttributeList::iid)
57 {
58 *obj = Vst::HostAttributeList::make();
59 return kResultTrue;
60 }
61 *obj = nullptr;
62 return kResultFalse;
63 }
64
65 Steinberg::tresult queryInterface(const char* _iid, void** obj) override
66 {
67 using namespace Steinberg;
68 using namespace Steinberg::Vst;
69 QUERY_INTERFACE(_iid, obj, FUnknown::iid, IHostApplication)
70 QUERY_INTERFACE(_iid, obj, IHostApplication::iid, IHostApplication)
71
72 if(m_support.isPlugInterfaceSupported(_iid) == kResultTrue)
73 return kResultOk;
74
75 *obj = nullptr;
76 return kResultFalse;
77 }
78
79 Steinberg::uint32 addRef() override { return 1; }
80
81 Steinberg::uint32 release() override { return 1; }
82};
83
85 : public QObject
87{
88 W_OBJECT(ApplicationPlugin)
89public:
91
92 void initialize() override;
93
94 VST3::Hosting::Module::Ptr getModule(const std::string& path);
95
96 void rescan();
97 void rescan(const QStringList& paths);
98 void vstChanged() W_SIGNAL(vstChanged)
99
100 void processIncomingMessage(const QString& txt);
101 void addInvalidVST(const QString& path);
102 void addVST(const QString& path, const QJsonObject& json);
103
104 void scanVSTsEvent();
105
106 std::pair<const AvailablePlugin*, const VST3::Hosting::ClassInfo*>
107 classInfo(const VST3::UID& uid) const noexcept;
108 QString pathForClass(const VST3::UID& uid) const noexcept;
109 std::optional<VST3::UID>
110 uidForPathAndClassName(const QString& path, const QString& cls) const noexcept;
111
112#if QT_CONFIG(process)
113 struct ScanningProcess
114 {
115 QString path;
116 std::unique_ptr<QProcess> process;
117 bool scanning{};
118 QElapsedTimer timer;
119 };
120
121 std::vector<ScanningProcess> m_processes;
122 QWebSocketServer m_wsServer;
123#endif
124
125 HostApp m_host;
126 ossia::string_map<VST3::Hosting::Module::Ptr> modules;
127 std::vector<AvailablePlugin> vst_infos;
128};
129}
Definition GUIApplicationPlugin.hpp:31
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:87
void initialize() override
initialize
Definition score-plugin-vst3/Vst3/ApplicationPlugin.cpp:115
Used to access all the application-wide state and structures.
Definition ApplicationContext.hpp:24
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:22
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:32