21#include "IPlugStructs.h"
24BEGIN_IGRAPHICS_NAMESPACE
28template <
int MAXNC = 1>
32 enum class EResponse {
37 IVMeterControl(
const IRECT& bounds,
const char* label,
const IVStyle& style = DEFAULT_STYLE, EDirection dir = EDirection::Vertical, std::initializer_list<const char*> trackNames = {},
int totalNSegs = 0, EResponse response = EResponse::Linear,
float lowRangeDB = -72.f,
float highRangeDB = 12.f, std::initializer_list<int> markers = {0, -6, -12, -24, -48})
40 , mLowRangeDB(lowRangeDB)
41 , mHighRangeDB(highRangeDB)
46 void SetResponse(EResponse response)
58 if (mResponse == EResponse::Log)
67 void DrawPeak(
IGraphics& g,
const IRECT& r,
int chIdx,
bool aboveBaseValue)
override
74 auto lowPointAbs = std::fabs(mLowRangeDB);
75 auto rangeDB = std::fabs(mHighRangeDB - mLowRangeDB);
77 for (
auto pt : mMarkers)
79 auto linearPos = (pt + lowPointAbs)/rangeDB;
81 auto r = mWidgetBounds.
FracRect(IVTrackControlBase::mDirection, linearPos);
83 if (IVTrackControlBase::mDirection == EDirection::Vertical)
97 str.SetFormatted(32,
"%i dB", pt);
98 g.
DrawText(DEFAULT_TEXT, str.Get(), r);
111 pos = stream.
Get(&d, pos);
113 if (mResponse == EResponse::Log)
115 auto lowPointAbs = std::fabs(mLowRangeDB);
116 auto rangeDB = std::fabs(mHighRangeDB - mLowRangeDB);
117 for (
auto c = d.chanOffset; c < (d.chanOffset + d.nChans); c++)
119 auto ampValue =
AmpToDB(
static_cast<double>(d.vals[c]));
120 auto linearPos = (ampValue + lowPointAbs)/rangeDB;
126 for (
auto c = d.chanOffset; c < (d.chanOffset + d.nChans); c++)
128 SetValue(
Clip(
static_cast<double>(d.vals[c]), 0., 1.), c);
138 EResponse mResponse = EResponse::Linear;
139 std::vector<int> mMarkers;
145template <
int MAXNC = 1>
150 std::initializer_list<const char*> trackNames = {},
int totalNSegs = 0,
float lowRangeDB = -60.f,
float highRangeDB = 12.f,
151 std::initializer_list<int> markers = {0, -6, -12, -24, -48})
156 void DrawPeak(
IGraphics& g,
const IRECT& r,
int chIdx,
bool aboveBaseValue)
override
159 float trackPos = mPeakValues[chIdx];
160 EVColor colorIdx = kX1;
162 if (trackPos < 0.0001)
171 const auto widgetBounds = IVTrackControlBase::mWidgetBounds;
172 const auto dir = IVTrackControlBase::mDirection;
175 if (dir == EDirection::Vertical)
177 peakRect = peakRect.
GetFromTop(IVTrackControlBase::mPeakSize);
183 peakRect = peakRect.
GetFromRight(IVTrackControlBase::mPeakSize);
198 pos = stream.
Get(&d, pos);
200 const auto lowRangeDB = IVPeakAvgMeterControl::mLowRangeDB;
201 const auto highRangeDB = IVPeakAvgMeterControl::mHighRangeDB;
203 double lowPointAbs = std::fabs(lowRangeDB);
204 double rangeDB = std::fabs(highRangeDB - lowRangeDB);
206 for (
auto c = d.chanOffset; c < (d.chanOffset + d.nChans); c++)
208 double peakValue =
AmpToDB(
static_cast<double>(std::get<0>(d.vals[c])));
209 double avgValue =
AmpToDB(
static_cast<double>(std::get<1>(d.vals[c])));
210 double linearPeakPos = (peakValue + lowPointAbs)/rangeDB;
211 double linearAvgPos = (avgValue + lowPointAbs)/rangeDB;
214 mPeakValues[c] =
static_cast<float>(linearPeakPos);
222 std::array<float, MAXNC> mPeakValues;
225const static IColor LED1 = {255, 36, 157, 16};
226const static IColor LED2 = {255, 153, 191, 28};
227const static IColor LED3 = {255, 215, 222, 37};
228const static IColor LED4 = {255, 247, 153, 33};
229const static IColor LED5 = COLOR_RED;
234template <
int MAXNC = 1>
246 LEDRange(
float lowRangeDB,
float highRangeDB,
int nSegs,
IColor color)
247 : lowRangeDB(lowRangeDB)
248 , highRangeDB(highRangeDB)
256 std::initializer_list<const char*> trackNames = {},
int totalNSegs = 13,
257 const std::vector<LEDRange>& ranges = {
260 {-36., -18., 3, LED3},
261 {-54., -36., 3, LED2},
262 {-72., -54., 3, LED1}
273 for (
auto ledRange : ranges)
275 if (ledRange.lowRangeDB < minRange)
276 minRange = ledRange.lowRangeDB;
278 if (ledRange.highRangeDB > maxRange)
279 maxRange = ledRange.highRangeDB;
281 nSegs += ledRange.nSegs;
284 assert(totalNSegs == nSegs);
295 void DrawTrackBackground(
IGraphics &g,
const IRECT &r,
int chIdx)
override
300 const float valPos = (dir == EDirection::Vertical) ? r.B - (val * r.
H()) : r.R - ((1.f-val) * r.
W());
304 for (
auto ledRange : mLEDRanges)
306 for (
auto i = 0; i < ledRange.nSegs; i++)
309 if (dir == EDirection::Vertical)
311 segRect = r.
GetGridCell(segIdx + i, totalNSegs, 1, dir, 1);
313 if (segRect.
MH() > valPos)
318 segRect = r.
GetGridCell(totalNSegs - 1 - (segIdx + i), 1, totalNSegs, dir, 1);
320 if (segRect.
MW() < valPos)
324 segIdx += ledRange.nSegs;
329 std::vector<LEDRange> mLEDRanges;
332END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
Manages a non-owned block of memory, for receiving arbitrary message byte streams.
int Get(T *pDst, int startPos) const
Get arbitary typed data from the stream.
IBlend GetBlend() const
Get the Blend for this control.
virtual void SetValue(double value, int valIdx=0)
Set one of the control's values.
double GetValue(int valIdx=0) const
Get the control's value.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
The lowest level base class of an IGraphics context.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
virtual void DrawLine(const IColor &color, float x1, float y1, float x2, float y2, const IBlend *pBlend=0, float thickness=1.f)
Draw a line to the graphics context.
ISender is a utility class which can be used to defer data from the realtime audio processing and sen...
Vectorial multi-channel capable meter control with segmented LEDs, log response.
void DrawTrackHandle(IGraphics &g, const IRECT &r, int chIdx, bool aboveBaseValue) override
Draw the main body of the track.
Vectorial multi-channel capable meter control, linear or log response.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMsgFromDelegate(int msgTag, int dataSize, const void *pData) override
Implement to receive messages sent to the control, see IEditorDelegate:SendControlMsgFromDelegate()
Vectorial multi-channel capable meter control, with log response, held-peaks and filled-average/rms R...
void OnMsgFromDelegate(int msgTag, int dataSize, const void *pData) override
Implement to receive messages sent to the control, see IEditorDelegate:SendControlMsgFromDelegate()
A base class for mult-strip/track controls, such as multi-sliders, meters Track refers to the channel...
void DrawWidget(IGraphics &g) override
Draw the IVControl main widget (override)
virtual void DrawBackground(IGraphics &g, const IRECT &r) override
Draw the IVControl background (usually transparent)
virtual void DrawLabel(IGraphics &g)
Draw the IVControl label text.
const IColor & GetColor(EVColor color) const
Get value of a specific EVColor in the IVControl.
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
static double AmpToDB(double amp)
Used to manage composite/blend operations, independent of draw class/platform.
Used to manage color data, independent of draw class/platform.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetFromRight(float amount) const
Get a subrect of this IRECT bounded in X by 'amount' and the right edge.
IRECT GetGridCell(int row, int col, int nRows, int nColumns) const
Get a subrect (by row, column) of this IRECT which is a cell in a grid of size (nRows * nColumns)
IRECT FracRect(EDirection layoutDir, float frac, bool fromTopOrRight=false) const
Get a new rectangle which is a fraction of this rectangle.
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
ISenderData is used to represent a typed data packet, that may contain values for multiple channels.
LED Range comprises info for a range of LED segments.
A struct encapsulating a set of properties used to configure IVControls.