Reapply local changes to Nyquist runtime

commit 48b6a9a859
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 f99d564fd6
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 5a7b6a7323
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 26e19bfd5a
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 46a3f91d59
Author: Steve Daulton <stevedaulton@gmail.com>
Date:   Mon Oct 29 15:20:36 2018 +0000

    Add some useful path definitions for Nyquist

commit 37ec7da3c3
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 297bf442a4
Author: Steve Daulton <stevedaulton@gmail.com>
Date:   Tue Oct 9 01:13:48 2018 +0100

    Fix typo in 665e2d0

commit 665e2d0e9c
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 5d34d022a5
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 ae2bbb3276
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 367d15a0b0
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 504cf0fe85
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).
This commit is contained in:
Leland Lucius 2020-01-13 12:46:34 -06:00
parent e6c1a89123
commit 017915d5b6
1 changed files with 78 additions and 0 deletions

View File

@ -6,3 +6,81 @@
; (load "test.lsp")
;; "_" (UNDERSCORE) - translation function
;;
;; Third party plug-ins are not translated by gettext in Audacity, but may include a
;; list of translations named *locale*. The format of *locale* must be:
;; (LIST (language-list) [(language-list) ...])
;; Each language-list is an a-list in the form:
;; ("cc" ((list "string" "translated-string") [(list "string" "translated-string") ...]))
;; where "cc" is the quoted country code.
;;
(setfn underscore _)
;;
(defun _(txt &aux newtxt)
(when (boundp '*locale*)
(when (not (listp *locale*))
(error "bad argument type" *locale*))
(let* ((cc (get '*audacity* 'language))
(translations (second (assoc cc *locale* :test 'string-equal))))
(if translations
(let ((translation (second (assoc txt translations :test 'string=))))
(if translation
(if (stringp translation)
(setf newtxt translation)
(error "bad argument type" translation))
(format t "No ~s translation of ~s.~%" cc txt)))
(progn
(setf *locale* '*unbound*)
(format t "No ~s translations.~%" cc)))))
(if newtxt newtxt (underscore txt)))
;;; Some helpers for parsing strings returned by (aud-do "GetInfo: ...
(defun eval-string (string)
;;; Evaluate a string as a LISP expression.
;;; If 'string' is not a valid LISP expression, the behaviour is undefined.
(eval (read (make-string-input-stream string))))
(defmacro quote-string (string)
;;; Prepend a single quote to a string
`(setf ,string (format nil "\'~a" ,string)))
(defun aud-get-info (str)
;;; Return "GetInfo: type=type" as Lisp list, or throw error
;;; Audacity 2.3.0 does not fail if type is not recognised, it
;;; falls back to a default, so test for valid types.
;;; 'Commands+' is not supported in Audacity 2.3.0
(let (type
info
(types '("Commands" "Menus" "Preferences"
"Tracks" "Clips" "Envelopes" "Labels" "Boxes")))
;Case insensitive search, then set 'type' with correct case string, or NIL.
(setf type (first (member str types :test 'string-equal)))
(if (not type)
(error (format nil "bad argument '~a' in (aud-get-info ~a)" str str)))
(setf info (aud-do (format nil "GetInfo: type=~a format=LISP" type)))
(if (not (last info))
(error (format nil "(aud-get-info ~a) failed.~%" str)))
(let* ((info-string (first info))
(sanitized ""))
;; Escape backslashes
(dotimes (i (length info-string))
(setf ch (subseq info-string i (1+ i)))
(if (string= ch "\\")
(string-append sanitized "\\\\")
(string-append sanitized ch)))
(eval-string (quote-string sanitized)))))
;;; *NYQ-PATH* is not required as path to Nyquist .lsp files
;;; is already defined (but not previously documented) as *runtime-path*
;;(setf *NYQ-PATH* (current-path))
;;; Load wrapper functions for aud-do commands.
;;; If commented out, "aud-do-support.lsp" may be loaded by a plug-in.
;;; Example: (lisp-loader (strcat *runtime-path* "aud-do-support.lsp"))
(load "aud-do-support.lsp")