f@0: // f@0: // AccessiblePeakMeter_controls.h f@0: // f@0: // Author: Fiore Martin f@0: // Started from IPlugMultiTargets example in WDL-OL, by Oli Larkin - https://github.com/olilarkin/wdl-ol f@0: // f@0: // Licensed under the Cockos WDL License, see README.txt f@0: // f@0: f@0: f@0: /* Knob with a text label and a text displaying the current value */ f@0: class IKnobMultiControlText : public IKnobControl f@0: { f@0: private: f@0: IRECT mDisplayRECT, mImgRECT, mNameRECT, mLabelRECT; f@0: IBitmap mBitmap; f@0: f@0: public: f@0: IKnobMultiControlText(IPlugBase* pPlug, IRECT pR, int paramIdx, IBitmap* pBitmap, IText* pText, int indent = 10) f@0: : IKnobControl(pPlug, pR, paramIdx), mBitmap(*pBitmap) f@0: { f@0: mText = *pText; f@0: /* mRECT is the bounding rectangle of the whole KnobMultiControlText */ f@0: mNameRECT = IRECT(mRECT.L, mRECT.T,mRECT.R, mRECT.T+16); f@0: mDisplayRECT = IRECT(mRECT.L, mRECT.B-25, mRECT.R-21, mRECT.B); // left, top, right, bottom f@0: mLabelRECT = mDisplayRECT; f@0: mLabelRECT.L = mDisplayRECT.R; // shift it to the right of the diplay RECT f@0: mLabelRECT.R = mLabelRECT.L+indent; // how much the display is indented f@0: mImgRECT = IRECT(mRECT.L, mRECT.T+16, &mBitmap); f@0: mDisablePrompt = false; f@0: } f@0: f@0: ~IKnobMultiControlText() {} f@0: f@0: bool Draw(IGraphics* pGraphics) f@0: { f@0: int i = 1 + int(0.5 + mValue * (double) (mBitmap.N - 1)); f@0: i = BOUNDED(i, 1, mBitmap.N); f@0: f@0: /* draw the knob */ f@0: pGraphics->DrawBitmap(&mBitmap, &mImgRECT, i, &mBlend); f@0: f@0: /* draw displayed value for host, that is the value as represented in the host */ f@0: char displayedValue[20]; f@0: mPlug->GetParam(mParamIdx)->GetDisplayForHost(displayedValue); f@0: f@0: bool dispDrawn = true; f@0: if (CSTR_NOT_EMPTY(displayedValue)) { f@0: dispDrawn = pGraphics->DrawIText(&mText, displayedValue, &mDisplayRECT); f@0: } f@0: f@0: /* name of the parameter */ f@0: if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetNameForHost())){ f@0: char nameDisp[MAX_PARAM_NAME_LEN]; f@0: strcpy(nameDisp, mPlug->GetParam(mParamIdx)->GetNameForHost()); f@0: f@0: if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetLabelForHost())){ f@0: char label[MAX_PARAM_LABEL_LEN]; f@0: strcpy(label, mPlug->GetParam(mParamIdx)->GetLabelForHost()); f@0: pGraphics->DrawIText(&mText, label, &mLabelRECT); f@0: } f@0: f@0: return dispDrawn && pGraphics->DrawIText(&mText, nameDisp, &mNameRECT); f@0: } f@0: f@0: return dispDrawn; f@0: } f@0: f@0: void OnMouseDown(int x, int y, IMouseMod* pMod) f@0: { f@0: OnMouseDrag(x, y, 0, 0, pMod); f@0: } f@0: f@0: /* double click puts it back to default value */ f@0: void OnMouseDblClick(int x, int y, IMouseMod* pMod) f@0: { f@0: if (mDefaultValue >= 0.0) f@0: { f@0: mValue = mDefaultValue; f@0: SetDirty(); f@0: } f@0: } f@0: f@0: }; f@0: f@0: /* Fader for the vertical peak level meter. It includes a text displaying the fader's current value in dB */ f@0: class IFaderVertText : public IFaderControl f@0: { f@0: ITextControl *mDisplayText; f@0: f@0: public : f@0: IFaderVertText(IPlugBase *pPlug, int x, int y, int len, int paramIdx, IBitmap *pBitmap, ITextControl* pText) f@0: : IFaderControl(pPlug, x, y, len, paramIdx, pBitmap), mDisplayText(pText) f@0: { f@0: makeDisplayText(); f@0: } f@0: f@0: ~IFaderVertText() {} f@0: f@0: void OnMouseDown(int x, int y, IMouseMod* pMod) f@0: { f@0: // empty method override avoids IFaderControl::SnapToMouse(x, y); f@0: } f@0: f@0: void OnMouseDblClick(int x, int y, IMouseMod *pMod){ f@0: IFaderControl::OnMouseDblClick(x, y, pMod); f@0: makeDisplayText(); f@0: } f@0: f@0: void OnMouseDrag(int x, int y, int dX, int dY, IMouseMod* pMod){ f@0: IFaderControl::OnMouseDrag(x, y, dX, dY, pMod); f@0: makeDisplayText(); f@0: } f@0: f@0: /* changes the display text upon mouse dragging. If a value is passed f@0: it is used for display else it's retrieved from the member value of this control. f@0: Passing an explicit value fixes an uncorrect update in SetValueFromPlug. f@0: The GUI update was in fact one step behind the update in the Daw. f@0: */ f@0: void makeDisplayText(const double* value = NULL) { f@0: char textDisplay[MAX_PARAM_LABEL_LEN + MAX_PARAM_DISPLAY_LEN+1]; f@0: f@0: if (value == NULL){ f@0: mPlug->GetParam(mParamIdx)->GetDisplayForHost(textDisplay); f@0: } f@0: else{ f@0: mPlug->GetParam(mParamIdx)->GetDisplayForHost(*value, true, textDisplay, true); f@0: } f@0: strcat(textDisplay, " "); f@0: strcat(textDisplay, mPlug->GetParam(mParamIdx)->GetLabelForHost()); f@0: mDisplayText->SetTextFromPlug(textDisplay); f@0: } f@0: f@0: /* This updates the GUI when the parameter is set from the Daw */ f@0: virtual void SetValueFromPlug(double value) { f@0: IFaderControl::SetValueFromPlug(value); f@0: f@0: makeDisplayText(&value); f@0: } f@0: }; f@0: f@0: /* Peak meter gauge. Doesn't control any parameter, f@0: only shows the audio level in dB. Orientation is vertical f@0: */ f@0: class IPeakMeterVert : public IControl f@0: { f@0: f@0: public: f@0: f@0: IPeakMeterVert(IPlugBase* pPlug, IRECT pR, double defaultValueNormalized) f@0: : IControl(pPlug, pR) f@0: { f@0: mColor = IColor (255, 0, 35, 150); f@0: mDefaultValue = defaultValueNormalized; f@0: } f@0: f@0: ~IPeakMeterVert() {} f@0: f@0: f@0: f@0: bool Draw(IGraphics* pGraphics) f@0: { f@0: f@0: /* big rectangle for the border */ f@0: IRECT paddedRect = mRECT.GetPadded(1); f@0: pGraphics->DrawRect(&COLOR_GRAY, &(paddedRect)); f@0: f@0: /* now fill everything red*/ f@0: pGraphics->FillIRect(&COLOR_RED, &mRECT); f@0: f@0: /* now fill with blue the part where the peak meter doesn't reach */ f@0: IRECT filledBit = IRECT(mRECT.L, mRECT.T, mRECT.R, mRECT.B - (mValue * mRECT.H())); f@0: pGraphics->FillIRect(&mColor, &filledBit); f@0: IRECT shade = IRECT(mRECT.L, mRECT.T, mRECT.L+1, mRECT.B - (mValue * mRECT.H())); f@0: pGraphics->FillIRect(&COLOR_BLUE, &shade); f@0: f@0: pGraphics->DrawHorizontalLine(&COLOR_YELLOW, mRECT.B + 1 - (mDefaultValue * mRECT.H()), mRECT.L, mRECT.R - 1); f@0: return true; f@0: } f@0: f@0: bool IsDirty() { return true;} f@0: f@0: protected: f@0: IColor mColor; f@0: }; f@0: