|
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,646
|
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.
|
|
|
07-14-2018, 01:35 PM
|
#7
|
Human being with feelings
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
|
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;
}
|
|
|
07-14-2018, 02:12 PM
|
#8
|
Human being with feelings
Join Date: Dec 2015
Posts: 331
|
Quote:
Originally Posted by olilarkin
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
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?
|
|
|
07-14-2018, 02:37 PM
|
#9
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Quote:
Originally Posted by earlevel
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.
|
|
|
07-14-2018, 03:30 PM
|
#10
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Quote:
Originally Posted by olilarkin
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.
|
|
|
07-15-2018, 01:25 AM
|
#11
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,646
|
Quote:
Originally Posted by earlevel
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.
|
|
|
07-15-2018, 04:22 AM
|
#12
|
Human being with feelings
Join Date: Apr 2012
Posts: 279
|
Quote:
Originally Posted by olilarkin
override IsDirty to do your animation... I think this would work...
|
... neat trick! Have to remember this
Quote:
Originally Posted by nofish
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.
|
|
|
07-15-2018, 11:42 AM
|
#13
|
Human being with feelings
Join Date: Dec 2015
Posts: 331
|
Quote:
Originally Posted by Tale
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.
|
|
|
07-16-2018, 12:56 AM
|
#14
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,646
|
Quote:
Originally Posted by earlevel
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...
|
|
|
Thread Tools |
|
Display Modes |
Linear 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 04:22 AM.
|