Skip to content

Commit e6c1a89

Browse files
committed
Update Nyquist runtime to r288
Totally forgot about these when upgrading Nyquist to r288.
1 parent 69ee0a8 commit e6c1a89

18 files changed

+3276
-1447
lines changed

nyquist/dspprims.lsp

+263-107
Large diffs are not rendered by default.

nyquist/envelopes.lsp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; envelopes.lsp -- support functions for envelope editor in jNyqIDE
1+
;; envelopes.lsp -- support functions for envelope editor in NyquistIDE
22

33
#| In Nyquist, editable envelopes are saved as one entry in the workspace
44
named *envelopes*. The entry is an association list where each element
@@ -18,7 +18,7 @@ To convert envelope data into functions, call (MAKE-ENV-FUNCTIONS).
1818
This function should be on the workspace's list of functions to call.
1919
(See ADD-ACTION-TO-WORKSPACE in Nyquist Manual.)
2020
21-
When the jNyqIDE wants to get the envelope data from the workspace, it
21+
When the NyquistIDE wants to get the envelope data from the workspace, it
2222
should call (GET-ENV-DATA), which will dump formatted data to Nyquist's
2323
standard output as follows:
2424
@@ -119,7 +119,7 @@ Saving the workspace automatically is something that Nyquist should do
119119
(make-env-function name expression)
120120
; make sure envelopes are redefined when workspace is loaded
121121
(add-to-workspace '*envelopes*) ; so *envelopes* will be saved
122-
(describe '*envelopes* "data for envelope editor in jNyqIDE")
122+
(describe '*envelopes* "data for envelope editor in NyquistIDE")
123123
(add-action-to-workspace 'make-env-functions)
124124
nil)
125125

nyquist/fileio.lsp

+62-40
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
(cond ((equal *default-sf-dir* "") (setf *default-sf-dir* path))))
3434

3535
;; s-save -- saves a file
36+
(setf *in-s-save* nil)
3637
(setf NY:ALL 1000000000) ; 1GIG constant for maxlen
3738
(defmacro s-save (expression &optional (maxlen NY:ALL) filename
3839
&key (format '*default-sf-format*)
@@ -42,27 +43,47 @@
4243
`(let ((ny:fname ,filename)
4344
(ny:maxlen ,maxlen)
4445
(ny:endian ,endian)
45-
(ny:swap 0))
46-
; allow caller to omit maxlen, in which case the filename will
47-
; be a string in the maxlen parameter position and filename will be null
48-
(cond ((null ny:fname)
49-
(cond ((stringp ny:maxlen)
50-
(setf ny:fname ny:maxlen)
51-
(setf ny:maxlen NY:ALL))
52-
(t
53-
(setf ny:fname *default-sound-file*)))))
46+
(ny:swap 0)
47+
max-sample) ; return value
48+
(cond (*in-s-save*
49+
(error "Recursive call to s-save (maybe play?) detected!")))
50+
(progv '(*in-s-save*) '(t)
51+
; allow caller to omit maxlen, in which case the filename will
52+
; be a string in the maxlen parameter position and filename will be null
53+
(cond ((null ny:fname)
54+
(cond ((stringp ny:maxlen)
55+
(setf ny:fname ny:maxlen)
56+
(setf ny:maxlen NY:ALL))
57+
(t
58+
(setf ny:fname *default-sound-file*)))))
5459

55-
(cond ((equal ny:fname "")
56-
(cond ((not ,play)
57-
(format t "s-save: no file to write! play option is off!\n"))))
58-
(t
59-
(setf ny:fname (soundfilename ny:fname))
60-
(format t "Saving sound file to ~A~%" ny:fname)))
61-
(cond ((eq ny:endian :big)
62-
(setf ny:swap (if (bigendianp) 0 1)))
63-
((eq ny:endian :little)
64-
(setf ny:swap (if (bigendianp) 1 0))))
65-
(snd-save ',expression ny:maxlen ny:fname ,format ,mode ,bits ny:swap ,play)))
60+
(cond ((equal ny:fname "")
61+
(cond ((not ,play)
62+
(format t "s-save: no file to write! play option is off!\n"))))
63+
(t
64+
(setf ny:fname (soundfilename ny:fname))
65+
(format t "Saving sound file to ~A~%" ny:fname)))
66+
(cond ((eq ny:endian :big)
67+
(setf ny:swap (if (bigendianp) 0 1)))
68+
((eq ny:endian :little)
69+
(setf ny:swap (if (bigendianp) 1 0))))
70+
; print device info the first time sound is played
71+
(cond (,play
72+
(cond ((not (boundp '*snd-list-devices*))
73+
(setf *snd-list-devices* t))))) ; one-time show
74+
(setf max-sample
75+
(snd-save ',expression ny:maxlen ny:fname ,format
76+
,mode ,bits ny:swap ,play))
77+
; more information if *snd-list-devices* was unbound:
78+
(cond (,play
79+
(cond (*snd-list-devices*
80+
(format t "\nSet *snd-list-devices* = t\n~A\n~A\n~A\n~A\n\n"
81+
" and call play to see device list again."
82+
"Set *snd-device* to a fixnum to select an output device"
83+
" or set *snd-device* to a substring of a device name"
84+
" to select the first device containing the substring.")))
85+
(setf *snd-list-devices* nil))) ; normally nil
86+
max-sample)))
6687

6788
;; MULTICHANNEL-MAX -- find peak over all channels
6889
;;
@@ -217,21 +238,21 @@
217238
(local-to-global 0) format nchans mode bits swap srate
218239
dur)))
219240

241+
220242
;; SF-INFO -- print sound file info
221243
;;
222244
(defun sf-info (filename)
223245
(let (s format channels mode bits swap srate dur flags)
224246
(format t "~A:~%" (soundfilename filename))
225247
(setf s (s-read filename))
226-
(setf format (car *rslt*))
227-
(setf channels (cadr *rslt*))
228-
(setf mode (caddr *rslt*))
229-
(setf bits (cadddr *rslt*))
230-
(setf *rslt* (cddddr *rslt*))
231-
(setf swap (car *rslt*))
232-
(setf srate (cadr *rslt*))
233-
(setf dur (caddr *rslt*))
234-
(setf flags (cadddr *rslt*))
248+
(setf format (snd-read-format *rslt*))
249+
(setf channels (snd-read-channels *rslt*))
250+
(setf mode (snd-read-mode *rslt*))
251+
(setf bits (snd-read-bits *rslt*))
252+
; (setf swap (snd-read-swap *rslt*))
253+
(setf srate (snd-read-srate *rslt*))
254+
(setf dur (snd-read-dur *rslt*))
255+
(setf flags (snd-read-flags *rslt*))
235256
(format t "Format: ~A~%"
236257
(nth format '("none" "AIFF" "IRCAM" "NeXT" "Wave" "PAF" "SVX"
237258
"NIST" "VOC" "W64" "MAT4" "Mat5" "PVF" "XI" "HTK"
@@ -290,14 +311,15 @@
290311
filename)
291312

292313

293-
(setfn s-read-format car)
294-
(setfn s-read-channels cadr)
295-
(setfn s-read-mode caddr)
296-
(setfn s-read-bits cadddr)
297-
(defun s-read-swap (rslt) (car (cddddr rslt)))
298-
(defun s-read-srate (rslt) (cadr (cddddr rslt)))
299-
(defun s-read-dur (rslt) (caddr (cddddr rslt)))
300-
(defun s-read-byte-offset (rslt) (car (cddddr (cddddr rslt))))
314+
(setfn snd-read-format car)
315+
(setfn snd-read-channels cadr)
316+
(setfn snd-read-mode caddr)
317+
(setfn snd-read-bits cadddr)
318+
(defun snd-read-swap (rslt) (car (cddddr rslt)))
319+
(defun snd-read-srate (rslt) (cadr (cddddr rslt)))
320+
(defun snd-read-dur (rslt) (caddr (cddddr rslt)))
321+
(defun snd-read-flags (rslt) (cadddr (cddddr rslt)))
322+
(defun snd-read-byte-offset (rslt) (cadr (cddddr (cddddr rslt))))
301323

302324
;; round is tricky because truncate rounds toward zero as does C
303325
;; in other words, rounding is down for positive numbers and up
@@ -328,7 +350,7 @@
328350
:time-offset ny:offset)
329351
ny:addend)
330352
ny:addend))
331-
,maxlen ny:fname ny:offset SND-HEAD-NONE 0 0 0 0.0))
353+
,maxlen ny:fname ny:offset SND-HEAD-NONE 0 0 0))
332354
(format t "Duration written: ~A~%" (car *rslt*))
333355
ny:peak))
334356

@@ -338,9 +360,9 @@
338360
(ny:peak 0.0)
339361
ny:input ny:rslt (ny:offset ,time-offset))
340362
(format t "Overwriting ~A at offset ~A~%" ny:fname ny:offset)
341-
(setf ny:offset (s-read-byte-offset ny:rslt))
363+
(setf ny:offset (snd-read-byte-offset ny:rslt))
342364
(setf ny:peak (snd-overwrite `,expr ,maxlen ny:fname ny:offset
343-
SND-HEAD-NONE 0 0 0 0.0))
365+
SND-HEAD-NONE 0 0 0))
344366
(format t "Duration written: ~A~%" (car *rslt*))
345367
ny:peak))
346368

