The if - else - endif statements provide the ability to selectively execute statements within an action. The else statement is optional and the sequences can be nested.
There are three modes of the if statement: one tests the action test state and the other two test per file results and constrain the set of files been processed.
When Test the action test state is selected, the if statement conditionally executes statements based on the action test state being the same as a specified state of true or false. Either the if statements or optionally the else statements; but never both will be executed.
Example 1:
Test if the Genre field is equal to "Rock" case insensitive (Set test state)
if true
' execute here if all active files have a Genre of Rock
else
' execute here if not all all active files have a Genre of Rock
endif
Example 2:
Test if the Genre field is equal to "Rock" case insensitive (Set test state) (Any)
if true per file
' execute here if all active files have a Genre of Rock
else
' execute here if not all all active files have a Genre of Rock
endif
Example 1 tests if all active files have a genre of Rock. Example 2 tests if any active file has a genre of Rock.
Examples 1 and 2 do not handle files with and without a genre of Rock. This is because the if variant only handles a simple is the condition true or false. The if statement uses the single global action test state established by the preceding Compare Text statement. The any constraint was established by the Compare Text statement.
The test per file test state mode allows you to get around the restriction.
Example 3:
Test if the Genre field is equal to "Rock" case insensitive (Set test state and per file test state)
if true per file
' execute here if all active files have a Genre of Rock
else
' execute here if not all all active files have a Genre of Rock
endif
In example 3, the Compare Text statement sets the per file test state. This state is maintained individually in each file. After executing the Compare Text statement the following holds:
The if statement in example 3 tests the per file test state, not the action test state. The set of files which meet the criteria is automatically made and constrains which files are available after the if and after the optional else.
Which files are available is strictly established when the if statement executes. Changing the per file test state within the if construct does not affect the file selection. When the if construct terminates the set of available files returns to whatever it was when the if was executed. This implementation allows for the safe nesting of if constructs.
Example 4:
Test if the Part of a Compilation field is true (Set test state and per file test state)
if true per file
Set the Comments field to "Compilation"
Test if the Album Artist field is equal to "Various Artists" case insensitive (Set test state and per file test state)
if true per file
Append "ยท& Various Artists" to the Comments field
endif
else
Set the Comments field to "Not a Compilation"
endif
The above example uses nested if constructs which constrain which files are accessible.
Before the per file test state was introduced in Yate v10.0, you had to use track variables to provide a per file test.
Example 5:
With the if statement as configured in example 5, a track variable in each available file is tested. The result of the test enables an execution model identical to the Test the Per File Test State mode described in the previous section.
As with the Test the Per File Test State mode, this mode determines which files are to be processed and where, when the if starts. Modifying the specified track variable does not affect the execution flow.
This mode has the additional capability of being able to test if the track variable is empty or not empty. empty is defined as completely empty. ie. a variable which contains a space is not empty.
Example 6:
1: Test if the Variable 1 field is empty (Set test state and Variable 2) 2: if Variable 2 is true 3: ' Process files which have an empty Variable 1 4: endif 5: 6: if Variable 1 is empty 7: ' Process files which have an empty Variable 1 8: endif
Lines 6 through 8 are equivalent to lines 1 through 4.
File availability statements can be used with the test the per file test state and test if Variable n modes to modify the set of selected files inside the if or else sections. However, when the optional else portion is started the appropriate file availability as determined by the if criteria is restored. Further, whenever endif is encountered or the construct is exited, the initial set of available files in effect when encountering the if are restored.
When file availability statements are used in a Test the action test state mode the set or available files is not reset when the construct terminates.
The Run and Build List statements can also constrain their functionality based on the per file test state and track variables.