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 loadBuses();
69 void loadPresets();
70
71 void loadProcessorStateToController();
72
73 void start(double sample_rate, int max_bs);
74 void stop();
75
76 bool supportsDouble{};
77 bool hasUI{};
78 int audio_ins = 0;
79 int event_ins = 0;
80 int audio_outs = 0;
81 int event_outs = 0;
82
83 MIDIControls midiControls{};
84
85 Steinberg::Vst::ProgramListInfo programs;
86};
87
88#if __cpp_concepts >= 201907
89template <typename T>
90concept BusVisitor = requires(T&& vis)
91{
92 vis.audioIn(Steinberg::Vst::BusInfo{}, int{});
93 vis.audioOut(Steinberg::Vst::BusInfo{}, int{});
94 vis.eventIn(Steinberg::Vst::BusInfo{}, int{});
95 vis.eventOut(Steinberg::Vst::BusInfo{}, int{});
96};
97void forEachBus(BusVisitor auto&& visitor, Steinberg::Vst::IComponent& component)
98#else
99template <typename T>
100void forEachBus(T&& visitor, Steinberg::Vst::IComponent& component)
101#endif
102{
103 const int audio_ins
104 = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kInput);
105 const int event_ins
106 = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kInput);
107 const int audio_outs
108 = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput);
109 const int event_outs
110 = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput);
111
112 Steinberg::Vst::BusInfo bus;
113 for(int i = 0; i < audio_ins; i++)
114 {
115 component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kInput, i, bus);
116 visitor.audioIn(bus, i);
117 }
118
119 for(int i = 0; i < event_ins; i++)
120 {
121 component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kInput, i, bus);
122 visitor.eventIn(bus, i);
123 }
124
125 for(int i = 0; i < audio_outs; i++)
126 {
127 component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput, i, bus);
128 visitor.audioOut(bus, i);
129 }
130
131 for(int i = 0; i < event_outs; i++)
132 {
133 component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput, i, bus);
134 visitor.eventOut(bus, i);
135 }
136}
137}
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