COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 11-23-2015, 11:44 AM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default setting color of peak meter dynamically ? (solved)

Still taking my first steps in WDL-OL and enjoying it...

So, with the help of this this tutorial and the IPlugControls example I've managed to build a simple distortion / clipper plugin with an output knob and a peak meter. Looks like this currently:

https://i.imgur.com/U7SY5jU.jpg

Now next step I'd like to try is change the color of the peak meter dynamically at some predetermined value (when over the clipping threshold) to indicate that signal clipping is happening. I.e. peak > clipping threshold ? -> turn meter red

How would I go doing this ?

As from what I understand so far, the color of the peak meter is set in
...controls.h here:

Code:
class IPeakMeterVert : public IControl
{
public:
	(...)

	bool Draw(IGraphics* pGraphics) 
	{
	  pGraphics->FillIRect(&COLOR_WHITE, &mRECT); // change this color dynamically ?

	  IRECT filledBit = IRECT(mRECT.L, mRECT.T, mRECT.R, mRECT.B - (mValue * mRECT.H()));
	  pGraphics->FillIRect(&mColor, &filledBit);
	  return true;
	}
        (...)
};
And the meter is drawn when doing in the plugin constructor:

Code:
mMeterIdx_L = pGraphics->AttachControl(new IPeakMeterVert(this, IRECT(meterL_left, meterTop, meterL_right, meterBottom))); 
mMeterIdx_R = pGraphics->AttachControl(new IPeakMeterVert(this, IRECT(meterR_left, meterTop, meterR_right, meterBottom)));

Last edited by nofish; 01-09-2016 at 07:28 AM.
nofish is offline   Reply With Quote
Old 11-24-2015, 05:54 AM   #2
random_id
Human being with feelings
 
random_id's Avatar
 
Join Date: May 2012
Location: PA, USA
Posts: 356
Default

You could do a bunch of things, but you probably want to start by making a new meter class that inherits the IPeakMeterVert class. Then you can override the Draw() method to have the color change dynamically based on mValue. Something like this (I haven't tested it).

Code:
bool Draw(IGraphics* pGraphics) 
{
IColor cMeter;
if (mValue < 0.7) cMeter = COLOR_GREEN;
else if (mValue < 0.9) cMeter = COLOR_YELLOW;
else cMeter = COLOR_RED;

pGraphics->FillIRect(&cMeter, &mRECT);
IRECT filledBit = IRECT(mRECT.L, mRECT.T, mRECT.R, mRECT.B - (mValue * mRECT.H()));

pGraphics->FillIRect(&mColor, &filledBit);
return true;
}
__________________
Website: LVC-Audio
random_id is offline   Reply With Quote
Old 01-09-2016, 07:23 AM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
Default

Sorry for the terribly late reply (got distracted with other things meanwhile), just wanted to say I got it working with the help of your code snippet so thanks a lot.

Still needs a lot optimization (still learning...) but it's there basically.

nofish is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.