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