Add Labels Macro Command

Looking for a way for a macro to add/create new labels with start, end, and text, without prompting for the label text.
Is this possible? The add label macro commands I see prompt for the label text to be entered. Hampers the use of macros for automation.

The “Add label at selection” command seems to work for me. It does leave focus in the label text, but only if it is the last macro command.

When I tried to use that to create a bunch of labels it pops up a dialog for user to enter each label’s text.

I’d rather have the set label command be able to create if doesn’t exist.

What I’m doing now that seems to work is this:
Concert_Title_Edit.txt

NewLabelTrack:
TrackMoveTop:
PasteNewLabel:
PasteNewLabel:
PasteNewLabel:
...
SelectTracks:Mode="Set" Track="1" TrackCount="1"
SelTrackStartToEnd:
Copy:
NewStereoTrack:
Paste:
...
SetLabel:End="642.135028" Label="1" Selected="0" Start="444.585715" Text="If I Stand"
SelectTime:End="640.850000" RelativeTo="ProjectStart" Start="638.850000"
FadeOut:Use_Preset="<Factory Defaults>"

SetLabel:End="1369.192910" Label="2" Selected="0" Start="1090.329910" Text="Calling Out Your Name"
SelectTime:End="1090.670000" RelativeTo="ProjectStart" Start="1090.329910"
FadeIn:Use_Preset="<Factory Defaults>"

SetLabel:End="1918.640000" Label="3" Selected="0" Start="1695.985488" Text="The Color Green"
SelectTime:End="1696.340000" RelativeTo="ProjectStart" Start="1695.985488"
FadeIn:Use_Preset="<Factory Defaults>"
...
SelectTracks:Mode="Set" Track="0" TrackCount="1"
SetLabel:End="0" Label="0" Selected="1" Start="0" Text="empty"
Delete:

Any pitfalls with doing like this?

One thing I don’t like about using the PasteNewLabel command in this way is that it creates all the labels initialized with whatever happens to currently be in the clipboard.

  1. How are you running these commands? Are you creating a “macro” (Macro Manager - Audacity Manual), or using the scripting interface? If using the scripting interface, are you doing so with mod-script-pipe and Python (or some other language), or with Nyquist “AUD-DO”?

  2. No need for the “NewLabelTrack:” command unless the project already contains other label tracks.

Yes, of course it does. The long name of that command is “Paste Text to New Label”
https://alphamanual.audacityteam.org/man/Scripting_Reference#Edit:_Labels

As I wrote previously, if you want an empty label, use the “Add label at selection” (Scripting Id: “AddLabel:”, Description: “Creates a new, empty label at the cursor or at the selection region.”)

Potential pitfall: If you need a label at time=0, then that should be created last because if there are multiple labels at time=0, then you probably can’t be sure which label will be picked by “SetLabel:”

  1. Running the commands as a macro; C:\Users\AHS\AppData\Roaming\audacity\Macros\macro_name.txt

  2. Thanks for the tip. Though will probably keep that for self documenting clarity sake.

  3. Don’t want an empty label. Want a bunch of labels with various start, end, and text. And want to set them at various places within the macro.

So we set a label at a specific start and end with some meaningful text like song title. Then perform edits for that section. The label text field sort of doubles as providing a human readable reference for the section that the macro is editing.

Initially I was using the “Add label at selection” (AddLabel) command. But each of them pops up a dialog prompt for user to enter the label text. I want the label text to be populated by the macro. To accomplish this I create a bunch of labels. Then set each of them with the desired position and text. Would be nicer if the set label command would create the label if the specified label doesn’t exist.
Using “Paste Text to New Label” is a work around for the pop up dialog.

The way I would do that would be:

  1. Set the selection to a time before zero (so that the label created in the next step will always be the first label)
  2. Add a label at the selection
  3. Set the label “index” 0, with the required start time, end time and text/
    Repeat 1 to 3 as required.

Note that macros can only run a simple list of commands. They can’t do conditional logic, or pass information from one command to another - for that you need to use “scripting”.

But step 2 of that pops up a “New Label” dialog box for user to input the label text.

Try it:

Select:End="0" Mode="Set" RelativeTo="ProjectStart" Start="0"
AddLabel:
SetLabel: Label="0" Start="7" End="10" Text="Audacity"
Select:End="0 Mode="Set" RelativeTo="ProjectStart" Start="0"
AddLabel:
SetLabel: Label="0" Start="4" End="5" Text="Foo Bar"
Select:End="0" Mode="Set" RelativeTo="ProjectStart" Start="0"
AddLabel:
SetLabel: Label="0" Start="1" End="2" Text="Hello World"
Select: Start="0" End="10" Mode="Set" RelativeTo="ProjectStart"
TrackMoveTop:

Pops up dialog box, prompting for label name/text, for each AddLabel command. So in this case; 3 times.
Oh also, what to add to the end (append) not the beginning (prepend).
Also the Select command seems to be irrelevant since the start and end times are being set with the SetLabel command anyway.

I’m unable to reproduce that on Linux or Windows 10.
I don’t have Windows 8.

You need to know the label index for SetLabel:
Adding a label before any other labels “should” guarantee that it is the zero index label.

The same should work, but note that currently the labels are not re-sorted after adding a label with a macro, so the label indexes will be in reverse order. This may also cause the labels to be staggered vertically until some other action causes the labels to be sorted.

What action will cause the added labels to be sorted?

Using the Label Editor does. Probably other things too.

I can reproduce this by enabling “Use dialog for the name of new label” in Preferences. If you turn that off then the labels should appear without prompting for a name. Does that work for you?

We are talking about macros here. Why would I be using the label editor.
As for “Probably other things too”. That is too vague to be of much help.

Well of course. That’s why I posted about it in the Feedback & Reviews forum regarding the macro AddLabel command behavior.
https://forum.audacityteam.org/t/new-label-dialog-preference-macro/50658/1

Macros are a new feature with dozens of new commands and thousands of ways of using and combining them. I’ve only been testing these new features for a few weeks longer than you, plus fixing some problems as they have arisen. I can’t be expected to know everything :wink:

I do know that using the Label Editor re-sorts the labels, so I shared that information with you.
I also know that reversing the project and reversing it back again will re-sort the labels.
If you find any quick and convenient way to resort the labels, please let me know.

When I get time I shall be looking into this to see if sorting could be added automatically when adding a new label with a macro, without imposing too much of a performance penalty if the project contains a lot of labels. If that can’t be done, then we may need an additional macro command to sort labels.
If you have better ideas, please say.

That’s looking promising. Even with a project with 1000 labels, I’m not seeing any noticeable slowdown (tested on Linux).

How about an AddLabel command option to append.

So first AddLabel is index 0, next one is at index 1, next one is at index 2, etc. Rather then each new one being at index 0, and index of all the previous being incremented.

So that new labels go after the last one, rather than before the first one.

Labels “should” be kept in order in the label track so that tabbing from tab to tab goes left to right (Shift + Tab for right to left). This is important for a lot of people that use labels for navigating through large projects (such as audiobooks).

This is now fixed in the alpha code.

Hello Steve.

(1) I gather from the posts in this topic that the native macro-capability is fairly new. If so, is there a plan to upgrade the macro-capability at all, apart from adding new Audacity commands as they are implemented?

(2) I installed NyQuist and copied a supplied macro. I have a feeling that NyQuist should be the target of my studies if i want to do semi-serious macro stuff. This topic interested me because I wanted to write a macro that generated labels with the time-stamp (mm:ss) of the Selection point, but as far as I know, Audacity macros do not support any sort of variable data, incremental, random or whatever. Is this correct?

Thanks, Chris

“Macros” was originally called “Chains”. It was greatly extended and renamed as “Macros” a few years ago.


There are plans to improve the Macro Manager interface, but Macros themselves are unlikely to change significantly.


“Nyquist”


Yes.


You can do that with normal Nyquist (no need for Macro commands).

This code may be run in the Nyquist Prompt (see: Nyquist Prompt - Audacity Manual) and will create a label at the selection, with the time range (in seconds) in the label text.

;version 4
;type analyze

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (list (list 0 1 (format nil "~a - ~a" start end))))
1 Like