COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 04-18-2009, 06:29 AM   #1
cc_
Human being with feelings
 
Join Date: Mar 2009
Posts: 256
Default Alternative switch class for IPlug

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:



(that switch is based on one from here rearranged to fit the order iplug needs, the modified knobman files are here)

Seems to work...

Code:
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);
}
Code:
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,blendMethod),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_ is offline   Reply With Quote
Old 04-22-2009, 09:43 AM   #2
cc_
Human being with feelings
 
Join Date: Mar 2009
Posts: 256
Default

Found a bug with continuously variabling automation it sometimes drew the wrong images, the line in the draw function should be:

Code:
     i = 1 + mMouseDown + 2 * int(0.5 + mValue * (mBitmap.N/2 - 1));
cc_ is offline   Reply With Quote
Old 11-10-2009, 09:15 PM   #3
asiohead
Human being with feelings
 
Join Date: Oct 2009
Posts: 8
Default

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
Attached Images
File Type: jpg ISwitch_OnMouse_error2.jpg (88.3 KB, 316 views)

Last edited by asiohead; 11-10-2009 at 09:37 PM.
asiohead is offline   Reply With Quote
Old 11-11-2009, 09:17 PM   #4
asiohead
Human being with feelings
 
Join Date: Oct 2009
Posts: 8
Default

ouch sorry, forgot to initialize the control's parameter ranges
asiohead 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 04:07 PM.


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