1 |
schoenebeck |
2732 |
<html> |
2 |
|
|
<head> |
3 |
|
|
<meta name="author" content="Christian Schoenebeck"> |
4 |
|
|
<title>wait() function</title> |
5 |
|
|
<meta name="description" content="Pauses execution for a certain amount of time."> |
6 |
|
|
</head> |
7 |
|
|
<body> |
8 |
|
|
<h1>wait()</h1> |
9 |
|
|
<p> |
10 |
schoenebeck |
2949 |
Suspends / pauses execution of the current event handler instance for the requested |
11 |
|
|
amount of microseconds. The paused event handler instance can also be resumed before |
12 |
schoenebeck |
2950 |
the requested amount times elapsed by calling <code lang="nksp">stop_wait()</code> from another |
13 |
schoenebeck |
2949 |
event handler instance. |
14 |
schoenebeck |
2732 |
</p> |
15 |
schoenebeck |
2973 |
<p> |
16 |
|
|
The <code>??duration-us??</code> argument must neither |
17 |
|
|
be negative nor zero, otherwise script execution will be aborted, because this |
18 |
|
|
is a common indication of bugs in scripts which could potentially lead to |
19 |
|
|
real-time instability or worse scenarios otherwise. |
20 |
|
|
</p> |
21 |
schoenebeck |
2949 |
<note> |
22 |
|
|
If the even handler instance's built-in variable <code>$NKSP_IGNORE_WAIT</code> |
23 |
|
|
reflects <code>1</code> then all calls to <code>wait()</code> will be ignored. |
24 |
|
|
This might for example be the case when <code>stop_wait()</code> with |
25 |
|
|
<code>1</code> being passed to the 2nd argument of that function. |
26 |
|
|
</note> |
27 |
|
|
|
28 |
schoenebeck |
2732 |
<h3>Function Prototype</h3> |
29 |
|
|
<p/> |
30 |
schoenebeck |
2742 |
<code lang="nksp"> |
31 |
schoenebeck |
2732 |
wait(??duration-us??) |
32 |
|
|
</code> |
33 |
|
|
|
34 |
|
|
<h3>Arguments</h3> |
35 |
|
|
<table> |
36 |
|
|
<tr> |
37 |
|
|
<th>Argument Name</th> <th>Data Type</th> <th>Description</th> |
38 |
|
|
</tr> |
39 |
|
|
<tr> |
40 |
|
|
<td><code>??duration-us??</code></td> |
41 |
|
|
<td>Integer Number</td> |
42 |
schoenebeck |
2973 |
<td>Positive (non zero) amount of microseconds to pause execution.<br> |
43 |
schoenebeck |
2732 |
[required]</td> |
44 |
|
|
</tr> |
45 |
|
|
</table> |
46 |
|
|
|
47 |
|
|
<h3>Return Value</h3> |
48 |
|
|
<p>None.</p> |
49 |
|
|
|
50 |
|
|
<h3>Examples</h3> |
51 |
|
|
<p/> |
52 |
|
|
<code> |
53 |
|
|
on init |
54 |
|
|
{ The amount of notes to play } |
55 |
|
|
declare const $delayNotes := 4 |
56 |
|
|
{ Tempo with which the new notes will follow the orignal note } |
57 |
|
|
declare const $bpm := 90 |
58 |
|
|
{ Convert BPM to microseconds (duration between the notes) } |
59 |
|
|
declare const $delayMicroSeconds := 60 * 1000000 / $bpm |
60 |
|
|
{ Just a working variable for being used with the while loop below } |
61 |
|
|
declare polyphonic $i |
62 |
|
|
{ For each successive note we trigger, we will reduce the velocity a bit} |
63 |
|
|
declare polyphonic $velocity |
64 |
|
|
end on |
65 |
|
|
|
66 |
|
|
on note |
67 |
|
|
{ First initialize the variable $i with 4 each time we enter this event |
68 |
|
|
handler, because each time we executed this handler, the variable will be 0 } |
69 |
|
|
$i := $delayNotes |
70 |
|
|
|
71 |
|
|
{ Loop which will be executed 4 times in a row } |
72 |
|
|
while ($i) |
73 |
|
|
{ Calculate the velocity for the next note being triggered } |
74 |
|
|
$velocity := 127 * $i / ($delayNotes + 1) |
75 |
|
|
{ Suspend this script for a short moment ... } |
76 |
|
|
wait($delayMicroSeconds) |
77 |
|
|
{ ... and after that short break, trigger a new note. } |
78 |
|
|
play_note($EVENT_NOTE, $velocity) |
79 |
|
|
{ Decrement loop counter $i by one } |
80 |
|
|
$i := $i - 1 |
81 |
|
|
end while |
82 |
|
|
end on |
83 |
|
|
</code> |
84 |
|
|
|
85 |
schoenebeck |
2872 |
<note> |
86 |
schoenebeck |
2732 |
Using the <code>wait()</code> function can lead to concurrency issues with |
87 |
|
|
regular variables, which are global variables by default. You might need |
88 |
|
|
to use <a href="nksp.html#polyphonic_variables">polyphonic variables</a> |
89 |
|
|
in such cases. |
90 |
|
|
</note> |
91 |
|
|
|
92 |
schoenebeck |
2872 |
<note> |
93 |
|
|
You need at least LinuxSampler 2.0.0.svn2 or higher for the |
94 |
|
|
<code>wait()</code> function to fully work as expected. Versions |
95 |
|
|
of LinuxSampler older than that will not resume the script at the |
96 |
|
|
requested amount of time, instead those older version will resume |
97 |
|
|
the script always at the beginning of the next audio fragment |
98 |
|
|
cycle. So effectively a <code>wait()</code> call with a LinuxSampler |
99 |
|
|
version older than 2.0.0.svn2 will pause your script for a few |
100 |
|
|
miliseconds, no matter which function argument you provided. |
101 |
schoenebeck |
2732 |
</note> |
102 |
|
|
|
103 |
|
|
</body> |
104 |
|
|
</html> |