score-plugin-vst3/Vst3/EffectModel.hpp
1 #pragma once
2 #include <Process/Dataflow/PortFactory.hpp>
3 #include <Process/GenericProcessFactory.hpp>
4 #include <Process/Process.hpp>
5 
6 #include <Control/DefaultEffectItem.hpp>
7 #include <Effect/EffectFactory.hpp>
8 #include <Vst3/Plugin.hpp>
9 
10 #include <score/tools/std/Invoke.hpp>
11 
12 #include <ossia/detail/hash_map.hpp>
13 
14 #include <verdigris>
15 
16 #include <public.sdk/source/vst/utility/uid.h>
17 #define VST_DEFAULT_PARAM_NUMBER_CUTOFF 10
18 
19 namespace vst3
20 {
21 class Model;
22 class ControlInlet;
23 }
24 PROCESS_METADATA(
25  , vst3::Model, "4cc30435-3237-4e94-a79e-1c2bd6b724a1", "VST 3", "VST 3",
26  Process::ProcessCategory::Other, "Plugins", "VST 3 plug-in",
27  "VST is a trademark of Steinberg Media Technologies GmbH", {}, {}, {},
28  QUrl("https://ossia.io/score-docs/processes/audio-plugins.html#common-formats-vst-vst3-lv2-jsfx"),
29  Process::ProcessFlags::ExternalEffect)
30 UUID_METADATA(
31  , Process::Port, vst3::ControlInlet, "82b24dd8-fbc0-43a6-adfa-7bb29ca48660")
32 DESCRIPTION_METADATA(, vst3::Model, "VST")
33 namespace vst3
34 {
35 
36 class CreateVSTControl;
37 class ControlInlet;
38 struct PortCreationVisitor;
39 
40 class Model final : public Process::ProcessModel
41 {
42  W_OBJECT(Model)
43  SCORE_SERIALIZE_FRIENDS
44  friend class vst3::CreateVSTControl;
45 
46 public:
47  PROCESS_METADATA_IMPL(Model)
48  Model(
49  TimeVal t, const QString& name, const Id<Process::ProcessModel>&, QObject* parent);
50 
51  ~Model() override;
52  template <typename Impl>
53  Model(Impl& vis, QObject* parent)
54  : ProcessModel{vis, parent}
55  {
56  init();
57  vis.writeTo(*this);
58  }
59 
60  ControlInlet* getControl(const Id<Process::Port>& p) const;
61  QString effect() const noexcept override;
62  QString prettyName() const noexcept override;
63  bool hasExternalUI() const noexcept;
64 
65  Plugin fx{};
66 
67  ossia::hash_map<Steinberg::Vst::ParamID, ControlInlet*> controls;
68 
69  void removeControl(const Id<Process::Port>&);
70  void removeControl(Steinberg::Vst::ParamID fxnum);
71 
72  void addControlFromEditor(Steinberg::Vst::ParamID id);
73  void on_addControl(const Steinberg::Vst::ParameterInfo& v);
74  void on_addControl_impl(ControlInlet* inl);
75  void initControl(ControlInlet* inl);
76 
77  void reloadControls();
78  Steinberg::tresult restartComponent(int32_t flags);
79 
80 private:
81  void loadPreset(const Process::Preset& preset) override;
82  Process::Preset savePreset() const noexcept override;
83  std::vector<Process::Preset> builtinPresets() const noexcept override;
84 
85  void init();
86  void create();
87  void load();
88  void mapAllControls(int numParams);
89  QByteArray readProcessorState() const;
90  QByteArray readControllerState() const;
91  void writeState();
92 
93  QString m_vstPath;
94  VST3::UID m_uid{};
95 
96  QByteArray m_savedProcessorState;
97  QByteArray m_savedControllerState;
98 
99  ossia::hash_map<Steinberg::Vst::ParamID, int32_t> m_paramToIndex;
100 
101  void closePlugin();
102  void initFx();
103 
104  friend struct PortCreationVisitor;
105 };
106 }
107 
108 namespace Process
109 {
110 template <>
111 QString EffectProcessFactory_T<vst3::Model>::customConstructionData() const noexcept;
112 
113 template <>
114 Process::Descriptor
115 EffectProcessFactory_T<vst3::Model>::descriptor(QString d) const noexcept;
116 }
117 
118 namespace vst3
119 {
120 using VSTEffectFactory = Process::EffectProcessFactory_T<Model>;
121 }
Definition: QmlObjects.hpp:114
Definition: EffectFactory.hpp:14
Definition: Port.hpp:102
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
The id_base_t class.
Definition: Identifier.hpp:57
Definition: /Vst3/Control.hpp:15
Definition: score-plugin-vst3/Vst3/EffectModel.hpp:41
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Definition: Preset.hpp:32
Definition: TimeValue.hpp:21
Definition: Plugin.hpp:43
Definition: score-plugin-vst3/Vst3/EffectModel.cpp:390