f@0
|
1 //
|
f@0
|
2 // AccessiblePeakMeter_controls.h
|
f@0
|
3 //
|
f@0
|
4 // Author: Fiore Martin
|
f@0
|
5 // Started from IPlugMultiTargets example in WDL-OL, by Oli Larkin - https://github.com/olilarkin/wdl-ol
|
f@0
|
6 //
|
f@0
|
7 // Licensed under the Cockos WDL License, see README.txt
|
f@0
|
8 //
|
f@0
|
9
|
f@0
|
10
|
f@0
|
11 /* Knob with a text label and a text displaying the current value */
|
f@0
|
12 class IKnobMultiControlText : public IKnobControl
|
f@0
|
13 {
|
f@0
|
14 private:
|
f@0
|
15 IRECT mDisplayRECT, mImgRECT, mNameRECT, mLabelRECT;
|
f@0
|
16 IBitmap mBitmap;
|
f@0
|
17
|
f@0
|
18 public:
|
f@0
|
19 IKnobMultiControlText(IPlugBase* pPlug, IRECT pR, int paramIdx, IBitmap* pBitmap, IText* pText, int indent = 10)
|
f@0
|
20 : IKnobControl(pPlug, pR, paramIdx), mBitmap(*pBitmap)
|
f@0
|
21 {
|
f@0
|
22 mText = *pText;
|
f@0
|
23 /* mRECT is the bounding rectangle of the whole KnobMultiControlText */
|
f@0
|
24 mNameRECT = IRECT(mRECT.L, mRECT.T,mRECT.R, mRECT.T+16);
|
f@0
|
25 mDisplayRECT = IRECT(mRECT.L, mRECT.B-25, mRECT.R-21, mRECT.B); // left, top, right, bottom
|
f@0
|
26 mLabelRECT = mDisplayRECT;
|
f@0
|
27 mLabelRECT.L = mDisplayRECT.R; // shift it to the right of the diplay RECT
|
f@0
|
28 mLabelRECT.R = mLabelRECT.L+indent; // how much the display is indented
|
f@0
|
29 mImgRECT = IRECT(mRECT.L, mRECT.T+16, &mBitmap);
|
f@0
|
30 mDisablePrompt = false;
|
f@0
|
31 }
|
f@0
|
32
|
f@0
|
33 ~IKnobMultiControlText() {}
|
f@0
|
34
|
f@0
|
35 bool Draw(IGraphics* pGraphics)
|
f@0
|
36 {
|
f@0
|
37 int i = 1 + int(0.5 + mValue * (double) (mBitmap.N - 1));
|
f@0
|
38 i = BOUNDED(i, 1, mBitmap.N);
|
f@0
|
39
|
f@0
|
40 /* draw the knob */
|
f@0
|
41 pGraphics->DrawBitmap(&mBitmap, &mImgRECT, i, &mBlend);
|
f@0
|
42
|
f@0
|
43 /* draw displayed value for host, that is the value as represented in the host */
|
f@0
|
44 char displayedValue[20];
|
f@0
|
45 mPlug->GetParam(mParamIdx)->GetDisplayForHost(displayedValue);
|
f@0
|
46
|
f@0
|
47 bool dispDrawn = true;
|
f@0
|
48 if (CSTR_NOT_EMPTY(displayedValue)) {
|
f@0
|
49 dispDrawn = pGraphics->DrawIText(&mText, displayedValue, &mDisplayRECT);
|
f@0
|
50 }
|
f@0
|
51
|
f@0
|
52 /* name of the parameter */
|
f@0
|
53 if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetNameForHost())){
|
f@0
|
54 char nameDisp[MAX_PARAM_NAME_LEN];
|
f@0
|
55 strcpy(nameDisp, mPlug->GetParam(mParamIdx)->GetNameForHost());
|
f@0
|
56
|
f@0
|
57 if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetLabelForHost())){
|
f@0
|
58 char label[MAX_PARAM_LABEL_LEN];
|
f@0
|
59 strcpy(label, mPlug->GetParam(mParamIdx)->GetLabelForHost());
|
f@0
|
60 pGraphics->DrawIText(&mText, label, &mLabelRECT);
|
f@0
|
61 }
|
f@0
|
62
|
f@0
|
63 return dispDrawn && pGraphics->DrawIText(&mText, nameDisp, &mNameRECT);
|
f@0
|
64 }
|
f@0
|
65
|
f@0
|
66 return dispDrawn;
|
f@0
|
67 }
|
f@0
|
68
|
f@0
|
69 void OnMouseDown(int x, int y, IMouseMod* pMod)
|
f@0
|
70 {
|
f@0
|
71 OnMouseDrag(x, y, 0, 0, pMod);
|
f@0
|
72 }
|
f@0
|
73
|
f@0
|
74 /* double click puts it back to default value */
|
f@0
|
75 void OnMouseDblClick(int x, int y, IMouseMod* pMod)
|
f@0
|
76 {
|
f@0
|
77 if (mDefaultValue >= 0.0)
|
f@0
|
78 {
|
f@0
|
79 mValue = mDefaultValue;
|
f@0
|
80 SetDirty();
|
f@0
|
81 }
|
f@0
|
82 }
|
f@0
|
83
|
f@0
|
84 };
|
f@0
|
85
|
f@0
|
86 /* Fader for the vertical peak level meter. It includes a text displaying the fader's current value in dB */
|
f@0
|
87 class IFaderVertText : public IFaderControl
|
f@0
|
88 {
|
f@0
|
89 ITextControl *mDisplayText;
|
f@0
|
90
|
f@0
|
91 public :
|
f@0
|
92 IFaderVertText(IPlugBase *pPlug, int x, int y, int len, int paramIdx, IBitmap *pBitmap, ITextControl* pText)
|
f@0
|
93 : IFaderControl(pPlug, x, y, len, paramIdx, pBitmap), mDisplayText(pText)
|
f@0
|
94 {
|
f@0
|
95 makeDisplayText();
|
f@0
|
96 }
|
f@0
|
97
|
f@0
|
98 ~IFaderVertText() {}
|
f@0
|
99
|
f@0
|
100 void OnMouseDown(int x, int y, IMouseMod* pMod)
|
f@0
|
101 {
|
f@0
|
102 // empty method override avoids IFaderControl::SnapToMouse(x, y);
|
f@0
|
103 }
|
f@0
|
104
|
f@0
|
105 void OnMouseDblClick(int x, int y, IMouseMod *pMod){
|
f@0
|
106 IFaderControl::OnMouseDblClick(x, y, pMod);
|
f@0
|
107 makeDisplayText();
|
f@0
|
108 }
|
f@0
|
109
|
f@0
|
110 void OnMouseDrag(int x, int y, int dX, int dY, IMouseMod* pMod){
|
f@0
|
111 IFaderControl::OnMouseDrag(x, y, dX, dY, pMod);
|
f@0
|
112 makeDisplayText();
|
f@0
|
113 }
|
f@0
|
114
|
f@0
|
115 /* changes the display text upon mouse dragging. If a value is passed
|
f@0
|
116 it is used for display else it's retrieved from the member value of this control.
|
f@0
|
117 Passing an explicit value fixes an uncorrect update in SetValueFromPlug.
|
f@0
|
118 The GUI update was in fact one step behind the update in the Daw.
|
f@0
|
119 */
|
f@0
|
120 void makeDisplayText(const double* value = NULL) {
|
f@0
|
121 char textDisplay[MAX_PARAM_LABEL_LEN + MAX_PARAM_DISPLAY_LEN+1];
|
f@0
|
122
|
f@0
|
123 if (value == NULL){
|
f@0
|
124 mPlug->GetParam(mParamIdx)->GetDisplayForHost(textDisplay);
|
f@0
|
125 }
|
f@0
|
126 else{
|
f@0
|
127 mPlug->GetParam(mParamIdx)->GetDisplayForHost(*value, true, textDisplay, true);
|
f@0
|
128 }
|
f@0
|
129 strcat(textDisplay, " ");
|
f@0
|
130 strcat(textDisplay, mPlug->GetParam(mParamIdx)->GetLabelForHost());
|
f@0
|
131 mDisplayText->SetTextFromPlug(textDisplay);
|
f@0
|
132 }
|
f@0
|
133
|
f@0
|
134 /* This updates the GUI when the parameter is set from the Daw */
|
f@0
|
135 virtual void SetValueFromPlug(double value) {
|
f@0
|
136 IFaderControl::SetValueFromPlug(value);
|
f@0
|
137
|
f@0
|
138 makeDisplayText(&value);
|
f@0
|
139 }
|
f@0
|
140 };
|
f@0
|
141
|
f@0
|
142 /* Peak meter gauge. Doesn't control any parameter,
|
f@0
|
143 only shows the audio level in dB. Orientation is vertical
|
f@0
|
144 */
|
f@0
|
145 class IPeakMeterVert : public IControl
|
f@0
|
146 {
|
f@0
|
147
|
f@0
|
148 public:
|
f@0
|
149
|
f@0
|
150 IPeakMeterVert(IPlugBase* pPlug, IRECT pR, double defaultValueNormalized)
|
f@0
|
151 : IControl(pPlug, pR)
|
f@0
|
152 {
|
f@0
|
153 mColor = IColor (255, 0, 35, 150);
|
f@0
|
154 mDefaultValue = defaultValueNormalized;
|
f@0
|
155 }
|
f@0
|
156
|
f@0
|
157 ~IPeakMeterVert() {}
|
f@0
|
158
|
f@0
|
159
|
f@0
|
160
|
f@0
|
161 bool Draw(IGraphics* pGraphics)
|
f@0
|
162 {
|
f@0
|
163
|
f@0
|
164 /* big rectangle for the border */
|
f@0
|
165 IRECT paddedRect = mRECT.GetPadded(1);
|
f@0
|
166 pGraphics->DrawRect(&COLOR_GRAY, &(paddedRect));
|
f@0
|
167
|
f@0
|
168 /* now fill everything red*/
|
f@0
|
169 pGraphics->FillIRect(&COLOR_RED, &mRECT);
|
f@0
|
170
|
f@0
|
171 /* now fill with blue the part where the peak meter doesn't reach */
|
f@0
|
172 IRECT filledBit = IRECT(mRECT.L, mRECT.T, mRECT.R, mRECT.B - (mValue * mRECT.H()));
|
f@0
|
173 pGraphics->FillIRect(&mColor, &filledBit);
|
f@0
|
174 IRECT shade = IRECT(mRECT.L, mRECT.T, mRECT.L+1, mRECT.B - (mValue * mRECT.H()));
|
f@0
|
175 pGraphics->FillIRect(&COLOR_BLUE, &shade);
|
f@0
|
176
|
f@0
|
177 pGraphics->DrawHorizontalLine(&COLOR_YELLOW, mRECT.B + 1 - (mDefaultValue * mRECT.H()), mRECT.L, mRECT.R - 1);
|
f@0
|
178 return true;
|
f@0
|
179 }
|
f@0
|
180
|
f@0
|
181 bool IsDirty() { return true;}
|
f@0
|
182
|
f@0
|
183 protected:
|
f@0
|
184 IColor mColor;
|
f@0
|
185 };
|
f@0
|
186
|