SYNOPSIS

  # E.g.: current directory contains 1 subdirectory-per-performer.
  # Inside each directory the structure is
  #   Composer/single*.mp3         (fine-grain output: <title> field)
  # and
  #   Composer/MultiPart/part*.mp3 (fine-grain output: <album> field)
  # Emit year and duration info; use "Quartets" as basename
  typeset_audio_dir -y -T -B Quartets *

  # Likewise, but this directory structure is w.r.t. current directory;
  # Do not emit year and duration, output to STDOUT
  typeset_audio_dir .
  typeset_audio_dir

  # Use artist as toplevel heading, album as the 2nd level; use track numbers;
  # name is based on title for any depth in directory hierarchy;
  # likewise for generation of 2nd level heading.  Mark audios with lyrics
  typeset_audio_dir -ynTL -P long -B All

  # Likewise, but the name is based on the album; ignore comments
  typeset_audio_dir -yTn -P short -B All_short

  # Likewise, but produce both long and short listings.  The short one serves
  # as a table-of-contents for the long one
  typeset_audio_dir -ynTL -P short,long -B All

DESCRIPTION

Scans directory (or directories) given on the command line, using MP3::Tag to obtain information about audio files (to process non-MP3 files, extra modules may be needed, see MP3::Tag, and -r \s-1FILENAME_FILTER\s0 option must be given). Produces (one or more, depending on -B option) TeX files with commands to typeset human-readable listings. Non-directories on the command line are ignored. (May also be used to process non-audio files, if MP3::Tag may extract the title/etc info from them.)

