iPlug 2: IGraphicsEditorDelegate.cpp Source File

1

2

3

4

5

6

7

8

9

10

14

15using namespace iplug;

16using namespace igraphics;

17

18IGEditorDelegate::IGEditorDelegate(int nParams)

20{

21}

22

23IGEditorDelegate::~IGEditorDelegate()

24{

25}

26

28{

29 if(!mGraphics)

30 {

31 mGraphics = std::unique_ptr<IGraphics>(CreateGraphics());

32 if (mLastWidth && mLastHeight && mLastScale)

33 GetUI()->Resize(mLastWidth, mLastHeight, mLastScale);

34 }

35

36 if(mGraphics)

37 return mGraphics->OpenWindow(pParent);

38 else

39 return nullptr;

40}

41

43{

44 if (!mClosing)

45 {

46 mClosing = true;

48

49 if (mGraphics)

50 {

51 mLastWidth = mGraphics->Width();

52 mLastHeight = mGraphics->Height();

53 mLastScale = mGraphics->GetDrawScale();

54 mGraphics->CloseWindow();

55 mGraphics = nullptr;

56 }

57

58 mClosing = false;

59 }

60}

61

63{

64 if (auto* pGraphics = GetUI())

65 {

66 const auto scale = pGraphics->GetPlatformWindowScale();

67 pGraphics->Resize(static_cast<int>(width / scale), static_cast<int>(height / scale), 1.0f, false);

68 }

69}

70

72{

74 mGraphics->SetScreenScale(scale);

75}

76

78{

79 if(!mGraphics)

80 return;

81

82 IControl* pControl = mGraphics->GetControlWithTag(ctrlTag);

83

84 assert(pControl);

85

86 if(pControl)

87 {

89 }

90}

91

93{

94 if(!mGraphics)

95 return;

96

97 IControl* pControl = mGraphics->GetControlWithTag(ctrlTag);

98

99 assert(pControl);

100

101 if(pControl)

102 {

104 }

105}

106

108{

109 if(mGraphics)

110 {

111 if (!normalized)

113

114 for (int c = 0; c < mGraphics->NControls(); c++)

115 {

116 IControl* pControl = mGraphics->GetControl(c);

117

118 int nVals = pControl->NVals();

119

120 for(int v = 0; v < nVals; v++)

121 {

122 if (pControl->GetParamIdx(v) == paramIdx)

123 {

125

126 }

127 }

128

129 }

130 }

131

133}

134

136{

137 if(mGraphics)

138 {

139 for (auto c = 0; c < mGraphics->NControls(); c++)

140 {

141 IControl* pControl = mGraphics->GetControl(c);

142

144 {

145 pControl->OnMidi(msg);

146 }

147 }

148 }

149

151}

152

154{

155 bool savedOK = true;

156

157 int width = mGraphics ? mGraphics->Width() : mLastWidth;

158 int height = mGraphics ? mGraphics->Height() : mLastHeight;

159 float scale = mGraphics ? mGraphics->GetDrawScale() : mLastScale;

160

161 savedOK &= (data.Put(&width) > 0);

162 savedOK &= (data.Put(&height) > 0);

163 savedOK &= (data.Put(&scale) > 0);

164

165 return savedOK;

166}

167

169{

170 int width = 0;

171 int height = 0;

172 float scale = 0.f;

173

174 startPos = data.Get(&width, startPos);

175 startPos = data.Get(&height, startPos);

176 startPos = data.Get(&scale, startPos);

177

179 {

180 if (width && height && scale)

182 }

183 else

184 {

185 mLastWidth = width;

186 mLastHeight = height;

187 mLastScale = scale;

188 }

189

190 return startPos;

191}

192

194{

196}

197

199{

201}

202

204{

206

207 if (pGraphics)

208 {

209 float x, y;

211 return pGraphics->OnKeyDown(x, y, key);

212 }

213 else

214 return false;

215}

216

218{

220

221 if (pGraphics)

222 {

223 float x, y;

225 return pGraphics->OnKeyUp(x, y, key);

226 }

227 else

228 return false;

229}

