comparison AccessiblePeakMeter_controls.h @ 0:4606bd505630 tip

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