Fade out audio on button press
-
@Christoph-Hart so in 2 months official release of hise 4 directly? ^^
-
@yall : Lol - version 3.0 would be enough for me for now
-
@Christoph-Hart Thank you! Now, a side question because my brain doesn't comprehend this.
I have some other actions I'd like to perform on the fade button. How can I set the timer so that it works like this:
- Button pressed: 1s fade
- Wait 1s
- Rest of the action
Thank you!
-
Is this other action something on the UI? And is the event triggered by a control callback?
-
@Christoph-Hart yeah, if’s on the UI. In fact, the fade is implemented in this context on an FX plugin:
- if slider changes value
- it activates the fade button
- now the script should wait until the audio fades
- convolution file is swapped
- fade button gets new value, the audio fades back up
It’s really there to hide clicks during the convolution swap. The fade should be very short (I can figure how to do this with the snippet you posted earlier so all good here) but generally speaking, I need some smoother experience without clicks in the audio.
-
I already have the ir swap and button change working, just need the wait part
-
Try a UI timer
https://docs.hise.audio/scripting/scripting-api/engine/index.html#createtimerobject
- Fade out the signal, start the timer with the same duration as the fade-out
- In the first timer callback, swap the ir
- In the second callback, stop the timer and fade in the signal again.
You need a variable that stores the state (and change the state in each timer callback callback)
-
Ok, almost there! It works great EXCEPT that it double triggers the fade button when moving the master slider. I'm pretty sure it's something obvious at this point?
reg fade = true; const var FadeTimer = Engine.createTimerObject(); const var Master = Content.getComponent("Master"); const var FadeOutButton = Content.getComponent("FadeOutButton"); inline function onMasterControl(component, value) { // Filtr 1 if (value == 1) { FadeTimer.setTimerCallback(function() { if(fade) { fade = false; FadeOutButton.setValue(0); FadeOutButton.changed(); Convo.setFile("{PROJECT_FOLDER}IR1.wav"); Console.print("Swap"); } else { Console.print("Fadein"); fade = true; FadeTimer.stopTimer(); FadeOutButton.setValue(1); FadeOutButton.changed(); } }); FadeTimer.startTimer(50); } // Value 2 if (value == 2) { // Something else } }; Content.getComponent("Master").setControlCallback(onMasterControl);
-
@Christoph-Hart maybe I’m calling the var change in the wrong spot? The fade works great when I turn the knob but it also fires again once I release the mouse
-
Still can't figure it out, maybe it's just that my logic is tired. The script above works except that it the fade action again once the mouse is released.
@Christoph-Hart save me, please! ;-)
-
- Try to save the
value
argument of theonMasterControl
in areg
variable and only fire the logic if it changes. This prevents multiple callbacks with the same value to fire multiple times. - put the
setTimerCallback()
outside of the control callback. - if you just select different IR's based on the slider's position, use an array with the names and then just pick up the one you want - this is especially true if you move the function declaration out of the value branch.
- before you call
startTimer()
, make sure to set thefade
variable back totrue
.
So your control callback should only look like this:
inline function onMasterControl(component, value) { if(value != storedValue) { storedValue = value; fade = true; callFadeOutNow(); // no need to wait for the timer... FadeTimer.startTimer(50); } }
- Try to save the
-
@Christoph-Hart thank you!