Difference between revisions of "MrC-temp"

From JRiverWiki
Jump to: navigation, search
(moved search and smartlist to its permanent home.)
m (test work in progress...)
Line 8: Line 8:
 
== This is MrC's working space for work-in-progress Wiki pages. ==
 
== This is MrC's working space for work-in-progress Wiki pages. ==
  
Nothing currently in progress.
+
Caution: Debris Ahead...
 +
 
 +
==Functions==
 +
===Conditional Functions===
 +
 
 +
The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result.
 +
 
 +
Although the expression language does not directly support AND, OR, and XOR, these can be easily emulated. See: Database_Expressions_AND_OR_And_XOR.
 +
 
 +
The NOT operator <span style="font-family: Consolas, monospace;"><b>!</b></span> (exclamation point) may be used in a conditional to invert the sense of the conditional test.  Inverting the sense of a test can make reading expressions easier, or support better IfElse() sequences.
 +
====If(&hellip;): Conditional if-else evaluator====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | If()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>if(</b><i>test</i><b>, </b><i>instructions when true</i><b>, </b><i>instructions when false</i><b>)</b></span>
 +
This will be the function you will likely use more than any other. It is typically used in conjunction with one or more other functions and allows you to give specific instructions depending upon whether the result is positive (1) or negative (0). The positive instruction is always given first.
 +
 
 +
Take care to provide all three arguments to the If() statement, and for nested statements, to ensure the proper number of closing parenthesis.  This can become less-than-obvious with nested sequences.  The built-in expression editor can lessen the burden by allowing line breaks or whitespace after commas (argument separators).  For example, the previous example is easier to read and maintain as:
 +
 
 +
:: <span style="font-family: Consolas, monospace;">if(!isempty([comment]),
 +
::: regex([comment], /#^(\\S+\\s+\\S+\\s+\\S+)#/, 1),
 +
::: *No Comment)</span>
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">if(isequal([artist], bob dylan, 1), Genius, Mediocre)</span>
 +
: Wherever this expression is applied, be it as an expression column or category, as part of a renaming rule, thumbnail text, if the artist tag is Bob Dylan, Media Center will produce Genius, and for all other artists, it will produce Mediocre. The IsEqual() function is described in the first table below.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isequal([artist], bob dylan, 1), Genius, if(isequal([album], Joshua Tree, 8), Great Album, Mediocre))</span>
 +
