Loading...
Searching...
No Matches
score-plugin-vst3/Vst3/Library.hpp
1#pragma once
2#include <Library/LibraryInterface.hpp>
3#include <Library/ProcessesItemModel.hpp>
4#include <Vst3/ApplicationPlugin.hpp>
5#include <Vst3/EffectModel.hpp>
6
7#include <score/tools/Bind.hpp>
8
9namespace vst3
10{
11class LibraryHandler final
12 : public QObject
14{
15 SCORE_CONCRETE("1d6ca523-628b-431a-9f70-87df92a63551")
16
17 void registerVSTClass(
18 Library::ProcessNode& parent, const AvailablePlugin& vst,
19 const VST3::Hosting::ClassInfo& cls)
20 {
21 constexpr static const auto key = Metadata<ConcreteKey_k, Model>::get();
22
23 auto name = QString::fromStdString(cls.name());
24 auto vendor = QString::fromStdString(cls.vendor());
25 auto desc = QString::fromStdString(cls.version());
26 auto uid = QString::fromStdString(cls.ID().toString());
27
28 //qDebug() << "UID: " << name << uid << (int)cls.ID().data()[0]<< (int)cls.ID().data()[1]<< (int)cls.ID().data()[12];
29
30 Library::ProcessData classdata{{key, name, uid}, {}, vendor, desc};
31 if(parent.author.isEmpty())
32 parent.author = vendor;
33 if(vst.classInfo.size() == 1)
34 parent.customData = uid;
35 Library::addToLibrary(parent, std::move(classdata));
36 }
37
39 override
40 {
41 constexpr static const auto key = Metadata<ConcreteKey_k, Model>::get();
42
43 QModelIndex node = model.find(key);
44 if(node == QModelIndex{})
45 {
46 return;
47 }
48 auto& parent = *reinterpret_cast<Library::ProcessNode*>(node.internalPointer());
49 parent.key = {};
50
52
53 auto reset_plugs = [this, &plug, &parent] {
54 for(const auto& vst : plug.vst_infos)
55 {
56 if(vst.isValid)
57 {
58 Library::ProcessData parent_data{{key, vst.name, QString{}}, {}, {}, {}};
59
60 const int numClasses = vst.classInfo.size();
61 switch(numClasses)
62 {
63 default: {
64 auto& node = Library::addToLibrary(parent, std::move(parent_data));
65
66 for(const auto& cls : vst.classInfo)
67 {
68 registerVSTClass(node, vst, cls);
69 }
70 break;
71 }
72 case 1: {
73 registerVSTClass(parent, vst, vst.classInfo[0]);
74 break;
75 }
76 case 0:
77 break;
78 }
79 }
80 }
81 };
82
83 reset_plugs();
84
85 con(plug, &vst3::ApplicationPlugin::vstChanged, this,
86 [&plug, &model, node, &parent, reset_plugs] {
87 model.beginRemoveRows(node, 0, parent.childCount());
88 parent.resize(0);
89 model.endRemoveRows();
90
91 int k = 0;
92 for(const auto& vst : plug.vst_infos)
93 if(vst.isValid)
94 k++;
95 if(k > 0)
96 {
97 model.beginInsertRows(node, 0, k - 1);
98 reset_plugs();
99 model.endInsertRows();
100 }
101 });
102 }
103};
104}
Definition LibraryInterface.hpp:22
Definition ProcessesItemModel.hpp:45
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:87
Definition score-plugin-vst3/Vst3/Library.hpp:14
Definition ProcessesItemModel.hpp:32
Static metadata implementation.
Definition lib/score/tools/Metadata.hpp:36
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15
T & applicationPlugin() const
Access a specific application plug-in instance.
Definition GUIApplicationContext.hpp:69
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:22