270 |
had in mind when you wrote a certain script three years ago, and also if |
had in mind when you wrote a certain script three years ago, and also if |
271 |
some other developer might need to continue working on your scripts one |
some other developer might need to continue working on your scripts one |
272 |
day, you should place as many comments into your scripts as possible. A |
day, you should place as many comments into your scripts as possible. A |
273 |
comment in NKSP is everything that is nested into a an opening and closing |
comment in NKSP is everything that is nested into an opening and closing |
274 |
pair of curly braces. |
pair of curly braces. |
275 |
</p> |
</p> |
276 |
<code>{ This is a comment. }</code> |
<code>{ This is a comment. }</code> |
469 |
</p> |
</p> |
470 |
<p> |
<p> |
471 |
Let's assume you wanted to write an instrument script that shall resemble |
Let's assume you wanted to write an instrument script that shall resemble |
472 |
a simple delay effect. You could do that by writing an note event handler |
a simple delay effect. You could do that by writing a note event handler |
473 |
that automatically triggers several new notes for each note being |
that automatically triggers several new notes for each note being |
474 |
triggered on a MIDI keyboard. The following example demonstrates how that |
triggered on a MIDI keyboard. The following example demonstrates how that |
475 |
could be achieved. |
could be achieved. |
528 |
happening when executing that script exactly: Each time you play a note |
happening when executing that script exactly: Each time you play a note |
529 |
on your keyboard, a new instance of the <code>note</code> event handler |
on your keyboard, a new instance of the <code>note</code> event handler |
530 |
will be spawned and executed by the sampler. In all our examples so far |
will be spawned and executed by the sampler. In all our examples so far |
531 |
our scripts were so simple, that in practice only one handler instance |
our scripts were so simple, that in practice only one event handler instance |
532 |
was executed at a time. This is different in this case though. Because |
was executed at a time. This is different in this case though. Because |
533 |
by calling the <code>wait()</code> function, the respective handler |
by calling the <code>wait()</code> function, the respective handler |
534 |
execution instance is paused for a while and in total each handler |
execution instance is paused for a while and in total each handler |
537 |
you play multiple, successive notes on your keyboard in short time, you |
you play multiple, successive notes on your keyboard in short time, you |
538 |
will have several instances of the <code>note</code> event handler running |
will have several instances of the <code>note</code> event handler running |
539 |
simultaniously. And that's where the problem starts. Because by default, |
simultaniously. And that's where the problem starts. Because by default, |
540 |
as said, all variables are global variables. So the handler instances |
as said, all variables are global variables. So the event handler instances |
541 |
which are now running in parallel, are all reading and modifying the same |
which are now running in parallel, are all reading and modifying the same |
542 |
data. Thus the individual handler instances will modify the |
data. Thus the individual event handler instances will modify the |
543 |
<code>$i</code> and <code>$velocity</code> variables of each other, causing |
<code>$i</code> and <code>$velocity</code> variables of each other, causing |
544 |
an undesired misbehavior. |
an undesired misbehavior. |
545 |
</p> |
</p> |
1031 |
execution of the script instance by calling <code>exit()</code>. The latter |
execution of the script instance by calling <code>exit()</code>. The latter |
1032 |
is important in this example, because otherwise the script execution instances would |
is important in this example, because otherwise the script execution instances would |
1033 |
continue to run in this endless loop forever, even after the respectives |
continue to run in this endless loop forever, even after the respectives |
1034 |
notes are gone. Which would let your CPU usage to increase with every new note |
notes are gone. Which would let your CPU usage increase with every new note |
1035 |
and would never decrease again. |
and would never decrease again. |
1036 |
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 |
1037 |
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 |
1190 |
<p> |
<p> |
1191 |
If you are already familiar with some programming languages, then you |
If you are already familiar with some programming languages, then you |
1192 |
might already have seen such synchronized code block concepts |
might already have seen such synchronized code block concepts |
1193 |
in languages like i.e. Java. This technique really provides an easy way |
in languages like e.g. Java. This technique really provides an easy way |
1194 |
to protect certain sections of your script against concurrency issues. |
to protect certain sections of your script against concurrency issues. |
1195 |
</p> |
</p> |
1196 |
<note class="important"> |
<note class="important"> |
1293 |
</code> |
</code> |
1294 |
<p> |
<p> |
1295 |
All these operations yield in a <i>boolean</i> result which could then |
All these operations yield in a <i>boolean</i> result which could then |
1296 |
be used i.e. with <code>if</code> or <code>while</code> loop statements. |
be used e.g. with <code>if</code> or <code>while</code> loop statements. |
1297 |
</p> |
</p> |
1298 |
|
|
1299 |
<h3>String Operators</h3> |
<h3>String Operators</h3> |
1381 |
You should only reset a preprocessor condition that way if you did set it |
You should only reset a preprocessor condition that way if you did set it |
1382 |
with <code>SET_CONDITION(??condition-name??)</code> before. Trying to |
with <code>SET_CONDITION(??condition-name??)</code> before. Trying to |
1383 |
reset a condition that has not been set before, or trying to reset a |
reset a condition that has not been set before, or trying to reset a |
1384 |
condition that has already been reset, will both be ignored by the samlper, |
condition that has already been reset, will both be ignored by the sampler, |
1385 |
but again you will get a warning, and you should take care about it. |
but again you will get a warning, and you should take care about it. |
1386 |
</p> |
</p> |
1387 |
|
|
1558 |
previous example just to disable messages. There is actually a built-in |
previous example just to disable messages. There is actually a built-in |
1559 |
preprocessor condition dedicated to perform that task much more conveniently for you. |
preprocessor condition dedicated to perform that task much more conveniently for you. |
1560 |
To disable all messages in your script, simply add <code>SET_CONDITION(NKSP_NO_MESSAGE)</code> |
To disable all messages in your script, simply add <code>SET_CONDITION(NKSP_NO_MESSAGE)</code> |
1561 |
i.e. at the very beginning of your script. |
e.g. at the very beginning of your script. |
1562 |
So the previous example can be simplified like this: |
So the previous example can be simplified to this: |
1563 |
</p> |
</p> |
1564 |
<code> |
<code> |
1565 |
{ Enable debug mode, so show all debug messages. } |
{ Enable debug mode, so show all debug messages. } |