Keeping keyboard colours the same when resetting Kontakt

Andrew Finch
Andrew Finch Member Posts: 17 Newcomer

Hey all,

Currently I have two buttons that colour different key ranges when selected. Looking at the code below, when I press button1 and then the reset '!' in Kontakt I want the current button key range to stay the same and not revert back to what I have written for the initialization section, how can I make the key ranges persistent on resetting? Thanks in advance.

on init
    
    declare ui_switch $button1
    set_text($button1,"")
    make_persistent ($button1)


    declare ui_switch $button2
    set_text($button2,"")
    make_persistent ($button2)
    
    
{****************KEYBOARD COLOURS******************}
    
    {Initialization}
    
    declare $count
    declare %key_color[128]
    declare %all_white_keys [71] := (0,2,4,5,7,9,11,...
                                     12,14,16,17,19,21,23,...
                                     24,26,28,29,31,33,35,...
                                     36,38,40,41,43,45,47,...
                                     48,50,52,53,55,57,59,...
                                     60,62,64,65,67,69,71,...
                                     72,74,76,77,79,81,83,...
                                     84,86,88,89,91,93,95,...
                                     96,98,100,101,103,105,107,...
                                     108,110,112,113,115,117,119,120)
    
    $count := 0
    while ($count < 127)
        set_key_color($count, $KEY_COLOR_INACTIVE)
        inc($count)
    end while
    
    $count := 0
    while ($count <= 70)
        set_key_color(%all_white_keys[$count],$KEY_COLOR_BLACK)
        inc($count)
    end while
    
    $count := 36
    while ($count <= 96)
        %key_color[$count] := $KEY_COLOR_BLUE
        inc($count)
    end while


{---Set Colours---}


    $count := 36
    while ($count <= 96)
        set_key_color($count, %key_color[$count])
        inc($count)
    end while
    
end on




{================Callbacks=================}


on ui_control ($button1)
    
    $button2 := 0
    $count := 0
    while ($count < 127)
        set_key_color($count, $KEY_COLOR_INACTIVE)
        inc($count)
    end while
    
    $count := 36
    while ($count <= 60)
        %key_color[$count] := $KEY_COLOR_BLUE
        inc($count)
    end while
    
    $count := 0
    while ($count <= 70)
        set_key_color(%all_white_keys[$count],$KEY_COLOR_BLACK)
        inc($count)
    end while
    
    { set key colors }
    $count := 36
    while ($count <= 60)
        set_key_color($count, %key_color[$count])
        inc($count)
    end while
end on


on ui_control ($button2)
    
    $button1 := 0
    $count := 0
    while ($count < 127)
        set_key_color($count, $KEY_COLOR_INACTIVE)
        inc($count)
    end while
    
    $count := 36
    while ($count <= 96)
        %key_color[$count] := $KEY_COLOR_BLUE
        inc($count)
    end while
    
    $count := 0
    while ($count <= 70)
        set_key_color(%all_white_keys[$count],$KEY_COLOR_BLACK)
        inc($count)
    end while
    
    { set key colors }
    $count := 36
    while ($count <= 96)
        set_key_color($count, %key_color[$count])
        inc($count)
    end while
end on



Answers

  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod

    I would suggest to do all your keycoloring in ONE function that you call from each button. Then you also call this function from "on persistence_changed" callback.

Back To Top