|
Part of my Kontakt 4 script mini tutorials. This one covers creating animated icons that you can use to convey information.
|
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
Animated icons
This tutorial will show you how to create icons that can be animated to convey information to the script user. For this tutorial you'll want to right click the PNG below and save it as string_main.png to your Kontakt pictures folder:
Documents\Native Instruments\Kontakt 4\pictures

Creating the resources
With the png file saved to your pictures folder, we also need to create a txt file that tells Kontakt how to use it. Kontakt will usually create one by default, but we want to create a special, animated icon so we need to configure it manually.
First, create a new file with the same name as your picture but with a .txt extension. For this tutorial, I've made string_main.txt. It should be in the same folder as your png.
To tell Kontakt that this is an animated image, paste the following text into the newly created .txt file:
Has Alpha Channel: yes
Number of Animations: 4
Horizontal Animation: no
Vertical Resizable: no
Horizontal Resizable: no
Fixed Top: 0
Fixed Bottom: 0
Fixed Left: 0
Fixed Right: 0
It's pretty self-explanatory as to what this txt file does. You'll notice there are four violins in various visual states on the tutorial image.
"Number of Animations: 4" tells Kontakt that this image has four frames of animation, ordered vertically.
Save this txt file and we'll head to Kontakt to script it.
The script itself
We'll be using a label to create our icon. For the purposes of this tutorial, we'll be making our icon change when notes are played and released. Let's look at the code:
on init
declare ui_label $ui_violin (0,0)
set_control_par_str (get_ui_id($ui_violin), $CONTROL_PAR_TEXT, "")
set_control_par_str (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE, "string_main")
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 0)
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_POS_X, 50)
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_POS_Y, 50)
end on
on note
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 1)
end on
on release
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 0)
end on
Line by line breakdown
declare ui_label $ui_violin (0,0)
Create a new label called $ui_violin and set its width and height to 0 by 0.
set_control_par_str (get_ui_id($ui_violin), $CONTROL_PAR_TEXT, "")
Set the label's text to blank. This will prevent any text appearing and will hide the label's background box.
set_control_par_str (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE, "string_main")
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 0)
Set the label's image file name to "string_main" and then set the current frame to 0. We miss off the file extension as Kontakt will automatically determine this.
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_POS_X, 75)
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_POS_Y, 5)
Position our label in pixels. We set it to 75,5 at the top of the script interface.
on note
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 1)
end on
In the on note event, we set the label's picture state (frame) to 1. This makes it look like the bow has hit the violin.
on release
set_control_par (get_ui_id($ui_violin), $CONTROL_PAR_PICTURE_STATE, 0)
end on
In the on release event, we set the label's picture state back to 0. This removes the bow from the violin.
Conclusion
As you can see, creating animated icons is pretty simple in Kontakt 4. You can use it to create quite a lot of nice visual effects that do your script more justice than a text based label.
Things to note
There are a few points to consider when animating things:
- Because they use labels, animated icons have no on_control event and cannot be scripted when clicked :(
- If your images are in directories inside the pictures folders, be sure to use a backslash in the path (eg. "requiem/string_main"). This will ensure your script works on Mac and PC Kontakt.
|
|