PDA

View Full Version : Alternative switch class for IPlug


cc_
04-18-2009, 06:29 AM
Here's some code for a switch that has extra states in between the notmal ones that are used when the mouse is down, like this:

http://burbleland.com/tmp/LEDButton02.png

(that switch is based on one from here (http://www.kvraudio.com/forum/viewtopic.php?p=3312244#3312244) rearranged to fit the order iplug needs, the modified knobman files are here (http://burbleland.com/tmp/LEDButton02.png))

Seems to work...


void ISwitch2Control::OnMouseUp(int x, int y)
{
mMouseDown=0;
SetDirty();
}

void ISwitch2Control::OnMouseDown(int x, int y, IMouseMod* pMod)
{
mMouseDown=1;
if (pMod->R) {
PromptUserInput();
}
else if (mBitmap.N > 2) {
mValue += 2.0 / (double) (mBitmap.N - 2);
}
else {
mValue += 1.0;
}
if (mValue > 1.001) {
mValue = 0.0;
}
SetDirty();
}

bool ISwitch2Control::Draw(IGraphics* pGraphics)
{
int i = 1;
if (mBitmap.N > 2) {
i = 1 + mMouseDown + int(0.5 + mValue * (mBitmap.N - 2));
i = BOUNDED(i, 1, mBitmap.N);
}
return pGraphics->DrawBitmap(&mBitmap, &mRECT, i, &mBlend);
}



class ISwitch2Control : public ISwitchControl
{
public:

ISwitch2Control(IPlugBase* pPlug, int x, int y, int paramIdx, IBitmap* pBitmap,
IChannelBlend::EBlendMethod blendMethod = IChannelBlend::kBlendNone)
: ISwitchControl(pPlug,x,y,paramIdx,pBitmap,blendMet hod),mMouseDown(0) {
mDblAsSingleClick=true; }

~ISwitch2Control() {}

void OnMouseDown(int x, int y, IMouseMod* pMod);
void OnMouseUp(int x, int y);
virtual bool Draw(IGraphics* pGraphics);
protected:
int mMouseDown;
};

cc_
04-22-2009, 09:43 AM
Found a bug with continuously variabling automation it sometimes drew the wrong images, the line in the draw function should be:


i = 1 + mMouseDown + 2 * int(0.5 + mValue * (mBitmap.N/2 - 1));

asiohead
11-10-2009, 09:15 PM
Nice control ! Was eager to use to test it in my Seq project instead of the IBitmapOverlayControl as you suggested.

But there's one problem tho, I get an error message and my plug crashes.

this is how I implement it:

//Switch2
IBitmap bitmapS2 = pGraphics->LoadIBitmap(SWITCH2_ID, SWITCH2_FN, kSwitch2Frames);
pGraphics->AttachControl( new ISwitch2Control(this, 100, 20,kSwitch2, &bitmapS2, IChannelBlend::kBlendNone));

AttachGraphics(pGraphics);

.... etc ...

//kSwitch2Frames = 4
the button image is defined in recources.h and 'project'.rc

I see the button on the screen, press it, it even works for a millisec, then the plugin crashes. I included the error screen in an attach

asiohead
11-11-2009, 09:17 PM
ouch sorry, forgot to initialize the control's parameter ranges