Hi,
I am using Audacity to annotate a large amount of data. I need to go trough each track and add labels on intervals of interest. The labels are generally composed by the track's name and a code: e.g., "track1_C00".
I found this thread (viewtopic.php?f=69&t=107137) where a user is trying to add a label at the start of a track, and I learned that it is possible to add widgets (https://audionyq.com/nyquist-programmin ... ata-types/) from which to select a series of option.
Can anyone help me write a NYQUIST macro that takes the track name, opens a widget with all my codes (n = 9), and then concatenates both into a label at selection?
I know this is something I should figure out by myself but I would deeply appreciate some guidance.
Thank you.
Shortcut to Label with track name + code
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
-
- Posts: 3
- Joined: Wed May 04, 2022 2:15 pm
- Operating System: macOS 10.15 Catalina or later
Re: Shortcut to Label with track name + code
Something like this?RafaelCampos wrote: ↑Thu May 05, 2022 11:41 amI know this is something I should figure out by myself but I would deeply appreciate some guidance.
Code: Select all
;nyquist plug-in
;version 4
;type tool analyze
;name "Add Custom Label"
;control code "Select code" choice "C01,C02,C03,C04,C05,C06,C07,C08,C09" 0
(defun getcode (id)
(format nil "_C0~a" (+ id 1)))
(let ((txt (get '*track* 'name))
(start (get '*selection* 'start))
(end (get '*selection* 'end)))
(setf txt (strcat txt (getcode code)))
(list (list 0 (- end start) txt)))
Learn more about Nyquist programming at audionyq.com
-
- Posts: 3
- Joined: Wed May 04, 2022 2:15 pm
- Operating System: macOS 10.15 Catalina or later
Re: Shortcut to Label with track name + code
Hi steve,
Exactly!

Just one detail: Is there a way to have it add the label to the same label track? Every-time I create a new label it also creates a new track (screenshot attached).
- Attachments
-
- Screenshot 2022-05-05 at 15.47.55.png (231.88 KiB) Viewed 132 times
Re: Shortcut to Label with track name + code
To do that you need to make the selection on the audio track and the label track.RafaelCampos wrote: ↑Thu May 05, 2022 2:51 pmIs there a way to have it add the label to the same label track?
Make the selection on the audio track first, then "Shift + Click" the "Select" button on the left end of the label track.
(Alternatively, if the audio track and the label track are next to each other, you can click + drag the selection across both tracks).
Learn more about Nyquist programming at audionyq.com
-
- Posts: 3
- Joined: Wed May 04, 2022 2:15 pm
- Operating System: macOS 10.15 Catalina or later
Re: Shortcut to Label with track name + code
That would take a lot of time because I would have to scroll down. However, when I export the labels (even when there are multiple tracks), Audacity creates a single .txt with all of them, which is exactly what I wanted. So it still works exactly as I needed even with multiple label tracks.
Thank you for your time. You just saved me many of hours of work.
Best!
Re: Shortcut to Label with track name + code
If you have lots to do, then there's a workaround, but probably not worth the effort if you can manage with the plug-in as is.RafaelCampos wrote: ↑Thu May 05, 2022 3:19 pmThat would take a lot of time because I would have to scroll down.
The workaround is to create another plug-in, using this code (additional headers are required to make it a full plug-in):
Code: Select all
;type tool
(defun first-label-track-id ()
(let ((tracks (aud-get-info "tracks"))
(tracknum 0))
(dolist (track tracks nil)
(when (member '(KIND "label") track :test 'equal)
(return tracknum))
(incf tracknum))))
(aud-do-command "selecttracks"
:track (first-label-track-id)
:trackcount 1
:mode "Add")
""
Then create a (normal) Macro with the two plug-ins. (add the label track to the selection, then create the label).
Finally, make a keyboard shortcut to run the macro (See: https://manual.audacityteam.org/man/key ... ences.html)
(Unfortunately it is not possible to combine both bits of code in a single Nyquist plug-in because changing the selection can only be done as a "Tools" type plug-in, and returning labels requires an "analyze" (or "tools analyze") type plug-in.
Learn more about Nyquist programming at audionyq.com