I’d like to automatically select a region adjacent to my selected region, using a macro or Python or something. Is this possible?
For example, I’ve selected a region starting at 01:25 and ending at 01:30. I want to auto-select the region from 01:20 to 01:25 with a single operation.
I’ve been looking at the macros and I think this would be possible if I could set a new selection as 100% of the old selection and starting at T-100% of the old selection starting point and ending at T-0% of the old selection. But I see no way to supply my select parameters with values relative to the current selection’s size (ideally in samples, not seconds).
Thanks Steve. This does get me part of the way there. Is there a way to prompt the user for an input? The selection size needs to be variable, and ideally the number of samples, not seconds.
Audacity macros can’t do that. Macros are just a list of commands that run in sequence. They don’t support user interaction or conditional operations. For those kind of features a more flexible programming language is required, such as Nyquist (built into Audacity) or an external language such as Python.
The Nyquist language can issue macro commands. For example;
The “SelectTime:” command shown in my last post can be sent from Nyquist using “AUD-DO”
A couple of addition pieces that we need so that this command works:
Audacity needs to be told that the code will be modifying the project using macro / scripting commands.
We do this by adding a special comment at the top of the script that declares the plug-in / script as a “Tool” type effect:
;type tool
Nyquist should always return a valid value to Audacity when it completes.
Valid values include: numbers, strings (text), sounds, stereo sounds, “label lists” (specially formatted lists that tell Audacity to add labels).
If we don’t want to send a value to Audacity at the end of the script, we can send an empty string, which Audacity accepts as “valid” and ignores it. An empty string return value is a “no-op” (no operation command).
To do that, the code can tell Audacity to produce a GUI with a control to set the required duration.
See this page for an overview: Missing features - Audacity Support
The Time widget shown above sets the variable “duration” to a numeric value: default = 1, minimum = 0, maximum = anything (“nil”)
Regardless of the time format used by the control, the value of the variable is always in seconds (converted automatically when necessary by the widget).
So the next thing that we need to do is to modify the AUD-DO command, so that “Start” = negative “duration”.
An easy way to do this is to construct the scripting command first, then send it to Audacity with “AUD-DO”.
Finally, the Nyquist script can be made into an installable plug-in by adding a few additional “header” comments.
See here for details of what is required: Missing features - Audacity Support
Top Tip:
Nyquist scripts must be written in plain text. A good plain text editor for Windows in NotePad++ (https://notepad-plus-plus.org/)