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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3256 - (show annotations) (download) (as text)
Tue May 30 16:14:40 2017 UTC (3 years, 5 months ago) by schoenebeck
File MIME type: text/html
File size: 5502 byte(s)
* NKSP: Added change_play_pos() function.

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>0</code>: The entire note's sample will be played to its end.<br>
57 <code>-1</code>: The note will be stopped when the event
58 handler's note stops (must only be used with
59 <code>note</code> event handlers).<br>
60 <code>-2</code>: The note will be stopped when a note-off event was received on the passed <code>??note??</code> number (argument 1).<br>
61 [optional, default: <code>0</code>]</td>
62 </tr>
63 </table>
64
65 <note>
66 You need at least LinuxSampler 2.0.0.svn2 for passing a value
67 higher than <code>0</code> for <code>??duration-us??</code>.<br>
68 <br>
69 You need at least LinuxSampler 2.0.0.svn3 for passing <code>-1</code> for
70 <code>??duration-us??</code>.<br>
71 <br>
72 You need at least LinuxSampler 2.0.0.svn55 for passing any other value than <code>0</code> for
73 <code>??offset-us??</code>.<br>
74 <br>
75 You need at least LinuxSampler 2.0.0.svn56 for passing <code>-2</code> for
76 <code>??duration-us??</code>.
77 </note>
78
79 <h3>Return Value</h3>
80 <table>
81 <tr>
82 <th>Description</th> <th>Data Type</th>
83 </tr>
84 <tr>
85 <td>Note's event ID of the new note that has been triggered. This event ID can be
86 used to control the note during its life time.</td>
87 <td>Event ID Number</td>
88 </tr>
89 </table>
90
91 <h3>Examples</h3>
92 <p>
93 The following example resembles a simple delay effect. For each note
94 being triggered by the musician, the script launches additional notes,
95 each one of such additional successive notes with a more and more reduced
96 volume.</p>
97 <code>
98 on init
99 { The amount of notes to play }
100 declare const $delayNotes := 4
101 { Tempo with which the new notes will follow the orignal note }
102 declare const $bpm := 90
103 { Convert BPM to microseconds (duration between the notes) }
104 declare const $delayMicroSeconds := 60 * 1000000 / $bpm
105 { Just a working variable for being used with the while loop below }
106 declare polyphonic $i
107 { For each successive note we trigger, we will reduce the velocity a bit}
108 declare polyphonic $velocity
109 end on
110
111 on note
112 { First initialize the variable $i with 4 each time we enter this event
113 handler, because each time we executed this handler, the variable will be 0 }
114 $i := $delayNotes
115
116 { Loop which will be executed 4 times in a row }
117 while ($i)
118 { Calculate the velocity for the next note being triggered }
119 $velocity := 127 * $i / ($delayNotes + 1)
120 { Suspend this script for a short moment ... }
121 wait($delayMicroSeconds)
122 { ... and after that short break, trigger a new note. }
123 play_note($EVENT_NOTE, $velocity)
124 { Decrement loop counter $i by one }
125 $i := $i - 1
126 end while
127 end on
128 </code>
129
130 <h3>See also</h3>
131 <p><code>note_off()</code>, <code>set_controller()</code>, <code>change_note()</code>, <code>change_velo()</code>, <code>change_play_pos()</code><p>
132
133 <h3>Availability</h3>
134 <p>Since LinuxSampler 2.0.0<p>
135
136 <note>
137 The special value <code>-1</code> for <code>??offset-us??</code> only exists
138 with NKSP, it is not available with KSP.<br>
139 <br>
140 The special value <code>-2</code> for <code>??duration-us??</code> only exists
141 with NKSP, it is not available with KSP.<br>
142 <br>
143 Dynamic, optional arguments are
144 only supported by NKSP. If you want to retain compatibility to KSP,
145 then you should always pass a value for all arguments of this function.
146 </note>
147
148 </body>
149 </html>

  ViewVC Help
Powered by ViewVC