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

New to Scripting ... How do I add AHSDR controls to the GUI?

Discussion in 'Scripting Workshop' started by truelight, Mar 10, 2011.

Thread Status:
Not open for further replies.
  1. truelight

    truelight Forum Member

    Messages:
    46
    I've created a couple of instruments of my own and I wanted to make the AHSDR modulation of the Amplifier section appear in the performance view. I did find that you can make your scripts appear in the GUI by adding


    make_perfview

    ... but I have no idea what else to type! I have several instruments with a dozen or so velocity levels and 8 round robins ... I need to make the Envelope knobs in performance view control all my groups at once! What do I need to do in scripting to accomplish this? Thank you so much for the help :D
    ---
    Ok I've googled a little bit and found on another forum a script very similar to what I want to accomplish ...

    http://vi-control.net/forum/viewtopic.php?t=19847&sid=379620442d1e0fb1d1fc8d580337121a


    The problem is, the knobs I now have only control the envelope of a single group! In my instrument I have anywhere from 30 to 200 groups (every round robin sample needs a group) that I need to all be controlled by these AHDSR knobs. So what do I need to do to make this occur? Thank you again :)
    ---
    Ok I don't want any of the extremely helpful scripting gurus on this forum to feel like they've wasted their time writing me a script ... I've figured it out :D . Here's my script (I took what I found on the other forum and tweaked it based on the responses there. It seems to be working so far!



    on init
    make_perfview
    declare $count

    declare ui_knob $Atk (0,1000000,1)
    set_text($Atk, "Attack")
    set_knob_unit($Atk, $KNOB_UNIT_MS)
    _set_engine_par($ENGINE_PAR_ATTACK, $Atk, 0, 0, -1)
    set_knob_label($Atk, _get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1))

    declare ui_knob $Hold (0,1000000,1)
    set_text($Hold, "Hold")
    set_knob_unit($Hold, $KNOB_UNIT_MS)
    _set_engine_par($ENGINE_PAR_HOLD, $Hold, 0, 0, -1)
    set_knob_label($Hold, _get_engine_par_disp($ENGINE_PAR_HOLD, 0, 0, -1))

    declare ui_knob $Decay (0,1000000,1)
    set_text($Decay, "Decay")
    set_knob_unit($Decay, $KNOB_UNIT_MS)
    _set_engine_par($ENGINE_PAR_DECAY, $Decay, 0, 0, -1)
    set_knob_label($Decay, _get_engine_par_disp($ENGINE_PAR_DECAY, 0, 0, -1))

    declare ui_knob $Sus (0,1000000,1)
    set_text($Sus, "Sustain")
    set_knob_unit($Sus, $KNOB_UNIT_DB)
    _set_engine_par($ENGINE_PAR_SUSTAIN, $Sus, 0, 0, -1)
    set_knob_label($Sus, _get_engine_par_disp($ENGINE_PAR_SUSTAIN, 0, 0, -1))

    declare ui_knob $Rel (0,1000000,1)
    set_text($Rel, "Release")
    set_knob_unit($Rel, $KNOB_UNIT_MS)
    _set_engine_par($ENGINE_PAR_RELEASE, $Rel, 0, 0, -1)
    set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1))
    end on


    on ui_control ($Atk)
    $count := 0
    while ($count <$NUM_GROUPS)
    _set_engine_par($ENGINE_PAR_ATTACK, $Atk, $count, 0, -1)
    inc($count)
    end while
    set_knob_label($Atk, _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, 0, -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, 0, -1)
    inc($count)
    end while
    set_knob_label($Decay, _get_engine_par_disp($ENGINE_PAR_DECAY, 0, 0, -1))
    end on

    on ui_control ($Sus)
    $count := 0
    while ($count <$NUM_GROUPS)
    _set_engine_par($ENGINE_PAR_SUSTAIN, $Sus, $count, 0, -1)
    inc($count)
    end while
    set_knob_label($Sus, _get_engine_par_disp($ENGINE_PAR_SUSTAIN, 0, 0, -1))
    end on

    on ui_control ($Rel)
    $count := 0
    while ($count <$NUM_GROUPS)
    _set_engine_par($ENGINE_PAR_RELEASE, $Rel, $count, 0, -1)
    inc($count)
    end while
    set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1))
    end on
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Your script is missing knob persistence, which means that knob positions won't be preserved when you save a NKI and reload it. Also, this script might fail if you use multiple envelopes per group (in this case you're encouraged to rename the envelope(s) and all envelope destinations, to do it you have to have script editor Edit window open (but you can hide the script editor itself), and right click the modulator/modulator intensity strip). Try this one instead:

    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
     
  3. plugaudio

    plugaudio Forum Member

    Messages:
    21
    why do i need this line and next 4

    $Attack := get_engine_par($ENGINE_PAR_ATTACK, 0, find_mod(0,"ENV_AHDSR"), -1)



    do I need similar in my first thing I did in KSP ( EQ CONTROL)



    on init
    make_perfview

    set_ui_height(3)


    declare const $eqslot := 0

    {first slot 0
    second slot 1
    ...}

    declare const $IS_INSERT_EFFECT := 1

    {0 - send FX
    1- instert FX}

    declare ui_knob $freq1 (0,1000000,1)
    declare ui_knob $freq2 (0,1000000,1)
    declare ui_knob $freq3 (0,1000000,1)

    declare ui_knob $gain1 (0,1000000,1)
    declare ui_knob $gain2 (0,1000000,1)
    declare ui_knob $gain3 (0,1000000,1)

    declare ui_knob $q1 (0,1000000,1)
    declare ui_knob $q2 (0,1000000,1)
    declare ui_knob $q3 (0,1000000,1)

    {units}

    set_knob_unit($freq1,$KNOB_UNIT_HZ)
    move_control ($freq1,1,1)
    set_knob_unit($freq2,$KNOB_UNIT_HZ)
    move_control ($freq2,1,3)
    set_knob_unit($freq3,$KNOB_UNIT_HZ)
    move_control ($freq3,1,6)
    set_knob_unit($gain1,$KNOB_UNIT_DB)
    move_control ($gain1,2,1)
    set_knob_unit($gain2,$KNOB_UNIT_DB)
    move_control ($gain2,2,3)
    set_knob_unit($gain3,$KNOB_UNIT_DB)
    move_control ($gain3,2,6)
    set_knob_unit($q1,$KNOB_UNIT_OCT)
    move_control ($q1,3,1)
    set_knob_unit($q2,$KNOB_UNIT_OCT)
    move_control ($q2,3,3)
    set_knob_unit($q3,$KNOB_UNIT_OCT)
    move_control ($q3,3,6)



    make_persistent($freq1)
    make_persistent($freq2)
    make_persistent($freq3)


    make_persistent($gain1)
    make_persistent($gain2)
    make_persistent($gain3)

    make_persistent($q1)
    make_persistent($q2)
    make_persistent($q3)

    read_persistent_var($freq1)
    read_persistent_var($freq2)
    read_persistent_var($freq3)

    read_persistent_var($gain1)
    read_persistent_var($gain2)
    read_persistent_var($gain3)

    read_persistent_var($q1)
    read_persistent_var($q2)
    read_persistent_var($q3)



    set_knob_label($freq1, get_engine_par_disp($ENGINE_PAR_FREQ1, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($freq2, get_engine_par_disp($ENGINE_PAR_FREQ2, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($freq3, get_engine_par_disp($ENGINE_PAR_FREQ3, -1, $eqslot, $IS_INSERT_EFFECT))


    set_knob_label($gain1, get_engine_par_disp($ENGINE_PAR_GAIN1, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($gain2, get_engine_par_disp($ENGINE_PAR_GAIN2, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($gain3, get_engine_par_disp($ENGINE_PAR_GAIN3, -1, $eqslot, $IS_INSERT_EFFECT))


    set_knob_label($q1, get_engine_par_disp($ENGINE_PAR_BW1, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($q2, get_engine_par_disp($ENGINE_PAR_BW2, -1, $eqslot, $IS_INSERT_EFFECT))
    set_knob_label($q3, get_engine_par_disp($ENGINE_PAR_BW3, -1, $eqslot, $IS_INSERT_EFFECT))


    end on

    on ui_control($freq1)

    set_engine_par($ENGINE_PAR_FREQ1, $freq1, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($freq1, get_engine_par_disp($ENGINE_PAR_FREQ1, -1, $eqslot, $IS_INSERT_EFFECT))

    end on

    on ui_control($freq2)

    set_engine_par($ENGINE_PAR_FREQ2, $freq2, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($freq2, get_engine_par_disp($ENGINE_PAR_FREQ2, -1, $eqslot, $IS_INSERT_EFFECT))

    end on


    on ui_control($freq3)

    set_engine_par($ENGINE_PAR_FREQ3, $freq3, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($freq1, get_engine_par_disp($ENGINE_PAR_FREQ3, -1, $eqslot, $IS_INSERT_EFFECT))

    end on


    on ui_control($gain1)

    set_engine_par($ENGINE_PAR_GAIN1, $gain1, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($gain1, get_engine_par_disp($ENGINE_PAR_GAIN1, -1, $eqslot, $IS_INSERT_EFFECT))

    end on



    on ui_control($gain2)

    set_engine_par($ENGINE_PAR_GAIN2, $gain2, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($gain2, get_engine_par_disp($ENGINE_PAR_GAIN2, -1, $eqslot, $IS_INSERT_EFFECT))

    end on



    on ui_control($gain3)

    set_engine_par($ENGINE_PAR_GAIN3, $gain3, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($gain1, get_engine_par_disp($ENGINE_PAR_GAIN3, -1, $eqslot, $IS_INSERT_EFFECT))

    end on

    on ui_control($q1)

    set_engine_par($ENGINE_PAR_BW1, $q1, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($q1, get_engine_par_disp($ENGINE_PAR_BW1, -1, $eqslot, $IS_INSERT_EFFECT))

    end on



    on ui_control($q2)

    set_engine_par($ENGINE_PAR_BW2, $q2, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($q2, get_engine_par_disp($ENGINE_PAR_BW2, -1, $eqslot, $IS_INSERT_EFFECT))

    end on



    on ui_control($q3)

    set_engine_par($ENGINE_PAR_BW3, $q3, -1, $eqslot, $IS_INSERT_EFFECT)

    set_knob_label($q3, get_engine_par_disp($ENGINE_PAR_BW3, -1, $eqslot, $IS_INSERT_EFFECT))

    end on
     
    Last edited: Mar 16, 2011
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    This sets the scripted knob to the correct position according to the saved parameter value in the NKI.


    Also please use www.pastebin.com to produce links to longer scripts - as you can see, NI forums can't handle long text strings well and the script needs a LOT of corrections before it can be pasted in Kontakt. You can also use
    Code:
     tags, but don't forget to DISABLE "Automatically parse links in text" checkbox before submitting your reply!
     
  5. plugaudio

    plugaudio Forum Member

    Messages:
    21
    thank you for help.

    am i right that there is no word about ENV_AHDSR in manual ?
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    That's a default name for envelope modulator. You can rename modulators if you have the Edit view of the Script Editor open (but you can close the Script Editor itself, to save vertical space), and right-clicking on the modulator panel or modulator intensity strip. Both are important if you're using a lot of differrent modulations.

    This is mentioned in KSP manual in the section where get/set_engine_par are explained.
     
  7. truelight

    truelight Forum Member

    Messages:
    46
    Hi EvilDragon,

    Your script seems to work perfectly! This was the exact issue I discovered once I had used my script for a little while ... thank you so much for taking the time to look at it and fix it! It's very appreciated :)
     
  8. jobro

    jobro Forum Member

    Messages:
    119
    I'm using the latest version of Kontakt (4.22), and for some reason this script doesn't seam to work for me. I tweak the knobs on the panel, but nothing seams to happen.

    Here is my version of the script (need some extra space for more controls), so here it is:

    Code:
    on init
    	make_perfview
    	set_ui_height(3)
    	declare 
    
    	declare ui_knob  (0,1000000,1)
    	declare ui_knob  (0,1000000,1)
    	declare ui_knob  (0,1000000,1)
    	declare ui_knob  (0,1000000,1)
    	declare ui_knob  (0,1000000,1)
    	
    	set_knob_unit(, )
    	set_knob_unit(, )
    	set_knob_unit(, )
    	set_knob_unit(, )
    	set_knob_unit(, )
    	
    	 := get_engine_par(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    	 := get_engine_par(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    	 := get_engine_par(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    	 := get_engine_par(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    	 := get_engine_par(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    	
    	make_persistent()
    	make_persistent()
    	make_persistent()
    	make_persistent()
    	make_persistent()
    	
    	read_persistent_var()
    	read_persistent_var()
    	read_persistent_var()
    	read_persistent_var()
    	read_persistent_var()
    	
    	set_knob_label(, get_engine_par_disp(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1))
    	set_knob_label(, get_engine_par_disp(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1))
    	set_knob_label(, get_engine_par_disp(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1))
    	set_knob_label(, get_engine_par_disp(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1))
    	set_knob_label(, get_engine_par_disp(, 0, find_mod(0,"ENV_AHDSR_VOLUME"), -1))
    	
    	message("")
    end on
    
    
    on ui_control ()
    	 := 0
    	while ( < )
    		set_engine_par(, , , find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    		inc()
    	end while
    
    	set_knob_label(, get_engine_par_disp(, 0, 0, -1))
    end on
    
    on ui_control ()
    	 := 0
    	while ( < )
    		set_engine_par(, , , find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    		inc()
    	end while
    
    	set_knob_label(, get_engine_par_disp(, 0, 0, -1))
    end on
    
    on ui_control ()
    	 := 0
    	while ( < )
    		set_engine_par(, , , find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    		inc()
    	end while
    
    	set_knob_label(, get_engine_par_disp(, 0, 0, -1))
    end on
    
    on ui_control ()
    	 := 0
    	while ( < )
    		set_engine_par(, , , find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    		inc()
    	end while
    
    	set_knob_label(, get_engine_par_disp(, 0, 0, -1))
    end on
    
    on ui_control ()
    	 := 0
    	while ( < )
    		set_engine_par(, , , find_mod(0,"ENV_AHDSR_VOLUME"), -1)
    		inc()
    	end while
    
    	set_knob_label(, get_engine_par_disp(, 0, 0, -1))
    end on
     
  9. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Umm.... that script is now completely messed up. Please disable "Automatically parses links in text" when posting scripts using
    Code:
     tag!
     
  10. jobro

    jobro Forum Member

    Messages:
    119
    Forget my question. I hadn't defined any AHDSR envelope. :)
     
Thread Status:
Not open for further replies.