Foobar2000:Title Formatting Introduction

From Hydrogenaudio Knowledgebase
Revision as of 20:50, 22 May 2005 by Foosion (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

Just text

foobar2000 uses titleformat scripts in several places. For example, you can customize the format of the playlist or the statusbar. The simplest thing you can do, is display some static text:

 This text will be displayed as-is.

Admittedly, this is pretty boring and you probably will not want to use this on its on. There is one more thing worth noting before we move on to more interesting things. Titleformat code uses some special characters which cannot be used in plain text, but you can use them inside single quotes:

 'These characters normally have special meaning: ( ) , [ ] $ %'

Single quotes, percent signs and ampersand can be included in the output, by doubling them outside single quotes.

Note that linebreaks will not appear in the output, unless they occur within single quotes:

 This is the
 first line.
 'This will stretch
 to the second line.'

Note that multiline scripts cannot be used everywhere; in the default components, they can be used for the text on the icon in the system notification area ("systray") and in the copy command script. The playlist and other singleline displays will truncate strings with line breaks, and would display the above example like this:

 This is the first line. This will stretch (...)

Song information

Titleformat scripts would be quite useless, if you could not display information about songs. To access the value of the "title" tag, you would write "title" in percent signs:

 %title%

Actually, the above is a little smarter than just using looking at the "title" tag. If the title tag is missing, it will use the filename instead. There are several of this field remappings that are intended to make your life a little easier; among them are %artist%, %tracknumber%, %playlist_number% and of course %title%.

A name written inside percent signs will generally try to look up the tag of the same name, unless it is one of the aforementioned remapped fields. Even in this case you can use the unaltered value of the tag:

 $meta(title)


A simple playlist script

Let's look at a simple script for the playlist:

 %playlist_number%. %artist% - %title%

This is nothing fancy. It displays the index of the track in the playlist, padded with zeros to make it the same length for all playlist entries. After that comes the artist and the title of the track. However, if there is no artist tag, this will just display a question mark, as it happens with all fields that cannot be found. To avoid this, we can put the part of the script that displays the artist tag in brackets. That way, it will only be displayed, if the tag is found.

 %playlist_number%. [%artist% - ]%title%

It would be nice, if we could show the length of a track in the playlist. No problem, the %length% field gives us the song length nicely formatted as minutes and seconds. It will even show hours, if the song really is that long. To make things a little nicer, we will make the length displayed on the far right of the playlist. All we have to do is to include a tabulator character before %length%. The $tab() function will do this for us.

 %playlist_number%. [%artist% - ]%title%
 $tab()
 %length%

If the song length happens to be unknown, this will display a question mark. That might happen with web streams, and to make this a little clearer, we will display "unknown length" instead. To test if the length field exists, we can use the $if2 function. This function takes two parameters. If the first parameter contains at least one valid field, it will return the value of that parameter. Otherwise, it will return the value of the second parameter.

 %playlist_number%. [%artist% - ]%title%
 $tab()
 $if2(%length%,unknown length)

Technical information

Technical information can be accessed in similar way as tags, either using %__name% or $info(name) where the name is one of those that can be seen in the "Other info" part of the properties window in foobar2000. There are some field remappings for technical information as well, for example %bitrate% gives you the average bitrate of a song or the current dynamic bitrate, if the song is playing, provided that the format supports reporting the dynamic bitrate.