: Here, we have two nested If functions. First we ask if the artist is Bob Dylan, if the result is positive, write Genius. If the artist is not Dylan, we then ask if the album is Joshua Tree, if yes, write Great Album, and if no, write mediocre
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(!isempty([comment]), regex([comment], /#^(\\S+\\s+\\S+\\s+\\S+)#/, 1), *No Comment)</span>
 +
: Output's the first three words of the comment field; otherwise, outputs *No Comment.  By inverting the sense of the conditional, the more interesting case is moved ahead of the more mundane case.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IfElse(&hellip;): Conditional if-elseif evaluator====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IfElse()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>ifelse(</b><i>test1</i><b>, </b><i>action1</i><b>, </b><i>test2</i><b>, </b><i>action2</i><b>, </b><i>&hellip;</i><b>)</b></span>
 +
The IfElse() conditional provides a convenient mechanism for shortening and more clearly expressing nested conditionals into an alternating sequence of tests and actions.  For example, consider a nested sequence of If() tests such as If(test1, action1, If(test2, action2, If(test3, action3))), shown below in a sequence of if/then/else pseudo-code statements:
 +
 
 +
:: <span style="font-family: Consolas, monospace;">if (test1)
 +
::: action1</span>
 +
:: <span style="font-family: Consolas, monospace;">else if (test2)
 +
::: action2</span>
 +
:: <span style="font-family: Consolas, monospace;">else if (test3)
 +
::: action3</span>
 +
 
 +
The IfElse() statement may be used to more cleanly express the flow of expression by removing the superfluous internal If() statements:
 +
 
 +
:: <span style="font-family: Consolas, monospace;">ifelse(test1, action1, test2, action2, test3, action3)</span>
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">ifelse(isequal([media type], Audio), Le Tunes, isequal([media type], Video]), Flix)</span>
 +
: If media type is audio, outputs "Le Tunes", else if media type is video, outputs "Flix"
 +
 
 +
;<span style="font-family: Consolas, monospace;">ifelse(isequal([artist], Bob Dylan), Genius, isequal([album], Joshua Tree, 8), Great Album, 1, Mediocre)</span>
 +
: This example, implements the nested if statements from the If() section above, first testing if the artist is Bob Dylan, and if true, outputs "Genius", otherwise evaluates the second test to determine if the album is "Joshua Tree", and if true, outputs "Great Album", otherwise, performs a final test, in this case a degenerate test of 1 (and 1 is always true), thus outputting the value "Mediocre".
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
===Query, Test and Comparison Functions===
 +
 
 +
The functions in this section return either a 1 (for true) or 0 (for false).  They are generally used inside [[Conditional Functions]].
 +
====Compare(&hellip;): Compares two numbers====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | Compare()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>compare(</b><i>value1</i><b>, </b><i>operator</i><b>, </b><i>value2</i><b>)</b></span>
 +
Compares two numeric values using one of the following operators:
 +
 
 +
{| style="background:#f9f9f9;"
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>=</b></span> || Equivalence
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b><</b></span> || Less than
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b><=</b></span> || Less than or equal to
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>></b></span> || Greater than
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>>=</b></span> || Greater than or equal to
 +
|}
 +
 
 +
Outputs 1 if the comparison is true, and 0 otherwise.
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">compare([bitrate], &lt;, 320)</span>
 +
: Returns 1 when the bitrate is less than 320 (Kbps), and 0 otherwise.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(compare(math(now() - [date modified, 0]), &gt;, 21), Expired, formatdate([date modified, 0], elapsed))</span>
 +
: Outputs the age of files under 21 days old, or 'Expired' for older files.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsEqual(&hellip;): Compares two values in one of nine specified modes====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsEqual()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isequal(</b><i>value1</i><b>, </b><i>value2</i><b>, </b><i>mode</i><b>)</b></span>
 +
Compares two values using one of the modes specified below and outputs 1 for a positive match and 0 for a negative match. Although the mode is specified as the last argument, the comparison should be mentally read as: value1 mode value2.
 +
 
 +
Available Compare Modes:
 +
 
 +
{| style="background:#f9f9f9;"
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>0</b></span> || Case-sensitive string compare for equality
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>1</b></span> || Case-insensitive string compare for equality
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>2</b></span> || Numeric compare for equality
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>3</b></span> || Numeric less than
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>4</b></span> || Numeric less than or equal to
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>5</b></span> || Numeric greater than
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>6</b></span> || Numeric greater than or equal to
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>7</b></span> || Substring search (case sensitive)
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>8</b></span> || Substring search (case insensitive)
 +
|}
 +
 
 +
Argument <i>mode</i> is optional (defaults to 0).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">isequal([artist], [album], 1)</span>
 +
: If the artist and album values are the same, the output will be 1, otherwise, the output will be 0.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isequal([artist], [album], 1), Eponymous, [album])</span>
 +
: The if() function basis its decision on the outcome of isequal(), so if the artist and album values are the same, the output will be Eponymous, otherwise, the output will be the value of album.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isequal([artist], [album], 1), Eponymous/,, [album]/))</span>
 +
: This example demonstrates the character 'escaping' mentioned in the overview earlier. Here, we want the output to be either "Eponymous," (note the inclusion of the comma) or the album value with a closing parenthesis. In order to achieve this, the comma, and the closing parenthesis, are escaped using a forward-slash character.  This informs the expression evaluator that these characters are not part of the expression syntax and are to be treated literally.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isequal([filename (path)], classical, 8), Classical, Not Classical)</span>
 +
: Because compare mode 8 has been specified, if the word "classical" appears anywhere in the case-insensitive file path, the expression will return Classical, and if not it will return Not Classical.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsEmpty(&hellip;): Tests a value for emptiness====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsEmpty()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isempty(</b><i>value</i><b>, </b><i>mode</i><b>)</b></span>
 +
Tests the given value for emptiness.  The value passed is typically an MC field, so that some action may be taken when the field is or is not empty.
 +
 
 +
The isempty() function returns 1 when the value is empty, otherwise 0.
 +
 
 +
Note that MC does not discriminate between a 0 value and an empty value for fields of type Integer and Decimal - both 0 and empty are considered equivalent for these field types.
 +
This is useful for fields such as the integer field Disc #, where an empty or 0 value implies that Disc # contains no useful data, and should be generally ignored or absent in display output.
 +
 
 +
