Author Topic: Additional Functions for more expressive (readable) Templates  (Read 1248 times)

pseudonym

  • Guest
Currently, the Template Editor allows:

Code
$If(<field1>=<field2>,<text>,<text>)

but for multiple conditions the template starts becoming unwieldy:

Code
$If(<condition1>,<text1>,
$If(<condition2>,<text2>,
$If(<condition2>,<text2>,...
$If(<conditionN>,<textN>,<textDefault>)))...)))

I am wondering if some of the following functions could be supported:

Code
$And(<condition1>,<condition2>,...,<conditionN>)
$Or(<condition1>,<condition2>,...,<conditionN>)
$Not(<condition>)
$Switch(
  $Case(<condition1>,<text1>),
  $Case(<condition2>,<text2>),
  ...
  $Case(<conditionN>,<textN>),
  $Default(<textDefault>)
)

Equalities as functions on strings or numbers:

Code
$ne(<field1>,<field2>)
$lt(<field1>,<field2>)
$le(<field1>,<field2>)
$gt(<field1>,<field2>)
$ge(<field1>,<field2>)

Alternatively, these equalities and AND, OR, NOT can be implemented as part of the $If statement's condition in addition to "=".

I know that virtual tags can act as functions, but sometimes I want to temporarily define a sub-function that can be reused later within the same template, and only within that template. Say:

Code
$Define(<Routine>,<Arguments>,<Template>)
...
$Routine(<Arguments>...)
...

I guess, what I am wondering is can templates be made more expressive because my currently auto-reorganization template looks like  this (with indentation removed, added for readability here):

Code
$RxReplace(<Album Artist>,"(^\.|\.$)","-")
$If(<Album Artist>="Various Artists",,
  $If($IsMatch(<Path>,"^.*\\(Compilation|Album|EP|Single)s\\.*$")=T,
      $If($IsMatch(<Path>,"^.*\\Compilations\\.*$")=T,\Compilations,
      $If($IsMatch(<Path>,"^.*\\Albums\\.*$")=T,\Albums,
      $If($IsMatch(<Path>,"^.*\\EPs\\.*$")=T,\EPs,\Singles))),
    $If($IsMatch(<Album>,"^.* \((EP|Single)\)$")=T,
      $If($IsMatch(<Album>,"^.* \(EP\)$")=T,\EPs,\Singles),
    $If($Len(<Album Kind>)=0,,\<Album Kind>))))
$RxReplace($If(<Folder Name>=<Album [Year]>,\$RxReplace(<Album [Year]>,"^\.","-"),
  $If($IsMatch(<Folder Name>," [\[\(][0-9]+[\)\]]$")=T,\$RxReplace(<Folder Name>,"^\.","-"),
  $If($IsMatch(<Album>," [\[\(][0-9]+[\)\]]$")=T,\$RxReplace(<Album>,"^\.","-"),
      \$RxReplace(<Album>,"(^\.|\.$)","-"))))," \((Single|EP)\)",)\
<Disc-Track#> <Title>



It's like this because the exceptions currently cannot be chained or cascade nor does the character mapping support the special case of the first and last characters in a path component (i.e.: changing '.' to '_' when as the first or last characters in a directory or filename). My concern is this could become more unwieldy as I add more conditions to it.

P.S.: Code highlighting could be helpful too.
Last Edit: December 27, 2020, 09:49:26 PM by pseudonym