/[svn]/doc/docbase/instrument_scripts/nksp/reference/functions/nksp_wait_function.html
ViewVC logotype

Contents of /doc/docbase/instrument_scripts/nksp/reference/functions/nksp_wait_function.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2732 - (show annotations) (download) (as text)
Sun Apr 26 20:54:00 2015 UTC (8 years, 11 months ago) by schoenebeck
File MIME type: text/html
File size: 2926 byte(s)
* Initial import of doc.linuxsampler.org.

1 <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 Suspends / pauses the current event handler instance for the requested
11 amount of microseconds.
12 </p>
13
14 <h3>Function Prototype</h3>
15 <p/>
16 <code>
17 wait(??duration-us??)
18 </code>
19
20 <h3>Arguments</h3>
21 <table>
22 <tr>
23 <th>Argument Name</th> <th>Data Type</th> <th>Description</th>
24 </tr>
25 <tr>
26 <td><code>??duration-us??</code></td>
27 <td>Integer Number</td>
28 <td>Amount of microseconds to pause execution.<br>
29 [required]</td>
30 </tr>
31 </table>
32
33 <h3>Return Value</h3>
34 <p>None.</p>
35
36 <h3>Examples</h3>
37 <p/>
38 <code>
39 on init
40 { The amount of notes to play }
41 declare const $delayNotes := 4
42 { Tempo with which the new notes will follow the orignal note }
43 declare const $bpm := 90
44 { Convert BPM to microseconds (duration between the notes) }
45 declare const $delayMicroSeconds := 60 * 1000000 / $bpm
46 { Just a working variable for being used with the while loop below }
47 declare polyphonic $i
48 { For each successive note we trigger, we will reduce the velocity a bit}
49 declare polyphonic $velocity
50 end on
51
52 on note
53 { First initialize the variable $i with 4 each time we enter this event
54 handler, because each time we executed this handler, the variable will be 0 }
55 $i := $delayNotes
56
57 { Loop which will be executed 4 times in a row }
58 while ($i)
59 { Calculate the velocity for the next note being triggered }
60 $velocity := 127 * $i / ($delayNotes + 1)
61 { Suspend this script for a short moment ... }
62 wait($delayMicroSeconds)
63 { ... and after that short break, trigger a new note. }
64 play_note($EVENT_NOTE, $velocity)
65 { Decrement loop counter $i by one }
66 $i := $i - 1
67 end while
68 end on
69 </code>
70
71 <note class="important">
72 Using the <code>wait()</code> function can lead to concurrency issues with
73 regular variables, which are global variables by default. You might need
74 to use <a href="nksp.html#polyphonic_variables">polyphonic variables</a>
75 in such cases.
76 </note>
77
78 <note class="important">
79 The <code>wait()</code> function is not fully implemented in LinuxSampler
80 yet. Currently a <code>wait()</code> function call suspends execution,
81 but since the respective scheduler code is yet missing in LinuxSampler,
82 the script will automatically be resumed with the next audio fragment
83 cycle. So effectively a <code>wait()</code> call will pause your script
84 for a few miliseconds with LinuxSampler right now, no matter which
85 function argument you provided. Hopefully this will be implemented soon
86 though.
87 </note>
88
89 </body>
90 </html>

  ViewVC Help
Powered by ViewVC