1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Nyquist: Only import built-in effects

Extreme slowdown has been reported when generating LISP
Functions for all scripting Commands, so only generate
LISP functions for built-in effects.
Additional LISP functions may be generated on demand
using (aud-import <command-name>).
This commit is contained in:
SteveDaulton 2020-02-11 20:00:03 +00:00
parent e0302257c5
commit 930e74dabc
2 changed files with 43 additions and 16 deletions

View File

@ -23,10 +23,9 @@
(defun aud-get-command (id) (defun aud-get-command (id)
;;; Return command signature from id string ;;; Return command signature from id string
(let ((all (aud-get-info "Commands"))) (let* ((helpstr (format nil "Help: Command=~s Format=LISP" id))
(dolist (cmd all) (cmd-sig (first (aud-do helpstr))))
(when (member (string id) (assoc 'id cmd) :test 'equal) (eval-string (quote-string cmd-sig))))
(return cmd)))))
(defun aud-import-command (command-sig &optional func-name) (defun aud-import-command (command-sig &optional func-name)
@ -87,12 +86,37 @@
(setf command \"" id ": \") (setf command \"" id ": \")
(dolist (p params) (dolist (p params)
(setf command (strcat command p))) (setf command (strcat command p)))
;(print command)
(aud-do command))") (aud-do command))")
(eval-string func-def))) (eval-string func-def)))
;;; Import all Audacity "Commands" as LISP functions (defun aud-import-commands ()
;;; Function names prefix the command id with "aud-". ;;; Import all Audacity "Commands" as LISP functions
(dolist (command (aud-get-info "Commands")) ;;; Function names prefix the command id with "aud-".
(aud-import-command command)) (dolist (command (aud-get-info "Commands"))
(aud-import-command command)))
(defun aud-import (id &optional func-name)
;;; Import one Command by ID.
;;; Example (aud-import "tone")
;;; Creates a function (aud-tone :frequency 440 :amplitude 0.8 :waveform "Sine")
(let ((cmd (aud-get-command id)))
(aud-import-command cmd func-name)))
(defun aud-import-effects ()
;;; Import built-in effect commands
(let ((common (list "Amplify" "AutoDuck" "BassAndTreble" "ChangePitch" "ChangeSpeed"
"ChangeTempo" "Chirp" "ClickRemoval" "Compressor" "DtmfTones"
"Distortion" "Echo" "FadeIn" "FadeOut" "FilterCurve" "FindClipping"
"GraphicEq" "Invert" "LoudnessNormalization" "Noise" "Normalize"
"Paulstretch" "Phaser" "Repeat" "Repair" "Reverb" "Reverse"
"Silence" "SlidingStretch" "Tone" "TruncateSilence" "Wahwah")))
(dolist (cmd common)
(aud-import cmd))))
(aud-import-effects)
;;; Uncomment the next line to load all "AUD-" commands.
;(aud-import-commands)

View File

@ -45,6 +45,15 @@
;;; If 'string' is not a valid LISP expression, the behaviour is undefined. ;;; If 'string' is not a valid LISP expression, the behaviour is undefined.
(eval (read (make-string-input-stream string)))) (eval (read (make-string-input-stream string))))
(defun escape-backslash (in-string)
;;; Escape backslashes
(let (ch (out-string ""))
(dotimes (i (length in-string) out-string)
(setf ch (subseq in-string i (1+ i)))
(if (string= ch "\\")
(string-append out-string "\\\\")
(string-append out-string ch)))))
(defmacro quote-string (string) (defmacro quote-string (string)
;;; Prepend a single quote to a string ;;; Prepend a single quote to a string
`(setf ,string (format nil "\'~a" ,string))) `(setf ,string (format nil "\'~a" ,string)))
@ -66,13 +75,7 @@
(if (not (last info)) (if (not (last info))
(error (format nil "(aud-get-info ~a) failed.~%" str))) (error (format nil "(aud-get-info ~a) failed.~%" str)))
(let* ((info-string (first info)) (let* ((info-string (first info))
(sanitized "")) (sanitized (escape-backslash info-string)))
;; 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))))) (eval-string (quote-string sanitized)))))