Foobar2000 Talk:Title Formatting Reference: Difference between revisions

From Hydrogenaudio Knowledgebase
(String Functions)
m (formatting)
 
(30 intermediate revisions by 6 users not shown)
Line 1: Line 1:
is there a way to change the field remappings? for instance, i want to make use of the MB-supplied ORIGYEAR field when possible for the %DATE% field.. --[[User:Herr klang|Herr klang]] 15:33, 12 Jun 2005 (CDT)
== Editing guidelines ==
* Do not document redundant fields such as %playlist_number%. When there is more than one way to do something, only document the way that is described in the official manual; the other ones may be old version leftovers or temporary for some other reason.
* Remember: less information is better if it still satisfies 99.99% of the people reading this.


IMO, this page is too complicated and too long. Suggest a table formatted version. See titleformat_help.html in your foobar program directory. Perhaps this page should exist as an expanded version to be consistent? --[[User:Reglib|Reglib]] 02:01, 3 May 2006 (CDT)
== Metadata ==
 
In my opinion the metadata description needs to be expanded.
 
For instance, I have no idea what the following means, or what the function does based on that argument:
{| border=1 cellspacing=0 cellpadding=2 style=""
Example: $meta(artist) "He, She, It"
! colspan="2" style="font-size:larger" | Metadata
At least put a proper artist title in the quotations to give us an adequate description of the function. [[Special:Contributions/68.80.11.34|68.80.11.34]] 07:59, 2 October 2012 (CEST)
|-
! %album artist%
| Defined as ''$if3($meta(album artist),$meta(artist),$meta(composer),$meta(performer))''.
|-
! %album%
| Defined as ''$if3($meta(album),$meta(venue))''.
|-
! %artist%
| Defined as ''$if3($meta(artist),$meta(album artist),$meta(composer),$meta(performer))''.
|-
! %disc%
%discnumber%
| Returns the disc number. The disc number is taken from the discnumber tag; if that does not exist, it is taken from the disc tag. If neither exist, the field is undefined.
|-
! %track artist%
| Defined as ''$meta(artist)'', if ''$meta(album artist)'' is different than ''$meta(artist)'', otherwise this field is empty.
|-
! %title%
| Defined as ''$if2($meta(title),%_filename%)''. Returns the ''title'' tag if available, otherwise it returns the filename excluding the extension.
|-
! %track%
%tracknumber%
| Returns the tracknumber padded to two digits from the left with zeroes. The tracknumber is taken from the tracknumber tag; if that does not exist, it is taken from the track tag. If neither exist, this field is undefined.
|}
 
 
{| border=1 cellspacing=0 cellpadding=2 style=""
! colspan="2" style="font-size:larger" | Technical information
|-
! %bitrate%
| Defined as ''$if2($info(bitrate_dynamic),$info(bitrate))''. Returns the current bitrate, if available, otherwise it returns the average bitrate. If neither is available, nothing is returned.
|-
! %channels%
| Defined as ''$channels()''. Returns the number of channels in text form; returns "mono" and "stereo" instead of "1" and "2".
|-
! %filesize%
| Defined as ''%_filesize%''. Returns the filesize in bytes.
|-
! %samplerate%
| Defined as ''$info(samplerate)''. Returns the samplerate in Hz.
|-
! %codec%
| Defined as ''$codec()''.
|}
 
 
{| border=1 cellspacing=0 cellpadding=2 style=""
! colspan="2" style="font-size:larger" | Special fields
|-
! %playlist_number%
| Defined as ''$num(%_playlist_number%,$len(%_playlist_total%))''. Returns the position of the track as index into the playlist. The first track has index 1. The index is padded from the left with zeroes to the same number of digits as the last track.
|}
 
 
{| border=1 cellspacing=0 cellpadding=2 style=""
! colspan="2" style="font-size:larger" | Control flow
|-
| colspan="2" | The functions in this section can be used to conditionally execute statements.
|-
! [...]
| Evaluates the expression between ''['' and '']''. If it has the truth value ''true'', its string value and the truth value ''true'' are returned. Otherwise an empty string and ''false'' are returned.
 
Example: ''[%artist%]'' returns the value of the artist tag, if it exists. Otherwise it returns nothing, when ''%artist%'' would return "?".
|-
! $if(cond,then)
| If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, ''false'' is returned.
|-
! $if(cond,then,else)
| If ''cond'' evaluates to ''true'', the ''then'' part is evaluated and its value returned. Otherwise, the ''else'' part is evaluated and its value returned.
|-
! $if2(a,else)
| Like ''$if(a,a,else)'' except that ''a'' is only evaluated once.
|-
! $if3(a1,a2,...,aN,else)
| Evaluates arguments ''a1'' ... ''aN'', until one is found that evaluates to ''true''. If that happens, its value is returned. Otherwise the ''else'' part is evaluated and its value returned.
|-
! $ifgreater(n1,n2,then,else)
| Compares the integer numbers ''n1'' and ''n2'', if ''n1'' is greater than ''n2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
|-
! $iflonger(s1,s2,then,else)
| Compares the length of the strings ''s1'' and ''s2'', if ''s1'' is longer than ''s2'', the ''then'' part is evaluated and its value returned. Otherwise the ''else'' part is evaluated and its value returned.
|-
! $select(n,a1,...,aN)
| If the value of ''n'' is between 1 and N, ''an'' is evaluated and its value returned. Otherwise ''false'' is returned.
|}
 
 
== Arithmetic functions ==
 
