# Fade out script for Kontakt 5 instruments



## DMXTom (May 16, 2017)

Hello
I´ve been looking for a script who fades out all my Layers slowly in time of 5-10 seconds. With the Releasfunction it doesn´t work on all Layers. So it would be better to have the simmeler Script with a button "Fade out" to contoll it with CC.

Thanks for helping


----------



## magneto538 (May 17, 2017)

DMXTom said:


> Hello
> I´ve been looking for a script who fades out all my Layers slowly in time of 5-10 seconds. With the Releasfunction it doesn´t work on all Layers. So it would be better to have the simmeler Script with a button "Fade out" to contoll it with CC.
> 
> Thanks for helping



Look for "fade_out" function in KSP Reference Manual. fade_out has three parameters: the first one is the Event ID you want to fade. You can store the Event ID of the currently playing events in a variable by assigning the play_note function to a variable, like this:

```
event_id := play_note(...)
```


Then you can fade the Event out by doing this

```
fade_out(event_id, 5000000, 1)
```


This particular function call is going to fade out the event in 5 seconds. When the event has been faded, its voice gets killed.


----------



## DMXTom (May 17, 2017)

Hi magneto
I´m a beginner in writing scripts. I´ve reading the page of Nils Liberg - but all the staff I found is in english :-(
So can you send me the whole script to fade out the *Volumen *?
Many thanks
Tom


----------



## DMXTom (May 17, 2017)

Hi once again
I´ve still found this script (sorry I don´t know where I got it from) but it doesn´t work.

on init
message("")
declare ui_switch $Fade_Out
declare ui_switch $Fade_In
declare $N_id
end on

on note
$N_id := $EVENT_ID
end on

on ui_control($Fade_Out)
if ($Fade_Out=1)
fade_out($N_id,5000000,0) {5sec}
else
fade_in($N_id,1000000000)
end if
end on

on ui_control($Fade_In)
$Fade_Out:=0
fade_in($N_id,20000)
$Fade_In:=0
end on


----------



## magneto538 (May 17, 2017)

Unless the instrument you are working on is very simple, the scripts you will find on the internet are unlikely to be ready to be used out of the box. You will have to customize them to your needs. In this case, the script should be working if I'm not mistaken, but if you want a custom solution you'll need to share some additional info about your instrument.

One possible bottleneck here is your release management. Are your samples supposed to be killed when the key on the keyboard is released? If not, you can have those samples to be played forever by adding the following piece of code to the script you posted above:



```
on release
    ignore_event($EVENT_ID)
end on
```


By adding this, the release will be ignored and the only way to kill the samples would be by using the Fade out button.

If you want this to be accomplished by using the Release, you will have to set the release of ALL the layers to be faded to 5 seconds. Each layer has its own envelope generator, so in order to kill all the layers you have to set the release manually on all the layers.


----------



## DMXTom (May 17, 2017)

Hi magneto,
sorry about my englisch  I hope I could translate your post correctly
I´m playing with kontakt and a midikeyboard in our chruch (popular musiK) At the end of some songs I still fade out for example an Asus2 chord (instrument a Layer) by hand with the Volumenslide. It´s not a good kind to do it, because the fade out ist "steppy". Thats the reason why I´m looking for an script. The script above doesn´t work. :-(
The Layer 1ist only a simple Loop with only a delay. The other Layers are simmeler with spezial textures.


----------



## magneto538 (May 17, 2017)

DMXTom said:


> Hi magneto,
> sorry about my englisch  I hope I could translate your post correctly
> I´m playing with kontakt and a midikeyboard in our chruch (popular musiK) At the end of some songs I still fade out for example an Asus2 chord (instrument a Layer) by hand with the Volumenslide. It´s not a good kind to do it, because the fade out ist "steppy". Thats the reason why I´m looking for an script. The script above doesn´t work. :-(
> The Layer 1ist only a simple Loop with only a delay. The other Layers are simmeler with spezial textures.



I'm sorry, but because I'm not English myself I am not sure I understood the issue...


----------



## DMXTom (May 20, 2017)

...I´ve know realyst with the ADSR Release. So I press a button on my key bevor the last Akkord, with CC automatic all Release goes on 100%. Thats all okey, but at the end of the fade out the sound fades out to fast...a script would be better...On high level especially with a curve vision of the fade out prozess


----------



## szcz (May 29, 2017)

Script you found would only fade-out/fade-in last played note.
Try this:

on init
declare ui_switch $fade_out
declare ui_knob $fade_time(500000,10000000,1000000)
make_persistent($fade_time)
end on

on ui_control ($fade_out)
fade_out($ALL_EVENTS,$fade_time,1)
$fade_out := 0
end on


----------

