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

Custom Knobs

Discussion in 'Scripting Workshop' started by E Keith B, Dec 27, 2021.

  1. E Keith B

    E Keith B New Member

    Messages:
    16
    Hello and Happy Holidays. I have this code below that I want to use to create an AHDSR for my Instrument. I borrowed this working script from this site. and it works. i have to tweak it to read the numbers it's suppose to read, but that's not my dilemma. I want to know How do I adjust this script to have custom knobs instead of Kontakt knobs. I know that I must ui_slider and not ui_knob. Any help would be appreciated. Below is the code.
    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)
       
       set_knob_defval($Attack, 0)
       set_knob_defval($Hold, 0)
       set_knob_defval($Decay, 0)
       set_knob_defval($Sustain, 1000000)
       set_knob_defval($Release, 670000)
       
       $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
    
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You use set_control_par_str() to set $CONTROL_PAR_PICTURE.
     
  3. E Keith B

    E Keith B New Member

    Messages:
    16
    I think I got it to work, using part the script posted above. I had a script that worked, but it only worked for one group. I added a "while" statement to my previous script, tweaked it and now I have it working for all the groups of my instrument. The script it posted below.
    Code:
    on init
       make_perfview
       set_ui_height_px(296)
       set_script_title("AHDSR")
       set_control_par($INST_ICON_ID,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
    
       declare $count
     
       declare ui_slider $knobAttack(0,1000000)
     
       declare $attack
       $attack := get_ui_id($knobAttack)
       set_knob_defval($knobAttack,0)
       set_control_par_str($attack,$CONTROL_PAR_PICTURE,"ChromedKnob2"){100px square}
       set_control_par($attack,$CONTROL_PAR_MOUSE_BEHAVIOUR,-1600)
       set_control_par($attack,$CONTROL_PAR_POS_X,98)
       set_control_par($attack,$CONTROL_PAR_POS_Y,16)
       declare ui_label $label (1,1)
       declare ui_label $ms(1,1)
       declare ui_label $name(1,1)
       set_text($label, get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1))
       set_text($ms, "ms")
       set_text($name, "ATTACK")
       hide_part ($label,$HIDE_PART_BG)
       hide_part($ms,$HIDE_PART_BG)
       hide_part($name,$HIDE_PART_BG)
       move_control_px($label,120,17)
       move_control_px($ms,148,17)
       move_control_px($name,126,105)
     
       make_persistent($knobAttack)
    
    end on
    
    on ui_control($knobAttack)
       $count := 0
       while ($count < $NUM_GROUPS)
           set_engine_par($ENGINE_PAR_ATTACK,$knobAttack, $count, find_mod(0,"ENV_AHDSR"), -1)
           inc($count)
       end while
           set_text($label, get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1 ))
     
    end on
    
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes, that should be mostly fine. But just to be 100% sure, you should use $count instead of 0 inside find_mod() too.
     
  5. E Keith B

    E Keith B New Member

    Messages:
    16
    Okay. I changed the script below and it works great. Thanks EvilDragon. Once again, you come through.
    Code:
    find_mod(0,"ENV_AHDSR") to
    find_mod($count, "ENV_AHDSR")
     
    Last edited: Dec 28, 2021