Why Are New Tracks Always Added to the End? You Should be Able to Add Them After the Selected Track

:smiley: <3 :smiley: <3

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!

trackmove.ny is a full “Nyquist plug-in” and can be installed: https://manual.audacityteam.org/man/customization.html#plug-ins

Once installed, you can create a custom shortcut to it: https://manual.audacityteam.org/man/keyboard_preferences.html

Inspired by trackmove.ny, I made a nyquist plug-in that:

  1. identifies the current track (call it track “a”)
  2. adds a label track and places it directly below that track
  3. 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:

  1. The plug-in picks “current track” based on the track that has focus–in particular, this means that if you:
  2. select some audio on track 1
  3. manually hit the down arrow to move focus to track 2
  4. run this plug-in
    then the plug-in will
  5. Place the new label track directly below track 2
  6. and then select the portion of track 2 matching the range of track 1 that you originally had selected
  7. The plug-in doesn’t try to do any sort of special handling if your selection spans multiple track–the plug-in will still:
  8. 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)
  9. make a label track directly below that one track
  10. 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:

  1. 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)

Congratulations. It works nicely. :ugeek:

I noticed in the code comments:

;; 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:")

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 :wink:

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.

Just came across this life-changing nugget. Thanks Steve! Insanely useful.

This Enhancement Request that I logged a while back (June 2020) addresses this issue:

Rationalizing where new tracks are created to aid usability and consistency #2392

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: