/[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 3238 - (show annotations) (download) (as text)
Sun May 28 16:47:02 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: text/html
File size: 4337 byte(s)
- NKSP: Just added some description to example code of play_note().

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 [optional, default: <code>0</code>]</td>
48 </tr>
49 <tr>
50 <td><code>??duration-us??</code></td>
51 <td>Integer Number</td>
52 <td>Length of the note to be played in microseconds.<br>
53 <code>-1</code>: The note will be stopped when the event
54 handler's note stops (must only be used with
55 <code>note</code> event handlers).<br>
56 <code>0</code>: The entire note's sample will be played to its end.<br>
57 [optional, default: <code>0</code>]</td>
58 </tr>
59 </table>
60
61 <note>
62 You need at least LinuxSampler 2.0.0.svn2 or higher for passing a value
63 higher than <code>0</code> for <code>??duration-us??</code>, and you need
64 at least LinuxSampler 2.0.0.svn3 or higher for passing <code>-1</code> for
65 <code>??duration-us??</code>.
66 </note>
67
68 <note class="important">
69 Passing any other value than <code>0</code> for <code>??offset-us??</code>
70 is not supported by LinuxSampler yet.
71 </note>
72
73 <h3>Return Value</h3>
74 <table>
75 <tr>
76 <th>Description</th> <th>Data Type</th>
77 </tr>
78 <tr>
79 <td>Note's event ID of the new note that has been triggered. This event ID can be
80 used to control the note during its life time.</td>
81 <td>Event ID Number</td>
82 </tr>
83 </table>
84
85 <h3>Examples</h3>
86 <p>
87 The following example resembles a simple delay effect. For each note
88 being triggered by the musician, the script launches additional notes,
89 each one of such additional successive notes with a more and more reduced
90 volume.</p>
91 <code>
92 on init
93 { The amount of notes to play }
94 declare const $delayNotes := 4
95 { Tempo with which the new notes will follow the orignal note }
96 declare const $bpm := 90
97 { Convert BPM to microseconds (duration between the notes) }
98 declare const $delayMicroSeconds := 60 * 1000000 / $bpm
99 { Just a working variable for being used with the while loop below }
100 declare polyphonic $i
101 { For each successive note we trigger, we will reduce the velocity a bit}
102 declare polyphonic $velocity
103 end on
104
105 on note
106 { First initialize the variable $i with 4 each time we enter this event
107 handler, because each time we executed this handler, the variable will be 0 }
108 $i := $delayNotes
109
110 { Loop which will be executed 4 times in a row }
111 while ($i)
112 { Calculate the velocity for the next note being triggered }
113 $velocity := 127 * $i / ($delayNotes + 1)
114 { Suspend this script for a short moment ... }
115 wait($delayMicroSeconds)
116 { ... and after that short break, trigger a new note. }
117 play_note($EVENT_NOTE, $velocity)
118 { Decrement loop counter $i by one }
119 $i := $i - 1
120 end while
121 end on
122 </code>
123
124 </body>
125 </html>

  ViewVC Help
Powered by ViewVC