Kontakt Scripting

CONTROL VOLUME AND GROUPS FROM KEYSWITCHS

Professional script to control buttons for changing groups of sounds with the keyboard. And control the sound of each group separately. This script for peoples Interested in programming who want to benefit from it. Using it or modifying it as needed or create his own kontakt libraries to edit your music.
There is a complet model of this script in kontakt library with all resources and container and pictures and texts for download on the end of poste.


{********begin of script**********}

on init  
    make_perfview 
    set_script_title("MASTER")   
    set_ui_height_px(232)
    set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"wallpaper") 
    set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"logo")


{***********************keyboard*************************}
declare $keys_black
    while ($keys_black<128)
        set_key_color($keys_black,$KEY_COLOR_BLACK)
        inc($keys_black)
    end while
    $keys_black := 0
    while ($keys_black<128)
        set_key_color($keys_black+1,$KEY_COLOR_WHITE)
        set_key_color($keys_black+3,$KEY_COLOR_WHITE)
        set_key_color($keys_black+6,$KEY_COLOR_WHITE)
        set_key_color($keys_black+8,$KEY_COLOR_WHITE)
        set_key_color($keys_black+10,$KEY_COLOR_WHITE)
        $keys_black := $keys_black+12
    end while
declare $keys_range
    $keys_range := 60
    while ($keys_range<61)
        set_key_color($keys_range,$KEY_COLOR_BLUE)
        inc($keys_range)
    end while

        set_key_color(41,$KEY_COLOR_RED)
        set_key_color(43,$KEY_COLOR_RED)
        set_key_color(45,$KEY_COLOR_RED)
{***********************declare labels*************************}
  declare ui_label $lbl_1(1,1)
  move_control_px($lbl_1,125,5)
  hide_part ($lbl_1,$HIDE_PART_BG)
  set_text($lbl_1,"GROUP 1                                    GROUP 2                                     GROUP 3")
  set_control_par(get_ui_id($lbl_1),$CONTROL_PAR_HEIGHT,20)
  set_control_par(get_ui_id($lbl_1),$CONTROL_PAR_WIDTH,600)
  set_control_par(get_ui_id($lbl_1),$CONTROL_PAR_FONT_TYPE,1)

  declare ui_label $lbl_2(1,1)
  move_control_px($lbl_2,120,120)
  hide_part ($lbl_2,$HIDE_PART_BG)
  set_text($lbl_2,"VOLUME 1                                  VOLUME 2                                   VOLUME 3")
  set_control_par(get_ui_id($lbl_2),$CONTROL_PAR_HEIGHT,20)
  set_control_par(get_ui_id($lbl_2),$CONTROL_PAR_WIDTH,600)
  set_control_par(get_ui_id($lbl_2),$CONTROL_PAR_FONT_TYPE,1)            

{********************declare buttons**************************}         

  declare ui_button $button_1
    set_control_par(get_ui_id($button_1),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($button_1),$CONTROL_PAR_WIDTH,50)
    set_control_par(get_ui_id($button_1),$CONTROL_PAR_FONT_TYPE,3)
    set_control_par_str(get_ui_id($button_1),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($button_1),$CONTROL_PAR_PICTURE,"pv_urban_button_onoff")
     $button_1 := 1
   
   
  declare ui_button $button_2
    set_control_par(get_ui_id($button_2),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($button_2),$CONTROL_PAR_WIDTH,50)
    set_control_par(get_ui_id($button_2),$CONTROL_PAR_FONT_TYPE,3)
    set_control_par_str(get_ui_id($button_2),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($button_2),$CONTROL_PAR_PICTURE,"pv_urban_button_onoff")

    declare ui_button $button_3
    set_control_par(get_ui_id($button_3),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($button_3),$CONTROL_PAR_WIDTH,50)
    set_control_par(get_ui_id($button_3),$CONTROL_PAR_FONT_TYPE,3)
    set_control_par_str(get_ui_id($button_3),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($button_3),$CONTROL_PAR_PICTURE,"pv_urban_button_onoff")


    move_control_px($button_1,130, 20)
    move_control_px($button_2,290, 20)
    move_control_px($button_3,450, 20)

{*********************declare volume*********************}

  declare ui_slider $volume_01(0, 1000000)
  set_control_par_str(get_ui_id($volume_01),  $CONTROL_PAR_PICTURE, "pv_vintage_drums_knob")
  set_control_par(get_ui_id($volume_01),$CONTROL_PAR_MOUSE_BEHAVIOUR,-750)
  make_persistent($volume_01)

  declare ui_slider $volume_02(0, 1000000)
  set_control_par_str(get_ui_id($volume_02),  $CONTROL_PAR_PICTURE, "pv_vintage_drums_knob")
  set_control_par(get_ui_id($volume_02),$CONTROL_PAR_MOUSE_BEHAVIOUR,-750)
  make_persistent($volume_02)

  declare ui_slider $volume_03(0, 1000000)
  set_control_par_str(get_ui_id($volume_03),  $CONTROL_PAR_PICTURE, "pv_vintage_drums_knob")
  set_control_par(get_ui_id($volume_03),$CONTROL_PAR_MOUSE_BEHAVIOUR,-750)
  make_persistent($volume_03)


  move_control_px($volume_01,  135, 70)
  move_control_px($volume_02,  295, 70)
  move_control_px($volume_03,  455, 70)

{********************control buttons************************}

end on
on ui_control($button_1)
  note_off($ALL_EVENTS)
  set_controller(1,0)
  $button_1:=1
  $button_2:=0
  $button_3:=0
end on
on ui_control($button_2)
  note_off($ALL_EVENTS)
  set_controller(1,0)
  $button_1:=0
  $button_2:=1
  $button_3:=0
end on
on ui_control($button_3)
  note_off($ALL_EVENTS)
  set_controller(1,0)
  $button_1:=0
  $button_2:=0
  $button_3:=1
end on
{*********************control volume************************}
on ui_control ($volume_01)
    set_engine_par($ENGINE_PAR_VOLUME,$volume_01,0,-1,-1)
end on
on ui_control ($volume_02)
    set_engine_par($ENGINE_PAR_VOLUME,$volume_02,1,-1,-1)
end on
on ui_control ($volume_03)
    set_engine_par($ENGINE_PAR_VOLUME,$volume_03,2,-1,-1)
end on

{********************keyswitchs************************}

on note
    if (%KEY_DOWN[41] = 1)
    $button_1 := 1
    $button_2 := 0
    $button_3 := 0
   end if

   if (%KEY_DOWN[43] = 1)
    $button_1 := 0
    $button_2 := 1
    $button_3 := 0
   end if

   if (%KEY_DOWN[45] = 1)
    $button_1 := 0
    $button_2 := 0
    $button_3 := 1
   end if
{***********************load groups***************************}
 disallow_group($ALL_GROUPS)
      if ($button_1 = 1)
        allow_group(0)
      end if
      if ($button_2 = 1)
        allow_group(1)
      end if
      if ($button_3 = 1)
        allow_group(2)
      end if
     
end on

{********end of script**********}


This script is valid for all versions of kontakt just copy it in the slot text and add your wallpaper.
You can use this script alone or you can add it to another script.
This script edited and scripted by BOUZIANE MOHAMMED FAYCEL.

Download the library model here