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 like generating |
11 |
a new MIDI note-on event programmatically. |
12 |
</p> |
13 |
|
14 |
<h3>Function Prototype</h3> |
15 |
<p/> |
16 |
<code lang="nksp"> |
17 |
play_note(??note??, [??velocity??], [??offset-us??], [??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>??note??</code></td> |
27 |
<td>Integer Number</td> |
28 |
<td>Note number (absolute pitch).<br> |
29 |
[required]</td> |
30 |
</tr> |
31 |
<tr> |
32 |
<td><code>??velocity??</code></td> |
33 |
<td>Integer Number</td> |
34 |
<td>Trigger velocity.<br> |
35 |
[optional, default: 127]</td> |
36 |
</tr> |
37 |
<tr> |
38 |
<td><code>??offset-us??</code></td> |
39 |
<td>Integer Number</td> |
40 |
<td>Start offset of the sample to be played in microseconds.<br> |
41 |
[optional, default: 0]</td> |
42 |
</tr> |
43 |
<tr> |
44 |
<td><code>??duration-us??</code></td> |
45 |
<td>Integer Number</td> |
46 |
<td>Length of the note to be played in microseconds.<br> |
47 |
-1: The note will be stopped when the event |
48 |
handler's note stops.<br> |
49 |
0: The entire note's sample will be played to its end.<br> |
50 |
[optional, default: 0]</td> |
51 |
</tr> |
52 |
</table> |
53 |
|
54 |
<note class="important"> |
55 |
Passing any other value than <code>0</code> for <code>??duration-us??</code> |
56 |
is not supported by LinuxSampler yet. |
57 |
</note> |
58 |
|
59 |
<h3>Return Value</h3> |
60 |
<table> |
61 |
<tr> |
62 |
<th>Description</th> <th>Data Type</th> |
63 |
</tr> |
64 |
<tr> |
65 |
<td>Note's event ID of the new note that has been triggered. This event ID can be |
66 |
used to control the note during its life time.</td> |
67 |
<td>Event ID Number</td> |
68 |
</tr> |
69 |
</table> |
70 |
|
71 |
<h3>Examples</h3> |
72 |
<p/> |
73 |
<code> |
74 |
on init |
75 |
{ The amount of notes to play } |
76 |
declare const $delayNotes := 4 |
77 |
{ Tempo with which the new notes will follow the orignal note } |
78 |
declare const $bpm := 90 |
79 |
{ Convert BPM to microseconds (duration between the notes) } |
80 |
declare const $delayMicroSeconds := 60 * 1000000 / $bpm |
81 |
{ Just a working variable for being used with the while loop below } |
82 |
declare polyphonic $i |
83 |
{ For each successive note we trigger, we will reduce the velocity a bit} |
84 |
declare polyphonic $velocity |
85 |
end on |
86 |
|
87 |
on note |
88 |
{ First initialize the variable $i with 4 each time we enter this event |
89 |
handler, because each time we executed this handler, the variable will be 0 } |
90 |
$i := $delayNotes |
91 |
|
92 |
{ Loop which will be executed 4 times in a row } |
93 |
while ($i) |
94 |
{ Calculate the velocity for the next note being triggered } |
95 |
$velocity := 127 * $i / ($delayNotes + 1) |
96 |
{ Suspend this script for a short moment ... } |
97 |
wait($delayMicroSeconds) |
98 |
{ ... and after that short break, trigger a new note. } |
99 |
play_note($EVENT_NOTE, $velocity) |
100 |
{ Decrement loop counter $i by one } |
101 |
$i := $i - 1 |
102 |
end while |
103 |
end on |
104 |
</code> |
105 |
|
106 |
</body> |
107 |
</html> |