PDA

View Full Version : Bitmap strip knob control for IPlug


Andrew J
03-08-2009, 05:12 AM
Someone shoot me if it's already in there, but I couldn't find a bitmap strip style knob control in IPlug (wdl_20090118). So I knocked one up by adding the following to IControl.h:

// A bitmap strip knob - Andrew J, 8-Mar-2009
class IKnobBitmapStripControl : public IKnobControl
{
public:

IKnobBitmapStripControl(IPlugBase* pPlug, int x, int y, int paramIdx, IBitmap* pBitmap,
double minAngle = -0.75 * PI, double maxAngle = 0.75 * PI,
EDirection direction = kVertical, double gearing = DEFAULT_GEARING)
: IKnobControl(pPlug, &IRECT(x, y, pBitmap), paramIdx, direction, gearing),
mBitmap(*pBitmap), mMinAngle(minAngle), mMaxAngle(maxAngle) {}
~IKnobBitmapStripControl() {}

bool Draw(IGraphics* pGraphics);

private:
IBitmap mBitmap;
double mMinAngle, mMaxAngle;
};

And to IControl.cpp:

// A bitmap strip knob - Andrew J, 8-Mar-2009
// Assumes that bitmap strip goes from top to bottom, starts at South and goes clockwise 360deg
bool IKnobBitmapStripControl::Draw(IGraphics* pGraphics)
{
int i = 1;
if (mBitmap.N > 1) {
double angle = mMinAngle + mValue * (mMaxAngle - mMinAngle);
i = 1 + int(0.5 + (double) ((mBitmap.N - 1)/2 * (1 + angle/PI)));
i = BOUNDED(i, 1, mBitmap.N);
}
return pGraphics->DrawBitmap(&mBitmap, &mRECT, i, &mBlend);
}

Not thoroughly tested, but seems to work fine for me...

-Andrew

bvesco
03-09-2009, 12:09 AM
You must have overlooked the IKnobMultiControl!


IBitmap bitmap = pGraphics->LoadIBitmap(KNOB_ID, KNOB_IMG, KNOB_FRAMES);
int knobIndex = pGraphics->AttachControl(new IKnobMultiControl(this, knobX, knobY, paramIdx, &bitmap));

Andrew J
03-09-2009, 12:49 AM
You must have overlooked the IKnobMultiControl!

I actually tried that first but didn't get it to work - must look again when I'm feeling less stupid.

Where's a good blush smilie when you need one? Ah, right there...

Andrew J
03-09-2009, 12:56 AM
Actually, just looked again. The difference is that the multi control doesn't map the knob angle to the bitmap index for you. IKnobBitmapStripControl takes care of that all by itself.

bvesco
03-10-2009, 08:46 AM
It's not supposed to map angle to the bitmap. It is supposed to map your parameter value to the bitmap. You set the value normalized from [0.0, 1.0] and it calculates the knob position from that value. So 0.0 is the first frame, 1.0 is the last frame, 0.5 is the "middle" frame and everything else in between. Maybe you have your parameters defined incorrectly?

bvesco
03-10-2009, 08:46 AM
Oh, also check out http://www.plugindeveloper.com/ for some other IPlug related stuff that might help out.

Andrew J
03-11-2009, 03:23 AM
Thanks Ben, I had already found that and registered. Some handy stuff there so far...