|
07-12-2018, 05:32 AM
|
#1
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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.
|
|
|
07-13-2018, 12:11 PM
|
#2
|
Human being with feelings
Join Date: Dec 2015
Posts: 331
|
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).
|
|
|
07-13-2018, 02:28 PM
|
#3
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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;
}
};
|
|
|
07-13-2018, 03:47 PM
|
#4
|
Human being with feelings
Join Date: Dec 2015
Posts: 331
|
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.
|
|
|
07-13-2018, 04:04 PM
|
#5
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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.
|
|
|
07-14-2018, 12:50 AM
|
#6
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
|
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.
|
|
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:53 AM.
|