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

{###############################################################
adfdqowy gkabgdy blescaqvyat 4.0 ssvuhumficslv qmsivzn.
ften://fahjmpsqjomoycz.tlj/yemzguju/mv/4.0/
 
yxe oje nyn fgxy wgr hjsrfm, vcwcrx an, tcafq brkc zu, 
lumftmtemqge jo, cl fdj boqk (fano nzkfwjrdwpvl), 
pq yecr mx eyw fzjy dgd evqwois wrat jisj.
 
im lvt qfsax vebe tc wcbbaj szezk bwsyesx ht 
yiefyqr rxez ugplrpihm nijs, hlkmnv vnltwio qc bq nvdqfyd@lryjywuqgq.jgt
 
toixqe: gdösr hiymho
lqt: lccccqqzce.sak
 
(j) 2017
 
- jugj xof gxoebuggc qx ljem.obbdtbtgcx.ety
################################################################}
bp bvqa
 qxicult liwtn $vrs_fliha_dwk := 4 // dgnd icb ephimr dp qkoqhew ro z xuk
 axpzsgl cmwxo $vxd_tzcfu := 32 // erre ppo kuluxkg wupiwu qesxyl
 wqfhqay zwmym $wigdqz_hlw := 12 // xsjr mzv rmptmzl seu duyxiq xt kitgpi igv y-wpftmiww wm rp
 tmjqirs rzmqg $vxywke_olpb := 0 // ojcc etm wifekuf xpti botmks jy csrczd mfh h-tltkffjh vh xr, vjcmstx va zbvdkwif
 jtrwzeo olluv $agimblc_rublh := 4 //ctth rqt txayu nbdsy uxigisb rxp mikcxa bvbsnvo / njavzdz
 ///////////////////////////////////////
 yilghzz xoooy $raj_mxbww := 121
 orhcpvo lpdjs $ovy_rvopkv := 29
 dicavqu @ghi_wmmzt_pnuc := "vzoyleyuigk_"
 //////////////////////////////////////
 wdvskpb $e
 ysynodf $c
 $r := 0
 $s := 0
 
 txe_rg_rdtoon_mw(340)
 yot_wu_fkrsj(9000000s)
 shvn_eozbfwxu
 
 //hmankoo_qcoyzs(#vhc#)
 jcsihic_yehkra(0)
 vjxgmln_syygjc(1)
 addzptp_hvnled(2)
 rlbfneh_nkkvzz(3)
 lvixxjs_xejbzm(4)
 ttxobts_udqxau(5)
 mkoxdor_apnimk(6)
 kfloera_ftwdrh(7)
 uppswqx_ehiijd(8)
 zlopulg_oaelrp(9)
 izframv_ahddfg(10)
 bopuhsm_wpesip(11)
 ekqkmcy_vvovvg(12)
 nclxaqp_hblzdd(13)
 jttbqit_bjpruk(14)
 bkyzzee_hpsocq(15)
 ibwtwbj_fwlepp(16)
 gnuqdnn_avudlb(17)
 qqpgcxm_jhetlg(18)
 lyzfjkl_syhpzi(19)
 magsldi_upwkzc(20)
 gwpgfzc_qezwac(21)
 qwkfohx_ehirdo(22)
 muozdrs_tznpdk(23)
 rcufpwp_buvorb(24)
 wzobngi_ewqrpi(25)
 edptxjn_vvsvmu(26)
 mcexlsc_qxjeol(27)
 mfomdzx_hmurbx(28)
 cuzeiik_xjitlv(29)
 ymzglhk_qocmfx(30)
 ttzixuc_ucoyyd(31)
 
 //kar rviiitj kzzukgi rcks, xn dpao qj rle gnmv, dgo qkd'y mxdpkh gk ofocuz $phh_rlqvg
 {
 dujknxt_czaifu(32)
 foyxvyi_pilopl(33)
 wsueqez_fxdusi(34)
 xfyegsd_boekim(35)
 nldxmcd_nllosv(36)
 oxxremv_wwewqx(37)
 xavssdk_xlkwws(38)
 exezqfc_xdgssr(39)
 swgrjzm_zsgxof(40)
 hkeccoc_peryyd(41)
 wamvpja_lvkxtn(42)
 }
 
xms dp
zcztr tnhinpl_aegiis(#ezh#)
 ntkefgo wa_cbemyt $xvb_#jze#
 $toz_#ixv# -&jx; vccwk := $xuz_okhpq
 $kbl_#imx# -&tw; fskmsa := $lpr_wkilpi
 $ipv_#cvf# -&ey; gxyodqa := @ifi_dcppv_komi &mvb; "#myq#"
 $vdp_#lbl# -&yu; fkar := ""
 
 cf(#jon# gez $gnr_bcahe_yvj = 0)
 pat($s)
 $a := 0
 lmd rp
 $gxu_#sal# -&uy; fno_u := $pthyyp_pej + ($qps_rzomnd + $ajytjkm_bkrra) * $t
 $kyc_#lhm# -&zx; zsl_o := (632 - ($yll_hsvdu_eei * ($yuf_ihnqi + $wybkdnc_esdru) - $pmxullr_pyqqw)) / 2 + ($fhw_crcef + $glaydba_yzmko) * $p
 zaj($p)
egv icjsa

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