From 017915d5b624f482ccdc4b15a5b311a9e85f93c2 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Mon, 13 Jan 2020 12:46:34 -0600 Subject: [PATCH] Reapply local changes to Nyquist runtime commit 48b6a9a8594c072de0849f33ad554e7f60980bb4 Author: Steve Daulton 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 f99d564fd6dbddfa995ff16ae18aef3429aee2ed Author: Steve Daulton Date: Tue Jul 2 15:02:00 2019 +0100 Fix bug 2148 Ensure that backslashes in GetInfo data are escaped. commit 5a7b6a7323a12591f79176588581e7dd84a49038 Author: Steve Daulton 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 26e19bfd5a2485aaa8aa1554b9d45c248b4c134b Author: Steve Daulton 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 46a3f91d5946a0248631d590a05073911f7f87cc Author: Steve Daulton Date: Mon Oct 29 15:20:36 2018 +0000 Add some useful path definitions for Nyquist commit 37ec7da3c33efbd7e804b59e8b3cbfec8ece8b8e Author: Steve Daulton Date: Thu Oct 11 02:43:07 2018 +0100 Throw error if Nyquist *LOCALE* is malformed Partial translations are allowed. commit 297bf442a45b4e7fd7831a35102585ac2d50cbc3 Author: Steve Daulton Date: Tue Oct 9 01:13:48 2018 +0100 Fix typo in 665e2d0 commit 665e2d0e9c72335911a8572393d0b30ee38b1662 Author: Steve Daulton 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 5d34d022a5cc7c4efa631a3a815121584dd2e9c6 Author: Steve Daulton 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 ae2bbb327613ed35ddc1e37d5f9fd443180b06c2 Author: Steve Daulton 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 367d15a0b0695f0aa29bc4500c6702bd17c3ce6f Author: Steve Daulton 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 504cf0fe8553a60aee5557e820c43ca6aa51a47a Author: Steve Daulton 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). --- nyquist/init.lsp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/nyquist/init.lsp b/nyquist/init.lsp index e2b905c6c..5fc5cbc3c 100644 --- a/nyquist/init.lsp +++ b/nyquist/init.lsp @@ -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")