30% OFF + bonus gift bundle using the discount code: Holiday2024

One of the crucial finishing touches to add to a Kontakt library is the key colors. Because the natural key colors obtained from the zones mapped in the instrument might not accurately represent the key ranges of the instrument, or if you don't use the group start options for keyswitches, you'll need to manually set the key colors through scripting.

While setting key colors through Kontakt is very straightforward using the "set_key_color()" function, I have a few recommendations on how to improve on this.

Firstly, don't set the key colors with the "set_key_color()" function directly. Instead, use an array to store the key colors first, setting all the ranges and keyswitches necessary, and then use a single loop to actually set the key colors on Kontakt's keyboard. Here's an example:

on init
  declare $counter
  declare %key_color[128]

  { initialize key colors }
  $counter := 0
  while ($counter <= 127)
    %key_color[$counter] := $KEY_COLOR_NONE
    inc($counter)
  end while

  { set an example key range }
  $counter := 48
  while ($counter <= 72)
    %key_color[$counter] := $KEY_COLOR_BLUE
    inc($counter)
  end while

  { set an example keyswitch }
  %key_color[36] := $KEY_COLOR_RED

  { set key colors }
  $counter := 0
  while ($counter <= 127)
    set_key_color($counter, %key_color[$counter])
    inc($counter)
  end while
end on

Another thing many libraries nowadays do is show unused key ranges as entirely black rather than Kontakt's own black and white default. Here's my approach to scripting this technique:

on init
  declare $counter
  declare %key_color[128]
  declare %black_keys[5] := (1, 3, 6, 8, 10)

  { default to all black }
  $counter := 0
  while ($counter <= 127)
    if (search(%black_keys, $counter mod 12) # -1)
      %key_color[$counter] := $KEY_COLOR_WHITE
    else
      %key_color[$counter] := $KEY_COLOR_BLACK
    end if
    inc($counter)
  end while

  { set an example key range }
  $counter := 48
  while ($counter <= 72)
    %key_color[$counter] := $KEY_COLOR_BLUE
    inc($counter)
  end while

  { set an example keyswitch }
  %key_color[36] := $KEY_COLOR_RED

  { set key colors }
  $counter := 0
  while ($counter <= 127)
    set_key_color($counter, %key_color[$counter])
    inc($counter)
  end while
end on

Of course, if you're using Nils' scripting editor or Sublime Text package, the "while" loops can be simplified to "for" loops, but this example should give you a good idea of one approach for setting the key colors in your Kontakt instrument.


Enjoyed reading this blog article? Here are some related topics with more articles you'll like: Articles, DIY Sampling, Kontakt Scripting


Share with Your Friends