Steve you are truly incredible (not to mention extremely generous for volunteering your time to help complete Internet strangers)! Thank you so much, your Nyquist code worked exactly as promised.
Now if I can just figure out how to map both that script and the other one you helped me write (https://forum.audacityteam.org/t/export-of-track-lengths/52704/11) to keyboard short-cuts, so I don’t have to go Menu => Tools => Nyquist Prompt => Load => Select Appropriate File => OK every time I want to switch between them, I’ll truly be in heaven!
Inspired by trackmove.ny, I made a nyquist plug-in that:
identifies the current track (call it track “a”)
adds a label track and places it directly below that track
moves focus back to track “a”.
I’m not sure if there are any differences to how plug-ins apply based on audacity version, but I’m running version 3.0.2 on linux, installed from the ppa.
A few notes:
The plug-in picks “current track” based on the track that has focus–in particular, this means that if you:
select some audio on track 1
manually hit the down arrow to move focus to track 2
run this plug-in
then the plug-in will
Place the new label track directly below track 2
and then select the portion of track 2 matching the range of track 1 that you originally had selected
The plug-in doesn’t try to do any sort of special handling if your selection spans multiple track–the plug-in will still:
pick the one track that has focus (if you selected with the mouse from top to bottom, that’ll be the last track of the selection, if you selected from bottom to top, it’ll be the top track of the selection)
make a label track directly below that one track
and then, because it only knows about that one track, put the focus back there, de-selecting the other tracks.
I don’t understand nyquist well enough to address these limitations, and this is sufficient for my purposes, but if anyone else does want to address this, go for it! It is lines 47-50 that place the focus back on the original track, and the function get-focus-track that picks which track to put the label track directly below.
To make a similar plug-in that adds any other kind of track, you can change:
Line 4:
;name "Add Labels Below"
This is the line that sets the display name you’ll see when you want to apply the plug-in in audacity (or use it as a step in a macro).
2. Line 40:
(aud-do "NewLabelTrack:")
This is the line that makes a new label track. You can replace “NewLabelTrack:” with any of the other scripting ids under “Tracks: Add New” in the scripting reference.
3. The file name, so you’ll be able to recognize it in the enable/disable add-ons menu after installation. add-labels-below.ny (1.64 KB)
;; Previous plug-in subtracted one from the number of
;; tracks, but that seemed to ignore the new track so
;; I changed it
The reason that the old plug-in code was out by one, is that the number of tracks in the project is found using this command:
(get '*project* 'tracks)
That looks up the TRACKS property of the PROJECT variable, which is set at the time that the plug-in is initiated. However, you add a new track (the label track) before reading the TRACKS property.
(aud-do "NewLabelTrack:")
(select-last)
So the project now has one more track than there was when the plug-in was initiated - that’s one more track than when the TRACKS property was set.
Personally I don’t see those things to be “limitations”. There can only be one track that has focus, so there is no ambiguity about which track to use. If the plug-in used the “selected track” as the reference, rather than the track “with focus”, then you need to decide if the reference track will be the first selected track, the final selected track, or some other track.
It would be possible to use the selected track(s) as the reference if you really wanted that, but in my opinion it’s probably not worth the effort
Thanks! Glad to have confirmation it works for someone else! And thanks for providing the basis I could use to make this–I’ve come across parentheses-based languages before, but never actually used one for anything, so I wouldn’t have known where to start without that.
I figured it was something like that! Didn’t really feel like doing the full investigation, so just left it as a breadcrumb for the next person. Thanks for the explanation!
Yep, that’s basically the conclusion I came to! For anyone not familiar with how track focus works, though, it could be unexpected behavior, so I wanted to make the intended behavior of the plug-in as clear as I could.
It has been marked as "an "accepted feature request in Muse’s project planning on GitHub - but so far no work has been done on this: https://github.com/orgs/audacity/projects/5