1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

AHDSR knob basics - go easy on me

Discussion in 'Scripting Workshop' started by ben_horwood, Oct 31, 2011.

  1. Big Bob

    Big Bob Forum Member

    Messages:
    606

    No, we won't be able to do that until NI includes a function for converting a string to numeric. We've had the inverse from day 1 with being able to concatenate a integer variable inside of a string expression but alas, not the inverse.

    But, regarding knob value entry, I'm almost positive I read somewhere that it was forthcoming. As I recall we were supposed to be able to double-click the value field (just like an edit box) and be able to then type in a numeric value. If I ever run across where I saw that, I'll let you know.
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    That happens for all the ordinary knobs in Kontakt, but not the scripted ones. This was added in Kontakt 4.2. :)
     
  3. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Ouch!

    Now that you spell it out for me, I think that must have been what I remembered reading about and just assumed it was going to apply to scripted knobs as well. Oh Phooey!
     
  4. ben_horwood

    ben_horwood Forum Member

    Messages:
    402
    I'm getting somewhere... and getting nowhere...

    So I've figured out that:

    Attack = 15000.01953125
    Hold = 15000.01953125
    Decay = 2500.04296875
    Release = 2500.04296875

    That means if I want an attack of 10ms for example, then I use the following:
    10/15 (ms) * 15000.01953125 = 100000.0130208333
    For 5ms it would be:
    5/15 * 15000.01953125 = 5000.006510416667

    Since decay and release have a different scale then I use the following instead:
    x/25 * 2500.04296875
    Therefore a 20ms delay would be:
    20/25 * 2500.04296875 = 2000.034375

    But since IDK the range for the sustain, I am unable to figure out how to properly calculate this... ?

    I'm sure it's probably doable, but all the maths I learned was SO long ago...

    My head hurts.... :(
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    The thing is that scaling of knob values to engine parameters is not linear for all controls. Some have an exponential curve, which makes conversion from EP to actual values a living hell. There's not much help there for now... save for Big Bob's math library, but IIRC it doesn't yet support all possible knob tapers that are used on different parameters in Kontakt.
     
  6. ben_horwood

    ben_horwood Forum Member

    Messages:
    402
    So help me out here please...

    I just want to figure out what -100db is for sustain?
    The knobs wont let me fine-tune enough (I can only either get -99.8 or -100.3)

    I just freakin want -100db :(

    Will Bob's math library help or not?
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    -100 dB on Sustain is in engine parameter value range from 21222 to 21303. So use any value from that range as the minimal value of your ui_value_edit.

    How did I get that? By typing -100 dB in the Sustain knob value field (Kontakt 4.2 and above), then using message(get_engine_par()) pointing to that envelope, which spits out the current value.
     
  8. ben_horwood

    ben_horwood Forum Member

    Messages:
    402
    Thanks ED.
    Do you know what that correlates to in the other AHDSR range?
    ...
    All this time I've been trying with 4.1.1...

    I have all versions to 4.2.4, but I've been using 4.1.1 to try and maintain compatability of my patches.

    Cheers
     
  9. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    I'll have to do knob taper graphs for envelopes sometimes. Currently I have only a few parameters, because getting to all the values is tedious, even though I have an almost automated script that does all the value checking and storing to NKA files...

    Here's what I have so far: http://minus.com/mbevbXePPE
     
  10. ben_horwood

    ben_horwood Forum Member

    Messages:
    402
    Thank you so much for this... it is very helpful. :)
     
  11. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Some values might differ on your configuration, because it seems that internal formulas that NI uses for translating knob values to engine parameter values don't work equally on all systems (as I seem to encounter when testing my value fetching script on different systems). So it's the best idea to use in-between values (you sum the EP value you want with the next one in the column, then divide by 2).
     
  12. ben_horwood

    ben_horwood Forum Member

    Messages:
    402
    What a mess the whole thing is. :confused:
     
  13. Andreas Hald

    Andreas Hald NI Product Owner

    Messages:
    74
    The script for displaying AHDSR provided by EvilDragon works flawlessly (as all his scripts, tips and pointers) when I add it to an empty script. How ever, I'm having trouble pasting/merging the script to an existing script. Obviously, I'm trying to add it the wrong place - but where can I check that? I have different groups in the script (5), and I'm looking to have a master AHDSR on performance view, which affects all groups with samples...

    Hopefully at some point, I can start giving back tips - instead of just getting tips!;0)

    -------EDIT--------
    Here's a link to my script so far. I want to add the AHDSR script (master for all groups) that EvilDragon has shown, as well as sliders for convolution verb (also all credit to EvilDragon) that effects all groups. I keep getting errors when trying to write them in.



    The AHDSR I want to get in (but so it works like a master on all groups)
    Code:
    on init
        make_perfview
    
        declare $count
    
        declare ui_knob $Attack (0,1000000,1)
        declare ui_knob $Hold (0,1000000,1)
        declare ui_knob $Decay (0,1000000,1)
        declare ui_knob $Sustain (0,1000000,1)
        declare ui_knob $Release (0,1000000,1)
       
        set_knob_unit($Attack, $KNOB_UNIT_MS)
        set_knob_unit($Hold, $KNOB_UNIT_MS)
        set_knob_unit($Decay, $KNOB_UNIT_MS)
        set_knob_unit($Sustain, $KNOB_UNIT_DB)
        set_knob_unit($Release, $KNOB_UNIT_MS)
       
        $Attack := get_engine_par($ENGINE_PAR_ATTACK, 0, find_mod(0,"ENV_AHDSR"), -1)
        $Hold := get_engine_par($ENGINE_PAR_HOLD, 0, find_mod(0,"ENV_AHDSR"), -1)
        $Decay := get_engine_par($ENGINE_PAR_DECAY, 0, find_mod(0,"ENV_AHDSR"), -1)
        $Sustain := get_engine_par($ENGINE_PAR_SUSTAIN, 0, find_mod(0,"ENV_AHDSR"), -1)
        $Release := get_engine_par($ENGINE_PAR_RELEASE, 0, find_mod(0,"ENV_AHDSR"), -1)
       
        make_persistent($Attack)
        make_persistent($Hold)
        make_persistent($Decay)
        make_persistent($Sustain)
        make_persistent($Release)
       
        read_persistent_var($Attack)
        read_persistent_var($Hold)
        read_persistent_var($Decay)
        read_persistent_var($Sustain)
        read_persistent_var($Release)
       
        set_knob_label($Attack, get_engine_par_disp($ENGINE_PAR_ATTACK, 0, find_mod(0,"ENV_AHDSR"), -1))
        set_knob_label($Hold, get_engine_par_disp($ENGINE_PAR_HOLD, 0, find_mod(0,"ENV_AHDSR"), -1))
        set_knob_label($Decay, get_engine_par_disp($ENGINE_PAR_DECAY, 0, find_mod(0,"ENV_AHDSR"), -1))
        set_knob_label($Sustain, get_engine_par_disp($ENGINE_PAR_SUSTAIN, 0, find_mod(0,"ENV_AHDSR"), -1))
        set_knob_label($Release, get_engine_par_disp($ENGINE_PAR_RELEASE, 0, find_mod(0,"ENV_AHDSR"), -1))
       
        message("")
    end on
    
    
    on ui_control ($Attack)
        $count := 0
        while ($count < $NUM_GROUPS)
            set_engine_par($ENGINE_PAR_ATTACK, $Attack, $count, find_mod(0,"ENV_AHDSR"), -1)
            inc($count)
        end while
    
        set_knob_label($Attack, get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1))
    end on
    
    on ui_control ($Hold)
        $count := 0
        while ($count < $NUM_GROUPS)
            set_engine_par($ENGINE_PAR_HOLD, $Hold, $count, find_mod(0,"ENV_AHDSR"), -1)
            inc($count)
        end while
    
        set_knob_label($Hold, get_engine_par_disp($ENGINE_PAR_HOLD, 0, 0, -1))
    end on
    
    on ui_control ($Decay)
        $count := 0
        while ($count < $NUM_GROUPS)
            set_engine_par($ENGINE_PAR_DECAY, $Decay, $count, find_mod(0,"ENV_AHDSR"), -1)
            inc($count)
        end while
    
        set_knob_label($Decay, get_engine_par_disp($ENGINE_PAR_DECAY, 0, 0, -1))
    end on
    
    on ui_control ($Sustain)
        $count := 0
        while ($count < $NUM_GROUPS)
            set_engine_par($ENGINE_PAR_SUSTAIN, $Sustain, $count, find_mod(0,"ENV_AHDSR"), -1)
            inc($count)
        end while
    
        set_knob_label($Sustain, get_engine_par_disp($ENGINE_PAR_SUSTAIN, 0, 0, -1))
    end on
    
    on ui_control ($Release)
        $count := 0
        while ($count < $NUM_GROUPS)
            set_engine_par($ENGINE_PAR_RELEASE, $Release, $count, find_mod(0,"ENV_AHDSR"), -1)
            inc($count)
        end while
    
        set_knob_label($Release, get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1))
    end on
    
    And the code for conv. verb I need to get in.
    Code:
    on init
        declare ui_slider $ConvSend (0,795000)
        declare ui_slider $ConvRecv (0,500000)
    
        set_control_par(get_ui_id($ConvRecv),$CONTROL_PAR_DEFAULT_VALUE,397000)
    
        make_persistent($ConvSend)
        make_persistent($ConvRecv)
    end on
    
    on ui_control ($ConvSend)
        set_engine_par($ENGINE_PAR_SENDLEVEL_0,$ConvSend,-1,7,1)
    end on
    
    on ui_control ($ConvRecv)
        set_engine_par($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN,$ConvRecv,-1,0,0)
    end on
    Someone who can help? Hopefully I will understand the language so that I'm able to write future features into my scripts easier.
     
    Last edited: Mar 28, 2014
  14. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    What kind of errors do you get?

    From glancing on the envelope parameters script, change:

    find_mod(0,"ENV_AHDSR")

    to:

    find_mod($count,"ENV_AHDSR")

    in the while loops of all ui_control callbacks. Also just to be sure, make get_engine_par_disp like this (but only in ui_control callbacks):

    get_engine_par_disp($ENGINE_PAR_HOLD, 0, find_mod(0,"ENV_AHDSR"), -1)
     
  15. Andreas Hald

    Andreas Hald NI Product Owner

    Messages:
    74
    Thanks EvilDragon. It was a matter of me not writing the codes the right places in the script (as I wrote), and it took me forever to figure it out (luckily a VERY HELPFUL guy helped me). Not sure I still quite understand it though - it's a pretty steep learning curve;0) But I managed to get it to work, though it creates other problems - which I will post in another thread - maybe others have experienced the same..It didn't really make a big difference changing those parameters, it works either way. But I'm sure as the VERY experienced scripter you are, that there's a reason to do so!;0)