Loading...
Searching...
No Matches
Plugin.hpp
1#pragma once
2
3#define RELEASE 1
4#include <ossia/detail/flat_map.hpp>
5
6#include <QString>
7
8#include <pluginterfaces/base/funknown.h>
9#include <pluginterfaces/gui/iplugview.h>
10#include <pluginterfaces/vst/ivstaudioprocessor.h>
11#include <pluginterfaces/vst/ivstcomponent.h>
12#include <pluginterfaces/vst/ivstunits.h>
13
14#include <string_view>
15
16#include <public.sdk/source/vst/hosting/hostclasses.h>
17#include <public.sdk/source/vst/hosting/module.h>
18#include <public.sdk/source/vst/hosting/plugprovider.h>
19
20namespace vst3
21{
22class ApplicationPlugin;
23class Model;
24
25inline QString fromString(const Steinberg::Vst::String128& str)
26{
27#if defined(_WIN32)
28 return [] <typename T>(const T& str) {
29 using char_type = std::decay_t<decltype(str[0])>;
30 if constexpr(std::is_same_v<char_type, char16_t>)
31 return QString::fromUtf16(str);
32 else
33 return QString::fromWCharArray(str);
34 }(str);
35#else
36 return QString::fromUtf16(str);
37#endif
38}
39
40using MIDIControls = ossia::flat_map<std::pair<int, int>, Steinberg::Vst::ParamID>;
41class PlugFrame;
42struct Plugin
43{
44 Plugin() = default;
45 Plugin(const Plugin&) = default;
46 Plugin(Plugin&&) = default;
47 Plugin& operator=(const Plugin&) = default;
48 Plugin& operator=(Plugin&&) = default;
49
50 ~Plugin();
51
52 void load(
53 Model& model, ApplicationPlugin& ctx, const std::string& path,
54 const VST3::UID& uid, double sr, int max_bs);
55 operator bool() const noexcept { return component && processor; }
56
57 std::string path;
58 VST3::Hosting::Module::Ptr mdl;
59 Steinberg::Vst::IComponent* component{};
60 Steinberg::Vst::IAudioProcessor* processor{};
61 Steinberg::Vst::IEditController* controller{};
62 Steinberg::Vst::IUnitInfo* units{};
63 Steinberg::IPlugView* view{};
64 PlugFrame* plugFrame{};
65
66 void loadAudioProcessor(ApplicationPlugin& ctx);
67 void loadEditController(Model& model, ApplicationPlugin& ctx);
68 void loadView(Model& model);
69 void loadBuses();
70 void loadPresets();
71
72 void loadProcessorStateToController();
73
74 void start(double sample_rate, int max_bs);
75 void stop();
76
77 bool supports_double{};
78 bool ui_available{};
79 bool ui_owned{};
80 int audio_ins = 0;
81 int event_ins = 0;
82 int audio_outs = 0;
83 int event_outs = 0;
84
85 MIDIControls midiControls{};
86
87 Steinberg::Vst::ProgramListInfo programs;
88};
89
90#if __cpp_concepts >= 201907
91template <typename T>
92concept BusVisitor = requires(T&& vis)
93{
94 vis.audioIn(Steinberg::Vst::BusInfo{}, int{});
95 vis.audioOut(Steinberg::Vst::BusInfo{}, int{});
96 vis.eventIn(Steinberg::Vst::BusInfo{}, int{});
97 vis.eventOut(Steinberg::Vst::BusInfo{}, int{});
98};
99void forEachBus(BusVisitor auto&& visitor, Steinberg::Vst::IComponent& component)
100#else
101template <typename T>
102void forEachBus(T&& visitor, Steinberg::Vst::IComponent& component)
103#endif
104{
105 const int audio_ins
106 = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kInput);
107 const int event_ins
108 = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kInput);
109 const int audio_outs
110 = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput);
111 const int event_outs
112 = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput);
113
114 Steinberg::Vst::BusInfo bus;
115 for(int i = 0; i < audio_ins; i++)
116 {
117 component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kInput, i, bus);
118 visitor.audioIn(bus, i);
119 }
120
121 for(int i = 0; i < event_ins; i++)
122 {
123 component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kInput, i, bus);
124 visitor.eventIn(bus, i);
125 }
126
127 for(int i = 0; i < audio_outs; i++)
128 {
129 component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput, i, bus);
130 visitor.audioOut(bus, i);
131 }
132
133 for(int i = 0; i < event_outs; i++)
134 {
135 component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput, i, bus);
136 visitor.eventOut(bus, i);
137 }
138}
139}
Definition score-plugin-vst3/Vst3/ApplicationPlugin.hpp:87
Definition score-plugin-vst3/Vst3/EffectModel.hpp:43
T & component(const score::Components &c)
component Fetch a Component from Components by type
Definition ComponentUtils.hpp:20
Definition Plugin.hpp:43