Skip to content

Commit 883aafe

Browse files
committed
Reapply local changes to Nyquist runtime
commit 48b6a9a Author: Steve Daulton <SteveDaulton@users.noreply.github.com> Date: Wed Dec 18 20:28:04 2019 +0000 Update init.lsp *NYQ-PATH* is not required (and not currently used). Use *RUNTIME-PATH* instead (already defined in Nyquist, but not previously documented). commit f99d564 Author: Steve Daulton <stevedaulton@gmail.com> Date: Tue Jul 2 15:02:00 2019 +0100 Fix bug 2148 Ensure that backslashes in GetInfo data are escaped. commit 5a7b6a7 Author: Steve Daulton <stevedaulton@gmail.com> Date: Thu Dec 27 19:44:05 2018 +0000 Fix multiple selection Nyquist file widget Wx "Style" flags are 4 bytes, not 1 byte. Also update a couple of comments in passing. commit 26e19bf Author: Steve Daulton <stevedaulton@gmail.com> Date: Fri Nov 9 16:35:37 2018 +0000 Add aud-do-support.lsp for Linux build Provides Nyquist (LISP) wrapper functions for macro "Commands". commit 46a3f91 Author: Steve Daulton <stevedaulton@gmail.com> Date: Mon Oct 29 15:20:36 2018 +0000 Add some useful path definitions for Nyquist commit 37ec7da Author: Steve Daulton <stevedaulton@gmail.com> Date: Thu Oct 11 02:43:07 2018 +0100 Throw error if Nyquist *LOCALE* is malformed Partial translations are allowed. commit 297bf44 Author: Steve Daulton <stevedaulton@gmail.com> Date: Tue Oct 9 01:13:48 2018 +0100 Fix typo in 665e2d0 commit 665e2d0 Author: Steve Daulton <stevedaulton@gmail.com> Date: Tue Oct 9 01:04:05 2018 +0100 Correction to translation of rms.ny Update Russian translation in rms.ny and make variables local to underscore function. commit 5d34d02 Author: Steve Daulton <stevedaulton@gmail.com> Date: Sun Oct 7 18:40:41 2018 +0100 Add rms.ny to Audacity bundle Tidy translation code in init.lsp Include rms.ny in Makefile.am Add rms.ny to Linux package Update Makefiles with: autoreconf --force --no-recursive Add rms.ny to mac build Add rms.ny to Windows build commit ae2bbb3 Author: Steve Daulton <stevedaulton@gmail.com> Date: Mon Sep 3 16:57:06 2018 +0100 AUD-GET-INFO function added to init.lsp Provide built-in Nyquist function to call scripting command GetInfo, and return result as LISP list. commit 367d15a Author: Steve Daulton <stevedaulton@gmail.com> Date: Sun Aug 26 20:07:47 2018 +0100 Add a couple of helpers for parsing string Provides a convenient function and macro, intended specifically for parsing strings returned by (aud-do "GetInfo: ... commit 504cf0f Author: Steve Daulton <stevedaulton@gmail.com> Date: Sun May 6 17:08:12 2018 +0100 Runtime translation for 3rd party Nyquist plug-ins 3rd party plug-ins may provide their own translations for runtime messages (return strings and debug messages).
1 parent 586b86a commit 883aafe

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

nyquist/init.lsp

+78
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,81 @@
88

99
; (load "test.lsp")
1010

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

0 commit comments

Comments
 (0)