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

Change Knobs to sliders

Discussion in 'Scripting Workshop' started by Cultz Music Group, Jan 8, 2017.

  1. Cultz Music Group

    Cultz Music Group New Member

    Messages:
    14
    Hey everyone. So I recently got into scripting and have had some success with my new drum sample script. I should say That I was able to to Frankenstein the script together using different pieces of information/scripts from different sources and tie all together with what i know now. The issues I am having is that though The script provides all the function that I want in to, i'd like to change the knobs into sliders so can use my own knob images (understanding that Kontakt won't let me change the default knob image). Every time when I try to do so though I cannot ever get my script to run. Any help would be of major help. Below is an example of the script i am working on for one knob.

    Code:
    on init
       set_ui_height_px(460)
       make_perfview
       message("")
       
       
       declare const $STARTGRPBELLB := 45 { Enter the group number of each new mic postion starting at zero }
       declare $countBellB { Needed for while loop}
       declare $link_groupsBellB := 5 { enter the number of groups you want to link here }
       declare ui_knob $Bell_B(0,1000000,1)
       move_control_px($Bell_B,  515, 350) { Positioning Knob }
       
       declare $initcountBellB
       declare ui_menu $menuBellB
       add_menu_item($menuBellB,"Default",-1)
       move_control_px($menuBellB,  515, 390)
       
       
       set_knob_unit($Bell_B,$KNOB_UNIT_DB)  {assign a unit mark to the knob}
       set_knob_defval($Bell_B,630000) { defval resets knob to a default vaule when command clicked}
       set_knob_label($Bell_B, get_engine_par_disp($ENGINE_PAR_VOLUME,$countBellB,-1,-1))
       
       
       make_persistent($Bell_B)
       read_persistent_var($Bell_B)
       
       
       
       $initcountBellB := $STARTGRPBELLB
       while($initcountBellB <  $NUM_OUTPUT_CHANNELS) {Add menu item to new channel when created}
         add_menu_item($menuBellB,output_channel_name($initcountBellB),$initcountBellB) {JUST THIS LINE OF CODE}
         
         inc($initcountBellB)
       end while
       
    end on
    
    
    on ui_control ($Bell_B)
       $countBellB := $STARTGRPBELLB
       while ($countBellB < $STARTGRPBELLB+$link_groupsBellB)
         set_engine_par($ENGINE_PAR_VOLUME,$Bell_B,$countBellB,-1,-1)
         set_engine_par($ENGINE_PAR_OUTPUT_CHANNEL,$menuBellB,$countBellB,-1,-1)
         inc($countBellB)
       end while
       set_knob_label($Bell_B,get_engine_par_disp($ENGINE_PAR_VOLUME,$STARTGRPBELLB,-1,-1))
    end on
    
    on ui_control ($menuBellB)
       $countBellB := $STARTGRPBELLB
       while ($countBellB < $STARTGRPBELLB+$link_groupsBellB)
         set_engine_par($ENGINE_PAR_OUTPUT_CHANNEL,$menuBellB,$countBellB,-1,-1)
         inc($countBellB)
       end while
       
    end on
     
    Last edited by a moderator: Jan 8, 2017
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You need to remove knob related commands if you're changing ui_knob to ui_slider (set_knob_defval, set_knob_unit, set_knob_label).


    Also, please use CODE tags when posting any code here.
     
  3. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Perhaps, this tutorial can help you ...


     
  4. Cultz Music Group

    Cultz Music Group New Member

    Messages:
    14
    Thanks will do you haven't learned how to do that yet and I'm new to all this but I'll make sure to do that for the next post. And thank you for your help.

    Sent from my SM-G920T using Tapatalk
     
  5. Cultz Music Group

    Cultz Music Group New Member

    Messages:
    14
    Thank you. I'll be sure to check out the video.

    Sent from my SM-G920T using Tapatalk
     
  6. STK The Producer

    STK The Producer New Member

    Messages:
    3
    Hey, this is exactly what I need to do to finish my instrument (literally the finish line is after this). How would you script this?

    Here is the line of code that needs to be changed:

    declare ui_knob $porta_combi_knob (0,127,1)

    I got everything else to work, except switching from knob to slider.

    I'm creating an 808 Bass instrument and portamento bass slides are a must-have feature. Obviously I could just use the basic knobs, however, I want to use my own knobs (sliders).

    Thanks in advance!!
     
  7. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    The KSP Reference Manual can help you, in page 36 .
     
  8. STK The Producer

    STK The Producer New Member

    Messages:
    3
    Thank you so much. I'm going to use it now!!! Thanks again!!!
     
  9. thormyrdal

    thormyrdal New Member

    Messages:
    13
    lol best answer ever!
     
  10. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    The proof of the pudding is in the eating.
     
  11. T.S.

    T.S. NI Product Owner

    Messages:
    581
    I like to use "get_ui_id" for this, it makes it easier to deal with several sliders/knobs.

    declare ui_slider Knob_Name (MIN_EP,MAX_EP)
    %Knob_ID[Count] := get_ui_id(Knob_Name)

    It ends up looking something like this. This might look a little strange because I use macros to build my code, but this has worked well for scripts with lots of knobs.
    Code:
    on init
      declare %Knob_ID[9]
      declare %KnobVal_ID[9]
      declare ui_slider $GEQ1G(0, 1000000)
        %Knob_ID[0] := get_ui_id($GEQ1G)
        set_control_par(%Knob_ID[0],$CONTROL_PAR_VALUE,500000)
        set_control_par(%Knob_ID[0],$CONTROL_PAR_DEFAULT_VALUE,500000)
        $GEQ1G := 500000
        read_persistent_var($GEQ1G)
        set_control_par_str(%Knob_ID[0],$CONTROL_PAR_PICTURE,!Knb_Pict[2])
        set_control_par(%Knob_ID[0],$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
        set_control_par(%Knob_ID[0],$CONTROL_PAR_POS_X,50)
        set_control_par(%Knob_ID[0],$CONTROL_PAR_POS_Y,77)
        set_control_par(%Knob_ID[0],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
      declare ui_label $GEQGval(1, 1) 
        %KnobVal_ID[0] := get_ui_id($GEQGval)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_WIDTH,45)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_HEIGHT,13)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_FONT_TYPE,11)
        set_control_par_str(%KnobVal_ID[0],$CONTROL_PAR_PICTURE,!Val_Pict[0])
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_HIDE,$HIDE_PART_BG)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_TEXT_ALIGNMENT,1)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_POS_X,38)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_POS_Y,101)
        set_control_par(%KnobVal_ID[0],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
        make_persistent($GEQ1G)
    end on
    on ui_control($GEQ1G)
      $cnt1 := 0
      $cnt2 := 0
      $cnt3 := 0
      call Set_EQFX
    end on
    function Set_EQFX
      set_engine_par(%EQ_EP[$cnt2],get_control_par(%Knob_ID[$cnt3],$CONTROL_PAR_VALUE),0,%EQ_Slot[$cnt1],-1)
      set_control_par_str(%KnobVal_ID[$cnt3],$CONTROL_PAR_TEXT,get_engine_par_disp(%EQ_EP[$cnt2],0,%EQ_Slot[$cnt1],-1))
      set_engine_par(%EQ_EP[$cnt2],get_control_par(%Knob_ID[$cnt3],$CONTROL_PAR_VALUE),1,%EQ_Slot[$cnt1],-1)
      set_control_par_str(%KnobVal_ID[$cnt3],$CONTROL_PAR_TEXT,get_engine_par_disp(%EQ_EP[$cnt2],1,%EQ_Slot[$cnt1],-1))
    end function
    
     
  12. STK The Producer

    STK The Producer New Member

    Messages:
    3
    Thank you so much. I'm going to try this now.