Macro command to toggle selection / deselection

Hello,

I am puzzling my way through the various new Macro commands (and, especially, those in the Extra menu).

One of the things that would really help me automate some fairly repetetive tasks would be the ability to deselect the current selection, move focus to an adjacent track, then select the SAME segment of that newly focused track.

(Following that, I might choose, say, to paste in the segment just copied from above, deselect this and move focus back to the original selection ready to perform another operation.)

However, I keep falling at the first hurdle: how do I DESELECT the current selection preparatory to shifting focus?

Manually, this is easy — just hit the enter key to toggle the current time selection on or off from the currently focused track.
Surely, there is a Macro command to facilitate this simple toggle feature?

Thanks for your help,


Eric

There’s a ridiculously simple way to do that (simple when you know :wink:)

  1. Press “Enter” to toggle the selection “off” in the current track.
  2. Press “Cursor up” or “Cursor down” to move focus to another track.
  3. Press “Enter” to toggle the selection “on” in the track that has focus.

Also:
“Ctrl + C” for “Copy”.
“Ctrl + V” for “Paste”
“Ctrl + X” for “Cut” (removes the selection and retains a copy on the clipboard for pasting).

Other shortcuts can be found here (don’t try to memorise them all): Commands and Keyboard Shortcut Reference - Audacity Manual

Oops, I’ve just read the end of your post :blush:

Why do you need a macro feature when it can be done so easily with “Enter”?

Because that is just part of various longer processes, for which the computer would be a lot more patient, accurate and (if reliably programmed) quicker than I.

I am processing a lot of spoken word audio (hours’ and hours’ worth) — which needs to be cleaned, breath by breath, click by click.
Sometimes, I must be prepared to scale back or undo parts of the “cleaning” where unrequired or too severe.

For example, a debreath plug-in sometimes mistakes intentional sounds — parts of words — for breaths; or else ignores real breaths.
When I step in to reduce the breath by hand, I might want to keep a copy of the the original raw sound in case I have to revert.
At that point, manually, I would do as you suggest - copy, enter, down-arrow, enter, paste, enter, up-arrow, enter, then run the effect, select the next problem, and so on.

Believe me, to be able to do this with a single keystroke could knock hours off my workload.

I have a series of denoising routines I run on a raw file before processing, and another series I run after processing.

In each case, and for each track, I make a duplicate for posterity before working on it.
(I have been caught out before by Audacity crashes, and it’s not funny when a two hour audio piece becomes unrecoverable).

Again, if I could automate the taking of duplicates and running of strings of effects into one Macro, I could leave each processing, go and put the kettle on — over time, yet more hours saved.

But, when things are duplicated, or copied and pasted, Audacity tends to maintain selection of both the new pasting and the original copy; thus any effect run automatically, as a step in a macro, operates upon both the original and the copy.

So again, if there is a macro step by which to deselect the original (or else the copy) before proceding, I want to know about it.

I could go on. Suffice to say, I have many batch processing uses to which I could put this new Macro facility — but I’m falling at the first hurdle because I can’t find a macro step for selecting and/or deselecting from the currently focused track.

Make sense?

Rather than running the macro on a 2 track project, couldn’t you simply export the track as a WAV file, then apply the macro on the one track, then import your duplicate track (the WAV file) back into the project?

Each chapter can have three or more tracks — which will multiply with each operation I run on them. One finished piece eventually consisted of seventeen separate tracks (for a single chapter out of a twenty chapter book). That’s a lot of exporting and reloading. But, if this can be done automatically, well I suppose it’s a valid approach. Just so long I can set the Macro batch processing and return after twenty minutes to find the repetetive tasks complete. I appreciate your advice.

What Macro steps would you use to do this?


I also have to delete fluffs and retakes, which means that the evolving edited track gets shorter and shorter. Working by hand, I use the sync-lock facility so that, when I delete a part of the current edit, the original is also trimmed in line - meaning that, wherever I am in a sound file (which might be up to three hours long), the original unprocessed sound is available exactly above the newly processed sound, point for point, wave for wave.

Hunting around a ninety minute .wav upload for the precise bit you want to revert to is also a big time-eater.

As I say, Steve, I had hoped to hear — from someone who has been working on these hundred-odd “Extra menu” Macro steps and “Scriptables” — that they include a single step by which to “Toggle Selection.” It is, as you point out, such a doddle with the Enter key, I was convinced there must be a valid Macro step to do the same thing.

Are you in a position to tell me, now, that this simply isn’t possible? (To toggle the selection using Macros?)

If you know this for a fact, you will have saved me further frustration hunting around to find it.

If you’re unsure, is there another Audacity boff who knows about Macros and can tell me whether or not such a step exists?

Personally, if I’m doing fine editing of a track to clean up glitches, with the aim of achieving a high quality product, I edit it manually. I don’t fully understand what you are trying to do with macros - the macro does not know if your audio has an accidental noise that shouldn’t be there. :confused:
Nevertheless, if you have a selection in track 1, and you want the same track selection, but in track 2, then you can do that with a macro like this:

