iPlug2 - C++ Audio Plug-in Framework
IPlugEditorDelegate.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 <cassert>
19 #include <cstring>
20 #include <stdint.h>
21 
22 #include "ptrlist.h"
23 
24 #include "IPlugParameter.h"
25 #include "IPlugMidi.h"
26 #include "IPlugStructs.h"
27 
28 BEGIN_IPLUG_NAMESPACE
29 
48 {
49 public:
50  IEditorDelegate(int nParams)
51  {
52  for (int i = 0; i < nParams; i++)
53  AddParam();
54  }
55 
56  virtual ~IEditorDelegate()
57  {
58  mParams.Empty(true);
59  }
60 
61  IEditorDelegate(const IEditorDelegate&) = delete;
62  IEditorDelegate& operator=(const IEditorDelegate&) = delete;
63 
67  IParam* AddParam() { return mParams.Add(new IParam()); }
68 
72  void RemoveParam(int idx) { return mParams.Delete(idx); }
73 
77  IParam* GetParam(int paramIdx) { return mParams.Get(paramIdx); }
78 
82  const IParam* GetParam(int paramIdx) const { return mParams.Get(paramIdx); }
83 
85  int NParams() const { return mParams.GetSize(); }
86 
89  virtual void* OpenWindow(void* pParent) { OnUIOpen(); return nullptr; }
90 
92  virtual void CloseWindow() { OnUIClose(); }
93 
95  virtual void OnParentWindowResize(int width, int height) { /* NO-OP*/ }
96 
97 #pragma mark - Methods you may want to override...
98 
100 
102  virtual void OnUIClose() {};
103 
109  virtual void OnParamChange(int paramIdx, EParamSource source, int sampleOffset = -1)
110  {
111  Trace(TRACELOC, "idx:%i src:%s\n", paramIdx, ParamSourceStrs[source]);
112  OnParamChange(paramIdx);
113  }
114 
117  virtual void OnParamChange(int paramIdx) {}
118 
123  virtual void OnParamChangeUI(int paramIdx, EParamSource source = kUnknown) {};
124 
128  virtual void OnParamReset(EParamSource source)
129  {
130  for (int i = 0; i < NParams(); ++i)
131  {
132  OnParamChange(i, source);
133  OnParamChangeUI(i, source);
134  }
135  }
136 
139  virtual void OnMidiMsgUI(const IMidiMsg& msg) {};
140 
143  virtual void OnSysexMsgUI(const ISysEx& msg) {};
144 
146  virtual bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) { return false; }
147 
152 
156  virtual bool OnKeyDown(const IKeyPress& key) { return false; }
157 
161  virtual bool OnKeyUp(const IKeyPress& key) { return false; }
162 
163 #pragma mark - Methods for sending values TO the user interface
164 
167  {
168  for (int i = 0; i < NParams(); ++i)
169  {
170  SendParameterValueFromDelegate(i, GetParam(i)->GetNormalized(), true);
171  }
172  }
173 
181  virtual void SendControlValueFromDelegate(int ctrlTag, double normalizedValue) {};
182 
191  virtual void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize = 0, const void* pData = nullptr) { OnMessage(msgTag, ctrlTag, dataSize, pData); }
192 
200  virtual void SendArbitraryMsgFromDelegate(int msgTag, int dataSize = 0, const void* pData = nullptr) { OnMessage(msgTag, kNoTag, dataSize, pData); }
201 
207  virtual void SendMidiMsgFromDelegate(const IMidiMsg& msg) { OnMidiMsgUI(msg); }
208 
214  virtual void SendSysexMsgFromDelegate(const ISysEx& msg) { OnSysexMsgUI(msg); }
215 
225  virtual void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized) { OnParamChangeUI(paramIdx, EParamSource::kDelegate); } // TODO: normalised?
226 
227 #pragma mark - Methods for sending values FROM the user interface
228  // The following methods are called from the user interface in order to set or query values of parameters in the class implementing IEditorDelegate
229 
232  virtual void DirtyParametersFromUI() {};
233 
238  virtual void BeginInformHostOfParamChangeFromUI(int paramIdx) = 0;
239 
244  virtual void SendParameterValueFromUI(int paramIdx, double normalizedValue)
245  {
246  assert(paramIdx < NParams());
247 
248  GetParam(paramIdx)->SetNormalized(normalizedValue);
249  OnParamChangeUI(paramIdx, EParamSource::kUI);
250  }
251 
257  virtual void EndInformHostOfParamChangeFromUI(int paramIdx) = 0;
258 
261  virtual bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize) { return false; }
262 
267  virtual void SendMidiMsgFromUI(const IMidiMsg& msg) {};
268 
274  virtual void SendSysexMsgFromUI(const ISysEx& msg) {};
275 
281  virtual void SendArbitraryMsgFromUI(int msgTag, int ctrlTag = kNoTag, int dataSize = 0, const void* pData = nullptr) {};
282 
283 #pragma mark -
284 
285  virtual void DeferMidiMsg(const IMidiMsg& msg) {};
286 
288  virtual void DeferSysexMsg(const ISysEx& msg) {};
289 
290 #pragma mark - Editor resizing
291  void SetEditorSize(int width, int height) { mEditorWidth = width; mEditorHeight = height; }
292 
298  void SetSizeConstraints(int widthLo, int widthHi, int heightLo, int heightHi)
299  {
300  mMinWidth = std::min(widthLo, widthHi);
301  mMaxWidth = std::max(widthLo, widthHi);
302  mMinHeight = std::min(heightLo, heightHi);
303  mMaxHeight = std::max(heightLo, heightHi);
304  }
305 
307  int GetEditorWidth() const { return mEditorWidth; }
308 
310  int GetEditorHeight() const { return mEditorHeight; }
311 
312  int GetMinWidth() const { return mMinWidth; }
313  int GetMaxWidth() const { return mMaxWidth; }
314  int GetMinHeight() const { return mMinHeight; }
315  int GetMaxHeight() const { return mMaxHeight; }
316 
321  bool ConstrainEditorResize(int& w, int& h) const
322  {
323  if(w >= mMinWidth && w <= mMaxWidth && h >= mMinHeight && h <= mMaxHeight)
324  {
325  return true;
326  }
327  else
328  {
329  w = Clip(w, mMinWidth, mMaxWidth);
330  h = Clip(h, mMinHeight, mMaxHeight);
331  return false;
332  }
333  }
334 
338  virtual bool SerializeEditorState(IByteChunk& chunk) const { return true; }
339 
344  virtual int UnserializeEditorState(const IByteChunk& chunk, int startPos) { return startPos; }
345 
348  virtual void SetScreenScale(float scale) {}
349 
350  friend class IPlugAPP;
351  friend class IPlugAAX;
352  friend class IPlugVST2;
353  friend class IPlugVST3;
354  friend class IPlugVST3Controller;
355  friend class IPlugVST3Processor;
356  friend class IPlugAU;
357  friend class IPlugAUv3;
358  friend class IPlugWEB;
359  friend class IPlugWAM;
360  friend class IPlugAPIBase;
361  friend class IPluginBase;
362 
363 private:
365  WDL_PtrList<IParam> mParams;
366 
368  int mEditorWidth = 0;
370  int mEditorHeight = 0;
372  int mMinWidth = 10, mMaxWidth = 100000, mMinHeight = 10, mMaxHeight = 100000;
373 };
374 
375 END_IPLUG_NAMESPACE
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:42
virtual void OnRestoreState()
This is called by API classes after restoring state and by IPluginBase::RestorePreset().
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:30
void SetSizeConstraints(int widthLo, int widthHi, int heightLo, int heightHi)
virtual void SetScreenScale(float scale)
Can be used by a host API to inform the editor of screen scale changes.
virtual void DeferSysexMsg(const ISysEx &msg)
This method is needed, for remote editors to avoid a feedback loop.
virtual bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void *pData)
This could be implemented in either DSP or EDITOR to receive a message from the other one...
virtual bool SerializeEditorState(IByteChunk &chunk) const
Serializes the editor state (such as scale) into a binary chunk.
virtual void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize=0, const void *pData=nullptr)
SendControlMsgFromDelegate (Abbreviation: SCMFD) WARNING: should not be called on the realtime audio ...
IPlug&#39;s parameter class.
virtual void SendParameterValueFromUI(int paramIdx, double normalizedValue)
SPVFUI Called by the UI during a parameter change gesture, in order to notify the host of the new val...
Standalone application base class for an IPlug plug-in.
Definition: IPlugAPP.h:35
virtual void BeginInformHostOfParamChangeFromUI(int paramIdx)=0
Called by the UI at the beginning of a parameter change gesture, in order to notify the host (via a c...
IPlug&#39;s parameter class.
virtual void SendArbitraryMsgFromUI(int msgTag, int ctrlTag=kNoTag, int dataSize=0, const void *pData=nullptr)
SendArbitraryMsgFromUI (Abbreviation: SAMFUI)
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.
virtual bool OnKeyDown(const IKeyPress &key)
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
Manages a block of memory, for plug-in settings store/recall.
Definition: IPlugStructs.h:111
virtual void DirtyParametersFromUI()
When modifying a range of parameters in the editor, it can be necessary to broadcast that fact via th...
virtual void OnUIClose()
Override this method to do something before the UI is closed.
VST2.4 API base class for an IPlug plug-in.
Definition: IPlugVST2.h:34
EParamSource
Used to identify the source of a parameter change.
int GetEditorWidth() const
AAX API base class for an IPlug plug-in.
Definition: IPlugAAX.h:77
bool ConstrainEditorResize(int &w, int &h) const
Constrain the incoming editor width and height values based on the minimum and maximum.
virtual void SendMidiMsgFromUI(const IMidiMsg &msg)
SendMidiMsgFromUI (Abbreviation: SMMFUI) This method should be used when sending a MIDI message from ...
VST3 base class for a non-distributed IPlug VST3 plug-in.
Definition: IPlugVST3.h:45
virtual void SendSysexMsgFromDelegate(const ISysEx &msg)
SendSysexMsgFromDelegate (Abbreviation: SSMFD) WARNING: should not be called on the realtime audio th...
void SetNormalized(double normalizedValue)
Sets the parameter value from a normalized range (usually coming from the linked IControl) ...
void SendCurrentParamValuesFromDelegate()
Loops through all parameters, calling SendParameterValueFromDelegate() with the current value of the ...
virtual void OnParamReset(EParamSource source)
Called when parameteres have changed to inform the plugin of the changes Override only if you need to...
This pure virtual interface delegates communication in both directions between a UI editor and someth...
virtual void EndInformHostOfParamChangeFromUI(int paramIdx)=0
Called by the user interface at the end of a parameter change gesture, in order to notify the host (v...
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
virtual void SendMidiMsgFromDelegate(const IMidiMsg &msg)
SendMidiMsgFromDelegate (Abbreviation: SMMFD) WARNING: should not be called on the realtime audio thr...
void RemoveParam(int idx)
Remove an IParam at a particular index Note: This is only used in special circumstances, since most plug-in formats don&#39;t support dynamic parameters.
virtual void CloseWindow()
If you are not using IGraphics you can if you need to free resources etc when the window closes...
virtual bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize)
If the editor changes UI dimensions, e.g.
virtual void OnUIOpen()
Override this method to do something before the UI is opened.
IParam * AddParam()
Adds an IParam to the parameters ptr list Note: This is only used in special circumstances, since most plug-in formats don&#39;t support dynamic parameters.
const IParam * GetParam(int paramIdx) const
Get a const pointer to one of the delegate&#39;s IParam objects (for const methods)
virtual void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized)
SendParameterValueFromDelegate (Abbreviation: SPVFD) WARNING: should not be called on the realtime au...
virtual void OnParamChange(int paramIdx)
Another version of the OnParamChange method without an EParamSource, for backwards compatibility / si...
virtual void OnParamChangeUI(int paramIdx, EParamSource source=kUnknown)
Override this method to do something to your UI when a parameter changes.
virtual void SendArbitraryMsgFromDelegate(int msgTag, int dataSize=0, const void *pData=nullptr)
SendArbitraryMsgFromDelegate (Abbreviation: SAMFD) WARNING: should not be called on the realtime audi...
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 void OnParamChange(int paramIdx, EParamSource source, int sampleOffset=-1)
Override this method to do something to your DSP when a parameter changes.
virtual int UnserializeEditorState(const IByteChunk &chunk, int startPos)
Unserializes editor state (such as scale).
virtual void SendControlValueFromDelegate(int ctrlTag, double normalizedValue)
SendControlValueFromDelegate (Abbreviation: SCVFD) WARNING: should not be called on the realtime audi...
MIDI and sysex structs/utilites.
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:538
int NParams() const
virtual bool OnKeyUp(const IKeyPress &key)
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
virtual void DeferMidiMsg(const IMidiMsg &msg)
This method is needed, for remote editors to avoid a feedback loop.
virtual void * OpenWindow(void *pParent)
If you are not using IGraphics, you can implement this method to attach to the native parent view e...
virtual void OnSysexMsgUI(const ISysEx &msg)
Handle incoming SysEx messages sent to the user interface.
Base class that contains plug-in info and state manipulation methods.
int GetEditorHeight() const
virtual void OnMidiMsgUI(const IMidiMsg &msg)
Handle incoming MIDI messages sent to the user interface.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Definition: IPlugStructs.h:612
virtual void OnParentWindowResize(int width, int height)
Called by app wrappers when the OS window scaling buttons/resizers are used.
virtual void SendSysexMsgFromUI(const ISysEx &msg)
SendMidiMsgFromUI (Abbreviation: SSMFUI) If a plug-in can send Sysex data as a result of actions in t...
IParam * GetParam(int paramIdx)
Get a pointer to one of the delegate&#39;s IParam objects.
WebAudioModule (WAM) API base class.
Definition: IPlugWAM.h:28