Set min & max value fx when routing to Slider

Discussion in 'KONTAKT: Sampling, Programming & Scripting' started by Nicko Junior, Jul 12, 2018.

  1. Nicko Junior

    Nicko Junior New Member

    Jul 12, 2018
    Hey guys, I'm a noob in Kontakt scripting. I want to ask if eg 2 knob effects can be routed with 1 slider but each effect is set differ between minimum value and max value.

    Example steps.
    1. Gain 1: min -6db and max 0db
    2. Gain 2: min -12db and max -6db
    3. then last, I want to set it in 1 knob / slider.

    Is it possible, if you can please give an example of the syntax. Thank you very much. :)
  2. EvilDragon

    EvilDragon KSP Wizard

    May 25, 2010
    Yep, it's possible, with a bit of elementary math. :) I am assuming you're talking about group volumes here. -12 dB is 397000, -6 dB is 500000, 0 dB is 630000. So all you need to do is some scaling and offsetting between those values depending on the min-max range of your one slider. Do note since volume is not a linear parameter, but exponential, you won't get one-to-one change in dB for your use case.

    I am assuming you're using Kontakt 5.6 or above:

    on init
        declare ui_slider $Vol12 (500000, 630000)
    end on
    on ui_control ($Vol12)
        set_engine_par($ENGINE_PAR_VOLUME, $Vol12, 0, -1, -1)
        set_engine_par($ENGINE_PAR_VOLUME, real_to_int(int_to_real($Vol12 - 103000) * 0.7923), 1, -1, -1)
    end on
    Explanation: our slider has 500000-630000 range, so that's 130000 units that the slider covers. We need to offset 500000 by subtracting 103000 to make the second group volume start from -12 dB (=397000). Then we need to scale the range that the slider covers so that the second group volume goes from 397000 to 500000, which means reducing 130000 to 103000, which is multiplying by a factor of 0.7923.

    There you have it. :)
    Gileno and polypx like this.
  3. OP
    Nicko Junior

    Nicko Junior New Member

    Jul 12, 2018
    mannnn! omg its works!!!! I have searched this a few days ago and finally found it here. THANK YOU SO MUCH!!

Share This Page