1021 |
|
|
1022 |
<h3>Synchronized Blocks</h3> |
<h3>Synchronized Blocks</h3> |
1023 |
<p> |
<p> |
1024 |
When we introduced the <a href="polyphonic_variables">polyphonic keyword</a> |
When we introduced the <a href="#polyphonic_variables">polyphonic keyword</a> |
1025 |
previously, we learned that a script may automatically be suspended by |
previously, we learned that a script may automatically be suspended by |
1026 |
the sampler at any time and then your script is thus sleeping for an |
the sampler at any time and then your script is thus sleeping for an |
1027 |
arbitrary while. The sampler must do such auto suspensions under certain |
arbitrary while. The sampler must do such auto suspensions under certain |
1500 |
use the preprocessor instead for such things. And like stated above, |
use the preprocessor instead for such things. And like stated above, |
1501 |
there are certain things which you can only achieve with the preprocessor. |
there are certain things which you can only achieve with the preprocessor. |
1502 |
</p> |
</p> |
1503 |
|
|
1504 |
|
<h3>Disable Messages</h3> |
1505 |
|
<p> |
1506 |
|
Since it is quite common to switch a script between a development version |
1507 |
|
and a production version, you actually don't need to wrap all your |
1508 |
|
<code>message()</code> calls into preprocessor statements like in the |
1509 |
|
previous example just to disable messages. There is actually a built-in |
1510 |
|
preprocessor condition dedicated to perform that task much more conveniently for you. |
1511 |
|
To disable all messages in your script, simply add <code>SET_CONDITION(NKSP_NO_MESSAGE)</code> |
1512 |
|
i.e. at the very beginng of your script. |
1513 |
|
So the previous example can be simplified like this: |
1514 |
|
</p> |
1515 |
|
<code> |
1516 |
|
{ Enable debug mode, so show all debug messages. } |
1517 |
|
SET_CONDITION(DEBUG_MODE) |
1518 |
|
|
1519 |
|
{ If our user declared condition "DEBUG_MODE" is not set ... } |
1520 |
|
USE_CODE_IF_NOT(DEBUG_MODE) |
1521 |
|
{ ... then enable this built-in condition to disable all message() calls. } |
1522 |
|
SET_CONDITION(NKSP_NO_MESSAGE) |
1523 |
|
END_USE_CODE |
1524 |
|
|
1525 |
|
on init |
1526 |
|
declare const %primes[12] := ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 ) |
1527 |
|
declare $i |
1528 |
|
|
1529 |
|
message("This script has just been loaded.") |
1530 |
|
|
1531 |
|
USE_CODE_IF(DEBUG_MODE) |
1532 |
|
$i := 0 |
1533 |
|
while ($i < num_elements(%primes)) |
1534 |
|
message("Prime " & $i & " is " & %primes[$i]) |
1535 |
|
$i := $i + 1 |
1536 |
|
end while |
1537 |
|
END_USE_CODE |
1538 |
|
end on |
1539 |
|
|
1540 |
|
on note |
1541 |
|
message("Note " & $EVENT_NOTE & " was triggered with velocity " & $EVENT_VELOCITY) |
1542 |
|
end on |
1543 |
|
|
1544 |
|
on release |
1545 |
|
message("Note " & $EVENT_NOTE & " was released with release velocity " & $EVENT_VELOCITY) |
1546 |
|
end on |
1547 |
|
|
1548 |
|
on controller |
1549 |
|
message("MIDI Controller " & $CC_NUM " changed its value to " & %CC[$CC_NUM]) |
1550 |
|
end on |
1551 |
|
</code> |
1552 |
|
<p> |
1553 |
|
You can then actually also add <code>RESET_CONDITION(NKSP_NO_MESSAGE)</code> |
1554 |
|
at another section of your script, which will cause all subsequent |
1555 |
|
<code>message()</code> calls to be processed again. So that way you can |
1556 |
|
easily enable and disable <code>message()</code> calls of entire individual |
1557 |
|
sections of your script, without having to wrap all <code>message()</code> |
1558 |
|
calls into preprocessor statements. |
1559 |
|
</p> |
1560 |
|
|
1561 |
<h2>What Next?</h2> |
<h2>What Next?</h2> |
1562 |
<p> |
<p> |
1563 |
You have completed the introduction of the NKSP real-time instrument |
You have completed the introduction of the NKSP real-time instrument |