Hello. I am new to using Nyquist/XLISP. I’ve read through the available documentation and am currently messing around with some of the .ny plugins.
When I use the Nyquist Prompt (current version of Audacity is 2.3.0) and try to enter a formula, I notice that it is selective in it’s output. I am not sure if there is a temp file somewhere that contains the full output.
For example, using an example from the documentation:
(defun foo ; define function FOO
(a b &optional c d &rest e) ; with some of each argument
(print a) (print b)
(print c) (print d) ; print out each
(foo) ; error: too few arguments
(foo 1) ; error: too few arguments
(foo 1 2) ; prints 1 2 NIL NIL NIL
(foo 1 2 3) ; prints 1 2 3 NIL NIL
(foo 1 2 3 4) ; prints 1 2 3 4 NIL
(foo 1 2 3 4 5) ; prints 1 2 3 4 (5)
If I then use this in the prompt:
(defun grav (x y &optional z)
(print x) (print y) (print z))
(grav 1 2 3)
… the output will be 3, instead of 1 2 3.
Thank you. I only program as a hobby, so I apologize if this is a simple problem. I will probably have more questions soon.
Nyquist is a separate program that has been shoehorned into Audacity. When you run a Nyquist script in Audacity, what happens is that Audacity passes the relevant code and data to Nyquist, then Nyquist runs the code and returns the final result back to Audacity (see this section about “return values”: https://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#Return_Values)
So in your case, the final result (the “return value”) is “3”, so that is what Audacity displays.
If you want to see the other printed values, use the Debug button rather than the “OK” button.
Oh God. I just had a lot of stuff typed out and it wiped it when it did the CAPTCHA.
I’m going to try this again. This is just how I interpret the code, please tell me where I am going wrong. I put my thoughts in comments behind semicolons.
(defun get-input (sig) ;Defines a function "get-input" with one formal parameter "sig".
"Preview takes the entire selection so that we know the correct
selection length, but preview only needs to process preview length." ;Not sure what this is. A comment? I tried deleting it and it seems to have no
(if (get '*track* 'view) ;NIL if preview ;special form if statement that looks for the value of the view property of the
;*track* global variable.
sig ;The "then" part of the if statement. sig is set to the value of 'view, unless it
; is Nil.
(multichan-expand #'trim-input sig))) ; The "else" part. sig is set to the value of the "trim-input" function which is part
; of the pre-defined function "multichan-expand.
I had more typed, so I’ll be back to re-do that in a few.
That’s about right. I’ll try to clarify a couple of things:
The string in the second line is just a comment. This is a feature that Nyquist has inherited from the LISP tradition.
In many dialects of Lisp, function definitions may include a “documentation string” (aka a “doc string”) as the first line in a function definition. When running the function, Lisp treats the doc string as a comment (ignores it) even though it is written without preceding semicolons. Other forms of Lisp have commands such as DESCRIBE and INSPECT that allow you to see a summary description of functions. Nyquist does not (currently) have any functions for reading doc strings, so in Nyquist a doc string is really no different from a normal comment. A description of doc strings in Emacs Lisp: https://www.emacswiki.org/emacs/DocString
Until (or “if”) Nyquist, or a Nyquist IDE, gets the ability to read doc strings, it is probably better to just use normal comments.
We now have a global variable previewp that is ‘true’/T when previewing, otherwise false’/NIL.
If I were writing that function today, I’d write it as:
(defun get-input (sig)
;;; Return trimmed sig when previewing, otherwise return sig.
(multichan-expand #'trim-input sig)
(multichan-expand #'trim-input sig)
multichan-expand is a function intended to make working with multi-channel sounds more convenient (Audacity currently supports mono or stereo).
You could read this line as saying:
for each channel in ‘sig’, apply the function ‘trim-input’