Kontakt and keyboard colours

VST, AU, AAX, CLAP, etc. Plugin Virtual Instruments Discussion
RELATED
PRODUCTS

Post

You need to set the starting value for $i and $j before the while loop.

Post

Thank you for responding!

I tried assigning them values at the begining outside of the if and inside it before the while and no go.

Maybe if I post what I have you can spot what I'm doing wrong?

Code: Select all

on init
make_perfview

declare $a:=1
declare $num_layers:=5
declare $i
declare $j

declare ui_menu $select
add_menu_item ($select,"Music/FX",1)
add_menu_item ($select,"Torgo/Master",2)
add_menu_item ($select,"Margaret/Michael",3)
add_menu_item ($select,"Couple/Cops/Debbie/Wives",4)
add_menu_item ($select,"Servo/Crow/Joel",5)

declare ui_knob $attack (0,127,1)
declare ui_knob $release (0,127,1)

set_knob_defval ($attack,0)
set_knob_defval ($release,0)


set_text ($attack,"Attack")
set_text ($release,"Release")

move_control ($select,3,2)
move_control ($attack,2,3)
move_control ($release,3,3)

make_persistent ($select)
make_persistent ($attack)
make_persistent ($release)
set_control_par (get_ui_id ($select), $CONTROL_PAR_WIDTH, 136)

$attack := _get_engine_par($ENGINE_PAR_ATTACK,0,0,-1) /7874
set_knob_label($attack,_get_engine_par_disp($ENGINE_PAR_ATTACK,0,0,-1))
set_knob_unit ($attack, $KNOB_UNIT_MS)

$release := _get_engine_par($ENGINE_PAR_RELEASE,0,0,-1) /7874
set_knob_label($release,_get_engine_par_disp($ENGINE_PAR_RELEASE,0,0,-1))
set_knob_unit ($release, $KNOB_UNIT_MS)


if ($select=1)
$i:=60
 while ($i <= 72)
   set_key_color($i,$KEY_COLOR_GREEN)
   inc ($i)
 end while
end if


if ($select=2)
$j:=80
 while ($j <= 92)
   set_key_color($j,$KEY_COLOR_RED)
   inc ($j)
 end while
end if

end on

on note

 if ($select=1)
    disallow_group($ALL_GROUPS)
    allow_group(2)
 end if
 
 if ($select=2)
    disallow_group($ALL_GROUPS)
    allow_group(1)
 end if
 
 if ($select=3)
    disallow_group($ALL_GROUPS)
    allow_group(0)
 end if
 
 if ($select=4)
    disallow_group($ALL_GROUPS)
    allow_group(4)
 end if
 
 if ($select=5)
    disallow_group($ALL_GROUPS)
    allow_group(3)
 end if

end on

on ui_control ($attack)
 $a :=0
 while ($a <= $num_layers)
   _set_engine_par($ENGINE_PAR_ATTACK,$attack * 7874,$a,0,-1)
 inc($a)
 end while
   set_knob_label($attack,_get_engine_par_disp($ENGINE_PAR_ATTACK,0,0,-1))
end on

on ui_control ($release)
 $a :=0
 while ($a <= $num_layers)
   _set_engine_par($ENGINE_PAR_RELEASE,$release * 7874,$a,0,-1)
 inc($a)
 end while
   set_knob_label($release,_get_engine_par_disp($ENGINE_PAR_RELEASE,0,0,-1))
end on
It's

Post

Aha.


