Shorten Commands

Options
Eduardo Gamero
Eduardo Gamero Member Posts: 30 Member

Does anyone know how to write this in a simpler way?


  set_control_par_str(get_ui_id($switch_1),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_2),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_3),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_4),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_5),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_6),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_7),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_8),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_9),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_10),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_11),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_12),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_13),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_14),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_15),$CONTROL_PAR_PICTURE,"switch")

  set_control_par_str(get_ui_id($switch_16),$CONTROL_PAR_PICTURE,"switch")

Best Answers

  • Gablux
    Gablux Member Posts: 85 Helper
    Answer ✓
    Options

    what @corbo-billy is talking about is:

    all ui controls in kontakt have an ID, hence why you use the get_ui_id function to grab each of these controls' ID before setting the control par str.

    What you could do instead of a macro, using regular vanilla KSP is:

    declare $loop_count := 0
    declare %switch_ids[16]
      %switch_ids[0] := get_ui_id($switch_1)
      %switch_ids[1] := get_ui_id($switch_2)
      %switch_ids[2] := get_ui_id($switch_3)
      {  ... and so on up to 16 }
    
    
    { then at the moment you need to set those control parameters you do: }
    
    $loop_count := 0
    while ($loop_count < 16) 
      set_control_par_str(%switch_ids[$loop_count],$CONTROL_PAR_PICTURE,"switch")
      inc($loop_count)
    end while
    

    A little less elegant than the macro version, but more efficient and vanilla code, no need to use Sublime or KSP plugin.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Answer ✓
    Options

    Thank you very much friend, you were a great help, greetings.

Answers

  • Gablux
    Gablux Member Posts: 85 Helper
    Options

    yes, if you use Sublime KSP (Sublime Text, the code editor + KSP plugin) you can write:

    iterate_macro(set_control_par_str(get_ui_id($switch_#n#), CONTROL_PAR_PICTURE,"switch") := 1 to 16


    the plugin has the functionality to compile what we could call SublimeKSP code (above) into regular (vanilla) KSP. In the end it is the same result, but the code you look at everyday while developing your instrument is way simpler and shorter.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    Is there a way to write that code without having to write the same thing many times?

  • corbo-billy
    corbo-billy Member Posts: 87 Helper
    Options

    Directly, from the KSP editor, you must gather all the switches in an Array and apply the execution, the attribution of this image to each switch by the process of a "while loop" with the keywords while __ end while .

    Sorry but I'm not very pedagogical and my English is limited.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    can you give me an example??? Sorry but I know very little about the code

  • Gablux
    Gablux Member Posts: 85 Helper
    Answer ✓
    Options

    what @corbo-billy is talking about is:

    all ui controls in kontakt have an ID, hence why you use the get_ui_id function to grab each of these controls' ID before setting the control par str.

    What you could do instead of a macro, using regular vanilla KSP is:

    declare $loop_count := 0
    declare %switch_ids[16]
      %switch_ids[0] := get_ui_id($switch_1)
      %switch_ids[1] := get_ui_id($switch_2)
      %switch_ids[2] := get_ui_id($switch_3)
      {  ... and so on up to 16 }
    
    
    { then at the moment you need to set those control parameters you do: }
    
    $loop_count := 0
    while ($loop_count < 16) 
      set_control_par_str(%switch_ids[$loop_count],$CONTROL_PAR_PICTURE,"switch")
      inc($loop_count)
    end while
    

    A little less elegant than the macro version, but more efficient and vanilla code, no need to use Sublime or KSP plugin.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Answer ✓
    Options

    Thank you very much friend, you were a great help, greetings.

Back To Top