nyquist/follow.lsp

-70
This file was deleted.

nyquist/init.lsp

-78
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,3 @@
66

77
; (load "test.lsp")
88

9-
10-
11-
;; "_" (UNDERSCORE) - translation function
12-
;;
13-
;; Third party plug-ins are not translated by gettext in Audacity, but may include a
14-
;; list of translations named *locale*. The format of *locale* must be:
15-
;; (LIST (language-list) [(language-list) ...])
16-
;; Each language-list is an a-list in the form:
17-
;; ("cc" ((list "string" "translated-string") [(list "string" "translated-string") ...]))
18-
;; where "cc" is the quoted country code.
19-
;;
20-
(setfn underscore _)
21-
;;
22-
(defun _(txt &aux newtxt)
23-
(when (boundp '*locale*)
24-
(when (not (listp *locale*))
25-
(error "bad argument type" *locale*))
26-
(let* ((cc (get '*audacity* 'language))
27-
(translations (second (assoc cc *locale* :test 'string-equal))))
28-
(if translations
29-
(let ((translation (second (assoc txt translations :test 'string=))))
30-
(if translation
31-
(if (stringp translation)
32-
(setf newtxt translation)
33-
(error "bad argument type" translation))
34-
(format t "No ~s translation of ~s.~%" cc txt)))
35-
(progn
36-
(setf *locale* '*unbound*)
37-
(format t "No ~s translations.~%" cc)))))
38-
(if newtxt newtxt (underscore txt)))
39-
40-
41-
;;; Some helpers for parsing strings returned by (aud-do "GetInfo: ...
42-
43-
(defun eval-string (string)
44-
;;; Evaluate a string as a LISP expression.
45-
;;; If 'string' is not a valid LISP expression, the behaviour is undefined.
46-
(eval (read (make-string-input-stream string))))
47-
48-
(defmacro quote-string (string)
49-
;;; Prepend a single quote to a string
50-
`(setf ,string (format nil "\'~a" ,string)))
51-
52-
(defun aud-get-info (str)
53-
;;; Return "GetInfo: type=type" as Lisp list, or throw error
54-
;;; Audacity 2.3.0 does not fail if type is not recognised, it
55-
;;; falls back to a default, so test for valid types.
56-
;;; 'Commands+' is not supported in Audacity 2.3.0
57-
(let (type
58-
info
59-
(types '("Commands" "Menus" "Preferences"
60-
"Tracks" "Clips" "Envelopes" "Labels" "Boxes")))
61-
;Case insensitive search, then set 'type' with correct case string, or NIL.
62-
(setf type (first (member str types :test 'string-equal)))
63-
(if (not type)
64-
(error (format nil "bad argument '~a' in (aud-get-info ~a)" str str)))
65-
(setf info (aud-do (format nil "GetInfo: type=~a format=LISP" type)))
66-
(if (not (last info))
67-
(error (format nil "(aud-get-info ~a) failed.~%" str)))
68-
(let* ((info-string (first info))
69-
(sanitized ""))
70-
;; Escape backslashes
71-
(dotimes (i (length info-string))
72-
(setf ch (subseq info-string i (1+ i)))
73-
(if (string= ch "\\")
74-
(string-append sanitized "\\\\")
75-
(string-append sanitized ch)))
76-
(eval-string (quote-string sanitized)))))
77-
78-
79-
;;; *NYQ-PATH* is not required as path to Nyquist .lsp files
80-
;;; is already defined (but not previously documented) as *runtime-path*
81-
;;(setf *NYQ-PATH* (current-path))
82-
83-
;;; Load wrapper functions for aud-do commands.
84-
;;; If commented out, "aud-do-support.lsp" may be loaded by a plug-in.
85-
;;; Example: (lisp-loader (strcat *runtime-path* "aud-do-support.lsp"))
86-
(load "aud-do-support.lsp")

nyquist/misc.lsp

+42-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
; Typically, you want this on.
4343
; *xlisp-traceback* -- print XLISP traceback on error in XLISP mode
4444
; Typically, you do not want this because the full
45-
; stack can be long and tedious.
45+
; stack can be long and tedious. Also allow XLISP
46+
; traceback in SAL mode if *sal-break* is true.
4647

4748
(setf *sal-mode* nil)
4849

@@ -192,3 +193,43 @@
192193
;; search for either .lsp or .sal file
193194
(sal-load ,file-name)))
194195

196+
;; COMPUTE-DEFAULT-SOUND-FILE -- construct and set *default-sound-file*
197+
;;
198+
;; (this is harder than it might seem because the default place for
199+
;; sound files is in /tmp, which is shared by users, so we'd like to
200+
;; use a user-specific name to avoid collisions)
201+
;;
202+
(defun compute-default-sound-file ()
203+
(let (inf user extension)
204+
; the reason for the user name is that if UserA creates a temp file,
205+
; then UserB will not be able to overwrite it. The user name is a
206+
; way to give each user a unique temp file name. Note that we don't
207+
; want each session to generate a unique name because Nyquist doesn't
208+
; delete the sound file at the end of the session.
209+
(setf user (get-user))
210+
#|
211+
(cond ((null user)
212+
(format t
213+
"Please type your user-id so that I can construct a default
214+
sound-file name. To avoid this message in the future, add
215+
this to your .login file:
216+
setenv USER <your id here>
217+
or add this to your init.lsp file:
218+
(setf *default-sound-file* \"<your filename here>\")
219+
(setf *default-sf-dir* \"<full pathname of desired directory here>\")
220+
221+
Your id please: ")
222+
(setf user (read))))
223+
|#
224+
; now compute the extension based on *default-sf-format*
225+
(cond ((= *default-sf-format* snd-head-AIFF)
226+
(setf extension ".aif"))
227+
((= *default-sf-format* snd-head-Wave)
228+
(setf extension ".wav"))
229+
(t
230+
(setf extension ".snd")))
231+
(setf *default-sound-file*
232+
(strcat (string-downcase user) "-temp" extension))
233+
(format t "Default sound file is ~A.~%" *default-sound-file*)))
234+
235+

0 commit comments

Comments
 (0)