Using the Message Bar in Kontakt
What Is the Message Bar For?
The message bar is an interesting and useful tool, with more to it than meets the eye. It is also a little misunderstood, often being used to display welcome message, prompts, control parameter readouts or other information that is typically meant for the user’s benefit. However, it isn’t actually meant to be used in this way. It’s true purpose is as a testing tool, for you the coder, while you are working on building the library or debugging it.
Imagine you write a snazzy bit of code, but it doesn’t work. You are staring at the code, hours pass, but you just don’t see what is going wrong. Wouldn’t it be helpful to see what that code was actually doing… besides not working? That is where the message bar comes in handy, allowing you to check what a line of code may be outputting and you can see where the problem is going wrong.
Clearing the Message Bar On Initialisation
In the KSP Reference Manual, you can see it actually recommends that every on init callback (see this article) has a message command to clear the message bar of any text. This is to make sure that if you use the message bar at any other time in your code, you will be able to start with a clean slate. The messages stay in the message bar until a new message overwrites them, so it is important that when a library loads, the messages are cleared out ready for the new prompts.
In the example below, you can see the performance view being created (see this article), but in the last part of the block a message command is used. This message is outputting effectively nothing (using the ““ to say that there is no text between the quotations and therefore, it is blank) and wipes the slate clean.
on init make_perfview set_ui_height_px(300) set_ui_width_px(800) message ("") end on
Debugging and Testing Using the Message Bar
Expanding on the previous example, let’s create some UI controls. We’ll create two controls, intending for one to control the cutoff of a filter and the other to control the resonance. Both of these knobs (see this article) are placed on the UI via the on init block.
on init make_perfview set_ui_height_px(300) set_ui_width_px(800) message ("") {Declare the Cutoff Knob} declare ui_knob $Cutoff (0, 1000000, 1) {Declare the knob and name it.} move_control_px($Cutoff, 50, 100) {Move the knob into position on the UI.} make_persistent($Cutoff) {Make the knob persistent to remember its value.} {Declare the Resonance Knob} declare ui_knob $Resonance (0, 1000000, 1) move_control_px($Resonance, 150, 100) make_persistent($Resonance) end on
Now, let’s add the on ui_control callback (see this article) to control the Cutoff Knob. In this example below, we use the message bar to test that the right knob is being linked to the callback by asking the message bar to read out the changing values. If the Cutoff knob is working, then this value should be updating as we adjust it.
on ui_control ($Cutoff) message ($Cutoff) end on
Instead of using the variable value in the message bar, you could swap that out for a string (or text). By adding “This is the one!” to the message command, the next time you use the control, it will display that text in the message bar to let you know it is working.
on ui_control ($Cutoff) message ("This is the one!") end on
After you have completed the test though, the message will stay there until overridden by other message command. This is why it is important to have the message(““) command in the on init callback. This way, you can click the ! at the top of the Kontakt window (on the right corner of the interface) to reload the script, essentially running the on init block again. This will clear the messages, allowing you to test again or run a different test.
Discovering Values (Such as Note Numbers)
A useful feature that we have already seen above is that the message bar can read out values so you can see how changing controls can affect the value of a variable. Above, we discovered the value of $Cutoff by having the message bar read out the current value when adjusted on the UI.
Another common area to use the message bar to read out values is with note names. When you start to look into key switching or changing colours of specific keys, you will need to know the note number. In order to get this, you don’t have to look beyond the script itself. Below, an on note callback is used with a message command. Every time a note is pressed (any note at all) the message bar will read out the note number.
on note message ($EVENT_NOTE) end on
Let’s say you press middle C on the keyboard. Now, your message bar will read out the number “60”. Using this information, you could turn on groups, colour notes or even run commands to change parameters. It is entirely up to you. In the example below, a note colour is changed.
on init set_key_color(60, $KEY_COLOR_RED) end on