Pay particular attention to the third example offered below, as it covers a caveat that comes with this particular function.
 +
 
 +
Two different test modes are available: a "string" test, and a "number" test.
 +
 
 +
Available test modes:
 +
 
 +
{| style="background:#f9f9f9;"
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>0</b></span> || String test (field must be empty to get a positive result)
 +
|-
 +
| align="center" width="100pt" | <span style="font-family: Consolas, monospace;"><b>1</b></span> || Numerical test (field must be empty, or contain 0 to get a positive result)
 +
|}
 +
 
 +
Argument <i>mode</i> is optional (defaults to 0).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">isempty([comment], 0)</span>
 +
: If the comment field is empty, isempty() returns 1, otherwise 0.
 +
 
 +
;<span style="font-family: Consolas, monospace;">isempty([track #], 1)</span>
 +
: Performs a numerical test for data in the [track #] field. If the field is empty or 0, a 1 is returned, otherwise 0 is returned.
 +
 
 +
;<span style="font-family: Consolas, monospace;">ifelse(!isempty([disc #]), [disc #])</span>
 +
: Outputs the value of the disc # field when it is not empty.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsRange(&hellip;): Tests a value for inclusion within a given range====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsRange()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isrange(</b><i>value</i><b>, </b><i>range</i><b>)</b></span>
 +
IsRange allows us to test if any given field falls inside any given range of values. If the field falls inside the given range, the function returns 1, and if outside the given range, the function returns 0.
 +
 
 +
A range is specified in the form of low-high, where low and high are either letters or numbers.
 +
The lowest value comes first, the highest second. Both low and high must be the same kind (letters or numbers).
 +
 
 +
Example Ranges:
 +
 
 +
:: 1-100
 +
:: a-z
 +
:: c-d
 +
:: 23-7542
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">isrange([artist], a-c)</span>
 +
: Artist values of Abba or Blondie will result in a 1, but ZZ Top will return a 0.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isrange([bitrate], 96-191), Poor Quality, High Quality)</span>
 +
: Returns Poor Quality for any file whose bitrate falls in the range of 96 to 191, and returns "High Quality" for all bitrates.
 +
 
 +
Additional Examples
 +
 
 +
:[http://wiki.jriver.com/index.php/CD_Reference_Number#Answer_2 Using IsRange() in a Search List.]
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsMissing(&hellip;): Tests to see if a file exists on the system====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsMissing()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>ismissing(</b><i>filepath</i><b>)</b></span>
 +
Tests the existence of a file in the file system. If the file is missing, the function returns 1 (positive), and if the file is found, the function returns 0 (negative). This function is useful for checking the integrity of your Media Center library as you can use it to produce a list of any files in your library that Media Center cannot find.
 +
IsMissing() treats special entries such as ripped Blu-ray or DVDs as single files, even though they physically exist in the file system as several files and directories.
 +
 
 +
Note: IsMissing() works directly on the file system and will cause performance to suffer: the larger the library, the longer it will take to produce results.
 +
 
 +
Argument <i>filepath</i> is optional (defaults to [Filename]).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">ismissing()</span>
 +
: Checks if the current file exists, and returns 1 (positive) if the file does not exist, and 0 (negative) if the file does exist.
 +
 
 +
;<span style="font-family: Consolas, monospace;">ismissing(C:\Music\My Lost File.mp3)</span>
 +
: Checks for "My Lost File.mp3" and returns 1 (positive) if the file does not exist, and 0 (negative) if the file does exist.
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(ismissing(), File is missing, File exists)</span>
 +
: Outputs "File is missing" or "File Exists" depending on the result returned by IsMissing().
 +
 
 +
;<span style="font-family: Consolas, monospace;">[=ismissing([filename])]=1</span>
 +
: This example demonstrates how to construct an expression for use as a Media Center search query. If you place this in the search field in the top right corner of the program while viewing all of your library, it will filter the list, leaving only the missing files on view. If all files in library exist, this list will be empty. You could also create a view scheme and use this string in the "Set rules for file display" search to give you a view that you can visit periodically to check that your library is not missing any files.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsRemovable(&hellip;): Tests to see if a file is stored on removable media====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsRemovable()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isremovable(</b><i>filepath</i><b>)</b></span>
 +
Checks to see if a file resides on removable media and if so, returns 1 (positive), and if not, returns 0 (negative). There is not a lot to say about this function, especially since Media Center comes equipped with a [Removable] field by default that is automatically populated with 1 for all files in the library that are on removable storage. The function works in exactly the same way as the IsMissing function described above, returning 1 (positive) if the file is on removable storage, and 0 (negative) if not.
 +
 
 +
Argument <i>filepath</i> is optional (defaults to [Filename]).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">isremovable()</span>
 +
: Checks if the current file is on removable storage, and if so, returns 1 (positive), if not, the function returns 0 (negative).
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsInPlayingNow(&hellip;): Tests to see if a file is in the Playing Now playlist====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsInPlayingNow()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isinplayingnow(</b><i>filepath</i><b>)</b></span>
 +
This function tests if a file is in any zone's Playing Now list.
 +
Used as an expression category, pane or file list column allows distinguishing files that are in the Playing Now list.
 +
 
 +
Argument <i>filepath</i> is optional (defaults to [Filename]).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">isinplayingnow()</span>
 +
: If the file in the Playing Now list, returns 1 (positive), and if not, returns 0 (negative).
 +
 
 +
;<span style="font-family: Consolas, monospace;">if(isinplayingnow(), Queued, Not queued)</span>
 +
: If the file in the Playing Now list, returns Queued, otherwise Not queued.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====IsPlaying(&hellip;): Tests to see if a file is in currently being played====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | IsPlaying()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>isplaying(</b><i>filepath</i><b>)</b></span>
 +
This function tests if a file is playing in any zone.
 +
Used as an expression category, pane or file list column allows distinguishing files that are playing now.
 +
 
 +
Argument <i>filepath</i> is optional (defaults to [Filename]).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">IfElse(IsPlaying(), &lt;font color="ff0000"&gt;&#9834;&lt;//font&gt;, IsInPlayingNow(), &#9834;)</span>
 +
: This expression in a file list expression column shows which files are in the Playing Now list and which are currently playing by outputing a musical note in the column.  The note will be red for any currently playing file.
 +
 
 +
Additional Examples
 +
 
 +
:[http://yabb.jriver.com/interact/index.php?topic=57461.0 How to use IsPlaying() and IsInPlayingNow()]
 +
 
 +
:[http://yabb.jriver.com/interact/index.php?topic=58137.msg393905#msg393905 How to play an artist's full work when a genre is shuffling?]
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
===Formatting Functions===
 +
 
 +
The functions in this section format their arguments in specific ways.
 +
Some functions are used for formatting values for better presentation, or according to some format, while other functions work on MC-internal "raw" data to convert to user-friendly formats.
 +
 
 +
Certain MC fields are used to store values in ways that are internally convenient or effecient.  But these field values are not terribly useful or meaningful when used directly.
 +
 
 +
For example, the Duration field holds values as a number seconds of length, while various Date/Time fields such as Date or Last Played store values as floating point numbers specifying a number of days and fractions of a day since a particular epoch time.
 +
 
 +
MC will generally format fields using the "display" format where necessary, such as in panes, file list columns, or various tools such as the Rename, Move & Copy tool.
 +
When a function requires a raw field value, or you want to access a raw field value, by sure to use the raw field format.
 +
This is done by appending a <span style="font-family: Consolas, monospace;"><b>,0</b></span> to the field's name inside the brackets. Example: <span style="font-family: Consolas, monospace;">[Date Imported,0]</span>.
 +
====Delimit(&hellip;): Outputs a value with head/tail strings when value is non-empty====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | Delimit()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>delimit(</b><i>expression</i><b>, </b><i>tail</i><b>, </b><i>head</i><b>)</b></span>
 +
Outputs the value of expression prepended with a head string and/or appended with a tail string, but only if the value of the expression is non-empty.  Nothing is output when the expression evaluates to empty.
 +
 
 +
Argument <i>tail</i> is optional (defaults to SPACE).
 +
 
 +
Argument <i>head</i> is optional (defaults to EMPTY).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">delimit([Track #], .)</span>
 +
: Appends a period after a track number if [Track #] is not empty, such as "12.".
 +
 
 +
;<span style="font-family: Consolas, monospace;">delimit([Date (year)], {, })</span>
 +
: Outputs the year surrounded by curly braces, for example "{2012}".
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====FormatBoolean(&hellip;): Formats a boolean (true / false) value in a specified manner====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | FormatBoolean()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>formatboolean(</b><i>conditional</i><b>, </b><i>true string</i><b>, </b><i>false string</i><b>)</b></span>
 +
Outputs string values to represent the 0 or 1 Boolean output resulting from the conditional expression.
 +
When the conditional evalutes to 1, the true string will be output, otherwise the false string will be output.
 +
 
 +
Argument <i>true string</i> is optional (defaults to True).
 +
 
 +
Argument <i>false string</i> is optional (defaults to False).
 +
 
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">formatboolean(isempty([number plays]), Never Played, Has Been Played)</span>
 +
: Returns "Never Played" when the expression IsEmpty([number plays]) evaluates to 0, and "Has Been Played" when it evaluates to 1.
 +
 
 +
;<span style="font-family: Consolas, monospace;">formatboolean(math([track #] % 2)</span>
 +
: Outputs the default True label for odd track numbers, and the default False label for even ones.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====FormatDuration(&hellip;): Presents a duration of seconds in a reader friendly format====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | FormatDuration()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>formatduration(</b><i>duration value</i><b>)</b></span>
 +
Formats a duration value into a friendly format. 
 +
The duration value argument is expected to be a value representing a number of seconds, typically used for media file duration.
 +
Media Center internally stores duration values in seconds.
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">formatduration([duration,0])</span>
 +
: Outputs a friendly display of the duration field.  This is the same output shown using the Duration field in a file list.
 +
 
 +
;<span style="font-family: Consolas, monospace;">formatduration(600)</span>
 +
: This will output ten minutes in the format 10:00.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
====FormatFileSize(&hellip;): Presents a number of bytes in a reader friendly format====
 +
 
 +
{| style="width: 100%; border: 2px solid black;" align="top" cellpadding="3"
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " width=100 | FormatFileSize()
 +
| style="background: #f9f9f9; color: #111; " width=1200 | <span style="font-family: Consolas, monospace; color:#0f3f8d"><b>formatfilesize(</b><i>bytes value</i><b>)</b></span>
 +
Formats a bytes value into a friendly format.
 +
The bytes value argument is expected to be a value representing a number of bytes, typically used for media file size.
 +
Media Center internally stores file size values in bytes.  This function will convert those byte values into unitized friendly formats such as 50 bytes, 3.2 KB or 10.4 MB.
 +
|- valign="top"
 +
! scope="row" style="background: #ecedf3; color: #111; " | Examples
 +
|style="background: #f9f9f9; color: #111; " |
 +
;<span style="font-family: Consolas, monospace;">formatfilesize([file size,0])</span>
 +
: Outputs a friendly format of the file size field.  This is the same output shown using the File Size field in a file list.
 +
 
 +
;<span style="font-family: Consolas, monospace;">formatfilesize(56123456)</span>
 +
: Outputs the bytes value 56,123,456 as 53.5 MB.
 +
|}
 +
<div style="text-align:right;">([[#top|Back to top)]]</div>
 +
 
 +
... and more to come...

Revision as of 01:24, 15 August 2013

Note: The Smartlist and Search - Rules and Modifiers page is now at its permanent home: Smartlist and Search - Rules and Modifiers

Note: The Regex() page is now at its permanent home: MC expression language page

Note: The File Properties page is now at its permanent home: File Properties (tags) page

This is MrC's working space for work-in-progress Wiki pages.

Caution: Debris Ahead...

Functions

Conditional Functions

The functions in this section test one or more arguments to produce either a true or false outcome, and execute specific actions depending upon that result.

Although the expression language does not directly support AND, OR, and XOR, these can be easily emulated. See: Database_Expressions_AND_OR_And_XOR.

The NOT operator ! (exclamation point) may be used in a conditional to invert the sense of the conditional test. Inverting the sense of a test can make reading expressions easier, or support better IfElse() sequences.

If(…): Conditional if-else evaluator

If() if(test, instructions when true, instructions when false)

This will be the function you will likely use more than any other. It is typically used in conjunction with one or more other functions and allows you to give specific instructions depending upon whether the result is positive (1) or negative (0). The positive instruction is always given first.

Take care to provide all three arguments to the If() statement, and for nested statements, to ensure the proper number of closing parenthesis. This can become less-than-obvious with nested sequences. The built-in expression editor can lessen the burden by allowing line breaks or whitespace after commas (argument separators). For example, the previous example is easier to read and maintain as:

if(!isempty([comment]),
regex([comment], /#^(\\S+\\s+\\S+\\s+\\S+)#/, 1),
*No Comment)
Examples
if(isequal([artist], bob dylan, 1), Genius, Mediocre)
Wherever this expression is applied, be it as an expression column or category, as part of a renaming rule, thumbnail text, if the artist tag is Bob Dylan, Media Center will produce Genius, and for all other artists, it will produce Mediocre. The IsEqual() function is described in the first table below.
if(isequal([artist], bob dylan, 1), Genius, if(isequal([album], Joshua Tree, 8), Great Album, Mediocre))
Here, we have two nested If functions. First we ask if the artist is Bob Dylan, if the result is positive, write Genius. If the artist is not Dylan, we then ask if the album is Joshua Tree, if yes, write Great Album, and if no, write mediocre
if(!isempty([comment]), regex([comment], /#^(\\S+\\s+\\S+\\s+\\S+)#/, 1), *No Comment)
Output's the first three words of the comment field; otherwise, outputs *No Comment. By inverting the sense of the conditional, the more interesting case is moved ahead of the more mundane case.

IfElse(…): Conditional if-elseif evaluator

IfElse() ifelse(test1, action1, test2, action2, )

The IfElse() conditional provides a convenient mechanism for shortening and more clearly expressing nested conditionals into an alternating sequence of tests and actions. For example, consider a nested sequence of If() tests such as If(test1, action1, If(test2, action2, If(test3, action3))), shown below in a sequence of if/then/else pseudo-code statements:

if (test1)
action1
else if (test2)
action2
else if (test3)
action3

The IfElse() statement may be used to more cleanly express the flow of expression by removing the superfluous internal If() statements:

ifelse(test1, action1, test2, action2, test3, action3)
Examples
ifelse(isequal([media type], Audio), Le Tunes, isequal([media type], Video]), Flix)
If media type is audio, outputs "Le Tunes", else if media type is video, outputs "Flix"
ifelse(isequal([artist], Bob Dylan), Genius, isequal([album], Joshua Tree, 8), Great Album, 1, Mediocre)
This example, implements the nested if statements from the If() section above, first testing if the artist is Bob Dylan, and if true, outputs "Genius", otherwise evaluates the second test to determine if the album is "Joshua Tree", and if true, outputs "Great Album", otherwise, performs a final test, in this case a degenerate test of 1 (and 1 is always true), thus outputting the value "Mediocre".

Query, Test and Comparison Functions

The functions in this section return either a 1 (for true) or 0 (for false). They are generally used inside Conditional Functions.

Compare(…): Compares two numbers

Compare() compare(value1, operator, value2)

Compares two numeric values using one of the following operators:

= Equivalence
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to

Outputs 1 if the comparison is true, and 0 otherwise.

Examples
compare([bitrate], <, 320)
Returns 1 when the bitrate is less than 320 (Kbps), and 0 otherwise.
if(compare(math(now() - [date modified, 0]), >, 21), Expired, formatdate([date modified, 0], elapsed))
Outputs the age of files under 21 days old, or 'Expired' for older files.

IsEqual(…): Compares two values in one of nine specified modes

IsEqual() isequal(value1, value2, mode)

Compares two values using one of the modes specified below and outputs 1 for a positive match and 0 for a negative match. Although the mode is specified as the last argument, the comparison should be mentally read as: value1 mode value2.

Available Compare Modes:

0 Case-sensitive string compare for equality
1 Case-insensitive string compare for equality
2 Numeric compare for equality
3 Numeric less than
4 Numeric less than or equal to
5 Numeric greater than
6 Numeric greater than or equal to
7 Substring search (case sensitive)
8 Substring search (case insensitive)

Argument mode is optional (defaults to 0).

Examples
isequal([artist], [album], 1)
If the artist and album values are the same, the output will be 1, otherwise, the output will be 0.
if(isequal([artist], [album], 1), Eponymous, [album])
The if() function basis its decision on the outcome of isequal(), so if the artist and album values are the same, the output will be Eponymous, otherwise, the output will be the value of album.
if(isequal([artist], [album], 1), Eponymous/,, [album]/))
This example demonstrates the character 'escaping' mentioned in the overview earlier. Here, we want the output to be either "Eponymous," (note the inclusion of the comma) or the album value with a closing parenthesis. In order to achieve this, the comma, and the closing parenthesis, are escaped using a forward-slash character. This informs the expression evaluator that these characters are not part of the expression syntax and are to be treated literally.
if(isequal([filename (path)], classical, 8), Classical, Not Classical)
Because compare mode 8 has been specified, if the word "classical" appears anywhere in the case-insensitive file path, the expression will return Classical, and if not it will return Not Classical.

IsEmpty(…): Tests a value for emptiness

IsEmpty() isempty(value, mode)

Tests the given value for emptiness. The value passed is typically an MC field, so that some action may be taken when the field is or is not empty.

The isempty() function returns 1 when the value is empty, otherwise 0.

Note that MC does not discriminate between a 0 value and an empty value for fields of type Integer and Decimal - both 0 and empty are considered equivalent for these field types. This is useful for fields such as the integer field Disc #, where an empty or 0 value implies that Disc # contains no useful data, and should be generally ignored or absent in display output.

Pay particular attention to the third example offered below, as it covers a caveat that comes with this particular function.

Two different test modes are available: a "string" test, and a "number" test.

Available test modes:

0 String test (field must be empty to get a positive result)
1 Numerical test (field must be empty, or contain 0 to get a positive result)

Argument mode is optional (defaults to 0).

Examples
isempty([comment], 0)
If the comment field is empty, isempty() returns 1, otherwise 0.
isempty([track #], 1)
Performs a numerical test for data in the [track #] field. If the field is empty or 0, a 1 is returned, otherwise 0 is returned.
ifelse(!isempty([disc #]), [disc #])
Outputs the value of the disc # field when it is not empty.

IsRange(…): Tests a value for inclusion within a given range

IsRange() isrange(value, range)

IsRange allows us to test if any given field falls inside any given range of values. If the field falls inside the given range, the function returns 1, and if outside the given range, the function returns 0.

A range is specified in the form of low-high, where low and high are either letters or numbers. The lowest value comes first, the highest second. Both low and high must be the same kind (letters or numbers).

Example Ranges:

1-100
a-z
c-d
23-7542
Examples
isrange([artist], a-c)
Artist values of Abba or Blondie will result in a 1, but ZZ Top will return a 0.
if(isrange([bitrate], 96-191), Poor Quality, High Quality)
Returns Poor Quality for any file whose bitrate falls in the range of 96 to 191, and returns "High Quality" for all bitrates.

Additional Examples

Using IsRange() in a Search List.

IsMissing(…): Tests to see if a file exists on the system

IsMissing() ismissing(filepath)

Tests the existence of a file in the file system. If the file is missing, the function returns 1 (positive), and if the file is found, the function returns 0 (negative). This function is useful for checking the integrity of your Media Center library as you can use it to produce a list of any files in your library that Media Center cannot find. IsMissing() treats special entries such as ripped Blu-ray or DVDs as single files, even though they physically exist in the file system as several files and directories.

Note: IsMissing() works directly on the file system and will cause performance to suffer: the larger the library, the longer it will take to produce results.

Argument filepath is optional (defaults to [Filename]).

Examples
ismissing()
Checks if the current file exists, and returns 1 (positive) if the file does not exist, and 0 (negative) if the file does exist.
ismissing(C:\Music\My Lost File.mp3)
Checks for "My Lost File.mp3" and returns 1 (positive) if the file does not exist, and 0 (negative) if the file does exist.
if(ismissing(), File is missing, File exists)
Outputs "File is missing" or "File Exists" depending on the result returned by IsMissing().
[=ismissing([filename])]=1
This example demonstrates how to construct an expression for use as a Media Center search query. If you place this in the search field in the top right corner of the program while viewing all of your library, it will filter the list, leaving only the missing files on view. If all files in library exist, this list will be empty. You could also create a view scheme and use this string in the "Set rules for file display" search to give you a view that you can visit periodically to check that your library is not missing any files.

IsRemovable(…): Tests to see if a file is stored on removable media

IsRemovable() isremovable(filepath)

Checks to see if a file resides on removable media and if so, returns 1 (positive), and if not, returns 0 (negative). There is not a lot to say about this function, especially since Media Center comes equipped with a [Removable] field by default that is automatically populated with 1 for all files in the library that are on removable storage. The function works in exactly the same way as the IsMissing function described above, returning 1 (positive) if the file is on removable storage, and 0 (negative) if not.

Argument filepath is optional (defaults to [Filename]).

Examples
isremovable()
Checks if the current file is on removable storage, and if so, returns 1 (positive), if not, the function returns 0 (negative).

IsInPlayingNow(…): Tests to see if a file is in the Playing Now playlist

IsInPlayingNow() isinplayingnow(filepath)

This function tests if a file is in any zone's Playing Now list. Used as an expression category, pane or file list column allows distinguishing files that are in the Playing Now list.

Argument filepath is optional (defaults to [Filename]).

Examples
isinplayingnow()
If the file in the Playing Now list, returns 1 (positive), and if not, returns 0 (negative).
if(isinplayingnow(), Queued, Not queued)
If the file in the Playing Now list, returns Queued, otherwise Not queued.

IsPlaying(…): Tests to see if a file is in currently being played

IsPlaying() isplaying(filepath)

This function tests if a file is playing in any zone. Used as an expression category, pane or file list column allows distinguishing files that are playing now.

Argument filepath is optional (defaults to [Filename]).

Examples
IfElse(IsPlaying(), <font color="ff0000">♪<//font>, IsInPlayingNow(), ♪)
This expression in a file list expression column shows which files are in the Playing Now list and which are currently playing by outputing a musical note in the column. The note will be red for any currently playing file.

Additional Examples

How to use IsPlaying() and IsInPlayingNow()
How to play an artist's full work when a genre is shuffling?

Formatting Functions

The functions in this section format their arguments in specific ways. Some functions are used for formatting values for better presentation, or according to some format, while other functions work on MC-internal "raw" data to convert to user-friendly formats.

Certain MC fields are used to store values in ways that are internally convenient or effecient. But these field values are not terribly useful or meaningful when used directly.

For example, the Duration field holds values as a number seconds of length, while various Date/Time fields such as Date or Last Played store values as floating point numbers specifying a number of days and fractions of a day since a particular epoch time.

MC will generally format fields using the "display" format where necessary, such as in panes, file list columns, or various tools such as the Rename, Move & Copy tool. When a function requires a raw field value, or you want to access a raw field value, by sure to use the raw field format. This is done by appending a ,0 to the field's name inside the brackets. Example: [Date Imported,0].

Delimit(…): Outputs a value with head/tail strings when value is non-empty

Delimit() delimit(expression, tail, head)

Outputs the value of expression prepended with a head string and/or appended with a tail string, but only if the value of the expression is non-empty. Nothing is output when the expression evaluates to empty.

Argument tail is optional (defaults to SPACE).

Argument head is optional (defaults to EMPTY).

Examples
delimit([Track #], .)
Appends a period after a track number if [Track #] is not empty, such as "12.".
delimit([Date (year)], {, })
Outputs the year surrounded by curly braces, for example "{2012}".

FormatBoolean(…): Formats a boolean (true / false) value in a specified manner

FormatBoolean() formatboolean(conditional, true string, false string)

Outputs string values to represent the 0 or 1 Boolean output resulting from the conditional expression. When the conditional evalutes to 1, the true string will be output, otherwise the false string will be output.

Argument true string is optional (defaults to True).

Argument false string is optional (defaults to False).

Examples
formatboolean(isempty([number plays]), Never Played, Has Been Played)
Returns "Never Played" when the expression IsEmpty([number plays]) evaluates to 0, and "Has Been Played" when it evaluates to 1.
formatboolean(math([track #] % 2)
Outputs the default True label for odd track numbers, and the default False label for even ones.

FormatDuration(…): Presents a duration of seconds in a reader friendly format

FormatDuration() formatduration(duration value)

Formats a duration value into a friendly format. The duration value argument is expected to be a value representing a number of seconds, typically used for media file duration. Media Center internally stores duration values in seconds.

Examples
formatduration([duration,0])
Outputs a friendly display of the duration field. This is the same output shown using the Duration field in a file list.
formatduration(600)
This will output ten minutes in the format 10:00.

FormatFileSize(…): Presents a number of bytes in a reader friendly format

FormatFileSize() formatfilesize(bytes value)

Formats a bytes value into a friendly format. The bytes value argument is expected to be a value representing a number of bytes, typically used for media file size. Media Center internally stores file size values in bytes. This function will convert those byte values into unitized friendly formats such as 50 bytes, 3.2 KB or 10.4 MB.

Examples
formatfilesize([file size,0])
Outputs a friendly format of the file size field. This is the same output shown using the File Size field in a file list.
formatfilesize(56123456)
Outputs the bytes value 56,123,456 as 53.5 MB.

... and more to come...