Add read_persistent_var($select) below make_persistent($select). When you use a value of a persistent variable/UI control within init callback (like you're doing here), you need to use read_persistent_var() to read that value so it can be used properly.

Post

EvilDragon wrote:Aha.


Add read_persistent_var($select) below make_persistent($select). When you use a value of a persistent variable/UI control within init callback (like you're doing here), you need to use read_persistent_var() to read that value so it can be used properly.
WOOHOO signs of life after adding that line. It seems to be somehow working, but it's not updating. If I save the instrument, it will load up with the correct color for the group, but won't change unless I save and reload with the other group selected. I'm not sure if it's because it is in on init or is there a way I can make it refresh. I tried going in on note, but things go crazy, plus this doesn't have anything to do with notes playing, right?

I hate to keep asking, but I'm not a programmer and this is the last block before I can release this.

Code: Select all

declare $i:=60
declare $j:=80

~O~O~O~O~O~O~O~O~O~

if ($select=1)
set_key_color($i,$KEY_COLOR_NONE)
 while ($i <= 72)
   set_key_color($i,$KEY_COLOR_GREEN)
   inc ($i)
 end while
end if

if ($select=2)
set_key_color($i,$KEY_COLOR_NONE)
 while ($j <= 92)
   set_key_color($j,$KEY_COLOR_RED)
   inc ($j)
 end while
end if
It's

Post

...I don't know if I got this right, but you'd need to add these lines in your select control callback, too. as I understand it now, you have these lines only added to the init callback. these lines also would have to be executed when you turn your select control...

Post

What Ioachm said. The "on init"-callback is only executed once, when you start the script. While the script is running, it is not executed again, so if you want the key colour to react to changes that are made while the script is running, the select-statement has to be in another callback, most suitably the on ui_control callback of the menue where the different sample groups can be selected.

Post

BARRGHRGH I'm one step closer looks like. I'm not too sure about the terms (or anything else for that matter), but I added the color changes on a ui_control callback? Now the color will appear when its supposed to, however, I can't get the COLOR_NONE to work and erase the previous group color. In fact, I don't think I've ever seen COLOR_NONE work.

It feels like I'm so close :hyper:

Code: Select all

on ui_control ($select)

if ($select=1)
 while ($j <= 92)
 set_key_color($j,$KEY_COLOR_NONE)
 inc ($j)
 end while
  while ($i <= 72)
  set_key_color($i,$KEY_COLOR_GREEN)
  inc ($i)
  end while
end if

if ($select=2)
  while ($i <= 72)
  set_key_color($i,$KEY_COLOR_NONE)
  inc ($i)
  end while
   while ($j <= 92)
   set_key_color($j,$KEY_COLOR_RED)
   inc ($j)
 end while
end if

end on
It's

Post

Just use KEY_COLOR_WHITE to the same effect. (It won't paint the black keys in white). And don't forget to reset $i and $j to the appropriate values in your on ui_control $select-callback, otherwise the whole thing will work only once (because the variables are only set to the appropriate values once - in the on init callback).

Another suggestion for an improvement: To make things more simple I'd actually set the whole keyboard to WHITE just before your select-statement whenever the "select"-menue is used. So you won't have to bother with "whitening" the keys of the previous group in every if-statement. (If you don't do this, you will probably need an extra variable to retain the value of the previously selected group (=the previous value of $select), otherwise the script wouldn't know which keys should be reset to white, as after changing the "select"-control, that value is gone).

Post

In fact you don't have to use two different counters. Just use $i, it's enough.

Post

streifentier wrote:And don't forget to reset $i and $j to the appropriate values in your on ui_control $select-callback, otherwise the whole thing will work only once (because the variables are only set to the appropriate values once - in the on init callback).
OMG that was it.

TBH, even the more elaborate of my instruments have scripting that i have picked up from here and there and consist of pieces put together mostly thought trial and error, and I don't have a real understanding of what the lines and sections do. I can hack, but I can't really start one from scatch. I think this one may end up being a learning experience.

I'm gonna get some sleep now that I'm pretty sure I have what I need, and come back and try your suggestions. The instrument actually has 5 groups, 4 have samples through the same 4 octaves, while one group has some holes. That's why I needed some kind of marker so one knows which keys trigger samples.

Thank you all for your help. I was about to do it in a half-usable way :oops:
It's

Post

EvilDragon wrote:Well that's as easy as running a loop and then using if statements within, for example:

Code: Select all

on init
    declare $i := 36
    while ($i <= 62)
        if (in_range($i,36,48))
            set_key_color($i,$KEY_COLOR_YELLOW)
        end if
        if (in_range($i,49,62))
            set_key_color($i,$KEY_COLOR_RED)
        end if
        inc($i)
    end while
end on
Evil, I just tried this - my first K5 scripting attempt *EVER* - - and it worked **PERFECTLY**!! I actually wanted to set up six different key groups with six different colors and that's exactly what I got! Brilliant! Huge thanks for posting it!.
A question? In Kontkat 5, are there more than the seven colors listed for K4?

Post

No, all key colors are the same as in K4.

Post Reply

Return to “Instruments”