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 void reset() noexcept override { OnReset(); }
108 clap_process_status process(const clap_process* pProcess) noexcept override;
109
110 // clap_plugin_latency
111 bool implementsLatency() const noexcept override { return true; }
112 uint32_t latencyGet() const noexcept override { return GetLatency(); }
113
114 // clap_plugin_tail
115 bool implementsTail() const noexcept override { return true; }
116 uint32_t tailGet() const noexcept override;
117
118 // clap_plugin_render
119 bool implementsRender() const noexcept override { return true; }
120 bool renderHasHardRealtimeRequirement() noexcept override { return false; }
121 bool renderSetMode(clap_plugin_render_mode mode) noexcept override;
122
123 // clap_plugin_state
124 bool implementsState() const noexcept override { return true; }
125 bool stateSave(const clap_ostream* pStream) noexcept override;
126 bool stateLoad(const clap_istream* pStream) noexcept override;
127
128 // clap_plugin_audio_ports
129 bool implementsAudioPorts() const noexcept override;
130 uint32_t audioPortsCount(bool isInput) const noexcept override;
131 bool audioPortsInfo(uint32_t index, bool isInput, clap_audio_port_info* pInfo) const noexcept override;
132
133 // clap_plugin_audio_ports_config
134 bool implementsAudioPortsConfig() const noexcept override;
135 uint32_t audioPortsConfigCount() const noexcept override;
136 bool audioPortsGetConfig(uint32_t index, clap_audio_ports_config* pConfig) const noexcept override;
137 bool audioPortsSetConfig(clap_id configIdx) noexcept override;
138
139 // clap_plugin_note_ports
140 bool implementsNotePorts() const noexcept override { return DoesMIDIIn() || DoesMIDIOut(); }
141 uint32_t notePortsCount(bool isInput) const noexcept override;
142 bool notePortsInfo(uint32_t index, bool isInput, clap_note_port_info* pInfo) const noexcept override;
143
144 // clap_plugin_params
145 bool implementsParams() const noexcept override { return true; }
146 uint32_t paramsCount() const noexcept override { return NParams(); }
147
148 bool paramsInfo(uint32_t paramIdx, clap_param_info* pInfo) const noexcept override;
149
150 bool paramsValue(clap_id paramIdx, double* pValue) noexcept override;
151 bool paramsValueToText(clap_id paramIdx, double value, char* display, uint32_t size) noexcept override;
152 bool paramsTextToValue(clap_id paramIdx, const char* display, double* pValue) noexcept override;
153
154 void paramsFlush(const clap_input_events* pInputParamChanges, const clap_output_events* pOutputParamChanges) noexcept override;
155 bool isValidParamId(clap_id paramIdx) const noexcept override { return paramIdx < NParams(); }
156
157 // clap_plugin_gui
158 bool implementsGui() const noexcept override;
159 bool guiCreate(const char* api, bool isFloating) noexcept override;
160 void guiDestroy() noexcept override;
161
162 bool guiSetScale(double scale) noexcept override;
163 bool guiShow() noexcept override;
164 bool guiHide() noexcept override;
165 bool guiGetSize(uint32_t* pWidth, uint32_t* pHeight) noexcept override;
166
167 bool guiCanResize() const noexcept override;
168 bool guiAdjustSize(uint32_t* pWidth, uint32_t* pHeight) noexcept override;
169 bool guiSetSize(uint32_t width, uint32_t height) noexcept override;
170
171 // clap_plugin_gui_cocoa/win32
172 bool guiIsApiSupported(const char* api, bool isFloating) noexcept override;
173 bool guiSetParent(const clap_window* pWindow) noexcept override;
174
175 // Helper to attach GUI Windows
176 bool GUIWindowAttach(void* parent) noexcept;
177
178 // Parameter flushing from GUI
179 void FlushParamsIfNeeded();
180
181 // Parameter Helpers
182 void ProcessInputEvents(const clap_input_events* pInputEvents) noexcept;
183 void ProcessOutputParams(const clap_output_events* pOutputParamChanges) noexcept;
184 void ProcessOutputEvents(const clap_output_events* pOutputEvents, int nFrames) noexcept;
185
186 // IPlug2-style host retrieval
187 ClapHost& GetClapHost() { return _host; }
188
189 // IPlug Config Helpers
190 void SetDefaultConfig();
191 int RequiredChannels() const;
192 uint32_t NBuses(ERoute direction) const;
193 uint32_t NChannels(ERoute direction, uint32_t bus) const;
194 uint32_t NBuses(ERoute direction, int configIdx) const;
195 uint32_t NChannels(ERoute direction, uint32_t bus, int configIdx) const;
196
197 IPlugQueue<ParamToHost> mParamValuesToHost {PARAM_TRANSFER_SIZE};
198 IMidiQueueBase<SysExData> mSysExToHost;
199 IMidiQueue mMidiToHost;
200 WDL_TypedBuf<float *> mAudioIO32;
201 WDL_TypedBuf<double *> mAudioIO64;
202 int mConfigIdx = 0;
203 int mTailCount = 0;
204 bool mHostHasTail = false;
205 bool mTailUpdate = false;
206 bool mLatencyUpdate = false;
207
208 void* mWindow = nullptr;
209 bool mGUIOpen = false;
210};
211
212IPlugCLAP* MakePlug(const InstanceInfo& info);
213
214END_IPLUG_NAMESPACE
215
216#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:138
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:73
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:105
void SetLatency(int samples) override
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
Definition: IPlugCLAP.cpp:113
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:89
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:67
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:132
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:83
The base class for IPlug Audio Processing.
bool DoesMIDIIn() const
int GetLatency() const
bool DoesMIDIOut() const
virtual void OnReset()
Override this method in your plug-in class to do something prior to playback etc.
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