iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugCLAP.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#ifndef _IPLUGAPI_
12#define _IPLUGAPI_
13// Only load one API class!
14
20#include "IPlugAPIBase.h"
21#include "IPlugProcessor.h"
22#include "plugin.hh"
23
24#include "config.h" // This is your plugin's config.h.
25
26BEGIN_IPLUG_NAMESPACE
27
29struct InstanceInfo
30{
31 const clap_plugin_descriptor* mDesc;
32 const clap_host* mHost;
33};
34
35// Set the level of host checking based on if this is debug build
36
37#ifdef _DEBUG
38using ClapPluginHelper = clap::helpers::Plugin<clap::helpers::MisbehaviourHandler::Terminate, clap::helpers::CheckingLevel::Maximal>;
39using ClapHost = clap::helpers::HostProxy<clap::helpers::MisbehaviourHandler::Terminate, clap::helpers::CheckingLevel::Maximal>;
40#else
41using ClapPluginHelper = clap::helpers::Plugin<clap::helpers::MisbehaviourHandler::Ignore, clap::helpers::CheckingLevel::None>;
42using ClapHost = clap::helpers::HostProxy<clap::helpers::MisbehaviourHandler::Ignore, clap::helpers::CheckingLevel::None>;
43#endif
44
47class IPlugCLAP : public IPlugAPIBase
48 , public IPlugProcessor
49 , public ClapPluginHelper
50{
51 struct ParamToHost
52 {
53 enum class Type { Begin, Value, End };
54
55 ParamToHost()
56 : mType(Type::Value)
57 , mIdx(-1)
58 , mValue(0.0)
59 {}
60
61 ParamToHost(Type type, int idx, double value)
62 : mType(type)
63 , mIdx(idx)
64 , mValue(value)
65 {}
66
67 uint32_t idx() const { return static_cast<uint32_t>(mIdx); }
68 double value() const { return mValue; }
69 uint16_t type() const
70 {
71 switch (mType)
72 {
73 case Type::Begin: return CLAP_EVENT_PARAM_GESTURE_BEGIN;
74 case Type::End: return CLAP_EVENT_PARAM_GESTURE_END;
75 case Type::Value: // fall through
76 default: return CLAP_EVENT_PARAM_VALUE;
77 }
78 }
79
80 Type mType;
81 int mIdx;
82 double mValue;
83 };
84
85public:
86 IPlugCLAP(const InstanceInfo& info, const Config& config);
87
88 // IPlugAPIBase
89 void BeginInformHostOfParamChange(int idx) override;
90 void InformHostOfParamChange(int idx, double normalizedValue) override;
91 void EndInformHostOfParamChange(int idx) override;
92 bool EditorResize(int viewWidth, int viewHeight) override;
93
94 // IPlugProcessor
95 void SetTailSize(int tailSize) override;
96 void SetLatency(int samples) override;
97 bool SendMidiMsg(const IMidiMsg& msg) override;
98 bool SendSysEx(const ISysEx& msg) override;
99
100private:
101 // clap_plugin
102 bool init() noexcept override;
103 bool activate(double sampleRate, uint32_t minFrameCount, uint32_t maxFrameCount) noexcept override;
104 void deactivate() noexcept override;
105 bool startProcessing() noexcept override { return true; }
106 void stopProcessing() noexcept override {}
107 clap_process_status process(const clap_process* pProcess) noexcept override;
108
109 // clap_plugin_latency
110 bool implementsLatency() const noexcept override { return true; }
111 uint32_t latencyGet() const noexcept override { return GetLatency(); }
112
113 // clap_plugin_tail
114 bool implementsTail() const noexcept override { return true; }
115 uint32_t tailGet() const noexcept override;
116
117 // clap_plugin_render
118 bool implementsRender() const noexcept override { return true; }
119 bool renderHasHardRealtimeRequirement() noexcept override { return false; }
120 bool renderSetMode(clap_plugin_render_mode mode) noexcept override;
121
122 // clap_plugin_state
123 bool implementsState() const noexcept override { return true; }
124 bool stateSave(const clap_ostream* pStream) noexcept override;
125 bool stateLoad(const clap_istream* pStream) noexcept override;
126
127 // clap_plugin_audio_ports
128 bool implementsAudioPorts() const noexcept override;
129 uint32_t audioPortsCount(bool isInput) const noexcept override;
130 bool audioPortsInfo(uint32_t index, bool isInput, clap_audio_port_info* pInfo) const noexcept override;
131
132 // clap_plugin_audio_ports_config
133 bool implementsAudioPortsConfig() const noexcept override;
134 uint32_t audioPortsConfigCount() const noexcept override;
135 bool audioPortsGetConfig(uint32_t index, clap_audio_ports_config* pConfig) const noexcept override;
136 bool audioPortsSetConfig(clap_id configIdx) noexcept override;
137
138 // clap_plugin_note_ports
139 bool implementsNotePorts() const noexcept override { return DoesMIDIIn() || DoesMIDIOut(); }
140 uint32_t notePortsCount(bool isInput) const noexcept override;
141 bool notePortsInfo(uint32_t index, bool isInput, clap_note_port_info* pInfo) const noexcept override;
142
143 // clap_plugin_params
144 bool implementsParams() const noexcept override { return true; }
145 uint32_t paramsCount() const noexcept override { return NParams(); }
146
147 bool paramsInfo(uint32_t paramIdx, clap_param_info* pInfo) const noexcept override;
148
149 bool paramsValue(clap_id paramIdx, double* pValue) noexcept override;
150 bool paramsValueToText(clap_id paramIdx, double value, char* display, uint32_t size) noexcept override;
151 bool paramsTextToValue(clap_id paramIdx, const char* display, double* pValue) noexcept override;
152
153 void paramsFlush(const clap_input_events* pInputParamChanges, const clap_output_events* pOutputParamChanges) noexcept override;
154 bool isValidParamId(clap_id paramIdx) const noexcept override { return paramIdx < NParams(); }
155
156 // clap_plugin_gui
157 bool implementsGui() const noexcept override;
158 bool guiCreate(const char* api, bool isFloating) noexcept override;
159 void guiDestroy() noexcept override;
160
161 bool guiSetScale(double scale) noexcept override;
162 bool guiShow() noexcept override;
163 bool guiHide() noexcept override;
164 bool guiGetSize(uint32_t* pWidth, uint32_t* pHeight) noexcept override;
165
166 bool guiCanResize() const noexcept override;
167 bool guiAdjustSize(uint32_t* pWidth, uint32_t* pHeight) noexcept override;
168 bool guiSetSize(uint32_t width, uint32_t height) noexcept override;
169
170 // clap_plugin_gui_cocoa/win32
171 bool guiIsApiSupported(const char* api, bool isFloating) noexcept override;
172 bool guiSetParent(const clap_window* pWindow) noexcept override;
173
174 // Helper to attach GUI Windows
175 bool GUIWindowAttach(void* parent) noexcept;
176
177 // Parameter Helpers
178 void ProcessInputEvents(const clap_input_events* pInputEvents) noexcept;
179 void ProcessOutputParams(const clap_output_events* pOutputParamChanges) noexcept;
180 void ProcessOutputEvents(const clap_output_events* pOutputEvents, int nFrames) noexcept;
181
182 // IPlug2-style host retrieval
183 ClapHost& GetClapHost() { return _host; }
184
185 // IPlug Config Helpers
186 void SetDefaultConfig();
187 int RequiredChannels() const;
188 uint32_t NBuses(ERoute direction) const;
189 uint32_t NChannels(ERoute direction, uint32_t bus) const;
190 uint32_t NBuses(ERoute direction, int configIdx) const;
191 uint32_t NChannels(ERoute direction, uint32_t bus, int configIdx) const;
192
193 IPlugQueue<ParamToHost> mParamValuesToHost {PARAM_TRANSFER_SIZE};
194 IMidiQueueBase<SysExData> mSysExToHost;
195 IMidiQueue mMidiToHost;
196 WDL_TypedBuf<float *> mAudioIO32;
197 WDL_TypedBuf<double *> mAudioIO64;
198 int mConfigIdx = 0;
199 int mTailCount = 0;
200 bool mHostHasTail = false;
201 bool mTailUpdate = false;
202 bool mLatencyUpdate = false;
203
204 void* mWindow = nullptr;
205 bool mGUIOpen = false;
206};
207
208IPlugCLAP* MakePlug(const InstanceInfo& info);
209
210END_IPLUG_NAMESPACE
211
212#endif
A class to help with queuing timestamped MIDI messages.
Definition: IPlugMidi.h:682
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
CLAP API base class for an IPlug plug-in.
Definition: IPlugCLAP.h:50
bool SendSysEx(const ISysEx &msg) override
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
Definition: IPlugCLAP.cpp:129
void InformHostOfParamChange(int idx, double normalizedValue) override
Implemented by the API class, called by the UI via SetParameterValue() with the value of a parameter ...
Definition: IPlugCLAP.cpp:66
void SetTailSize(int tailSize) override
Call this method if you need to update the tail size at runtime, for example if the decay time of you...
Definition: IPlugCLAP.cpp:96
void SetLatency(int samples) override
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
Definition: IPlugCLAP.cpp:104
bool EditorResize(int viewWidth, int viewHeight) override
Implementations call into the APIs resize hooks returns a bool to indicate whether the DAW or plugin ...
Definition: IPlugCLAP.cpp:80
void BeginInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the beginning of a parameter cha...
Definition: IPlugCLAP.cpp:61
bool SendMidiMsg(const IMidiMsg &msg) override
Send a single MIDI message // TODO: info about what thread should this be called on or not called on!
Definition: IPlugCLAP.cpp:123
void EndInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the end of a parameter change ge...
Definition: IPlugCLAP.cpp:75
The base class for IPlug Audio Processing.
bool DoesMIDIIn() const
int GetLatency() const
bool DoesMIDIOut() const
A lock-free SPSC queue used to transfer data between threads based on MLQueue.h by Randy Jones based ...
Definition: IPlugQueue.h:32
ERoute
Used to identify whether a bus/channel connection is an input or an output.
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:539