iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugProcessor.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#pragma once
12
13#include <cstring>
14#include <cstdint>
15#include <ctime>
16#include <cmath>
17#include <cstdio>
18#include <cassert>
19#include <limits>
20#include <memory>
21#include <vector>
22
23#include "ptrlist.h"
24
25#include "IPlugPlatform.h"
26#include "IPlugConstants.h"
27#include "IPlugStructs.h"
28#include "IPlugUtilities.h"
29#include "NChanDelay.h"
30
36BEGIN_IPLUG_NAMESPACE
37
38struct Config;
39
42{
43public:
44
45 enum TailSize
46 {
47 kTailNone = 0,
48 kTailInfinite = std::numeric_limits<int>::max()
49 };
50
54 IPlugProcessor(const Config& config, EAPI plugAPI);
55 virtual ~IPlugProcessor();
56
57 IPlugProcessor(const IPlugProcessor&) = delete;
58 IPlugProcessor& operator=(const IPlugProcessor&) = delete;
59
60#pragma mark - Methods you implement in your plug-in class - you do not call these methods
61
70 virtual void ProcessBlock(sample** inputs, sample** outputs, int nFrames);
71
76 virtual void ProcessMidiMsg(const IMidiMsg& msg);
77
80 virtual void ProcessSysEx(const ISysEx& msg) {}
81
83 virtual void OnReset() { TRACE }
84
89 virtual void OnActivate(bool active) { TRACE }
90
91#pragma mark - Methods you can call - some of which have custom implementations in the API classes, some implemented in IPlugProcessor.cpp
92
96 virtual bool SendMidiMsg(const IMidiMsg& msg) = 0;
97
101 virtual bool SendMidiMsgs(WDL_TypedBuf<IMidiMsg>& msgs);
102
106 virtual bool SendSysEx(const ISysEx& msg) { return false; }
107
109 double GetSampleRate() const { return mSampleRate; }
110
112 int GetBlockSize() const { return mBlockSize; }
113
115 int GetLatency() const { return mLatency; }
116
118 int GetTailSize() const { return mTailSize; }
119
121 bool GetTailIsInfinite() const { return GetTailSize() == kTailInfinite; }
122
124 bool GetBypassed() const { return mBypassed; }
125
127 bool GetRenderingOffline() const { return mRenderingOffline; };
128
129#pragma mark -
131 double GetSamplePos() const { return mTimeInfo.mSamplePos; }
132
134 double GetTempo() const { return mTimeInfo.mTempo; }
135
137 double GetPPQPos() const { return mTimeInfo.mPPQPos; }
138
140 bool GetTransportIsRunning() const { return mTimeInfo.mTransportIsRunning; }
141
143 double GetSamplesPerBeat() const;
144
147 void GetTimeSig(int& numerator, int& denominator) const { numerator = mTimeInfo.mNumerator; denominator = mTimeInfo.mDenominator; }
148
149#pragma mark -
150
156 virtual void GetBusName(ERoute direction, int busIdx, int nBuses, WDL_String& str) const;
157
159 int NIOConfigs() const { return mIOConfigs.GetSize(); }
160
162 const IOConfig* GetIOConfig(int idx) const { return mIOConfigs.Get(idx); }
163
165 int GetIOConfigWithChanCounts(std::vector<int>& inputBuses, std::vector<int>& outputBuses);
166
171 int MaxNBuses(ERoute direction, int* pConfigIdxWithTheMostBuses = nullptr) const;
172
177 int MaxNChannelsForBus(ERoute direction, int busIdx) const;
178
182 bool HasWildcardBus(ERoute direction) const { return mIOConfigs.Get(0)->ContainsWildcard(direction); } // \todo only supports a single I/O config
183
186 int MaxNChannels(ERoute direction) const { return mChannelData[direction].GetSize(); }
187
191 bool IsChannelConnected(ERoute direction, int chIdx) const { return (chIdx < mChannelData[direction].GetSize() && mChannelData[direction].Get(chIdx)->mConnected); }
192
195 int NChannelsConnected(ERoute direction) const;
196
199 inline int NInChansConnected() const { return NChannelsConnected(ERoute::kInput); }
200
203 inline int NOutChansConnected() const { return NChannelsConnected(ERoute::kOutput); }
204
209 bool LegalIO(int NInputChans, int NOutputChans) const; //TODO: this should be updated
210
212 bool HasSidechainInput() const { return MaxNBuses(ERoute::kInput) > 1; }
213
215 void LimitToStereoIO();//TODO: this should be updated
216
218 bool IsInstrument() const { return mPlugType == EIPlugPluginType::kInstrument; }
219
221 bool IsMidiEffect() const { return mPlugType == EIPlugPluginType::kMIDIEffect; }
222
224 int GetAUPluginType() const;
225
227 bool DoesMIDIIn() const { return mDoesMIDIIn; }
228
230 bool DoesMIDIOut() const { return mDoesMIDIOut; }
231
233 bool DoesMPE() const { return mDoesMPE; }
234
241 void SetChannelLabel(ERoute direction, int idx, const char* formatStr, bool zeroBased = false);
242
246 virtual void SetLatency(int latency);
247
252 virtual void SetTailSize(int tailSize) { mTailSize = tailSize; }
253
265 static int ParseChannelIOStr(const char* IOStr, WDL_PtrList<IOConfig>& channelIOList, int& totalNInChans, int& totalNOutChans, int& totalNInBuses, int& totalNOutBuses);
266
267protected:
268#pragma mark - Methods called by the API class - you do not call these methods in your plug-in class
269 void SetChannelConnections(ERoute direction, int idx, int n, bool connected);
270 void InitLatencyDelay();
271
272 //The following methods are duplicated, in order to deal with either single or double precision processing,
273 //depending on the value of arguments passed in
274 void AttachBuffers(ERoute direction, int idx, int n, PLUG_SAMPLE_DST** ppData, int nFrames);
275 void AttachBuffers(ERoute direction, int idx, int n, PLUG_SAMPLE_SRC** ppData, int nFrames);
276 void PassThroughBuffers(PLUG_SAMPLE_SRC type, int nFrames);
277 void PassThroughBuffers(PLUG_SAMPLE_DST type, int nFrames);
278 void ProcessBuffers(PLUG_SAMPLE_SRC type, int nFrames);
279 void ProcessBuffers(PLUG_SAMPLE_DST type, int nFrames);
280 void ProcessBuffersAccumulating(int nFrames); // only for VST2 deprecated method single precision
281 void ZeroScratchBuffers();
282 void SetSampleRate(double sampleRate) { mSampleRate = sampleRate; }
283 void SetBlockSize(int blockSize);
284 void SetBypassed(bool bypassed) { mBypassed = bypassed; }
285 void SetTimeInfo(const ITimeInfo& timeInfo) { mTimeInfo = timeInfo; }
286 void SetRenderingOffline(bool renderingOffline) { mRenderingOffline = renderingOffline; }
287 const WDL_String& GetChannelLabel(ERoute direction, int idx) { return mChannelData[direction].Get(idx)->mLabel; }
288
289private:
291 EIPlugPluginType mPlugType;
293 bool mDoesMIDIIn;
295 bool mDoesMIDIOut;
297 bool mDoesMPE;
299 int mLatency;
301 double mSampleRate = DEFAULT_SAMPLE_RATE;
303 int mBlockSize = 0;
305 int mTailSize = 0;
307 bool mBypassed = false;
309 bool mRenderingOffline = false;
311 WDL_PtrList<IOConfig> mIOConfigs;
312 /* Manages pointers to the actual data for each channel */
313 WDL_TypedBuf<sample*> mScratchData[2];
314 /* A list of IChannelData structures corresponding to every input/output channel */
315 WDL_PtrList<IChannelData<>> mChannelData[2];
317 std::unique_ptr<NChanDelayLine<sample>> mLatencyDelay = nullptr;
318protected: // protected because it needs to be access by the API classes, and don't want a setter/getter
321};
322
323END_IPLUG_NAMESPACE
IPlug Constant definitions, Types, magic numbers.
Include to get consistently named preprocessor macros for different platforms and logging functionali...
Utility functions and macros.
The base class for IPlug Audio Processing.
bool GetTailIsInfinite() const
virtual bool SendMidiMsgs(WDL_TypedBuf< IMidiMsg > &msgs)
Send a collection of MIDI messages // TODO: info about what thread should this be called on or not ca...
const IOConfig * GetIOConfig(int idx) const
virtual bool SendSysEx(const ISysEx &msg)
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
int GetTailSize() const
bool GetTransportIsRunning() const
double GetSamplePos() const
virtual void SetTailSize(int tailSize)
Call this method if you need to update the tail size at runtime, for example if the decay time of you...
virtual void ProcessMidiMsg(const IMidiMsg &msg)
Override this method to handle incoming MIDI messages.
bool LegalIO(int NInputChans, int NOutputChans) const
Check if a certain configuration of input channels and output channels is allowed based on the channe...
int NOutChansConnected() const
Convenience method to find out how many output channels are connected.
bool HasSidechainInput() const
virtual void GetBusName(ERoute direction, int busIdx, int nBuses, WDL_String &str) const
Get the name for a particular bus.
virtual void SetLatency(int latency)
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
bool IsMidiEffect() const
bool IsInstrument() const
int MaxNBuses(ERoute direction, int *pConfigIdxWithTheMostBuses=nullptr) const
Used to determine the maximum number of input or output buses based on what was specified in the chan...
virtual bool SendMidiMsg(const IMidiMsg &msg)=0
Send a single MIDI message // TODO: info about what thread should this be called on or not called on!
bool GetRenderingOffline() const
bool DoesMPE() const
void SetChannelLabel(ERoute direction, int idx, const char *formatStr, bool zeroBased=false)
This allows you to label input/output channels in supporting VST2 hosts.
int GetAUPluginType() const
bool DoesMIDIIn() const
int NChannelsConnected(ERoute direction) const
double GetSampleRate() const
bool IsChannelConnected(ERoute direction, int chIdx) const
double GetTempo() const
int GetIOConfigWithChanCounts(std::vector< int > &inputBuses, std::vector< int > &outputBuses)
int GetBlockSize() const
int MaxNChannelsForBus(ERoute direction, int busIdx) const
For a given input or output bus what is the maximum possible number of channels.
ITimeInfo mTimeInfo
Contains detailed information about the transport state.
bool GetBypassed() const
int NIOConfigs() const
bool HasWildcardBus(ERoute direction) const
Check if we have any wildcard characters in the channel I/O configs.
virtual void ProcessSysEx(const ISysEx &msg)
Override this method to handle incoming MIDI System Exclusive (SysEx) messages.
int NInChansConnected() const
Convenience method to find out how many input channels are connected.
int MaxNChannels(ERoute direction) const
void LimitToStereoIO()
This is called by IPlugVST in order to limit a plug-in to stereo I/O for certain picky hosts.
void GetTimeSig(int &numerator, int &denominator) const
virtual void OnActivate(bool active)
Override OnActivate() which should be called by the API class when a plug-in is "switched on" by the ...
int GetLatency() const
bool DoesMIDIOut() const
static int ParseChannelIOStr(const char *IOStr, WDL_PtrList< IOConfig > &channelIOList, int &totalNInChans, int &totalNOutChans, int &totalNInBuses, int &totalNOutBuses)
A static method to parse the config.h channel I/O string.
virtual void OnReset()
Override this method in your plug-in class to do something prior to playback etc.
double GetPPQPos() const
virtual void ProcessBlock(sample **inputs, sample **outputs, int nFrames)
Override in your plug-in class to process audio In ProcessBlock you are always guaranteed to get vali...
double GetSamplesPerBeat() const
ERoute
Used to identify whether a bus/channel connection is an input or an output.
Encapsulates information about the host transport state.
Definition: IPlugStructs.h:585
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
An IOConfig is used to store bus info for each input/output configuration defined in the channel io s...
Definition: IPlugStructs.h:504
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:539