1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Solved Trigger a slider by a key

Discussion in 'Scripting Workshop' started by Jesse01, Sep 24, 2021.

  1. Jesse01

    Jesse01 New Member

    Messages:
    14
    Hi All,

    I wanna trigger $slider1 with $KEY24 and make it go through all the 30 motions and not jump from 0 to 30.



    Code:
    on init
    
    make_perfview
    set_ui_height_px(300)
     
    declare ui_slider $slider1(0, 30)
    hide_part($slider1,  $HIDE_PART_BG .or. $HIDE_PART_MOD_LIGHT .or. $HIDE_PART_TITLE .or. $HIDE_PART_VALUE)
    set_control_par_str(get_ui_id($slider1),  $CONTROL_PAR_PICTURE,"slide")
    move_control_px($slider1,1, 20)
    set_control_par(get_ui_id($slider1), $CONTROL_PAR_MOUSE_BEHAVIOUR, -1000)
    make_persistent($slider1)
    
    set_key_color(24,$KEY_COLOR_RED)
    declare const $KEY24 := 24
    
    
    end on 
    on note
    if ($EVENT_NOTE = $KEY24)
       $slider1 :=  30
      end if
      end on
    
     
  2. ericchesek

    ericchesek New Member

    Messages:
    11
    Right now, your script says:
    When Key 24 is pressed, take the value of slider1 and set it equal to 30 IMMEDIATELY. There are no other instructions to tell slider1 to go from 0 (or its current state) to 1, to 2, to 3, to 4, etc.

    How fast does the slider need to transition? Should it move by increments of 1? 0.1? 10? Once the slider is set to the value 30 using this script, will it ever change again? Should it return to 0? What if it goes above 30?

    More information is needed to make this work flawlessly for you, but here is a start:

    Code:
    on init
      make_perfview
      set_ui_height_px(300)
      message("")
      declare ui_slider $slider1(0, 30) 
      hide_part($slider1,$HIDE_PART_BG .or. $HIDE_PART_MOD_LIGHT .or. $HIDE_PART_TITLE .or. $HIDE_PART_VALUE)
      set_control_par_str(get_ui_id($slider1),$CONTROL_PAR_PICTURE,"slide")
      move_control_px($slider1,1,20)
      set_control_par(get_ui_id($slider1),$CONTROL_PAR_MOUSE_BEHAVIOUR,-1000)
      make_persistent($slider1)
      set_key_color(24,$KEY_COLOR_RED)
      declare const $KEY24 := 24
      declare $sliderCount := 0
    end on
    
    on note
      if ($EVENT_NOTE=$KEY24)
        $sliderCount := 1
        while ($slider1<30)
          $slider1 := $slider1+$sliderCount
          message($slider1)
          if ($slider1>get_control_par(get_ui_id($slider1),$CONTROL_PAR_MAX_VALUE))
            $slider1 := get_control_par(get_ui_id($slider1),$CONTROL_PAR_MAX_VALUE)
          else
            if ($slider1<get_control_par(get_ui_id($slider1),$CONTROL_PAR_MIN_VALUE))
              $slider1 := get_control_par(get_ui_id($slider1),$CONTROL_PAR_MIN_VALUE)
            end if
          end if
          wait(50000)
          inc($sliderCount)
        end while
      end if
    end on
    
    
    1. Added message("") on init to clear the message box.
    2. Add variable sliderCount to use in a while loop.
    3. Changed on note logic to do the following: when note 24 is pressed, the slider value is equal to its current value plus 1. That value is written as a message in Kontakt.
    Then, we check if the slider value is outside the min and max ranges of 0 to 30, which is how you defined the slider.
    Once the min and max values are handled so we do not get warnings from Kontakt, wait(50000) holds the value for a moment before incrementing sliderCount and running the loop again. Increase or decrease this wait period to change how long it takes the slider to transition.
    The loop exits after slider1 is finally set to 30.

    Hopefully this does what you need!