Switching between different functions

I’m trying to write a Nyquist plugin to switch between effect 0 and effect 1. Here is the code

;nyquist plug-in
;version 1
;type process
;name “Flip Sound”
;action “Flipping…”
;info “Flip Frequency-Based or Sample-Based Sounds Upside-Down.”

;control text “Spectrum Or Waveform?”
;control md “Flip this” int “0=Frequency 1=Waveform” 0 0 1
;control text “We currently do not support different scales, reverse, time-and-frequency swapping or frequency-analysis.”
;control text “This plugin was a pain-in-the-butt to make, and took all night. Please, enjoy it. Until help is made, you could try using a different program to…”
;control text “1. Flip semitones, like Frequency Spectrum, except frequencies are set in musical notes”
;control text “2. Flip time, play in reverse”
;control text “3. Swap time and frequency, turn spectrum so Horizontal and Vertical is reversed”
;control text “4. Flip frequency analysis, turn spectrum in negative”

;effect 0
(lowpass6 (mult 1 (highpass6 S 20) (hzosc 20000)) 20000)
;effect 1
(mult S -1)

Hi Winston, and welcome to the forum. I guess you’re the guy I wrote to on facebook?


To switch between effect 0 and effect 1, you need to do something like this:

(if something-is-true
    (effect-0)
    (effect-1))

In the case of your code, I assume that you want “effect-0” when “md = 0” and “effect-1” when “md = 1”.

(if (= md 0)
    (effect-0)
    (effect-1))

Note that we don’t need to test if md = 1 because there are only two options.
The general syntax is:

(if <condition>
    (do-this)
    (else-do-this))

Some additional notes:


It is highly recommended to write all new code in the latest version syntax (version 4). The most obvious difference between version 4 and earlier versions is that Nyquist effects now use TRACK (or track) to access the selected audio. (previous versions used “S” for this purpose).
“S” was a poor choice in early versions of Audacity, because “S” could also represent the value 0.25 (as shown in the Nyquist manual: MIDI, Adagio, and Sequences)



In version 4 plug-ins, we have more types of control widgets available than just sliders.
For choice between Spectrum or Waveform, we can use a “choice” widget (see: Missing features - Audacity Support and Missing features - Audacity Support)

;control variable-name "text-left" choice "string-1,string-2,..." initial-value

Here’s all of the active parts of your code, updated to version 4:

;nyquist plug-in
;version 4
;type process
;name "Flip Sound"

;control md "Spectrum Or Waveform" choice "Spectrum,Waveform" 0

(if (= md 0)
    (lowpass6 (mult (highpass6 *track* 20) (hzosc 20000))
              20000)
    (mult *track* -1))

(I’ve removed the “mult 1” because multiplying by 1 does nothing)