How to Create a Kontakt 7 Instrument (Part 2) - Push It!
Welcome to the second 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 Language.
Prerequisites
This tutorial continues from the first installment of this multi-part series. So, if you have not followed the instructions there, 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:
```
on init
message("Hello World!")
end on
```
Ensure that the script functions by clicking Apply. Upon clicking Apply, you should see Hello World! appearing in the status bar / console at the bottom of the screen.
Step One - Creating the Performance View
-
To begin, we will create the performance view of the instrument. You can think of the performance view as the canvas upon which your buttons, dials, and other graphical elements will appear when someone is using the instrument. Modify your code as follows:
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) end onNotice that
make_perfviewinforms the compiler that there is a user interface that needs to be rendered to the user, even when they are not in the script editor. Without this line of code, your user interface will not be visible. Then,set_ui_height_pxandset_ui_width_pxtell the compiler the size of the performance view.Most important, notice the curly
{}braces, which allows you to comment your code. Throughout your process of learning how to program, I highly advise keeping good notes about what your code does! After all, when you return later in a week, month, or year, it’s helpful to know what your code is doing. -
To ensure that your script is functioning, hit
apply. Then, click the wrench icon to switch to performance view. Your window should look like this:
Note that if your screen does not look like the above, you probably did not click that wrench.
Step Two - Placing Your First Button
-
Next, let’s place your first button. Modify your code as follows:
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 $switch that is tied to a button. Set that switch to on } declare ui_switch $switch $switch := 1 message("Hello World!") end onNotice that the
declarecommand is used to create a variable calledswitch. This variable has a$sign in front of it, which tells us that this variable is an integer. Further, this variable calledswitchis tied to a button, signified byui_switch. Then$switchis set to1. When aui_switchhas a value of0it is off. When it is1it is on. -
Now, click the
Applybutton. -
Upon clicking
Apply, you should see the following:
-
Click on the button called
switch. You’ll notice that in the on position it is lighter in color. In the off position, it is darker in color
Step Three - Making the Button Interactive
-
Now, it’s time to learn a little about callbacks. A callback is a block of code that is executed at a specific time. For example, the
on initcallback is run each time the script is run. This callback is the first callback to be run, always. You can create multiple callbacks in your program. Modify your code as follows:{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 $switch that is tied to a button. Set that switch to on } declare ui_switch $switch $switch := 1 end on {this runs when the ui_control called $switch is changed} on ui_control($switch) if($switch = 1) message("it's on!") else message("it's off!") end if end onNotice that a new callback called
ui_control($switch)is included. When$switch1is manipulated, this callback is called. Notice that the value of$switch1is passed to this callback using the()parentheses. Then, inside the callback, theifstatement makes a decision. If$switch = 1or on, thenit's on!is messaged in the console. Otherwise,it's offis messaged. -
Click “Apply” and play with the button. Notice what is displayed in the console.

Congratulations
You have now created your first interactive button!
The tutorial to follow will discuss the placement of buttons within the performance view.
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.