Disable set of key switches with menu

Andrew Finch
Andrew Finch Member Posts: 17 Newcomer
edited March 2022 in Scripting Workshop

Hi Guys,

I am trying to have a menu that allows the user to move between a 'simple' and 'advanced' key switch system. The problem is that when I select advanced even though the red 'simple' key switch notes disappear and the magenta 'advanced' ones appear, the blacked out key switch 'simple' notes still work when the 'advanced' dropdown is selected. How do I disable $key_switch_1 to $key_switch_4 when the 'advanced' dropdown is selected?

on ui_control ($simple_advanced_menu) 
    select ($simple_advanced_menu) 
            
        case 0 {Simple Dropdown}                     
            
            set_key_color($key_switch_1, $KEY_COLOR_RED)
            set_key_color($key_switch_2, $KEY_COLOR_RED)
            set_key_color($key_switch_3, $KEY_COLOR_RED)
            set_key_color($key_switch_4, $KEY_COLOR_RED)
            
            set_control_par(get_ui_id($key_switch_1), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_2), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_3), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_4), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_1), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_2), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_3), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_4), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_1), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_2), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_3), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_4), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            
            set_control_par(get_ui_id($key_switch_5), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_6), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_7), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_8), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_5), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_6), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_7), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_8), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
                   
        case 1 {Advanced Dropdown}
               
            set_key_color($key_switch_5, $KEY_COLOR_MAGENTA)
            set_key_color($key_switch_6, $KEY_COLOR_MAGENTA)
            set_key_color($key_switch_7, $KEY_COLOR_MAGENTA)
            set_key_color($key_switch_8, $KEY_COLOR_MAGENTA)
            
            set_control_par(get_ui_id($key_switch_1), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_2), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_3), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($key_switch_4), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_1), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_2), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_3), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            set_control_par(get_ui_id($button_4), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
            
            set_control_par(get_ui_id($key_switch_5), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_6), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_7), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_8), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_5), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_6), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_7), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($button_8), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
            set_control_par(get_ui_id($key_switch_5), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_6), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_7), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            set_control_par(get_ui_id($key_switch_8), $CONTROL_PAR_HIDE, $HIDE_PART_BG)
            
    end select 
    
end on 