The functions in this section can be used to perform arithmetic on integer numbers. A string will be automatically converted to a number and vice versa. The conversion to a number uses the longest prefix of the string, that can be interpreted as number. Leading whitespace is ignored.
 
Example: "c3po" -> 0, " -12" -> -12, but "- 12" -> 0
{| border=1 cellspacing=0 cellpadding=2
! $add(a,b)
| Adds ''a'' and ''b''.
 
Can be used with an arbitrary number of arguments. ''$add(a,b,...)'' is the same as ''$add($add(a,b),...)''.
|-
! $div(a,b)
| Divides ''a'' through ''b''. If ''b'' evaluates to zero, it returns ''a''.
 
Can be used with an arbitrary number of arguments. ''$div(a,b,...)'' is the same as ''$div($div(a,b),...)''.
|-
! $greater(a,b)
| Returns true, if ''a'' is greater than ''b'', otherwise false.
|-
! $max(a,b)
| Returns the maximum of ''a'' and ''b''.
 
Can be used with an arbitrary number of arguments. ''$max(a,b,...)'' is the same as ''$max($max(a,b),...)''.
|-
! $min(a,b)
| Returns the minimum of ''a'' and ''b''.
 
Can be used with an arbitrary number of arguments. ''$min(a,b,...)'' is the same as ''$min($min(a,b),...)''.
|-
! $mod(a,b)
| Computes the remainder of dividing ''a'' through ''b''. The result has the same sign as ''a''. If ''b'' evaluates to zero, the result is ''a''.
 
Can be used with an arbitrary number of arguments. ''$mod(a,b,...)'' is the same as ''$mod($mod(a,b),...)''.
|-
! $mul(a,b)
| Multiplies ''a'' and ''b''.
 
Can be used with an arbitrary number of arguments. ''$mul(a,b,...)'' is the same as ''$mul($mul(a,b),...)''.
|-
! $muldiv(a,b,c)
| Multiplies ''a'' and ''b'', then divides by ''c''. The result is rounded to the nearest integer.
|-
! $rand()
| Generates a random number in the range from 0 to 2<sup>32</sup>-1.
|-
! $sub(a,b)
| Subtracts ''b'' from ''a''.
 
Can be used with an arbitrary number of arguments. ''$sub(a,b,...)'' is the same as ''$sub($sub(a,b),...)''.
|}
 
 
== Boolean functions ==
The functions in this section can be used to work with truth values (''true'' and ''false''), which have no explicit representation in titleformat scripts. They do not return a string or number value. You can use them for more complex conditions with ''$if'' and related functions.
{| border=1 cellspacing=0 cellpadding=2
! $and(...)
| Logical And of an arbitrary number of arguments. Returns ''true'', if and only if all arguments evaluate to ''true''.
 
Special case: ''$and(x,y)'' is ''true'', if both ''x'' and ''y'' are ''true''. Otherwise it is ''false''.
|-
! $or(...)
| Logical Or of an arbitrary number of arguments. Returns ''true'', if at least one argument evaluates to ''true''.
 
Special case: ''$or(x,y)'' is ''true'', if ''x'' or ''y'' is ''true'', or if both are ''true''. Otherwise it is ''false''.
|-
! $not(x)
| Logical Not. Returns ''false'', if ''x'' is ''true'', otherwise it returns ''true''.
|-
! $xor(...)
| Logical Exclusive-or of an arbitrary number of arguments. Returns ''true'', if an odd number of arguments evaluate to ''true''.
 
Special case: ''$xor(x,y)'' is ''true'', if one of ''x'' and ''y'' is ''true'', but not both. Otherwise it is ''false''.
|}
 
 
== Color functions ==
{| border=1 cellspacing=0 cellpadding=2
!$blend(color1,color2,part,total)
| Returns a color that is a blend between ''color1'' and ''color2''. If ''part'' is smaller than or equal to zero, ''color1'' is returned. If ''part'' is greater than or equal to ''total'', ''color2'' is returned. Otherwise a blended color is returned that is ''part'' parts ''color1'' and ''total''-''part'' parts ''color2''. The blending is performed in the RGB color space.
|-
! $hsl()
| Resets the text color to the default color.
|-
! $hsl(h,s,l)
| Sets the color for text in the HSL color space. ''h'', ''s'' and ''l'' are the hue, saturation, and lightness of the color for unselected text. The color for selected text is set to the inverse color.
The ranges of ''h'', ''s'', and ''l'' are from 0 to 240; the function is designed to interpret those values in the same way as the standard Windows color dialog.
|-
! $hsl(h1,s1,l1,h2,s2,l2)
| Sets the color for text in the HSL color space. ''h1'', ''s1'' and ''l1'' are the hue, saturation, and lightness of the color for unselected text. ''h2'', ''s2'' and ''l2'' are the hue, saturation, and lightness of the color for selected text.
|-
! $rgb()
| Resets the text color to the default color.
|-
! $rgb(r,g,b)
| Sets the color for text. ''r'', ''g'' and ''b'' are the red, green and blue component of the color for unselected text. The color for selected text is set to the inverse color.
|-
! $rgb(r1,g1,b1,r2,g2,b2)
| Sets the color for text. ''r1'', ''g1'' and ''b1'' are the red, green and blue component of the color for unselected text. ''r2'', ''g2'' and ''b2'' are the red, green and blue component of the color for selected text.
|-
! $transition(string,color1,color2)
|Inserts color codes into ''string'', so that the first character has ''color1'', the last character has ''color2'', and intermediate characters have blended colors. The blending is performed in the RGB color space. Note that color codes are additional characters that will also be counted by string manipulation functions. For example, if you need to truncate a string, you should do this before applying ''$transition''.
|}
 
 
== Now playing info ==
The following functions and fields are only usable for scripts used with the currently playing item, ie: the status bar, the main window title, and the copy command script.
 
{| border=1 cellspacing=0 cellpadding=2
! %playback_time%
| Returns the elapsed time formatted as [HH:]MM:SS.
|-
! %playback_time_seconds%
%_time_elapsed%
| Returns elapsed time in seconds.
|-
! %playback_time_remaining%
%_time_remaining%
| Returns remaining time until track ends, formatted as [HH:]MM:SS.
|-
! %playback_time_remaining_seconds%
%_time_remaining_seconds%
| Returns remaining time in seconds.
|-
! %length%
%_time_total%
| Returns the length of the track formatted as hours, minutes, and seconds.
|-
! %length_ex%
| Returns the length of the track formatted as hours, minutes, seconds, and milliseconds.
|-
! %length_seconds%
%_time_total_seconds%
| Returns the length of the track in seconds.
|-
! %length_seconds_fp%
| Returns the length of the track in seconds as floating point number.
|-
! %length_samples%
| Returns the length of the track in samples.
|}
 
 
= Playlist info =
The following functions and fields are usable for playlist scripts such as masstagger.
{| border=1 cellspacing=0 cellpadding=2
! %isplaying%
%_isplaying%
| Returns "1" if file is currently playing and empty string otherwise.
|-
! %ispaused%
%_ispaused%
| Returns "1" if playback is paused, empty string otherwise.
|-
! %list_index%
%_playlist_number%
| Returns a zero-padded playlist index of specified item. The first item is at index 1.
 
Also see [[Foobar2000:Titleformat Reference#%playlist_number%|%playlist_number%]].
|-
! %list_total%
%_playlist_total%
| Returns number of items in the playlist.
|-
! %playlist_name%
%_playlist_name%
| Returns the name of the playlist containing the specified item.
|}
 
 
== String functions ==
 
The functions in this section can be used to manipulate character strings.
{| border=1 cellspacing=0 cellpadding=2
! $abbr(x)
| Returns abbreviation of ''x''.
|-
! $abbr(x,len)
| Returns abbreviation of ''x'', if ''x'' is longer than ''len'' characters, otherwise returns ''x''.
|-
! $ansi(x)
| Converts ''x'' to system codepage and back. Any characters that are not present in the system codepage will be removed / replaced. Useful for mass-renaming files to ensure compatibility with non-unicode-capable software.
|-
! $ascii(x)
| Converts ''x'' to ASCII. Any characters that are not present in ASCII will be removed / replaced.
|-
! $caps(x)
| Converts first letter in every word of x to uppercase, and all other letters to lowercase.
|-
! $caps2(x)
| Converts first letter in every word of x to uppercase, and leaves all other letters as they are.
|-
! $char(x)
| Inserts Unicode character with code ''x''.
|-
! $crc32(a)
| Computes the CRC32 of the string ''a'' as a number. Intended for use in coloring scripts.
 
Example: $rgb($mod($crc32(%album%),256),128,128)
|-
! $crlf()
| Inserts end-of-line marker (carriage return, line feed). Can be used to generate multiple lines in the output, for example for the tooltip of the system  notification area ("systray") icon.
|-
! $cut(a,len)
| Returns first ''len'' characters on the left of ''a''.
|-
! $directory(x)
| Extracts directory name from the file path ''x''.
|-
! $directory(x,n)
| Extracts directory name from the file path ''x''; goes up by ''n'' levels.
|-
! $ext(x)
| Extracts file extension from ''x'' which must be a file name or path.
|-
! $filename(x)
| Extracts file name from full path.
|-
! $fix_eol(x)
| If ''x'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by " (...)". Otherwise ''x'' is returned unaltered.
|-
! $fix_eol(x,indicator)
| If ''x'' contains an end-of-line marker (CR-LF), the end-of-line marker and all text to the right of it is replaced by ''indicator''. Otherwise ''x'' is returned unaltered.
|-
! $hex(n)
| Formats the integer number ''n'' in hexadecimal notation.
|-
! $hex(n,len)
| Formats the integer number ''n'' in hexadecimal notation with ''len'' digits. Pads with zeros from the left if necessary.
|-
! $insert(a,b,n)
| Inserts ''b'' into ''a'' after ''n'' characters.
|-
! $left(a,len)
| Returns the first ''len'' characters from the left of ''a''.
|-
! $len(a)
| Returns length of string ''a'' in characters.
|-
! $len2(a)
| Returns length of string x in characters, respecting double-width character rules (double-width characters will be counted as two).
|-
! $longer(a,b)
| Returns ''true'', if string ''a'' is longer than string ''b'', false otherwise.
|-
! $lower(a)
| Converts ''a'' to lowercase.
|-
! $longest(a,...)
| Returns the longest of its arguments. Can be used with an arbitrary number of strings.
|-
! $num(n,len)
| Formats the integer number ''n'' in decimal notation with ''len'' digits. Pads with zeros from the left if necessary.
|-
! $pad(x,len)
| Pads ''x'' from the left with spaces to ''len'' characters.
|-
! $pad_right(x,y)
| Pads ''x'' from the right with spaces to ''len'' characters.
|-
! $pad(x,len,char)
| Pads ''x'' from the left with ''char'' to ''len'' characters.
|-
! $pad_right(x,len,char)
| Pads ''x'' from the right with ''char'' to ''len'' characters.
|-
! $padcut(x,len)
| Returns first ''len'' characters from the left of ''x'', if ''x'' is longer than ''len'' characters. Otherwise pads ''x'' from the left with spaces to ''len'' characters.
|-
! $padcut_right(x,len)
| Returns first ''len'' characters from the left of ''x'', if ''x'' is longer than ''len'' characters. Otherwise pads ''x'' from the right with spaces to ''len'' characters.
|-
! $progress(pos,range,len,a,b)
| Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''a'' and ''b'' are characters to build progress bar with.
 
Example:''$progress(%_time_elapsed_seconds%, %_time_total_seconds%, 20,'#','=')'' produces "====#===============", the # character is moving with playback position.
|-
! $progress2(pos,range,len,a,b)
| Creates a progress bar: ''pos'' contains position, ''range'' contains range, ''len'' progress bar length in characters, ''a'' and ''b'' are characters to build progress bar with. Produces different appearance than ''$progress''.
|-
! $repeat(a,n)
| Returns ''n'' copies of ''a''. Note that ''a'' is evaluated once before its value is used, so ''$repeat'' cannot be used for loops.
|-
! $replace(a,b,c)
| Replaces all occurrences of string ''b'' in string ''a'' with string ''c''.
 
Can also be used with an arbitrary number of arguments. Note that ''$replace(a,b1,c1,b2,c2)'' is generally not the same as ''$replace($replace(a,b1,c1),b2,c2)''.
 
Example: ''$replace(ab,a,b,b,c)'' -> "bc", ''$replace($replace(ab,a,b),b,c)'' -> "cc"
|-
! $right(a,len)
| Returns the first ''len'' characters from the right of ''a''.
|-
! $roman(n)
| Formats the integer number ''n'' in roman notation.
|-
! $rot13()
| Performs [http://en.wikipedia.org/wiki/ROT13 ROT13] transformation to given string.
 
Example: ''$rot13('foobar2000')'' -> "sbbone2000".
|-
! $shortest
| Returns the shortest of its arguments. Can be used with an arbitrary number of strings.
|-
! $strchr(s,c)
| Finds first occurence of character ''c'' in string ''s''.
 
Example: ''$strchr(abca,a)'' -> 1
|-
! $strrchr(s,c)
| Finds last occurence of character ''c'' in string ''s''.
 
Example: ''$strrchr(abca,a)'' -> 4
|-
! $strstr(s1,s2)
| Finds first occurence of string ''s2'' in string ''s1''.
|-
! $strcmp(s1,s2)  
| Performs a case-sensitive comparison of the strings ''s1'' and ''s2''.
|-
! $stricmp(s1,s2)
| Performs a case-insensitive comparison of the strings ''s1'' and ''s2''.
|-
! $substr(s,m,n)
| Returns substring of string ''s'', starting from ''m''-th character and ending at ''n''-th character.
|-
! $trim(s)
| Removes leading and trailing spaces from string ''s''.
|-
! $tab()
| Inserts one tabulator character.
|-
! $tab(n)
| Inserts ''n'' tabulator characters.
|-
! $upper(s)
| Converts string ''s'' to uppercase.
|}

Latest revision as of 15:35, 25 January 2013

Editing guidelines

  • Do not document redundant fields such as %playlist_number%. When there is more than one way to do something, only document the way that is described in the official manual; the other ones may be old version leftovers or temporary for some other reason.
  • Remember: less information is better if it still satisfies 99.99% of the people reading this.

Metadata

In my opinion the metadata description needs to be expanded. For instance, I have no idea what the following means, or what the function does based on that argument: Example: $meta(artist) → "He, She, It" At least put a proper artist title in the quotations to give us an adequate description of the function. 68.80.11.34 07:59, 2 October 2012 (CEST)