KSP: Custom knob UI
A brief tutorial on creating custom knob UI elements. This was written because it's not completely obvious how NI do it.

Share

I wanted to make some really short tutorials for Kontakt 4 scripting. There's tons of resources out there so I figured that this series would only really cover tips and tricks that I use. Therefore I'll warn that this series is aimed at people who have played with Kontakt scripting a little and know what they're doing. If you don't, I definitely recommend checking out the documentation that comes with Kontakt, and poking about scripts included in Kontakt 4's library

Custom knob graphics in Kontakt
Many of the instruments that come with NI seem to have custom knob UI elements. I've had a few emails now with people asking how this is achieved ($CONTROL_PAR_PICTURE doesn't appear to work on ui_knob elements.

The answer is surprisingly simple. Let's take a look at an implementation:

on init
    declare ui_slider $knob (1,5)
    set_control_par_str(get_ui_id($knob),$CONTROL_PAR_TEXT,"")
    set_control_par_str(get_ui_id($knob),$CONTROL_PAR_PICTURE,"test/test_knob")
    set_control_par(get_ui_id($knob), $CONTROL_PAR_MOUSE_BEHAVIOUR, -500)
end on

As you can see, the secret is to use a ui_slider rather than a ui_knob. Inside of our init function, the first line declares our slider with a range of 1-5, the second line sets its text to blank. The third line sets our picture and our forth line specifies that we want to change the mouse movement.

$CONTROL_PAR_MOUSE_BEHAVIOUR sets both the scale and the direction. A negative value indicates that we want this control to be vertically-draggable.


Conclusion
There you go. That's how we have custom knob controls. Not quite as obvious as it could be, but entirely possible to create a completely custom UI.


Things to note
There are a few points to consider when using sliders as knobs.
  • You have to manually create your labels that show values.

  • If your animated graphic contains more frames than the slider range, it will still fully animate but lock to the nearest value on mouse release. This can be a little disorientating if your value range is small but your animation frame count is huge.