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 
20 namespace vst3
21 {
22 class ApplicationPlugin;
23 class Model;
24 
25 inline QString fromString(const Steinberg::Vst::String128& str)
26 {
27 #if defined(_WIN32)
28  return QString::fromWCharArray(str);
29 #else
30  return QString::fromUtf16(str);
31 #endif
32 }
33 
34 using MIDIControls = ossia::flat_map<std::pair<int, int>, Steinberg::Vst::ParamID>;
35 
36 struct Plugin
37 {
38  Plugin() = default;
39  Plugin(const Plugin&) = default;
40  Plugin(Plugin&&) = default;
41  Plugin& operator=(const Plugin&) = default;
42  Plugin& operator=(Plugin&&) = default;
43 
44  ~Plugin();
45 
46  void load(
47  Model& model, ApplicationPlugin& ctx, const std::string& path,
48  const VST3::UID& uid, double sr, int max_bs);
49  operator bool() const noexcept { return component && processor; }
50 
51  std::string path;
52  VST3::Hosting::Module::Ptr mdl;
53  Steinberg::Vst::IComponent* component{};
54  Steinberg::Vst::IAudioProcessor* processor{};
55  Steinberg::Vst::IEditController* controller{};
56  Steinberg::Vst::IUnitInfo* units{};
57  Steinberg::IPlugView* view{};
58 
59  void loadAudioProcessor(ApplicationPlugin& ctx);
60  void loadEditController(Model& model, ApplicationPlugin& ctx);
61  void loadBuses();
62  void loadPresets();
63 
64  void loadProcessorStateToController();
65 
66  void start(double sample_rate, int max_bs);
67  void stop();
68 
69  bool supportsDouble{};
70  bool hasUI{};
71  int audio_ins = 0;
72  int event_ins = 0;
73  int audio_outs = 0;
74  int event_outs = 0;
75 
76  MIDIControls midiControls{};
77 
78  Steinberg::Vst::ProgramListInfo programs;
79 };
80 
81 #if __cpp_concepts >= 201907
82 template <typename T>
83 concept BusVisitor = requires(T&& vis)
84 {
85  vis.audioIn(Steinberg::Vst::BusInfo{}, int{});
86  vis.audioOut(Steinberg::Vst::BusInfo{}, int{});
87  vis.eventIn(Steinberg::Vst::BusInfo{}, int{});
88  vis.eventOut(Steinberg::Vst::BusInfo{}, int{});
89 };
90 void forEachBus(BusVisitor auto&& visitor, Steinberg::Vst::IComponent& component)
91 #else
92 template <typename T>
93 void forEachBus(T&& visitor, Steinberg::Vst::IComponent& component)
94 #endif
95 {
96  const int audio_ins
97  = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kInput);
98  const int event_ins
99  = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kInput);
100  const int audio_outs
101  = component.getBusCount(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput);
102  const int event_outs
103  = component.getBusCount(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput);
104 
105  Steinberg::Vst::BusInfo bus;
106  for(int i = 0; i < audio_ins; i++)
107  {
108  component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kInput, i, bus);
109  visitor.audioIn(bus, i);
110  }
111 
112  for(int i = 0; i < event_ins; i++)
113  {
114  component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kInput, i, bus);
115  visitor.eventIn(bus, i);
116  }
117 
118  for(int i = 0; i < audio_outs; i++)
119  {
120  component.getBusInfo(Steinberg::Vst::kAudio, Steinberg::Vst::kOutput, i, bus);
121  visitor.audioOut(bus, i);
122  }
123 
124  for(int i = 0; i < event_outs; i++)
125  {
126  component.getBusInfo(Steinberg::Vst::kEvent, Steinberg::Vst::kOutput, i, bus);
127  visitor.eventOut(bus, i);
128  }
129 }
130 }
Definition: score-plugin-vst3/Vst3/ApplicationPlugin.hpp:86
Definition: score-plugin-vst3/Vst3/EffectModel.hpp:40
T & component(const score::Components &c)
component Fetch a Component from Components by type
Definition: ComponentUtils.hpp:20
Definition: Plugin.hpp:37