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 online now   Reply With Quote
Old 07-14-2018, 01:35 PM   #7
olilarkin
Human being with feelings
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
Default

if this is just a visual effect - an animation, you don't need another thread, and you definitely don't need to use the audio thread.

create a member variable mCountdown in your IControl, initialise it to 0 and on MouseUp/whatever set it to a certain number of frames e.g., if IGraphics FPS = 25 (the default) and you want the animation to continue for 1 sec, you would set mCountdown to 25.

override IsDirty to do your animation... I think this would work...

bool MyControl::IsDirty()
{
if( mCountdown--) {
// do animation

return true;
}

return mDirty;
}
__________________
VirtualCZ | Endless Series | iPlug2 | Linkedin | Facebook
olilarkin is offline   Reply With Quote
Old 07-14-2018, 02:12 PM   #8
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

Quote:
Originally Posted by olilarkin View Post
if this is just a visual effect...
Well, I was alluding to this when I said "I don't want to guess too much what exactly you want to do", but I assumed he most likely wanted the parameter to follow the smoothed control...but not sure...

Quote:
Originally Posted by Tale View Post
Just an idea, but you could also "simulate" the lower-priority thread from inside the audio thread, by only running it every N samples.
I don't think that would be a good place to send a parameter change, no?
earlevel is offline   Reply With Quote
Old 07-14-2018, 02:37 PM   #9
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by earlevel View Post
but I assumed he most likely wanted the parameter to follow the smoothed control...but not sure...
Correct, I want the parameter to follow the control. Sorry for not mentioning this explicitly.
nofish is offline   Reply With Quote
Old 07-14-2018, 03:30 PM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by olilarkin View Post
override IsDirty to do your animation...
This is getting there...



Problem is now I can't hold the fader up with the mouse anymore (which also should be possible), because it starts the animation as soon as it detects 'dirty' (i.e. immediately after touching) I think. You can see this in the gif, mouse button is still pressed while fader returns which it shouldn't.
nofish is offline   Reply With Quote
Old 07-15-2018, 01:25 AM   #11
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by earlevel View Post
I don't think that would be a good place to send a parameter change, no?
I think that depends on the situation, not?

Anyway, I generate noise and play an animation when my plug-in is in demo mode, and I control this from within the audio thread. While the noise is playing I update a timer value, and let the control know via SetValueFromPlug(). Works for me.
Tale is online now   Reply With Quote
Old 07-15-2018, 04:22 AM   #12
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Quote:
Originally Posted by olilarkin View Post
override IsDirty to do your animation... I think this would work...
... neat trick! Have to remember this

Quote:
Originally Posted by nofish View Post
Problem is now I can't hold the fader up with the mouse anymore (which also should be possible), because it starts the animation as soon as it detects 'dirty' (i.e. immediately after touching) I think. You can see this in the gif, mouse button is still pressed while fader returns which it shouldn't.
You should be able to handle that easily with OnMouseUp(). Just start your animation only if e.g. a bool was set true in there.
stw is offline   Reply With Quote
Old 07-15-2018, 11:42 AM   #13
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

Quote:
Originally Posted by Tale View Post
I think that depends on the situation, not?

Anyway, I generate noise and play an animation when my plug-in is in demo mode, and I control this from within the audio thread. While the noise is playing I update a timer value, and let the control know via SetValueFromPlug(). Works for me.
Well, like I said, he's looking to set the parameter, not just the control. When I suggesting the audio thread wouldn't be a good place, it was in regards to setting a parameter.
earlevel is offline   Reply With Quote
Old 07-16-2018, 12:56 AM   #14
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by earlevel View Post
Well, like I said, he's looking to set the parameter, not just the control. When I suggesting the audio thread wouldn't be a good place, it was in regards to setting a parameter.
Oops, I missed that, sorry! Yeah, I guess you don't want to call something like SetParameterFromGUI() from the audio thread...
Tale is online now   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 01:29 AM.


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