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 <memory>
20#include <vector>
21
22#include "ptrlist.h"
23
24#include "IPlugPlatform.h"
25#include "IPlugConstants.h"
26#include "IPlugStructs.h"
27#include "IPlugUtilities.h"
28#include "NChanDelay.h"
29
35BEGIN_IPLUG_NAMESPACE
36
37struct Config;
38
41{
42public:
46 IPlugProcessor(const Config& config, EAPI plugAPI);
47 virtual ~IPlugProcessor();
48
49 IPlugProcessor(const IPlugProcessor&) = delete;
50 IPlugProcessor& operator=(const IPlugProcessor&) = delete;
51
52#pragma mark - Methods you implement in your plug-in class - you do not call these methods
53
62 virtual void ProcessBlock(sample** inputs, sample** outputs, int nFrames);
63
68 virtual void ProcessMidiMsg(const IMidiMsg& msg);
69
72 virtual void ProcessSysEx(ISysEx& msg) {}
73
75 virtual void OnReset() { TRACE }
76
81 virtual void OnActivate(bool active) { TRACE }
82
83#pragma mark - Methods you can call - some of which have custom implementations in the API classes, some implemented in IPlugProcessor.cpp
84
88 virtual bool SendMidiMsg(const IMidiMsg& msg) = 0;
89
93 virtual bool SendMidiMsgs(WDL_TypedBuf<IMidiMsg>& msgs);
94
98 virtual bool SendSysEx(const ISysEx& msg) { return false; }
99
101 double GetSampleRate() const { return mSampleRate; }
102
104 int GetBlockSize() const { return mBlockSize; }
105
107 int GetLatency() const { return mLatency; }
108
110 int GetTailSize() { return mTailSize; }
111
113 bool GetBypassed() const { return mBypassed; }
114
116 bool GetRenderingOffline() const { return mRenderingOffline; };
117
118#pragma mark -
120 double GetSamplePos() const { return mTimeInfo.mSamplePos; }
121
123 double GetTempo() const { return mTimeInfo.mTempo; }
124
126 double GetPPQPos() const { return mTimeInfo.mPPQPos; }
127
129 bool GetTransportIsRunning() const { return mTimeInfo.mTransportIsRunning; }
130
132 double GetSamplesPerBeat() const;
133
136 void GetTimeSig(int& numerator, int& denominator) const { numerator = mTimeInfo.mNumerator; denominator = mTimeInfo.mDenominator; }
137
138#pragma mark -
139
145 virtual void GetBusName(ERoute direction, int busIdx, int nBuses, WDL_String& str) const;
146
148 int NIOConfigs() const { return mIOConfigs.GetSize(); }
149
151 const IOConfig* GetIOConfig(int idx) const { return mIOConfigs.Get(idx); }
152
154 int GetIOConfigWithChanCounts(std::vector<int>& inputBuses, std::vector<int>& outputBuses);
155
160 int MaxNBuses(ERoute direction, int* pConfigIdxWithTheMostBuses = nullptr) const;
161
166 int MaxNChannelsForBus(ERoute direction, int busIdx) const;
167
171 bool HasWildcardBus(ERoute direction) const { return mIOConfigs.Get(0)->ContainsWildcard(direction); } // \todo only supports a single I/O config
172
175 int MaxNChannels(ERoute direction) const { return mChannelData[direction].GetSize(); }
176
180 bool IsChannelConnected(ERoute direction, int chIdx) const { return (chIdx < mChannelData[direction].GetSize() && mChannelData[direction].Get(chIdx)->mConnected); }
181
184 int NChannelsConnected(ERoute direction) const;
185
188 inline int NInChansConnected() const { return NChannelsConnected(ERoute::kInput); }
189
192 inline int NOutChansConnected() const { return NChannelsConnected(ERoute::kOutput); }
193
198 bool LegalIO(int NInputChans, int NOutputChans) const; //TODO: this should be updated
199
201 bool HasSidechainInput() const { return MaxNBuses(ERoute::kInput) > 1; }
202
204 void LimitToStereoIO();//TODO: this should be updated
205
207 bool IsInstrument() const { return mPlugType == EIPlugPluginType::kInstrument; }
208
210 bool IsMidiEffect() const { return mPlugType == EIPlugPluginType::kMIDIEffect; }
211
213 int GetAUPluginType() const;
214
216 bool DoesMIDIIn() const { return mDoesMIDIIn; }
217
219 bool DoesMIDIOut() const { return mDoesMIDIOut; }
220
222 bool DoesMPE() const { return mDoesMPE; }
223
230 void SetChannelLabel(ERoute direction, int idx, const char* formatStr, bool zeroBased = false);
231
235 virtual void SetLatency(int latency);
236
241 void SetTailSize(int tailSize) { mTailSize = tailSize; }
242
254 static int ParseChannelIOStr(const char* IOStr, WDL_PtrList<IOConfig>& channelIOList, int& totalNInChans, int& totalNOutChans, int& totalNInBuses, int& totalNOutBuses);
255
256protected:
257#pragma mark - Methods called by the API class - you do not call these methods in your plug-in class
258 void SetChannelConnections(ERoute direction, int idx, int n, bool connected);
259 void InitLatencyDelay();
260
261 //The following methods are duplicated, in order to deal with either single or double precision processing,
262 //depending on the value of arguments passed in
263 void AttachBuffers(ERoute direction, int idx, int n, PLUG_SAMPLE_DST** ppData, int nFrames);
264 void AttachBuffers(ERoute direction, int idx, int n, PLUG_SAMPLE_SRC** ppData, int nFrames);
265 void PassThroughBuffers(PLUG_SAMPLE_SRC type, int nFrames);
266 void PassThroughBuffers(PLUG_SAMPLE_DST type, int nFrames);
267 void ProcessBuffers(PLUG_SAMPLE_SRC type, int nFrames);
268 void ProcessBuffers(PLUG_SAMPLE_DST type, int nFrames);
269 void ProcessBuffersAccumulating(int nFrames); // only for VST2 deprecated method single precision
270 void ZeroScratchBuffers();
271 void SetSampleRate(double sampleRate) { mSampleRate = sampleRate; }
272 void SetBlockSize(int blockSize);
273 void SetBypassed(bool bypassed) { mBypassed = bypassed; }
274 void SetTimeInfo(const ITimeInfo& timeInfo) { mTimeInfo = timeInfo; }
275 void SetRenderingOffline(bool renderingOffline) { mRenderingOffline = renderingOffline; }
276 const WDL_String& GetChannelLabel(ERoute direction, int idx) { return mChannelData[direction].Get(idx)->mLabel; }
277
278private:
280 EIPlugPluginType mPlugType;
282 bool mDoesMIDIIn;
284 bool mDoesMIDIOut;
286 bool mDoesMPE;
288 int mLatency;
290 double mSampleRate = DEFAULT_SAMPLE_RATE;
292 int mBlockSize = 0;
294 int mTailSize = 0;
296 bool mBypassed = false;
298 bool mRenderingOffline = false;
300 WDL_PtrList<IOConfig> mIOConfigs;
301 /* Manages pointers to the actual data for each channel */
302 WDL_TypedBuf<sample*> mScratchData[2];
303 /* A list of IChannelData structures corresponding to every input/output channel */
304 WDL_PtrList<IChannelData<>> mChannelData[2];
306 std::unique_ptr<NChanDelayLine<sample>> mLatencyDelay = nullptr;
307protected: // protected because it needs to be access by the API classes, and don't want a setter/getter
310};
311
312END_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.
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
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 bool SendSysEx(const ISysEx &msg)
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
bool GetTransportIsRunning() const
double GetSamplePos() const
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.
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 ProcessSysEx(ISysEx &msg)
Override this method to handle incoming MIDI System Exclusive (SysEx) messages.
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