SelectTracks:Mode="Set" Track="1" TrackCount="1"
SetTrackStatus:Focused="1" Selected="1"

(note that in “Select Tracks”, the track number is zero indexed. That is, Track=“0” is the first track, and Track=“1” means the second track).

Thanks for that.

I’ll try it and get back to you,

E.

OK, thanks Steve.

That’s getting pretty close.

But my selection happens, in this instance, to be the fifth track in the project; next time, it may be the third - or the seventh.

Is there any way I can apply that same formula — but to the current track and the next track: tracks “x” and “x+1”?

In other words (I have no knowledge of Nyquist macros), how can I “get” the number of the current track as a variable — then apply SelectTracks “Set” to that track number, and SetTrackStatus to the following track (track x + 1)?

Normal Macros are only a list of commands that run in strict sequence from start to end. They don’t have “variables”, or looping, or logic … Those kind of “programming” features are provided by Nyquist (built in), or Python (running externally from Audacity).

The simplest way to run macro commands with Nyquist, is to use the “Nyquist Prompt” https://manual.audacityteam.org/man/nyquist_prompt.html
Macro scripting commands can be sent from Nyquist using the “aud-do” function, like this:
(aud-do “scripting-command”)

Note that the scripting command must be in quotes. If the command itself includes quotes, then they must be “escaped” with a backslash. So, for example, “Set” becomes "Set". Numbers do not need to be quoted.

Using our previous example:

SelectTracks:Mode="Set" Track="1" TrackCount="1"
SetTrackStatus:Focused="1" Selected="1"

becomes:

(aud-do "SelectTracks:Mode=\"Set\" Track=1 TrackCount=1")
(aud-do "SetTrackStatus:Focused=1 Selected=1")

Thanks again, Steve.

Is there a programming instruction manual for Nyquist (built in) somewhere — so I can learn to use variables and programming logic in my batch commands?


Meanwhile, with your help, a little lateral thinking, and a lot of stubborn, witless, trial and error, I have found a way to do something akin to my hoped-for outcome above: a simple step which duplicates the selection (cut and paste to the track below), then returns the selection to its original one-track focus (the duplicate deselected).

It works — but I’m pretty sure there must be a more efficient way to do it.

Here, as work in progress, are the necessary steps:

Copy:
SelectTracks:Mode="Set" TrackCount="0"
NextTrack:
SelectTracks:Mode="Set" TrackCount="0"
ShiftDown:
Paste:
SelectTracks:Mode="Set" TrackCount="0"
PrevTrack:
SelectTracks:Mode="Set" TrackCount="0"
ShiftUp:
SelectTracks:Mode="Set" TrackCount="0"
ShiftUp:

I find it puzzling that: to get the selection to move down, I actually had to double up on the move instructions
(NextTrack + SelectTracks “0” + ShiftDown + SelectTracks “0”);
and, to get it to move back up again, I had effectively to triple up on the commands
(PrevTrack + SelectTracks “0” + ShiftUp + SelectTracks “0” + ShiftUp)

— but it has got me there. I can add in, say, a debreath effect at the end.

Grateful if anyone can see a more efficient way of doing exactly the same thing.

Meanwhile, thanks once again, Steve, for your patient advice.

The macro command “Toggle Focused Track” is the equivalent of pressing the enter key, which deselects the focused track but leaves the selection range intact. Then use the macro commands “Move focus to next track” or “Move focus to previous track” followed by “Toggle Focused Track”.

I think that will do what you want.

As Steve points out, you can’t loop through all the tracks, but you can set up your macro to do what you want to the selection then move to the next track and make the same selection. You’re now ready to run the macro again on the new track and move to the next. Assign a keyboard shortcut to the macro through Keyboard Preferences to make it easier, or open the Macros Palette for quick access to your macro.

– Bill

Bill,

that is exactly what I was looking for. Thank you very much for understanding and slinging me a straightforward answer.


(To be honest, I’m still struggling with the “Move Focus to Next and Select” steps — on my Mac (High sierra), nothing gets selected.
Is it a bug — or do I simply not think in the same way as the geniuses who have implemented these appealing macros? I can’t tell.
Trying them out is a minefield. I’m really hoping for a fleshed-out manual and some rethought command-entry “ergonomics” for 2.4 Macros. )

Onward and upward.

Thanks again,


Eric

Eric:
If you haven’t already done so, go to Audacity > Preferences, then the Interface tab and check “Show Extra Menus”. Now, under the Extra menu, you’ll have menu equivalents of all the macro commands that don’t replicate regular menu actions, including moving focus and changing selectedness. So you can try out these macro steps without making and running a macro.

