![]() ![]() So the way to read the above instruction would be that the variable $interval is set equal to ‑3. The := notation can be read as "set equal to”. You can assign a value to a variable when it's declared by changing the declare instruction to:Īlternatively, you can assign a value to a variable at any other point in the script - including the on note callback - by using the following instruction. By default, newly declared variables are assigned a value of 0, so at the moment our harmoniser will simply trigger a duplicate note of the same pitch. Now that we've declared our $interval variable, we need to assign a value to it. Once you've added the variable declaration to the 'on init' callback, your Script Editor should look something like this. So if you define the on init callback in the script with the declare $interval instruction, you should end up with a script that looks like the one shown in the screen above right. And, in the same way we defined the behaviour of the on note callback by adding instructions between the lines on note and end on, we'll define the on init callback by adding instructions between on init and end on. And to do this, we need to define another callback, called on init.Īs you might already have guessed, the on init callback is triggered when KSP initialises a script, just as the on note callback is triggered when a note is played. Instead, variables should be declared once when KSP first initialises the script. The reason for this is that if variables could be declared in the on note callback, they would end up being declared every time a note was played, which could create a number of issues. However, to make matters a little more complicated, KSP doesn't allow you to declare variables in the on note callback. So to declare our $interval variable, we need to write the following instruction in our script. It's bit like bringing a really expensive bottle of Scotch through customs: you need to declare it before you can start drinking it. And if you look at the Script Editor's Status Line, KSP reports "ERROR (line 2): variable $interval was not declared”. The reason for the error is that when we use a variable of our own - as opposed to a built‑in variable like $EVENT_NOTE - we have to first tell KSP of its existence before we can actually start using it. But in this case, the highlighted line is indeed to blame. It's worth noting that there are cases where the highlighted line isn't always the one that contains the error (see the 'Debugging' box for more on script troubleshooting), so it's often worth checking the line before or after as well when tracking down a problem. The line containing our play_note command will be highlighted in red, and this means that KSP found an error in our script. If you click Apply right now, you'll notion the Change Indicator doesn't turn black. So if $interval stores the value ‑3 and $EVENT_NOTE is 60, the pitch of the note to play would be 60 plus ‑3, which is the same as 60 – 3 = 57. The reason for this - and now for a flashback to school maths lessons - is that adding a negative value results in that value being subtracted from the sum. In the above instruction, we now get the pitch of the harmony note by adding $interval to the built‑in $EVENT_NOTE variable. ![]() Play_note($EVENT_NOTE + $interval, $EVENT_VELOCITY, 0, ‑1) To do this, we'll substitute the ‑3 constant for a variable that's called $interval. In order to make our harmoniser adjustable without needing to edit the script, we need to define the interval of the harmony note as a variable - a value that can change - instead of defining it as a constant. So if we wanted this particular script to produce a different harmony note instead, we would need to edit this constant value. We refer to a value such as ‑3 as a constant because its value will never change: ‑3 will always be ‑3. Play_note($EVENT_NOTE - 3, $EVENT_VELOCITY, 0, ‑1)īecause the interval of the harmony note is written into the script with the constant ‑3, the script is, in essence, a fixed harmoniser. It should have looked something like this: ![]() Last month, we looked at creating the simplest harmoniser, and finished with a script that would play a harmony note a minor third below the original note. Building on last month's introduction to the basics of scripting in Native Instruments' Kontakt soft sampler, we explain how to make your scripted functions adjustable via a simple user interface.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |