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