Skip to content

Commit

Permalink
Add IBMeterControl
Browse files Browse the repository at this point in the history
A bitmap meter control, that can be used for VUMeters. Use with IPeakAvgSender<1>
  • Loading branch information
olilarkin committed Sep 26, 2022
1 parent 3b9d61e commit 7ec7dcb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
35 changes: 35 additions & 0 deletions IGraphics/Controls/IControls.cpp
Expand Up @@ -1573,3 +1573,38 @@ void IBTextControl::Draw(IGraphics& g)
{
g.DrawBitmapedText(mBitmap, mRECT, mText, &mBlend, mStr.Get(), mVCentre, mMultiLine, mCharWidth, mCharHeight, mCharOffset);
}

void IBMeterControl::OnMsgFromDelegate(int msgTag, int dataSize, const void* pData)
{
if (!IsDisabled() && msgTag == ISender<>::kUpdateMessage)
{
IByteStream stream(pData, dataSize);

int pos = 0;
ISenderData<1, std::pair<float, float>> d;
pos = stream.Get(&d, pos);

if (mResponse == EResponse::Log)
{
auto lowPointAbs = std::fabs(mLowRangeDB);
auto rangeDB = std::fabs(mHighRangeDB - mLowRangeDB);
for (auto c = d.chanOffset; c < (d.chanOffset + d.nChans); c++)
{
auto [peak, avg] = d.vals[c];
auto ampValue = AmpToDB(avg);
auto linearPos = (ampValue + lowPointAbs)/rangeDB;
SetValue(Clip(linearPos, 0., 1.), c);
}
}
else
{
for (auto c = d.chanOffset; c < (d.chanOffset + d.nChans); c++)
{
auto [peak, avg] = d.vals[c];
SetValue(Clip(avg, 0.f, 1.f), c);
}
}

SetDirty(false);
}
}
41 changes: 41 additions & 0 deletions IGraphics/Controls/IControls.h
Expand Up @@ -662,6 +662,47 @@ class IBTextControl : public ITextControl
bool mVCentre;
};

/** A bitmap meter control, that can be used for VUMeters. Use with IPeakAvgSender<1> */
class IBMeterControl : public IBitmapControl
{
public:
enum class EResponse {
Linear,
Log,
};

/** Constructs a bitmap meter control
* @param x The x position of the top left point in the control's bounds (width will be determined by bitmap's dimensions)
* @param y The y position of the top left point in the control's bounds (height will be determined by bitmap's dimensions)
* @param bitmap The bitmap resource for the control */
IBMeterControl(float x, float y, const IBitmap& bitmap, EResponse response = EResponse::Linear, float lowRangeDB = -72.f, float highRangeDB = 12.f)
: IBitmapControl(x, y, bitmap)
, mResponse(response)
, mLowRangeDB(lowRangeDB)
, mHighRangeDB(highRangeDB)
{}

/** Constructs a bitmap meter control
* @param bounds The control's bounds
* @param bitmap The bitmap resource for the control */
IBMeterControl(const IRECT& bounds, const IBitmap& bitmap, EResponse response = EResponse::Linear, float lowRangeDB = -72.f, float highRangeDB = 12.f)
: IBitmapControl(bounds, bitmap)
, mResponse(response)
, mLowRangeDB(lowRangeDB)
, mHighRangeDB(highRangeDB)
{}

virtual ~IBMeterControl() {}
void Draw(IGraphics& g) override { DrawBitmap(g); }
void OnRescale() override { mBitmap = GetUI()->GetScaledBitmap(mBitmap); }
void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override;

protected:
float mHighRangeDB;
float mLowRangeDB;
EResponse mResponse = EResponse::Linear;
};

END_IGRAPHICS_NAMESPACE
END_IPLUG_NAMESPACE

Expand Down

0 comments on commit 7ec7dcb

Please sign in to comment.