iPlug2 - C++ Audio Plug-in Framework
IPlugAPIBase.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 <memory>
16 
17 #include "ptrlist.h"
18 #include "mutex.h"
19 
20 #include "IPlugPlatform.h"
21 #include "IPlugPluginBase.h"
22 #include "IPlugConstants.h"
23 #include "IPlugStructs.h"
24 #include "IPlugUtilities.h"
25 #include "IPlugParameter.h"
26 #include "IPlugQueue.h"
27 #include "IPlugTimer.h"
28 
36 BEGIN_IPLUG_NAMESPACE
37 
38 struct Config;
39 
42 class IPlugAPIBase : public IPluginBase
43 {
44 
45 public:
46  IPlugAPIBase(Config config, EAPI plugAPI);
47  virtual ~IPlugAPIBase();
48 
49  IPlugAPIBase(const IPlugAPIBase&) = delete;
50  IPlugAPIBase& operator=(const IPlugAPIBase&) = delete;
51 
52 #pragma mark - Methods you can implement/override in your plug-in class - you do not call these methods
53 
59  virtual bool CompareState(const uint8_t* pIncomingState, int startPos) const;
60 
61  /* implement this and return true to trigger your custom about box, when someone clicks about in the menu of a standalone app or VST3 plugin */
62  virtual bool OnHostRequestingAboutBox() { return false; }
63 
64  /* implement this and return true to trigger your custom help info, when someone clicks help in the menu of a standalone app or VST3 plugin */
65  virtual bool OnHostRequestingProductHelp() { return false; }
66 
69  virtual void OnHostIdentified() {}
70 
74  virtual void OnHostRequestingImportantParameters(int count, WDL_TypedBuf<int>& results);
75 
80  virtual bool OnHostRequestingSupportedViewConfiguration(int width, int height) { return true; }
81 
85  virtual void OnHostSelectedViewConfiguration(int width, int height) {}
86 
92  virtual bool GetMidiNoteText(int noteNumber, char* str) const { *str = '\0'; return false; }
93 
97  virtual void* GetAAXViewInterface()
98  {
99 #ifndef NO_IGRAPHICS
100  return (void*) GetUI();
101 #else
102  return nullptr;
103 #endif
104  }
105 
107  virtual void OnIdle() {}
108 
109 #pragma mark - Methods you can call - some of which have custom implementations in the API classes, some implemented in IPlugAPIBase.cpp
110 
114  void SetParameterValue(int paramIdx, double normalizedValue);
115 
117  virtual void GetTrackColor(int& r, int& g, int& b) { r = 0; g = 0; b = 0; }
118 
120  virtual void GetTrackName(WDL_String& str) {}
121 
123  virtual int GetTrackIndex() { return 0; }
124 
126  virtual void GetTrackNamespace(WDL_String& str) {}
127 
129  virtual int GetTrackNamespaceIndex() { return 0; }
130 
133  virtual void DirtyParametersFromUI() override;
134 
135 #pragma mark - Methods called by the API class - you do not call these methods in your plug-in class
136 
142  virtual void SendParameterValueFromAPI(int paramIdx, double value, bool normalized);
143 
147  void SetHost(const char* host, int version);
148 
151  virtual void HostSpecificInit() {}
152 
153  //IEditorDelegate
154  void BeginInformHostOfParamChangeFromUI(int paramIdx) override { BeginInformHostOfParamChange(paramIdx); }
155 
156  void EndInformHostOfParamChangeFromUI(int paramIdx) override { EndInformHostOfParamChange(paramIdx); }
157 
158  bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize) override;
159 
160  void SendParameterValueFromUI(int paramIdx, double normalisedValue) override
161  {
162  SetParameterValue(paramIdx, normalisedValue);
163  IPluginBase::SendParameterValueFromUI(paramIdx, normalisedValue);
164  }
165 
166  //These are handled in IPlugAPIBase for non DISTRIBUTED APIs
167  void SendMidiMsgFromUI(const IMidiMsg& msg) override;
168 
169  void SendSysexMsgFromUI(const ISysEx& msg) override;
170 
171  void SendArbitraryMsgFromUI(int msgTag, int ctrlTag = kNoTag, int dataSize = 0, const void* pData = nullptr) override;
172 
173  void DeferMidiMsg(const IMidiMsg& msg) override { mMidiMsgsFromEditor.Push(msg); }
174 
175  void DeferSysexMsg(const ISysEx& msg) override
176  {
177  SysExData data(msg.mOffset, msg.mSize, msg.mData); // copies data
178  mSysExDataFromEditor.Push(data);
179  }
180 
182  void CreateTimer();
183 
184 private:
187  virtual bool EditorResize(int width, int height) { return false; }
188 
191  virtual void BeginInformHostOfParamChange(int paramIdx) {}
192 
195  virtual void EndInformHostOfParamChange(int paramIdx) {}
196 
200  virtual void InformHostOfParamChange(int paramIdx, double normalizedValue) {}
201 
202  //DISTRIBUTED ONLY (Currently only VST3)
204  virtual void TransmitMidiMsgFromProcessor(const IMidiMsg& msg) {}
205 
207  virtual void TransmitSysExDataFromProcessor(const SysExData& data) {}
208 
209  void OnTimer(Timer& t);
210 
211  friend class IPlugAPP;
212  friend class IPlugAAX;
213  friend class IPlugVST2;
214  friend class IPlugVST3;
215  friend class IPlugVST3Controller;
216  friend class IPlugVST3Processor;
217  friend class IPlugAU;
218  friend class IPlugAUv3;
219  friend class IPlugWEB;
220  friend class IPlugWAM;
221 
222 private:
223  WDL_String mParamDisplayStr;
224  std::unique_ptr<Timer> mTimer;
225 
226  IPlugQueue<ParamTuple> mParamChangeFromProcessor {PARAM_TRANSFER_SIZE};
227  IPlugQueue<IMidiMsg> mMidiMsgsFromEditor {MIDI_TRANSFER_SIZE}; // a queue of midi messages generated in the editor by clicking keyboard UI etc
228  IPlugQueue<IMidiMsg> mMidiMsgsFromProcessor {MIDI_TRANSFER_SIZE}; // a queue of MIDI messages received (potentially on the high priority thread), by the processor to send to the editor
229  IPlugQueue<SysExData> mSysExDataFromEditor {SYSEX_TRANSFER_SIZE}; // a queue of SYSEX data to send to the processor
230  IPlugQueue<SysExData> mSysExDataFromProcessor {SYSEX_TRANSFER_SIZE}; // a queue of SYSEX data to send to the editor
231  SysExData mSysexBuf;
232 };
233 
234 END_IPLUG_NAMESPACE
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:42
Utility functions and macros.
virtual void OnHostRequestingImportantParameters(int count, WDL_TypedBuf< int > &results)
Called by AUv3 plug-ins to get the "overview parameters".
A lock-free SPSC queue used to transfer data between threads based on MLQueue.h by Randy Jones based ...
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:30
virtual void SendParameterValueFromAPI(int paramIdx, double value, bool normalized)
This is called from the plug-in API class in order to update UI controls linked to plug-in parameters...
bool Push(const T &item)
Definition: IPlugQueue.h:55
Include to get consistently named preprocessor macros for different platforms and logging functionali...
Standalone application base class for an IPlug plug-in.
Definition: IPlugAPP.h:35
virtual bool GetMidiNoteText(int noteNumber, char *str) const
Override this method to provide custom text linked to MIDI note numbers in API classes that support t...
Definition: IPlugAPIBase.h:92
virtual bool OnHostRequestingSupportedViewConfiguration(int width, int height)
Called by AUv3 plug-in hosts to query support for multiple UI sizes.
Definition: IPlugAPIBase.h:80
IPlug&#39;s parameter class.
virtual void GetTrackName(WDL_String &str)
Get the name of the track that the plug-in is inserted on.
Definition: IPlugAPIBase.h:120
virtual void HostSpecificInit()
This method is implemented in some API classes, in order to do specific initialisation for particular...
Definition: IPlugAPIBase.h:151
AudioUnit v3 API base class for an IPlug plug-in.
Definition: IPlugAUv3.h:42
VST3 Processor API-base class for a distributed IPlug VST3 plug-in.
Base class for timer.
Definition: IPlugTimer.h:39
virtual int GetTrackIndex()
Get the index of the track that the plug-in is inserted on.
Definition: IPlugAPIBase.h:123
VST2.4 API base class for an IPlug plug-in.
Definition: IPlugVST2.h:34
virtual void GetTrackNamespace(WDL_String &str)
Get the namespace of the track that the plug-in is inserted on.
Definition: IPlugAPIBase.h:126
AAX API base class for an IPlug plug-in.
Definition: IPlugAAX.h:77
Base class that contains plug-in info and state manipulation methods.
VST3 base class for a non-distributed IPlug VST3 plug-in.
Definition: IPlugVST3.h:45
virtual bool CompareState(const uint8_t *pIncomingState, int startPos) const
Override this method to implement a custom comparison of incoming state data with your plug-ins state...
IPlug Constant definitions, Types, magic numbers.
void CreateTimer()
Called by the API class to create the timer that pumps the parameter/message queues.
virtual void DirtyParametersFromUI() override
In a distributed VST3 or WAM plugin, if you modify the parameters on the UI side (e.g.
virtual int GetTrackNamespaceIndex()
Get the namespace index of the track that the plug-in is inserted on.
Definition: IPlugAPIBase.h:129
virtual void OnHostSelectedViewConfiguration(int width, int height)
Called by some AUv3 plug-in hosts when a particular UI size is selected.
Definition: IPlugAPIBase.h:85
This file includes classes for implementing timers - in order to get a regular callback on the main t...
virtual void OnIdle()
Override this method to get an "idle"" call on the main thread.
Definition: IPlugAPIBase.h:107
virtual void GetTrackColor(int &r, int &g, int &b)
Get the color of the track that the plug-in is inserted on.
Definition: IPlugAPIBase.h:117
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
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:538
This structure is used when queueing Sysex messages.
Definition: IPlugStructs.h:44
void SetParameterValue(int paramIdx, double normalizedValue)
SetParameterValue is called from the UI in the middle of a parameter change gesture (possibly via del...
Base class that contains plug-in info and state manipulation methods.
virtual void * GetAAXViewInterface()
You need to implement this method if you are not using IGraphics and you want to support AAX&#39;s view i...
Definition: IPlugAPIBase.h:97
void SetHost(const char *host, int version)
Called to set the name of the current host, if known (calls on to HostSpecificInit() and OnHostIdenti...
virtual void OnHostIdentified()
Implement this to do something specific when IPlug becomes aware of the particular host that is hosti...
Definition: IPlugAPIBase.h:69
WebAudioModule (WAM) API base class.
Definition: IPlugWAM.h:28