Moving direction of selection?

Hi there,

If I make a selection in a track dragging from left to right is it possible to change the selection from right to left from where the selection starts or left to right from where the selection ends? Could I do this with two different macros?

Best wishes

Joe

Selections may be adjusted using “Shift + Click and Drag”:

1.Make a selection (Click and drag) and release the mouse button.
2. Move the mouse pointer near to the start or end of the selection - whichever you want to adjust - no need to be exact.
3. Press and hold the Shift key
4. While holding down the Shift key, Click and drag.

Hi Steve,

Thank you for your explanation. I didn’t realise you can hold down Shift to enable the hand to change a selection. Is it possible though to swap the selection to the left or right of the cursor? If I select a section of a track and make a change, I was wondering if I could run a macro so that I deselect the selection and I am able to drag in the opposite direction? At the moment, once I’ve selected and made a change, I need to click on the track to deselect and then make a new selection dragging in the opposite direction. Is it possible to create a macro so I don’t need that extra click so the selected area swaps to the right or left of the cursor?

Best wishes

Joe

You shouldn’t need to hold down the shift

just hover near the edge of the selection till the pointing hand appears and then just click&drag to adjust the selection.

Peter

If the pointer is close enough to the edge of the selection, then the Shift key is not required, but when holding down the shift key you don’t need to be so precise. Without the Shift key, if you are not close enough to the edge of the selection, the selection may be lost.

I’m not sure what you are asking for here. If I select, for example the audio between 4 and 5 seconds and amplify, then I can then drag the cursor between say 3 and 4 seconds without needing an extra click.

However, if you want to select the one second of audio prior to your current selection:

On the Extras Menu (View > Extras Menu) > Scriptables II > Select. Then you could specify Start Time = -1, and Relative to Selection Start. Be sure to check those items you want and deselect those you don’t want, as this is not done automatically for you.

For a macro, you would issue the Select command and specify the same parameters.

Hi there,

I’ve created this short video to explain the functionality I’m looking for. I hope it clarifies things:
https://youtu.be/hCVhJ3raNfw

Best wishes

Joe

If you want the selection to be the same size, you can’t do that with a macro. A macro is just a list of commands.

You can easily do it with the mouse.

  1. Move the mouse pointer over the left edge of the selection so that the pointer turns into a pointing finger
  2. Click and drag to the right, past the right edge of the selection.
  3. Release the left mouse button.

(A similarly from right to left).

You can also do it with Nyquist.
This code can be run in the Nyquist Prompt.

;type tool
(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start)) 
  (aud-do-command "SelectTime:" :start end :end (+ end dur))
  "")

The above moves the selection to the right.
To move the selection to the left, modify the “aud-do-command” line.


For convenience, you could either,

  1. Turn the above code into a plug-in (see: https://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference) and install it.
  2. Create a macro containing the Nyquist Prompt with the above code.

You could also allocate a keyboard shortcut to the macro / plug-in (See: https://manual.audacityteam.org/man/keyboard_preferences.html)

Thanks for the advice as always, Steve. I’ve had a look at the link you shared https://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference Could you clarify how I can make these two NYQUIST plug-ins using your commands? How do I make an .ny file and where do I find the Plug in widgets dialogue box?

Best wishes

Joe

To make a Nyquist plug-in you will need a plain text editor. For Windows I recommend NotePad++.

To convert the code into a plug-in you need to add “headers” (see: Missing features - Audacity Support). Some headers are optional but there are 4 “required” headers that must be present.

When the headers are added, save the file with “.ny” as the file extension, then install it in the usual way.


What do you mean by “widgets dialogue box”?

Thanks Steve. So is this the code I need to add to Notepad+ +?

;nyquist plug-in
;name "Change direction"
;type tool
;version 1
(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start)) 
  (aud-do-command "SelectTime:" :start end :end (+ end dur))
  "")

The plug in widgets dialogue box I referred to is on this page:
https://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference

Best wishes

Joe

That looks like it should work.

Make that ;version 4 (all new plug-ins should be written in the latest version).

It is usual to have an empty line between the header and the code - that’s not required, but it helps readability to have a bit of space between blocks.

It is also recommended (but not required) to include:
;author (your name)
;copyright (the license, usually GPLv2+)
;release (a release version number for the plug-in)

So putting that all together would look similar to:

;nyquist plug-in
;name "Change direction"
;type tool
;version 4
;author "Your name here"
;copyright "GPL v2 or later"
;release 0.0.1

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start)) 
  (aud-do-command "SelectTime:" :start end :end (+ end dur))
  "")

A plug-in will have a dialogue box if it has any widgets to display.
The widgets are defined in the plug-in as “;control” header lines.

You could, for example, add a “choice” widget to select whether to move the selection to the left or to the right:

;control direction "Move selection to" choice "Right,Left" 0

and then modify the code so that it moves the selection in the direction selected by the user:

;nyquist plug-in
;name "Change direction"
;type tool
;version 4
;author "Your name here"
;copyright "GPL v2 or later"
;release 0.0.1

;control direction "Move selection to" choice "Right,Left" 0

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start))
  (if (= direction 0) ;right
      (aud-do-command "SelectTime:" :start end :end (+ end dur))
      (aud-do-command "SelectTime:" :start (max 0 (- start dur)) :end start))
  "")

However I suspect that it would be a better workflow to have two plug-ins, one to move the selection to the left, and one to move it to the right. You will then be able to assign a separate keyboard shortcut to each.

Hi Steve,

Thanks for the advice. How do I save as a .ny file in Notepad++? I’ve searched through the drop down menu of options under Save as type and can’t see the ny / Nyquist option. Can you clarify too what code I would need to move the selection to the opposite direction too? Thank you.

Best wishes

Joe

It’s been a long time since I’ve used NotePad++ (I’m on Linux), but if I recall correctly, you can just type the full name including file extension.


See the code in my previous post.
The “direction” variable is set by the “;control” line to a value of 0 (default: Right) or 1 (Left).
Later on in the code you will see:

(if (= direction 0) ...

which selects the first option if “direction” is equal to 0, otherwise the second option.

Hi Steve,

So I followed your advice and have been able to make an .ny file. I put it in the Audacity plug in folder along with the other plugins, but when I open the plugin manager, my new plugin doesn’t appear in the list. Any suggestions why?

So this is code I’m using:

;nyquist plug-in
;name "Change Direction"
;type tool
;version 4
;author "Joe Dale"
;copyright "GPL v2 or later"
;release 0.0.1

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start)) 
  (aud-do-command "SelectTime:" :start end :end (+ end dur))
  "")

I like your idea of creating two plugins, one to change direction from right to left and one from left to right. I’m just now sure of what code I need to do this.

I’ve really enjoyed learning new Audacity skills with you, btw.

Best wishes

Joe

Did you use the “Nyquist Plugin Installer” to do that? (See: Nyquist Plugin Installer - Audacity Manual)
(I wrote that tool because it was so common for people to get the wrong folder).

In recent versions of Audacity it is necessary to close and restart Audacity after adding a plug-in before it appears in the Effect Manager.
See the written instructions here (ignore the video, it’s out of date and wrong): Installing plugins - Audacity Support

I’ve now used the Nyquist Plugin Installer and it works!!! Thank you!!!

You’ve probably answered this already, but what do I need to change now in the code to allow me to change the selection in the opposite direction?

;nyquist plug-in
;name "Change Direction"
;type tool
;version 4
;author "Joe Dale"
;copyright "GPL v2 or later"
;release 0.0.1

(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))
  (setf dur (- end start)) 
  (aud-do-command "SelectTime:" :start end :end (+ end dur))
  "")

“aud-do-command” is a Nyquist command that sends a macro/scripting command from Nyquist to Audacity.

Macro / scripting commands each have:

  • A name, followed by a colon “:”
  • None or more keyword parameters (a “name / value” pair)

In this case, the command name is “SelectTime:” and it has key word parameters “start” and “end”.
The keyword names are written with a colon prefix, so they are:

:start <value> :end <vallue>



(let ((start (get '*selection* 'start))
      (end (get '*selection* 'end)))

These two lines set variables “start” and “end” to the start and end time of the current selection as it exists when the code is launched. The names “start”, “end” and “dur” are not magical, they could have been anything, for example we could have had:

(let ((beginning (get '*selection* 'start))
      (finish (get '*selection* 'end)))
  (setf duration (- finish beginning)) 
  (aud-do-command "SelectTime:" :start finish :end (+ finish duration))
  "")

or

(let ((t0 (get '*selection* 'start))
      (t1 (get '*selection* 'end)))
  (setf tr (- t1 t0)) 
  (aud-do-command "SelectTime:" :start t1 :end (+ t1 tr))
  "")

The important thing is that in the macro/scripting command to move the selection to the right, we set
“:start” to
and
“:end” to plus

The duration of the original selection is calculate as
minus

Obviously what we need to do to move the selection to the left is to set:
The important thing is that in the macro/scripting command, we set
“:start” to minus
and
“:end” to


I think you have enough information to work out how to write the “to the left” version. Have a go and post what you come up with.

I see that you posted while I was typing :wink:

When you post code in a forum post, use the “</>” button (above the message composing box).
That will enter “code” tags into your post, like this:

You can then add your code between the “" and the "” like this:

You code goes here.

and then the code is displayed properly with spacing preserved.