To try this out, open or create a project with several tracks then click in the first track (creating a point selection). Note that the colour of the Track Control Panel changes, indicating that the first track is selected (which means editing operations will be performed on that track), and has a yellow border which means it “has focus”. Now choose the menu command Extra > Focus > Move Focus to Next Track; note that the yellow focus border moves to the second track but that the colour of the Track Control Panel indicates that track 2 is “not selected”. Now do Extra > Focus > Toggle Focused Track; now the Track Control Panel of track 2 changes colour to indicate that track 2 is “selected”. Both tracks are now selected and editing operations will be applied to both tracks. Now click in Track 1; the yellow focus border moves to track 1, the Track Control Panel of track 2 changes to the “not selected” colour and the Track Control Panel of track 1 remains at the “selected” colour. Now do Extra > Focus > Move Focus to Next and Select; this has the same effect as the two menu commands you did previously.

It may appear that “nothing gets selected” since all that happens when you move to and select the next track is that the editing cursor appears in the next track. If you do the above steps but start with a range selection in track 1 you’ll see the selection extending into track 2.

Hope this helps.

– Bill

Thanks very much, Bill, for the very comprehensive reply, and sorry to have been so slow picking it up.

Yes, I have been having a play with those Extra menu “Scriptables.”

I have to say that the Move Focus instruction is reliable.

But have you played around with the Move Focus to Next and Select and the Move Focus to Previous and Select commands?

Try it. Copy some sound onto three different tracks; select a portion of sound in one of them; then have a play with the Move Focus to ~ And Select instructions.

I must say, I find these instructions counter-intuitive, seemingly inconsistent and — well, is it possible — buggy?

What are they supposed to do — in your experience; do you find that they do this consistently?

The focus moves reliably enough, but it seems to me that what will ultimately wind up selected seems almost random enough to run a sweepstake.

The “Extra” menu is hidden by default as many of the commands are not useful as menu commands, but they need to be menu commands so that they are available for shortcuts, for scripting, and for Macros.
Many of them have been added to help blind users, and for other users that can’t use a mouse.

The “Move Focus to Next / Previous and Select” commands don’t work well from the menus because the menu takes focus away from the tracks.

The “Move focus to next and select” has the shortcut “Shift + Down cursor”.
Try this in a project with 3 tracks:

  1. Make a selection in the first track
  2. Press “Shift + Down cursor”.
    The selection is extended to the next track.

I think I see what you mean. Steve, try this.
Make a project with 3 or more tracks
Make a region selection in the first track
Do Shift+Down-arrow: focus moves to second track and both tracks 1 and 2 are selected
Do Shift+Down-arrow: focus moves to third track and tracks 1, 2 and 3 are selected
Do Shift+Up-arrow: focus moves to second track, track 3 is de-selected
This seems wrong. The command is “Move focus to previous track and (then?) select”.

Now, try this.
Make a region selection in the first track.
Shift+click on the “Select” button in the second track: tracks 1 and 2 are selected
Shift+click on the “Select” button in the third track: tracks 1, 2 and 3 are selected
Shift+click on the “Select” button in the second track: focus moves to second track, track 3 is de-selected, as in the first example
Now, this is may be correct: shift+click extends a selection. Think about a word processor. Click in the text then shift+click further along - the selection is extended. But in the word processor if you shift+click inside that selection, the selection does not change. Shift+click will extend but not contract a selection.

So here’s my conclusion. The Shift+Up/Down-arrow commands are behaving correctly (in the above examples) given that they are extending or contracting the selection based on the first-selected track being the “anchor” for the selection.

But, try this.
Make a region selection in the first track
Do Down-arrow.
Do Shift+Down-arrow: track 2 is selected and focus moves to track 3 which remains not-selected.
Is that correct? Shouldn’t the Shift+Down-arrow into track 3 select tracks 1 through 3, same as if the user selected in track 1 then shift-clicked the Select button in track 3? I certainly wouldn’t expect the actual behaviour.

There’s probably some consistent logic behind this, but I can’t see it.

– Bill

I think that’s the intended use for these commands, though the description in the manual is rather vague.

I agree that looks weird.

There’s definitely “consistent logic” behind it, though I agree it is weird.

  • IF [focused track is selected] AND [destination track not selected]
  • THEN [move focus] AND THEN [Select focussed track]
  • ELSE IF [focused track is selected] AND [destination track is selected]
  • THEN [deselect focused track] AND THEN [move focus]
  • ELSE IF [focused track is not selected] AND [destination track not selected]
  • THEN [select focused track] AND THEN [move focus]
  • ELSE IF [focused track is not selected] AND [destination track is selected]
  • THEN [move focus] AND THEN [deselect focussed track]

No, it’s not obvious at all, but it’s the required logic to make a selection expand and contract.
Personally, I’d have just done:

  • [move focus] AND THEN [select]

but that does not give the expand / contract behaviour.

Thanks, Bill, for understanding my confusion.

And thank you, Steve for precisely detailing the underlying logic. This does now make sense.

But you’re right that I would probably do better to move the focus and then to toggle selection in two separate macro steps; I hadn’t originally noticed the “Toggle Focus” instruction. The icing on the bun will come when I grasp Nyquist macro instructions well enough for my macro first to check whether the adjacent track is already selected (since that can affect the result in either case).

Yes, thank you Bill for highlighting the problem.

This issue is now being discussed on the Audacity QA mailing list, to see if we can agree to a less confusing behaviour for future versions of Audacity.