Switching between different functions

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Mac OS X
GNU/Linux and Unix-like
Post Reply
Posts: 56
Joined: Fri Aug 28, 2020 12:59 pm
Operating System: Windows 10

Switching between different functions

Post by Winston » Fri Aug 28, 2020 1:08 pm

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)
Last edited by steve on Fri Aug 28, 2020 1:45 pm, edited 1 time in total.
Reason: Topic split and given relevant title

Site Admin
Posts: 81314
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Switching between different functions

Post by steve » Fri Aug 28, 2020 2:10 pm

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:

Code: Select all

(if something-is-true
In the case of your code, I assume that you want "effect-0" when "md = 0" and "effect-1" when "md = 1".

Code: Select all

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

Code: Select all

(if <condition>


Some additional notes:

Winston wrote:
Fri Aug 28, 2020 1:08 pm
;version 1
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: https://www.cs.cmu.edu/~rbd/doc/nyquist ... l#index973)

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: https://wiki.audacityteam.org/wiki/Nyqu ... ce#widgets and https://wiki.audacityteam.org/wiki/Nyqu ... ice_Widget)

Code: Select all

;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:

Code: Select all

;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))
    (mult *track* -1))

(I've removed the "mult 1" because multiplying by 1 does nothing)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply