Key Switches for 20 Groups

DaDrumBum1
DaDrumBum1 Member Posts: 8 Newcomer
edited July 2022 in Scripting Workshop

I have set up keyswitches and UI Buttons for different groups and they work great as most of my instruments only have a few groups to switch from. However I have a few patches that have about 20 groups and the way I have it scripted, it would be a huge task to replicate it for 20 groups. Just wondering if there is a better way at doing this for larger numbers? I am super new to scripting.

{==========================KeySwitches============================}

declare const $keyswitch1 := 0
declare const $keyswitch2 := 1
declare const $keyswitch3 := 2
set_key_color($keyswitch1, $KEY_COLOR_RED)
set_key_color($keyswitch2, $KEY_COLOR_RED)
set_key_color($keyswitch3, $KEY_COLOR_RED)
declare $current_state

{==========================Key Switch Info============================}

declare const $hx := 100
declare const $hy := 10

declare ui_label $label_T (1,1)
set_control_par(get_ui_id($label_T),$CONTROL_PAR_WIDTH,$hx)
set_control_par(get_ui_id($label_T),$CONTROL_PAR_HEIGHT,$hy)
set_control_par(get_ui_id($label_T),$CONTROL_PAR_FONT_TYPE,1)
hide_part ($label_T,$HIDE_PART_BG)
move_control_px($label_T, 51, 10)
set_text ($label_T,"Key Switch Info:")

declare ui_label $label_1 (1,1)
set_control_par(get_ui_id($label_1),$CONTROL_PAR_WIDTH,$hx)
set_control_par(get_ui_id($label_1),$CONTROL_PAR_HEIGHT,$hy)
set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,5)
hide_part ($label_1,$HIDE_PART_BG)
move_control_px($label_1, 66, 30)
set_text ($label_1,"C-2 = Ver. A")

declare ui_label $label_2 (1,1)
set_control_par(get_ui_id($label_2),$CONTROL_PAR_WIDTH,$hx)
set_control_par(get_ui_id($label_2),$CONTROL_PAR_HEIGHT,$hy)
set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
hide_part ($label_2,$HIDE_PART_BG)
move_control_px($label_2, 66, 45)
set_text ($label_2,"C#-2 = Ver. B")

declare ui_label $label_3 (1,1)
set_control_par(get_ui_id($label_3),$CONTROL_PAR_WIDTH,$hx)
set_control_par(get_ui_id($label_3),$CONTROL_PAR_HEIGHT,$hy)
set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)
hide_part ($label_3,$HIDE_PART_BG)
move_control_px($label_3, 66, 60)
set_text ($label_3,"D-2 = Ver. C")


declare const $lab1 := $keyswitch1
declare const $lab2 := $keyswitch2
declare const $lab3 := $keyswitch3

{==========================UI Switches============================}

declare const $pw := 15
declare const $ph := 15

declare ui_switch $ks1
$ks1 := 1
set_text($ks1,"")
set_control_par_str(get_ui_id($ks1),$CONTROL_PAR_PICTURE,"onbutton")
set_control_par(get_ui_id($ks1),$CONTROL_PAR_WIDTH,$pw)
set_control_par(get_ui_id($ks1),$CONTROL_PAR_HEIGHT,$ph)
move_control_px($ks1,55,25)

declare ui_switch $ks2
set_text($ks2,"")
set_control_par_str(get_ui_id($ks2),$CONTROL_PAR_PICTURE,"onbutton")
set_control_par(get_ui_id($ks2),$CONTROL_PAR_WIDTH,$pw)
set_control_par(get_ui_id($ks2),$CONTROL_PAR_HEIGHT,$ph)
move_control_px($ks2,55,40)

declare ui_switch $ks3
set_text($ks3,"")
set_control_par_str(get_ui_id($ks3),$CONTROL_PAR_PICTURE,"onbutton")
set_control_par(get_ui_id($ks3),$CONTROL_PAR_WIDTH,$pw)
set_control_par(get_ui_id($ks3),$CONTROL_PAR_HEIGHT,$ph)
move_control_px($ks3,55,55)
{==========================UI Switches============================}

