iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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
28BEGIN_IPLUG_NAMESPACE
29
49{
50public:
51 IEditorDelegate(int nParams)
52 {
53 for (int i = 0; i < nParams; i++)
54 AddParam();
55 }
56
57 virtual ~IEditorDelegate()
58 {
59 mParams.Empty(true);
60 }
61
62 IEditorDelegate(const IEditorDelegate&) = delete;
63 IEditorDelegate& operator=(const IEditorDelegate&) = delete;
64
68 IParam* AddParam() { return mParams.Add(new IParam()); }
69
73 void RemoveParam(int idx) { return mParams.Delete(idx); }
74
78 IParam* GetParam(int paramIdx) { return mParams.Get(paramIdx); }
79
83 const IParam* GetParam(int paramIdx) const { return mParams.Get(paramIdx); }
84
86 int NParams() const { return mParams.GetSize(); }
87
90 virtual void* OpenWindow(void* pParent) { OnUIOpen(); return nullptr; }
91
93 virtual void CloseWindow() { OnUIClose(); }
94
96 virtual void OnParentWindowResize(int width, int height) { /* NO-OP*/ }
97
98#pragma mark - Methods you may want to override...
101
103 virtual void OnUIClose() {};
104
110 virtual void OnParamChange(int paramIdx, EParamSource source, int sampleOffset = -1)
111 {
112 Trace(TRACELOC, "idx:%i src:%s\n", paramIdx, ParamSourceStrs[source]);
113 OnParamChange(paramIdx);
114 }
115
118 virtual void OnParamChange(int paramIdx) {}
119
124 virtual void OnParamChangeUI(int paramIdx, EParamSource source = kUnknown) {};
125
129 virtual void OnParamReset(EParamSource source)
130 {
131 for (int i = 0; i < NParams(); ++i)
132 {
133 OnParamChange(i, source);
134 OnParamChangeUI(i, source);
135 }
136 }
137
140 virtual void OnMidiMsgUI(const IMidiMsg& msg) {};
141
144 virtual void OnSysexMsgUI(const ISysEx& msg) {};
145
147 virtual bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) { return false; }
148
153
157 virtual bool OnKeyDown(const IKeyPress& key) { return false; }
158
162 virtual bool OnKeyUp(const IKeyPress& key) { return false; }
163
164#pragma mark - Methods for sending values TO the user interface
168 {
169 for (int i = 0; i < NParams(); ++i)
170 {
171 SendParameterValueFromDelegate(i, GetParam(i)->GetNormalized(), true);
172 }
173 }
174
182 virtual void SendControlValueFromDelegate(int ctrlTag, double normalizedValue) {};
183
192 virtual void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize = 0, const void* pData = nullptr) { OnMessage(msgTag, ctrlTag, dataSize, pData); }
193
201 virtual void SendArbitraryMsgFromDelegate(int msgTag, int dataSize = 0, const void* pData = nullptr) { OnMessage(msgTag, kNoTag, dataSize, pData); }
202
208 virtual void SendMidiMsgFromDelegate(const IMidiMsg& msg) { OnMidiMsgUI(msg); }
209
215 virtual void SendSysexMsgFromDelegate(const ISysEx& msg) { OnSysexMsgUI(msg); }
216
226 virtual void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized) { OnParamChangeUI(paramIdx, EParamSource::kDelegate); } // TODO: normalised?
227
228#pragma mark - Methods for sending values FROM the user interface
229 // The following methods are called from the user interface in order to set or query values of parameters in the class implementing IEditorDelegate
230
233 virtual void DirtyParametersFromUI() {};
234
239 virtual void BeginInformHostOfParamChangeFromUI(int paramIdx) = 0;
240
245 virtual void SendParameterValueFromUI(int paramIdx, double normalizedValue)
246 {
247 assert(paramIdx < NParams());
248
249 GetParam(paramIdx)->SetNormalized(normalizedValue);
250 OnParamChangeUI(paramIdx, EParamSource::kUI);
251 }
252
258 virtual void EndInformHostOfParamChangeFromUI(int paramIdx) = 0;
259
262 virtual bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize) { return false; }
263
268 virtual void SendMidiMsgFromUI(const IMidiMsg& msg) {};
269
275 virtual void SendSysexMsgFromUI(const ISysEx& msg) {};
276
282 virtual void SendArbitraryMsgFromUI(int msgTag, int ctrlTag = kNoTag, int dataSize = 0, const void* pData = nullptr) {};
283
284#pragma mark -
286 virtual void DeferMidiMsg(const IMidiMsg& msg) {};
287
289 virtual void DeferSysexMsg(const ISysEx& msg) {};
290
291#pragma mark - Editor resizing
292 void SetEditorSize(int width, int height) { mEditorWidth = width; mEditorHeight = height; }
293
299 void SetSizeConstraints(int widthLo, int widthHi, int heightLo, int heightHi)
300 {
301 mMinWidth = std::min(widthLo, widthHi);
302 mMaxWidth = std::max(widthLo, widthHi);
303 mMinHeight = std::min(heightLo, heightHi);
304 mMaxHeight = std::max(heightLo, heightHi);
305 }
306
308 int GetEditorWidth() const { return mEditorWidth; }
309
311 int GetEditorHeight() const { return mEditorHeight; }
312
313 int GetMinWidth() const { return mMinWidth; }
314 int GetMaxWidth() const { return mMaxWidth; }
315 int GetMinHeight() const { return mMinHeight; }
316 int GetMaxHeight() const { return mMaxHeight; }
317
322 virtual bool ConstrainEditorResize(int& w, int& h) const
323 {
324 if(w >= mMinWidth && w <= mMaxWidth && h >= mMinHeight && h <= mMaxHeight)
325 {
326 return true;
327 }
328 else
329 {
330 w = Clip(w, mMinWidth, mMaxWidth);
331 h = Clip(h, mMinHeight, mMaxHeight);
332 return false;
333 }
334 }
335
339 virtual bool SerializeEditorState(IByteChunk& chunk) const { return true; }
340
345 virtual int UnserializeEditorState(const IByteChunk& chunk, int startPos) { return startPos; }
346
349 virtual void SetScreenScale(float scale) {}
350
351 friend class IPlugAPP;
352 friend class IPlugAAX;
353 friend class IPlugVST2;
354 friend class IPlugVST3;
355 friend class IPlugVST3Controller;
356 friend class IPlugVST3Processor;
357 friend class IPlugAU;
358 friend class IPlugAUv3;
359 friend class IPlugWEB;
360 friend class IPlugWAM;
361 friend class IPlugAPIBase;
362 friend class IPluginBase;
363
364private:
366 WDL_PtrList<IParam> mParams;
367
369 int mEditorWidth = 0;
371 int mEditorHeight = 0;
373 int mMinWidth = 10, mMaxWidth = 100000, mMinHeight = 10, mMaxHeight = 100000;
374};
375
376END_IPLUG_NAMESPACE
MIDI and sysex structs/utilites.
Manages a block of memory, for plug-in settings store/recall.
Definition: IPlugStructs.h:112
This pure virtual interface delegates communication in both directions between a UI editor and someth...
IParam * AddParam()
Adds an IParam to the parameters ptr list Note: This is only used in special circumstances,...
virtual void OnSysexMsgUI(const ISysEx &msg)
Handle incoming SysEx messages sent to the user interface.
virtual int UnserializeEditorState(const IByteChunk &chunk, int startPos)
Unserializes editor state (such as scale).
virtual void OnParamReset(EParamSource source)
Called when parameters have changed to inform the plugin of the changes Override only if you need to ...
virtual void OnUIClose()
Override this method to do something before the UI is closed.
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...
virtual void OnParamChange(int paramIdx, EParamSource source, int sampleOffset=-1)
Override this method to do something to your DSP when a parameter changes.
IParam * GetParam(int paramIdx)
Get a pointer to one of the delegate's IParam objects.
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 when a parameter changes on the main/UI thread Like OnParamChang...
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...
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...
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 SendControlValueFromDelegate(int ctrlTag, double normalizedValue)
SendControlValueFromDelegate (Abbreviation: SCVFD) WARNING: should not be called on the realtime audi...
virtual void SendMidiMsgFromUI(const IMidiMsg &msg)
SendMidiMsgFromUI (Abbreviation: SMMFUI) This method should be used when sending a MIDI message from ...
virtual void OnMidiMsgUI(const IMidiMsg &msg)
Handle incoming MIDI messages sent to the user interface.
virtual void CloseWindow()
If you are not using IGraphics you can if you need to free resources etc when the window closes.
virtual void SetScreenScale(float scale)
Can be used by a host API to inform the editor of screen scale changes.
void SendCurrentParamValuesFromDelegate()
Loops through all parameters, calling SendParameterValueFromDelegate() with the current value of the ...
void SetSizeConstraints(int widthLo, int widthHi, int heightLo, int heightHi)
void RemoveParam(int idx)
Remove an IParam at a particular index Note: This is only used in special circumstances,...
virtual void DeferMidiMsg(const IMidiMsg &msg)
This method is needed, for remote editors to avoid a feedback loop.
const IParam * GetParam(int paramIdx) const
Get a const pointer to one of the delegate's IParam objects (for const methods)
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 ...
virtual void DeferSysexMsg(const ISysEx &msg)
This method is needed, for remote editors to avoid a feedback loop.
virtual bool SerializeEditorState(IByteChunk &chunk) const
Serializes the editor state (such as scale) into a binary chunk.
virtual void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized)
SendParameterValueFromDelegate (Abbreviation: SPVFD) WARNING: should not be called on the realtime au...
virtual void SendArbitraryMsgFromUI(int msgTag, int ctrlTag=kNoTag, int dataSize=0, const void *pData=nullptr)
SendArbitraryMsgFromUI (Abbreviation: SAMFUI)
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 OnKeyUp(const IKeyPress &key)
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
int GetEditorHeight() const
virtual void DirtyParametersFromUI()
When modifying a range of parameters in the editor, it can be necessary to broadcast that fact via th...
virtual void SendSysexMsgFromUI(const ISysEx &msg)
SendMidiMsgFromUI (Abbreviation: SSMFUI) If a plug-in can send Sysex data as a result of actions in t...
virtual bool OnKeyDown(const IKeyPress &key)
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
int GetEditorWidth() const
virtual void SendArbitraryMsgFromDelegate(int msgTag, int dataSize=0, const void *pData=nullptr)
SendArbitraryMsgFromDelegate (Abbreviation: SAMFD) WARNING: should not be called on the realtime audi...
virtual void SendMidiMsgFromDelegate(const IMidiMsg &msg)
SendMidiMsgFromDelegate (Abbreviation: SMMFD) WARNING: should not be called on the realtime audio thr...
virtual bool ConstrainEditorResize(int &w, int &h) const
Constrain the incoming editor width and height values based on the minimum and maximum.
virtual bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize)
If the editor changes UI dimensions, e.g.
virtual void OnRestoreState()
This is called by API classes after restoring state and by IPluginBase::RestorePreset().
virtual void SendSysexMsgFromDelegate(const ISysEx &msg)
SendSysexMsgFromDelegate (Abbreviation: SSMFD) WARNING: should not be called on the realtime audio th...
virtual void OnParentWindowResize(int width, int height)
Called by app wrappers when the OS window scaling buttons/resizers are used.
virtual void OnUIOpen()
Override this method to do something before the UI is opened.
IPlug's parameter class.
void SetNormalized(double normalizedValue)
Sets the parameter value from a normalized range (usually coming from the linked IControl)
AAX API base class for an IPlug plug-in.
Definition: IPlugAAX.h:80
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
Standalone application base class for an IPlug plug-in.
Definition: IPlugAPP.h:37
AudioUnit v2 API base class for an IPlug plug-in.
Definition: IPlugAU.h:56
AudioUnit v3 API base class for an IPlug plug-in.
Definition: IPlugAUv3.h:45
VST2.4 API base class for an IPlug plug-in.
Definition: IPlugVST2.h:36
VST3 Controller API-base class for a distributed IPlug VST3 plug-in.
VST3 base class for a non-distributed IPlug VST3 plug-in.
Definition: IPlugVST3.h:51
VST3 Processor API-base class for a distributed IPlug VST3 plug-in.
WebAudioModule (WAM) API base class.
Definition: IPlugWAM.h:31
Base class that contains plug-in info and state manipulation methods.
EParamSource
Used to identify the source of a parameter change.
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Definition: IPlugStructs.h:616
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:539