11 |
your own instrument scripts in short time. It concentrates on describing |
your own instrument scripts in short time. It concentrates on describing |
12 |
the script language. If you rather want to learn how to modify and |
the script language. If you rather want to learn how to modify and |
13 |
attach scripts to your sounds, then please refer to the gigedit manual for |
attach scripts to your sounds, then please refer to the gigedit manual for |
14 |
<a href="gigedit_scripts.html">how to manage instrument scripts with gigedit</a>. |
<a href="gigedit_scripts.html">how to manage instrument scripts with gigedit</a> |
15 |
|
for Gigasampler/GigaStudio format sounds, or refer to the SFZ opcode |
16 |
|
<code lang="sfz">script</code> for attaching NKSP scripts with |
17 |
|
SFZ format sounds. |
18 |
</p> |
</p> |
19 |
|
|
20 |
<h3>At a Glance</h3> |
<h3>At a Glance</h3> |
254 |
<p> |
<p> |
255 |
The left hand side's <code>??variable-name??</code> is an arbitrary name |
The left hand side's <code>??variable-name??</code> is an arbitrary name |
256 |
you can chose for your variable. That name might consist of English |
you can chose for your variable. That name might consist of English |
257 |
letters A to Z (lower and upper case) and the underscore character "<code>_</code>". |
letters A to Z (lower and upper case), digits (<code>0</code> to <code>9</code>), |
258 |
|
and the underscore character "<code>_</code>". |
259 |
Variable names must be unique. So you can neither declare several variables |
Variable names must be unique. So you can neither declare several variables |
260 |
with the same name, nor can you use a name for your variable that is |
with the same name, nor can you use a name for your variable that is |
261 |
already been reserved by <i>built-in variables</i>. |
already been reserved by <i>built-in variables</i>. |
772 |
@postfix := "nd" |
@postfix := "nd" |
773 |
case 3 |
case 3 |
774 |
@postfix := "rd" |
@postfix := "rd" |
775 |
end if |
end select |
776 |
|
|
777 |
message("This is the " & $numberOfNotes & @postfix & " note triggered so far.") |
message("This is the " & $numberOfNotes & @postfix & " note triggered so far.") |
778 |
end on |
end on |
813 |
case 3 |
case 3 |
814 |
message("Third note was triggered!") { Will never be printed ! } |
message("Third note was triggered!") { Will never be printed ! } |
815 |
exit |
exit |
816 |
end if |
end select |
817 |
|
|
818 |
message("Wow, already the " & $numberOfNotes & "th note triggered.") |
message("Wow, already the " & $numberOfNotes & "th note triggered.") |
819 |
end on |
end on |
852 |
case 1 to 99 |
case 1 to 99 |
853 |
message("Less than 100 notes triggered so far") |
message("Less than 100 notes triggered so far") |
854 |
exit |
exit |
855 |
end if |
end select |
856 |
|
|
857 |
message("Wow, already the " & $numberOfNotes & "th note triggered.") |
message("Wow, already the " & $numberOfNotes & "th note triggered.") |
858 |
end on |
end on |
937 |
<p> |
<p> |
938 |
We already came across various built-in functions, which you may call |
We already came across various built-in functions, which you may call |
939 |
by your scripts to perform certain tasks or behavior which is already |
by your scripts to perform certain tasks or behavior which is already |
940 |
provided for you by the sampler. When working on larger scripts, you |
provided for you by the sampler. NKSP also allows you to write your |
941 |
|
own functions, which you then may call from various places of your |
942 |
|
script. |
943 |
|
<p> |
944 |
|
</p> |
945 |
|
When working on larger scripts, you |
946 |
may notice that you easily get to the point where you may have to |
may notice that you easily get to the point where you may have to |
947 |
duplicate portions of your script code, since there are certain things |
duplicate portions of your script code, since there are certain things |
948 |
that you may have to do again and again in different parts of your script. |
that you may have to do again and again in different parts of your script. |
949 |
Software developers usually try to avoid such code duplications to |
Software developers usually try to avoid such code duplications to |
950 |
keep the overall amount of code as small as possible, since it would |
keep the overall amount of code as small as possible, since the |
951 |
|
overall amount of code would bloat quickly and would |
952 |
make the software very hard to maintain. One way for you to avoid such |
make the software very hard to maintain. One way for you to avoid such |
953 |
script code duplications with NKSP is to write so called <i>User Functions</s>. |
script code duplications with NKSP is to write so called <i>User Functions</s>. |
954 |
</p> |
</p> |
974 |
</code> |
</code> |
975 |
<p> |
<p> |
976 |
This script will run an endless loop for each note being triggered. |
This script will run an endless loop for each note being triggered. |
977 |
Every <code>200ms</code> it will turn the volume alternatingly down and |
Every <code lang="none">200ms</code> it will turn the volume alternatingly down and |
978 |
up to create the audible stuttering effect. After each <code>wait()</code> |
up to create the audible stuttering effect. After each <code lang="nksp">wait()</code> |
979 |
call it calls <code>event_status($EVENT_ID)</code> to check whether |
call it calls <code>event_status($EVENT_ID)</code> to check whether |
980 |
this note is still alive, and as soon as the note died, it will stop |
this note is still alive, and as soon as the note died, it will stop |
981 |
execution of the script instance by calling <code>exit()</code>. The latter |
execution of the script instance by calling <code>exit()</code>. The latter |
982 |
is important in this case, because otherwise the script instances would |
is important in this example, because otherwise the script execution instances would |
983 |
continue to run in this endless loop forever, even after the respectives |
continue to run in this endless loop forever, even after the respectives |
984 |
notes are gone. Which would let your CPU usage to increase with every note. |
notes are gone. Which would let your CPU usage to increase with every new note |
985 |
|
and would never decrease again. |
986 |
This behavior of the sampler is not a bug, it is intended, since there may |
This behavior of the sampler is not a bug, it is intended, since there may |
987 |
also be cases where you want to do certain things by script even after the |
also be cases where you want to do certain things by script even after the |
988 |
respective notes are dead and gone. However as you can see, that script is |
respective notes are dead and gone. However as you can see, that script is |
1008 |
</code> |
</code> |
1009 |
<p> |
<p> |
1010 |
The script became in this simple example only slightly smaller, but it also |
The script became in this simple example only slightly smaller, but it also |
1011 |
became easier to read. And in practice, with a more complex script, you can |
became easier to read and behaves identically to the previous solution. |
1012 |
|
And in practice, with a more complex script, you can |
1013 |
reduce the overall amount of script code a lot this way. You can choose any |
reduce the overall amount of script code a lot this way. You can choose any |
1014 |
name for your own user functions, as long as the name is not already |
name for your own user functions, as long as the name is not already |
1015 |
reserved by a built-in function. Note that for calling a user function, |
reserved by a built-in function. Note that for calling a user function, |