Easy way to put Selection Toolbar info into export filename?

Effects, Recipes, Interfacing with other software, etc.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Easy way to put Selection Toolbar info into export filename?

Permanent link to this post Posted by frew_frew » Sat Feb 04, 2017 5:31 pm

Hello,

In Audacity I'm wondering if there's any trick to be able to quickly and easily put
into the clipboard the time and length of a selected area.

What I do a lot these days is I browse recordings that I've done, and I
File> Export Selected Audio to a wav or mp3.

In the filename I put the selection start and the selection length,
for reference, in order to easily get back to that particular selected area
if I should ever want to, rather than saving the whole project file
(in order to save disk space), for example:

PJ_1-25-17_1_6m_23_166_len10_974.wav

6m_23_166_len10_974 is the part I'd love to be able to put into the clipboard
or something like that. For example, perhaps 6:23.166 10.974, etc.,
so I can just paste it into the filename, to ease my workflow so i don't have to
manually look to see what the start and length is each time I wish to put that
info into the exported mp3/wav filename. It's kind of a lot of looking back and
forth between the Selection Toolbar and the Export Selected Audio dialog box
filename each time I save a selection to mp3/wav.

For example, one thing I'm wondering is, when I go
Edit> Region Save
where is that data stored?
If I could access that, it may be useful for me.

What would you do in a situation where you want to create many, many
individual files using File> Export Selected Audio, and where you want
the individual filenames to contain the precise start and length of the
selected area of the Audacity project file?

Thanks for any ideas,

frew
frew_frew
 
Posts: 30
Joined: Mon Jan 02, 2017 5:55 pm
Operating System: Windows XP

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by Robert J. H. » Sun Feb 05, 2017 5:39 pm

Hi
Have you tried using labels and multiple export?

Here's some code for the Nyquist prompt as a proof of concept.
Code: Select all
(let* ((start (get '*selection* 'start))
   (end (get '*selection* 'end))
   (content (format nil "~a ~a" start end)))
 (list (list start end content)))


What it does:
- you first have to select a region.
- Then open the Nyquist prompt (under effects) and paste the code.
- Press OK
- A label track is being created with a label that has as only text content the start and end time of the region you had selected.

Now, you can make another selection and press "Ctrl+R"
Make sure that the label track is selected as well, otherwise you'll get a new one with a single label.

This can also be made into a plug-in in order to avoid opening the Nyquist prompt each time at first usage or if you do something else between labelling.

You can also add non-changing text within the quotes after '(format ....', e.g.
Code: Select all
(format nil "Project0114-02-16 ~a S ~a E ~a Len" start end (- end start))


The track title can be added automatically, only the date must be entered manually.

The times are in seconds and if you want it formated, it will need some special code to e.g. extract hours and minutes. Not a big deal though.

There's also a way to just display the start and end times (or the length) if you prefer to copy them manually.

Robert
Robert J. H.
 
Posts: 1813
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 7

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by Gale Andrews » Mon Feb 06, 2017 1:23 am

Hi Robert

Unless the selection is at the start of the track, the label seems to be placed after the end of the selection.


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26093
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by Robert J. H. » Mon Feb 06, 2017 6:19 am

Gale Andrews wrote:Hi Robert

Unless the selection is at the start of the track, the label seems to be placed after the end of the selection.


Gale

I think it's a bug in that the times are stretched, with regard to the selection length.
I get the absolute times of the selection but on return they are scaled somehow or rather the start time seems to be added a second time.

Put the whole code within 'abs-env' like this:
Code: Select all
(abs-env
   (let* ((start (get '*selection* 'start))
      (end (get '*selection* 'end))
      (content (format nil "~a ~a" start end)))
    (list (list start end content))))


Does this the trick for you?
Robert J. H.
 
Posts: 1813
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 7

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by steve » Mon Feb 06, 2017 11:27 am

Gale Andrews wrote:Unless the selection is at the start of the track, the label seems to be placed after the end of the selection.

The code correctly finds the start and end time of the selection, but these are not the correct times for the label placement.
When Nyquist returns labels to Audacity, Audacity interprets the start/end times as relative to the start of the selection.

For correct label placement, the numeric element(s) of the label must be relative to the start of the selection. Two examples are given below:
Code: Select all
(let* ((start (get '*selection* 'start))
       (end (get '*selection* 'end))
       (content (format nil "~a ~a" start end)))
  (list (list (- start start) (- end start) content)))

Code: Select all
(let* ((start (get '*selection* 'start))
       (end (get '*selection* 'end))
       (content (format nil "~a ~a" start end)))
  (list (list 0 (get-duration 1) content)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44458
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by frew_frew » Tue Feb 07, 2017 2:52 am

Robert J. H. wrote:Here's some code for the Nyquist prompt as a proof of concept


Thanks for pointing me in this direction.
I'll explore it further.

steve wrote:For correct label placement, the numeric element(s) of the label must be relative to the start of the selection. Two examples are given below


Yes thanks, these work to place the labels in the right spot.

Again my original goal is to easily paste the start/end times of a selection
(or the start/duration times) into a filename at the save dialog.

Now I'm wondering if it might be somehow easier to have these times automatically
put into the label names during an Export Multiple.

So for now I guess copy and paste the label into the filename, but not sure if that is much easier
than just looking at the Selection Toolbar and typing them into the filename.

It would be great to have the times formatted as hh:mm:ss + milliseconds

I know that's a lot to ask so not really expecting all that.
But just wondering if there were a relatively easy way.
Seems like many would find this to be a useful Audacity feature.
Especially for those creating lots of loop extracts from long recordings,
where a reference to the time position of the loop in the original recording
is placed directly into the filename of the exported loops.

Thanks for any other ideas.

frew
frew_frew
 
Posts: 30
Joined: Mon Jan 02, 2017 5:55 pm
Operating System: Windows XP

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by steve » Tue Feb 07, 2017 8:38 am

frew_frew wrote:So for now I guess copy and paste the label into the filename

Export Multiple can use the label text, if you are exporting based on labels: http://manual.audacityteam.org/man/expo ... .html#name
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44458
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by steve » Tue Feb 07, 2017 9:34 am

frew_frew wrote:It would be great to have the times formatted as hh:mm:ss + milliseconds

Try this:

Code: Select all
(setf decimal-places 3)

(defun format-time (sec)
  (setf *float-format*
    (format nil "%.~af" decimal-places))
  (let* ((hh (truncate (/ sec 3600)))
         (sec (- sec (* hh 3600)))
         (mm (truncate (/ sec 60)))
         (sec (- sec (* mm 60))))
    (cond
      ((> hh 0)
        (format nil "~ah:~am:~as" (dd hh) (dd mm) (dd sec)))
      ((> mm 0)
        (format nil "~am:~as" (dd mm) (dd sec)))
      (t
        (format nil "~as" (dd sec))))))

(defun dd (n)
"pads n if required for double digit"
  (if (< n 10)
      (format nil "0~a" n)
      n))

(let* ((start (get '*selection* 'start))
       (end (get '*selection* 'end))
       (content (format nil "~a ~a"
                        (format-time start)
                        (format-time end))))
  (list (list 0 (get-duration 1) content)))


If you want to turn this code into a plug-in so that it can be installed for easy use, you just need to add the required "headers". See: http://wiki.audacityteam.org/wiki/Nyqui ... _Reference

Topic moved to the "adding features" section.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44458
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by Gale Andrews » Tue Feb 07, 2017 5:02 pm

steve wrote:Topic moved to the "adding features" section.

Is the feature request to make the code snippet an Audacity effect, or to have an option for Export Selected Audio to offer the selection start and end and length as file name?

Can we justify the latter as an option, given there is little time saving unless you want to export multiple selections? In that case you can use Export Multiple with this snippet.



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26093
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Easy way to put Selection Toolbar info into export filen

Permanent link to this post Posted by steve » Tue Feb 07, 2017 6:56 pm

frew' requested (an) "Easy way to put Selection Toolbar info into export filename"

Frew gave a very detailed use case in the first post, then described a more general use case:
(for) "those creating lots of loop extracts from long recordings,
where a reference to the time position of the loop in the original recording
is placed directly into the filename of the exported loops."


I'm not sure that I'd described asking users to type, or even copy/paste thirty lines of code into the Nyquist Prompt, as an "easy way", though the code could be made into a plug-in, and that may suffice.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44458
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Next

Return to Audio Processing



Who is online

Users browsing this forum: No registered users and 6 guests