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.
Samse26
Posts: 78
Joined: Tue Nov 27, 2018 12:05 pm
Operating System: Windows 8 or 8.1

Re: Export individual label when multiple labels in project

Post by Samse26 » Wed Apr 14, 2021 4:54 pm

OK OK - user error.
It seems that the destination directory has to exist. It didn't (C:\tmp, not C:\temp), hence the macro bailed out.
Would be nice to provide either an explanatory message or document in the code that this is a requirement.

On a sidenote I found that the label names don't get correctly exported if they contain non-ASCII characters (e.g. German umlauts: replaced by underscore) or double quotes (first occurrence replaced by \ and following text truncated).
Given Steve's comment on Nyquist's limitations on string processing (and my limitations on NYquist programming), I won't venture into fixing the code ;)
I'm just stating this here to set expectations for future potential users.
I will therefore revert to the "classical" way of exporting single label tracks (close all but one, export, undo closing).

steve
Site Admin
Posts: 81281
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 Apr 14, 2021 7:12 pm

Samse26 wrote:
Wed Apr 14, 2021 4:54 pm
It seems that the destination directory has to exist. It didn't (C:\tmp, not C:\temp), hence the macro bailed out.
Would be nice to provide either an explanatory message or document in the code that this is a requirement.
A related problem is that the code will only work on Windows ("C:\" does not exist on Mac or Linux), and there is no guarantee that "C:\tmp" will be writeable.

A simple solution would be to query Audacity for the location of the "Documents" directory (which should be writeable on all platforms):

Code: Select all

(setf savepath (string-right-trim "\/"(get '*system-dir* 'documents)))
To be absolutely sure that the output directory is writeable, a test function could be added:

Code: Select all

(defun iswriteable (path fname)
  ;; Return T if path is writeable, else NIL.
  (setf path (string-right-trim "\/" path))
  (setf path (format nil "~a~a~a"
                  path *file-separator* fname))
  (let ((fp (open path :direction :output))
       rslt)
    (if fp
        (progn (close fp)
          t)
        nil)))

(print (iswriteable "C:\tmp" "test.txt"))
However, the above code will create a zero byte file "C:\tmp\test.txt" if the directory is writeable, so in practice it would be better to use the actual filename that you intend to write to.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply