How do I get set_key_color to apply on instrument load?

drobertbaker
drobertbaker Member Posts: 3 Newcomer
edited October 2024 in Scripting Workshop

The simplest script in Kontakt 6:

on init
set_key_color(1, $KEY_COLOR_RED)
end on

works great when applied, however when I load the instrument, the keys come up all white.

All the instruments I look at have the keyswitches colored on instrument load.

What's the secret I'm missing?


I copied all the code from another instrument's script that works just fine straight into mine.
Same result, nothing.
Some setting on the instrument I created?

I copied another instrument made by somebody else with instrument keys in blue and keyswitches in red over my new instrument.

OK. The new copied one worked fine.

Then I overwrote its scriptcode with my simple

on init
set_key_color(1, $KEY_COLOR_RED)
end on

It no longer showed any red keyswitches (mine or the originals)on instrument load.

Then I copied the imported script back to where it originally was, so this imported instrument was back to how I found it.

It showed NO red keyswitches.
HOWEVER, the now invisible original keyswitches worked JUST FINE!

??????????

Comments

  • theodorech
    theodorech Member Posts: 73 Member

    First, double-check that you’re not using the key-lighting factory script. Also, the note you’re changing the color of is 1 (C#-2). Not sure if that’s what you intended. The general approach should be: a) put all the keyswitch MIDI note numbers into an array, b) loop through that array and colorize, c) wrap the loop in a function and call it whenever needed, plus include it in the persistence_changed callback.


    on init declare $i
    declare const $NUM_KEYSWITCHES := 4
    declare %keyswitches_notes[$NUM_KEYSWITCHES] := (36, 38, 40, 41) end on function colorize
    $i := 0
    while ($i<$NUM_KEYSWITCHES)
    set_key_color(%keyswitches_notes[$i],$KEY_COLOR_RED)
    inc($i)
    end while
    end function on persistence_changed
    call colorize
    end on

  • drobertbaker
    drobertbaker Member Posts: 3 Newcomer

    Thank you for your detailed response ( which I only just saw now because I expected the forum to inform me of any response).


    This is an elegant and comprehensive method for doing what I want.
    However it doesn't resolve my issue:
    These colorizations do not show up on loading the instrument, despite the "on init" section. It works fine on applying the code directly.
    As no else seems to have this HUGE issue, there's clearly something else going on other than the obvious, but I'm baffled as to what.


    I've tried:
    -restarting Kontakt
    -having the DAW(Reaper) rescan the plugins
    -restarting the DAW
    -rebooting the OS!


    I was particularly amazed by modifying a correctly working existing instrument's "on init" (got no color on instrument load) and then restoring the original code (STILL no color on instrument load).


    Indentation? Invisible characters? Beats me!

  • theodorech
    theodorech Member Posts: 73 Member

    If you keep this function that colors the keyboard inside the persistence_changed callback, the keyboard will get recolored every time you restart Kontakt's engine. Just so you know, that was a pretty basic example of how you can colorize.

This discussion has been closed.
Back To Top