Answers

  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod

    You would do this in note callback, where you actually handle what incoming notes are supposed to do.

  • Andrew Finch
    Andrew Finch Member Posts: 17 Newcomer

    Ok, so looking at the Kontakt Factory Library the code below is for 4 key switches, how would you integrate buttons 5-8 and key switches 5-8 into that with the menus?

    on note 
        ignore_event($EVENT_ID)
        play_note(%actual_keyswitches[$active_group],1,0,1000)
        $played_note_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
        
    
    
        {if incoming note equals one of the six EXISTING keyswitches ignore them}
            if (search(%actual_keyswitches,$EVENT_NOTE) # -1)
                ignore_event($EVENT_ID)
            end if
        
        {if incoming note equals one of the six value edits}
        if ($EVENT_NOTE = $key_switch_1 or...
            $EVENT_NOTE = $key_switch_2 or...
            $EVENT_NOTE = $key_switch_3 or...
            $EVENT_NOTE = $key_switch_4)
    
    
    
    
                 {set all buttons to zero}
                $count := 0
                while ($count < 4)
                    set_control_par(%articulation_id[$count],$CONTROL_PAR_VALUE,0)
                    inc($count)
                end while
            
            ignore_event($EVENT_ID)
            
            if($EVENT_NOTE = $key_switch_1)
                $button_1 := 1
                $active_group := 0
                play_note(%actual_keyswitches[0],1,0,1000)
            end if
            
            if($EVENT_NOTE = $key_switch_2)
                $button_2 := 1
                $active_group := 1
                play_note(%actual_keyswitches[1],1,0,1000)
            end if
            
            if($EVENT_NOTE = $key_switch_3)
                $button_3 := 1
                $active_group := 2
                play_note(%actual_keyswitches[2],1,0,1000)
            end if
            
            if($EVENT_NOTE = $key_switch_4)
                $button_4 := 1
                $active_group := 3
                play_note(%actual_keyswitches[3],1,0,1000)
            end if
    
    
        end if
    end on 
    
  • Andrew Finch
    Andrew Finch Member Posts: 17 Newcomer

    I was expecting something like this might work but it doesn't activate the second set of KS, any ideas?:

    on note 
        
        ignore_event($EVENT_ID)
        play_note(%actual_keyswitches[$active_group],1,0,1000)
        $played_note_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
        
        
        if($simple_advanced_menu = 0)
            if (search(%actual_keyswitches,$EVENT_NOTE) # -1)
                ignore_event($EVENT_ID)
            end if
            if ($EVENT_NOTE = $key_switch_1 or...
                $EVENT_NOTE = $key_switch_2 or...
                $EVENT_NOTE = $key_switch_3 or...
                $EVENT_NOTE = $key_switch_4)
                
                
                $count := 0
                while ($count < 4)
                    set_control_par(%articulation_id[$count],$CONTROL_PAR_VALUE,0)
                    inc($count)
                end while
                
                $count := 0
                while ($count < 4)
                    set_control_par(%articulation_id2[$count],$CONTROL_PAR_VALUE,0)
                    inc($count)
                end while
                
                ignore_event($EVENT_ID)
                
                if($EVENT_NOTE = $key_switch_1)
                    $button_1 := 1
                    $active_group := 0
                    play_note(%actual_keyswitches[0],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_2)
                    $button_2 := 1
                    $active_group := 1
                    play_note(%actual_keyswitches[1],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_3)
                    $button_3 := 1
                    $active_group := 2
                    play_note(%actual_keyswitches[2],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_4)
                    $button_4 := 1
                    $active_group := 3
                    play_note(%actual_keyswitches[3],1,0,1000)
                end if
                
                if($simple_advanced_menu = 1)
                    
                    if (search(%actual_keyswitches2,$EVENT_NOTE) # -1)
                        ignore_event($EVENT_ID)
                    end if
                    
                    if ($EVENT_NOTE = $key_switch_5 or...
                        $EVENT_NOTE = $key_switch_6 or...
                        $EVENT_NOTE = $key_switch_7 or...
                        $EVENT_NOTE = $key_switch_8)
                        
                        $count := 0
                        while ($count < 4)
                            set_control_par(%articulation_id[$count],$CONTROL_PAR_VALUE,0)
                            inc($count)
                        end while
                        
                        $count := 0
                        while ($count < 4)
                            set_control_par(%articulation_id2[$count],$CONTROL_PAR_VALUE,0)
                            inc($count)
                        end while
                        
                        if($EVENT_NOTE = $key_switch_5)
                            $button_5 := 1
                            $active_group := 4
                            play_note(%actual_keyswitches2[0],1,0,1000)
                        end if
                        
                        if($EVENT_NOTE = $key_switch_6)
                            $button_6 := 1
                            $active_group := 5
                            play_note(%actual_keyswitches2[1],1,0,1000)
                        end if
                        
                        if($EVENT_NOTE = $key_switch_7)
                            $button_7 := 1
                            $active_group := 6
                            play_note(%actual_keyswitches2[2],1,0,1000)
                        end if
                        
                        if($EVENT_NOTE = $key_switch_8)
                            $button_8 := 1
                            $active_group := 7
                            play_note(%actual_keyswitches2[3],1,0,1000)
                        end if
                    end if
                end if
            end if
        end if
    end on
    
  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod
    edited March 2022

    Your branching is off kilter. You need an end if before if ($simple_advanced_menu = 1) so that you close the if ($simple_advanced_menu = 0) branch first. Then remove one end if from the end to match all the openings with closures. Watch out with indentation and all should be clearer.

  • Andrew Finch
    Andrew Finch Member Posts: 17 Newcomer
    edited March 2022

    Ok so applying that I think this is what you mean? The advanced dropdown still isn't working though, is there something obvious missing from on note? It is weird as when I comment out all the = 0 elements key switches 5-8 work. I have attached the rest of the script just in case.

    on note 
        
        if($simple_advanced_menu = 0)
            
            ignore_event($EVENT_ID)
            play_note(%actual_keyswitches[$active_group],1,0,1000)
            $played_note_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
            
            if (search(%actual_keyswitches,$EVENT_NOTE) # -1)
                ignore_event($EVENT_ID)
            end if
            
            if ($EVENT_NOTE = $key_switch_1 or...
                $EVENT_NOTE = $key_switch_2 or...
                $EVENT_NOTE = $key_switch_3 or...
                $EVENT_NOTE = $key_switch_4)
                
                $count := 0
                while ($count < 4)
                    set_control_par(%articulation_id[$count],$CONTROL_PAR_VALUE,0)
                    inc($count)
                end while
                
                $count := 0
                while ($count < 4)
                    set_control_par(%articulation_id2[$count],$CONTROL_PAR_VALUE,0)
                    inc($count)
                end while
                
                ignore_event($EVENT_ID)
                
                if($EVENT_NOTE = $key_switch_1)
                    $button_1 := 1
                    $active_group := 0
                    play_note(%actual_keyswitches[0],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_2)
                    $button_2 := 1
                    $active_group := 1
                    play_note(%actual_keyswitches[1],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_3)
                    $button_3 := 1
                    $active_group := 2
                    play_note(%actual_keyswitches[2],1,0,1000)
                end if
                
                if($EVENT_NOTE = $key_switch_4)
                    $button_4 := 1
                    $active_group := 3
                    play_note(%actual_keyswitches[3],1,0,1000)
                end if
            end if
            
            if($simple_advanced_menu = 1)
                
                ignore_event($EVENT_ID)
                play_note(%actual_keyswitches2[$active_group2],1,0,1000)
                $played_note_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
                
                if (search(%actual_keyswitches2,$EVENT_NOTE) # -1)
                    ignore_event($EVENT_ID)
                end if
                
                if ($EVENT_NOTE = $key_switch_5 or...
                    $EVENT_NOTE = $key_switch_6 or...
                    $EVENT_NOTE = $key_switch_7 or...
                    $EVENT_NOTE = $key_switch_8)
                    
                    $count := 0
                    while ($count < 4)
                        set_control_par(%articulation_id[$count],$CONTROL_PAR_VALUE,0)
                        inc($count)
                    end while
                    
                    $count := 0
                    while ($count < 4)
                        set_control_par(%articulation_id2[$count],$CONTROL_PAR_VALUE,0)
                        inc($count)
                    end while
                    
                    if($EVENT_NOTE = $key_switch_5)
                        $button_5 := 1
                        $active_group2 := 0
                        play_note(%actual_keyswitches2[0],1,0,1000)
                    end if
                    
                    if($EVENT_NOTE = $key_switch_6)
                        $button_6 := 1
                        $active_group2 := 1
                        play_note(%actual_keyswitches2[1],1,0,1000)
                    end if
                    
                    if($EVENT_NOTE = $key_switch_7)
                        $button_7 := 1
                        $active_group2 := 2
                        play_note(%actual_keyswitches2[2],1,0,1000)
                    end if
                    
                    if($EVENT_NOTE = $key_switch_8)
                        $button_8 := 1
                        $active_group2 := 3
                        play_note(%actual_keyswitches2[3],1,0,1000)
                    end if
                end if
            end if
        end if
    end on
    
  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod

    So the main thing is if you want the "advanced" to work with all 8 KS, you need to check for all 8 KS, not just 5-8.


    But this code can be heavily optimized... you should store all the keyswitches in one single array, then you can search(array, $EVENT_NOTE) instead of doing individual checks for each KS and using or...

  • Andrew Finch
    Andrew Finch Member Posts: 17 Newcomer
    edited March 2022

    That has sorted it, thank you very much.

Back To Top