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