|
8 | 8 |
|
9 | 9 | ; (load "test.lsp")
|
10 | 10 |
|
| 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