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

Help for Audacity on GNU/Linux.
Forum rules
ImageThis forum is for Audacity on GNU/Linux.
Please state:
  • which version of Linux you are using,
  • the exact three-section version number of Audacity from Help menu > About Audacity,
  • whether you installed your distribution's release, PPA version, or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade (see https://www.audacityteam.org/download/).
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Post Reply
machineghost
Posts: 67
Joined: Wed Sep 05, 2018 5:00 pm
Operating System: Linux *buntu

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

Post by machineghost » Tue Aug 27, 2019 5:00 pm

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"?

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

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

Post by steve » Tue Aug 27, 2019 5:27 pm

"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.
machineghost wrote:
Tue Aug 27, 2019 5:00 pm
And also, just curious: does anyone know why it seems to be possible to macro every command in Audacity except "Cursor to Stored Position"?
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)

Code: Select all

StoreCursorPosition:
SelectAll:
Amplify:Ratio="1.4125376"
SelCursorStoredCursor:
SelectTime:End="0" RelativeTo="SelectionEnd" Start="0"

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

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

Post by steve » Tue Aug 27, 2019 5:29 pm

machineghost wrote:
Tue Aug 27, 2019 5:00 pm
I'm using the "Move Track Here" plug-in that another user in this forum made for me.
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

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

Post by steve » Tue Aug 27, 2019 6:34 pm

machineghost wrote:
Tue Aug 27, 2019 5:00 pm
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
So is the aim of this to add a new, empty, mono track, immediately below the current track?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

machineghost
Posts: 67
Joined: Wed Sep 05, 2018 5:00 pm
Operating System: Linux *buntu

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

Post by machineghost » Tue Aug 27, 2019 7:02 pm

steve wrote:
Tue Aug 27, 2019 6:34 pm
machineghost wrote:
Tue Aug 27, 2019 5:00 pm
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
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 :D

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:

Code: Select all

;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
(aud-import-commands)


(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"))
        hasfocus)
    (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)))
    (select-last)
    (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?

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

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

Post by steve » Tue Aug 27, 2019 11:47 pm

machineghost wrote:
Tue Aug 27, 2019 7:02 pm
P.S. And for the record, I just don't understand why the default behavior is "always add tracks 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.
machineghost wrote:
Tue Aug 27, 2019 7:02 pm
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)
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 KiB) Downloaded 18 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

machineghost
Posts: 67
Joined: Wed Sep 05, 2018 5:00 pm
Operating System: Linux *buntu

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

Post by machineghost » Wed Aug 28, 2019 5:55 am

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.

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

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

Post by steve » Wed Aug 28, 2019 8:04 am

machineghost wrote:
Wed Aug 28, 2019 5:55 am
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.
machineghost wrote:
Wed Aug 28, 2019 5:55 am
do you by any chance know of a way to return the focus back to the original track?
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: https://bugzilla.audacityteam.org/show_bug.cgi?id=2115
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

machineghost
Posts: 67
Joined: Wed Sep 05, 2018 5:00 pm
Operating System: Linux *buntu

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

Post by machineghost » Wed Aug 28, 2019 3:36 pm

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!

Post Reply