iPlug2 - C++ Audio Plug-in Framework
IPlugPluginBase.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 
18 #include "IPlugDelegate_select.h"
19 #include "IPlugParameter.h"
20 #include "IPlugStructs.h"
21 #include "IPlugLogger.h"
22 
23 BEGIN_IPLUG_NAMESPACE
24 
26 class IPluginBase : public EDITOR_DELEGATE_CLASS
27 {
28 public:
29  IPluginBase(int nParams, int nPresets);
30  virtual ~IPluginBase();
31 
32  IPluginBase(const IPluginBase&) = delete;
33  IPluginBase& operator=(const IPluginBase&) = delete;
34 
35 #pragma mark - Plug-in properties
36 
37  const char* GetPluginName() const { return mPluginName.Get(); }
38 
42  int GetPluginVersion(bool decimal) const;
43 
49  void GetPluginVersionStr(WDL_String& str) const;
50 
52  const char* GetMfrName() const { return mMfrName.Get(); }
53 
55  const char* GetProductName() const { return mProductName.Get(); }
56 
58  int GetUniqueID() const { return mUniqueID; }
59 
61  int GetMfrID() const { return mMfrID; }
62 
64  EHost GetHost() const { return mHost; }
65 
68  void GetHostStr(WDL_String& str) const { GetHostNameStr(GetHost(), str); }
69 
73  int GetHostVersion(bool decimal) const;
74 
77  void GetHostVersionStr(WDL_String& str) const;
78 
80  EAPI GetAPI() const { return mAPI; }
81 
83  const char* GetAPIStr() const;
84 
86  const char* GetArchStr() const;
87 
92  void GetBuildInfoStr(WDL_String& str, const char* date, const char* time) const;
93 
95  bool HasUI() const { return mHasUI; }
96 
98  bool GetHostResizeEnabled() const { return mHostResize; }
99 
100  /*** @return a CString with the bundle identifier (macOS/IOS only) */
101  const char* GetBundleID() const { return mBundleID.Get(); }
102 
103 #pragma mark - Parameters
104 
106  int NParamGroups() const { return mParamGroups.GetSize(); }
107 
111  int AddParamGroup(const char* name) { mParamGroups.Add(name); return NParamGroups(); }
112 
116  const char* GetParamGroupName(int idx) const { return mParamGroups.Get(idx); }
117 
120 
121 #pragma mark - State Serialization
122 
123  bool DoesStateChunks() const { return mStateChunks; }
124 
128  bool SerializeParams(IByteChunk& chunk) const;
129 
134  int UnserializeParams(const IByteChunk& chunk, int startPos);
135 
139  virtual bool SerializeState(IByteChunk& chunk) const { TRACE return SerializeParams(chunk); }
140 
146  virtual int UnserializeState(const IByteChunk& chunk, int startPos) { TRACE return UnserializeParams(chunk, startPos); }
147 
151  virtual bool SerializeVST3CtrlrState(IByteChunk& chunk) const { return true; }
152 
156  virtual int UnserializeVST3CtrlrState(const IByteChunk& chunk, int startPos) { return startPos; }
157 
160  int GetCurrentPresetIdx() const { return mCurrentPresetIdx; }
161 
164  void SetCurrentPresetIdx(int idx) { assert(idx > -1 && idx < NPresets()); mCurrentPresetIdx = idx; }
165 
167  virtual void InformHostOfPresetChange() {};
168 
169 #pragma mark - Preset Manipulation
170 
173  IPreset* GetPreset(int idx) { return mPresets.Get(idx); }
174 
178  void ModifyCurrentPreset(const char* name = 0);
179 
182  int NPresets() const { return mPresets.GetSize(); }
183 
187  bool RestorePreset(int idx);
188 
192  bool RestorePreset(const char* name);
193 
197  const char* GetPresetName(int idx) const;
198 
202  void CopyPreset(IPreset* pSrc, int destIdx, bool copyname = false)
203  {
204  IPreset* pDst = mPresets.Get(destIdx);
205 
206  pDst->mChunk.Clear();
207  pDst->mChunk.PutChunk(&pSrc->mChunk);
208  pDst->mInitialized = true;
209  strncpy(pDst->mName, pSrc->mName, MAX_PRESET_NAME_LEN - 1);
210  }
211 
218  void MakeDefaultPreset(const char* name = 0, int nPresets = 1);
219 
225  void MakePreset(const char* name, ...);
226 
234  void MakePresetFromNamedParams(const char* name, int nParamsNamed, ...);
235 
239  void MakePresetFromChunk(const char* name, IByteChunk& chunk);
240 
247  void MakePresetFromBlob(const char* name, const char* blob, int sizeOfChunk);
248 
251 
253  virtual void OnPresetsModified() {}
254 
256  void EnsureDefaultPreset();
257 
261  bool SerializePresets(IByteChunk& chunk) const;
262 
267  int UnserializePresets(const IByteChunk& chunk, int startPos);
268 
271  void DumpMakePresetSrc(const char* file) const;
272 
276  void DumpMakePresetFromNamedParamsSrc(const char* file, const char* paramEnumNames[]) const;
277 
280  void DumpPresetBlob(const char* file) const;
281 
285  bool SavePresetAsFXP(const char* file) const;
286 
290  bool SaveBankAsFXB(const char* file) const;
291 
295  bool LoadPresetFromFXP(const char* file);
296 
300  bool LoadBankFromFXB(const char* file);
301 
302 
303 #pragma mark - Parameter manipulation
304 
320  void InitParamRange(int startIdx, int endIdx, int countStart, const char* nameFmtStr, double defaultVal, double minVal, double maxVal, double step, const char* label = "", int flags = 0, const char* group = "", const IParam::Shape& shape = IParam::ShapeLinear(), IParam::EParamUnit unit = IParam::kUnitCustom, IParam::DisplayFunc displayFunc = nullptr);
321 
329  void CloneParamRange(int cloneStartIdx, int cloneEndIdx, int startIdx, const char* searchStr = "", const char* replaceStr = "", const char* newGroup = "");
330 
335  void ForParamInRange(int startIdx, int endIdx, std::function<void(int paramIdx, IParam& param)> func);
336 
340  void ForParamInGroup(const char* paramGroup, std::function<void(int paramIdx, IParam& param)> func);
341 
346  void CopyParamValues(int startIdx, int destIdx, int nParams);
347 
351  void CopyParamValues(const char* inGroup, const char* outGroup);
352 
354  void RandomiseParamValues();
355 
359  void RandomiseParamValues(int startIdx, int endIdx);
360 
363  void RandomiseParamValues(const char* paramGroup);
364 
366  void DefaultParamValues();
367 
371  void DefaultParamValues(int startIdx, int endIdx);
372 
375  void DefaultParamValues(const char* paramGroup);
376 
378  void PrintParamValues();
379 
380  friend class IPlugAPP;
381  friend class IPlugAAX;
382  friend class IPlugVST2;
383  friend class IPlugVST3;
384  friend class IPlugVST3Controller;
385  friend class IPlugVST3Processor;
386  friend class IPlugAU;
387  friend class IPlugAUv3;
388  friend class IPlugWEB;
389  friend class IPlugWAM;
390  friend class IPlugAPIBase;
391 
392 private:
393  int mCurrentPresetIdx = 0;
395  bool mStateChunks = false;
397  WDL_String mPluginName;
399  WDL_String mProductName;
401  WDL_String mMfrName;
402  /* Plug-in unique four char ID as an int */
403  int mUniqueID;
404  /* Manufacturer unique four char ID as an int */
405  int mMfrID;
407  int mVersion;
409  int mHostVersion = 0;
411  EHost mHost = kHostUninit;
413  EAPI mAPI;
415  WDL_String mBundleID;
417  bool mHasUI = false;
419  bool mHostResize = false;
421  WDL_PtrList<const char> mParamGroups;
423  WDL_PtrList<IPreset> mPresets;
424 
425 #ifdef PARAMS_MUTEX
426  friend class IPlugVST3ProcessorBase;
427 protected:
429  WDL_Mutex mParams_mutex;
430 #endif
431 };
432 
433 END_IPLUG_NAMESPACE
void MakeDefaultPreset(const char *name=0, int nPresets=1)
This method can be used to initialize baked-in factory presets with the default parameter values...
void GetBuildInfoStr(WDL_String &str, const char *date, const char *time) const
Get the build date of the plug-in and architecture/api details in one string.
const char * GetPresetName(int idx) const
Get the name a preset.
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:42
virtual void InformHostOfParameterDetailsChange()
Implemented by the API class, call this if you update parameter labels and hopefully the host should ...
void MakePreset(const char *name,...)
Create a baked-in factory preset, specifiying parameter values sequentially usage: MakePreset(name...
void PrintParamValues()
Default parameter values for a parameter group.
const char * GetArchStr() const
const char * GetProductName() const
Get the product name as a CString.
int NPresets() const
Gets the number of factory presets.
void CloneParamRange(int cloneStartIdx, int cloneEndIdx, int startIdx, const char *searchStr="", const char *replaceStr="", const char *newGroup="")
Clone a range of parameters, optionally doing a string substitution on the parameter name...
const char * GetAPIStr() const
void Clear()
Clears the chunk (resizes to 0)
Definition: IPlugStructs.h:214
virtual void InformHostOfPresetChange()
Implemented by the API class, called by the UI (etc) when the plug-in initiates a program/preset chan...
void DumpMakePresetSrc(const char *file) const
Writes a call to MakePreset() for the current preset to a new text file.
void ForParamInGroup(const char *paramGroup, std::function< void(int paramIdx, IParam &param)> func)
Modify a parameter group simulataneously.
void MakePresetFromNamedParams(const char *name, int nParamsNamed,...)
Create a baked-in factory preset, specifiying parameter values with a list of parameter index and val...
IPlug&#39;s parameter class.
void GetHostVersionStr(WDL_String &str) const
Get the host version number as a string.
Standalone application base class for an IPlug plug-in.
Definition: IPlugAPP.h:35
void PruneUninitializedPresets()
[AUV2 only] Removes any presets that weren&#39;t initialized
void SetCurrentPresetIdx(int idx)
Set the index of the current, active preset.
void RandomiseParamValues()
Randomise all parameters.
IPlug&#39;s parameter class.
void GetPluginVersionStr(WDL_String &str) const
Gets the plug-in version as a string.
bool DoesStateChunks() const
virtual bool SerializeState(IByteChunk &chunk) const
Override this method to serialize custom state data, if your plugin does state chunks.
AudioUnit v3 API base class for an IPlug plug-in.
Definition: IPlugAUv3.h:42
int GetMfrID() const
EHost
Host identifier.
const char * GetParamGroupName(int idx) const
Get the parameter group name as a particular index.
Base struct for parameter shaping.
void EnsureDefaultPreset()
[VST2 only] Called to fill uninitialzed presets
void GetHostStr(WDL_String &str) const
Get the host name as a CString.
void DumpPresetBlob(const char *file) const
Writes a call to MakePresetFromBlob() for the current preset to a new text file.
IPlug logging a.k.a tracing functionality.
VST3 Processor API-base class for a distributed IPlug VST3 plug-in.
Manages a block of memory, for plug-in settings store/recall.
Definition: IPlugStructs.h:111
EAPI GetAPI() const
void DefaultParamValues()
Set all parameters to their default values.
int UnserializePresets(const IByteChunk &chunk, int startPos)
[VST2 only] Called when the VST2 host calls effSetChunk for a bank *
void CopyPreset(IPreset *pSrc, int destIdx, bool copyname=false)
Copy source preset to preset at index.
VST2.4 API base class for an IPlug plug-in.
Definition: IPlugVST2.h:34
void MakePresetFromBlob(const char *name, const char *blob, int sizeOfChunk)
Creates a preset from a base64 encoded CString.
AAX API base class for an IPlug plug-in.
Definition: IPlugAAX.h:77
int UnserializeParams(const IByteChunk &chunk, int startPos)
Unserializes double precision floating point, non-normalised values from a byte chunk into mParams...
const char * GetPluginName() const
VST3 base class for a non-distributed IPlug VST3 plug-in.
Definition: IPlugVST3.h:45
IPreset * GetPreset(int idx)
Get a ptr to a factory preset @ param idx The index number of the preset you are referring to...
virtual int UnserializeState(const IByteChunk &chunk, int startPos)
Override this method to unserialize custom state data, if your plugin does state chunks.
int GetUniqueID() const
A struct used for specifying baked-in factory presets.
Definition: IPlugStructs.h:598
std::function< void(double, WDL_String &)> DisplayFunc
DisplayFunc allows custom parameter display functions, defined by a lambda matching this signature...
const char * GetMfrName() const
Get the manufacturer name as a CString.
int GetHostVersion(bool decimal) const
Get the host version number as an integer.
bool LoadPresetFromFXP(const char *file)
Load VST2 format preset.
int GetCurrentPresetIdx() const
Get the index of the current, active preset.
void ModifyCurrentPreset(const char *name=0)
This method should update the current preset with current values NOTE: This is only relevant for VST2...
Used for choosing an editor delegate.
EHost GetHost() const
bool LoadBankFromFXB(const char *file)
Load VST2 format bank [VST2 only].
bool GetHostResizeEnabled() const
bool SerializeParams(IByteChunk &chunk) const
Serializes the current double precision floating point, non-normalised values (IParam::mValue) of all...
EParamUnit
Used by AudioUnit plugins to determine the appearance of parameters, based on the kind of data they r...
bool RestorePreset(int idx)
Restore a preset by index.
void ForParamInRange(int startIdx, int endIdx, std::function< void(int paramIdx, IParam &param)> func)
Modify a range of parameters with a lamda function.
void MakePresetFromChunk(const char *name, IByteChunk &chunk)
Creates a preset from an IByteChunk containging serialized data.
Shared VST3 processor code.
bool SavePresetAsFXP(const char *file) const
Save current state as a VST2 format preset.
int AddParamGroup(const char *name)
Called to add a parameter group name, when a unique group name is discovered.
VST3 Controller API-base class for a distributed IPlug VST3 plug-in.
AudioUnit v2 API base class for an IPlug plug-in.
Definition: IPlugAU.h:54
virtual int UnserializeVST3CtrlrState(const IByteChunk &chunk, int startPos)
VST3 ONLY! - THIS IS ONLY INCLUDED FOR COMPATIBILITY - NOONE ELSE SHOULD NEED IT! ...
void DumpMakePresetFromNamedParamsSrc(const char *file, const char *paramEnumNames[]) const
Writes a call to MakePresetFromNamedParams() for the current preset to a new text file...
bool HasUI() const
int PutChunk(const IByteChunk *pRHS)
Put another IByteChunk into this one.
Definition: IPlugStructs.h:208
int NParamGroups() const
void InitParamRange(int startIdx, int endIdx, int countStart, const char *nameFmtStr, double defaultVal, double minVal, double maxVal, double step, const char *label="", int flags=0, const char *group="", const IParam::Shape &shape=IParam::ShapeLinear(), IParam::EParamUnit unit=IParam::kUnitCustom, IParam::DisplayFunc displayFunc=nullptr)
Initialise a range of parameters simultaneously.
int GetPluginVersion(bool decimal) const
Get the plug-in version number.
void CopyParamValues(int startIdx, int destIdx, int nParams)
Copy a range of parameter values.
bool SerializePresets(IByteChunk &chunk) const
[VST2 only] Called when the VST2 host calls effGetChunk for a bank *
Linear parameter shaping.
bool SaveBankAsFXB(const char *file) const
Save current bank as a VST2 format bank [VST2 only].
Base class that contains plug-in info and state manipulation methods.
virtual void OnPresetsModified()
[VST2 only] Called when the preset name is changed by the host
static void GetHostNameStr(EHost host, WDL_String &str)
Gets a human-readable name from host identifier.
WebAudioModule (WAM) API base class.
Definition: IPlugWAM.h:28
virtual bool SerializeVST3CtrlrState(IByteChunk &chunk) const
VST3 ONLY! - THIS IS ONLY INCLUDED FOR COMPATIBILITY - NOONE ELSE SHOULD NEED IT! ...