score-plugin-vst/Vst/Library.hpp
1 #pragma once
2 #include <Library/LibraryInterface.hpp>
3 #include <Library/ProcessesItemModel.hpp>
4 #include <Vst/ApplicationPlugin.hpp>
5 #include <Vst/EffectModel.hpp>
6 
7 #include <score/tools/Bind.hpp>
8 
9 #include <ossia/detail/algorithms.hpp>
10 
11 #include <algorithm>
12 namespace vst
13 {
14 
15 class LibraryHandler final
16  : public QObject
18 {
19  SCORE_CONCRETE("6a13c3cc-bca7-44d6-a0ef-644e99204460")
20  void setup(Library::ProcessesItemModel& model, const score::GUIApplicationContext& ctx)
21  override
22  {
23  constexpr static const auto key = Metadata<ConcreteKey_k, Model>::get();
24 
25  QModelIndex node = model.find(key);
26  if(node == QModelIndex{})
27  {
28  return;
29  }
30  auto& parent = *reinterpret_cast<Library::ProcessNode*>(node.internalPointer());
31  parent.key = {};
32 
33  auto& plug = ctx.applicationPlugin<vst::ApplicationPlugin>();
34 
35  auto reset_plugs = [=, &plug, &parent] {
36  auto& fx = parent.emplace_back(
37  Library::ProcessData{{{}, "Effects", {}}, {}, {}, {}}, &parent);
38  auto& inst = parent.emplace_back(
39  Library::ProcessData{{{}, "Instruments", {}}, {}, {}, {}}, &parent);
40  for(const auto& vst : plug.vst_infos)
41  {
42  if(vst.isValid)
43  {
44  const auto& name
45  = vst.displayName.isEmpty() ? vst.prettyName : vst.displayName;
47  {key, name, QString::number(vst.uniqueID)}, {}, vst.author, {}};
48  if(vst.isSynth)
49  {
50  Library::addToLibrary(inst, std::move(pdata));
51  }
52  else
53  {
54  Library::addToLibrary(fx, std::move(pdata));
55  }
56  }
57  }
58  };
59 
60  reset_plugs();
61 
62  con(plug, &vst::ApplicationPlugin::vstChanged, this,
63  [&model, node, &parent, reset_plugs] {
64  model.beginRemoveRows(node, 0, 1);
65  parent.resize(0);
66  model.endRemoveRows();
67 
68  model.beginInsertRows(node, 0, 1);
69  reset_plugs();
70  model.endInsertRows();
71  });
72  }
73 };
74 }
Definition: LibraryInterface.hpp:22
Definition: ProcessesItemModel.hpp:45
Definition: score-plugin-vst/Vst/ApplicationPlugin.hpp:34
Definition: score-plugin-vst/Vst/Library.hpp:18
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