This file contains the base IControl implementation, along with some base classes for specific types ...

Manages a block of memory, for plug-in settings store/recall.

int Put(const T *pVal)

Copies arbitary typed data into the IByteChunk.

int Get(T *pDst, int startPos) const

Get arbitary typed data from the IByteChunk.

The lowest level base class of an IGraphics control.

bool GetWantsMidi() const

virtual void SetValueFromDelegate(double value, int valIdx=0)

Set the control's value from the delegate This method is called from the class implementing the IEdit...

int GetParamIdx(int valIdx=0) const

Get the index of a parameter that the control is linked to Normaly controls are either linked to a si...

virtual void OnMsgFromDelegate(int msgTag, int dataSize, const void *pData)

Implement to receive messages sent to the control, see IEditorDelegate:SendControlMsgFromDelegate()

virtual void OnMidi(const IMidiMsg &msg)

Implement to receive MIDI messages sent to the control if mWantsMidi == true, see IEditorDelegate:Sen...

This pure virtual interface delegates communication in both directions between a UI editor and someth...

IParam * GetParam(int paramIdx)

Get a pointer to one of the delegate's IParam objects.

virtual void CloseWindow()

If you are not using IGraphics you can if you need to free resources etc when the window closes.

virtual void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized)

SendParameterValueFromDelegate (Abbreviation: SPVFD) WARNING: should not be called on the realtime au...

virtual void SendMidiMsgFromDelegate(const IMidiMsg &msg)

SendMidiMsgFromDelegate (Abbreviation: SMMFD) WARNING: should not be called on the realtime audio thr...

bool SerializeEditorSize(IByteChunk &data) const

Serializes the size and scale of the IGraphics.

void * OpenWindow(void *pHandle) final

If you are not using IGraphics, you can implement this method to attach to the native parent view e....

int UnserializeEditorSize(const IByteChunk &chunk, int startPos)

Unserializes the size and scale of the IGraphics.

void SetScreenScale(float scale) final

Can be used by a host API to inform the editor of screen scale changes.

bool OnKeyDown(const IKeyPress &key) override

KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...

bool SerializeEditorState(IByteChunk &chunk) const override

Serializes the editor state (such as scale) into a binary chunk.

void SendControlValueFromDelegate(int ctrlTag, double normalizedValue) override

SendControlValueFromDelegate (Abbreviation: SCVFD) WARNING: should not be called on the realtime audi...

void SendMidiMsgFromDelegate(const IMidiMsg &msg) override

SendMidiMsgFromDelegate (Abbreviation: SMMFD) WARNING: should not be called on the realtime audio thr...

void OnParentWindowResize(int width, int height) override

Called by app wrappers when the OS window scaling buttons/resizers are used.

int UnserializeEditorState(const IByteChunk &chunk, int startPos) override

Unserializes editor state (such as scale).

void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize=0, const void *pData=nullptr) override

SendControlMsgFromDelegate (Abbreviation: SCMFD) WARNING: should not be called on the realtime audio ...

bool OnKeyUp(const IKeyPress &key) override

KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...

IGraphics * GetUI()

Get a pointer to the IGraphics context.

virtual IGraphics * CreateGraphics()

Called to create the IGraphics instance for this editor.

void CloseWindow() final

If you are not using IGraphics you can if you need to free resources etc when the window closes.

void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized) override

SendParameterValueFromDelegate (Abbreviation: SPVFD) WARNING: should not be called on the realtime au...

The lowest level base class of an IGraphics context.

void Resize(int w, int h, float scale, bool needsPlatformResize=true)

Resizes the graphics context to new dimensions and scale.

bool OnKeyDown(float x, float y, const IKeyPress &key)

bool OnKeyUp(float x, float y, const IKeyPress &key)

virtual void GetMouseLocation(float &x, float &y) const =0

Get the x, y position of the mouse cursor.

double ToNormalized(double nonNormalizedValue) const

Convert a real value to normalized value for this parameter.

Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...

Encapsulates a MIDI message and provides helper functions.