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
48{
49public:
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...
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
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 -
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 virtual 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
363private:
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
375END_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