Create Label for Each Clip in Track

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
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
Post Reply
anthonyt
Posts: 3
Joined: Tue Aug 01, 2017 6:48 pm
Operating System: Windows 7

Create Label for Each Clip in Track

Post by anthonyt » Tue Aug 01, 2017 6:57 pm

I'm looking for a plug-in that will create a label for each clip on a particular track. For example, on track one, I have split the .wav into five pieces. Clicking on the menu item for this hypothetical plug-in it should create a corresponding label on a single label track for each clip.

If this has been built before, I'd love to hear about it.

In the meantime, I've been going through the board and found a smattering of create label plug-ins which I can leverage but can't find anything to just loop through a track and identify each clip/clip boundary. I'm new to Audacity and Nyquist so I might not be using the right nonmenclature.

Any guidance you could give me would be appreciated.

anthonyt
Posts: 3
Joined: Tue Aug 01, 2017 6:48 pm
Operating System: Windows 7

Re: Create Label for Each Clip in Track

Post by anthonyt » Tue Aug 01, 2017 9:24 pm

I have gotten a little farther down the road. I can print out the list of clip start/end times and I can add a label but when I combine the two within a loop, it just ignores the list command (no error message). Any insight?

(setf mylist (get '*track* 'clips))

(print
(dolist (x mylist)
(print x)
(list (list x "label") )
(setf i (1+ i))))

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

Re: Create Label for Each Clip in Track

Post by steve » Tue Aug 01, 2017 9:25 pm

Until recently, that would not have been possible.
In "version 4" plug-in code, you can get the times for start and end of audio clips from the *TRACKS* property list.
For more info, see: http://wiki.audacityteam.org/wiki/Nyqui ... 2ATRACK.2A

Some info about creating labels: http://wiki.audacityteam.org/wiki/Nyqui ... urn_Values

Is that enough? Ask if you get stuck.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Create Label for Each Clip in Track

Post by steve » Tue Aug 01, 2017 10:22 pm

Crossed posts.
anthonyt wrote:(setf mylist (get '*track* 'clips))

(print
(dolist (x mylist)
(print x)
(list (list x "label") )
(setf i (1+ i))))
You're pretty close.
To create the labels, you need to return the specially crafted "list of lists". You don't need to print it.

Assuming that you are dealing with mono tracks, "mylist" in your example should look something like this:

Code: Select all

(setf mylist (get '*track* 'clips))
(print mylist)
Debug output:

Code: Select all

((0 1.9127) (2.84981 5.08344) (5.08344 6.53402) (7.00899 9.99998))
So this is a list containing lists with the start and end times of each clip. In fact, that is very nearly what we want.

To create labels, what we want is:
((0 1.9127 "string") (2.84981 5.08344 "string") (5.08344 6.53402 "string") (7.00899 9.99998 "string"))

Because we want to modify each list within the list, it's easier to do this with a DO loop rather than DOLIST.
I've added some comments to this code, but if you need clarification about it, just ask.

Code: Select all

;version 4
(setf label-string "Clip")

(let ((cliplist (get '*track* 'clips))
      labels) ;local variable = NIL
  (do ((i 0 (1+ i)))
      ((not (nth i cliplist)) labels)  ;return value is 'labels'
    ;; create the label and push onto "labels" list
    (push (append (nth i cliplist) (list label-string))
          labels)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

anthonyt
Posts: 3
Joined: Tue Aug 01, 2017 6:48 pm
Operating System: Windows 7

Re: Create Label for Each Clip in Track

Post by anthonyt » Wed Aug 02, 2017 7:52 am

This was awesome! Thank you, Steve.

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

Re: Create Label for Each Clip in Track

Post by steve » Wed Aug 02, 2017 9:48 am

Did you understand the code? If not, I'd be happy to answer questions.
If you'd be interested in making it into an installable plug-in (that just needs a few more headers adding), and support for stereo tracks (that needs "(get '*track* 'clips)" to be handled fully), then I think it could be a useful tool for other and could be uploaded to the Audacity wiki plug-ins page. No problem if not - that was just a thought ;)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply