Scripting Helper

Share your Audacity/Nyquist plug-ins here, or test drive the latest plug-ins submitted by Audacity users.

After testing a plug-in from this forum, please post feedback for the plug-in author.
Post Reply
steve
Site Admin
Posts: 48993
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Scripting Helper

Post by steve » Sat Oct 06, 2018 3:12 pm

Requires Audacity 2.3.0 or later.

The plug-in (bottom of post) is called "Scripting Helper..." and it was made primarily for experimenting and testing the new AUD-DO functions.
When installed, it will appear in the Tools menu.

Window000.png
Window000.png (20.21 KiB) Viewed 191 times

The plug-in performs 4 functions according to the "Command" setting.

Command: List All
Prints a list (sorted alphabetically) of all "Scriptable" commands.
Note that there are some valid scripting commands listed in https://alphamanual.audacityteam.org/ma ... _Reference that are not included in this list (for example "MidiDeviceInfo:". This is because they are not defined in either "Scriptables I" or "Scriptables II". (Technically, it's because they are not listed by "Extra > Scriptables II > GetInfo". I don't know if James intends to add the missing commands at a later date).

Command: Arguments
This looks up the function arguments for the command given in "Command id".
Example:
If "Command id" is set to "Amplify", then the output shows:
Amplify:
Ratio (float)
AllowClipping (bool)

Command: Syntax
This looks up the Nyquist / LISP syntax for the AUD-DO command for the command given in "Command id".
Example:
If "Command id" is set to "Amplify", then the output shows:
"Amplify: Ratio=float AllowClipping=bool"
This means that the full Nyquist command would be:
(aud-do "Amplify: Ratio=float AllowClipping=bool")

Command: Run Command
This tests the command given in "Command to run".
Example:
If "Command to run" is:
(aud-do "Amplify: Ratio=0.5")
and some audio is selected, then the audio will be amplified by a ratio of 0.5, and
Scripting Helper will return a message saying what it has done:
Ran command: (aud-do "Amplify: Ratio=0.5")

Note that "Run Command" is not restricted to the list of Scriptable I and Scriptables II, but may be used with any valid scriptable command. For example, the following command will work:
(aud-do "MidiDeviceInfo:")

Download:
scripting-help.ny
(3.74 KiB) Downloaded 10 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Scripting Helper

Post by steve » Sat Oct 06, 2018 4:34 pm

Example use:

By running the effect with "Command: List All" we can see that there is a command called "ChangePitch".

changepitch.png
changepitch.png (31.43 KiB) Viewed 185 times

This is the same effect as "Change Pitch" in the Effect menu, but with AUD-DO we can run it in a Nyquist script.

Next we need to know what parameters are available for this effect, so we enter "ChangePitch" (without quotes) as the "Command id", and select "Command:Arguments"

2.png
2.png (23.27 KiB) Viewed 185 times

Produces the output:

3.png
3.png (17.36 KiB) Viewed 185 times

Which shows us that there are two parameters; "Percentage", which is a floating point number, and SBSMS, which is a boolean true / false.
For scripting commands, use the number "1" for "true" and "0" for "false".

Now we can check the correct syntax by selecting "Command:Syntax"

4.png
4.png (22.88 KiB) Viewed 185 times

Produces the output:

5.png
5.png (17.17 KiB) Viewed 185 times

So let's say that we want to lower the pitch by 1 octave (-50%), using the "High Quality" (SBSMS) option.
First we will need to select some audio, then we need to substitute our preferred values into the AUD-DO command, using the syntax shown above.

An AUD-DO command is always in the form: (aud-do "command in quotes")

So this is our syntax:

Code: Select all

(aud-do "ChangePitch: Percentage=double SBSMS=bool")
and putting in our values of "-50" and "1" ("true"), we get:

Code: Select all

(aud-do "ChangePitch: Percentage=-50.0 SBSMS=1")
So now we can copy and paste that command into the "Command to run:" box, and select "Command:Run Command"

6.png
6.png (30.51 KiB) Viewed 185 times

Click "OK" and we see that the selected audio is processed, and a confirmation message returned:

7.png
7.png (19.4 KiB) Viewed 185 times

Note:
A limitation of running scripting commands with Nyquist is that ONLY the scripting commands are allowed to change the project. We cannot (yet) have a mixture of scripting commands changing the project and normal Nyquist commands changing the project. So we can run the above scripting command in the Nyquist Prompt like this:

Code: Select all

;type tool
(aud-do "ChangePitch: Percentage=-50.0 SBSMS=1")
but we if for example we do this:

Code: Select all

;type tool
(aud-do "ChangePitch: Percentage=-50.0 SBSMS=1")
(mult *track* 0.5)
The command (mult *track* 0.5) will fail,
but we could do:

Code: Select all

;type tool
(aud-do "ChangePitch: Percentage=-50.0 SBSMS=1")
(aud-do "Amplify: Ratio=0.5")
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply