Store Cursor Position Doesn't Work in Macro: Any Workaround?

I’m using the “Move Track Here” plug-in that another user in this forum made for me. This plug-in simply moves the bottom-most track to the current position, which is handy because Audacity inexplicably adds new tracks to the bottom instead of to the current cursor position.

The only problem is, adding a new track shifts the focus to the bottom, so if I’m on track #7 of 30, to add a new track I have to select add new track, go to the bottom, scroll back up to track #7, and then use the plug-in to move my new track up.

I thought I could use the macro system to simplify this, by making a macro that:

  • Stores the current cursor position
  • Makes a new track
  • Restores the cursor to its stored position
  • Moves the track to that position

However, what I’ve found is that … well first off, there is no “Cursor to Stored Position” command available in the macros at all. That was weird. But then I did find “Select Cursor to Stored”, and that seems to work …

… when I use it with other commands. For instance, a macro of:

  • Store the current cursor position
  • Move to project start
  • Select Cursor to Stored

does work. But when I throw a “Mono Track (NewMonoTrack)” command in, it doesn’t seem to matter what I add after: “Cursor to Project Start”, “Cursor to Selection End”, “Select Cursor to Stored” … heck even if I throw a Pause in for good measure, it doesn’t matter: at the end of my macro I’m always at the very end of my project, on the newly created (last) track.

So my question is, is there any way to make this work, either officially or through some sort of hack?

And also, just curious: does anyone know why it seems to be possible to macro every command in Audacity except “Cursor to Stored Position”?

“Store Cursor Position” does work, but not in the way that you are thinking. The “cursor position” is the “time” position for the selection cursor. It does not store which track is selected. A typical way this might be used is to store the cursor position, do something, move the cursor to some other position, then select from the stored cursor position to the new cursor position. This command is not relevant to your current task.

Probably because it’s not necessary.
Example - this stores the current cursor position, selects the entire project, applies “Amplify”, then restores the original cursor position. (It’s the final two commands that restore the cursor position)

SelectTime:End="0" RelativeTo="SelectionEnd" Start="0"

I guess that was me. Do you have a link to the topic where I posted the plug-in, or could you post it here so that I can see what you have so far.

So is the aim of this to add a new, empty, mono track, immediately below the current track?

Yes, exactly, and you’re awesome for making me that plug-in :smiley:

But as I said, now that I’ve discovered the beauty of Audacity’s macro system, I thought I could use it to achieve that effect (ie. I’m on track 6 out of 30, I click my macro, now I have a brand new mono track at position #7) … but I haven’t been able to figure out how to make it work.

The plug-in is:

;nyquist plug-in
;version 4
;type tool
;name "Move Track Here"
;release 2.3.2
;author "Steve Daulton"
;copyright "Released under terms of the GNU General Public License version 2"

;; This plug-in moves the bottom track in the project up to one below the track
;; that currently has focus.

;; Import Audacity commands as LISP functions

(defun select-last ()
  ;;Select the final track and set focus on it.
  (let ((last-track (1- (get '*project* 'tracks))))
    (aud-SelectTracks :track last-track
                      :trackcount 1
                      :mode "Set")
    (aud-do "SetTrack:Focused=1 Selected=1")))

(defun get-focus-track ()
  ;; Return index of track that has focus.
  (let ((info (aud-get-info "Tracks"))
    (dotimes (i (length info) (throw 'err "No track focus"))
      (setf hasfocus (second (assoc 'FOCUSED (nth i info))))
      (when (= hasfocus 1)
        (return (1+ i))))))

(defun move ()
  (let ((ft (get-focus-track)))
    (do ((i (1- (get '*project* 'tracks)) (1- i)))
        ((<= i ft))
      (aud-do "TrackMoveUp:")))

(catch 'err (move))

P.S. And for the record, I just don’t understand why the default behavior is “always add tracks at the end”. It seems to me (data point of one) that it would make more sense to just add new tracks at the current cursor position all the time, without the need of special plug-ins or macros. But I guess other users must find it valuable to always have them come at the end?

I think it’s because that’s the way that Dominic Mazzoni wrote it 20 years ago, and there’s been little demand to change it.

One of the main limitations of ordinary Macros, is that they only perform a single list of instructions.

In this case, IF track 6 is selected, then you want to insert a new “track 7”, ELSE IF track 7 is selected, then you want to insert a new “track 7” …
Normal Macros can’t do this kind of “conditional” branching - you need to use a more powerful / flexible programming language, such as Nyquist or Python.

This plug-in is a variation on the previous plug-in, but it adds a new track, then moves it below the track that originally had focus.
add-track-here.ny (1.21 KB)

That worked great, thanks!

I know I’m being greedy, but do you by any chance know of a way to return the focus back to the original track? Right now it adds the track at the right spot, but you remain scrolled down to the bottom.

That doesn’t happen for me. On my Linux (Xubuntu 18.04) machine with Audacity 2.3.3 alpha, the newly added empty track ends up in view. The difference may be due to changes in Audacity from 2.3.2 to 2.3.3 alpha.

Probably not. It’s not working quite correctly even with Audacity 2.3.3 alpha. Although the track is in view, I’ve not been able to get the yellow “focus” line around the track. I think this is probably due to this bug in Audacity:

Ahhh, well I’ll just have to wait for 2.3.3 to get out of alpha then (and until that happens the new version is still a significant improvement).

Thanks … yet again … for your help!