With -B, the file *_list.tex contains all the data about audio files (when -P with both \*(C`short,long\*(C' is given, another similar file *_list_long.tex is also written); the file *_titles.tex contains a 0th approximation to the possible \*(L"title\*(R" of the collection (one based on -N option and a short summary of toplevel directories). The file *_common.tex contains macros common for the following files. The remaining files define different environments to typeset the listing (including two TeX files with \*(L"content\*(R" as needed): a \*(L"normal\*(R" listing (for A4/Letter, *_text.tex), two flavors of a \*(L"compressed\*(R" listing (for jewel case insert, *_cdbooklet.tex and *_cdcover.tex), and a back insert for the jewel case (*_backcover.tex).

The intent is to support many different layouts of directories with audio files with as little tinkering with command-line options as possible; thus \*(C`type_audio_dir\*(C' tries to do as much as possible by guestimates. Similtaneously, one should be able to tune the script to handle the layout they have.

The script emits headers for several levels of \*(L"grouping\*(R". The \*(L"toplevel\*(R" group header is emited once for every \*(L"toplevel\*(R" directory (with audio files), further headers are emited based on changes in descriptors of the audio files during scan.

OPTIONS

-B

gives basename of the output file. Without this option the script will output to \s-1STDOUT\s0. With this option, script separates the layout from content, and produces 6 TeX files: basename_text.tex basename_cdcover.tex basename_cdbooklet.tex basename_backcover.tex basename_list.tex basename_titles.tex basename_common.tex The last file contains the common macros needed for typesetting. The previous two files contain the information about audio files encountered. The others files contain frameworks to typeset this information. The first four files are supposed to be human-editable; they will not be overwritten by a following rerun with the same basename given to the script. By editing these files, one can choose between several encodings, languages, multicolumn output, font size, interline spacing, margins, page size etc. The \*(C`*_titles.tex\*(C' file is of mixed nature: it reflects the content of audio files, and is supposed to be human-editable. It will be overwritten unless it is Read-Only; so if you hand-edit it, make it Read-Only. Similar overwrite logic is applied to \*(C`*_common.tex\*(C' file too. a shortcut to setting hairy options; currently, two values of \*(C`plan\*(C' are supported: short => -1 "" -2 "" -t -1e100 -a -1e100 -c long => -1 "" -2 "@l" -t 1e100 -a 1e100 for generation of short/long listings. In the short listing, records correspond to the album names. In the long listing, records correspond to individual files, and album names serve as second-level headings.

-y

Emit year (or date) information if present. Very long date descriptors (e.g., when multiple ranges of dates are present) are compressed as much as possible.

-Y

Emit the whole date information if present.

-T

Emit duration information.

-n

Enable emit track number. Environment variable \s-1TYPESET_AUDIO_TRACK\s0 may contain the format to interpolate for typesetting (defaults to \*(C`%{mA}%{n1}\*(C'). For example, set \s-1TYPESET_AUDIO_TRACK\s0 to \*(C`%{n1}\*(C' to use \*(L"pure\*(R" track number instead of combination of media/disk number and track number.

-1

Toplevel header format; is interpolate()d by MP3::Tag based on the content of the first audio file encountered during scan of this toplevel directory. The empty value is the default; in this case the header is based on the name of the directory (with some normalization: underscore is converted to space).

-2

Second-level heading format; is interpolate()d by MP3::Tag. Calculated based on the content of each audio file. The heading is emited when the interpolated value changes (subject to option -a). Empty string disables generation.

-a

Ignore changes to the second-level heading for directories deeper than this inside top-level directory. Defaults to 2. For example, in Performer/Composer/Collection/part1.mp3 Performer/Composer/Collection/part2.mp3 Performer/Composer/single1.mp3 Performer/Composer/single2.mp3 if the toplevel directory is Performer, then changes of the second-level header in single*.mp3 would create a new second-level heading. However, similar changes in part*.mp3 will not create a new heading. \s-1NOTE:\s0 maybe this default of 2 is not very intuitive. It is recommended to explicitly set this option to the value you feel appropriate (1e100 would play role of infinity - so any change will generate a new second-level heading).

-t

The title-cutoff depth (w.r.t. toplevel directory). Defaults to 2. In audio files deeper than this the album %l is used as the name; otherwise the title %t of the audio file is used. Set to \*(C`-1e100\*(C' to always use %l, and to 1e100 to always use %a.

-@

Replace all \*(C`@\*(C' by \*(C`%\*(C' in options. Very useful with \s-1DOSISH\s0 shells to include \*(C`%\*(C'-escapes necessary for MP3::Tag's interpolate().

-e \s-1ENCODINGS\s0

Sets encodings for output files, directory names (when uses to generate headings), and hint files. \s-1ENCODINGS\s0 is a comma-separated list of directives; each directive is either an encoding name (to use for all targets), or \*(C`TARGET_LETTERS:encoding\*(C'. Target letters are \*(C`o\*(C', \*(C`d\*(C', and \*(C`h\*(C' for output, names of directories, and files .top_heading correspondingly. Use 0 instead of an encoding to do byte-oriented read/write.

-c

What to use as \*(L"comment\*(R" for a record (a part which is typeset differently). If not given, the ID3v2 frame \*(C`TXXX[add-to:file-by-person,l,t,n]\*(C' is used. If the content of this field is contained at end of the title, nothing is added, just this part is typeset differently.

-L

Mark files with embedded (un)syncronized lyrics and pictures. Put the explanation of used symbols at the end of the listing.

-N \s-1COLLECTION_NAME\s0

(defaults to \*(L"\s-1COLLECTION\s0\*(R") the name of the collection to insert into the file *_title.tex. The interaction with encoding may be less than intuitive; you may want to check/edit this file for corrections.

-F \s-1FONT_ENCODING_SYMBOL\s0

(defaults to \*(C`T2A\*(C'): the name of \*(C`LaTeX\*(C' font encoding. If your installation is broken and \*(C`T2A\*(C' is not available, you may try \*(C`T1\*(C' or \*(C`OT1\*(C'. See \*(L"\s-1PROBLEMS\s0 when \s-1TYPESETTING\s0\*(R".

-r \s-1FILENAME_FILTER\s0

sets the regular expression for filenames to look for (the default is \*(C`(?i:\.mp3$)\*(C'.

Info read from file system

The following files are used to give hints to typeset_audio_dir:

.content_comment

Content of this file is used as a comment field in the output for all files in this directory.

.top_heading

If empty, indicates that when the depth of files modifies the output, it is calculated w.r.t. the subdirectories of the directory of this file (ouph!). If contains a number, it is added to this depth. Example: suppose your section heading is based on directory names. Suppose the directory tree to process contains a directory Mixed/2009. If you want names of subdirectories of this directory to become section headings, make file Mixed/2009/.top_heading which contains 0. If the same holds for other subdirectories of Mixed, instead of creation of such file in all year-subdirectories, one can make file Mixed/.top_heading which contains \*(C`-1\*(C'. Otherwise the content of this file is used as a toplevel heading for this directory.

TYPESETTING

Running this script will only generate necessary TeX files, but will not typeset them (they will look much better if you first edit the files to suit your needs). Recall how to typeset TeX documents (here we assume \s-1PDF\s0 target):

latex document.tex && dvips document.dvi && ps2pdf document

(a lot of temporary files are going to be generated too; you can break this into multiple commands on \*(C`&&\*(C'). Some of the files (e.g., ..._cdcover.tex) fit better with landscape orientation; one needs

latex document.tex && dvips -t landscape document.dvi && ps2pdf document

With ..._cdbooklet.tex, for best result, one better should rearrange pages for booklet 2up 2-pages-per-side printing:

latex document.tex && dvips -t landscape -f < document.dvi | psbook | pstops "2:0(0,-6cm)+1(0,6cm)" > document.ps && ps2pdf -dAutoRotatePages=/None document

(all on one line, or give 3 separate commands, breaking on \*(C`&&\*(C'; more details on running dvips is put in the beginning of the TeX file). If you can easily print a .ps file, you can omit the last step. (The option \*(C`-dAutoRotatePages=/None\*(C' interferes with viewing; one may omit it unless one does \*(L"extra flipping of even pages\*(R", as below.)

Note that this assumes that when you send files to printer you request duplexing with \*(L"binding on the short side of paper\*(R". If you printer can survive manual duplexing, do as usual: print first the even pages in opposite order, reload paper, then print odd pages (you need to understand in which orientation you must put paper back when reloading; there are 4 variants, and only one is correct ;-). For \*(L"real\*(R" duplex printers, see below.

PROBLEMS when TYPESETTING

incomplete installations

! Font T2A/cmr/m/n/10.95=larm1095 at 10.95pt not loadable: Metric (TFM) file not found. For best multilanguage coverage I could find, by default the generated LaTeX files use \*(C`T2A\*(C'-encoded-fonts with extra Latin characters provided by \*(C`textcomp\*(C'. Apparently, some \*(C`TeX\*(C' installations omit \*(C`T2A\*(C' encoding tables. You may want to change \*(C`T2A\*(C' to, e.g., \*(C`T1\*(C' by using option \*(C`-F T1\*(C'.

In a booklet, page 1 is at end, the rest is a mess

The \*(C`landscape\*(C' option of \*(C`geometry\*(C' package should rotate the page 90 degrees. Depending on the way it is configured, the direction of rotation varies. If .pdf file obtained with \*(C`-dAutoRotatePages=/None\*(C' option has top of page on the left, you may need to invert the direction of shifting: instead of \*(C`2:0(0,-6cm)+1(0,6cm)\*(C' one should use \*(C`2:0(0,6cm)+1(0,-6cm)\*(C'. By default, most duplex printers are configured to \*(L"bind on the long side of paper\*(R"; so to avoid manual setup of binding options, you may want to flip even pages in the generated file. To do this, add an extra ps2ps step at the end of pipeline, e.g.: ... psbook | pstops "2:0(0,-6cm)+1(0,6cm)" | pstops "2:0,1U(1w,1h)" > document.ps

A4-sized paper vs. Letter-sized paper

Some TeX/PS installations do not have correctly set-up site configuration files, so do not know what is the usual paper size on your printer. Fortunately, all steps of the typesetting pipeline allow a manual reconfiguration. Unfortunately, command options for the required reconfigurations are subtly different for different steps. For example, if your TeX/PS-utils think that your paper size is \*(C`letter\*(C', while what you actually print to is \*(C`a4\*(C', you need to do the following (depending on which configuration files are broken, you might be able to omit some modifications):

1.

Add \*(C`a4paper\*(C' to the \*(C`\usepackage[...,...]{geometry}\*(C' options (the comma-separated list in brackets) in TeX files which use \*(C`geometry\*(C'.

2.

Add \*(C`-t a4\*(C' as a \*(C`dvips\*(C' options.

3.

Add \*(C`-pa4\*(C' as a \*(C`pstops\*(C' option. (If it breaks rotation, omit it, sigh!)

4.

Add \*(C`-sPAPERSIZE=a4\*(C' as a \*(C`ps2pdf\*(C' option.

Example commandline working with some of complications dvips -t landscape -f < All_cdbooklet-a4.dvi | psbook | pstops -pa4 "2:0(0,-6cm)+1(0,6cm)" | pstops -pa4 "2:0,1U(1w,1h)" > Output-even_flipped-a4.ps && ps2pdf -sPAPERSIZE=a4 -dAutoRotatePages=/None Output-even_flipped-a4 Likewise, quite often one needs to add \*(C`-pletter\*(C' to \*(C`ps2ps\*(C' commandlines for correct printing to letter-size paper. You can check the resulting \s-1PDF\s0 file in a viewer: the status line should show the correct paper size (e.g., 8.5in x 11in is \*(L"Letter\*(R"), even pages should be flipped (for binding \*(L"on the long side\*(R"), and the wireframes on different pages should be positioned exactly at same positions (for visual verification, choose \*(L"fit-to-page\*(R" scaling, and quickly switch pages back-and-forth by keyboard or by \*(L"Next page\*(R" button).

Warnings from dvips

Note also that if your \*(C`TeX/dvips\*(C' installation is completely correct, you can remove \*(C`-t landscape\*(C' from your \*(C`dvips\*(C' command line; not removing it would produce a warning \*(C`both both landscape and papersize specified: ignoring landscape\*(C'.

Systematic duplexing offset

Some printers can't reliably match positions on the front and back side when printing; there is little one can do with it. However, if your printer adds some consistent misplacement of front and back sides, one can put workarounds for it. For example, when \*(L"binding on the short side\*(R", the common error is that (in landscape orientation) backside is offset horizontally w.r.t. frontside. For example, if offset is 3.4mm to the left, one can shift the image on the page by half of this, 0.17cm to the left: replace "2:0(0,-6cm)+1(0,6cm)" by \*(L"2:0(0,-6.17cm)+1(0,5.83cm)\*(R". With \*(L"binding on the long side\*(R", the typical error is vertical offset. To work around, one needs to shift vertically (again, by half the amount) after flipping even pages. To shift 0.17cm up, add an extra step \*(C`pstops "(0.17cm,0)"\*(C' to the pipeline after the "2:0,1U(1w,1h)" step (untested).

HINTS

The default font sizes and density of type is chosen to optimize printing of a DL-DVD collection of short high quality audio (of song-like duration: about 100 subheadings, and 2000 audio files). You may improve the visual quality if you tune the typesetting to your particular needs.

The most commonly changed settings are on top of the generated files. These are fonts and degrees of vertical squeeze of paragraphs for the principal title, titles of sections (1st level) and subsections (2nd level), and of actual records emited for each audio file, as well as the number of columns. Slightly further in the file are settings for gaps to left around section headings, and for fine-tuning of squeezing.

Do not forget that if you can't describe a complicated layout by command-line options, you still have a possibility to run this script many times (once per directory with \*(L"handable layout\*(R", using -B and other options suitable for this subdirectory). Then you can use LaTeX \*(C`\input\*(C' directives to include the generated basename_list.tex files into the toplevel \*(C`LaTeX\*(C' file.

You can also redefine \*(C`\preSection * \postSection\*(C' to do nothing, and put the necessary code to generate the headers into the top-level file.

Modify the formatting macros to suit your needs. (Of more tricky stuff, mention \*(C`\squeezeContunuationLines\*(C' and \*(C`\parskip\*(C', which regulate the density of lines - without changing the line font; note that setting \*(C`\parskip\*(C' is a part of the action of \*(C`\squeezeContunuationLines\*(C'. \*(C`\columnsep\*(C' regulates the horizontal separation of columns. One can also fine-tune the vertical position of the start of the first page; for backcover, also tune up \*(C`\CDbackMargin\*(C' and \*(C`\CDbackTopMargin\*(C'. The definition(s) of \*(C`\squeezeContunuationLines\*(C' are commented out (by \*(C`%\*(C') in non-*_common.tex files; you may uncomment it, and tune it up separately for each TeX file.)

One can combine two (or more) lists (e.g., one with the short style, and one with the long style) into one output file; the generated files ..._cdbooklet.tex and ..._text.tex already have a necessary template (disabled) at the end. (Moreover, with -P \*(C`short,long\*(C', this is done automatically.

For example, with two lists created in \*(L"\s-1SYNOPSIS\s0\*(R", All_list.tex, and All_short_list.tex, find \*(C`\iffalse\*(C' near the end of All_short_cdbooklet.tex and change it to \*(C`\iftrue\*(C'; then change the name in the directive

\input{another_list}

to All_list

This will make the \*(L"short\*(R" cdbooklet become a kind of \*(L"table of contents\*(R" for the combined \*(L"short+long\*(R" cdbooklet. (Of course, one can change the values of macros \*(C`\SectionFont\*(C' etc, \*(C`\COLUMNS\*(C', type of squeeze to suit your needs - the point is that they should not be necessarily the same for the second list.)

WORKFLOW

The module is quite flexible; here is one of the possible workflows (suitable if all you need is -P <short> and -P <long>:

Put all the \*(L"toplevel\*(R" directories as subdirectories of the current directory (well, this is not really necessary!), and put the heading to use for each directory into a file .top_heading. You may need to specify the encoding used in this file into the options (do similar to \*(C`-e h:cp1252\*(C').