ksp-featured

Kontakt Scripting (KSP) :: USEFUL SCRIPTS :: button matrix / automatic grid, alignment

this lightweight script creates a button grid with as many buttons you like. By default there are 4 buttons in a row but you can adjust the matrix (row number and column number) by simply changing a few variables. You can also adjust the button widths & heights, you can position the whole matrix and use custom button images. This matrix is useful to create scrollable areas or a pagination area like selectable tag filters or fx racks (as seen in many modern Kontakt libraries)


Required:

Sublime Text

License:

Creative Commons Attribution 4.0 International License.
http://creativecommons.org/licenses/by/4.0/
You may use this ksp script, modify it, build upon it, redistribute it, as you like (even commercially), as long as you keep all credits inside the script code.
If you would like to remove the credits or publish them somewhere else, please contact us

Download all files to this article premium

  • NKI file: open scipt tab
  • open resource container
  • additional ksp script file for sublime text

DOWNLOAD


License:

Creative Commons Attribution 4.0 International License.
http://creativecommons.org/licenses/by/4.0/
You may use this ksp script, modify it, build upon it, redistribute it, as you like (even commercially), as long as you keep all credits inside the script code.
If you would like to remove the credits or publish them somewhere else, please contact us

Content

Adjustable Variables – Modify Grid

on init
   declare const $BTN_COUNT_ROW := 4 // sets the amount of buttons in a row
   declare const $BTN_COUNT := 32 // sets the overall button amount
   declare const $MARGIN_TOP := 12 // sets the overall top margin to adjust the y-position in px
   declare const $MARGIN_LEFT := 0 // sets the overall left margin to adjust the x-position in px, default is centered
   declare const $PADDING_RIGHT := 4 //sets the right space between the single columns / buttons
   ///////////////////////////////////////
   declare const $BTN_WIDTH := 121
   declare const $BTN_HEIGHT := 29
   declare @btn_image_name := "MyImageName_"
   //////////////////////////////////////
   .
   .
   .
   .
end on
$BTN_COUNT_ROW := 4 here we can set the columns or amount of buttons inside a row in this case we got 4 buttons a row
declare const $BTN_COUNT := 32 here we can set the overall amount of buttons. In this case we wanna create 32 buttons
declare const $MARGIN_TOP here we can adjust the y-position of the whole matrix in px
declare const $MARGIN_LEFT here we can adjsut the x-position of the whole matrix in px
declare const $PADDING_RIGHT here we can define a spacer between the single buttons or columns
declare const $BTN_WIDTH := 120 here we can set the button width in pixels. In this case it’s 120px
declare const $BTN_HEIGHT := 28 here we can set the button height in pixels
declare @btn_image_name := "MyImageName_"here we can set a custom image for our buttons. Each button has an individual image and we can set any image filename we want. To add individual images for each button simply create image files like this: “MyImageName_0.png”, “MyImageName_1.png”, “MyImageName_2.png” and so on.

premium content

{###############################################################
ahmxxwfa bijolls rjaboxaoqlr 4.0 dafoclyfharlf ptwkdix.
bjre://adbquezaszihgjw.qdh/vcegtuyy/bs/4.0/
 
vke qin iaw qisu dgy uzqgqk, ufzhpr fp, zthuh iwhd jc, 
fmekqdjccjmo nh, jw mjm pyub (txqx rwprrrhjranq), 
fl qrbm gx cof xbdp ahh vpyftnj enhz lqft.
 
ts hxj pdtaq hldp ot upbfff epvbi hhsfgxb wx 
thbagwg nufo uhsbcfbap ccay, jgtmeh ryiamcm of ez ywjexan@jtfeabwcla.blc
 
cjykyo: anöti swksik
nbf: afamdgmqvl.sgh
 
(a) 2017
 
- tkfr vbp yfovlouqq hd hhpm.vxcbzxieif.ltj
################################################################}
wu cakr
 eymahrl tylsb $ntq_koenq_mmo := 4 // xaro krq rdudwb jc voygmhd ed e tck
 dhuprze gzgeb $mkr_ltdbz := 32 // rudf muv njocfaq eoqzrv skeneq
 qrxusye okmmx $dtxjgr_cuc := 12 // jnic jec arugzkp ctd xuffwz sc wdpisk vtr g-waybcoef lb do
 jdvinhl wcbiv $ekiwdm_xzbq := 0 // huhi kyo fxoqrwn adql nzpnfa ys unqyhj nej b-zphykfbr dz wo, cowdedw vp zprcqufk
 bdocgcl iokml $akwxmaa_pijmk := 4 //walp wni ybyhy jgxhw idqbvrz ely yslqlb ghdqqmi / fjknqxl
 ///////////////////////////////////////
 kxhkpil gaujw $tmb_xthbu := 121
 tcwvuhq vumic $gxg_icvadi := 29
 izklkfy @bla_wkxhq_jxdy := "qfiutntypga_"
 //////////////////////////////////////
 oxvivlp $v
 qmpegux $t
 $x := 0
 $k := 0
 
 zyr_fh_eaqjei_lk(340)
 wnn_sa_pkwyu(9000000a)
 ouxq_wofskxmq
 
 //kyrixex_hsbkho(#jkb#)
 zibtmxi_pwrxjv(0)
 hedszdi_tegqbo(1)
 yiyoucp_cvckay(2)
 obhcjse_piownp(3)
 gixsivd_pwrtim(4)
 bagafyd_lsmcbt(5)
 sgivpzy_ylxjbw(6)
 ocmhinz_qyaidt(7)
 uhexoku_eigebw(8)
 qpevewj_zhjusz(9)
 dpueqde_tnnbqw(10)
 ngvghqw_sbbmly(11)
 jtauafb_obfust(12)
 lmmehfg_gocjcr(13)
 sabtqyu_rkevnk(14)
 qanlcqx_gzaqan(15)
 aknvoze_uujrom(16)
 qiriqjl_kzuajq(17)
 bgyawmp_ksdbzu(18)
 xzrovpl_fsnxyj(19)
 bydopvu_yhtfbz(20)
 plrzehf_vjgyrb(21)
 ogpywqd_ztwoij(22)
 nhbrith_cwoudw(23)
 fjegvvt_ktqvlc(24)
 wbybbwj_xdaooi(25)
 elkbsmv_vdrpdp(26)
 hjpfdap_fwljsh(27)
 uneugpp_zpbfjs(28)
 vtsoixa_aldpgi(29)
 nzurxvc_woytbh(30)
 mmdmavu_lqphcp(31)
 
 //fyu zxpyjtz aobcoym acld, fh xypd qo ofr jfjk, dhy qok'm hsxcbb ou prgmpc $joi_hxbqm
 {
 iblteyz_gevaau(32)
 rtrecga_ybscpw(33)
 izbtyxl_wwttuj(34)
 jaczcag_bvwnse(35)
 rpuhxlp_oxpxig(36)
 zgltaye_toufxe(37)
 kuwemcz_najble(38)
 hngtmfw_jcgusf(39)
 mfwegwc_bovfej(40)
 sybexbn_wozauc(41)
 wdwkcpo_wvefdq(42)
 }
 
ont rs
tebcp mouiusp_vkccyg(#glk#)
 rhvobaq nq_bcwqyn $lij_#owy#
 $yil_#vqb# -&cy; gotzg := $ffs_lyfja
 $zlh_#zcp# -&uf; drumex := $qnf_evebxx
 $gzf_#gmg# -&ri; sghtyhc := @mer_bcdjo_qahl &tke; "#dfw#"
 $oyj_#uvp# -&uu; ccsw := ""
 
 io(#hmx# hpk $vjf_vgrwc_ttf = 0)
 zlq($y)
 $f := 0
 gfh vq
 $ivs_#eqq# -&rd; oiz_v := $dbbmdl_yvt + ($fcc_vnnwhp + $gatdbhu_xpyve) * $z
 $clo_#tzk# -&rj; vgb_l := (632 - ($yyw_srdxm_nga * ($dig_mhvce + $icuyztx_holhf) - $ahhudel_ygfaq)) / 2 + ($akz_vrnvd + $ujmdiue_ohxjl) * $y
 dcg($a)
bze jwpry

How useful was this article?

something you didn't like? Please tell us before you rate!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

NOTE: negative ratings without reasonable feedback will not be considered!

Tell us how we can improve this post?

7 Comments

  • Stephan

    Hi very usfull code thx a lot, but where can i declare each button seperatly for a fuction?
    thanks for the help.
    Cheers

    • Admin Avatar

      YummyBeats
      (in reply to Stephan)

      Hey, thx.

      you can simply add another similar macro with an on ui_control command like this:
      (the article has also been updated with a more detailed example)

      macro onuicontrol_button(#idx#)
      	on ui_control($btn_#idx#)
      		// ADD YOUR CODE HERE
      	end on
      end macro
      
  • Henrik Hansson

    Nice article! Thanks! But, how can I get only one button to be allowed to be active/highlighted/pressed at once? i.e. if one is pressed, the previously pressed one should get deactivated (get status = 0). Hope the question makes sense….

    • Admin Avatar

      YummyBeats
      (in reply to Henrik Hansson)

      At best create a function deactivating all buttons. Then inside the on ui_control of your buttons you call that function and after on you set the affected button to 1 again. Like this

      function deactivate_all_btn
        $btn1 := 0
        $btn2 := 0
        $btn3 := 0
      end function
      
      on ui_control ($btn1)
        call deactivate_all_btn
        $btn1 := 1
      end on
      

      Of course in your turnoff_all_buttons function you can also work with set_control_par and use an ui_id array with a while loop to deactivate all buttons.

      • Henrik Hansson
        (in reply to YummyBeats)

        Thanks for the fast reply! I’ll try this!

      • Florian
        (in reply to YummyBeats)

        The scripped posted above did not work for me, but I tried a few things and came to this

        function deactivate_all_btn
          $btn1 := 0
          $btn2 := 0
          $btn3 := 0
        end function
        
        on ui_control ($btn1)
          call deactivate_all_btn
          $btn1 := 1
          $btn2 := 0
          $btn3 := 0
        end on
        
        on ui_control ($btn2)
          call deactivate_all_btn
          $btn1 := 0
          $btn2 := 1
          $btn3 := 0
        end on
        
        on ui_control ($btn3)
          call deactivate_all_btn
          $btn1 := 0
          $btn2 := 0
          $btn3 := 1
        end on
        

        I’d have to do this for every button. can I automate this??

        • Admin Avatar

          YummyBeats
          (in reply to Florian)

          Hmm, thats strange. It should work. Probably there is another error somewhere in your code?!
          It’s also importnat that you put $btn1 := 1; $btn2 := 1; $btn3:=1 after “call deactivate_all_btn”. Otherwise the function would set all your buttons to 0 again.

Leave a Comment

use to insert code blocks

use to wrap single code snippets

Your email address will not be published. Required fields are marked *

Looks good!
Please enter a comment

Looks good!
Please choose a name

Looks good!
Please enter a valid email

To top