Export individual label when multiple labels in project

Share your Audacity/Nyquist plug-ins here, or test drive the latest plug-ins submitted by Audacity users.

After testing a plug-in from this forum, please post feedback for the plug-in author.
agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Export individual label when multiple labels in project

Post by agua » Wed Sep 30, 2020 8:42 pm

Is there any project to make export multiple label tracks separately possible in a near future ? The process of temporarily deleting other label tracks to export one separately and then undo the deletes is a bit unatural, to say the least. Would it be difficult to enable this separate export feature ?
If not a future target, is there a Nyquist code which could do it ?

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

Re: Export individual label when multiple labels in project

Post by steve » Wed Sep 30, 2020 9:32 pm

It could be done with a Nyquist plug-in, though I'm not aware of any existing plug-in that does that.
Have you used (programmed) Nyquist at all?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Thu Oct 01, 2020 1:39 am

Yes I have already coded a little with Nyquist, like making a plugin to export audio tracks with their name as filename. But I don't know what code to use for doing so to a label track. Could you help putting me on the right way to do it ?

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

Re: Export individual label when multiple labels in project

Post by steve » Thu Oct 01, 2020 12:20 pm

agua wrote:
Thu Oct 01, 2020 1:39 am
Could you help putting me on the right way to do it ?
Sure.

To get label data with Nyquist, use the "GetInfo:" scripting (Macro) command.
(https://manual.audacityteam.org/man/scr ... rence.html)

Try this in the Nyquist Prompt:

Code: Select all

;type tool
(setf label-data (aud-do-command "GetInfo:" :type "Labels" :format "LISP"))

(format nil "~a" label-data)
If the project contains label tracks, you will see a list printed.
The first item in the list is a list containing the label data. The second (final) element is "T".

Because "label-data" is a Lisp list, you can access the first element with (first label-data)

Example:
Trackpanel000.png
Trackpanel000.png (22.6 KiB) Viewed 687 times

Code: Select all

;type tool
(setf label-data (aud-do-command "GetInfo:" :type "Labels" :format "LISP"))

(format nil "~a" (first label-data))
Returns:

Code: Select all

((1
    ((0 0 "Start")
      (180 180 "Middle")
      (360 360 "End")))
  (2
    ((120 180 "Hello")
      (180 240 "World"))))
Notice that the first item in this list is the first label track, and the second item is the second label track.

To get the label data for the second label track, you could use:
(second (first label-data))
which gives the list:
(2 ((120 180 "Hello") (180 240 "World")))
where the first item is the track index (zero indexed, so "2" = third track)
and the second item is the labels:
(list 120 180 "Hello")
and
(list 180 240 "World")

------------------

To write a text file to disk, see: https://www.audacity-forum.de/download/ ... ef-190.htm
You can use the FORMAT command to write to the file pointer.
Example:

Code: Select all

(setf file-pointer (open "C:\output directory\test-file.txt" :direction :output))
(format file-pointer "text to write to the file")
(close file-pointer)
------------------

For the plug-in's GUI, you will probably want to use the "file widget".
This is the most complex Nyquist widget, but it is well documented:
  1. https://wiki.audacityteam.org/wiki/Nyqu ... ce#widgets
  2. https://wiki.audacityteam.org/wiki/Nyqu ... ton_Widget
  3. https://wiki.audacityteam.org/wiki/Nyqu ... n_Tutorial
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Thu Oct 01, 2020 4:44 pm

Thanks a lot, Steve. I'll work on this and let you know how it come out. :))

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Thu Oct 01, 2020 5:34 pm

Hi, Steve. Is there a Nyquist way to get the name of the currently selected label track (assuming I select only one at a time) ?

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

Re: Export individual label when multiple labels in project

Post by steve » Thu Oct 01, 2020 5:53 pm

agua wrote:
Thu Oct 01, 2020 5:34 pm
Hi, Steve. Is there a Nyquist way to get the name of the currently selected label track (assuming I select only one at a time) ?
There's the Macro / Scripting command: GetInfo: Type="Tracks"

You can call that command like this:

Code: Select all

 (aud-do-command "GetInfo:" :type "Tracks" :format "LISP")
or a slightly simpler (more convenient) way:

Code: Select all

(aud-get-info "Tracks")
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Thu Oct 01, 2020 10:10 pm

Hi Steve. I think I am almost there, but still cant solve the filename problem with backslashes... Here is my code :

Code: Select all

(setq exportableLabelTrack "none")
(let ((tracks (aud-get-info "tracks")))
 (dotimes (j (length tracks))
  (setf track (nth j tracks))
  (setf isSelected (if (= 1 (second (assoc 'selected track))) "oui" "non"))
  (setf isLabel (if (equal "label" (second (assoc 'kind track))) "oui" "non"))
  ;(print (strcat (second (assoc 'name track)) "/selected:" isSelected "/islabel:" isLabel))
  (setf bothYes (strcat isSelected isLabel))
  (cond ((equal bothYes "ouioui")
    (print (second (assoc 'name track)))
	( setq exportableLabelTrack (second (assoc 'name track)))
    )
	;(t (print bothYes))
  )
 )
)
(cond ((not(equal exportableLabelTrack "none"))
    (setf filename "D:\\Myproject\\tests\\test-file.txt")
    (setf file-pointer (open filename :direction :output))
    (format file-pointer exportableLabelTrack)
    (close file-pointer)
    (print exportableLabelTrack)
	)
)
It does not work with simple backslashes either, nor with *file-separator* audacity variable. Would you have a workaround I could use ?
Also, I don't know yet how to get the label track text content once I know which track it is (as I did above)... that's why I temporarily just put the trackname as content.

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

Re: Export individual label when multiple labels in project

Post by steve » Fri Oct 02, 2020 3:50 pm

I'll put together some code for you, but may not be until after the weekend (I'll do it sooner if possible).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Fri Oct 02, 2020 4:26 pm

This is extremely kind of you, Steve, I appreciate a lot as it is an operation I have to do a lot in musical arrangements. I wish I were more at ease with Nyquist, but it seems difficult if not practiced regurlarly... ;)

Post Reply