1 |
<html> |
2 |
<head> |
3 |
<meta name="author" content="Christian Schoenebeck"> |
4 |
<title>play_note() function</title> |
5 |
<meta name="description" content="Triggers a new note."> |
6 |
</head> |
7 |
<body> |
8 |
<h1>play_note()</h1> |
9 |
<p> |
10 |
Triggers a new note to be played by the sampler. This is almost |
11 |
like generating |
12 |
a new MIDI note-on event programmatically, with the difference though |
13 |
that triggering a note programmatically this way does not cause a |
14 |
<code lang="nksp">note</code> event handler to be executed for the new note, nor |
15 |
will any MIDI specific note-on handling be done (i.e. it will have |
16 |
no effect on key switching or on the status of built-in array variable |
17 |
<code>%KEY_DOWN[]</code>). |
18 |
</p> |
19 |
|
20 |
<h3>Function Prototype</h3> |
21 |
<p/> |
22 |
<code lang="nksp"> |
23 |
play_note(??note??, [??velocity??], [??offset-us??], [??duration-us??]) |
24 |
</code> |
25 |
|
26 |
<h3>Arguments</h3> |
27 |
<table> |
28 |
<tr> |
29 |
<th>Argument Name</th> <th>Data Type</th> <th>Description</th> |
30 |
</tr> |
31 |
<tr> |
32 |
<td><code>??note??</code></td> |
33 |
<td>Integer Number</td> |
34 |
<td>Note number (absolute pitch).<br> |
35 |
[required]</td> |
36 |
</tr> |
37 |
<tr> |
38 |
<td><code>??velocity??</code></td> |
39 |
<td>Integer Number</td> |
40 |
<td>Trigger velocity.<br> |
41 |
[optional, default: <code>127</code>]</td> |
42 |
</tr> |
43 |
<tr> |
44 |
<td><code>??offset-us??</code></td> |
45 |
<td>Integer Number</td> |
46 |
<td>Start offset of the sample to be played in microseconds.<br> |
47 |
<code>-1</code>: Do not override the start offset and use the |
48 |
regular start offset as defined by the |
49 |
instrument file.<br> |
50 |
[optional, default: <code>-1</code>]</td> |
51 |
</tr> |
52 |
<tr> |
53 |
<td><code>??duration-us??</code></td> |
54 |
<td>Integer Number</td> |
55 |
<td>Length of the note to be played in microseconds.<br> |
56 |
<code>-1</code>: The note will be stopped when the event |
57 |
handler's note stops (must only be used with |
58 |
<code>note</code> event handlers).<br> |
59 |
<code>0</code>: The entire note's sample will be played to its end.<br> |
60 |
[optional, default: <code>0</code>]</td> |
61 |
</tr> |
62 |
</table> |
63 |
|
64 |
<note> |
65 |
You need at least LinuxSampler 2.0.0.svn2 or higher for passing a value |
66 |
higher than <code>0</code> for <code>??duration-us??</code>.<br> |
67 |
<br> |
68 |
You need at least LinuxSampler 2.0.0.svn3 or higher for passing <code>-1</code> for |
69 |
<code>??duration-us??</code>.<br> |
70 |
<br> |
71 |
You need at least LinuxSampler 2.0.0.svn55 or higher for passing any other value than <code>0</code> for |
72 |
<code>??offset-us??</code>. |
73 |
</note> |
74 |
|
75 |
<h3>Return Value</h3> |
76 |
<table> |
77 |
<tr> |
78 |
<th>Description</th> <th>Data Type</th> |
79 |
</tr> |
80 |
<tr> |
81 |
<td>Note's event ID of the new note that has been triggered. This event ID can be |
82 |
used to control the note during its life time.</td> |
83 |
<td>Event ID Number</td> |
84 |
</tr> |
85 |
</table> |
86 |
|
87 |
<h3>Examples</h3> |
88 |
<p> |
89 |
The following example resembles a simple delay effect. For each note |
90 |
being triggered by the musician, the script launches additional notes, |
91 |
each one of such additional successive notes with a more and more reduced |
92 |
volume.</p> |
93 |
<code> |
94 |
on init |
95 |
{ The amount of notes to play } |
96 |
declare const $delayNotes := 4 |
97 |
{ Tempo with which the new notes will follow the orignal note } |
98 |
declare const $bpm := 90 |
99 |
{ Convert BPM to microseconds (duration between the notes) } |
100 |
declare const $delayMicroSeconds := 60 * 1000000 / $bpm |
101 |
{ Just a working variable for being used with the while loop below } |
102 |
declare polyphonic $i |
103 |
{ For each successive note we trigger, we will reduce the velocity a bit} |
104 |
declare polyphonic $velocity |
105 |
end on |
106 |
|
107 |
on note |
108 |
{ First initialize the variable $i with 4 each time we enter this event |
109 |
handler, because each time we executed this handler, the variable will be 0 } |
110 |
$i := $delayNotes |
111 |
|
112 |
{ Loop which will be executed 4 times in a row } |
113 |
while ($i) |
114 |
{ Calculate the velocity for the next note being triggered } |
115 |
$velocity := 127 * $i / ($delayNotes + 1) |
116 |
{ Suspend this script for a short moment ... } |
117 |
wait($delayMicroSeconds) |
118 |
{ ... and after that short break, trigger a new note. } |
119 |
play_note($EVENT_NOTE, $velocity) |
120 |
{ Decrement loop counter $i by one } |
121 |
$i := $i - 1 |
122 |
end while |
123 |
end on |
124 |
</code> |
125 |
|
126 |
<h3>See also</h3> |
127 |
<p><code>note_off()</code>, <code>set_controller()</code><p> |
128 |
|
129 |
<h3>Availability</h3> |
130 |
<p>Since LinuxSampler 2.0.0<p> |
131 |
|
132 |
<note> |
133 |
The special value <code>-1</code> for <code>??offset-us??</code> only exists |
134 |
with NKSP, it is not available with KSP.<br> |
135 |
<br> |
136 |
Dynamic, optional arguments are |
137 |
only supported by NKSP. If you want to retain compatibility to KSP, |
138 |
then you should always pass a value for all arguments of this function. |
139 |
</note> |
140 |
|
141 |
</body> |
142 |
</html> |