COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 07-12-2018, 05:32 AM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default making a 'damped' control ?

In my plugin I want to make a control that kinda behaves like a pitch wheel, returning to default (center) on mouse release, but not instantly, instead smoothly returning within say one second.

I know that I need to do a custom control (inherited from IControl) and override the OnMouseUp() method, but then what ?
How would I do the actual 'smooth return to default' ?

Last edited by nofish; 07-12-2018 at 05:37 AM.
nofish is offline   Reply With Quote
Old 07-13-2018, 12:11 PM   #2
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

I don't want to guess too much exactly what you want to do, but I suggest you think about the behavior, and whether it's the param or the control that you want to return. Typically, we move a control to change a param, but when we aren't actively moving the control, and the param is changing, the param is changing the control (as it does with automation).
earlevel is offline   Reply With Quote
Old 07-13-2018, 02:28 PM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Thanks for the reply.
To be more clear, I want something like this, just the fader not returning immediately ('jumpy') as currently but a bit 'smoother'.



What I have so far (for the immediate returning):

Code:
class IFaderControl_returnToDefaultOnMouseUp : public IFaderControl
{
public:
	IFaderControl_returnToDefaultOnMouseUp(IPlugBase* pPlug, int x, int y, int len, int paramIdx, IBitmap* pBitmap, EDirection direction, bool onlyHandle) :
		IFaderControl(pPlug, x, y, len, paramIdx, pBitmap, direction, onlyHandle) {}

	~IFaderControl_returnToDefaultOnMouseUp() {}

private:
	void OnMouseUp(int x, int y, IMouseMod* pMod) override
	{
		mDefaultValue = mPlug->GetParam(mParamIdx)->GetDefaultNormalized();
		mValue = mDefaultValue;
	}
};
nofish is offline   Reply With Quote
Old 07-13-2018, 03:47 PM   #4
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

This sort of things are pretty easy to manage if you have a "heartbeat" thread, where you can execute some code regularly at a lower priority than the audio thread. Where you force the param back to the default value on mouseUp, you'd start a state machine to perform the change incrementally. There's a idle (separate from the GUI idle) handler in IPlug that seems appropriate, but it's not implemented across all plugin types (maybe not at all, but I think I recall it might be with VST). I think you need to create your own thread, unless someone else knows otherwise.
earlevel is offline   Reply With Quote
Old 07-13-2018, 04:04 PM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Ok, needing to create a seperate thread is what I've gathered because my first approach was trying to increment/decrement the param directly in small steps in OnMouseUp() in a while... loop which froze the whole GUI (rather obviously).

Thanks.
nofish is offline   Reply With Quote
Old 07-14-2018, 12:50 AM   #6
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Just an idea, but you could also "simulate" the lower-priority thread from inside the audio thread, by only running it every N samples. Of course that would waste some CPU cycles in the audio thread, but it might be simpler.
Tale 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 05:53 AM.


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