Debian Codegraph @

doc/part3.html

raw
1 <!DOCTYPE html>
2 <html><head><title>The NyquistIDE Program</title>
3 <link rel="stylesheet" type="text/css" href="nyquiststyle.css">
4 <link rel="icon" href="nyquist-icon.png" />
5 <link rel="shortcut icon" href="nyquist-icon.png" />
6 </head>
7 <body bgcolor="ffffff">
8 <a href = "part2.html">Previous Section</a> | <a href = "part4.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
9 <hr>
10 <a name = "18"><h2>The NyquistIDE Program</h2></a>
11 <p>The NyquistIDE program combines many helpful functions and interfaces
12 to help you get the most out of Nyquist. NyquistIDE is implemented in
13 Java, and you will need the Java runtime system or development system
14 installed on your computer to use NyquistIDE. The best way to learn
15 about NyquistIDE is to just use it. This chapter introduces some of
16 the less obvious features. If you are confused by something and you do
17 not find the information you need here, please contact the author.</p>
18 <a name = "19"><h3>NyquistIDE Overview</h3></a>
19 <p>The NyquistIDE runs the command-line version of Nyquist as a subtask,
20 so everything that works in Nyquist should work when using the
21 NyquistIDE and vice-versa. Input to Nyquist is usually entered in the
22 top left window of the NyquistIDE. When you type return, if the
23 expression or statement appears to be complete, the expression you
24 typed is sent to Nyquist. Output from Nyquist appears in a window
25 below. You cannot type into or edit the output window text.</p>
26
27 <p>The normal way to use the NyquistIDE is to create or open one or more
28 files. You edit these files and then click the Load button. To load a
29 file, NyquistIDE saves the file, sets the current directory of Nyquist
30 to that of the file, then issues a <code>load</code> command to Nyquist. In
31 this case and several others, you may notice that NyquistIDE sends
32 expressions to Nyquist automatically for evaluation. You can always
33 see the commands and their results in the output window.</p>
34
35 <p>Notice that when you load a selected file window, NyquistIDE uses
36 <code>setdir</code> to change Nyquist's current directory. This helps to
37 keep the two programs in sync. Normally, you should keep all the files
38 of a project in the same directory and avoid manually changing
39 Nyquist's current directory (i.e. avoid calling <code>setdir</code> in your
40 code).</p>
41
42 <p>Arranging windows in the NyquistIDE can be time-consuming, and
43 depending on the operating system, it is possible for a window to get
44 into a position where you cannot drag it to a new position. The
45 Window:Tile menu command can be used to automatically lay out windows
46 in a rational way. There is a preference setting to determine the
47 height of the completion list relative to the height of the output
48 window.</p>
49
50 <p>Many of the key commands for editing files are standard and built into
51 Java. A special
52 command, &ldquo;Copy to Lisp,&rdquo; or Control-U (Command-U on macOS) copies the
53 selection and enters it into the input window as if it had been typed
54 there.</p>
55 <a name = "20"><h3>The Button Bar</h3></a><a name="index110"></a>
56 <p>There are a number of buttons with frequently-used operations. These are:
57 <ul>
58 <li>
59 Info &ndash; <a name="index111"></a>Print information about Nyquist memory
60 utilization, including
61 the number of free cons cells, the number of garbage collections,
62 the total number of cons cells, the total amount of sample buffer memory,
63 and the amount of memory in free sample buffers.</li>
64 <li>Break &ndash; <a name="index112"></a>Send a break character to XLISP. This
65 can be used to enter the debugger (the break loop) while a program is
66 running. Resume by typing <code>(co)</code>.</li>
67 <li>SAL/Lisp &ndash; <a name="index113"></a><a name="index114"></a>Switch modes.
68 The button names the mode (SAL or Lisp) you will switch to, not the
69 current mode. For example, if you are in Lisp mode and want to type
70 a SAL command, click the SAL button first.</li>
71 <li>Top &ndash; <a name="index115"></a>Enters <code>(top)</code> into Nyquist.
72 If the XLISP prompt is <code>1&gt;</code> or
73 some other integer followed by &ldquo;<code>&gt;</code>&rdquo;, clicking the Top button
74 will exit the debug loop and return to the top-level prompt.</li>
75 <li>Replay &ndash; <a name="index116"></a>Enters <code>(r)</code> into Nyquist.
76 This command replays the last computed sound.</li>
77 <li>F2-F12 &ndash; <a name="index117"></a>Enters <code>(f2)</code> etc. into Nyquist.
78 These commands are not built-in, and allow users to define their own
79 custom actions.</li>
80 <li>Browse &ndash; <a name="index118"></a>Equivalent to the Window:Browse
81 menu item. (See Section <a href = "#23">Browser</a>.)</li>
82 <li>EQ &ndash; <a name="index119"></a>Equivalent to the Window:EQ menu item.
83 (See Section <a href = "#25">Equalizer Editor</a>.)</li>
84 <li>EnvEdit &ndash; <a name="index120"></a>Equivalent to the Window:Envelope Edit
85 menu item. (See Section <a href = "#24">Envelope Editor</a>.)</li>
86 <li>NewFile &ndash; <a name="index121"></a>Equivalent to the File:New menu
87 item. Opens a new file editing window for creating and
88 loading a Lisp or SAL program file.</li>
89 <li>OpenFile &ndash; <a name="index122"></a>Equivalent to the File:Open menu
90 item. Opens an existing Lisp or SAL program file for editing and loading.</li>
91 <li>SaveFile &ndash; <a name="index123"></a>Equivalent to the File:Save menu
92 item (found on the editing window's menu bar). Saves the contents
93 of an editing window to its associated file.</li>
94 <li>Load &ndash; <a name="index124"></a>Equivalent to the File:Load menu
95 item (found on the editing window's menu bar). Performs a Save operation,
96 then sends a command to Nyquist that loads the file as a program.</li>
97 <li>Mark &ndash; <a name="index125"></a>Sends a Control-A to Nyquist. While
98 playing a sound, this displays and records the approximate time in the
99 audio stream. (See Section <a href = "part8.html#100">Sound File Input and Output</a> for more detail.)
100 </li></ul></p>
101 <a name = "21"><h3>Command Completion</h3></a>
102 <p>To help with programming, NyquistIDE maintains a command-completion window.
103 As you type the first letters of function names, NyquistIDE lists matching
104 functions and their parameters in the Completion List window. If you click
105 on an entry in this window, the displayed expression will replace the
106 incompletely typed function name. A preference allows you to match initial
107 letters or any substring of the complete function name. This is controlled
108 by the &ldquo;Use full search for code completion&rdquo; preference.</p>
109
110 <p>In addition, if you right click (or under macOS, hold down the
111 Alt/Option key and click) on an entry, NyquistIDE will display
112 documentation for the function. Documentation can come from a local
113 copy or from the online copy (determined by the &ldquo;Use online manual
114 instead of local copy&rdquo; preference). Documentation can be displayed
115 within the NyquistIDE window or in an external browser (determined by
116 the &ldquo;Use window in NyquistIDE for help browser&rdquo; preference.)
117 Currently, the external browser option does not seem to locate
118 documentation properly, but this should be fixed in the future.</p>
119 <a name = "22"><h3>Extension Manager</h3></a>
120 <p>The NyquistIDE Extension Manager is a facility to download extensions that
121 are written in Lisp or SAL. (If you want to extend the nyquist program itself
122 or the NyquistIDE program, you will have to write C or Java respectively and
123 recompile. See Appendix <a href = "part17.html#207">Appendix 1: Extending Nyquist</a> for information on writing new
124 DSP functions, also known as unit generators.)</p>
125
126 <p>Selecting the Extension Manager item in the Window menu will open a window
127 in the NyquistIDE with a list of extensions. Each extension is stored as
128 a subdirectory of the <code>lib</code> directory, which should be on the search
129 path (<code>XLISPPATH</code>) for <code>nyquist</code>. A list of extensions is hosted
130 in a fixed location
131 (<code>https://www.cs.cmu.edu/~music/nyquist/extensions/extlist.txt</code>)
132 along with secure checksums to guard against malicious code.</p>
133
134 <p>When you install an extension, a single file is first downloaded
135 using a URL that is obtained from the list of extensions, and the file
136 is scanned for a header that can specify additional files to download.</p>
137
138 <p>Some special files may be included in an extension. <code>autoload.lsp</code> is
139 a Lisp file that is loaded automatically when nyquist is started. Nyquist
140 scans the subdirectories of the <code>lib</code> directory to find all the
141 <code>autoload.lsp</code> files. Typically, <code>autoload.lsp</code> files are used
142 to create stubs for functions in the extensions so that extension
143 code is mostly loaded dynamically on demand, saving time and space when
144 nyquist starts.</p>
145
146 <p>Extensions may also include <code>nyquistwords.txt</code>, which is a description
147 of functions in the extensions that is used to generate the completion list.
148 When an extension function appears in the completion list, it is followed by
149 "ext:" and the extension name, e.g. the completion item
150 "speed-dial(list) ext: dtmf" means that the <code>speed-dial</code> function is
151 defined in the <code>dtmf</code> directory. By convention, any function in the
152 completion list should be directly callable, with an entry in
153 <code>autoload.lsp</code> so that the function will be dynamically loaded.</p>
154
155 <p>To create a new extension, see the extension <code>ext-template1</code> for an
156 example with documentation in HTML, or <code>ext-template2</code> for a simple
157 single-file extension where the documentation consists of comments in the
158 SAL source file. </p>
159
160 <p>To submit an extension for possible publication, it is best to put the
161 extension file(s) in a local directory and use a customized local list of
162 extensions. The Nyquist Preferences includes a button where you can designate
163 a local file for the list of extensions. It should have the same format
164 as <code>extlist.txt</code> at the URL given above (you can simply open the URL
165 in your browser to see it. The extension under development
166 can be referenced in the extension list using a URL with the <code>file://</code>
167 protocol. For the checksum, use any value. The Extension Manager will compute
168 the correct checksum and display it, so you can then copy that into your
169 <code>extlist.txt</code>, click the Update button to fetch it, and try again to
170 install the extension.</p>
171 <a name = "23"><h3>Browser</h3></a><a name="index126"></a><a name="index127"></a>
172 <p>If you click on the Browse button or use the Window:Browse menu command,
173 NyquistIDE will display a browser window that is pre-loaded with a number of
174 Nyquist commands to create sounds. You can adjust parameters, audition
175 the sounds, and capture the expression that creates the sound. In many
176 cases, the expression checks to see if necessary functions are defined,
177 loading files if necessary before playing the sound. If you want to use
178 a sound in your own program, you can often simplify things by explicitly
179 loading the required file just once at the beginning of your file.</p>
180
181 <p>Since Nyquist now supports a mix of Lisp and SAL, you may find yourself in
182 the position of having code from the browser in one language while you are
183 working in the other. The best way to handle this is to put the code for
184 the sound you want into a function defined in a Lisp (<code>.lsp</code>) or SAL
185 (<code>.sal</code>) file. Load the file (from Lisp, use the <code>sal-load</code>
186 command to load a SAL file), and call the function from the language of
187 your choice.</p>
188 <a name = "24"><h3>Envelope Editor</h3></a><a name="index128"></a><a name="index129"></a><a name="index130"></a>
189 <p>The envelope editor allows you graphically to design and edit piece-wise
190 linear and exponential envelopes. The editor maintains a list of envelopes
191 and you select the one to edit or delete using the drop down list in the
192 Saved Envelopes List area. The current envelope appears in the Graphical
193 Envelope Editor area. You can click to add or drag points. Alternatively,
194 you can use the Envelope Points window to select and edit any breakpoint
195 by typing coordinates. The duration of the envelope is controlled by the
196 Stop field in the Range area, and the vertical axis is controlled by the
197 Min and Max fields.</p>
198
199 <p>When you click the Save button, <i>all</i> envelopes are written to Nyquist.
200 You can then use the envelope by treating the envelope name as a function.
201 For example, if you define an envelope named &ldquo;fast-attack,&rdquo; then you
202 can create the envelope within a Nyquist SAL program by writing
203 the expression <code>fast-attack()</code>.</p>
204
205 <p>These edited envelopes are saved to a file named <code>workspace.lsp</code>
206 <a name="index131"></a> in
207 the current directory. The workspace is Nyquist's mechanism for saving
208 data of all kinds (see Section <a href = "part15.html#183">Workspaces</a>). The normal way to
209 work with workspaces is to (1) load the workspace, i.e.
210 <code>load "workspace"</code>, as soon as you start Nyquist; (2) invoke
211 the envelope editor to change values in the workspace; and (3) save the
212 workspace at any time, especially before you exit NyquistIDE. If you follow
213 these steps, envelopes will be preserved from session to session, and
214 the entire collection of envelopes will appear in the editor. Be
215 sure to make backups of your <code>workspace.lsp</code> file along with your
216 other project files.</p>
217
218 <p>The envelope editor can create linear and exponential envelopes. Use the
219 Type pull-down menu to select the type you want. Envelopes can be created
220 using default starting and ending values using <code>pwl</code> or <code>pwe</code>,
221 or you can specify the initial values using <code>pwlv</code> or <code>pwev</code>.
222 The envelope editor uses <code>pwl</code> or <code>pwe</code> if no point is explicitly
223 entered as the initial or final point. To create a <code>pwlv</code> or <code>pwev</code>
224 function, create a point and drag it to the leftmost or rightmost edge
225 of the graphical editing window. You will see the automatically
226 generated default starting or ending
227 point disappear from the graph.</p>
228
229 <p>Exponential envelopes should never decay to zero. If you enter a zero
230 amplitude, you will see that the envelope remains at zero to the next
231 breakpoint. To get an exponential decay to &ldquo;silence,&rdquo; try using an
232 amplitude of about 0.001 (about -60dB). To enter small values like
233 this, you can type them into the Amplitude box and click &ldquo;Update Point.&rdquo;</p>
234
235 <p>The Load button refreshes the editor from data saved in the Nyquist
236 process. Normally, there is no need to use this because the editor
237 automatically loads data when you open it.</p>
238 <a name = "25"><h3>Equalizer Editor</h3></a><a name="index132"></a><a name="index133"></a>
239 <p>The Equalizer Editor provides a graphical EQ interface for creating and
240 adjusting equalizers. Unlike the envelope editor, where you can type
241 any envelope name, equalizers are named <code>eq-0</code>, <code>eq-1</code>, etc.,
242 and you select the equalizer to edit using a pull-down menu. The <code>Set</code>
243 button should be use to record changes. </p>
244 <a name = "26"><h3>UPIC Editor</h3></a><a name="index134"></a><a name="index135"></a><a name="index136"></a>
245 <p>The
246 UPIC Editor is inspired by the UPIC system by Iannis Xenakis at the Centre
247 d'Edudes de Mathematique et Automatique Musicales (CEMaMu). The UPIC Editor
248 is accessed by the &ldquo;Upic Edit&rdquo; menu item in the &ldquo;Window&rdquo; menu of the
249 NyquistIDE. Once opened, you can draw pitch contours in the main panel by
250 pressing the left mouse button and dragging with the mouse down. Contours
251 represent tones in a frequency vs. time coordinate system. Any contour can be
252 deleted by right-clicking (or shift-clicking on an Apple computer) to
253 select the contour (indicated by the color red), and typing the Delete key.</p>
254
255 <p>A collection of contours can be saved to a file and later retrieved using the
256 items in the File menu (use the File menu in the UPIC Editor window, not in
257 the main NyquistIDE window.) The file is a SAL program in a special format
258 that can be parsed by the UPIC Editor. The file can also be loaded
259 into Nyquist using the File:Load menu item, or by executing a load command
260 in Nyquist.</p>
261
262 <p>The panel at the top of the editor offers control over various parameters.
263 The Name box is a Nyquist variable name. This name takes effect when you
264 save a file from the UPIC Editor. The variable name is stored in the
265 file so that when a UPIC Editor-generated file
266 is loaded into Nyquist, the data is assigned to this variable name.
267 The data is
268 a list of contours, where each contour specifies a waveform, an envelope,
269 and a list of time-frequency coordinates.</p>
270
271 <p>The next item in the panel is the Waveform box. The Waveform box names a
272 waveform for a contour. Default waveforms are sinusoid, triangle, and
273 sawtooth, but you can type in your own names. The currently selected
274 waveform is stored with the contour when it is created (entered by
275 drawing). You cannot change or edit the waveform name associated with
276 a contour once the contour is created, but you can always delete the
277 contour and replace it. The Envelope box names an envelope for a
278 contour. The envelope names a Nyquist function. The default, <code>upic-env</code>
279 is a trapezoid shape with an onset time and offset time of 10ms. As with
280 waveforms, the envelope is stored with each contour when the contour is
281 created and cannot be edited.</p>
282
283 <p>The Stop Time box gives the duration of the drawing area in seconds.
284 The Min Freq box gives the minimum frequency (at the bottom of the
285 drawing area), and the Max Freq box gives the maximum frequency (at the
286 top of the drawing area). The vertical frequency axis can use a linear
287 scale corresponding to frequency in Hertz or a logarithmic scale
288 corresponding to semitones. The &ldquo;linear&rdquo; checkbox selects the linear
289 scale. When <i>any</i> of these parameters (described in this paragraph and
290 delimited by the border labeled &ldquo;Range&rdquo; on the control panel) is changed,
291 you must press the Update Range button for the change to take effect.</p>
292
293 <p>The Background menu lets you display a grid that indicates pitch locations.
294 The &ldquo;C's&rdquo; item draws a line at C in every visible octave. E.g. middle C
295 is about 260 Hz, so a reference line will be drawn near 260 Hz.
296 Lines will be drawn around 130 Hz (an octave below middle C), and around
297 520 Hz (an octave above middle C), etc. The &ldquo;GrandStaff&rdquo; menu item
298 draws reference lines for each line of the grand staff commonly used
299 for piano music. The pitches are G2, B2, D3, F3, A3, E4, G4, B4, D5, and
300 F5. Finally, you can load a picture using the
301 Background:Load Picture... menu item. Then, the Background:Show Picture
302 menu item toggles whether the picture is displayed or not. This feature
303 allows you to trace an image. (For example, see the Sonic Self-Portrait
304 at <code>http://www.cs.cmu.edu/~rbd</code>.) You may wish to use an image editor
305 to lighten the image so that superimposed contours will be more visible.</p>
306
307 <p>Each change to the Range data, background choice, and each entry of a
308 contour is an action that you can undo or redo with the Undo and Redo
309 buttons.</p>
310
311 <p>To convert UPIC data into sound, first load <code>upic.sal</code> and load
312 a file generated by the UPIC Editor. Now, suppose the variable name
313 used is <code>upicdata</code>. You can play the data by writing
314 </p>
315 <pre>
316 play upic(upicdata)
317 </pre>
318
319 <p>
320 If you created your own names for waveforms or envelopes, you must be
321 sure that these exist before calling the <code>upic</code> function. Each
322 waveform must be the name of a variable which is set to a Nyquist
323 wave table. (See Section <a href = "part2.html#11">Non-Sinusoidal Waveforms</a> for information on how
324 to create a wave table.) Also, each envelope must name a function with
325 no parameters that will return an amplitude envelope. The following is
326 the built-in definition for <code>upic-env</code>:
327 </p>
328 <pre>
329 define function upic-env()
330 return env(0.01, 0.01, 0.01, 1, 1, 1)
331 </pre>
332
333 <p>
334 To make a custom envelope function named <code>upic-smooth</code> with a 0.2
335 second attack and a 0.3 second decay, you could write:
336 </p>
337 <pre>
338 define function upic-smooth()
339 return env(0.2, 0.01, 0.3, 1, 1, 1)
340 </pre>
341
342 <p></p>
343 <hr>
344 <a href = "part2.html">Previous Section</a> | <a href = "part4.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
345 </body></html>