How to Create a Kontakt 7 Instrument (Part 4) - Midi Scale

Welcome to the fourth installment of my multi-part series about how to engage in the beautiful pursuit of building your own instruments, effects, and plugins in the Kontakt Script Processor (KSP).

Prerequisites

This tutorial continues from the third installment of this multi-part series. So, if you have not followed the instructions in our previous installments, best to backtrack and complete those steps. Further, this tutorial requires a full version of Kontakt. Likely, Kontakt 5 or later is fine. However, screenshots in this tutorial are of Kontakt 7.

Getting Started

Continuing from where we left off, please ensure that the following starter code is in place in the scripting window:

```
{this always runs when the script starts}
on init

  {set the basics of the UI, setting the height at 213 and width at 720}
  make_perfview
  set_ui_height_px(213)
  set_ui_width_px(633)

  {declare a variable called $run that is tied to a button. Set that button to off }
  declare ui_switch $run
  $run := 0
  message("Ready to run")

  {declare another button called $option1 that is tied to a button. The initial value is set to on}
  declare ui_switch $option1
  $option1 := 1
  declare $option1Id
  $option1Id := get_ui_id($option1)
  set_control_par_str($option1Id, $CONTROL_PAR_TEXT, "A")

  {declare another button called $option2 that is tied to a button. The initial value is set to off}
  declare ui_switch $option2
  $option2 := 0
  declare $option2Id
  $option2Id := get_ui_id($option2)
  set_control_par_str($option2Id, $CONTROL_PAR_TEXT, "B")

  {declare another button called $option3 that is tied to a button. The initial value is set to off}
  declare ui_switch $option3
  $option3 := 0
  declare $option3Id
  $option3Id := get_ui_id($option3)
  set_control_par_str($option3Id, $CONTROL_PAR_TEXT, "C")

  {set initial instrument state value}
  declare @state
  @state := "A"

end on

{creates a function that resets the values of run}
function resetRun()

  $run := 0
  message("Ready to run")

end function

{this runs when the ui_control called $switch is changed}
on ui_control($run)

  if($run = 1)
    message("Running " & @state)
  else
    message("Ready to run")
  end if
end on

{this runs when the ui_control called $option1 is changed}
on ui_control ($option1)

  $option1 := 1

  {toggle the other buttons off}
  $option2 := 0
  $option3 := 0

  {reset the run button}
  call resetRun()

  @state := "A"

end on

{this runs when the ui_control called $option2 is changed}
on ui_control ($option2)

  $option2 := 1

  {toggle the other buttons off}
  $option1 := 0
  $option3 := 0

  {reset the run button}
  call resetRun()

  @state := "B"

end on

{this runs when the ui_control called $option3 is changed}
on ui_control ($option3)

  $option3 := 1

  {toggle the other buttons off}
  $option1 := 0
  $option2 := 0

  {reset the run button}
  call resetRun()

  @state := "C"

end on
```

Ensure that the script functions by clicking Apply. Upon clicking Apply followed by clicking C, and run you should see Running C appearing in the status bar / console at the bottom of the screen.

Step One - Building Scales

Step Two - Looping with While

Step Three - Overcoming the Curses of Midi Routing

Congratulations

You have now worked with MIDI for the first time in your project. In our next iteration of this series, we will be adding further possibilities for midi generation.

Copyright © 2022 THI. All rights reserved. gelvinwhite.com is operated by THI.

Native Instruments®️ and Kontakt®️ are registered trademarks of Native Instruments GmbH. We have no affiliation with Native Instruments.

kontakt7