on ui_control ($ks1)
   $current_state := 0
   $ks1 := 1
   $ks2 := 0
   $ks3 := 0

   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)

end on


on ui_control ($ks2)
   $current_state := 1
   $ks1 := 0
   $ks2 := 1
   $ks3 := 0

   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)

   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,1)
end on

on ui_control ($ks3)
   $current_state := 2
   $ks1 := 0
   $ks2 := 0
   $ks3 := 1

   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,1)
   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
end on

{==========================Key Switch Info============================}

on note
disallow_group($ALL_GROUPS)

if ($current_state = 0)
   allow_group(0)
end if

if($current_state = 1)
   allow_group(1)
 end if

if($current_state = 2)
   allow_group(2)
 end if

if ($EVENT_NOTE = $lab1)
   $current_state := 0
   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)
   $ks1 := 1
   $ks2 := 0
   $ks3 := 0

end if 

if ($EVENT_NOTE = $lab2)
   $current_state := 1
   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)
   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,1)
   $ks1 := 0
   $ks2 := 1
   $ks3 := 0


end if

if ($EVENT_NOTE = $lab3)
   $current_state := 2
   set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,5)
   set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,1)
   set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
   $ks1 := 0
   $ks2 := 0
   $ks3 := 1

end if


end on


Comments

  • DaDrumBum1
    DaDrumBum1 Member Posts: 8 Newcomer

    Ok So I have just discovered functions, which has made this a lot cleaner. I am doing stuff like this:


    function clear_ui_switch
       $ks1 := 0
       $ks2 := 0
       $ks3 := 0
    end function
    
    function clear_ks_info
       set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,1)
       set_control_par(get_ui_id($label_2),$CONTROL_PAR_FONT_TYPE,1)
       set_control_par(get_ui_id($label_3),$CONTROL_PAR_FONT_TYPE,1)
    end function
    
    function switch1
       $current_state := 0
       call clear_ui_switch
       $ks1 := 1
       call clear_ks_info
       set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,5)
       $attack := get_engine_par($ENGINE_PAR_ATTACK,$current_state,1,0)
       set_knob_label($attack,_get_engine_par_disp($ENGINE_PAR_ATTACK,$current_state,1,0))
       $decay := get_engine_par($ENGINE_PAR_DECAY,$current_state,1,0)
       set_knob_label ($decay,_get_engine_par_disp($ENGINE_PAR_DECAY,$current_state,1,0))
       $sustain := get_engine_par($ENGINE_PAR_SUSTAIN,$current_state,1,0)
       set_knob_label ($sustain,_get_engine_par_disp($ENGINE_PAR_SUSTAIN,$current_state,1,0))
       $release := get_engine_par($ENGINE_PAR_RELEASE,$current_state,1,0)
       set_knob_label ($release,_get_engine_par_disp($ENGINE_PAR_RELEASE,$current_state,1,0))
    end function
    


    function switch2

    ect.. ect.. for each new switch.


    However its still a lot to do for 20. Just wondering if there is any type of easier way?

  • Reid115
    Reid115 Member Posts: 47 Member

    I'm not sure what you're trying to do, but I would recommend using SublimeKSP as it makes a lot of things easier for you. For example, you can write macros to generate repetative code. Regardless, there's a lot you're doing that is not necessary. For example, you're checking every option for allow group when you could just do:

    allow_group($current_state)
    

    And a lot of what you're doing in the switch functions can be made to be the exact same every time, and thus put in a separate function:

    $attack := get_engine_par($ENGINE_PAR_ATTACK,$current_state,$current_state + 1,0)
    

    Also, use selects instead of if statements when it makes more sense:

    select ($EVENT_NOTE)
        case lab1
            
        case lab2
    
        case lab3
    
    end select
    

    In general I recommend reading the manual.

Back To Top